From 2f3ca9d9e477ed96103a36cbb0d8edf6416dc90c Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 19 Mar 2020 11:32:44 +0900 Subject: [PATCH] [qwaq] Clean up the hierarchy I think I've finally figured out what I want the core hierarchy to be. Right now, it's just the two classes: View and Window (derived from View). Window has a Group, and Group is just a collection of Views that it manages. QwaqApplication is just an object but like a Window, it has a Group of views. View Window has a Group Group contains Views QwaqApplication has a group More work needs to be done on drawing and event handling, but things are working again. --- ruamoko/qwaq/qwaq-app.r | 1 + ruamoko/qwaq/qwaq-group.h | 14 +++++++++++--- ruamoko/qwaq/qwaq-group.r | 25 ++++++++++--------------- ruamoko/qwaq/qwaq-view.h | 9 ++++++++- ruamoko/qwaq/qwaq-view.r | 13 ++++++++++++- ruamoko/qwaq/qwaq-window.h | 8 ++++---- ruamoko/qwaq/qwaq-window.r | 16 +++++++++++----- 7 files changed, 57 insertions(+), 29 deletions(-) diff --git a/ruamoko/qwaq/qwaq-app.r b/ruamoko/qwaq/qwaq-app.r index d8809f307..798c83308 100644 --- a/ruamoko/qwaq/qwaq-app.r +++ b/ruamoko/qwaq/qwaq-app.r @@ -4,6 +4,7 @@ int fence; #include "color.h" #include "qwaq-app.h" #include "qwaq-curses.h" +#include "qwaq-group.h" #include "qwaq-window.h" #include "qwaq-screen.h" #include "qwaq-view.h" diff --git a/ruamoko/qwaq/qwaq-group.h b/ruamoko/qwaq/qwaq-group.h index 483a07c05..956e43d1a 100644 --- a/ruamoko/qwaq/qwaq-group.h +++ b/ruamoko/qwaq/qwaq-group.h @@ -1,17 +1,25 @@ #ifndef __qwaq_group_h #define __qwaq_group_h -#include "qwaq-view.h" +#include -@interface Group : View +#include "event.h" +#include "qwaq-draw.h" + +@class View; + +@interface Group : Object { Array *views; int focused; - id buffer; + id context; } -initWithContext: (id) context; -insert: (View *) view; -remove: (View *) view; +-draw; +-redraw; +-handleEvent: (qwaq_event_t *) event; @end #endif//__qwaq_group_h diff --git a/ruamoko/qwaq/qwaq-group.r b/ruamoko/qwaq/qwaq-group.r index e9982fd1c..0480fbf05 100644 --- a/ruamoko/qwaq/qwaq-group.r +++ b/ruamoko/qwaq/qwaq-group.r @@ -1,7 +1,9 @@ #include #include "event.h" +#include "qwaq-draw.h" #include "qwaq-garray.h" #include "qwaq-group.h" +#include "qwaq-view.h" @implementation Group @@ -10,18 +12,7 @@ if (!(self = [super init])) { return nil; } - textContext = context; - absRect = rect = { nil, [textContext size] }; - buffer = [DrawBuffer buffer: rect.extent]; - views = [[Array array] retain]; - return self; -} - --initWithRect: (Rect) rect -{ - if (!(self = [super initWithRect: rect])) { - return nil; - } + self.context = context; views = [[Array array] retain]; return self; } @@ -34,7 +25,7 @@ -insert: (View *) view { [views addObject: view]; - view.textContext = buffer; + [view setContext: context]; return self; } @@ -58,7 +49,7 @@ not_dont_draw (id aView, void *aGroup) View *view = aView; Group *group = (Group *) aGroup; - return !(view.options & ofDontDraw); + return !([view options] & ofDontDraw); } -draw @@ -69,9 +60,13 @@ not_dont_draw (id aView, void *aGroup) return self; } +-redraw +{ + return self; +} + -handleEvent: (qwaq_event_t *) event { - [super handleEvent: event]; if (event.what & qe_focused) { if (focused >= 0) { [[views objectAtIndex:focused] handleEvent: event]; diff --git a/ruamoko/qwaq/qwaq-view.h b/ruamoko/qwaq/qwaq-view.h index 54e52f03a..ef6d79568 100644 --- a/ruamoko/qwaq/qwaq-view.h +++ b/ruamoko/qwaq/qwaq-view.h @@ -53,12 +53,19 @@ enum { } -initWithRect: (Rect) rect; - (void) dealloc; + -setOwner: (Group *) owner; --(struct Rect_s *)getRect; + +-(struct Rect_s *)rect; + +-(int) options; + +-setContext: (id) context; -draw; -redraw; -handleEvent: (qwaq_event_t *) event; + - (void) refresh; - (void) mvprintf: (Point) pos, string fmt, ...; - (void) mvvprintf: (Point) pos, string fmt, @va_list args; diff --git a/ruamoko/qwaq/qwaq-view.r b/ruamoko/qwaq/qwaq-view.r index 659e9ffbe..5217504fd 100644 --- a/ruamoko/qwaq/qwaq-view.r +++ b/ruamoko/qwaq/qwaq-view.r @@ -27,6 +27,17 @@ [super dealloc]; } +- setContext: (id) context +{ + textContext = context; + return self; +} + +- (int) options +{ + return options; +} + static void updateScreenCursor (View *view) { @@ -84,7 +95,7 @@ updateScreenCursor (View *view) return self; } -- (Rect *) getRect +- (Rect *) rect { return ▭ } diff --git a/ruamoko/qwaq/qwaq-window.h b/ruamoko/qwaq/qwaq-window.h index 2e925c035..18c4f9fc6 100644 --- a/ruamoko/qwaq/qwaq-window.h +++ b/ruamoko/qwaq/qwaq-window.h @@ -3,17 +3,17 @@ #include "Object.h" -@class Array; +@class Group; #include "qwaq-draw.h" #include "qwaq-rect.h" #include "qwaq-view.h" -#include "qwaq-group.h" -@interface Window: Group +@interface Window: View { - Point point; // FIXME can't be local :( struct panel_s *panel; + Group *objects; + Point point; // FIXME can't be local :( DrawBuffer *buf; } +windowWithRect: (Rect) rect; diff --git a/ruamoko/qwaq/qwaq-window.r b/ruamoko/qwaq/qwaq-window.r index af0f576cb..0f3c81037 100644 --- a/ruamoko/qwaq/qwaq-window.r +++ b/ruamoko/qwaq/qwaq-window.r @@ -2,6 +2,7 @@ #include "event.h" #include "qwaq-curses.h" +#include "qwaq-group.h" #include "qwaq-window.h" #include "qwaq-view.h" @@ -18,9 +19,9 @@ return nil; } self.rect = rect; - buffer = [[TextContext alloc] initWithRect: rect]; - textContext = buffer; - panel = create_panel ([(id)buffer window]); + textContext = [[TextContext alloc] initWithRect: rect]; + panel = create_panel ([(id)textContext window]); + buf = [DrawBuffer buffer: {3, 3}]; [buf mvaddstr: {0, 0}, "XOX"]; [buf mvaddstr: {0, 1}, "OXO"]; @@ -28,6 +29,11 @@ return self; } +-setContext: (id) context +{ + return self; +} + -handleEvent: (qwaq_event_t *) event { /* switch (event.what) { @@ -74,7 +80,7 @@ -setBackground: (int) ch { - [(id)buffer bkgd: ch]; + [(id)textContext bkgd: ch]; return self; } @@ -95,7 +101,7 @@ } } [super draw]; - [(id)buffer border: box_sides, box_corners]; + [(id)textContext border: box_sides, box_corners]; Point pos = { 1, 1 }; //for (int i = ACS_ULCORNER; i <= ACS_STERLING; i++) { for (int i = 32; i <= 127; i++) {