quakeforge/ruamoko/qwaq/qwaq-window.r
Bill Currie d88a091fc6 [qwaq] Use protocols to distinguish object abilities
Well, that took a fair bit more than it should have to get working: had
to implement the protocol support in qfcc and engine-side ruamoko.
2020-03-02 15:22:54 +09:00

86 lines
1.4 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;
}
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;
}
-takeFocus
{
return self;
}
-loseFocus
{
return self;
}
-draw
{
return self;
}
@end