[qwaq] Use protocols to distinguish object abilities

Well, that took a fair bit more than it should have to get working: had
to implement the protocol support in qfcc and engine-side ruamoko.
This commit is contained in:
Bill Currie 2020-03-02 15:22:54 +09:00
parent 0e40366c7f
commit d88a091fc6
9 changed files with 62 additions and 5 deletions

View file

@ -32,4 +32,16 @@ typedef struct qwaq_event_s {
} e; } e;
} qwaq_event_t; } qwaq_event_t;
#ifdef __QFCC__ // don't want C gcc to see this :)
@protocol HandleEvent
-handleEvent: (struct qwaq_event_s *) event;
@end
@protocol TakeFocus <HandleEvent>
-takeFocus;
-loseFocus;
@end
#endif
#endif//__qwaq_event_h #endif//__qwaq_event_h

View file

@ -166,6 +166,9 @@ main (int argc, const char **argv)
Sys_Error ("couldn't load %s", name); Sys_Error ("couldn't load %s", name);
} }
//pr.pr_trace = 1;
//pr.pr_trace_depth = -1;
PR_PushFrame (&pr); PR_PushFrame (&pr);
if (argc > 2) if (argc > 2)
pr_argc = argc - 1; pr_argc = argc - 1;

8
ruamoko/qwaq/qwaq-draw.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef __qwaq_draw_h
#define __qwaq_draw_h
@protocol Draw
-draw;
@end
#endif

View file

@ -3,14 +3,16 @@
#include <Object.h> #include <Object.h>
#include "qwaq-draw.h"
#include "qwaq-rect.h" #include "qwaq-rect.h"
@class View; @class View;
@class Array; @class Array;
@interface Screen: Object @interface Screen: Object <HandleEvent, Draw>
{ {
Rect rect; Rect rect;
Array *views; Array *views;
Array *event_handlers;
View *focusedView; View *focusedView;
struct window_s *window; struct window_s *window;
} }

View file

@ -19,6 +19,12 @@
-add: obj -add: obj
{ {
if ([obj conformsToProtocol: @protocol (Draw)]) {
[views addObject: obj];
}
if ([obj conformsToProtocol: @protocol (HandleEvent)]) {
[event_handlers addObject: obj];
}
return self; return self;
} }
@ -29,4 +35,14 @@
return self; return self;
} }
-handleEvent: (qwaq_event_t *) event
{
return self;
}
-draw
{
return self;
}
@end @end

View file

@ -4,9 +4,10 @@
#include <Array.h> #include <Array.h>
#include <Object.h> #include <Object.h>
#include "qwaq-draw.h"
#include "qwaq-rect.h" #include "qwaq-rect.h"
@interface View: Object @interface View: Object <Draw>
{ {
Rect rect; Rect rect;
Rect absRect; Rect absRect;
@ -14,7 +15,6 @@
struct window_s *window; struct window_s *window;
} }
-initWithRect: (Rect) rect; -initWithRect: (Rect) rect;
-handleEvent: (struct qwaq_event_s *) event;
@end @end
#endif//__qwaq_view_h #endif//__qwaq_view_h

View file

@ -28,7 +28,7 @@ rectContainsPoint (Rect *rect, Point *point)
return self; return self;
} }
-handleEvent: (qwaq_event_t *) event -draw
{ {
return self; return self;
} }

View file

@ -6,9 +6,10 @@
@class View; @class View;
@class Array; @class Array;
#include "qwaq-draw.h"
#include "qwaq-rect.h" #include "qwaq-rect.h"
@interface Window: Object @interface Window: Object <Draw, TakeFocus>
{ {
Rect rect; Rect rect;
Point point; // FIXME can't be local :( Point point; // FIXME can't be local :(

View file

@ -68,4 +68,19 @@
wbkgd (window, ch); wbkgd (window, ch);
return self; return self;
} }
-takeFocus
{
return self;
}
-loseFocus
{
return self;
}
-draw
{
return self;
}
@end @end