2020-02-29 15:40:55 +00:00
|
|
|
#include "qwaq-curses.h"
|
|
|
|
#include "qwaq-view.h"
|
2020-03-05 06:44:53 +00:00
|
|
|
#include "qwaq-group.h"
|
2020-02-29 15:40:55 +00:00
|
|
|
|
|
|
|
@implementation View
|
|
|
|
|
2020-03-05 15:32:09 +00:00
|
|
|
-init
|
|
|
|
{
|
|
|
|
return [super init];
|
|
|
|
}
|
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
-initWithRect: (Rect) rect
|
|
|
|
{
|
|
|
|
if (!(self = [super init])) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
self.rect = rect;
|
|
|
|
self.absRect = rect;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-05 06:44:53 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
if (owner) {
|
|
|
|
[owner remove:self];
|
|
|
|
}
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
updateScreenCursor (View *view)
|
|
|
|
{
|
|
|
|
while ((view.state & sfInFocus) && view.owner) {
|
|
|
|
View *owner = (View *) view.owner;
|
|
|
|
if (view.cursor.x >= 0 && view.cursor.x < view.xlen
|
|
|
|
&& view.cursor.y >= 0 && view.cursor.y < view.ylen) {
|
|
|
|
owner.cursor.x = view.cursor.x + view.xpos;
|
|
|
|
owner.cursor.y = view.cursor.y + view.ypos;
|
|
|
|
owner.cursorState = view.cursorState;
|
|
|
|
} else {
|
|
|
|
owner.cursorState = 0;
|
|
|
|
}
|
|
|
|
view = owner;
|
|
|
|
}
|
|
|
|
if (view.state & sfInFocus) {
|
|
|
|
if (view.cursor.x >= 0 && view.cursor.x < view.xlen
|
|
|
|
&& view.cursor.y >= 0 && view.cursor.y < view.ylen) {
|
|
|
|
curs_set (view.cursorState);
|
|
|
|
move(view.cursor.x, view.cursor.y);
|
|
|
|
} else {
|
|
|
|
curs_set (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 06:22:54 +00:00
|
|
|
-draw
|
2020-02-29 15:40:55 +00:00
|
|
|
{
|
2020-03-05 06:44:53 +00:00
|
|
|
state |= sfDrawn;
|
|
|
|
updateScreenCursor (self);
|
2020-02-29 15:40:55 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-05 06:44:53 +00:00
|
|
|
-hide
|
2020-03-03 12:30:47 +00:00
|
|
|
{
|
2020-03-05 06:44:53 +00:00
|
|
|
if (state & sfDrawn) {
|
|
|
|
state &= ~sfDrawn;
|
|
|
|
updateScreenCursor (self);
|
|
|
|
}
|
2020-03-03 12:30:47 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-redraw
|
|
|
|
{
|
2020-03-05 06:44:53 +00:00
|
|
|
if ((state & sfDrawn) && !(options & ofDontDraw)) {
|
|
|
|
[self draw];
|
|
|
|
[owner redraw];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-setOwner: (Group *) owner
|
|
|
|
{
|
|
|
|
self.owner = owner;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (Rect *) getRect
|
|
|
|
{
|
|
|
|
return ▭
|
2020-03-03 12:30:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 08:25:19 +00:00
|
|
|
- (void) printf: (string) fmt, ...
|
|
|
|
{
|
|
|
|
[textContext vprintf: fmt, @args];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) vprintf: (string) fmt, @va_list args
|
|
|
|
{
|
|
|
|
[textContext vprintf: fmt, args];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) refresh
|
|
|
|
{
|
|
|
|
[textContext refresh];
|
|
|
|
}
|
2020-03-06 08:57:33 +00:00
|
|
|
|
2020-03-06 08:25:19 +00:00
|
|
|
- (void) addch: (int) ch
|
|
|
|
{
|
|
|
|
[textContext addch:ch];
|
2020-03-06 08:57:33 +00:00
|
|
|
}
|
2020-03-06 08:25:19 +00:00
|
|
|
|
|
|
|
- (void) mvprintf: (Point) pos, string fmt, ...
|
|
|
|
{
|
|
|
|
pos.x += xpos;
|
|
|
|
pos.y += ypos;
|
|
|
|
[textContext mvvprintf: pos, fmt, @args];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mvvprintf: (Point) pos, string fmt, @va_list args
|
|
|
|
{
|
|
|
|
pos.x += xpos;
|
|
|
|
pos.y += ypos;
|
|
|
|
[textContext mvvprintf: pos, fmt, args];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mvaddch: (Point) pos, int ch
|
|
|
|
{
|
|
|
|
pos.x += xpos;
|
|
|
|
pos.y += ypos;
|
|
|
|
[textContext mvaddch: pos, ch];
|
|
|
|
}
|
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
Rect getwrect (window_t window) = #0;
|