call [self init] rather than [super init] (and variants where possible) to

ease derived class initialization (all allocation can be done in -init).
Objective-C rocks :)
This commit is contained in:
Bill Currie 2004-02-13 02:51:38 +00:00
parent de567310fb
commit e472364f51
8 changed files with 23 additions and 17 deletions

View file

@ -4,9 +4,9 @@
@implementation Group @implementation Group
- (id) initWithBounds: (Rect)bounds - (id) init
{ {
self = [super initWithBounds:bounds]; self = [super init];
views = [[Array alloc] init]; views = [[Array alloc] init];
return self; return self;
} }
@ -19,6 +19,7 @@
- (View) addView: (View)aView - (View) addView: (View)aView
{ {
[views addItem:aView]; [views addItem:aView];
return aView;
} }
- (void) moveTo: (integer)x y:(integer)y - (void) moveTo: (integer)x y:(integer)y

View file

@ -4,7 +4,7 @@
- (id) initWithComponents: (integer)_x : (integer)_y - (id) initWithComponents: (integer)_x : (integer)_y
{ {
self = [super init]; self = [self init];
x = _x; x = _x;
y = _y; y = _y;
return self; return self;
@ -12,7 +12,7 @@
- (id) initWithPoint: (Point) aPoint - (id) initWithPoint: (Point) aPoint
{ {
self = [super init]; self = [self init];
if (!self || !aPoint) if (!self || !aPoint)
return NIL; return NIL;

View file

@ -7,7 +7,7 @@
- (id) initWithComponents: (integer)x : (integer)y : (integer)w : (integer)h - (id) initWithComponents: (integer)x : (integer)y : (integer)w : (integer)h
{ {
self = [super init]; self = [self init];
origin = [[Size alloc] initWithComponents: x : y]; origin = [[Size alloc] initWithComponents: x : y];
size = [[Size alloc] initWithComponents: w : h]; size = [[Size alloc] initWithComponents: w : h];
return self; return self;
@ -15,7 +15,7 @@
- (id) initWithOrigin: (Point)anOrigin size: (Size)aSize - (id) initWithOrigin: (Point)anOrigin size: (Size)aSize
{ {
self = [super init]; self = [self init];
if (!self || !anOrigin || !aSize) if (!self || !anOrigin || !aSize)
return NIL; return NIL;
@ -28,7 +28,7 @@
- (id) initWithRect: (Rect)aRect - (id) initWithRect: (Rect)aRect
{ {
self = [super init]; self = [self init];
if (!self || !aRect) if (!self || !aRect)
return NIL; return NIL;

View file

@ -4,7 +4,7 @@
- (id) initWithComponents: (integer)w : (integer)h - (id) initWithComponents: (integer)w : (integer)h
{ {
self = [super init]; self = [self init];
width = w; width = w;
height = h; height = h;
return self; return self;
@ -12,7 +12,7 @@
- (id) initWithSize: (Size)aSize - (id) initWithSize: (Size)aSize
{ {
self = [super init]; self = [self init];
if (!self || !aSize) if (!self || !aSize)
return NIL; return NIL;

View file

@ -7,7 +7,7 @@
- (id) initWithBounds: (Rect)aRect size: (integer) aSize - (id) initWithBounds: (Rect)aRect size: (integer) aSize
{ {
self = [super initWithBounds:aRect]; self = [self initWithBounds:aRect];
dir = ylen > xlen; dir = ylen > xlen;
size = aSize; size = aSize;
index = 0; index = 0;

View file

@ -3,6 +3,17 @@
#include "draw.h" #include "draw.h"
@implementation Text @implementation Text
- (id) init
{
text = str_new ();
return self;
}
- (void) dealloc
{
str_free (text);
}
- (id) initWithBounds: (Rect)aRect - (id) initWithBounds: (Rect)aRect
{ {
return [self initWithBounds:aRect text:""]; return [self initWithBounds:aRect text:""];
@ -11,16 +22,10 @@
- (id) initWithBounds: (Rect)aRect text:(string)str - (id) initWithBounds: (Rect)aRect text:(string)str
{ {
self = [super initWithBounds:aRect]; self = [super initWithBounds:aRect];
text = str_new ();
str_copy (text, str); str_copy (text, str);
return self; return self;
} }
- (void) dealloc
{
str_free (text);
}
- (void) setText: (string)str - (void) setText: (string)str
{ {
str_copy (text, str); str_copy (text, str);

View file

@ -7,6 +7,7 @@
- (id) initWithComponents: (integer)x : (integer)y : (integer)w : (integer)h - (id) initWithComponents: (integer)x : (integer)y : (integer)w : (integer)h
{ {
self = [self init];
xpos = xabs = x; xpos = xabs = x;
ypos = yabs = y; ypos = yabs = y;
xlen = w; xlen = w;

View file

@ -9,7 +9,6 @@
{ {
Array views; Array views;
} }
- (id) initWithBounds: (Rect)bounds;
- (void) dealloc; - (void) dealloc;
- (View) addView: (View)aView; - (View) addView: (View)aView;
- (void) moveTo: (integer)x y:(integer)y; - (void) moveTo: (integer)x y:(integer)y;