From c2149afa96c346b59dc90076693d7797e22cd4f8 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Mon, 7 May 2018 16:17:53 +0000 Subject: [PATCH] child window, new icon size set git-svn-id: svn://kolibrios.org@7274 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/iconedit/actions_history.h | 5 +- programs/cmm/iconedit/canvas_resize.h | 96 ++++++++++++++++++++ programs/cmm/iconedit/cursors/bar.cur | Bin 766 -> 326 bytes programs/cmm/iconedit/cursors/fill.cur | Bin 766 -> 326 bytes programs/cmm/iconedit/cursors/line.cur | Bin 766 -> 326 bytes programs/cmm/iconedit/cursors/pipette.cur | Bin 766 -> 326 bytes programs/cmm/iconedit/cursors/rectangle.cur | Bin 766 -> 326 bytes programs/cmm/iconedit/cursors/select.cur | Bin 766 -> 326 bytes programs/cmm/iconedit/iconedit.c | 52 ++++++++--- programs/cmm/lib/gui.h | 58 +----------- programs/cmm/lib/gui/child_window.h | 23 +++++ programs/cmm/lib/gui/text_view_area.h | 54 +++++++++++ 12 files changed, 215 insertions(+), 73 deletions(-) create mode 100644 programs/cmm/iconedit/canvas_resize.h create mode 100644 programs/cmm/lib/gui/child_window.h create mode 100644 programs/cmm/lib/gui/text_view_area.h diff --git a/programs/cmm/iconedit/actions_history.h b/programs/cmm/iconedit/actions_history.h index 94c3097044..800c8d7db6 100644 --- a/programs/cmm/iconedit/actions_history.h +++ b/programs/cmm/iconedit/actions_history.h @@ -1,4 +1,3 @@ -// Actions history #define MAX_ACTIONS_COUNT 15 @@ -24,8 +23,10 @@ void _ActionsHistory::init() { head = tail = 0; currentIndex = -1; - for (i = 0; i < MAX_ACTIONS_COUNT; i++) + for (i = 0; i < MAX_ACTIONS_COUNT; i++) { + stack[i] = free(stack[i]); stack[i] = malloc(image.columns * image.rows * 4); + } saveCurrentState(); } diff --git a/programs/cmm/iconedit/canvas_resize.h b/programs/cmm/iconedit/canvas_resize.h new file mode 100644 index 0000000000..9db079dcfc --- /dev/null +++ b/programs/cmm/iconedit/canvas_resize.h @@ -0,0 +1,96 @@ + +child_window Window_CanvasReSize = {#CanvasReSize_Thread}; + +//===================================================// +// // +// CODE // +// // +//===================================================// + +char text_columns[4]; +char text_rows[4]; + +edit_box edit_columns = {60,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff, + 0x10000000,sizeof(text_columns)-1,#text_columns,0, 1000000000000010b}; +edit_box edit_rows = {60,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff, + 0x10000000,sizeof(text_rows)-1,#text_rows,0, 1000000000000000b}; + +#define BTN_APPLY 10 + +void CanvasReSize_Thread() +{ + int id, butw; + + sprintf(#text_columns, "%i", image.columns); + sprintf(#text_rows, "%i", image.rows); + edit_columns.size = edit_columns.pos = edit_columns.shift = edit_columns.shift_old = strlen(#text_columns); + edit_rows.size = edit_rows.pos = edit_rows.shift = edit_rows.shift_old = strlen(#text_rows); + + SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); + loop() switch(WaitEvent()) + { + case evMouse: + edit_box_mouse stdcall (#edit_columns); + edit_box_mouse stdcall (#edit_rows); + break; + + case evKey: + GetKeys(); + + if (SCAN_CODE_ESC == key_scancode) ExitProcess(); + if (SCAN_CODE_ENTER == key_scancode) EventApplyClick(); + if (SCAN_CODE_TAB == key_scancode) EventTabClick(); + + EAX= key_ascii << 8; + edit_box_key stdcall (#edit_columns); + edit_box_key stdcall (#edit_rows); + break; + + case evButton: + id = GetButtonID(); + if (CLOSE_BTN == id) ExitProcess(); + if (BTN_APPLY == id) EventApplyClick(); + break; + + case evReDraw: + DefineAndDrawWindow(Form.left+canvas.x + 100, Form.top+skin_height+canvas.y+40, + 200, 170, 0x34, system.color.work, "Canvas", 0); + WriteText(20, 20, 0x90, system.color.work_text, "Width"); + WriteText(20, 60, 0x90, system.color.work_text, "Height"); + DrawStandartCaptButton(20, 100, BTN_APPLY, "OK"); + DrawEditBoxes(); + } +} + +void DrawEditBoxes() +{ + DrawEditBoxPos(20+70, 20-4, #edit_columns); + DrawEditBoxPos(20+70, 60-4, #edit_rows); +} + +//===================================================// +// // +// EVENTS // +// // +//===================================================// + +void EventApplyClick() +{ + int new_rows = atoi(#text_rows); + int new_columns = atoi(#text_columns); + if (new_columns>MAX_CELL_SIZE) || (new_rows>MAX_CELL_SIZE) { + notify("'Maximum icon size exceeded!\nPlease, try something less or equal to 256x256.' -E"); + return; + } + image.create(new_rows, new_columns); + actionsHistory.init(); + ActivateWindow(GetProcessSlot(Form.ID)); + ExitProcess(); +} + +void EventTabClick() +{ + if (edit_columns.flags & 0b10) { edit_columns.flags -= 0b10; edit_rows.flags += 0b10; } + else { edit_columns.flags += 0b10; edit_rows.flags -= 0b10; } + DrawEditBoxes(); +} \ No newline at end of file diff --git a/programs/cmm/iconedit/cursors/bar.cur b/programs/cmm/iconedit/cursors/bar.cur index 279e7556ad8017604c6d2900374a58122d8ed0a8..f072484d33e6805d078b7c70aa7775e2f365bc49 100644 GIT binary patch literal 326 zcmaiuF%H5o3`Kv;z}$s7L<}8~IDkEL;UXLZI&y_>h>cSa2??oEj}*x`4HC2i*m|+Q zBiSDyICxK3T5cV%0#F;?5W`uH@h-WiG8tc0{Zc<#)@Vxw>q=0c1)D|?!bH;iTFwJ|xp~^5GZP CX?K$V literal 766 zcmd5%OA5j;5PhwJ%Xa0uOZOfiUAXZgUc+3YwX4Df*U8infLNC z$polTq3c>~xb8Ku1+XJJq9-b>nE^{LN1F+&RnBA+u}O^M$UO^DpGgvtBqVOA`(MGq zLgcAjBu&u`xQcerRdleQbg*6VwfpOS=i>FbpPIDvs~;lW@7!|!Y{xSqYUiJ5oyQ8| y-Cy+c%&%IXnIn(-v5qjJm?k6Flab5b$Zc3?e;kZIOvd+!IE&a-fv0|jzWD&If4+eL diff --git a/programs/cmm/iconedit/cursors/fill.cur b/programs/cmm/iconedit/cursors/fill.cur index 7dbcfec10c7a525a6740cfaba4428d4957bb71a6..88bb3f082749c2ee596696ecd110426242a7a688 100644 GIT binary patch delta 133 zcmeyzdW=bcfq{vEkwHO$iGi6xfWd%qqJW4ZBLf&fDG-|pA_6A=|NlR+(aGKb$ngN; zEes5dQa}~F3=FJn4Gg@^4h%vE9T>zPG%#>~1d81P$~^(9i2$md0K^GE378&+h5(Ua>RuRRygo@;;};NmQtVch!f7Z ufbq7V>+>tkzatsz{neT3EB8oB%Z>;cq2o_;VY?0@QLAO+u5=SHsf(hZ~m9 zdy31N%0Vjs!&o@094^)E<`6-on0_b(KkpKVy diff --git a/programs/cmm/iconedit/cursors/pipette.cur b/programs/cmm/iconedit/cursors/pipette.cur index 6d5074a3e4e82ab960f5cfea6692b75f94e41e6e..0d15687d650e5b7e511ed55f71b9a7b1b7dc58fd 100644 GIT binary patch delta 138 zcmeyzdW=bcfq{vEkwHNLL<%q%FisQ@QDkHQ11JSzGeJbaV_zkr_+#K*Gn4MxVWF`ypjHkIN|h!soc_4hk=8KPt-*d{%b_oFe7zJ_OE(+q4g4H8-Mk7HAqn|R-j8J2 Xldlc=7RFA3Ufu|ahRLMfQ&4;W&(x;* diff --git a/programs/cmm/iconedit/cursors/rectangle.cur b/programs/cmm/iconedit/cursors/rectangle.cur index 85de8f482d9a57d3e2e8f1a16d102c212b623031..834935e9271ddb1a5c09ac6f78c6a3c86e509eb3 100644 GIT binary patch literal 326 zcmaiuu?@mN3`M_9!3NYtj-d~^^0 aqaYkK-gD*wwV!h}Y&^)}v{7B}iN_0k=y}rs literal 766 zcmd5&F%H5o47?U3#xgNy;xDwz_~L{ z{GKCl0dOT8F%tuh^fYQc3!0=076c%H6uH58@^tp5cEfB0=LlW&1(7Ot}bVZe~L_Q{1nK#~-G4e6Iii literal 766 zcmd5)%MOA-3>?tJ<9hPU(Z7J3pXGkq-uxAh{QyFp(p_G`MB~MQX*!)QEd-!Og{C>< z#OqlD7XVkXAv?0dk&&RchiFBHn3I@AN{O`yHJ?FqqFJaH%>6HLu@Pk}3Gh1?#O+Xg z70bf-dX|an$=~Yl`bF0L!orCBeCpMH#V%jhr`ujcP_@%8JWgxA@mJ^B^Q&IY=0EWP b5?U>M46W|4zYT5QVdh;m9%lB`TiWCofl|!j diff --git a/programs/cmm/iconedit/iconedit.c b/programs/cmm/iconedit/iconedit.c index 17cde8c384..246c405621 100644 --- a/programs/cmm/iconedit/iconedit.c +++ b/programs/cmm/iconedit/iconedit.c @@ -32,7 +32,7 @@ pipet aside color view // // //===================================================// -#define T_TITLE "Icon Editor 0.54.2 Alpha" +#define T_TITLE "Icon Editor 0.55 Alpha" #define TOPBAR_H 24+8 #define LEFTBAR_W 16+5+5+3+3 @@ -86,6 +86,7 @@ enum { BTN_SCREEN_COPY, BTN_ZOOM_IN, BTN_ZOOM_OUT, + BTN_CANVAS_RESIZE, BTNS_PALETTE_COLOR_MAS = 100, BTNS_LAST_USED_COLORS = 400 }; @@ -131,6 +132,7 @@ _image image; _ActionsHistory actionsHistory; #include "tools.h" +#include "canvas_resize.h" //===================================================// // // @@ -188,6 +190,7 @@ void main() loop() switch(WaitEvent()) { case evMouse: + if (Window_CanvasReSize.thread_exists()) break; mouse.get(); if (mouse.lkm) tool_color = color1; @@ -233,6 +236,7 @@ void main() break; case evButton: + if (Window_CanvasReSize.thread_exists()) break; btn = GetButtonID(); if (zoom.click(btn)) DrawEditArea(); @@ -240,7 +244,7 @@ void main() switch(btn) { case BTN_NEW: - EventCleanCanvas(); + EventCreateNewIcon(); break; case BTN_OPEN: RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path)); @@ -293,6 +297,9 @@ void main() case BTN_SCREEN_COPY: setCurrentTool(TOOL_SCREEN_COPY); break; + case BTN_CANVAS_RESIZE: + notify("Sorry, not implemented yet."); + break; case CLOSE_BTN: EventExitIconEdit(); break; @@ -305,6 +312,8 @@ void main() if (currentTool != TOOL_NONE) && (tools[currentTool].onKeyEvent != 0) tools[currentTool].onKeyEvent(key_scancode); + if (key_scancode == SCAN_CODE_DEL) EventCleanCanvas(); + 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); @@ -319,11 +328,12 @@ void main() if (key_scancode == SCAN_CODE_KEY_Y) actionsHistory.redoLastAction(); if (key_scancode == SCAN_CODE_MINUS) {zoom.dec(); DrawEditArea();} - if (key_scancode == SCAN_CODE_PLUS) {zoom.inc(); DrawEditArea();} + if (key_scancode == SCAN_CODE_PLUS) {zoom.inc(); DrawEditArea();} break; case evReDraw: + Window_CanvasReSize.thread_exists(); draw_window(); break; } @@ -352,8 +362,16 @@ void DrawStatusBar() { zoom.draw(wrapper.x, wrapper.y + wrapper.h + 6); - sprintf(#param,"Canvas: %ix%i", image.rows, image.columns); - WriteText(wrapper.x+wrapper.w-calc(strlen(#param)*8), zoom.y+2, 0x90, system.color.work_text, #param); + DrawCaptButton( + wrapper.x+wrapper.w-calc(strlen(#param)*8) +6 - 1, + zoom.y, + calc(strlen(#param)*8)-6, + 18, + BTN_CANVAS_RESIZE, + system.color.work_button, + system.color.work_button_text, + sprintf(#param,"%i x %i", image.rows, image.columns) + ); } void draw_window() @@ -391,20 +409,18 @@ void draw_window() DrawEditArea(); - //BG under LeftBar DrawBar(0, TOPBAR_H, LEFTBAR_W-1, Form.cheight - TOPBAR_H, system.color.work); - //BG under RightBar + DrawLeftPanel(); + DrawBar(wrapper.x+wrapper.w, TOPBAR_H, Form.cwidth-wrapper.x-wrapper.w, Form.cheight - TOPBAR_H, system.color.work); - //BG under StatusBar - DrawBar(LEFTBAR_W-1, wrapper.y + wrapper.h, wrapper.w+1, - Form.cheight - wrapper.y - wrapper.h, system.color.work); - - DrawLeftPanel(); DrawActiveColor(right_bar.y); DrawColorPallets(); - DrawStatusBar(); DrawPreview(); + + DrawBar(LEFTBAR_W-1, wrapper.y + wrapper.h, wrapper.w+1, + Form.cheight - wrapper.y - wrapper.h, system.color.work); + DrawStatusBar(); } void DrawLeftPanel() @@ -608,6 +624,12 @@ void ShowWindow_TestIcon() // // //===================================================// +void EventCreateNewIcon() +{ + EventSaveIconToFile(); + Window_CanvasReSize.create(); +} + void EventSaveIconToFile() { int i=0; @@ -623,8 +645,8 @@ void EventSaveIconToFile() void EventCleanCanvas() { - EventSaveIconToFile(); - image.create(32, 32); + image.create(image.rows, image.columns); + actionsHistory.saveCurrentState(); DrawCanvas(); } diff --git a/programs/cmm/lib/gui.h b/programs/cmm/lib/gui.h index 4683f55c23..3d13329255 100644 --- a/programs/cmm/lib/gui.h +++ b/programs/cmm/lib/gui.h @@ -20,6 +20,8 @@ #include "../lib/gui/tabs.h" #include "../lib/gui/more_less_box.h" #include "../lib/gui/checkbox.h" +#include "../lib/gui/child_window.h" +#include "../lib/gui/text_view_area.h" :int last_free_button_id = 1000; :int GetFreeButtonId() @@ -229,62 +231,6 @@ ESBYTE[next_word_pointer] = '\n'; } -/* -We have a long text and need to show it in block. -Normal line break '\n' must be applied. -Long lines should be breaked by word. -TODO: scroll -*/ -:int DrawTextViewArea(int x,y,w,h, dword buf_start, bg_col, text_col) -{ - dword write_start; - dword buf_end; - int line_h = 15; - int label_length_max; - int write_length; - bool end_found; - - write_start = buf_start; - buf_end = strlen(buf_start) + buf_start; - label_length_max = w / 8; // 8 big font char width - - loop() - { - if (bg_col!=-1) DrawBar(x, y, w+1, line_h, bg_col); - end_found = false; - write_length = strchr(write_start, '\n') - write_start; //search normal line break - if (write_length > label_length_max) || (write_length<=0) //check its position: exceeds maximum line length or not found - { - if (buf_end - write_start < label_length_max) //check does current line the last - { - write_length = buf_end - write_start; - end_found = true; - } - else - { - for (write_length=label_length_max; write_length>0; write_length--) { //search for white space to make the line break - if (ESBYTE[write_start+write_length] == ' ') { - end_found = true; - break; - } - } - } - if (end_found != true) write_length = label_length_max; //no white space, so we write label_length_max - } - ESI = write_length; //set text length attribute for WriteText() - WriteText(x, y, 0x10, text_col, write_start); - // if (editpos >= write_start-buf_start) && (editpos <= write_start-buf_start + write_length) { - // WriteTextB(-write_start+buf_start+editpos * 8 + x - 5 +1, y, 0x90, 0xFF0000, "|"); - // } - write_start += write_length + 1; - y += line_h; - if (write_start >= buf_end) break; - } - if (bg_col!=-1) DrawBar(x,y,w+1,h-y+line_h-4,bg_col); - return y+line_h; -} - - //this function increase falue and return it //useful for list of controls which goes one after one :struct incn diff --git a/programs/cmm/lib/gui/child_window.h b/programs/cmm/lib/gui/child_window.h new file mode 100644 index 0000000000..0b0a64c646 --- /dev/null +++ b/programs/cmm/lib/gui/child_window.h @@ -0,0 +1,23 @@ +:struct child_window +{ + dword window_loop_pointer; + dword id; + char stak[4096]; + void create(); + bool thread_exists(); +}; + +:void child_window::create() +{ + id = CreateThread(window_loop_pointer, #stak+4092); +} + +:bool child_window::thread_exists() +{ + dword proc_slot = GetProcessSlot(id); + if (proc_slot) { + ActivateWindow(proc_slot); + return true; + } + return false; +} \ No newline at end of file diff --git a/programs/cmm/lib/gui/text_view_area.h b/programs/cmm/lib/gui/text_view_area.h new file mode 100644 index 0000000000..c1571bb80b --- /dev/null +++ b/programs/cmm/lib/gui/text_view_area.h @@ -0,0 +1,54 @@ +/* +We have a long text and need to show it in block. +Normal line break '\n' must be applied. +Long lines should be breaked by word. +TODO: scroll +*/ +:int DrawTextViewArea(int x,y,w,h, dword buf_start, bg_col, text_col) +{ + dword write_start; + dword buf_end; + int line_h = 15; + int label_length_max; + int write_length; + bool end_found; + + write_start = buf_start; + buf_end = strlen(buf_start) + buf_start; + label_length_max = w / 8; // 8 big font char width + + loop() + { + if (bg_col!=-1) DrawBar(x, y, w+1, line_h, bg_col); + end_found = false; + write_length = strchr(write_start, '\n') - write_start; //search normal line break + if (write_length > label_length_max) || (write_length<=0) //check its position: exceeds maximum line length or not found + { + if (buf_end - write_start < label_length_max) //check does current line the last + { + write_length = buf_end - write_start; + end_found = true; + } + else + { + for (write_length=label_length_max; write_length>0; write_length--) { //search for white space to make the line break + if (ESBYTE[write_start+write_length] == ' ') { + end_found = true; + break; + } + } + } + if (end_found != true) write_length = label_length_max; //no white space, so we write label_length_max + } + ESI = write_length; //set text length attribute for WriteText() + WriteText(x, y, 0x10, text_col, write_start); + // if (editpos >= write_start-buf_start) && (editpos <= write_start-buf_start + write_length) { + // WriteTextB(-write_start+buf_start+editpos * 8 + x - 5 +1, y, 0x90, 0xFF0000, "|"); + // } + write_start += write_length + 1; + y += line_h; + if (write_start >= buf_end) break; + } + if (bg_col!=-1) DrawBar(x,y,w+1,h-y+line_h-4,bg_col); + return y+line_h; +}