HUD interface leak fixes and enhancements. Something is still leaking

memory, though.
This commit is contained in:
Brian Koropoff 2003-05-15 06:49:10 +00:00
parent dedb2fa6bf
commit dcf1bcf141
3 changed files with 62 additions and 18 deletions

View file

@ -2,7 +2,7 @@
@interface HUDObject : Object
{
Point origin;
Point origin, size;
BOOL visible;
integer handle;
}
@ -14,6 +14,8 @@
- (Point) origin;
- (void) setOrigin: (Point) newPoint;
- (void) translate: (Point) addPoint;
- (Point) size;
//- (void) center Horizontal: (BOOL) h Vertical: (BOOL) v;
- (BOOL) isVisible;
- (void) setVisible: (BOOL) _visible;
- (void) display;

View file

@ -1,6 +1,7 @@
#include "draw.h"
#include "debug.h"
#include "gib.h"
#include "string.h"
#include "HUD.h"
integer HUDHandleClass;
@ -13,6 +14,7 @@ integer HUDHandleClass;
- (id) initWithComponents: (integer) x : (integer) y
{
self = [super init];
origin = [[Point alloc] initWithComponents: x :y];
visible = YES;
handle = GIB_Handle_New (self, HUDHandleClass);
@ -23,6 +25,7 @@ integer HUDHandleClass;
- (void) free
{
[origin free];
[size free];
GIB_Handle_Free (handle, HUDHandleClass);
[super free];
}
@ -37,6 +40,11 @@ integer HUDHandleClass;
return origin;
}
- (Point) size
{
return size;
}
- (void) setOrigin: (Point) newPoint
{
[origin setPoint :newPoint];
@ -47,6 +55,16 @@ integer HUDHandleClass;
[origin addPoint :addPoint];
}
/*
- (void) center Horizontal: (BOOL) h Vertical: (BOOL) v
{
Point newCoords;
integer newX, newY;
if (h) {
newX = X
*/
- (BOOL) isVisible
{
return visible;
@ -66,7 +84,7 @@ integer HUDHandleClass;
- (id) initWithComponents: (integer) x :(integer) y :(string) _text
{
self = [super initWithComponents :x :y];
text = _text;
[self setText :_text];
return self;
}
@ -79,6 +97,8 @@ integer HUDHandleClass;
- (void) setText: (string) _text
{
text = _text;
[size free];
size = [[Point alloc] initWithComponents :8*(integer) strlen (text) :8];
}
- (void) display
@ -92,21 +112,23 @@ integer HUDHandleClass;
- (id) initWithComponents: (integer)x :(integer)y :(string) _file
{
self = [super initWithComponents :x :y];
picture = [[QPic alloc] initName :_file];
[self setFile :_file];
return self;
}
- (void) free
{
[super free];
[picture free];
[super free];
}
- (void) setFile: (string) _file
{
[picture free];
picture = [[QPic alloc] initName :_file];
[size free];
size = [[Point alloc] initWithComponents :[picture width] :[picture height]];
}
- (void) display

View file

@ -15,8 +15,8 @@ void (integer argc, string [] argv) gib_hud_new_text_f =
return;
newText = [[HUDText alloc] initWithComponents
:(integer) stof (argv[1])
:(integer) stof (argv[2])
:stoi (argv[1])
:stoi (argv[2])
:argv[3]
];
@ -33,8 +33,8 @@ void (integer argc, string [] argv) gib_hud_new_graphic_f =
return;
newGraphic = [[HUDGraphic alloc] initWithComponents
:(integer) stof (argv[1])
:(integer) stof (argv[2])
:stoi (argv[1])
:stoi (argv[2])
:argv[3]
];
@ -53,16 +53,36 @@ void (integer argc, string [] argv) gib_hud_delete_f =
return;
for (i = 1; i < argc; i++) {
trashObject = GIB_Handle_Get ((integer) stof (argv[i]), HUDHandleClass);
trashObject = GIB_Handle_Get (stoi (argv[i]), HUDHandleClass);
if (trashObject) {
[HUDObjects removeItem :trashObject];
[trashObject free];
} else
dprint (sprintf ("Warning: no HUD object associated with handle %i\n", (integer) stof (argv[i])));
dprint (sprintf ("Warning: no HUD object associated with handle %i\n", stoi (argv[i])));
}
};
void (integer argc, string [] argv) gib_hud_get_origin_f =
void (integer argc, string [] argv) gib_hud_get_rect_f =
{
local HUDObject myObject;
local Point myPoint;
if (argc != 2)
return;
myObject = GIB_Handle_Get (stoi (argv[1]), HUDHandleClass);
if (!myObject)
return;
myPoint = [myObject origin];
GIB_Return (itos ([myPoint x]));
GIB_Return (itos ([myPoint y]));
myPoint = [myObject size];
GIB_Return (itos ([myPoint x]));
GIB_Return (itos ([myPoint y]));
};
void (integer argc, string [] argv) gib_hud_get_size_f =
{
local HUDObject myObject;
local Point myOrigin;
@ -70,7 +90,7 @@ void (integer argc, string [] argv) gib_hud_get_origin_f =
if (argc != 2)
return;
myObject = GIB_Handle_Get ((integer) stof (argv[1]), HUDHandleClass);
myObject = GIB_Handle_Get (stoi (argv[1]), HUDHandleClass);
if (!myObject)
return;
@ -87,14 +107,14 @@ void (integer argc, string [] argv) gib_hud_set_translate_f =
if (argc < 4)
return;
p = [[Point alloc] initWithComponents :(integer) stof (argv[argc-2]) :(integer) stof (argv[argc-1])];
p = [[Point alloc] initWithComponents :stoi (argv[argc-2]) :stoi (argv[argc-1])];
if (argv[0] == "HUD::translate")
for (i = 1; i < argc - 2; i++)
[(HUDObject) GIB_Handle_Get ((integer) stof (argv[i]), HUDHandleClass) translate :p];
[(HUDObject) GIB_Handle_Get (stoi (argv[i]), HUDHandleClass) translate :p];
else
for (i = 1; i < argc - 2; i++)
[(HUDObject) GIB_Handle_Get ((integer) stof (argv[i]), HUDHandleClass) setOrigin :p];
[(HUDObject) GIB_Handle_Get (stoi (argv[i]), HUDHandleClass) setOrigin :p];
[p free];
};
@ -105,7 +125,7 @@ void (integer argc, string [] argv) gib_hud_set_text_f =
if (argc != 3)
return;
myObject = GIB_Handle_Get ((integer) stof (argv[1]), HUDHandleClass);
myObject = GIB_Handle_Get (stoi (argv[1]), HUDHandleClass);
if (!myObject || ![myObject isKindOf :[HUDText class]])
return;
[myObject setText :argv[2]];
@ -118,7 +138,7 @@ void (integer argc, string [] argv) gib_hud_set_file_f =
if (argc != 3)
return;
myObject = GIB_Handle_Get ((integer) stof (argv[1]), HUDHandleClass);
myObject = GIB_Handle_Get (stoi (argv[1]), HUDHandleClass);
if (!myObject || ![myObject isKindOf :[HUDGraphic class]])
return;
[myObject setFile :argv[2]];
@ -129,7 +149,7 @@ void () HUD_Init =
GIB_Builtin_Add ("HUD::newText", gib_hud_new_text_f);
GIB_Builtin_Add ("HUD::newGraphic", gib_hud_new_graphic_f);
GIB_Builtin_Add ("HUD::delete", gib_hud_delete_f);
GIB_Builtin_Add ("HUD::getOrigin", gib_hud_get_origin_f);
GIB_Builtin_Add ("HUD::getRect", gib_hud_get_rect_f);
GIB_Builtin_Add ("HUD::setOrigin", gib_hud_set_translate_f);
GIB_Builtin_Add ("HUD::translate", gib_hud_set_translate_f);
GIB_Builtin_Add ("HUD::setText", gib_hud_set_text_f);