mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[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).
This commit is contained in:
parent
ee9d3a36ab
commit
10adb116ef
5 changed files with 71 additions and 52 deletions
|
@ -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 \
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
int fence;
|
||||
|
||||
#include <AutoreleasePool.h>
|
||||
#include <key.h>
|
||||
|
||||
#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];
|
||||
|
|
|
@ -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);
|
||||
|
|
24
ruamoko/qwaq/qwaq-editor.h
Normal file
24
ruamoko/qwaq/qwaq-editor.h
Normal file
|
@ -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
|
30
ruamoko/qwaq/qwaq-editor.r
Normal file
30
ruamoko/qwaq/qwaq-editor.r
Normal file
|
@ -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
|
Loading…
Reference in a new issue