2020-03-22 13:03:34 +00:00
|
|
|
#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
|
|
|
|
{
|
2020-03-22 13:42:56 +00:00
|
|
|
[super draw];
|
2020-03-22 13:03:34 +00:00
|
|
|
unsigned lind = base_index;
|
|
|
|
int *lbuf = [linebuffer buffer];
|
|
|
|
for (int y = 0; y < ylen; y++) {
|
2020-03-22 13:42:56 +00:00
|
|
|
lind = [buffer formatLine:lind from:x_index into:lbuf width:xlen
|
2020-03-22 13:03:34 +00:00
|
|
|
highlight:selection colors: {COLOR_PAIR (1), COLOR_PAIR(2)}];
|
|
|
|
[textContext blitFromBuffer: linebuffer to: {xpos, ypos + y}
|
|
|
|
from: [linebuffer rect]];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-22 13:42:56 +00:00
|
|
|
-handleEvent:(qwaq_event_t *) event
|
|
|
|
{
|
|
|
|
if (event.what & qe_mouse) {
|
|
|
|
if (event.what == qe_mouseclick) {
|
|
|
|
if (event.mouse.buttons & (1 << 3)) {
|
|
|
|
[self scrollUp: 1];
|
|
|
|
}
|
|
|
|
if (event.mouse.buttons & (1 << 4)) {
|
|
|
|
[self scrollDown: 1];
|
|
|
|
}
|
|
|
|
if (event.mouse.buttons & (1 << 5)) {
|
|
|
|
[self scrollLeft: 1];
|
|
|
|
}
|
|
|
|
if (event.mouse.buttons & (1 << 6)) {
|
|
|
|
[self scrollRight: 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-scrollUp:(unsigned) count
|
|
|
|
{
|
|
|
|
if (count == 1) {
|
|
|
|
base_index = [buffer prevLine: base_index];
|
|
|
|
} else {
|
|
|
|
base_index = [buffer prevLine: base_index :count];
|
|
|
|
}
|
|
|
|
[self redraw];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-scrollDown:(unsigned) count
|
|
|
|
{
|
|
|
|
if (count == 1) {
|
|
|
|
base_index = [buffer nextLine: base_index];
|
|
|
|
} else {
|
|
|
|
base_index = [buffer nextLine: base_index :count];
|
|
|
|
}
|
|
|
|
[self redraw];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-scrollLeft:(unsigned) count
|
|
|
|
{
|
|
|
|
if (x_index > count) {
|
|
|
|
x_index -= count;
|
|
|
|
} else {
|
|
|
|
x_index = 0;
|
|
|
|
}
|
|
|
|
[self redraw];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-scrollRight:(unsigned) count
|
|
|
|
{
|
|
|
|
if (1024 - x_index > count) {
|
|
|
|
x_index += count;
|
|
|
|
} else {
|
|
|
|
x_index = 1024;
|
|
|
|
}
|
|
|
|
[self redraw];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-22 13:03:34 +00:00
|
|
|
@end
|