diff --git a/ruamoko/lib/Makefile.am b/ruamoko/lib/Makefile.am index f488a192c..e2b34ee99 100644 --- a/ruamoko/lib/Makefile.am +++ b/ruamoko/lib/Makefile.am @@ -19,11 +19,11 @@ noinst_LIBRARIES= libr.a libgui.a libcsqc.a libr_a_SOURCES=\ crudefile.r debug.r entities.r infokey.r math.r message.r nq_message.r \ physics.r qw_message.r qw_physics.r qw_sys.r sound.r string.r system.r \ - Object.r Entity.r + Object.r Entity.r Point.r Size.r Rect.r libr_a_AR=$(PAK) -cf libgui_a_SOURCES=\ - draw.r InputLine.r key.r Point.r + draw.r InputLine.r key.r libgui_a_AR=$(PAK) -cf libcsqc_a_SOURCES= \ diff --git a/ruamoko/lib/Rect.r b/ruamoko/lib/Rect.r new file mode 100644 index 000000000..0d720bda4 --- /dev/null +++ b/ruamoko/lib/Rect.r @@ -0,0 +1,89 @@ +#include "Object.h" +#include "Point.h" +#include "Size.h" +#include "Rect.h" + +@implementation Rect + +- (id) initWithComponents: (integer)x : (integer)y : (integer)w : (integer)h +{ + id (self) = [super init]; + id (origin) = [[Size alloc] initWithComponents: x : y]; + id (size) = [[Size alloc] initWithComponents: w : h]; + return self; +} + +- (id) initWithOrigin: (Point)anOrigin size: (Size)aSize +{ + id (self) = [super init]; + + if (!self || !anOrigin || !aSize) + return NIL; + + id (origin) = [anOrigin copy]; + id (size) = [aSize copy]; + + return self; +} + +- (id) initWithRect: (Rect)aRect +{ + id (self) = [super init]; + + if (!self || !aRect) + return NIL; + + [self setRect: aRect]; + + return self; +} + +- (id) copy +{ + local id myCopy = [super copy]; + + if (!myCopy) + myCopy = [[self class] alloc]; + + return [myCopy initWithOrigin: origin size: size]; +} + +- (Point) origin +{ + return origin; +} + +- (Size) size +{ + return size; +} + +- (void) setOrigin: (Point)aPoint +{ + if (!aPoint) + return; + + if (origin) + [origin free]; + + id (origin) = [aPoint copy]; +} + +- (void) setSize: (Size)aSize +{ + if (!aSize) + return; + + if (size) + [size free]; + + id (size) = [aSize copy]; +} + +- (void) setRect: (Rect)aRect +{ + [self setOrigin: [aRect origin]]; + [self setSize: [aRect size]]; +} + +@end diff --git a/ruamoko/lib/Size.r b/ruamoko/lib/Size.r new file mode 100644 index 000000000..a2a87bfb0 --- /dev/null +++ b/ruamoko/lib/Size.r @@ -0,0 +1,74 @@ +#include "Size.h" + +@implementation Size + +- (id) initWithComponents: (integer)w : (integer)h +{ + id (self) = [super init]; + width = w; + height = h; + return self; +} + +- (id) initWithSize: (Size)aSize +{ + id (self) = [super init]; + + if (!self || !aSize) + return NIL; + + width = [aSize width]; + height = [aSize height]; + + return self; +} + +- (id) copy +{ + local id myCopy = [super copy]; + + if (!myCopy) + myCopy = [[self class] alloc]; + + return [myCopy initWithComponents: width : height]; +} + +- (id) width +{ + return width; +} + +- (id) height +{ + return height; +} + +- (void) setSize: (Size)aSize +{ + width = [aSize width]; + height = [aSize height]; +} + +- (void) setWidth: (integer) w +{ + width = w; +} + +- (void) setHeight: (integer) h +{ + height = h; +} + +- (void) addSize: (Size)aSize +{ + width += [aSize width]; + height += [aSize height]; +} + +- (void) subtractSize: (Size)aSize +{ + width += [aSize width]; + height += [aSize height]; +} + +@end