2020-03-01 09:25:02 +00:00
|
|
|
#include <Array.h>
|
2020-03-19 11:31:59 +00:00
|
|
|
#include <string.h>
|
2020-03-01 09:25:02 +00:00
|
|
|
|
|
|
|
#include "event.h"
|
2020-03-19 11:31:59 +00:00
|
|
|
#include "qwaq-button.h"
|
2020-03-01 09:25:02 +00:00
|
|
|
#include "qwaq-curses.h"
|
2020-03-19 02:32:44 +00:00
|
|
|
#include "qwaq-group.h"
|
2020-03-19 11:31:59 +00:00
|
|
|
#include "qwaq-listener.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-19 02:32:44 +00:00
|
|
|
textContext = [[TextContext alloc] initWithRect: rect];
|
|
|
|
panel = create_panel ([(id)textContext window]);
|
|
|
|
|
2020-03-19 07:27:30 +00:00
|
|
|
objects = [[Group alloc] initWithContext: textContext owner: self];
|
|
|
|
|
2020-03-19 11:31:59 +00:00
|
|
|
string titlestr = "drag me";
|
|
|
|
DrawBuffer *title = [DrawBuffer buffer: {xlen, 1}];
|
|
|
|
[title mvaddstr: {(xlen - strlen(titlestr)) / 2, 0}, titlestr];
|
|
|
|
|
|
|
|
Button *b = [[Button alloc] initWithPos: {0, 0} releasedIcon: title
|
|
|
|
pressedIcon: title];
|
|
|
|
[[b onDrag] addListener: self message: @selector(dragWindow:)];
|
|
|
|
[self addView: b];
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:31:59 +00:00
|
|
|
- (void) dragWindow: (Button *) sender
|
|
|
|
{
|
|
|
|
Point delta = [sender delta];
|
|
|
|
xpos += delta.x;
|
|
|
|
ypos += delta.y;
|
|
|
|
move_panel (panel, xpos, ypos);
|
|
|
|
[owner redraw];
|
|
|
|
}
|
|
|
|
|
2020-03-19 02:32:44 +00:00
|
|
|
-setContext: (id<TextContext>) context
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-01 09:25:02 +00:00
|
|
|
-handleEvent: (qwaq_event_t *) event
|
|
|
|
{
|
2020-03-19 07:27:30 +00:00
|
|
|
[objects handleEvent: event];
|
2020-03-01 09:25:02 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-addView: (View *) view
|
|
|
|
{
|
2020-03-19 07:27:30 +00:00
|
|
|
[objects insert: view];
|
2020-03-01 09:25:02 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-setBackground: (int) ch
|
|
|
|
{
|
2020-03-19 02:32:44 +00:00
|
|
|
[(id)textContext 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-19 02:32:44 +00:00
|
|
|
[(id)textContext border: box_sides, box_corners];
|
2020-03-19 07:27:30 +00:00
|
|
|
[objects draw];
|
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
|