Implement Size and Rect.

This commit is contained in:
Jeff Teunissen 2002-08-17 06:47:03 +00:00
parent 5e1ce57322
commit 51ce063486
3 changed files with 165 additions and 2 deletions

View file

@ -19,11 +19,11 @@ noinst_LIBRARIES= libr.a libgui.a libcsqc.a
libr_a_SOURCES=\ libr_a_SOURCES=\
crudefile.r debug.r entities.r infokey.r math.r message.r nq_message.r \ 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 \ 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 libr_a_AR=$(PAK) -cf
libgui_a_SOURCES=\ libgui_a_SOURCES=\
draw.r InputLine.r key.r Point.r draw.r InputLine.r key.r
libgui_a_AR=$(PAK) -cf libgui_a_AR=$(PAK) -cf
libcsqc_a_SOURCES= \ libcsqc_a_SOURCES= \

89
ruamoko/lib/Rect.r Normal file
View file

@ -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

74
ruamoko/lib/Size.r Normal file
View file

@ -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