diff --git a/programs/cmm/iconedit/bmp32x32header b/programs/cmm/iconedit/bmp32x32header new file mode 100644 index 0000000000..d2a1d9d780 Binary files /dev/null and b/programs/cmm/iconedit/bmp32x32header differ diff --git a/programs/cmm/iconedit/colors_mas.h b/programs/cmm/iconedit/colors_mas.h index 9c734b561f..77de42fe8f 100644 --- a/programs/cmm/iconedit/colors_mas.h +++ b/programs/cmm/iconedit/colors_mas.h @@ -1,40 +1,23 @@ struct _colors { - int x,y,w,h; + unsigned rows, columns; - unsigned cell_size; - dword mas[MAX_COLORS*MAX_COLORS]; - dword image; - void set_default_values(); - void set_color(); - dword get_color(); + dword mas[32*32]; + dword img; + void set_pixel(); + dword get_pixel(); dword get_image(); - void draw_cell(); - void draw_all_cells(); void move(); }; -void _colors::set_default_values() +void _colors::set_pixel(int _r, _c, _color) { - int i; - - columns = MAX_COLORS; - rows = MAX_COLORS; - cell_size = 5; - w = columns * cell_size; - h = rows * cell_size; - - for (i = 0; i < columns*rows; i++) mas[i]=0xBFCAD2; + mas[columns*_r + _c] = _color; } -void _colors::set_color(int _r, _c, _color) +dword _colors::get_pixel(int _r, _c) { - mas[MAX_COLORS*_r + _c] = _color; -} - -dword _colors::get_color(int _r, _c) -{ - return mas[MAX_COLORS*_r + _c]; + return mas[columns*_r + _c]; } dword _colors::get_image() @@ -42,93 +25,86 @@ dword _colors::get_image() int r=0, c=0; dword i; - free(image); - i = image = malloc(rows*columns*3); + free(img); + i = img = malloc(rows*columns*3); for (r = 0; r < rows; r++) { for (c = 0; c < columns; c++) { - rgb.DwordToRgb(get_color(r,c)); + rgb.DwordToRgb(get_pixel(r,c)); ESBYTE[i] = rgb.b; ESBYTE[i+1] = rgb.g; ESBYTE[i+2] = rgb.r; i += 3; } } - return image; -} - -void _colors::draw_cell(int _x, _y, _color) -{ - //DrawRectangle(_x, _y, cell_size, cell_size, system.color.work_graph); - //DrawBar(_x+1, _y+1, cell_size-1, cell_size-1, _color); - DrawBar(_x, _y, cell_size, cell_size, _color); -} - -void _colors::draw_all_cells() -{ - int r, c, i; - for (i=300; i 0; c--) set_color(r, c, get_color(r, c-1)); - set_color(r, 0, first_element_data); + first_element_data = get_pixel(r, columns-1); + for (c = columns-1; c > 0; c--) set_pixel(r, c, get_pixel(r, c-1)); + set_pixel(r, 0, first_element_data); } } - if (direction == DIRECTION_UP) + if (_direction == MOVE_UP) { for (c = 0; c < columns; c++) { - first_element_data = get_color(0, c); - for (r = 0; r < rows-1; r++) set_color(r, c, get_color(r+1, c)); - set_color(rows-1, c, first_element_data); + first_element_data = get_pixel(0, c); + for (r = 0; r < rows-1; r++) set_pixel(r, c, get_pixel(r+1, c)); + set_pixel(rows-1, c, first_element_data); } } - if (direction == DIRECTION_DOWN) + if (_direction == MOVE_DOWN) { for (c = 0; c < columns; c++) { - first_element_data = get_color(rows-1, c); - for (r = rows-1; r > 0; r--) set_color(r, c, get_color(r-1, c)); - set_color(0, c, first_element_data); + first_element_data = get_pixel(rows-1, c); + for (r = rows-1; r > 0; r--) set_pixel(r, c, get_pixel(r-1, c)); + set_pixel(0, c, first_element_data); } } - draw_all_cells(); + + if (_direction == FLIP_HOR) + { + for (r = 0; r < rows; r++) + { + for (c = 0; c < columns/2; c++) { + first_element_data = get_pixel(r, c); + set_pixel(r, c, get_pixel(r, columns-c)); + set_pixel(r, columns-c, first_element_data); + } + } + } } diff --git a/programs/cmm/iconedit/compile_en.bat b/programs/cmm/iconedit/compile_en.bat index 0a5e78f959..3672d0c74b 100644 --- a/programs/cmm/iconedit/compile_en.bat +++ b/programs/cmm/iconedit/compile_en.bat @@ -1,5 +1,13 @@ -@del *. +@del iconedit @c-- iconedit.c @rename *.com *. @del warning.txt -@pause \ No newline at end of file + + +if exist iconedit ( + "C:\Program Files (x86)\WinImage\winimage.exe" "C:\Users\Leency\Desktop\kolibri.img" /H /Q /I iconedit + cd D:\Kolibri\Infrastructure\QEMU + call "D:\Kolibri\Infrastructure\QEMU\qemu-kos-img.bat" +) else ( + @pause +) diff --git a/programs/cmm/iconedit/iconedit.c b/programs/cmm/iconedit/iconedit.c index a46d3a1b20..1b21969487 100644 --- a/programs/cmm/iconedit/iconedit.c +++ b/programs/cmm/iconedit/iconedit.c @@ -4,27 +4,39 @@ * Licence: GPL v2 */ +/* +TODO/BUGS +Flip first pixel doesn't work well +Open with param +Set minimal window size +Scroll mouse, +/- keyboard +*/ + #define MEMSIZE 4096*40 #include "../lib/gui.h" +#include "../lib/random.h" +#include "../lib/mem.h" #include "../lib/obj/libimg.h" #include "../lib/patterns/rgb.h" #include "../lib/patterns/libimg_load_skin.h" +#include "colors_mas.h" + //===================================================// // // // DATA // // // //===================================================// -#define T_TITLE "Icon Editor 0.05" +#define T_TITLE "Icon Editor 0.08" -#define MAX_COLORS 32 -#define TOOLBAR_H 24+8 +#define TOOLBAR_H 24+9 #define PALLETE_SIZE 116 -rect wrapper = { 10, TOOLBAR_H+5, NULL, NULL }; -rect right_bar = { NULL, TOOLBAR_H+5, 280, NULL }; +rect wrapper = { 10, TOOLBAR_H, NULL, NULL }; +rect right_bar = { NULL, TOOLBAR_H, 280, NULL }; +rect canvas = { NULL, NULL, NULL, NULL }; dword active_color_1 = 0x000000; dword active_color_2 = 0xFFFfff; @@ -49,7 +61,9 @@ proc_info Form; bool pick_active = false; -more_less_box zoom = { NULL, NULL, NULL, 1, MAX_COLORS, 22, 23, "Zoom" }; +#define ZOOM_IN 22 +#define ZOOM_OUT 23 +more_less_box zoom = { NULL, NULL, 11, 1, 40, ZOOM_IN, ZOOM_OUT, "Zoom" }; dword palette_colors[] = { 0x330000,0x331900,0x333300,0x193300,0x003300,0x003319,0x003333,0x001933,0x000033,0x190033,0x330033,0x330019,0x000000, @@ -63,6 +77,9 @@ dword palette_colors[] = { 0xFFCCCC,0xFFE5CC,0xFFFFCC,0xE5FFCC,0xCCFFCC,0xCCFFE5,0xCCFFFF,0xCCE5FF,0xCCCCFF,0xE5CCFF,0xFFCCFF,0xFFCCE5,0xFFFFFF }; +_colors image; + +libimg_image open_image; //===================================================// // // @@ -70,9 +87,6 @@ dword palette_colors[] = { // // //===================================================// -#include "colors_mas.h" -_colors canvas; - void main() { word btn; @@ -81,8 +95,19 @@ void main() load_dll(libimg, #libimg_init, 1); Libimg_LoadImage(#skin, "/sys/icons16.png"); - canvas.set_default_values(); - zoom.value = canvas.cell_size; + CreateCanvas(); + + /* + if (param) { + Libimg_LoadImage(#open_image, #param); + if (open_image.w==32) && (open_image.h==32) { + memmov(#image.mas, open_image.image, 32*32*3); + } + else { + notify("'Error: image format is unacceptable.\nOnly images created in IconEditor (BMP, 32x32x16b) can be opened!' -E"); + } + } + */ SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); @@ -92,13 +117,14 @@ void main() mouse.get(); if (pick_active) EventPickColor(mouse.lkm, mouse.pkm); else { - if (mouse.lkm) - && (mouse.x>canvas.x) && (mouse.y>canvas.y) + if (mouse.x>canvas.x) && (mouse.y>canvas.y) && (mouse.y= BTN_PALETTE_COLOR_MAS) && (btn < BTN_PALETTE_COLOR_MAS+PALLETE_SIZE) { - active_color_1 = palette_colors[btn-BTN_PALETTE_COLOR_MAS]; + if (mouse.lkm) active_color_1 = palette_colors[btn-BTN_PALETTE_COLOR_MAS]; + if (mouse.pkm) active_color_2 = palette_colors[btn-BTN_PALETTE_COLOR_MAS]; DrawActiveColor(NULL); } - if (zoom.click(btn)) EventZoom(); + if (zoom.click(btn)) DrawEditArea(); break; case evKey: GetKeys(); - if (key_scancode == SCAN_CODE_ESC) ExitProcess(); + if (key_scancode == SCAN_CODE_ESC) pick_active=false; if (key_scancode == SCAN_CODE_KEY_I) EventPickActivate(); break; @@ -158,7 +207,7 @@ void DrawStatusBar() zoom.x = wrapper.x; zoom.draw(); - sprintf(#param,"Canvas: %ix%i", canvas.rows, canvas.columns); + 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); } @@ -167,14 +216,14 @@ void draw_window() #define TB_ICON_PADDING 26 incn tx; system.color.get(); - DefineAndDrawWindow(215, 100, 700, 540, 0x33, system.color.work, T_TITLE, 0); + DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x33, system.color.work, T_TITLE, 0); GetProcessInfo(#Form, SelfInfo); right_bar.x = Form.cwidth - right_bar.w; tx.n = wrapper.x - TB_ICON_PADDING; DrawToolbarButton(BTN_NEW, tx.inc(TB_ICON_PADDING), 2); //not implemented DrawToolbarButton(BTN_OPEN, tx.inc(TB_ICON_PADDING), 0); //not implemented - DrawToolbarButton(BTN_SAVE, tx.inc(TB_ICON_PADDING), 5); //not implemented + DrawToolbarButton(BTN_SAVE, tx.inc(TB_ICON_PADDING), 5); DrawToolbarButton(BTN_MOVE_LEFT, tx.inc(TB_ICON_PADDING+8), 30); DrawToolbarButton(BTN_MOVE_RIGHT, tx.inc(TB_ICON_PADDING), 31); DrawToolbarButton(BTN_MOVE_UP, tx.inc(TB_ICON_PADDING), 32); @@ -190,12 +239,12 @@ void draw_window() DrawEditArea(); DrawDefaultColors(right_bar.x, right_bar.y); - DrawActiveColor(Form.cheight-40); + DrawActiveColor(right_bar.y + 200); DrawStatusBar(); } -:void DrawEditArea() +void DrawEditArea() { dword color1=0xC0C0C0; int left_padding; @@ -205,10 +254,17 @@ void draw_window() wrapper.h = Form.cheight - TOOLBAR_H - 35; //canvas{ - canvas.x = -canvas.cell_size*canvas.columns+wrapper.w/2 + wrapper.x; - canvas.y = -canvas.cell_size*canvas.rows+wrapper.h/2 + wrapper.y; + canvas.w = image.columns * zoom.value; + canvas.h = image.rows * zoom.value; + if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) { + zoom.value--; + DrawEditArea(); + return; + } + canvas.x = -zoom.value*image.columns+wrapper.w/2 + wrapper.x; + canvas.y = -zoom.value*image.rows+wrapper.h/2 + wrapper.y; DrawRectangle(canvas.x-1, canvas.y-1, canvas.w+1, canvas.h+1, 0x808080); - canvas.draw_all_cells(); + DrawCanvas(); //} left_padding = canvas.x-wrapper.x-1; @@ -218,13 +274,13 @@ void draw_window() if (left_padding>0) { - DrawBar(wrapper.x, wrapper.y, wrapper.w, top_padding, color1); - DrawBar(wrapper.x, wrapper.y+wrapper.h-top_padding, wrapper.w, top_padding, color1); + DrawBar(wrapper.x, wrapper.y, wrapper.w, top_padding, color1); //top + DrawBar(wrapper.x, wrapper.y+wrapper.h-top_padding, wrapper.w, top_padding, color1); //bottom } if (top_padding>0) { - DrawBar(wrapper.x, wrapper.y+left_padding, left_padding, wrapper.h-left_padding-left_padding, color1); - DrawBar(wrapper.x+wrapper.w-left_padding, wrapper.y+left_padding, left_padding, wrapper.h-left_padding-left_padding, color1); + DrawBar(wrapper.x, wrapper.y+top_padding, left_padding, wrapper.h-top_padding-top_padding, color1); //left + DrawBar(wrapper.x+wrapper.w-left_padding, wrapper.y+top_padding, left_padding, wrapper.h-top_padding-top_padding, color1); //right } } @@ -236,6 +292,11 @@ void DrawActiveColor(dword iny) sprintf(#param, "%A", active_color_1); EDI = system.color.work; WriteText(right_bar.x + 30, outy + 3, 0xD0, system.color.work_text, #param+4); + + DrawBar(right_bar.x+110, outy, 20, 20, active_color_2); + sprintf(#param, "%A", active_color_2); + EDI = system.color.work; + WriteText(right_bar.x+110 + 30, outy + 3, 0xD0, system.color.work_text, #param+4); } void DrawDefaultColors(dword _x, _y) @@ -280,15 +341,39 @@ void EventPickColor(dword lkm_status, pkm_status) } } -void EventZoom() +dword bmp_32x32x16_header[] = FROM "bmp32x32header"; +void EventSave() { - canvas.cell_size = zoom.value; - canvas.w = canvas.columns * canvas.cell_size; - canvas.h = canvas.rows * canvas.cell_size; - if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) { - zoom.click(23); - EventZoom(); - return; + char save_buf[3126]; + dword image_buf = image.get_image(); + memmov(#save_buf, #bmp_32x32x16_header, sizeof(bmp_32x32x16_header)); + memmov(#save_buf+sizeof(bmp_32x32x16_header), image_buf, sizeof(save_buf)-sizeof(bmp_32x32x16_header)); + if (WriteFile(sizeof(save_buf), #save_buf, "/rd/1/saved_image.bmp")==0) + { + notify("'File saved as /rd/1/saved_image.bmp' -O"); + } + else { + notify("'Error saving BPM file, probably not enought space on ramdisk!' -E"); } - DrawEditArea(); } + +void CreateCanvas() +{ + int i; + image.columns = 32; + image.rows = 32; + for (i = 0; i < image.columns*image.rows; i++) image.mas[i]=0xBFCAD2; +} + +void DrawCanvas() +{ + int r, c; + for (r = 0; r < image.rows; r++) + { + for (c = 0; c < image.columns; c++) + { + DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y, + zoom.value, zoom.value, image.get_pixel(r, c)); + } + } +} \ No newline at end of file