From a576b68db3161e17ebef06b15b258956e1ab951a Mon Sep 17 00:00:00 2001 From: leency Date: Tue, 25 Feb 2025 14:35:21 +0200 Subject: [PATCH] C-- menu: quick update to avoid full redraw, now redraw only changed items --- programs/cmm/browser/TWB/special.h | 1 + programs/cmm/menu/menu.c | 100 ++++++++++++++++++----------- 2 files changed, 64 insertions(+), 37 deletions(-) diff --git a/programs/cmm/browser/TWB/special.h b/programs/cmm/browser/TWB/special.h index 75b73f654..a78362729 100644 --- a/programs/cmm/browser/TWB/special.h +++ b/programs/cmm/browser/TWB/special.h @@ -50,6 +50,7 @@ char *unicode_symbols[]={ "#65122", "+", "#8594", "->", +"#8627", "->", "uarr", "^", "darr", "v", diff --git a/programs/cmm/menu/menu.c b/programs/cmm/menu/menu.c index 5f6a32830..f3b8d0d39 100644 --- a/programs/cmm/menu/menu.c +++ b/programs/cmm/menu/menu.c @@ -13,7 +13,8 @@ #define FONT_HEIGHT 16 llist menu1; -collection names=0; +collection names=0; //contains all items: real items + separators +collection real_names=0; //contains only real items without separators collection hotkeys=0; int selected, win_x, win_y; @@ -69,8 +70,11 @@ void GetMenuItems(dword current_name) } } - hotkeys.add(hotkey+1); names.add(current_name); + if (!streq(current_name, "-")) { + real_names.add(current_name); + hotkeys.add(hotkey+1); + } if (next_name) GetMenuItems(next_name+2); } @@ -84,6 +88,8 @@ int GetSeparatorsCount() return count; } +//this is a very dirty hack because I change +//the real position of mouse.y to fictive one that handles separators int MoveMouseToHandleSeparators(int _mouse_y) { int i, item_y=menu1.y; @@ -103,11 +109,28 @@ int MoveMouseToHandleSeparators(int _mouse_y) return _mouse_y; } +dword inactive_background_color; +dword active_background_color; +dword active_top_border_color; +dword inactive_text_shadow_color; +bool skin_dark; +void GetColors() +{ + sc.get(); + inactive_background_color = MixColors(sc.work, 0xFFFfff,230); + active_background_color = MixColors(sc.button, sc.work,230); + active_top_border_color = MixColors(sc.line, sc.button,240); + inactive_text_shadow_color = MixColors(sc.work,0xFFFfff,120); + skin_dark = skin_is_dark(); +} + void main() { proc_info Form; if (!param) RunProgram("/sys/network/WebView", "http://board.kolibrios.org/viewtopic.php?f=24&t=4233#p74599"); + + GetColors(); GetMenuItems(#param); GetMenuWidths(); @@ -145,7 +168,6 @@ void main() case evReDraw: DefineAndDrawWindow(win_x, win_y, menu1.w+4, menu1.h+4, 0x01, 0, 0, 0x01fffFFF); - sc.get(); Draw3DPopup(0,0,menu1.w+2,menu1.h+2); draw_list(); } @@ -194,59 +216,63 @@ inline ProcessKeys() } } +void draw_item(int item_y, i, bool active) +{ + dword name_color; + dword hotkey_color; + if (active) { + hotkey_color = name_color = sc.button_text; + DrawBar(menu1.x, item_y+1, menu1.w, ITEM_H-2, active_background_color); + DrawBar(menu1.x, item_y, menu1.w, 1, active_top_border_color); + DrawBar(menu1.x, item_y+ITEM_H-1, menu1.w, 1, sc.light); + } else { + name_color = sc.work_text; + hotkey_color = sc.line; + DrawBar(menu1.x, item_y, menu1.w, ITEM_H, inactive_background_color); + if (!skin_dark) WriteText(TEXT_MARGIN+1, item_y + menu1.text_y +1, TEXT_FONT_TYPE, + inactive_text_shadow_color, real_names.get(i)); + } + WriteText(-strlen(hotkeys.get(i))*FONT_WIDTH + menu_w - TEXT_MARGIN, + item_y + menu1.text_y, TEXT_FONT_TYPE, hotkey_color, hotkeys.get(i)); + WriteText(TEXT_MARGIN, item_y + menu1.text_y, TEXT_FONT_TYPE, name_color, real_names.get(i)); +} + + void draw_list() { int i, item_y=menu1.y, item_i=0; - dword name_color; - dword hotkey_color; + #define MAX_ITEMS 128 + static int item_y_mas[MAX_ITEMS]; + static int init = true; + static int old_y; - static dword inactive_background_color; - static dword active_background_color; - static dword active_top_border_color; - static dword inactive_text_shadow_color; - static bool skin_dark; - - static bool colors_set; - if (!colors_set) { - colors_set = true; - inactive_background_color = MixColors(sc.work, 0xFFFfff,230); - active_background_color = MixColors(sc.button, sc.work,230); - active_top_border_color = MixColors(sc.line, sc.button,240); - inactive_text_shadow_color = MixColors(sc.work,0xFFFfff,120); - skin_dark = skin_is_dark(); - } - - for (i=0; i