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
{
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<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);
}
}
return img;
}
enum {
DIRECTION_LEFT,
DIRECTION_RIGHT,
DIRECTION_UP,
DIRECTION_DOWN
MOVE_LEFT,
MOVE_RIGHT,
MOVE_UP,
MOVE_DOWN,
FLIP_VER,
FLIP_HOR,
ROTE
};
void _colors::move(int direction)
void _colors::move(int _direction)
{
int r, c;
dword first_element_data;
if (direction == DIRECTION_LEFT)
if (_direction == MOVE_LEFT)
{
for (r = 0; r < rows; r++)
{
first_element_data = get_color(r, 0);
for (c = 0; c < columns-1; c++) set_color(r, c, get_color(r, c+1));
set_color(r, columns-1, first_element_data);
first_element_data = get_pixel(r, 0);
for (c = 0; c < columns-1; c++) set_pixel(r, c, get_pixel(r, c+1));
set_pixel(r, columns-1, first_element_data);
}
}
if (direction == DIRECTION_RIGHT)
if (_direction == MOVE_RIGHT)
{
for (r = 0; r < rows; r++)
{
first_element_data = get_color(r, columns-1);
for (c = columns-1; c > 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);
}
}
}
}

View File

@ -1,5 +1,13 @@
@del *.
@del iconedit
@c-- iconedit.c
@rename *.com *.
@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
*/
/*
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<canvas.y+canvas.h) && (mouse.x<canvas.x+canvas.w)
{
canvas.set_color(mouse.y-canvas.y/canvas.cell_size,
mouse.x-canvas.x/canvas.cell_size, active_color_1);
canvas.draw_all_cells();
if (mouse.lkm) image.set_pixel(mouse.y-canvas.y/zoom.value,
mouse.x-canvas.x/zoom.value, active_color_1);
if (mouse.pkm) image.set_pixel(mouse.y-canvas.y/zoom.value,
mouse.x-canvas.x/zoom.value, active_color_2);
DrawCanvas();
}
}
break;
@ -107,17 +133,39 @@ void main()
btn = GetButtonID();
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:
canvas.move(DIRECTION_LEFT);
image.move(MOVE_LEFT);
DrawCanvas();
break;
case BTN_MOVE_RIGHT:
canvas.move(DIRECTION_RIGHT);
image.move(MOVE_RIGHT);
DrawCanvas();
break;
case BTN_MOVE_UP:
canvas.move(DIRECTION_UP);
image.move(MOVE_UP);
DrawCanvas();
break;
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;
case CLOSE_BTN:
ExitProcess();
@ -127,15 +175,16 @@ void main()
}
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);
}
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));
}
}
}