Quark v0.3: generate buffer only for visible items, handle selection on key move, bugfixes

git-svn-id: svn://kolibrios.org@7924 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-05-15 22:00:20 +00:00
parent 2c7085e0ae
commit 67dc3cd6fc
6 changed files with 75 additions and 75 deletions

View File

@ -126,12 +126,17 @@ struct llist
:int llist::ProcessKey(dword key) :int llist::ProcessKey(dword key)
{ {
if (horisontal_selelection) switch(key) if (horisontal_selelection) {
{ if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) switch(key) {
case SCAN_CODE_LEFT: return KeyLeft(); case SCAN_CODE_HOME: KeyHome(); break;
case SCAN_CODE_RIGHT: return KeyRight(); case SCAN_CODE_END: KeyEnd();
case SCAN_CODE_HOME: return KeyHomeHor(); }
case SCAN_CODE_END: return KeyEndHor(); switch(key) {
case SCAN_CODE_LEFT: return KeyLeft();
case SCAN_CODE_RIGHT: return KeyRight();
case SCAN_CODE_HOME: return KeyHomeHor();
case SCAN_CODE_END: return KeyEndHor();
}
} }
switch(key) switch(key)
{ {

View File

@ -9,11 +9,11 @@ char short_app_name[] = "Quark";
#ifdef LANG_RUS #ifdef LANG_RUS
char intro[] = "<EFBFBD>â® ¯à®á⮩ ¯à®á¬®âà騪 ⥪áâ . char intro[] = "<EFBFBD>â® ¯à®á⮩ ¯à®á¬®âà騪 ⥪áâ .
<EFBFBD>®¯à®¡ã©â¥ ®âªàëâì ª ª®©-­¨¡ã¤ì ⥪áâ®¢ë© ä ©«."; <EFBFBD>®¯à®¡ã©â¥ ®âªàëâì ⥪áâ®¢ë© ä ©«.";
char copied_chars[] = "‘ª®¯¨à®¢ ­® ᨢ®«®¢: %i"; char copied_chars[] = "‘ª®¯¨à®¢ ­® ᨢ®«®¢: %i";
char about[] = "Quark Text v0.2 char about[] = "Quark Text v0.4
¢â®à: Š¨à¨«« ¨¯ â®¢ aka Leency ¢â®à: Š¨à¨«« ¨¯ â®¢ aka Leency
 ©â: http://aspero.pro  ©â: http://aspero.pro
@ -44,12 +44,12 @@ char rmb_menu[] =
#else #else
char intro[] = "Quark will be a nice Code Editor one day. char intro[] = "Quark is a simple text viewer.
Try to open some text file."; Try to open some text file.";
char copied_chars[] = "Copied %i chars"; char copied_chars[] = "Copied %i chars";
char about[] = "Quark Text v0.2 char about[] = "Quark Text v0.4
Author: Kiril Lipatov aka Leency Author: Kiril Lipatov aka Leency
Website: http://aspero.pro Website: http://aspero.pro

View File

@ -2,19 +2,13 @@
void ParseAndPaint() void ParseAndPaint()
{ {
//search.clear(); //search.clear();
list.KeyHome();
list.count=0; list.count=0;
selection.cancel();
Parse(); Parse();
list.visible = list.h / list.item_h; list.visible = list.h / list.item_h;
if (list.count < list.visible) { DrawBuf.Init(list.x, list.y, list.w, list.visible+1*list.item_h);
DrawBuf.bufh = list.visible;
} else {
DrawBuf.bufh = list.count;
}
DrawBuf.Init(list.x, list.y, list.w, DrawBuf.bufh+1*list.item_h);
DrawPage(); DrawPage();
} }
@ -28,7 +22,6 @@ dword buflen = strlen(io.buffer_data) + io.buffer_data;
lines.drop(); lines.drop();
lines.add(io.buffer_data); lines.add(io.buffer_data);
selection.cancel();
for (off = io.buffer_data; off < buflen; off++) for (off = io.buffer_data; off < buflen; off++)
{ {
@ -54,33 +47,33 @@ dword buflen = strlen(io.buffer_data) + io.buffer_data;
void PaintVisible() void PaintVisible()
{ {
int i; int i;
dword y; dword ydraw, absolute_y;
dword line_bg; dword line_bg;
bool swapped = false; bool swapped_selection = false;
list.column_max = lines.get(list.cur_y+1) - lines.get(list.cur_y); list.column_max = lines.get(list.cur_y+1) - lines.get(list.cur_y);
list.CheckDoesValuesOkey(); list.CheckDoesValuesOkey();
if (selection.end_offset < selection.start_offset) { if (selection.end_offset < selection.start_offset) {
swapped = selection.swap_start_end(); swapped_selection = selection.swap_start_end();
} }
for ( i=list.first; i < list.first+list.visible+1; i++) for ( i=0; i < list.visible+1; i++)
{ {
y = i * list.item_h; ydraw = i * list.item_h;
absolute_y = i + list.first;
line_bg = theme.bg; line_bg = theme.bg;
if (selection.start_y < i) && (selection.end_y > i) line_bg = selection.color; if (selection.start_y < absolute_y) && (selection.end_y > absolute_y) line_bg = selection.color;
DrawBuf.DrawBar(0, y, list.w, list.item_h, line_bg); DrawBuf.DrawBar(0, ydraw, list.w, list.item_h, line_bg);
selection.draw(i); selection.draw(absolute_y);
if (i<list.count) DrawBuf.WriteText(3, y+3, list.font_type, theme.text, if (absolute_y<list.count) DrawBuf.WriteText(3, ydraw+3, list.font_type, theme.text,
lines.get(i), lines.get(i+1) - lines.get(i)); lines.get(absolute_y), lines.get(absolute_y+1) - lines.get(absolute_y));
} }
PutPaletteImage(list.first * DrawBuf.bufw * list.item_h * 4 + buf_data+8, PutPaletteImage(buf_data+8, DrawBuf.bufw, list.h, list.x, list.y, 32, 0);
DrawBuf.bufw, list.h, list.x, list.y, 32, 0);
if (swapped) selection.swap_start_end(); if (swapped_selection) selection.swap_start_end();
} }

View File

@ -4,7 +4,7 @@
Licence: GPLv2 Licence: GPLv2
The core components of this app are: The core components of this app are:
1. list: text grid with keyboard and mouse proceed 1. list: text grid with keyboard and mouse events
2. lines: the mas of pointers for each line start 2. lines: the mas of pointers for each line start
3. selection 3. selection
*/ */
@ -85,7 +85,8 @@ enum {
COLOR_SCHEME=8, COLOR_SCHEME=8,
RMB_MENU, RMB_MENU,
BTN_FIND_NEXT, BTN_FIND_NEXT,
BTN_FIND_CLOSE BTN_FIND_CLOSE,
BTN_CHANGE_CHARSET
}; };
dword menu_id; dword menu_id;
@ -114,14 +115,12 @@ void LoadFileFromDocPack()
{ {
dword bufsize = atoi(#param + 1) + 20; dword bufsize = atoi(#param + 1) + 20;
dword bufpointer = malloc(bufsize); dword bufpointer = malloc(bufsize);
dword filesize;
ESDWORD[bufpointer+0] = 0; ESDWORD[bufpointer+0] = 0;
ESDWORD[bufpointer+4] = 8; ESDWORD[bufpointer+4] = 8;
IpcSetArea(bufpointer, bufsize); IpcSetArea(bufpointer, bufsize);
SetEventMask(EVM_IPC);
SetEventMask(EVM_IPC);
if (@WaitEventTimeout(200) != evIPC) { if (@WaitEventTimeout(200) != evIPC) {
notify("'IPC FAIL'E"); notify("'IPC FAIL'E");
return; return;
@ -190,6 +189,9 @@ void HandleButtonEvent()
case BTN_FIND_CLOSE: case BTN_FIND_CLOSE:
search.hide(); search.hide();
break; break;
case BTN_CHANGE_CHARSET:
EventShowCharsetsList();
break;
} }
} }
@ -228,17 +230,6 @@ void HandleKeyEvent()
case SCAN_CODE_KEY_F: case SCAN_CODE_KEY_F:
search.show(); search.show();
return; return;
case SCAN_CODE_HOME:
list.KeyHome();
list.KeyHomeHor();
DrawPage();
return;
case SCAN_CODE_END:
list.KeyEnd();
list.column_max = strlen(lines.get(list.cur_y));
list.KeyEndHor();
DrawPage();
return;
case SCAN_CODE_KEY_A: case SCAN_CODE_KEY_A:
selection.select_all(); selection.select_all();
DrawPage(); DrawPage();
@ -261,11 +252,16 @@ void HandleKeyEvent()
} }
if (search.edit_key()) { if (search.edit_key()) {
return; return;
} else if (list.ProcessKey(key_scancode)) { } else {
DrawPage(); if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_start();
else selection.cancel();
if (list.ProcessKey(key_scancode)) {
if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_end();
DrawPage();
}
return; return;
} }
EventInsertCharIntoText(); //EventInsertCharIntoText();
} }
void HandleMouseEvent() void HandleMouseEvent()
@ -281,7 +277,7 @@ void HandleMouseEvent()
GetKeyModifier(); GetKeyModifier();
if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) { if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
if (mouse.down) && (!selection.is_active()) selection.set_start(); if (mouse.down) selection.set_start();
list.ProcessMouse(mouse.x, mouse.y); list.ProcessMouse(mouse.x, mouse.y);
if (mouse.up) selection.set_end(); if (mouse.up) selection.set_end();
DrawPage(); DrawPage();
@ -290,6 +286,7 @@ void HandleMouseEvent()
list.ProcessMouse(mouse.x, mouse.y); list.ProcessMouse(mouse.x, mouse.y);
if (mouse.down) { if (mouse.down) {
selection.cancel();
selection.set_start(); selection.set_start();
} }
selection.set_end(); selection.set_end();
@ -386,15 +383,15 @@ void EventShowCharsetsList()
void EventShowReopenMenu() void EventShowReopenMenu()
{ {
menu_id = REOPEN_IN_APP; menu_id = REOPEN_IN_APP;
open_lmenu(Form.left+5 + reopenin_mx, Form.top+29+skin_height, open_lmenu(Form.left+5 + reopenin_mx + 23, Form.top+29+skin_height,
MENU_ALIGN_TOP_LEFT, NULL, MENU_ALIGN_TOP_RIGHT, NULL,
"Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther"); "Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther");
} }
void EventShowThemesList() void EventShowThemesList()
{ {
menu_id = COLOR_SCHEME; menu_id = COLOR_SCHEME;
open_lmenu(Form.left+2 + theme_mx + 26, open_lmenu(Form.left+5 + theme_mx + 23,
Form.top+29+skin_height, MENU_ALIGN_TOP_RIGHT, Form.top+29+skin_height, MENU_ALIGN_TOP_RIGHT,
curcol_scheme+1, #color_scheme_names); curcol_scheme+1, #color_scheme_names);
} }
@ -646,17 +643,15 @@ void DrawToolbar()
AddTopBarButton(#EventOpenDialog, ECTRL+SCAN_CODE_KEY_O, 0, x.set(8), false); AddTopBarButton(#EventOpenDialog, ECTRL+SCAN_CODE_KEY_O, 0, x.set(8), false);
//AddTopBarButton(#EventSave, ECTRL+SCAN_CODE_KEY_S, 5, x.inc(SMALL_GAP), false); //AddTopBarButton(#EventSave, ECTRL+SCAN_CODE_KEY_S, 5, x.inc(SMALL_GAP), false);
AddTopBarButton(#EventShowFileInfo, ECTRL+SCAN_CODE_KEY_I, 10, x.inc(SMALL_GAP), false); AddTopBarButton(#EventShowFileInfo, ECTRL+SCAN_CODE_KEY_I, 10, x.inc(SMALL_GAP), false);
AddTopBarButton(#EventMagnifyMinus, ECTRL+SCAN_CODE_MINUS, 32, x.inc(BIG_GAP), false); AddTopBarButton(#EventMagnifyMinus, ECTRL+SCAN_CODE_MINUS, 33, x.inc(BIG_GAP), false);
AddTopBarButton(#EventMagnifyPlus, ECTRL+SCAN_CODE_PLUS, 33, x.inc(SMALL_GAP), false); AddTopBarButton(#EventMagnifyPlus, ECTRL+SCAN_CODE_PLUS, 32, x.inc(SMALL_GAP), false);
AddTopBarButton(#EventClickSearch, ECTRL+SCAN_CODE_KEY_F, 49, x.inc(BIG_GAP), serha); search_mx = EAX; AddTopBarButton(#EventClickSearch, ECTRL+SCAN_CODE_KEY_F, 49, x.inc(BIG_GAP), serha); search_mx = EAX;
x.set(Form.cwidth-4); x.set(Form.cwidth-4);
AddTopBarButton(#EventShowInfo, NULL, -1, x.inc(-SMALL_GAP), false); burger_mx = EAX; //AddTopBarButton(#EventShowInfo, NULL, -1, x.inc(-SMALL_GAP), false); burger_mx = EAX;
AddTopBarButton(#EventShowThemesList, NULL, 40, x.inc(-BIG_GAP), thema); theme_mx = EAX; AddTopBarButton(#EventShowThemesList, NULL, 40, x.inc(-SMALL_GAP), thema); theme_mx = EAX;
AddTopBarButton(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-SMALL_GAP), reopa); reopenin_mx = EAX; AddTopBarButton(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-SMALL_GAP), reopa); reopenin_mx = EAX;
//AddTopBarButton(#EventOpenSysfuncs, NULL, 18, x.inc(-SMALL_GAP), false); //AddTopBarButton(#EventOpenSysfuncs, NULL, 18, x.inc(-SMALL_GAP), false);
//AddTopBarButton(#EventOpenPipet, NULL, 39, x.inc(-SMALL_GAP), false); //AddTopBarButton(#EventOpenPipet, NULL, 39, x.inc(-SMALL_GAP), false);
DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1,
60, 12, button.add(#EventShowCharsetsList));
} }
void DrawStatusBar(dword _in_text) void DrawStatusBar(dword _in_text)
@ -666,9 +661,13 @@ void DrawStatusBar(dword _in_text)
if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text)); if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text));
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph); DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph);
DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work); DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work);
WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4,
60, sc.work_text, real_encoding*10+#charsets);
WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text); WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text);
if (param[0]) {
WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4,
60, sc.work_text, real_encoding*10+#charsets);
DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1,
60, 12, BTN_CHANGE_CHARSET+10);
}
} }
void draw_window() void draw_window()

View File

@ -24,19 +24,22 @@ bool SELECTION::is_active()
void SELECTION::draw_line(dword x,y,w) void SELECTION::draw_line(dword x,y,w)
{ {
DrawBuf.DrawBar(x, y, w, list.item_h, color); DrawBuf.DrawBar(x, y - list.first * list.item_h, w, list.item_h, color);
} }
void SELECTION::draw(int i) void SELECTION::draw(int i)
{ {
if (is_active()) { if (is_active()) {
if (start_y == i) && (end_y == i) draw_line(start_x * list.font_w+2, start_y * list.item_h, end_x - start_x * list.font_w); if (start_y == i) && (end_y == i) draw_line(start_x * list.font_w+2, start_y, end_x - start_x * list.font_w);
else if (start_y == i) draw_line(start_x * list.font_w+2, start_y * list.item_h, list.w -2- calc(start_x * list.font_w)); else if (start_y == i) draw_line(start_x * list.font_w+2, start_y, list.w -2- calc(start_x * list.font_w));
else if (end_y == i) draw_line(0, end_y * list.item_h, end_x * list.font_w+2); else if (end_y == i) draw_line(0, end_y, end_x * list.font_w+2);
//DrawBuf.DrawBar(start_x * list.font_w + 2, start_y * list.item_h, 2, list.item_h, 0x00FF00); //DrawBuf.DrawBar(start_x * list.font_w + 2, start_y * list.item_h, 2, list.item_h, 0x00FF00);
//DrawBuf.DrawBar(end_x * list.font_w + 0, end_y * list.item_h, 2, list.item_h, 0xFF00FF); //DrawBuf.DrawBar(end_x * list.font_w + 0, end_y * list.item_h, 2, list.item_h, 0xFF00FF);
} }
DrawBuf.DrawBar(list.cur_x * list.font_w + 2, list.cur_y * list.item_h, 2, list.item_h, theme.cursor); //DrawCursor //DrawCursor
if (list.cur_y >= list.first) && (list.cur_y <= list.first+list.visible) {
DrawBuf.DrawBar(list.cur_x * list.font_w + 2, list.cur_y - list.first * list.item_h, 2, list.item_h, theme.cursor);
}
} }
void SELECTION::cancel() void SELECTION::cancel()
@ -49,6 +52,7 @@ void SELECTION::cancel()
void SELECTION::set_start() void SELECTION::set_start()
{ {
if (selection.is_active()) return;
start_x = list.cur_x; start_x = list.cur_x;
start_y = list.cur_y; start_y = list.cur_y;
normalize(); normalize();
@ -61,8 +65,8 @@ void SELECTION::set_end()
end_y = list.cur_y; end_y = list.cur_y;
normalize(); normalize();
end_offset = lines.get(end_y) + end_x; end_offset = lines.get(end_y) + end_x;
debugval("end_x", end_x); //debugval("end_x", end_x);
debugval("end_y", end_y); //debugval("end_y", end_y);
} }
@ -78,11 +82,10 @@ void SELECTION::select_all()
start_x = 0; start_x = 0;
end_y = lines.count-2; end_y = lines.count-2;
end_x = lines.get(end_y+1) - lines.get(end_y); end_x = lines.get(end_y+1) - lines.get(end_y);
//normalize();
start_offset = lines.get(start_y) + start_x; start_offset = lines.get(start_y) + start_x;
end_offset = lines.get(end_y) + end_x; end_offset = lines.get(end_y) + end_x;
debugval("end_x__", end_x); //debugval("end_x__", end_x);
debugval("end_y__", end_y); //debugval("end_y__", end_y);
} }
bool SELECTION::swap_start_end() bool SELECTION::swap_start_end()