From 10adb116efd70df7d6d557daa97005c3587eb2dd Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 22 Mar 2020 22:03:34 +0900 Subject: [PATCH] [qwaq] Start working on the source view/editor Line formatting is a bit messed up, but other than non-virtual text being double-counted, things seem to be ok (view only). --- ruamoko/qwaq/Makefile.am | 1 + ruamoko/qwaq/qwaq-app.r | 54 ++++--------------------------- ruamoko/qwaq/qwaq-editbuffer-bi.c | 14 +++++--- ruamoko/qwaq/qwaq-editor.h | 24 ++++++++++++++ ruamoko/qwaq/qwaq-editor.r | 30 +++++++++++++++++ 5 files changed, 71 insertions(+), 52 deletions(-) create mode 100644 ruamoko/qwaq/qwaq-editor.h create mode 100644 ruamoko/qwaq/qwaq-editor.r diff --git a/ruamoko/qwaq/Makefile.am b/ruamoko/qwaq/Makefile.am index 4f8b552e2..3e803509b 100644 --- a/ruamoko/qwaq/Makefile.am +++ b/ruamoko/qwaq/Makefile.am @@ -28,6 +28,7 @@ qwaq_app_dat_src= \ qwaq-button.r \ qwaq-draw.r \ qwaq-editbuffer.r \ + qwaq-editor.r \ qwaq-garray.r \ qwaq-group.r \ qwaq-listener.r \ diff --git a/ruamoko/qwaq/qwaq-app.r b/ruamoko/qwaq/qwaq-app.r index f2834b77e..4ea23f2ae 100644 --- a/ruamoko/qwaq/qwaq-app.r +++ b/ruamoko/qwaq/qwaq-app.r @@ -1,10 +1,13 @@ int fence; + #include +#include #include "color.h" #include "qwaq-app.h" #include "qwaq-button.h" #include "qwaq-curses.h" +#include "qwaq-editor.h" #include "qwaq-group.h" #include "qwaq-listener.h" #include "qwaq-window.h" @@ -47,6 +50,7 @@ arp_end (void) objects = [[Group alloc] initWithContext: screen owner: nil]; [screen bkgd: COLOR_PAIR (1)]; + [screen scrollok: 1]; Rect r = { nil, [screen size] }; r.offset.x = r.extent.width / 4; r.offset.y = r.extent.height / 4; @@ -54,57 +58,11 @@ arp_end (void) r.extent.height /= 2; Window *w; [objects insert: w = [[Window windowWithRect: r] setBackground: COLOR_PAIR (2)]]; - DrawBuffer *released = [DrawBuffer buffer: {12, 1}]; - DrawBuffer *pressed = [DrawBuffer buffer: {12, 1}]; - Button *b = [[Button alloc] initWithPos: {3, 4} releasedIcon: released - pressedIcon: pressed]; - [w addView: b]; - [released bkgd: COLOR_PAIR(3)]; - [released clear]; - [released mvaddstr: {2, 0}, "press me"]; - [pressed bkgd: COLOR_PAIR(4)]; - [pressed clear]; - [pressed mvaddstr: {1, 0}, "release me"]; - [[b onPress] addListener: self : @selector (buttonPressed:)]; - [[b onRelease] addListener: self : @selector (buttonReleased:)]; - [[b onClick] addListener: self : @selector (buttonClick:)]; - [[b onDrag] addListener: self : @selector (buttonDrag:)]; - [[b onAuto] addListener: self : @selector (buttonAuto:)]; + r = {{1, 1}, {r.extent.width - 2, r.extent.height - 2}}; + [w addView: [[Editor alloc] initWithRect: r file: "Makefile"]]; return self; } --(void) buttonPressed: (id) sender -{ - [screen mvaddstr: {2, 0}, " pressed "]; - [screen refresh]; -} - --(void) buttonReleased: (id) sender -{ - [screen mvaddstr: {2, 0}, "released "]; - [screen refresh]; -} - --(void) buttonClick: (id) sender -{ - [screen mvprintf: {2, 1}, "clicked %d", [sender click]]; - [screen refresh]; -} - --(void) buttonDrag: (id) sender -{ - [screen mvaddstr: {2, 0}, "dragged "]; - Point delta = [sender delta]; - [screen mvprintf: {15, 0}, "%3d %3d", delta.x, delta.y]; - [screen refresh]; -} - --(void) buttonAuto: (id) sender -{ - [screen mvprintf: {2, 2}, "%d", autocount++]; - [screen refresh]; -} - -run { [self draw]; diff --git a/ruamoko/qwaq/qwaq-editbuffer-bi.c b/ruamoko/qwaq/qwaq-editbuffer-bi.c index d8ec63969..a7cf25cc5 100644 --- a/ruamoko/qwaq/qwaq-editbuffer-bi.c +++ b/ruamoko/qwaq/qwaq-editbuffer-bi.c @@ -501,20 +501,23 @@ static void bi_i_EditBuffer__init (progs_t *pr) { qwaq_ebresources_t *res = PR_Resources_Find (pr, "qwaq-editbuffer"); + __auto_type self = &P_STRUCT (pr, qwaq_editbuffer_t, 0); txtbuffer_t *txtbuffer = TextBuffer_Create (); editbuffer_t *buffer = editbuffer_new (res); buffer->txtbuffer = txtbuffer; buffer->tabSize = 4; // FIXME - R_INT (pr) = editbuffer_index (res, buffer); + self->buffer = editbuffer_index (res, buffer); + R_INT (pr) = PR_SetPointer (pr, self); } static void bi_i_EditBuffer__initWithFile_ (progs_t *pr) { qwaq_ebresources_t *res = PR_Resources_Find (pr, "qwaq-editbuffer"); - const char *filename = P_GSTRING (pr, 0); + __auto_type self = &P_STRUCT (pr, qwaq_editbuffer_t, 0); + const char *filename = P_GSTRING (pr, 2); txtbuffer_t *txtbuffer = TextBuffer_Create (); editbuffer_t *buffer = editbuffer_new (res); @@ -522,14 +525,17 @@ bi_i_EditBuffer__initWithFile_ (progs_t *pr) buffer->tabSize = 4; // FIXME loadFile (buffer->txtbuffer, filename); - R_INT (pr) = editbuffer_index (res, buffer); + + self->buffer = editbuffer_index (res, buffer); + R_INT (pr) = PR_SetPointer (pr, self); } static void bi_i_EditBuffer__dealloc (progs_t *pr) { qwaq_ebresources_t *res = PR_Resources_Find (pr, "qwaq-editbuffer"); - int buffer_id = P_STRUCT (pr, qwaq_editbuffer_t, 0).buffer; + __auto_type self = &P_STRUCT (pr, qwaq_editbuffer_t, 0); + int buffer_id = self->buffer; editbuffer_t *buffer = get_editbuffer (res, __FUNCTION__, buffer_id); TextBuffer_Destroy (buffer->txtbuffer); diff --git a/ruamoko/qwaq/qwaq-editor.h b/ruamoko/qwaq/qwaq-editor.h new file mode 100644 index 000000000..8a9fd6e06 --- /dev/null +++ b/ruamoko/qwaq/qwaq-editor.h @@ -0,0 +1,24 @@ +#ifndef __qwaq_editor_h +#define __qwaq_editor_h + +#include "qwaq-editbuffer.h" +#include "qwaq-view.h" + +@class EditBuffer; + +@interface Editor : View +{ + EditBuffer *buffer; + DrawBuffer *linebuffer; + eb_sel_t selection; + unsigned base_index; // top left corner + unsigned line_index; // current line + unsigned char_index; // current character + unsigned old_cind; // previous character + Point cursor; + unsigned line_count; +} +-initWithRect:(Rect) rect file:(string) filename; +@end + +#endif//__qwaq_editor_h diff --git a/ruamoko/qwaq/qwaq-editor.r b/ruamoko/qwaq/qwaq-editor.r new file mode 100644 index 000000000..2192ec320 --- /dev/null +++ b/ruamoko/qwaq/qwaq-editor.r @@ -0,0 +1,30 @@ +#include "color.h" +#include "qwaq-editor.h" + +@implementation Editor + +-initWithRect:(Rect) rect file:(string) filename +{ + if (!(self = [super initWithRect: rect])) { + return nil; + } + buffer = [[EditBuffer alloc] initWithFile: filename]; + line_count = [buffer countLines: {0, [buffer textSize]}]; + linebuffer = [DrawBuffer buffer: { xlen, 1 }]; + return self; +} + +-draw +{ + unsigned lind = base_index; + int *lbuf = [linebuffer buffer]; + for (int y = 0; y < ylen; y++) { + lind = [buffer formatLine:lind from:0 into:lbuf width:xlen + highlight:selection colors: {COLOR_PAIR (1), COLOR_PAIR(2)}]; + [textContext blitFromBuffer: linebuffer to: {xpos, ypos + y} + from: [linebuffer rect]]; + } + return self; +} + +@end