[qwaq] Get Window working

It even draws a border around itself.
This commit is contained in:
Bill Currie 2020-03-06 00:32:09 +09:00
parent f18e3c3ad7
commit ad4cde15b5
7 changed files with 46 additions and 28 deletions

View file

@ -2,10 +2,11 @@
#define __qwaq_app_h #define __qwaq_app_h
#include "event.h" #include "event.h"
#include "qwaq-group.h"
@class Screen; @class Screen;
@interface QwaqApplication: Object @interface QwaqApplication: Group
{ {
qwaq_event_t event; qwaq_event_t event;
qwaq_command endState; qwaq_command endState;

View file

@ -33,32 +33,28 @@ arp_end (void)
if (!(self = [super init])) { if (!(self = [super init])) {
return nil; return nil;
} }
initialize (); initialize ();
init_pair (1, COLOR_WHITE, COLOR_BLUE); init_pair (1, COLOR_WHITE, COLOR_BLUE);
init_pair (2, COLOR_WHITE, COLOR_BLACK); init_pair (2, COLOR_WHITE, COLOR_BLACK);
screen = [[Screen screen] retain]; screen = [[Screen screen] retain];
[self insert:screen];
[screen setBackground: COLOR_PAIR (1)]; [screen setBackground: COLOR_PAIR (1)];
Rect r = *[screen getRect]; Rect r = *[screen getRect];
[screen printf:"%d %d %d %d\n",
r.offset.x, r.offset.y, r.extent.width, r.extent.height];
r.offset.x = r.extent.width / 4; r.offset.x = r.extent.width / 4;
r.offset.y = r.extent.height / 4; r.offset.y = r.extent.height / 4;
r.extent.width /= 2; r.extent.width /= 2;
r.extent.height /= 2; r.extent.height /= 2;
[screen printf:"%d %d %d %d\n",
r.offset.x, r.offset.y, r.extent.width, r.extent.height];
[screen printf:"%d\n", acs_char(ACS_HLINE)];
[screen addch: acs_char(ACS_HLINE) atX:4 Y:4];
Window *w; Window *w;
//[screen add: w=[[Window windowWithRect: r] setBackground: COLOR_PAIR (2)]]; [self insert: w=[[Window windowWithRect: r] setBackground: COLOR_PAIR (2)]];
//wprintf (w.window, "%d %d %d %d\n", r.offset.x, r.offset.y, r.extent.width, r.ylen); //wprintf (w.window, "%d %d %d %d\n", r.offset.x, r.offset.y, r.extent.width, r.ylen);
[screen redraw];
return self; return self;
} }
-run -run
{ {
[screen draw]; [self draw];
do { do {
arp_start (); arp_start ();

View file

@ -12,6 +12,15 @@
return self; return self;
} }
-initWithRect: (Rect) rect
{
if (!(self = [super initWithRect: rect])) {
return nil;
}
views = [[Array array] retain];
return self;
}
-(void)dealloc -(void)dealloc
{ {
[views release]; [views release];

View file

@ -10,12 +10,11 @@
-init -init
{ {
if (!(self = [super init])) { if (!(self = [super initWithRect:getwrect (stdscr)])) {
return nil; return nil;
} }
window = stdscr; window = stdscr;
scrollok (window, 1); scrollok (window, 1);
rect = getwrect (window);
return self; return self;
} }
@ -28,7 +27,7 @@
-handleEvent: (qwaq_event_t *) event -handleEvent: (qwaq_event_t *) event
{ {
if (event.what & qe_mouse) { if (event.what & qe_mouse) {
[self printf:"%04x %2d %2d %d %08x\r", event.what, event.mouse.x, event.mouse.y, event.mouse.click, event.mouse.buttons]; [self printf:"%04x %2d %2d %d %08x \r", event.what, event.mouse.x, event.mouse.y, event.mouse.click, event.mouse.buttons];
[self redraw]; [self redraw];
} }
return self; return self;
@ -61,13 +60,9 @@
return self; return self;
} }
- (Rect *) getRect
{
return ▭
}
-setOwner: owner -setOwner: owner
{ {
self.owner = owner;
return self; return self;
} }

View file

@ -20,6 +20,11 @@ rectContainsPoint (Rect *rect, Point *point)
@implementation View @implementation View
-init
{
return [super init];
}
-initWithRect: (Rect) rect -initWithRect: (Rect) rect
{ {
if (!(self = [super init])) { if (!(self = [super init])) {

View file

@ -13,13 +13,9 @@
@interface Window: Group @interface Window: Group
{ {
Point point; // FIXME can't be local :( Point point; // FIXME can't be local :(
Array *views;
View *focusedView;
struct window_s *window;
struct panel_s *panel; struct panel_s *panel;
} }
+windowWithRect: (Rect) rect; +windowWithRect: (Rect) rect;
-addView: (View *) view;
-setBackground: (int) ch; -setBackground: (int) ch;
@end @end

View file

@ -17,7 +17,6 @@
if (!(self = [super init])) { if (!(self = [super init])) {
return nil; return nil;
} }
views = [[Array array] retain];
self.rect = rect; self.rect = rect;
window = create_window (xpos, ypos, xlen, ylen); window = create_window (xpos, ypos, xlen, ylen);
panel = create_panel (window); panel = create_panel (window);
@ -76,22 +75,39 @@
-draw -draw
{ {
int x = 0, y = 0; static box_sides_t box_sides = {
for (int i = ACS_ULCORNER; i <= ACS_STERLING; i++) { 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];
int x = 1, y = 1;
wborder (window, box_sides, box_corners);
//for (int i = ACS_ULCORNER; i <= ACS_STERLING; i++) {
for (int i = 32; i <= 127; i++) {
int ch = acs_char (i); int ch = acs_char (i);
if (ch) { if (ch) {
mvwaddch (window, x, y, ch); mvwaddch (window, x, y, ch);
} else { } else {
mvwaddch (window, x, y, '.'); mvwaddch (window, x, y, '.');
} }
if (++x >= xlen) { if (++x > 32) {
x = 0; x = 1;
if (++y >= ylen) { if (++y >= ylen) {
break; break;
} }
} }
} }
[views makeObjectsPerformSelector: @selector (draw)]; wrefresh (window);
return self; return self;
} }