[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.
This commit is contained in:
Bill Currie 2020-03-19 11:32:44 +09:00
parent b16093a533
commit 2f3ca9d9e4
7 changed files with 57 additions and 29 deletions

View file

@ -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"

View file

@ -1,17 +1,25 @@
#ifndef __qwaq_group_h
#define __qwaq_group_h
#include "qwaq-view.h"
#include <Array.h>
@interface Group : View
#include "event.h"
#include "qwaq-draw.h"
@class View;
@interface Group : Object
{
Array *views;
int focused;
id<TextContext> buffer;
id<TextContext> context;
}
-initWithContext: (id<TextContext>) context;
-insert: (View *) view;
-remove: (View *) view;
-draw;
-redraw;
-handleEvent: (qwaq_event_t *) event;
@end
#endif//__qwaq_group_h

View file

@ -1,7 +1,9 @@
#include <Array.h>
#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];

View file

@ -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<TextContext>) 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;

View file

@ -27,6 +27,17 @@
[super dealloc];
}
- setContext: (id<TextContext>) 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 &rect;
}

View file

@ -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;

View file

@ -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<TextContext>) 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++) {