From babba2a8cef81aab722f8412f52415827044d1fd Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Thu, 1 Nov 2018 21:48:33 +0000 Subject: [PATCH] CMM new lib: events.h IconEdit: use event model netcheck: example of event model, can be used for network testing git-svn-id: svn://kolibrios.org@7521 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/browser/WebView.c | 7 +- programs/cmm/browser/download_manager.h | 44 +++- programs/cmm/examples/Tupfile.lua | 1 + programs/cmm/examples/netcheck.c | 101 +++++++++ programs/cmm/iconedit/iconedit.c | 263 ++++++++---------------- programs/cmm/iconedit/tools.h | 1 - programs/cmm/lib/array.h | 6 +- programs/cmm/lib/events.h | 46 +++++ programs/cmm/lib/keyboard.h | 1 + 9 files changed, 278 insertions(+), 192 deletions(-) create mode 100644 programs/cmm/examples/netcheck.c create mode 100644 programs/cmm/lib/events.h diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index f144ab2e0a..f2f7c636b4 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -127,7 +127,12 @@ void main() skin.h = 26; wv_progress_bar.progress_color = 0x72B7EB; CreateDir("/tmp0/1/downloads"); - if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME); + if (param) && (param[0]=='-') && (param[1]=='d') { + strcpy(#downloader_edit, #param+3); + CreateThread(#Downloader,#downloader_stak+4092); + ExitProcess(); + } + else if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME); WB1.list.SetFont(8, 14, 10011000b); WB1.list.no_selection = true; SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); diff --git a/programs/cmm/browser/download_manager.h b/programs/cmm/browser/download_manager.h index 3125807906..88f557db94 100644 --- a/programs/cmm/browser/download_manager.h +++ b/programs/cmm/browser/download_manager.h @@ -19,13 +19,16 @@ DOWNLOADER downloader; #endif char save_to[4096] = "/tmp0/1/Downloads"; +#define CONX 15 + proc_info DL_Form; char downloader_edit[10000]; char filepath[4096]; edit_box ed = {NULL,57,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit)-2,#downloader_edit,0,2,19,19}; -progress_bar pb = {0, 20, 58, 350, 17, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; +progress_bar pb = {0, CONX, 58, 350, 17, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; //progress_bar pb = {0, 180, 55, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; //progress_bar: value, left, top, width, height, style, min, max, back_color, progress_color, frame_color; + bool downloader_opened; @@ -106,7 +109,6 @@ void Key_Scan(int id) void DL_Draw_Window() { - int cleft = 15; int but_x = 0; int but_y = 58; DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work); @@ -116,7 +118,7 @@ void DL_Draw_Window() DeleteButton(306); if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED) { - but_x = cleft + DrawStandartCaptButton(cleft, but_y, 301, START_DOWNLOADING); + but_x = CONX + DrawStandartCaptButton(CONX, but_y, 301, START_DOWNLOADING); if (filepath[0]) { but_x += DrawStandartCaptButton(but_x, but_y, 305, SHOW_IN_FOLDER); @@ -128,8 +130,8 @@ void DL_Draw_Window() DrawStandartCaptButton(DL_Form.width - 190, but_y, 302, STOP_DOWNLOADING); DrawDownloading(); } - WriteText(cleft, ed.top + 4, 0x90, system.color.work_text, "URL:"); - ed.width = DL_Form.cwidth - ed.left - cleft - 3; + WriteText(CONX, ed.top + 4, 0x90, system.color.work_text, "URL:"); + ed.width = DL_Form.cwidth - ed.left - CONX - 3; ed.offset=0; DrawEditBox(#ed); } @@ -151,13 +153,41 @@ void StartDownloading() pb.value = 0; DL_Draw_Window(); } + +struct TIME +{ + dword old; + dword cur; + dword gone; +} time = {0,0,0}; + +dword netdata_received; +dword speed; + +void CalculateSpeed() +{ + time.cur = GetStartTime(); + + if (time.old) { + time.gone = time.cur - time.old; + if (time.gone > 200) { + speed = downloader.httpd.content_received - netdata_received / time.gone * 100; + debugval("speed", speed); + debugln(ConvertSizeToKb(speed) ); + time.old = time.cur; + netdata_received = downloader.httpd.content_received; + } + } + else time.old = time.cur; +} void DrawDownloading() { char bytes_received[70]; sprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.httpd.content_received) ); - DrawBar(15, pb.top + 22, strlen(#bytes_received+4)*12, 16, system.color.work); - WriteText(15, pb.top + 22, 0x90, system.color.work_text, #bytes_received); + DrawBar(CONX, pb.top + 22, pb.width, 16, system.color.work); + WriteText(CONX, pb.top + 22, 0x90, system.color.work_text, #bytes_received); + //CalculateSpeed(); progressbar_draw stdcall(#pb); } diff --git a/programs/cmm/examples/Tupfile.lua b/programs/cmm/examples/Tupfile.lua index 877ec702f4..2ee5586d22 100644 --- a/programs/cmm/examples/Tupfile.lua +++ b/programs/cmm/examples/Tupfile.lua @@ -10,3 +10,4 @@ tup.rule("rgb.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD tup.rule("console.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "console.com") tup.rule("info.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "info.com") tup.rule("pig.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "pig.com") +tup.rule("netcheck.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "netcheck.com") diff --git a/programs/cmm/examples/netcheck.c b/programs/cmm/examples/netcheck.c new file mode 100644 index 0000000000..0c8b3cfaf9 --- /dev/null +++ b/programs/cmm/examples/netcheck.c @@ -0,0 +1,101 @@ +/* + * Network testing utility + * Leency 2018 +*/ + +#define MEMSIZE 4096*10 + +#include "../lib/fs.h" +#include "../lib/gui.h" +#include "../lib/events.h" + +//===================================================// +// // +// DATA // +// // +//===================================================// + +char download_file[] = "-d http://kolibri-n.org/files/KolibriN9.zip"; + +EVENTS button; +EVENTS key; + +//===================================================// +// // +// CODE // +// // +//===================================================// + +void main() +{ + loop() switch(WaitEvent()) + { + case evButton: + button.press( GetButtonID() ); + break; + + case evKey: + GetKeys(); + key.press( key_scancode ); + break; + + case evReDraw: + draw_window(); + break; + } +} + +void draw_window() +{ + system.color.get(); + DefineAndDrawWindow(215, 100, 350, 300, 0x34, system.color.work, "Network testing utility",0); + button.init(10); + key.init(10); + + WriteText(10,10, 0x90, system.color.work_text, "Download via:"); + AddEvent(10, 30, #EventRunAsmDownloader, SCAN_CODE_F1, "ASM Downloader [F1]"); + AddEvent(10, 60, #EventRunCmmDownloader, SCAN_CODE_F2, "C-- Downloader [F2]"); + AddEvent(10, 120, #EventRunNetStat, SCAN_CODE_F3, "NetStat [F3]"); + AddEvent(10, 150, #EventRunNetCfg, SCAN_CODE_F4, "NetCfg [F4]"); + AddEvent(10, 180, #EventRunBoard, SCAN_CODE_F5, "Board [F5]"); + button.add_n(1, #ExitProcess); + key.add_n(SCAN_CODE_ESC, #ExitProcess); +} + +void AddEvent(dword bx, by, event, hotkey, text) +{ + DrawStandartCaptButton(bx, by, button.add(event), text); + key.add_n(hotkey, event); +} + +//===================================================// +// // +// EVENTS // +// // +//===================================================// + +void EventRunAsmDownloader() +{ + RunProgram("/sys/network/downloader", #download_file+3); +} + +void EventRunCmmDownloader() +{ + RunProgram("/sys/network/webview", #download_file); +} + +void EventRunNetStat() +{ + RunProgram("/sys/network/netstat", NULL); +} + +void EventRunNetCfg() +{ + RunProgram("/sys/network/netcfg", NULL); +} + +void EventRunBoard() +{ + RunProgram("/sys/develop/board", NULL); +} + diff --git a/programs/cmm/iconedit/iconedit.c b/programs/cmm/iconedit/iconedit.c index 6278f4095f..0e6bde9094 100644 --- a/programs/cmm/iconedit/iconedit.c +++ b/programs/cmm/iconedit/iconedit.c @@ -4,13 +4,14 @@ * Licence: GPL v2 */ -#define MEMSIZE 4096*500 +#define MEMSIZE 1024*2000 #include "../lib/gui.h" #include "../lib/random.h" #include "../lib/mem.h" #include "../lib/cursor.h" #include "../lib/list_box.h" +#include "../lib/events.h" #include "../lib/obj/libimg.h" #include "../lib/obj/box_lib.h" @@ -36,14 +37,14 @@ char image_menu_items[] = Заменить все цвета 1 на 2"; ?define T_MENU_IMAGE "Иконка" ?define T_TEST_ICON "Проверить иконку" -?define T_TITLE "Icon Editor 0.59 Alpha" +?define T_TITLE "Icon Editor 0.60 Alpha" #else char image_menu_items[] = "Count colors used Replace all colors equal to 1 by 2"; ?define T_MENU_IMAGE "Icon" ?define T_TEST_ICON "Test Icon" -?define T_TITLE "Редактор иконок 0.59 Alpha" +?define T_TITLE "Редактор иконок 0.60 Alpha" #endif @@ -81,32 +82,10 @@ signed priorHoverX; signed priorHoverY; bool canvasMouseMoved = false; +EVENTS button; +EVENTS key; + enum { - BTN_NEW = 40, - BTN_OPEN, - BTN_SAVE, - BTN_MOVE_LEFT, - BTN_MOVE_RIGHT, - BTN_MOVE_UP, - BTN_MOVE_DOWN, - BTN_FLIP_HOR, - BTN_FLIP_VER, - BTN_ROTATE_LEFT, - BTN_ROTATE_RIGHT, - BTN_TEST_ICON, - BTN_PENCIL, - BTN_PICK, - BTN_FILL, - BTN_LINE, - BTN_RECT, - BTN_BAR, - BTN_SELECT, - BTN_SCREEN_COPY, - BTN_ZOOM_IN, - BTN_ZOOM_OUT, - BTN_CANVAS_RESIZE, - BTN_CROP, - BTN_IMAGE_MENU, BTNS_PALETTE_COLOR_MAS = 100, BTNS_LAST_USED_COLORS = 400 }; @@ -272,116 +251,12 @@ void main() if (zoom.click(btn)) DrawEditArea(); - switch(btn) - { - case BTN_NEW: - EventCreateNewIcon(); - break; - case BTN_OPEN: - EventOpenIcon(); - break; - case BTN_SAVE: - EventSaveIconToFile(); - break; - case BTN_MOVE_LEFT: - EventMove(MOVE_LEFT); - break; - case BTN_MOVE_RIGHT: - EventMove(MOVE_RIGHT); - break; - case BTN_MOVE_UP: - EventMove(MOVE_UP); - break; - case BTN_MOVE_DOWN: - EventMove(MOVE_DOWN); - break; - case BTN_FLIP_VER: - EventMove(FLIP_VER); - break; - case BTN_FLIP_HOR: - EventMove(FLIP_HOR); - break; - case BTN_ROTATE_LEFT: - EventMove(ROTATE_LEFT); - break; - case BTN_ROTATE_RIGHT: - EventMove(ROTATE_RIGHT); - break; - case BTN_TEST_ICON: - EventTestIcon(); - break; - case BTN_PENCIL: - setCurrentTool(TOOL_PENCIL); - break; - case BTN_PICK: - setCurrentTool(TOOL_PIPETTE); - break; - case BTN_FILL: - setCurrentTool(TOOL_FILL); - break; - case BTN_LINE: - setCurrentTool(TOOL_LINE); - break; - case BTN_RECT: - setCurrentTool(TOOL_RECT); - break; - case BTN_BAR: - setCurrentTool(TOOL_BAR); - break; - case BTN_SELECT: - setCurrentTool(TOOL_SELECT); - break; - case BTN_SCREEN_COPY: - setCurrentTool(TOOL_SCREEN_COPY); - break; - case BTN_CANVAS_RESIZE: - notify("Sorry, not implemented yet."); - break; - case BTN_CROP: - EventCrop(); - break; - case BTN_IMAGE_MENU: - EventShowImageMenu(); - break; - case CLOSE_BTN: - EventExitIconEdit(); - break; - } - break; + button.press(btn); case evKey: GetKeys(); - if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) - { - switch(key_scancode) - { - case SCAN_CODE_KEY_S: - EventSaveIconToFile(); - break; - case SCAN_CODE_KEY_O: - EventOpenIcon(); - break; - case SCAN_CODE_LEFT: - EventMove(MOVE_LEFT); - break; - case SCAN_CODE_RIGHT: - EventMove(MOVE_RIGHT); - break; - case SCAN_CODE_UP: - EventMove(MOVE_UP); - break; - case SCAN_CODE_DOWN: - EventMove(MOVE_DOWN); - break; - case SCAN_CODE_KEY_R: - EventMove(BTN_ROTATE_RIGHT); - break; - case SCAN_CODE_KEY_L: - EventMove(BTN_ROTATE_LEFT); - break; - } - } + if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) key.press(ECTRL + key_scancode); if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) { if (key_scancode == SCAN_CODE_DEL) EventCleanCanvas(); @@ -390,15 +265,7 @@ void main() if (currentTool != TOOL_NONE) && (tools[currentTool].onKeyEvent != 0) tools[currentTool].onKeyEvent(key_scancode); - if (key_scancode == SCAN_CODE_KEY_P) setCurrentTool(TOOL_PENCIL); - if (key_scancode == SCAN_CODE_KEY_I) setCurrentTool(TOOL_PIPETTE); - if (key_scancode == SCAN_CODE_KEY_F) setCurrentTool(TOOL_FILL); - if (key_scancode == SCAN_CODE_KEY_L) setCurrentTool(TOOL_LINE); - if (key_scancode == SCAN_CODE_KEY_R) setCurrentTool(TOOL_RECT); - if (key_scancode == SCAN_CODE_KEY_B) setCurrentTool(TOOL_BAR); - if (key_scancode == SCAN_CODE_KEY_S) setCurrentTool(TOOL_SELECT); - - if (key_scancode == SCAN_CODE_KEY_T) EventTestIcon(); + key.press(key_scancode); if (key_scancode == SCAN_CODE_KEY_Z) actionsHistory.undoLastAction(); if (key_scancode == SCAN_CODE_KEY_Y) actionsHistory.redoLastAction(); @@ -416,17 +283,19 @@ void main() } } -void DrawTopPanelButton(dword _id, _x, _icon_n) +void DrawTopPanelButton(dword _event, _hotkey, _x, _icon_n) { DrawWideRectangle(_x, 4, 22, 22, 3, semi_white); PutPixel(_x,4,system.color.work); PutPixel(_x,4+21,system.color.work); PutPixel(_x+21,4,system.color.work); PutPixel(_x+21,4+21,system.color.work); - DefineHiddenButton(_x, 4, 21, 21, _id); + DefineHiddenButton(_x, 4, 21, 21, button.add(_event)); img_draw stdcall(top_icons.image, _x+3, 7, 16, 16, 0, _icon_n*16); + if (_hotkey) key.add_n(_hotkey, _event); } + int DrawFlatPanelButton(dword _id, _x, _y, _text) { #define P 10 @@ -441,14 +310,14 @@ int DrawFlatPanelButton(dword _id, _x, _y, _text) return w; } -void DrawLeftPanelButton(dword _id, _y, _icon_n) +void DrawLeftPanelButton(dword _event, _hotkey, _y, _icon_n) { int x = 5; DrawRectangle(x, _y, 22-1, 22-1, system.color.work); - DefineHiddenButton(x, _y, 21, 21, _id); + DefineHiddenButton(x, _y, 21, 21, button.add(_event)); img_draw stdcall(left_icons.image, x+3, _y+3, 16, 16, 0, _icon_n*16); + key.add_n(_hotkey, _event); } - void DrawStatusBar() { zoom.draw(wrapper.x, wrapper.y + wrapper.h + 6); @@ -459,56 +328,71 @@ void DrawStatusBar() zoom.y, calc(strlen(#param)*8)+6, 18, - BTN_CANVAS_RESIZE, + button.add(#EventCanvasResize), system.color.work_button, system.color.work_button_text, #param ); } + void DrawWindow() { - #define GAP 27 + #define GAPH 27 + #define GAPV 28 #define BLOCK_SPACE 10 incn tx; + incn ty; system.color.get(); DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x73, NULL, T_TITLE, 0); GetProcessInfo(#Form, SelfInfo); if (Form.status_window>2) return; if (Form.width < 560) { MoveSize(OLD,OLD,560,OLD); return; } if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; } + button.init(40); + key.init(40); right_bar.x = Form.cwidth - right_bar.w; b_color_gradient.x = b_last_colors.x = b_default_palette.x = right_bar.x; DrawBar(0, 0, Form.cwidth, TOPBAR_H-1, system.color.work); DrawBar(0, TOPBAR_H-1, Form.cwidth, 1, system.color.work_graph); - tx.n = 5-GAP; - DrawTopPanelButton(BTN_NEW, tx.inc(GAP), 2); - DrawTopPanelButton(BTN_OPEN, tx.inc(GAP), 0); //not implemented - DrawTopPanelButton(BTN_SAVE, tx.inc(GAP), 5); - DrawTopPanelButton(BTN_MOVE_LEFT, tx.inc(GAP+BLOCK_SPACE), 30); - DrawTopPanelButton(BTN_MOVE_RIGHT, tx.inc(GAP), 31); - DrawTopPanelButton(BTN_MOVE_UP, tx.inc(GAP), 32); - DrawTopPanelButton(BTN_MOVE_DOWN, tx.inc(GAP), 33); - - DrawTopPanelButton(BTN_FLIP_HOR, tx.inc(GAP+BLOCK_SPACE), 34); - DrawTopPanelButton(BTN_FLIP_VER, tx.inc(GAP), 35); - DrawTopPanelButton(BTN_ROTATE_LEFT, tx.inc(GAP), 37); - DrawTopPanelButton(BTN_ROTATE_RIGHT, tx.inc(GAP), 36); - - DrawTopPanelButton(BTN_TEST_ICON, tx.inc(GAP+BLOCK_SPACE), 12); - - DrawTopPanelButton(BTN_CROP, tx.inc(GAP+BLOCK_SPACE), 46); + tx.n = 5-GAPH; + DrawTopPanelButton(#EventCreateNewIcon, ECTRL + SCAN_CODE_KEY_N, tx.inc(GAPH), 2); + DrawTopPanelButton(#EventOpenIcon, ECTRL + SCAN_CODE_KEY_O, tx.inc(GAPH), 0); + DrawTopPanelButton(#EventSaveIconToFile, ECTRL + SCAN_CODE_KEY_S, tx.inc(GAPH), 5); + DrawTopPanelButton(#EventMoveLeft, ECTRL + SCAN_CODE_LEFT, tx.inc(GAPH+BLOCK_SPACE), 30); + DrawTopPanelButton(#EventMoveRight, ECTRL + SCAN_CODE_RIGHT, tx.inc(GAPH), 31); + DrawTopPanelButton(#EventMoveUp, ECTRL + SCAN_CODE_UP, tx.inc(GAPH), 32); + DrawTopPanelButton(#EventMoveDown, ECTRL + SCAN_CODE_DOWN, tx.inc(GAPH), 33); + DrawTopPanelButton(#EventFlipHor, 0, tx.inc(GAPH+BLOCK_SPACE), 34); + DrawTopPanelButton(#EventFlipVer, 0, tx.inc(GAPH), 35); + DrawTopPanelButton(#EventRotateLeft, ECTRL + SCAN_CODE_KEY_L, tx.inc(GAPH), 37); + DrawTopPanelButton(#EventRotateRight, ECTRL + SCAN_CODE_KEY_R, tx.inc(GAPH), 36); + DrawTopPanelButton(#EventTestIcon, ECTRL + SCAN_CODE_KEY_T, tx.inc(GAPH+BLOCK_SPACE), 12); + DrawTopPanelButton(#EventCrop, 0, tx.inc(GAPH+BLOCK_SPACE), 46); image_menu_btn.x = tx.n; - image_menu_btn.w = DrawFlatPanelButton(BTN_IMAGE_MENU, image_menu_btn.x, image_menu_btn.y, T_MENU_IMAGE); + image_menu_btn.w = DrawFlatPanelButton(button.add(#EventShowImageMenu), image_menu_btn.x, image_menu_btn.y, T_MENU_IMAGE); //tx.inc(image_menu_btn.w + BLOCK_SPACE); DrawEditArea(); DrawBar(0, TOPBAR_H, LEFTBAR_W-1, Form.cheight - TOPBAR_H, system.color.work); - DrawLeftPanel(); + + ty.n = right_bar.y - GAPV - 2; + + DrawLeftPanelButton(#EventSelectToolPencil, SCAN_CODE_KEY_P, ty.inc(GAPV), 38); + DrawLeftPanelButton(#EventSelectToolPick, SCAN_CODE_KEY_I, ty.inc(GAPV), 39); + DrawLeftPanelButton(#EventSelectToolFill, SCAN_CODE_KEY_F, ty.inc(GAPV), 40); + DrawLeftPanelButton(#EventSelectToolLine, SCAN_CODE_KEY_L, ty.inc(GAPV), 41); + DrawLeftPanelButton(#EventSelectToolRect, SCAN_CODE_KEY_R, ty.inc(GAPV), 42); + DrawLeftPanelButton(#EventSelectToolBar, SCAN_CODE_KEY_B, ty.inc(GAPV), 43); + DrawLeftPanelButton(#EventSelectToolSelect, SCAN_CODE_KEY_S, ty.inc(GAPV), 44); + DrawLeftPanelButton(#EventSelectToolScrCopy,SCAN_CODE_KEY_Q, ty.inc(GAPV), 45); + DrawLeftPanelSelection(); + + button.add_n(1, #EventExitIconEdit); DrawBar(wrapper.x+wrapper.w, TOPBAR_H, Form.cwidth-wrapper.x-wrapper.w, Form.cheight - TOPBAR_H, system.color.work); @@ -521,20 +405,10 @@ void DrawWindow() DrawStatusBar(); } -void DrawLeftPanel() +void DrawLeftPanelSelection() { - #define GAP 28 - incn ty; - ty.n = right_bar.y - GAP - 2; - DrawLeftPanelButton(BTN_PENCIL, ty.inc(GAP), 38); - DrawLeftPanelButton(BTN_PICK, ty.inc(GAP), 39); - DrawLeftPanelButton(BTN_FILL, ty.inc(GAP), 40); - DrawLeftPanelButton(BTN_LINE, ty.inc(GAP), 41); - DrawLeftPanelButton(BTN_RECT, ty.inc(GAP), 42); - DrawLeftPanelButton(BTN_BAR, ty.inc(GAP), 43); - DrawLeftPanelButton(BTN_SELECT, ty.inc(GAP), 44); - DrawLeftPanelButton(BTN_SCREEN_COPY, ty.inc(GAP), 45); - DrawRectangle3D(5, currentTool*GAP+right_bar.y-2, 16+3+2, 16+3+2, 0x333333, 0x777777); + DrawRectangle3D(5, previousTool*GAPV+right_bar.y-2, 16+3+2, 16+3+2, system.color.work, system.color.work); + DrawRectangle3D(5, currentTool*GAPV+right_bar.y-2, 16+3+2, 16+3+2, 0x333333, 0x777777); } void DrawEditArea() @@ -895,6 +769,31 @@ void EventReplaceImageColors(dword c1, c2) } } +void EventCanvasResize() +{ + notify("Sorry, not implemented yet."); +} + +void EventMoveLeft() { EventMove(MOVE_LEFT); } +void EventMoveRight() { EventMove(MOVE_RIGHT); } +void EventMoveUp() { EventMove(MOVE_UP); } +void EventMoveDown() { EventMove(MOVE_DOWN); } +void EventFlipHor() { EventMove(FLIP_HOR); } +void EventFlipVer() { EventMove(FLIP_VER); } +void EventRotateLeft() { EventMove(ROTATE_LEFT); } +void EventRotateRight() { EventMove(ROTATE_RIGHT); } + +void EventSelectToolPencil() { setCurrentTool(TOOL_PENCIL); DrawLeftPanelSelection(); } +void EventSelectToolPick() { setCurrentTool(TOOL_PIPETTE); DrawLeftPanelSelection(); } +void EventSelectToolFill() { setCurrentTool(TOOL_FILL); DrawLeftPanelSelection(); } +void EventSelectToolLine() { setCurrentTool(TOOL_LINE); DrawLeftPanelSelection(); } +void EventSelectToolRect() { setCurrentTool(TOOL_RECT); DrawLeftPanelSelection(); } +void EventSelectToolBar() { setCurrentTool(TOOL_BAR); DrawLeftPanelSelection(); } +void EventSelectToolSelect() { setCurrentTool(TOOL_SELECT); DrawLeftPanelSelection(); } +void EventSelectToolScrCopy() { setCurrentTool(TOOL_SCREEN_COPY); DrawLeftPanelSelection(); } + +char test_icon_stak22[4096]; + stop: char test_icon_stak[4096]; diff --git a/programs/cmm/iconedit/tools.h b/programs/cmm/iconedit/tools.h index 31690d7e3f..5e5ef9860f 100644 --- a/programs/cmm/iconedit/tools.h +++ b/programs/cmm/iconedit/tools.h @@ -107,7 +107,6 @@ void setCurrentTool(int index) { Cursor.Restore(); if (wrapper.hovered()) SetCursor(); - DrawLeftPanel(); DrawCanvas(); } diff --git a/programs/cmm/lib/array.h b/programs/cmm/lib/array.h index 1eaacb0563..e55ae1809c 100644 --- a/programs/cmm/lib/array.h +++ b/programs/cmm/lib/array.h @@ -1,5 +1,7 @@ // Author: Pavel Iakovlev by. pavelyakov +#ifndef INCLUDE_ARRAY_H +#define INCLUDE_ARRAY_H // Array memory: [dword key][byte flags][dword left][dword right][dword value] -> 17 bytes = 1 position // If key don't exists then value == 0 @@ -161,4 +163,6 @@ :byte Dictionary::init(dword size) { RETURN array.init(size); -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/programs/cmm/lib/events.h b/programs/cmm/lib/events.h new file mode 100644 index 0000000000..640953c708 --- /dev/null +++ b/programs/cmm/lib/events.h @@ -0,0 +1,46 @@ + +#ifndef INCLUDE_ARRAY_H +#include "../lib/array.h" +#endif + +#define ECTRL 300 + +struct EVENTS +{ + Array array; + int new_id; + void init(); + int add(); + int add_n(); + bool press(); +}; + +void EVENTS::init(dword size) +{ + array.init(size); + new_id = 900; +} + +int EVENTS::add(dword event1) +{ + new_id++; + array.set(new_id, event1); + return new_id; +} + +int EVENTS::add_n(dword id, event2) +{ + array.set(id, event2); + return new_id; +} + +bool EVENTS::press(dword id) +{ + dword event3; + if (array.get(id)) { + event3 = array.get(id); + event3(); + return true; + } + return false; +} \ No newline at end of file diff --git a/programs/cmm/lib/keyboard.h b/programs/cmm/lib/keyboard.h index a2f16ddfaa..e08a5392c5 100644 --- a/programs/cmm/lib/keyboard.h +++ b/programs/cmm/lib/keyboard.h @@ -71,6 +71,7 @@ #define SCAN_CODE_KEY_N 049 #define SCAN_CODE_KEY_O 024 #define SCAN_CODE_KEY_P 025 +#define SCAN_CODE_KEY_Q 016 #define SCAN_CODE_KEY_R 019 #define SCAN_CODE_KEY_S 031 #define SCAN_CODE_KEY_T 020