mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
[qwaq] Flatten the hierarchy and do some cleanup
This commit is contained in:
parent
80d9401eee
commit
92cb3a5285
10 changed files with 172 additions and 111 deletions
|
@ -57,7 +57,7 @@ qwaq_x11_DEPENDENCIES= $(qwaq_x11_libs) $(QWAQ_DEPS)
|
|||
|
||||
r_depfiles_remade=
|
||||
|
||||
qwaq_app_dat_SOURCES=qwaq-app.r qwaq-view.r qwaq-window.r
|
||||
qwaq_app_dat_SOURCES=qwaq-app.r qwaq-screen.r qwaq-window.r qwaq-view.r
|
||||
qwaq_app_obj=$(qwaq_app_dat_SOURCES:.r=.o)
|
||||
qwaq_app_dep=$(addprefix ./$(DEPDIR)/,$(qwaq_app_obj:.o=.Qo))
|
||||
qwaq-app.dat$(EXEEXT): $(qwaq_app_obj) $(QFCC_DEP)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#ifndef __qwaq_app_h
|
||||
#define __qwaq_app_h
|
||||
|
||||
#include "qwaq-view.h"
|
||||
|
||||
#include "event.h"
|
||||
|
||||
@class Screen;
|
||||
|
||||
@interface QwaqApplication: Object
|
||||
{
|
||||
qwaq_event_t event;
|
||||
qwaq_command endState;
|
||||
View *view;
|
||||
Screen *screen;
|
||||
}
|
||||
-run;
|
||||
-handleEvent: (qwaq_event_t *) event;
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "qwaq-app.h"
|
||||
#include "qwaq-curses.h"
|
||||
#include "qwaq-window.h"
|
||||
#include "qwaq-screen.h"
|
||||
#include "qwaq-view.h"
|
||||
|
||||
static AutoreleasePool *autorelease_pool;
|
||||
static void
|
||||
|
@ -33,18 +35,18 @@ arp_end (void)
|
|||
initialize ();
|
||||
init_pair (1, COLOR_WHITE, COLOR_BLUE);
|
||||
init_pair (2, COLOR_WHITE, COLOR_BLACK);
|
||||
view = [[View viewFromWindow:stdscr] retain];
|
||||
[view setBackground: COLOR_PAIR (1)];
|
||||
Rect r = view.rect;
|
||||
wprintf (view.window, "%d %d %d %d\n", r.xpos, r.ypos, r.xlen, r.ylen);
|
||||
screen = [[Screen screen] retain];
|
||||
[screen setBackground: COLOR_PAIR (1)];
|
||||
Rect r = screen.rect;
|
||||
wprintf (screen.window, "%d %d %d %d\n", r.xpos, r.ypos, r.xlen, r.ylen);
|
||||
r.xpos = r.xlen / 4;
|
||||
r.ypos = r.ylen / 4;
|
||||
r.xlen /= 2;
|
||||
r.ylen /= 2;
|
||||
wprintf (view.window, "%d %d %d %d\n", r.xpos, r.ypos, r.xlen, r.ylen);
|
||||
wrefresh(view.window);
|
||||
wprintf (screen.window, "%d %d %d %d\n", r.xpos, r.ypos, r.xlen, r.ylen);
|
||||
wrefresh(screen.window);
|
||||
Window *w;
|
||||
[view addView: w=[[Window windowWithRect: r] setBackground: COLOR_PAIR (2)]];
|
||||
[screen add: w=[[Window windowWithRect: r] setBackground: COLOR_PAIR (2)]];
|
||||
wprintf (w.window, "%d %d %d %d\n", r.xpos, r.ypos, r.xlen, r.ylen);
|
||||
return self;
|
||||
}
|
||||
|
@ -68,7 +70,7 @@ arp_end (void)
|
|||
|
||||
-handleEvent: (qwaq_event_t *) event
|
||||
{
|
||||
[view handleEvent: event];
|
||||
[screen handleEvent: event];
|
||||
if (event.event_type == qe_key && event.e.key == '\x18') {
|
||||
event.event_type = qe_command;
|
||||
event.e.message.command = qc_exit;
|
||||
|
|
21
ruamoko/qwaq/qwaq-rect.h
Normal file
21
ruamoko/qwaq/qwaq-rect.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef __qwaq_rect_h
|
||||
#define __qwaq_rect_h
|
||||
|
||||
typedef struct {
|
||||
int xpos;
|
||||
int ypos;
|
||||
int xlen;
|
||||
int ylen;
|
||||
} Rect;
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
} Point;
|
||||
|
||||
@extern Rect makeRect (int xpos, int ypos, int xlen, int ylen);
|
||||
//XXX will not work if point or rect point to a local variabl
|
||||
@extern int rectContainsPoint (Rect *rect, Point *point);
|
||||
@extern Rect getwrect (struct window_s *window);
|
||||
|
||||
#endif//__qwaq_rect_h
|
22
ruamoko/qwaq/qwaq-screen.h
Normal file
22
ruamoko/qwaq/qwaq-screen.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef __qwaq_screen_h
|
||||
#define __qwaq_screen_h
|
||||
|
||||
#include <Object.h>
|
||||
|
||||
#include "qwaq-rect.h"
|
||||
@class View;
|
||||
@class Array;
|
||||
|
||||
@interface Screen: Object
|
||||
{
|
||||
Rect rect;
|
||||
Array *views;
|
||||
View *focusedView;
|
||||
struct window_s *window;
|
||||
}
|
||||
+(Screen *) screen;
|
||||
-add: obj;
|
||||
-setBackground: (int) ch;
|
||||
@end
|
||||
|
||||
#endif//__qwaq_screen_h
|
32
ruamoko/qwaq/qwaq-screen.r
Normal file
32
ruamoko/qwaq/qwaq-screen.r
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "qwaq-curses.h"
|
||||
#include "qwaq-screen.h"
|
||||
|
||||
@implementation Screen
|
||||
+(Screen *) screen
|
||||
{
|
||||
return [[[self alloc] init] autorelease];
|
||||
}
|
||||
|
||||
-init
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
window = stdscr;
|
||||
rect = getwrect (window);
|
||||
return self;
|
||||
}
|
||||
|
||||
-add: obj
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
-setBackground: (int) ch
|
||||
{
|
||||
wbkgd (window, ch);
|
||||
wrefresh (window);
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
|
@ -4,41 +4,17 @@
|
|||
#include <Array.h>
|
||||
#include <Object.h>
|
||||
|
||||
#include "event.h"
|
||||
#include "qwaq-curses.h"
|
||||
|
||||
typedef struct {
|
||||
int xpos;
|
||||
int ypos;
|
||||
int xlen;
|
||||
int ylen;
|
||||
} Rect;
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
} Point;
|
||||
|
||||
@extern Rect makeRect (int xpos, int ypos, int xlen, int ylen);
|
||||
//XXX will not work if point or rect point to a local variabl
|
||||
@extern int rectContainsPoint (Rect *rect, Point *point);
|
||||
@extern Rect getwrect (window_t window);
|
||||
#include "qwaq-rect.h"
|
||||
|
||||
@interface View: Object
|
||||
{
|
||||
Rect rect;
|
||||
Rect absRect;
|
||||
Array *views;
|
||||
Point point; // can't be local :(
|
||||
View *focusedView;
|
||||
window_t window;
|
||||
panel_t panel;
|
||||
struct window_s *window;
|
||||
}
|
||||
+viewFromWindow: (window_t) window;
|
||||
-initWithRect: (Rect) rect;
|
||||
-handleEvent: (qwaq_event_t *) event;
|
||||
-addView: (View *) view;
|
||||
-setBackground: (int) ch;
|
||||
-handleEvent: (struct qwaq_event_s *) event;
|
||||
@end
|
||||
|
||||
#endif//__qwaq_view_h
|
||||
|
|
|
@ -17,11 +17,6 @@ rectContainsPoint (Rect *rect, Point *point)
|
|||
|
||||
@implementation View
|
||||
|
||||
+viewFromWindow: (window_t) window
|
||||
{
|
||||
return [[[self alloc] initFromWindow: window] autorelease];
|
||||
}
|
||||
|
||||
-initWithRect: (Rect) rect
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
|
@ -29,76 +24,12 @@ rectContainsPoint (Rect *rect, Point *point)
|
|||
}
|
||||
self.rect = rect;
|
||||
self.absRect = rect;
|
||||
self.window = create_window (rect.xpos, rect.ypos, rect.xlen, rect.ylen);
|
||||
self.panel = create_panel (self.window);
|
||||
return self;
|
||||
}
|
||||
|
||||
-initFromWindow: (window_t) window
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
rect = getwrect (window);
|
||||
self.window = window;
|
||||
self.panel = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
-initWithPanel: (panel_t) panel
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
self.panel = panel;
|
||||
self.window = panel_window (panel);
|
||||
rect = getwrect (window);
|
||||
return self;
|
||||
}
|
||||
|
||||
-addView: (View *) view
|
||||
{
|
||||
[views addObject: view];
|
||||
return self;
|
||||
}
|
||||
|
||||
-setBackground: (int) ch
|
||||
{
|
||||
wbkgd (window, ch);
|
||||
if (!panel) {
|
||||
wrefresh (window);
|
||||
}
|
||||
self.window = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
-handleEvent: (qwaq_event_t *) event
|
||||
{
|
||||
switch (event.event_type) {
|
||||
case qe_mouse:
|
||||
point.x = event.e.mouse.x;
|
||||
point.y = event.e.mouse.y;
|
||||
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];
|
||||
event.event_type != qe_none && i--> 0; ) {
|
||||
View *v = [views objectAtIndex: i];
|
||||
[v handleEvent: event];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case qe_none:
|
||||
break;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
#ifndef __qwaq_window_h
|
||||
#define __qwaq_window_h
|
||||
|
||||
#include "qwaq-view.h"
|
||||
#include "Object.h"
|
||||
|
||||
@interface Window: View
|
||||
@class View;
|
||||
@class Array;
|
||||
|
||||
#include "qwaq-rect.h"
|
||||
|
||||
@interface Window: Object
|
||||
{
|
||||
Rect rect;
|
||||
Point point; // FIXME can't be local :(
|
||||
Array *views;
|
||||
View *focusedView;
|
||||
struct window_s *window;
|
||||
struct panel_s *panel;
|
||||
}
|
||||
+windowWithRect: (Rect) rect;
|
||||
-addView: (View *) view;
|
||||
-setBackground: (int) ch;
|
||||
@end
|
||||
|
||||
#endif//__qwaq_window_h
|
||||
|
|
|
@ -1,8 +1,71 @@
|
|||
#include <Array.h>
|
||||
|
||||
#include "event.h"
|
||||
#include "qwaq-curses.h"
|
||||
#include "qwaq-window.h"
|
||||
#include "qwaq-view.h"
|
||||
|
||||
@implementation Window
|
||||
|
||||
+windowWithRect: (Rect) rect
|
||||
{
|
||||
return [[[self alloc] initWithRect: rect] autorelease];
|
||||
}
|
||||
|
||||
-initWithRect: (Rect) rect
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
self.rect = rect;
|
||||
window = create_window (rect.xpos, rect.ypos, rect.xlen, rect.ylen);
|
||||
panel = create_panel (window);
|
||||
return self;
|
||||
}
|
||||
|
||||
-handleEvent: (qwaq_event_t *) event
|
||||
{
|
||||
switch (event.event_type) {
|
||||
case qe_mouse:
|
||||
point.x = event.e.mouse.x;
|
||||
point.y = event.e.mouse.y;
|
||||
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];
|
||||
event.event_type != qe_none && i--> 0; ) {
|
||||
View *v = [views objectAtIndex: i];
|
||||
[v handleEvent: event];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case qe_none:
|
||||
break;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-addView: (View *) view
|
||||
{
|
||||
[views addObject: view];
|
||||
view.absRect.xpos = view.rect.xpos + rect.xpos;
|
||||
view.absRect.ypos = view.rect.ypos + rect.ypos;
|
||||
view.window = window;
|
||||
return self;
|
||||
}
|
||||
|
||||
-setBackground: (int) ch
|
||||
{
|
||||
wbkgd (window, ch);
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue