quakeforge/ruamoko/qwaq/qwaq-window.r
Bill Currie f3236410d0 [qwaq] Make the event system more informative
Doesn't have timestamps at this stage, but otherwise it reflects the
event system I had in my old text UI which was heavily based on
TurboVision. TV is pretty good (after looking at things a bit closer I
found it wasn't as deep as I thought), and better yet, Borland released
it to the public domain 23 years ago! (wish I'd known that).

Anyway, this commit gets something happening on the screen, even though
the current hierarchy is still a mess.
2020-03-04 22:09:40 +09:00

123 lines
2 KiB
R

#include <Array.h>
#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;
}
views = [[Array array] retain];
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.what) {
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;
}
-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;
[view setParent: self];
return self;
}
-setBackground: (int) ch
{
wbkgd (window, ch);
return self;
}
-takeFocus
{
return self;
}
-loseFocus
{
return self;
}
-draw
{
int x = 0, y = 0;
for (int i = ACS_ULCORNER; i <= ACS_STERLING; i++) {
int ch = acs_char (i);
if (ch) {
mvwaddch (window, x, y, ch);
} else {
mvwaddch (window, x, y, '.');
}
if (++x >= rect.xlen) {
x = 0;
if (++y >= rect.ylen) {
break;
}
}
}
[views makeObjectsPerformSelector: @selector (draw)];
return self;
}
-(Rect *) getRect
{
return &rect;
}
-setParent: parent
{
self.parent = parent;
return self;
}
-redraw
{
return [parent redraw];
}
@end