From 92cb3a5285fb75538255c18e2e2dc692e4ecf74b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 1 Mar 2020 18:25:02 +0900 Subject: [PATCH] [qwaq] Flatten the hierarchy and do some cleanup --- ruamoko/qwaq/Makefile.am | 2 +- ruamoko/qwaq/qwaq-app.h | 6 ++-- ruamoko/qwaq/qwaq-app.r | 18 +++++----- ruamoko/qwaq/qwaq-rect.h | 21 +++++++++++ ruamoko/qwaq/qwaq-screen.h | 22 ++++++++++++ ruamoko/qwaq/qwaq-screen.r | 32 +++++++++++++++++ ruamoko/qwaq/qwaq-view.h | 30 ++-------------- ruamoko/qwaq/qwaq-view.r | 71 +------------------------------------- ruamoko/qwaq/qwaq-window.h | 18 ++++++++-- ruamoko/qwaq/qwaq-window.r | 63 +++++++++++++++++++++++++++++++++ 10 files changed, 172 insertions(+), 111 deletions(-) create mode 100644 ruamoko/qwaq/qwaq-rect.h create mode 100644 ruamoko/qwaq/qwaq-screen.h create mode 100644 ruamoko/qwaq/qwaq-screen.r diff --git a/ruamoko/qwaq/Makefile.am b/ruamoko/qwaq/Makefile.am index f38fc77e5..38584d949 100644 --- a/ruamoko/qwaq/Makefile.am +++ b/ruamoko/qwaq/Makefile.am @@ -57,7 +57,7 @@ qwaq_x11_DEPENDENCIES= $(qwaq_x11_libs) $(QWAQ_DEPS) r_depfiles_remade= -qwaq_app_dat_SOURCES=qwaq-app.r qwaq-view.r qwaq-window.r +qwaq_app_dat_SOURCES=qwaq-app.r qwaq-screen.r qwaq-window.r qwaq-view.r qwaq_app_obj=$(qwaq_app_dat_SOURCES:.r=.o) qwaq_app_dep=$(addprefix ./$(DEPDIR)/,$(qwaq_app_obj:.o=.Qo)) qwaq-app.dat$(EXEEXT): $(qwaq_app_obj) $(QFCC_DEP) diff --git a/ruamoko/qwaq/qwaq-app.h b/ruamoko/qwaq/qwaq-app.h index c02beac67..b603fb4b1 100644 --- a/ruamoko/qwaq/qwaq-app.h +++ b/ruamoko/qwaq/qwaq-app.h @@ -1,15 +1,15 @@ #ifndef __qwaq_app_h #define __qwaq_app_h -#include "qwaq-view.h" - #include "event.h" +@class Screen; + @interface QwaqApplication: Object { qwaq_event_t event; qwaq_command endState; - View *view; + Screen *screen; } -run; -handleEvent: (qwaq_event_t *) event; diff --git a/ruamoko/qwaq/qwaq-app.r b/ruamoko/qwaq/qwaq-app.r index 80ed06c41..d9051f4d9 100644 --- a/ruamoko/qwaq/qwaq-app.r +++ b/ruamoko/qwaq/qwaq-app.r @@ -4,6 +4,8 @@ #include "qwaq-app.h" #include "qwaq-curses.h" #include "qwaq-window.h" +#include "qwaq-screen.h" +#include "qwaq-view.h" static AutoreleasePool *autorelease_pool; static void @@ -33,18 +35,18 @@ arp_end (void) initialize (); init_pair (1, COLOR_WHITE, COLOR_BLUE); init_pair (2, COLOR_WHITE, COLOR_BLACK); - view = [[View viewFromWindow:stdscr] retain]; - [view setBackground: COLOR_PAIR (1)]; - Rect r = view.rect; - wprintf (view.window, "%d %d %d %d\n", r.xpos, r.ypos, r.xlen, r.ylen); + screen = [[Screen screen] retain]; + [screen setBackground: COLOR_PAIR (1)]; + Rect r = screen.rect; + wprintf (screen.window, "%d %d %d %d\n", r.xpos, r.ypos, r.xlen, r.ylen); r.xpos = r.xlen / 4; r.ypos = r.ylen / 4; r.xlen /= 2; r.ylen /= 2; - wprintf (view.window, "%d %d %d %d\n", r.xpos, r.ypos, r.xlen, r.ylen); - wrefresh(view.window); + wprintf (screen.window, "%d %d %d %d\n", r.xpos, r.ypos, r.xlen, r.ylen); + wrefresh(screen.window); Window *w; - [view addView: w=[[Window windowWithRect: r] setBackground: COLOR_PAIR (2)]]; + [screen add: w=[[Window windowWithRect: r] setBackground: COLOR_PAIR (2)]]; wprintf (w.window, "%d %d %d %d\n", r.xpos, r.ypos, r.xlen, r.ylen); return self; } @@ -68,7 +70,7 @@ arp_end (void) -handleEvent: (qwaq_event_t *) event { - [view handleEvent: event]; + [screen handleEvent: event]; if (event.event_type == qe_key && event.e.key == '\x18') { event.event_type = qe_command; event.e.message.command = qc_exit; diff --git a/ruamoko/qwaq/qwaq-rect.h b/ruamoko/qwaq/qwaq-rect.h new file mode 100644 index 000000000..0c26b5817 --- /dev/null +++ b/ruamoko/qwaq/qwaq-rect.h @@ -0,0 +1,21 @@ +#ifndef __qwaq_rect_h +#define __qwaq_rect_h + +typedef struct { + int xpos; + int ypos; + int xlen; + int ylen; +} Rect; + +typedef struct { + int x; + int y; +} Point; + +@extern Rect makeRect (int xpos, int ypos, int xlen, int ylen); +//XXX will not work if point or rect point to a local variabl +@extern int rectContainsPoint (Rect *rect, Point *point); +@extern Rect getwrect (struct window_s *window); + +#endif//__qwaq_rect_h diff --git a/ruamoko/qwaq/qwaq-screen.h b/ruamoko/qwaq/qwaq-screen.h new file mode 100644 index 000000000..365c54506 --- /dev/null +++ b/ruamoko/qwaq/qwaq-screen.h @@ -0,0 +1,22 @@ +#ifndef __qwaq_screen_h +#define __qwaq_screen_h + +#include + +#include "qwaq-rect.h" +@class View; +@class Array; + +@interface Screen: Object +{ + Rect rect; + Array *views; + View *focusedView; + struct window_s *window; +} ++(Screen *) screen; +-add: obj; +-setBackground: (int) ch; +@end + +#endif//__qwaq_screen_h diff --git a/ruamoko/qwaq/qwaq-screen.r b/ruamoko/qwaq/qwaq-screen.r new file mode 100644 index 000000000..cd4e25365 --- /dev/null +++ b/ruamoko/qwaq/qwaq-screen.r @@ -0,0 +1,32 @@ +#include "qwaq-curses.h" +#include "qwaq-screen.h" + +@implementation Screen ++(Screen *) screen +{ + return [[[self alloc] init] autorelease]; +} + +-init +{ + if (!(self = [super init])) { + return nil; + } + window = stdscr; + rect = getwrect (window); + return self; +} + +-add: obj +{ + return self; +} + +-setBackground: (int) ch +{ + wbkgd (window, ch); + wrefresh (window); + return self; +} + +@end diff --git a/ruamoko/qwaq/qwaq-view.h b/ruamoko/qwaq/qwaq-view.h index 63a9b4db5..811998ed0 100644 --- a/ruamoko/qwaq/qwaq-view.h +++ b/ruamoko/qwaq/qwaq-view.h @@ -4,41 +4,17 @@ #include #include -#include "event.h" -#include "qwaq-curses.h" - -typedef struct { - int xpos; - int ypos; - int xlen; - int ylen; -} Rect; - -typedef struct { - int x; - int y; -} Point; - -@extern Rect makeRect (int xpos, int ypos, int xlen, int ylen); -//XXX will not work if point or rect point to a local variabl -@extern int rectContainsPoint (Rect *rect, Point *point); -@extern Rect getwrect (window_t window); +#include "qwaq-rect.h" @interface View: Object { Rect rect; Rect absRect; - Array *views; Point point; // can't be local :( - View *focusedView; - window_t window; - panel_t panel; + struct window_s *window; } -+viewFromWindow: (window_t) window; -initWithRect: (Rect) rect; --handleEvent: (qwaq_event_t *) event; --addView: (View *) view; --setBackground: (int) ch; +-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 e71006846..c03d880f4 100644 --- a/ruamoko/qwaq/qwaq-view.r +++ b/ruamoko/qwaq/qwaq-view.r @@ -17,11 +17,6 @@ rectContainsPoint (Rect *rect, Point *point) @implementation View -+viewFromWindow: (window_t) window -{ - return [[[self alloc] initFromWindow: window] autorelease]; -} - -initWithRect: (Rect) rect { if (!(self = [super init])) { @@ -29,76 +24,12 @@ rectContainsPoint (Rect *rect, Point *point) } self.rect = rect; self.absRect = rect; - self.window = create_window (rect.xpos, rect.ypos, rect.xlen, rect.ylen); - self.panel = create_panel (self.window); - return self; -} - --initFromWindow: (window_t) window -{ - if (!(self = [super init])) { - return nil; - } - rect = getwrect (window); - self.window = window; - self.panel = nil; - return self; -} - --initWithPanel: (panel_t) panel -{ - if (!(self = [super init])) { - return nil; - } - self.panel = panel; - self.window = panel_window (panel); - rect = getwrect (window); - return self; -} - --addView: (View *) view -{ - [views addObject: view]; - return self; -} - --setBackground: (int) ch -{ - wbkgd (window, ch); - if (!panel) { - wrefresh (window); - } + self.window = nil; return self; } -handleEvent: (qwaq_event_t *) event { - switch (event.event_type) { - case qe_mouse: - point.x = event.e.mouse.x; - point.y = event.e.mouse.y; - for (int i = [views count]; i--> 0; ) { - View *v = [views objectAtIndex: i]; - if (rectContainsPoint (&v.absRect, &point)) { - [v handleEvent: event]; - break; - } - } - break; - case qe_key: - case qe_command: - if (focusedView) { - [focusedView handleEvent: event]; - for (int i = [views count]; - event.event_type != qe_none && i--> 0; ) { - View *v = [views objectAtIndex: i]; - [v handleEvent: event]; - } - } - break; - case qe_none: - break; - } return self; } diff --git a/ruamoko/qwaq/qwaq-window.h b/ruamoko/qwaq/qwaq-window.h index 13730ccca..5d777c828 100644 --- a/ruamoko/qwaq/qwaq-window.h +++ b/ruamoko/qwaq/qwaq-window.h @@ -1,11 +1,25 @@ #ifndef __qwaq_window_h #define __qwaq_window_h -#include "qwaq-view.h" +#include "Object.h" -@interface Window: View +@class View; +@class Array; + +#include "qwaq-rect.h" + +@interface Window: Object { + Rect rect; + Point point; // FIXME can't be local :( + Array *views; + View *focusedView; + struct window_s *window; + struct panel_s *panel; } ++windowWithRect: (Rect) rect; +-addView: (View *) view; +-setBackground: (int) ch; @end #endif//__qwaq_window_h diff --git a/ruamoko/qwaq/qwaq-window.r b/ruamoko/qwaq/qwaq-window.r index 48722cdc2..70fe2c476 100644 --- a/ruamoko/qwaq/qwaq-window.r +++ b/ruamoko/qwaq/qwaq-window.r @@ -1,8 +1,71 @@ +#include + +#include "event.h" +#include "qwaq-curses.h" #include "qwaq-window.h" +#include "qwaq-view.h" @implementation Window + +windowWithRect: (Rect) rect { return [[[self alloc] initWithRect: rect] autorelease]; } + +-initWithRect: (Rect) rect +{ + if (!(self = [super init])) { + return nil; + } + self.rect = rect; + window = create_window (rect.xpos, rect.ypos, rect.xlen, rect.ylen); + panel = create_panel (window); + return self; +} + +-handleEvent: (qwaq_event_t *) event +{ + switch (event.event_type) { + case qe_mouse: + point.x = event.e.mouse.x; + point.y = event.e.mouse.y; + for (int i = [views count]; i--> 0; ) { + View *v = [views objectAtIndex: i]; + if (rectContainsPoint (&v.absRect, &point)) { + [v handleEvent: event]; + break; + } + } + break; + case qe_key: + case qe_command: + if (focusedView) { + [focusedView handleEvent: event]; + for (int i = [views count]; + event.event_type != qe_none && i--> 0; ) { + View *v = [views objectAtIndex: i]; + [v handleEvent: event]; + } + } + break; + case qe_none: + break; + } + return self; +} + +-addView: (View *) view +{ + [views addObject: view]; + view.absRect.xpos = view.rect.xpos + rect.xpos; + view.absRect.ypos = view.rect.ypos + rect.ypos; + view.window = window; + return self; +} + +-setBackground: (int) ch +{ + wbkgd (window, ch); + return self; +} @end