mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-11 15:51:36 +00:00
2f3ca9d9e4
I think I've finally figured out what I want the core hierarchy to be. Right now, it's just the two classes: View and Window (derived from View). Window has a Group, and Group is just a collection of Views that it manages. QwaqApplication is just an object but like a Window, it has a Group of views. View Window has a Group Group contains Views QwaqApplication has a group More work needs to be done on drawing and event handling, but things are working again.
147 lines
2.3 KiB
R
147 lines
2.3 KiB
R
#include "qwaq-curses.h"
|
|
#include "qwaq-view.h"
|
|
#include "qwaq-group.h"
|
|
|
|
@implementation View
|
|
|
|
-init
|
|
{
|
|
return [super init];
|
|
}
|
|
|
|
-initWithRect: (Rect) rect
|
|
{
|
|
if (!(self = [super init])) {
|
|
return nil;
|
|
}
|
|
self.rect = rect;
|
|
self.absRect = rect;
|
|
return self;
|
|
}
|
|
|
|
- (void) dealloc
|
|
{
|
|
if (owner) {
|
|
[owner remove:self];
|
|
}
|
|
[super dealloc];
|
|
}
|
|
|
|
- setContext: (id<TextContext>) context
|
|
{
|
|
textContext = context;
|
|
return self;
|
|
}
|
|
|
|
- (int) options
|
|
{
|
|
return options;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
-draw
|
|
{
|
|
state |= sfDrawn;
|
|
updateScreenCursor (self);
|
|
return self;
|
|
}
|
|
|
|
-hide
|
|
{
|
|
if (state & sfDrawn) {
|
|
state &= ~sfDrawn;
|
|
updateScreenCursor (self);
|
|
}
|
|
return self;
|
|
}
|
|
|
|
-redraw
|
|
{
|
|
if ((state & sfDrawn) && !(options & ofDontDraw)) {
|
|
[self draw];
|
|
[owner redraw];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
-setOwner: (Group *) owner
|
|
{
|
|
self.owner = owner;
|
|
return self;
|
|
}
|
|
|
|
- (Rect *) rect
|
|
{
|
|
return ▭
|
|
}
|
|
|
|
- (void) forward: (SEL) sel : (@va_list) args
|
|
{
|
|
if (!textContext) {
|
|
return;
|
|
}
|
|
if (!__obj_responds_to (textContext, sel)) {
|
|
[self error: "no implementation for %s", sel_get_name (sel)];
|
|
}
|
|
obj_msg_sendv (textContext, sel, args);
|
|
}
|
|
|
|
- (void) refresh
|
|
{
|
|
if (__obj_responds_to (textContext, @selector(refresh))) {
|
|
[(id)textContext refresh];
|
|
}
|
|
}
|
|
|
|
- (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];
|
|
}
|
|
|
|
-handleEvent: (qwaq_event_t *) event
|
|
{
|
|
return self;
|
|
}
|
|
|
|
@end
|