From d88a091fc658500d16fd88219e2102067ac376f1 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 2 Mar 2020 15:22:54 +0900 Subject: [PATCH] [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. --- ruamoko/qwaq/event.h | 12 ++++++++++++ ruamoko/qwaq/main.c | 3 +++ ruamoko/qwaq/qwaq-draw.h | 8 ++++++++ ruamoko/qwaq/qwaq-screen.h | 4 +++- ruamoko/qwaq/qwaq-screen.r | 16 ++++++++++++++++ ruamoko/qwaq/qwaq-view.h | 4 ++-- ruamoko/qwaq/qwaq-view.r | 2 +- ruamoko/qwaq/qwaq-window.h | 3 ++- ruamoko/qwaq/qwaq-window.r | 15 +++++++++++++++ 9 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 ruamoko/qwaq/qwaq-draw.h diff --git a/ruamoko/qwaq/event.h b/ruamoko/qwaq/event.h index 006d37c42..f494234a9 100644 --- a/ruamoko/qwaq/event.h +++ b/ruamoko/qwaq/event.h @@ -32,4 +32,16 @@ typedef struct qwaq_event_s { } e; } qwaq_event_t; +#ifdef __QFCC__ // don't want C gcc to see this :) +@protocol HandleEvent +-handleEvent: (struct qwaq_event_s *) event; +@end + +@protocol TakeFocus +-takeFocus; +-loseFocus; +@end + +#endif + #endif//__qwaq_event_h diff --git a/ruamoko/qwaq/main.c b/ruamoko/qwaq/main.c index 3f88a428a..191714c74 100644 --- a/ruamoko/qwaq/main.c +++ b/ruamoko/qwaq/main.c @@ -166,6 +166,9 @@ main (int argc, const char **argv) Sys_Error ("couldn't load %s", name); } + //pr.pr_trace = 1; + //pr.pr_trace_depth = -1; + PR_PushFrame (&pr); if (argc > 2) pr_argc = argc - 1; diff --git a/ruamoko/qwaq/qwaq-draw.h b/ruamoko/qwaq/qwaq-draw.h new file mode 100644 index 000000000..4abac3e55 --- /dev/null +++ b/ruamoko/qwaq/qwaq-draw.h @@ -0,0 +1,8 @@ +#ifndef __qwaq_draw_h +#define __qwaq_draw_h + +@protocol Draw +-draw; +@end + +#endif diff --git a/ruamoko/qwaq/qwaq-screen.h b/ruamoko/qwaq/qwaq-screen.h index 365c54506..cbd0a6721 100644 --- a/ruamoko/qwaq/qwaq-screen.h +++ b/ruamoko/qwaq/qwaq-screen.h @@ -3,14 +3,16 @@ #include +#include "qwaq-draw.h" #include "qwaq-rect.h" @class View; @class Array; -@interface Screen: Object +@interface Screen: Object { Rect rect; Array *views; + Array *event_handlers; View *focusedView; struct window_s *window; } diff --git a/ruamoko/qwaq/qwaq-screen.r b/ruamoko/qwaq/qwaq-screen.r index cd4e25365..e44c25481 100644 --- a/ruamoko/qwaq/qwaq-screen.r +++ b/ruamoko/qwaq/qwaq-screen.r @@ -19,6 +19,12 @@ -add: obj { + if ([obj conformsToProtocol: @protocol (Draw)]) { + [views addObject: obj]; + } + if ([obj conformsToProtocol: @protocol (HandleEvent)]) { + [event_handlers addObject: obj]; + } return self; } @@ -29,4 +35,14 @@ return self; } +-handleEvent: (qwaq_event_t *) event +{ + return self; +} + +-draw +{ + return self; +} + @end diff --git a/ruamoko/qwaq/qwaq-view.h b/ruamoko/qwaq/qwaq-view.h index 811998ed0..e532f9f0b 100644 --- a/ruamoko/qwaq/qwaq-view.h +++ b/ruamoko/qwaq/qwaq-view.h @@ -4,9 +4,10 @@ #include #include +#include "qwaq-draw.h" #include "qwaq-rect.h" -@interface View: Object +@interface View: Object { Rect rect; Rect absRect; @@ -14,7 +15,6 @@ struct window_s *window; } -initWithRect: (Rect) rect; --handleEvent: (struct qwaq_event_s *) event; @end #endif//__qwaq_view_h diff --git a/ruamoko/qwaq/qwaq-view.r b/ruamoko/qwaq/qwaq-view.r index c03d880f4..8cf37c53d 100644 --- a/ruamoko/qwaq/qwaq-view.r +++ b/ruamoko/qwaq/qwaq-view.r @@ -28,7 +28,7 @@ rectContainsPoint (Rect *rect, Point *point) return self; } --handleEvent: (qwaq_event_t *) event +-draw { return self; } diff --git a/ruamoko/qwaq/qwaq-window.h b/ruamoko/qwaq/qwaq-window.h index 5d777c828..66c6d440e 100644 --- a/ruamoko/qwaq/qwaq-window.h +++ b/ruamoko/qwaq/qwaq-window.h @@ -6,9 +6,10 @@ @class View; @class Array; +#include "qwaq-draw.h" #include "qwaq-rect.h" -@interface Window: Object +@interface Window: Object { Rect rect; Point point; // FIXME can't be local :( diff --git a/ruamoko/qwaq/qwaq-window.r b/ruamoko/qwaq/qwaq-window.r index 70fe2c476..307f09dce 100644 --- a/ruamoko/qwaq/qwaq-window.r +++ b/ruamoko/qwaq/qwaq-window.r @@ -68,4 +68,19 @@ wbkgd (window, ch); return self; } + +-takeFocus +{ + return self; +} + +-loseFocus +{ + return self; +} + +-draw +{ + return self; +} @end