2020-03-01 09:25:02 +00:00
|
|
|
#include <Array.h>
|
|
|
|
|
|
|
|
#include "event.h"
|
|
|
|
#include "qwaq-curses.h"
|
2020-02-29 15:40:55 +00:00
|
|
|
#include "qwaq-window.h"
|
2020-03-01 09:25:02 +00:00
|
|
|
#include "qwaq-view.h"
|
2020-02-29 15:40:55 +00:00
|
|
|
|
|
|
|
@implementation Window
|
2020-03-01 09:25:02 +00:00
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
+windowWithRect: (Rect) rect
|
|
|
|
{
|
|
|
|
return [[[self alloc] initWithRect: rect] autorelease];
|
|
|
|
}
|
2020-03-01 09:25:02 +00:00
|
|
|
|
|
|
|
-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;
|
|
|
|
}
|
2020-03-02 06:22:54 +00:00
|
|
|
|
|
|
|
-takeFocus
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-loseFocus
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-draw
|
|
|
|
{
|
2020-03-02 09:29:31 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-02 06:22:54 +00:00
|
|
|
return self;
|
|
|
|
}
|
2020-02-29 15:40:55 +00:00
|
|
|
@end
|