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;
|
2020-03-06 08:25:19 +00:00
|
|
|
buffer = [[TextContext alloc] initWithRect: rect];
|
2020-03-06 08:45:58 +00:00
|
|
|
textContext = buffer;
|
2020-03-17 16:39:12 +00:00
|
|
|
panel = create_panel ([(id)buffer window]);
|
2020-03-13 01:00:05 +00:00
|
|
|
buf = [DrawBuffer buffer: {3, 3}];
|
|
|
|
[buf mvaddstr: {0, 0}, "XOX"];
|
|
|
|
[buf mvaddstr: {0, 1}, "OXO"];
|
|
|
|
[buf mvaddstr: {0, 2}, "XOX"];
|
2020-03-01 09:25:02 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-handleEvent: (qwaq_event_t *) event
|
|
|
|
{
|
2020-03-05 06:44:53 +00:00
|
|
|
/* switch (event.what) {
|
2020-03-01 09:25:02 +00:00
|
|
|
case qe_mouse:
|
2020-03-03 12:30:47 +00:00
|
|
|
mvwprintf(window, 0, 3, "%2d %2d %08x",
|
2020-03-04 10:10:09 +00:00
|
|
|
event.mouse.x, event.mouse.y, event.mouse.buttons);
|
2020-03-03 12:30:47 +00:00
|
|
|
[self redraw];
|
2020-03-04 10:10:09 +00:00
|
|
|
point.x = event.mouse.x;
|
|
|
|
point.y = event.mouse.y;
|
2020-03-01 09:25:02 +00:00
|
|
|
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];
|
2020-03-04 13:09:40 +00:00
|
|
|
event.what != qe_none && i--> 0; ) {
|
2020-03-01 09:25:02 +00:00
|
|
|
View *v = [views objectAtIndex: i];
|
|
|
|
[v handleEvent: event];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case qe_none:
|
|
|
|
break;
|
2020-03-05 06:44:53 +00:00
|
|
|
}*/
|
2020-03-01 09:25:02 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-addView: (View *) view
|
|
|
|
{
|
2020-03-05 06:44:53 +00:00
|
|
|
/* [views addObject: view];
|
2020-03-01 09:25:02 +00:00
|
|
|
view.absRect.xpos = view.rect.xpos + rect.xpos;
|
|
|
|
view.absRect.ypos = view.rect.ypos + rect.ypos;
|
|
|
|
view.window = window;
|
2020-03-05 06:44:53 +00:00
|
|
|
[view setOwner: self];*/
|
2020-03-01 09:25:02 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-setBackground: (int) ch
|
|
|
|
{
|
2020-03-17 16:39:12 +00:00
|
|
|
[(id)buffer bkgd: ch];
|
2020-03-01 09:25:02 +00:00
|
|
|
return self;
|
|
|
|
}
|
2020-03-02 06:22:54 +00:00
|
|
|
|
|
|
|
-draw
|
|
|
|
{
|
2020-03-05 15:32:09 +00:00
|
|
|
static box_sides_t box_sides = {
|
|
|
|
ACS_VLINE, ACS_VLINE,
|
|
|
|
ACS_HLINE, ACS_HLINE,
|
|
|
|
};
|
|
|
|
static box_corners_t box_corners = {
|
|
|
|
ACS_ULCORNER, ACS_URCORNER,
|
|
|
|
ACS_LLCORNER, ACS_LRCORNER,
|
|
|
|
};
|
|
|
|
if (box_sides.ls == ACS_VLINE) {
|
|
|
|
int *foo = &box_sides.ls;
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
foo[i] = acs_char (foo[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[super draw];
|
2020-03-17 16:39:12 +00:00
|
|
|
[(id)buffer border: box_sides, box_corners];
|
2020-03-06 08:25:19 +00:00
|
|
|
Point pos = { 1, 1 };
|
2020-03-05 15:32:09 +00:00
|
|
|
//for (int i = ACS_ULCORNER; i <= ACS_STERLING; i++) {
|
|
|
|
for (int i = 32; i <= 127; i++) {
|
2020-03-02 09:29:31 +00:00
|
|
|
int ch = acs_char (i);
|
|
|
|
if (ch) {
|
2020-03-06 08:45:58 +00:00
|
|
|
[self mvaddch: pos, ch];
|
2020-03-02 09:29:31 +00:00
|
|
|
} else {
|
2020-03-06 08:45:58 +00:00
|
|
|
[self mvaddch: pos, '.'];
|
2020-03-02 09:29:31 +00:00
|
|
|
}
|
2020-03-06 08:25:19 +00:00
|
|
|
if (++pos.x > 32) {
|
|
|
|
pos.x = 1;
|
|
|
|
if (++pos.y >= ylen) {
|
2020-03-02 09:29:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 16:39:12 +00:00
|
|
|
[(id)textContext blitFromBuffer: buf to: makePoint (6, 3) from: [buf rect]];
|
2020-03-06 08:45:58 +00:00
|
|
|
[self refresh];
|
2020-03-02 06:22:54 +00:00
|
|
|
return self;
|
|
|
|
}
|
2020-03-03 12:30:47 +00:00
|
|
|
|
|
|
|
-(Rect *) getRect
|
|
|
|
{
|
|
|
|
return ▭
|
|
|
|
}
|
|
|
|
|
2020-03-05 06:44:53 +00:00
|
|
|
-setOwner: owner
|
2020-03-03 12:30:47 +00:00
|
|
|
{
|
2020-03-05 06:44:53 +00:00
|
|
|
self.owner = owner;
|
2020-03-03 12:30:47 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-redraw
|
|
|
|
{
|
2020-03-05 06:44:53 +00:00
|
|
|
return [owner redraw];
|
2020-03-03 12:30:47 +00:00
|
|
|
}
|
2020-03-06 08:46:36 +00:00
|
|
|
|
|
|
|
- (void) mvprintf: (Point) pos, string fmt, ...
|
|
|
|
{
|
|
|
|
[textContext mvvprintf: pos, fmt, @args];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mvvprintf: (Point) pos, string fmt, @va_list args
|
|
|
|
{
|
|
|
|
[textContext mvvprintf: pos, fmt, args];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mvaddch: (Point) pos, int ch
|
|
|
|
{
|
|
|
|
[textContext mvaddch: pos, ch];
|
|
|
|
}
|
2020-02-29 15:40:55 +00:00
|
|
|
@end
|