mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
[qwaq] Create protocols for DrawBuffer and TextContext
Plenty of flaws at the moment (casts to id :/), but the basic idea seems to be ok.
This commit is contained in:
parent
e5bc6dd8b6
commit
affadc3d25
10 changed files with 36 additions and 36 deletions
|
@ -47,9 +47,7 @@ arp_end (void)
|
|||
r.offset.y = r.extent.height / 4;
|
||||
r.extent.width /= 2;
|
||||
r.extent.height /= 2;
|
||||
Window *w;
|
||||
[objects 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);
|
||||
[objects insert: [[Window windowWithRect: r] setBackground: COLOR_PAIR (2)]];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,20 +5,17 @@
|
|||
|
||||
#include "qwaq-rect.h"
|
||||
|
||||
@interface DrawBuffer : Object
|
||||
{
|
||||
int *buffer;
|
||||
Extent size;
|
||||
Point cursor;
|
||||
}
|
||||
+ (DrawBuffer *) buffer: (Extent) size;
|
||||
- initWithSize: (Extent) size;
|
||||
@class DrawBuffer;
|
||||
|
||||
@protocol DrawBuffer
|
||||
- blitFromBuffer: (DrawBuffer *) srcBuffer to: (Point) pos from: (Rect) rect;
|
||||
- (Rect) rect;
|
||||
- (Extent) size;
|
||||
- (int *) buffer;
|
||||
- (Rect) rect;
|
||||
@end
|
||||
|
||||
- blitFromBuffer: (DrawBuffer *) srcBuffer to: (Point) pos from: (Rect) rect;
|
||||
@protocol TextContext
|
||||
- (Extent) size;
|
||||
|
||||
- (void) printf: (string) fmt, ...;
|
||||
- (void) vprintf: (string) fmt, @va_list args;
|
||||
|
@ -30,4 +27,14 @@
|
|||
- (void) mvaddstr: (Point) pos, string str;
|
||||
@end
|
||||
|
||||
@interface DrawBuffer : Object <DrawBuffer, TextContext>
|
||||
{
|
||||
int *buffer;
|
||||
Extent size;
|
||||
Point cursor;
|
||||
}
|
||||
+ (DrawBuffer *) buffer: (Extent) size;
|
||||
- initWithSize: (Extent) size;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
Rect r = { {}, size };
|
||||
Rect t = { pos, rect.extent };
|
||||
|
||||
wprintf (stdscr, "src: %p\n", srcBuffer);
|
||||
wprintf (stdscr, "srcSize: %d %d\n", srcSize.width, srcSize.height);
|
||||
|
||||
t = clipRect (r, t);
|
||||
if (t.extent.width < 0 || t.extent.height < 0) {
|
||||
return self;
|
||||
|
|
|
@ -31,9 +31,9 @@ typedef BOOL condition_func2 (id object, void *anObject, void *data);
|
|||
{
|
||||
Array *views;
|
||||
int focused;
|
||||
id buffer; //FIXME id<TextContext> or sim
|
||||
id<TextContext> buffer;
|
||||
}
|
||||
-initWithContext: (id) context; //FIXME id<TextContext> or sim
|
||||
-initWithContext: (id<TextContext>) context;
|
||||
-insert: (View *) view;
|
||||
-remove: (View *) view;
|
||||
@end
|
||||
|
|
|
@ -4,14 +4,13 @@
|
|||
|
||||
@implementation Group
|
||||
|
||||
-initWithContext: (id) context
|
||||
-initWithContext: (id<TextContext>) context
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
textContext = context;
|
||||
absRect = rect = { nil, [textContext size] };
|
||||
printf ("\n\nsize:%d %d\n\n", rect.extent.width, rect.extent.height);
|
||||
buffer = [DrawBuffer buffer: rect.extent];
|
||||
views = [[Array array] retain];
|
||||
return self;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
return nil;
|
||||
}
|
||||
textContext = [TextContext screen];
|
||||
[textContext scrollok: 1];
|
||||
[(id)textContext scrollok: 1];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
#ifdef __QFCC__
|
||||
#include <Object.h>
|
||||
#include "qwaq-curses.h"
|
||||
#include "qwaq-draw.h"
|
||||
#include "qwaq-rect.h"
|
||||
|
||||
@class DrawBuffer;
|
||||
|
||||
@interface TextContext : Object
|
||||
@interface TextContext : Object<TextContext>
|
||||
{
|
||||
window_t window;
|
||||
union {
|
||||
|
@ -43,12 +44,6 @@
|
|||
|
||||
- blitFromBuffer: (DrawBuffer *) srcBuffer to: (Point) pos from: (Rect) rect;
|
||||
|
||||
- (void) printf: (string) fmt, ...;
|
||||
- (void) vprintf: (string) mft, @va_list args;
|
||||
- (void) addch: (int) ch;
|
||||
- (void) mvprintf: (Point) pos, string fmt, ...;
|
||||
- (void) mvvprintf: (Point) pos, string mft, @va_list args;
|
||||
- (void) mvaddch: (Point) pos, int ch;
|
||||
- (void) refresh;
|
||||
+ (void) refresh;
|
||||
- (void) bkgd: (int) ch;
|
||||
|
|
|
@ -45,7 +45,7 @@ enum {
|
|||
Rect absRect;
|
||||
Point point; // can't be local :(
|
||||
Group *owner;
|
||||
TextContext *textContext;
|
||||
id<TextContext> textContext;
|
||||
int state;
|
||||
int options;
|
||||
int cursorState;
|
||||
|
@ -65,11 +65,7 @@ enum {
|
|||
- (void) mvaddch: (Point) pos, int ch;
|
||||
@end
|
||||
|
||||
//These are forwarded (FIXME make a protocol)
|
||||
@interface View (TextContext)
|
||||
- (void) printf: (string) fmt, ...;
|
||||
- (void) vprintf: (string) fmt, @va_list args;
|
||||
- (void) addch: (int) ch;
|
||||
@interface View (TextContext) <TextContext>
|
||||
@end
|
||||
|
||||
#endif//__qwaq_view_h
|
||||
|
|
|
@ -102,7 +102,9 @@ updateScreenCursor (View *view)
|
|||
|
||||
- (void) refresh
|
||||
{
|
||||
[textContext refresh];
|
||||
if (__obj_responds_to (textContext, @selector(refresh))) {
|
||||
[(id)textContext refresh];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) mvprintf: (Point) pos, string fmt, ...
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
self.rect = rect;
|
||||
buffer = [[TextContext alloc] initWithRect: rect];
|
||||
textContext = buffer;
|
||||
panel = create_panel ([buffer window]);
|
||||
panel = create_panel ([(id)buffer window]);
|
||||
buf = [DrawBuffer buffer: {3, 3}];
|
||||
[buf mvaddstr: {0, 0}, "XOX"];
|
||||
[buf mvaddstr: {0, 1}, "OXO"];
|
||||
|
@ -74,7 +74,7 @@
|
|||
|
||||
-setBackground: (int) ch
|
||||
{
|
||||
[buffer bkgd: ch];
|
||||
[(id)buffer bkgd: ch];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@
|
|||
}
|
||||
}
|
||||
[super draw];
|
||||
[buffer border: box_sides, box_corners];
|
||||
[(id)buffer border: box_sides, box_corners];
|
||||
Point pos = { 1, 1 };
|
||||
//for (int i = ACS_ULCORNER; i <= ACS_STERLING; i++) {
|
||||
for (int i = 32; i <= 127; i++) {
|
||||
|
@ -112,7 +112,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
[textContext blitFromBuffer: buf to: makePoint (6, 3) from: [buf rect]];
|
||||
[(id)textContext blitFromBuffer: buf to: makePoint (6, 3) from: [buf rect]];
|
||||
[self refresh];
|
||||
return self;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue