[qwaq] Use new TextContext

Not quite right yet, but it worked first try (once I got another
compiler bug sorted).
This commit is contained in:
Bill Currie 2020-03-06 17:25:19 +09:00
parent 9b269c2f8e
commit bea64838cc
9 changed files with 91 additions and 37 deletions

View file

@ -31,7 +31,7 @@ typedef BOOL condition_func2 (id object, void *anObject, void *data);
{
Array *views;
int focused;
struct window_s *window;
TextContext *buffer;
}
-insert: (View *) view;
-remove: (View *) view;

View file

@ -116,7 +116,7 @@ not_dont_draw (id aView, void *aGroup)
Group *group = (Group *) aGroup;
if (!(view.options & ofDontDraw)) {
if (!view.textContext) {
view.textContext = group.window;
view.textContext = group.buffer;
}
return YES;
}

View file

@ -11,8 +11,6 @@
+(Screen *) screen;
-handleEvent: (qwaq_event_t *) event;
-setBackground: (int) ch;
-printf: (string) fmt, ...;
-addch: (int) ch atX: (int) x Y: (int) y;
@end
#endif//__qwaq_screen_h

View file

@ -13,14 +13,8 @@
if (!(self = [super initWithRect:getwrect (stdscr)])) {
return nil;
}
textContext = stdscr;
scrollok (textContext, 1);
return self;
}
-setBackground: (int) ch
{
wbkgd (textContext, ch);
textContext = [TextContext screen];
[textContext scrollok: 1];
return self;
}
@ -36,27 +30,21 @@
-draw
{
update_panels ();
doupdate ();
[TextContext doupdate];
return self;
}
-redraw
{
update_panels ();
wrefresh(textContext);
doupdate ();
[textContext refresh];
[TextContext doupdate];
return self;
}
-printf: (string) fmt, ...
-setBackground: (int) ch
{
wvprintf (textContext, fmt, @args);
return self;
}
-addch: (int) ch atX: (int) x Y: (int) y
{
mvwaddch(textContext, x, y, ch);
[textContext bkgd:ch];
return self;
}

View file

@ -17,16 +17,20 @@
+ (void) move: (Point) pos;
+ (void) curs_set: (int) visibility;
+ (void) doupdate;
+ (TextContext *) screen;
-init;
-initWithRect: (Rect) rect;
-initWithWindow: (window_t) window;
- (void) mvprintf: (Point) pos, string fmt, ...;
-(window_t) window;
- (void) printf: (string) fmt, ...;
- (void) vprintf: (string) mft, @va_list args;
- (void) mvprintf: (Point) pos, string fmt, ...;
- (void) mvvprintf: (Point) pos, string mft, @va_list args;
- (void) refresh;
- (void) mvaddch: (Point) pos, int ch;
- (void) refresh;
- (void) bkgd: (int) ch;
- (void) scrollok: (int) flag;
- (void) border: (box_sides_t) sides, box_corners_t corners;

View file

@ -17,6 +17,15 @@
+ (void) curs_set: (int) visibility = #0;
+ (void) doupdate = #0;
static TextContext *screen;
+ (TextContext *) screen
{
if (!screen) {
screen = [[TextContext alloc] init];
}
return screen;
}
- init
{
if (!(self = [super init])) {
@ -45,6 +54,11 @@
return self;
}
-(window_t) window
{
return window;
}
- (void) mvprintf: (Point) pos, string fmt, ... = #0;
- (void) printf: (string) fmt, ... = #0;
- (void) vprintf: (string) mft, @va_list args = #0;

View file

@ -6,6 +6,7 @@
#include "qwaq-draw.h"
#include "qwaq-rect.h"
#include "qwaq-textcontext.h"
@class Group;
@ -44,7 +45,7 @@ enum {
Rect absRect;
Point point; // can't be local :(
Group *owner;
struct window_s *textContext; //FIXME separate class
TextContext *textContext;
int state;
int options;
int cursorState;
@ -56,6 +57,14 @@ enum {
-(struct Rect_s *)getRect;
-draw;
-redraw;
- (void) refresh;
- (void) printf: (string) fmt, ...;
- (void) vprintf: (string) fmt, @va_list args;
//- (void) addch: (int) ch;
- (void) mvprintf: (Point) pos, string fmt, ...;
- (void) mvvprintf: (Point) pos, string fmt, @va_list args;
- (void) mvaddch: (Point) pos, int ch;
@end
#endif//__qwaq_view_h

View file

@ -105,6 +105,47 @@ updateScreenCursor (View *view)
return ▭
}
- (void) printf: (string) fmt, ...
{
[textContext vprintf: fmt, @args];
}
- (void) vprintf: (string) fmt, @va_list args
{
[textContext vprintf: fmt, args];
}
- (void) refresh
{
[textContext refresh];
}
/*
- (void) addch: (int) ch
{
[textContext addch:ch];
}*/
- (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];
}
@end
Rect getwrect (window_t window) = #0;

View file

@ -18,8 +18,8 @@
return nil;
}
self.rect = rect;
window = create_window (xpos, ypos, xlen, ylen);
panel = create_panel (window);
buffer = [[TextContext alloc] initWithRect: rect];
panel = create_panel ([buffer window]);
return self;
}
@ -69,7 +69,7 @@
-setBackground: (int) ch
{
wbkgd (window, ch);
[buffer bkgd: ch];
return self;
}
@ -90,24 +90,24 @@
}
}
[super draw];
int x = 1, y = 1;
wborder (window, box_sides, box_corners);
[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++) {
int ch = acs_char (i);
if (ch) {
mvwaddch (window, x, y, ch);
[buffer mvaddch: pos, ch];
} else {
mvwaddch (window, x, y, '.');
[buffer mvaddch: pos, '.'];
}
if (++x > 32) {
x = 1;
if (++y >= ylen) {
if (++pos.x > 32) {
pos.x = 1;
if (++pos.y >= ylen) {
break;
}
}
}
wrefresh (window);
[buffer refresh];
return self;
}