PixelEditor 0.08: work in progress

git-svn-id: svn://kolibrios.org@7151 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2018-02-07 22:09:46 +00:00
parent b29e17d01d
commit 9b41f854fe
4 changed files with 188 additions and 119 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 B

View File

@ -1,40 +1,23 @@
struct _colors struct _colors
{ {
int x,y,w,h;
unsigned rows, columns; unsigned rows, columns;
unsigned cell_size; dword mas[32*32];
dword mas[MAX_COLORS*MAX_COLORS]; dword img;
dword image; void set_pixel();
void set_default_values(); dword get_pixel();
void set_color();
dword get_color();
dword get_image(); dword get_image();
void draw_cell();
void draw_all_cells();
void move(); void move();
}; };
void _colors::set_default_values() void _colors::set_pixel(int _r, _c, _color)
{ {
int i; mas[columns*_r + _c] = _color;
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;
} }
void _colors::set_color(int _r, _c, _color) dword _colors::get_pixel(int _r, _c)
{ {
mas[MAX_COLORS*_r + _c] = _color; return mas[columns*_r + _c];
}
dword _colors::get_color(int _r, _c)
{
return mas[MAX_COLORS*_r + _c];
} }
dword _colors::get_image() dword _colors::get_image()
@ -42,93 +25,86 @@ dword _colors::get_image()
int r=0, c=0; int r=0, c=0;
dword i; dword i;
free(image); free(img);
i = image = malloc(rows*columns*3); i = img = malloc(rows*columns*3);
for (r = 0; r < rows; r++) for (r = 0; r < rows; r++)
{ {
for (c = 0; c < columns; c++) for (c = 0; c < columns; c++)
{ {
rgb.DwordToRgb(get_color(r,c)); rgb.DwordToRgb(get_pixel(r,c));
ESBYTE[i] = rgb.b; ESBYTE[i] = rgb.b;
ESBYTE[i+1] = rgb.g; ESBYTE[i+1] = rgb.g;
ESBYTE[i+2] = rgb.r; ESBYTE[i+2] = rgb.r;
i += 3; i += 3;
} }
} }
return image; return img;
}
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<MAX_COLORS*MAX_COLORS+300; i++) DeleteButton(i);
for (r = 0; r < rows; r++)
{
for (c = 0; c < columns; c++)
{
draw_cell(c*cell_size + x, r*cell_size + y, get_color(r, c));
//DefineHiddenButton(c*cell_size + x, r*cell_size + y, cell_size, cell_size, r*columns+c+300+BT_NOFRAME);
}
}
} }
enum { enum {
DIRECTION_LEFT, MOVE_LEFT,
DIRECTION_RIGHT, MOVE_RIGHT,
DIRECTION_UP, MOVE_UP,
DIRECTION_DOWN MOVE_DOWN,
FLIP_VER,
FLIP_HOR,
ROTE
}; };
void _colors::move(int direction) void _colors::move(int _direction)
{ {
int r, c; int r, c;
dword first_element_data; dword first_element_data;
if (direction == DIRECTION_LEFT) if (_direction == MOVE_LEFT)
{ {
for (r = 0; r < rows; r++) for (r = 0; r < rows; r++)
{ {
first_element_data = get_color(r, 0); first_element_data = get_pixel(r, 0);
for (c = 0; c < columns-1; c++) set_color(r, c, get_color(r, c+1)); for (c = 0; c < columns-1; c++) set_pixel(r, c, get_pixel(r, c+1));
set_color(r, columns-1, first_element_data); set_pixel(r, columns-1, first_element_data);
} }
} }
if (direction == DIRECTION_RIGHT) if (_direction == MOVE_RIGHT)
{ {
for (r = 0; r < rows; r++) for (r = 0; r < rows; r++)
{ {
first_element_data = get_color(r, columns-1); first_element_data = get_pixel(r, columns-1);
for (c = columns-1; c > 0; c--) set_color(r, c, get_color(r, c-1)); for (c = columns-1; c > 0; c--) set_pixel(r, c, get_pixel(r, c-1));
set_color(r, 0, first_element_data); set_pixel(r, 0, first_element_data);
} }
} }
if (direction == DIRECTION_UP) if (_direction == MOVE_UP)
{ {
for (c = 0; c < columns; c++) for (c = 0; c < columns; c++)
{ {
first_element_data = get_color(0, c); first_element_data = get_pixel(0, c);
for (r = 0; r < rows-1; r++) set_color(r, c, get_color(r+1, c)); for (r = 0; r < rows-1; r++) set_pixel(r, c, get_pixel(r+1, c));
set_color(rows-1, c, first_element_data); set_pixel(rows-1, c, first_element_data);
} }
} }
if (direction == DIRECTION_DOWN) if (_direction == MOVE_DOWN)
{ {
for (c = 0; c < columns; c++) for (c = 0; c < columns; c++)
{ {
first_element_data = get_color(rows-1, c); first_element_data = get_pixel(rows-1, c);
for (r = rows-1; r > 0; r--) set_color(r, c, get_color(r-1, c)); for (r = rows-1; r > 0; r--) set_pixel(r, c, get_pixel(r-1, c));
set_color(0, c, first_element_data); 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);
}
}
}
} }

View File

@ -1,5 +1,13 @@
@del *. @del iconedit
@c-- iconedit.c @c-- iconedit.c
@rename *.com *. @rename *.com *.
@del warning.txt @del warning.txt
@pause
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
)

View File

@ -4,27 +4,39 @@
* Licence: GPL v2 * 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 #define MEMSIZE 4096*40
#include "../lib/gui.h" #include "../lib/gui.h"
#include "../lib/random.h"
#include "../lib/mem.h"
#include "../lib/obj/libimg.h" #include "../lib/obj/libimg.h"
#include "../lib/patterns/rgb.h" #include "../lib/patterns/rgb.h"
#include "../lib/patterns/libimg_load_skin.h" #include "../lib/patterns/libimg_load_skin.h"
#include "colors_mas.h"
//===================================================// //===================================================//
// // // //
// DATA // // DATA //
// // // //
//===================================================// //===================================================//
#define T_TITLE "Icon Editor 0.05" #define T_TITLE "Icon Editor 0.08"
#define MAX_COLORS 32 #define TOOLBAR_H 24+9
#define TOOLBAR_H 24+8
#define PALLETE_SIZE 116 #define PALLETE_SIZE 116
rect wrapper = { 10, TOOLBAR_H+5, NULL, NULL }; rect wrapper = { 10, TOOLBAR_H, NULL, NULL };
rect right_bar = { NULL, TOOLBAR_H+5, 280, NULL }; rect right_bar = { NULL, TOOLBAR_H, 280, NULL };
rect canvas = { NULL, NULL, NULL, NULL };
dword active_color_1 = 0x000000; dword active_color_1 = 0x000000;
dword active_color_2 = 0xFFFfff; dword active_color_2 = 0xFFFfff;
@ -49,7 +61,9 @@ proc_info Form;
bool pick_active = false; 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[] = { dword palette_colors[] = {
0x330000,0x331900,0x333300,0x193300,0x003300,0x003319,0x003333,0x001933,0x000033,0x190033,0x330033,0x330019,0x000000, 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 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() void main()
{ {
word btn; word btn;
@ -81,8 +95,19 @@ void main()
load_dll(libimg, #libimg_init, 1); load_dll(libimg, #libimg_init, 1);
Libimg_LoadImage(#skin, "/sys/icons16.png"); Libimg_LoadImage(#skin, "/sys/icons16.png");
canvas.set_default_values(); CreateCanvas();
zoom.value = canvas.cell_size;
/*
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); SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
@ -92,13 +117,14 @@ void main()
mouse.get(); mouse.get();
if (pick_active) EventPickColor(mouse.lkm, mouse.pkm); if (pick_active) EventPickColor(mouse.lkm, mouse.pkm);
else { else {
if (mouse.lkm) if (mouse.x>canvas.x) && (mouse.y>canvas.y)
&& (mouse.x>canvas.x) && (mouse.y>canvas.y)
&& (mouse.y<canvas.y+canvas.h) && (mouse.x<canvas.x+canvas.w) && (mouse.y<canvas.y+canvas.h) && (mouse.x<canvas.x+canvas.w)
{ {
canvas.set_color(mouse.y-canvas.y/canvas.cell_size, if (mouse.lkm) image.set_pixel(mouse.y-canvas.y/zoom.value,
mouse.x-canvas.x/canvas.cell_size, active_color_1); mouse.x-canvas.x/zoom.value, active_color_1);
canvas.draw_all_cells(); if (mouse.pkm) image.set_pixel(mouse.y-canvas.y/zoom.value,
mouse.x-canvas.x/zoom.value, active_color_2);
DrawCanvas();
} }
} }
break; break;
@ -107,17 +133,39 @@ void main()
btn = GetButtonID(); btn = GetButtonID();
switch(btn) switch(btn)
{ {
case BTN_NEW:
CreateCanvas();
DrawCanvas();
break;
case BTN_OPEN:
RunProgram("/sys/lod", sprintf(#param, "*bmp* %s",#program_path));
break;
case BTN_SAVE:
EventSave();
break;
case BTN_MOVE_LEFT: case BTN_MOVE_LEFT:
canvas.move(DIRECTION_LEFT); image.move(MOVE_LEFT);
DrawCanvas();
break; break;
case BTN_MOVE_RIGHT: case BTN_MOVE_RIGHT:
canvas.move(DIRECTION_RIGHT); image.move(MOVE_RIGHT);
DrawCanvas();
break; break;
case BTN_MOVE_UP: case BTN_MOVE_UP:
canvas.move(DIRECTION_UP); image.move(MOVE_UP);
DrawCanvas();
break; break;
case BTN_MOVE_DOWN: case BTN_MOVE_DOWN:
canvas.move(DIRECTION_DOWN); image.move(MOVE_DOWN);
DrawCanvas();
break;
case BTN_FLIP_VER:
image.move(FLIP_VER);
DrawCanvas();
break;
case BTN_FLIP_HOR:
image.move(FLIP_HOR);
DrawCanvas();
break; break;
case CLOSE_BTN: case CLOSE_BTN:
ExitProcess(); ExitProcess();
@ -127,15 +175,16 @@ void main()
} }
if (btn >= BTN_PALETTE_COLOR_MAS) && (btn < BTN_PALETTE_COLOR_MAS+PALLETE_SIZE) if (btn >= 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); DrawActiveColor(NULL);
} }
if (zoom.click(btn)) EventZoom(); if (zoom.click(btn)) DrawEditArea();
break; break;
case evKey: case evKey:
GetKeys(); 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(); if (key_scancode == SCAN_CODE_KEY_I) EventPickActivate();
break; break;
@ -158,7 +207,7 @@ void DrawStatusBar()
zoom.x = wrapper.x; zoom.x = wrapper.x;
zoom.draw(); 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); 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 #define TB_ICON_PADDING 26
incn tx; incn tx;
system.color.get(); 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); GetProcessInfo(#Form, SelfInfo);
right_bar.x = Form.cwidth - right_bar.w; right_bar.x = Form.cwidth - right_bar.w;
tx.n = wrapper.x - TB_ICON_PADDING; tx.n = wrapper.x - TB_ICON_PADDING;
DrawToolbarButton(BTN_NEW, tx.inc(TB_ICON_PADDING), 2); //not implemented DrawToolbarButton(BTN_NEW, tx.inc(TB_ICON_PADDING), 2); //not implemented
DrawToolbarButton(BTN_OPEN, tx.inc(TB_ICON_PADDING), 0); //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_LEFT, tx.inc(TB_ICON_PADDING+8), 30);
DrawToolbarButton(BTN_MOVE_RIGHT, tx.inc(TB_ICON_PADDING), 31); DrawToolbarButton(BTN_MOVE_RIGHT, tx.inc(TB_ICON_PADDING), 31);
DrawToolbarButton(BTN_MOVE_UP, tx.inc(TB_ICON_PADDING), 32); DrawToolbarButton(BTN_MOVE_UP, tx.inc(TB_ICON_PADDING), 32);
@ -190,12 +239,12 @@ void draw_window()
DrawEditArea(); DrawEditArea();
DrawDefaultColors(right_bar.x, right_bar.y); DrawDefaultColors(right_bar.x, right_bar.y);
DrawActiveColor(Form.cheight-40); DrawActiveColor(right_bar.y + 200);
DrawStatusBar(); DrawStatusBar();
} }
:void DrawEditArea() void DrawEditArea()
{ {
dword color1=0xC0C0C0; dword color1=0xC0C0C0;
int left_padding; int left_padding;
@ -205,10 +254,17 @@ void draw_window()
wrapper.h = Form.cheight - TOOLBAR_H - 35; wrapper.h = Form.cheight - TOOLBAR_H - 35;
//canvas{ //canvas{
canvas.x = -canvas.cell_size*canvas.columns+wrapper.w/2 + wrapper.x; canvas.w = image.columns * zoom.value;
canvas.y = -canvas.cell_size*canvas.rows+wrapper.h/2 + wrapper.y; 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); 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; left_padding = canvas.x-wrapper.x-1;
@ -218,13 +274,13 @@ void draw_window()
if (left_padding>0) if (left_padding>0)
{ {
DrawBar(wrapper.x, wrapper.y, 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); DrawBar(wrapper.x, wrapper.y+wrapper.h-top_padding, wrapper.w, top_padding, color1); //bottom
} }
if (top_padding>0) if (top_padding>0)
{ {
DrawBar(wrapper.x, 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+left_padding, left_padding, wrapper.h-left_padding-left_padding, color1); 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); sprintf(#param, "%A", active_color_1);
EDI = system.color.work; EDI = system.color.work;
WriteText(right_bar.x + 30, outy + 3, 0xD0, system.color.work_text, #param+4); 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) 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; char save_buf[3126];
canvas.w = canvas.columns * canvas.cell_size; dword image_buf = image.get_image();
canvas.h = canvas.rows * canvas.cell_size; memmov(#save_buf, #bmp_32x32x16_header, sizeof(bmp_32x32x16_header));
if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) { memmov(#save_buf+sizeof(bmp_32x32x16_header), image_buf, sizeof(save_buf)-sizeof(bmp_32x32x16_header));
zoom.click(23); if (WriteFile(sizeof(save_buf), #save_buf, "/rd/1/saved_image.bmp")==0)
EventZoom(); {
return; notify("'File saved as /rd/1/saved_image.bmp' -O");
}
else {
notify("'Error saving BPM file, probably not enought space on ramdisk!' -E");
}
}
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));
}
} }
DrawEditArea();
} }