[qwaq] Clean things up in prep for button testing

This commit is contained in:
Bill Currie 2020-03-19 16:27:30 +09:00
parent 23e6b49845
commit 19161ea80a
6 changed files with 38 additions and 66 deletions

View file

@ -40,7 +40,7 @@ arp_end (void)
init_pair (2, COLOR_WHITE, COLOR_BLACK); init_pair (2, COLOR_WHITE, COLOR_BLACK);
TextContext *screen = [TextContext screen]; TextContext *screen = [TextContext screen];
objects = [[Group alloc] initWithContext: screen]; objects = [[Group alloc] initWithContext: screen owner: nil];
[screen bkgd: COLOR_PAIR (1)]; [screen bkgd: COLOR_PAIR (1)];
Rect r = { nil, [screen size] }; Rect r = { nil, [screen size] };

View file

@ -10,18 +10,21 @@
@interface Group : Object @interface Group : Object
{ {
View *owner;
Array *views; Array *views;
View *mouse_grabbed; View *mouse_grabbed;
View *mouse_within; View *mouse_within;
int focused; int focused;
id<TextContext> context; id<TextContext> context;
} }
-initWithContext: (id<TextContext>) context; -initWithContext: (id<TextContext>) context owner: (View *) owner;
-insert: (View *) view; -insert: (View *) view;
-remove: (View *) view; -remove: (View *) view;
-draw; -draw;
-redraw; -redraw;
-handleEvent: (qwaq_event_t *) event; -handleEvent: (qwaq_event_t *) event;
-(void) grabMouse;
-(void) releaseMouse;
@end @end
#endif//__qwaq_group_h #endif//__qwaq_group_h

View file

@ -7,12 +7,14 @@
@implementation Group @implementation Group
-initWithContext: (id<TextContext>) context -initWithContext: (id<TextContext>) context owner: (View *) owner
{ {
if (!(self = [super init])) { if (!(self = [super init])) {
return nil; return nil;
} }
self.owner = owner;
self.context = context; self.context = context;
focused = -1;
views = [[Array array] retain]; views = [[Array array] retain];
return self; return self;
} }
@ -108,4 +110,17 @@ find_mouse_view(Group *group, Point pos)
} }
return self; return self;
} }
-(void) grabMouse
{
mouse_grabbed = mouse_within;
[owner grabMouse];
}
-(void) releaseMouse
{
mouse_grabbed = mouse_within;
[owner grabMouse];
}
@end @end

View file

@ -63,6 +63,8 @@ enum {
-(Rect)rect; -(Rect)rect;
-(int) containsPoint: (Point) point; -(int) containsPoint: (Point) point;
-(void) grabMouse;
-(void) releaseMouse;
-(int) options; -(int) options;

View file

@ -105,6 +105,16 @@ updateScreenCursor (View *view)
return rectContainsPoint (rect, point); return rectContainsPoint (rect, point);
} }
-(void) grabMouse
{
[owner grabMouse];
}
-(void) releaseMouse
{
[owner releaseMouse];
}
- (void) forward: (SEL) sel : (@va_list) args - (void) forward: (SEL) sel : (@va_list) args
{ {
if (!textContext) { if (!textContext) {

View file

@ -22,6 +22,8 @@
textContext = [[TextContext alloc] initWithRect: rect]; textContext = [[TextContext alloc] initWithRect: rect];
panel = create_panel ([(id)textContext window]); panel = create_panel ([(id)textContext window]);
objects = [[Group alloc] initWithContext: textContext owner: self];
buf = [DrawBuffer buffer: {3, 3}]; buf = [DrawBuffer buffer: {3, 3}];
[buf mvaddstr: {0, 0}, "XOX"]; [buf mvaddstr: {0, 0}, "XOX"];
[buf mvaddstr: {0, 1}, "OXO"]; [buf mvaddstr: {0, 1}, "OXO"];
@ -36,45 +38,13 @@
-handleEvent: (qwaq_event_t *) event -handleEvent: (qwaq_event_t *) event
{ {
/* switch (event.what) { [objects handleEvent: event];
case qe_mouse:
mvwprintf(window, 0, 3, "%2d %2d %08x",
event.mouse.x, event.mouse.y, event.mouse.buttons);
[self redraw];
point.x = event.mouse.x;
point.y = event.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.what != qe_none && i--> 0; ) {
View *v = [views objectAtIndex: i];
[v handleEvent: event];
}
}
break;
case qe_none:
break;
}*/
return self; return self;
} }
-addView: (View *) view -addView: (View *) view
{ {
/* [views addObject: view]; [objects insert: view];
view.absRect.xpos = view.rect.xpos + rect.xpos;
view.absRect.ypos = view.rect.ypos + rect.ypos;
view.window = window;
[view setOwner: self];*/
return self; return self;
} }
@ -102,35 +72,7 @@
} }
[super draw]; [super draw];
[(id)textContext border: box_sides, box_corners]; [(id)textContext border: box_sides, box_corners];
Point pos = { 1, 1 }; [objects draw];
//for (int i = ACS_ULCORNER; i <= ACS_STERLING; i++) {
for (int i = 32; i <= 127; i++) {
int ch = acs_char (i);
if (ch) {
[self mvaddch: pos, ch];
} else {
[self mvaddch: pos, '.'];
}
if (++pos.x > 32) {
pos.x = 1;
if (++pos.y >= ylen) {
break;
}
}
}
[textContext blitFromBuffer: buf to: makePoint (6, 3) from: [buf rect]];
[self refresh];
return self;
}
-(Rect *) getRect
{
return &rect;
}
-setOwner: owner
{
self.owner = owner;
return self; return self;
} }