2017-10-12 01:19:28 +02:00
|
|
|
|
/*
|
2018-02-08 17:47:35 +01:00
|
|
|
|
* Icon Editor for KolibriOS
|
2018-03-15 20:19:53 +01:00
|
|
|
|
* Authors: Leency, Nicolas
|
2017-10-12 01:19:28 +02:00
|
|
|
|
* Licence: GPL v2
|
|
|
|
|
*/
|
|
|
|
|
|
2018-11-01 22:48:33 +01:00
|
|
|
|
#define MEMSIZE 1024*2000
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
|
|
|
|
#include "../lib/gui.h"
|
2018-02-07 23:09:46 +01:00
|
|
|
|
#include "../lib/random.h"
|
|
|
|
|
#include "../lib/mem.h"
|
2018-04-29 22:42:03 +02:00
|
|
|
|
#include "../lib/cursor.h"
|
2018-10-10 16:44:01 +02:00
|
|
|
|
#include "../lib/list_box.h"
|
2018-11-01 22:48:33 +01:00
|
|
|
|
#include "../lib/events.h"
|
2018-04-22 21:00:01 +02:00
|
|
|
|
|
2017-10-17 01:41:50 +02:00
|
|
|
|
#include "../lib/obj/libimg.h"
|
2018-04-22 21:00:01 +02:00
|
|
|
|
#include "../lib/obj/box_lib.h"
|
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
|
#include "../lib/patterns/rgb.h"
|
2021-06-12 10:58:31 +02:00
|
|
|
|
#include "../lib/patterns/toolbar_button.h"
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2018-02-07 23:09:46 +01:00
|
|
|
|
#include "colors_mas.h"
|
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
|
//===================================================//
|
|
|
|
|
// //
|
|
|
|
|
// DATA //
|
|
|
|
|
// //
|
|
|
|
|
//===================================================//
|
|
|
|
|
|
2018-09-14 11:49:37 +02:00
|
|
|
|
#ifdef LANG_RUS
|
2020-05-24 18:46:26 +02:00
|
|
|
|
char edit_menu_items[] =
|
|
|
|
|
"<EFBFBD><EFBFBD>१<EFBFBD><EFBFBD><EFBFBD>|Ctrl+X
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>|Ctrl+C
|
|
|
|
|
<EFBFBD><EFBFBD>⠢<EFBFBD><EFBFBD><EFBFBD>|Ctrl+V";
|
2018-10-10 16:44:01 +02:00
|
|
|
|
char image_menu_items[] =
|
2021-06-12 10:58:31 +02:00
|
|
|
|
"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⢮ 㭨<><E3ADA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 梥⮢
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> 梥<EFBFBD><EFBFBD> 1 <EFBFBD><EFBFBD> 2
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
2018-10-10 16:44:01 +02:00
|
|
|
|
?define T_MENU_IMAGE "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
2021-06-12 10:58:31 +02:00
|
|
|
|
?define T_TEST_ICON "<EFBFBD><EFBFBD>ઠ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
2020-11-27 00:29:40 +01:00
|
|
|
|
?define T_TITLE "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0.70a Beta"
|
2020-04-25 16:36:28 +02:00
|
|
|
|
?define T_UNIC_COLORS_COUNT "'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 梥⮢: %i.' -I"
|
|
|
|
|
?define T_TOO_BIG_IMAGE_FOR_PREVIEW "'IconEdit
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ࠦ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 誮<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>讥 <EFBFBD><EFBFBD><EFBFBD> <EFBFBD>।<EFBFBD><EFBFBD><EFBFBD>ᬮ<EFBFBD><EFBFBD><EFBFBD>!' -tE"
|
|
|
|
|
?define T_ERROR_CROP_TOOL "'<27><><EFBFBD> <20><>१<EFBFBD><E0A5A7> <20><><EFBFBD><EFBFBD>ࠦ<EFBFBD><E0A0A6><EFBFBD><EFBFBD> <20><><EFBFBD>砫<EFBFBD> <20>㦭<EFBFBD> <20>뤥<EFBFBD><EBA4A5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.' -W"
|
|
|
|
|
?define T_ERROR_IMA_ICONEDIT "'<27><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ।<><E0A5A4><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>࠭<EFBFBD><E0A0AD>
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ࠦ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 誮<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>!' -E"
|
2018-09-14 11:49:37 +02:00
|
|
|
|
#else
|
2020-05-24 18:46:26 +02:00
|
|
|
|
char edit_menu_items[] =
|
|
|
|
|
"Cut|Ctrl+X
|
|
|
|
|
Copy|Ctrl+C
|
|
|
|
|
Paste|Ctrl+V";
|
2018-10-10 16:44:01 +02:00
|
|
|
|
char image_menu_items[] =
|
2021-06-12 10:58:31 +02:00
|
|
|
|
"Count unic colors used
|
|
|
|
|
Replace all colors equal to 1 by 2
|
|
|
|
|
Test icon";
|
2018-10-10 16:44:01 +02:00
|
|
|
|
?define T_MENU_IMAGE "Icon"
|
|
|
|
|
?define T_TEST_ICON "Test Icon"
|
2020-05-24 18:46:26 +02:00
|
|
|
|
?define T_TITLE "Icon Editor 0.70 Beta"
|
2020-04-25 16:36:28 +02:00
|
|
|
|
?define T_UNIC_COLORS_COUNT "'Image has %i unique colors.' -I"
|
|
|
|
|
?define T_TOO_BIG_IMAGE_FOR_PREVIEW "'IconEdit
|
|
|
|
|
Image is too big for preview!' -tE"
|
|
|
|
|
?define T_ERROR_CROP_TOOL "'You need to select something before using crop tool.' -W"
|
|
|
|
|
?define T_ERROR_IMA_ICONEDIT "'Hey, this is just an icon editor,
|
|
|
|
|
selected image is too big to open!' -E"
|
2018-09-14 11:49:37 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2017-10-17 01:41:50 +02:00
|
|
|
|
|
|
|
|
|
#define PALLETE_SIZE 116
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2021-06-12 10:58:31 +02:00
|
|
|
|
#define TOPBAR_H 24+8
|
|
|
|
|
int leftbar_w;
|
|
|
|
|
|
2018-03-18 15:21:06 +01:00
|
|
|
|
#define PAL_ITEMS_X_COUNT 13
|
|
|
|
|
#define COLSIZE 18
|
2018-03-21 16:14:21 +01:00
|
|
|
|
#define RIGHT_BAR_W PAL_ITEMS_X_COUNT*COLSIZE
|
2018-03-15 20:19:53 +01:00
|
|
|
|
|
2018-04-21 21:42:08 +02:00
|
|
|
|
#define TO_CANVAS_X(xval) xval - canvas.x/zoom.value
|
|
|
|
|
#define TO_CANVAS_Y(yval) yval - canvas.y/zoom.value
|
|
|
|
|
|
2018-03-21 16:14:21 +01:00
|
|
|
|
block canvas = { NULL, NULL, NULL, NULL };
|
2021-06-12 10:58:31 +02:00
|
|
|
|
block wrapper = { 0, TOPBAR_H, NULL, NULL };
|
2018-05-06 17:02:12 +02:00
|
|
|
|
block right_bar = { NULL, 10+TOPBAR_H, RIGHT_BAR_W+10, NULL };
|
2018-10-10 16:44:01 +02:00
|
|
|
|
block image_menu_btn = { NULL, 4, NULL, 22 };
|
2018-03-21 16:14:21 +01:00
|
|
|
|
|
2018-10-01 18:41:14 +02:00
|
|
|
|
dword linear_gradient[RIGHT_BAR_W];
|
|
|
|
|
block b_color_gradient = {NULL, 40+TOPBAR_H, RIGHT_BAR_W, 25};
|
|
|
|
|
//block b_opacity_gradient = {NULL, 75+TOPBAR_H, RIGHT_BAR_W, 15};
|
|
|
|
|
block b_last_colors = {NULL, 75+TOPBAR_H, RIGHT_BAR_W, COLSIZE};
|
|
|
|
|
block b_default_palette = {NULL, COLSIZE+10+75+TOPBAR_H, RIGHT_BAR_W, COLSIZE*9};
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2018-10-01 18:41:14 +02:00
|
|
|
|
dword transparent = 0xBFCAD2;
|
2018-03-23 11:23:58 +01:00
|
|
|
|
dword color1 = 0x000000;
|
2018-04-22 21:00:01 +02:00
|
|
|
|
dword color2 = 0xBFCAD2;
|
2018-03-23 11:23:58 +01:00
|
|
|
|
dword tool_color;
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2018-04-24 17:14:08 +02:00
|
|
|
|
signed hoverX;
|
|
|
|
|
signed hoverY;
|
|
|
|
|
signed priorHoverX;
|
|
|
|
|
signed priorHoverY;
|
|
|
|
|
bool canvasMouseMoved = false;
|
|
|
|
|
|
2018-11-01 22:48:33 +01:00
|
|
|
|
EVENTS button;
|
|
|
|
|
EVENTS key;
|
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
|
enum {
|
2018-02-09 17:46:59 +01:00
|
|
|
|
BTNS_PALETTE_COLOR_MAS = 100,
|
|
|
|
|
BTNS_LAST_USED_COLORS = 400
|
2017-10-12 01:19:28 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
proc_info Form;
|
2018-04-22 21:00:01 +02:00
|
|
|
|
dword semi_white;
|
2018-10-01 18:41:14 +02:00
|
|
|
|
bool bg_dark=false;
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2018-04-19 16:16:32 +02:00
|
|
|
|
more_less_box zoom = { 11, 1, 40, "Zoom" };
|
2018-02-07 17:02:34 +01:00
|
|
|
|
|
2018-02-08 12:37:33 +01:00
|
|
|
|
dword default_palette[] = {
|
2018-03-16 21:34:44 +01:00
|
|
|
|
0x330000,0x331900,0x333300,0x193300,0x003300,0x003319,0x003333,0x001933,0x000033,0x190033,
|
|
|
|
|
0x330033,0x330019,0x000000,0x660000,0x663300,0x666600,0x336600,0x006600,0x006633,0x006666,
|
|
|
|
|
0x003366,0x000066,0x330066,0x660066,0x660033,0x202020,0x990000,0x994C00,0x999900,0x4C9900,
|
|
|
|
|
0x009900,0x00994C,0x009999,0x004C99,0x000099,0x4C0099,0x990099,0x99004C,0x404040,0xCC0000,
|
|
|
|
|
0xCC6600,0xCCCC00,0x66CC00,0x00CC00,0x00CC66,0x00CCCC,0x0066CC,0x0000CC,0x6600CC,0xCC00CC,
|
|
|
|
|
0xCC0066,0x606060,0xFF0000,0xFF8000,0xFFFF00,0x80FF00,0x00FF00,0x00FF80,0x00FFFF,0x0080FF,
|
|
|
|
|
0x0000FF,0x7F00FF,0xFF00FF,0xFF007F,0x808080,0xFF3333,0xFF9933,0xFFFF33,0x99FF33,0x33FF33,
|
|
|
|
|
0x33FF99,0x33FFFF,0x3399FF,0x3333FF,0x9933FF,0xFF33FF,0xFF3399,0xA0A0A0,0xFF6666,0xFFB266,
|
|
|
|
|
0xFFFF66,0xB2FF66,0x66FF66,0x66FFB2,0x66FFFF,0x66B2FF,0x6666FF,0xB266FF,0xFF66FF,0xFF66B2,
|
|
|
|
|
0xC0C0C0,0xFF9999,0xFFCC99,0xFFFF99,0xCCFF99,0x99FF99,0x99FFCC,0x99FFFF,0x99CCFF,0x9999FF,
|
|
|
|
|
0xCC99FF,0xFF99FF,0xFF99CC,0xE0E0E0,0xFFCCCC,0xFFE5CC,0xFFFFCC,0xE5FFCC,0xCCFFCC,0xCCFFE5,
|
|
|
|
|
0xCCFFFF,0xCCE5FF,0xCCCCFF,0xE5CCFF,0xFFCCFF,0xFFCCE5,0xFFFFFF
|
2017-10-12 01:19:28 +02:00
|
|
|
|
};
|
2018-10-01 18:41:14 +02:00
|
|
|
|
|
|
|
|
|
#define LAST_USED_MAX 13
|
|
|
|
|
dword last_used_colors[LAST_USED_MAX] = {
|
2018-03-16 21:34:44 +01:00
|
|
|
|
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,
|
2018-10-01 18:41:14 +02:00
|
|
|
|
0xFFFFFF,0xFFFFFF,0xFFFFFF
|
2018-02-09 17:46:59 +01:00
|
|
|
|
};
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2018-04-29 22:42:03 +02:00
|
|
|
|
CustomCursor Cursor;
|
|
|
|
|
dword CursorBar = FROM "cursors/bar.cur";
|
|
|
|
|
dword CursorFill = FROM "cursors/fill.cur";
|
|
|
|
|
dword CursorLine = FROM "cursors/line.cur";
|
|
|
|
|
dword CursorPencil = FROM "cursors/pencil.cur";
|
|
|
|
|
dword CursorPipette = FROM "cursors/pipette.cur";
|
|
|
|
|
dword CursorRectangle = FROM "cursors/rectangle.cur";
|
|
|
|
|
dword CursorSelect = FROM "cursors/select.cur";
|
|
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
|
_image image;
|
2018-02-07 23:09:46 +01:00
|
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
|
#include "actions_history.h"
|
|
|
|
|
|
|
|
|
|
_ActionsHistory actionsHistory;
|
2018-02-05 20:13:37 +01:00
|
|
|
|
|
2018-04-22 15:33:01 +02:00
|
|
|
|
#include "tools.h"
|
2018-05-07 18:17:53 +02:00
|
|
|
|
#include "canvas_resize.h"
|
2018-02-10 12:47:33 +01:00
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
|
//===================================================//
|
|
|
|
|
// //
|
|
|
|
|
// CODE //
|
|
|
|
|
// //
|
|
|
|
|
//===================================================//
|
|
|
|
|
|
2018-05-02 18:32:29 +02:00
|
|
|
|
libimg_image top_icons;
|
|
|
|
|
libimg_image left_icons;
|
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
|
void main()
|
|
|
|
|
{
|
|
|
|
|
word btn;
|
2018-04-24 17:14:08 +02:00
|
|
|
|
libimg_image open_image;
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2017-10-17 01:41:50 +02:00
|
|
|
|
load_dll(libimg, #libimg_init, 1);
|
2018-04-22 21:00:01 +02:00
|
|
|
|
load_dll(boxlib, #box_lib_init,0);
|
|
|
|
|
|
2020-05-24 18:46:26 +02:00
|
|
|
|
top_icons.load("/sys/icons16.png");
|
|
|
|
|
left_icons.load("/sys/icons16.png");
|
2021-06-12 10:58:31 +02:00
|
|
|
|
leftbar_w = left_icons.w + 16;
|
2018-05-02 18:32:29 +02:00
|
|
|
|
|
2020-04-18 01:52:24 +02:00
|
|
|
|
sc.get();
|
2020-04-13 13:51:56 +02:00
|
|
|
|
bg_dark = skin_is_dark();
|
2018-10-01 18:41:14 +02:00
|
|
|
|
|
2020-04-18 01:52:24 +02:00
|
|
|
|
semi_white = MixColors(sc.work, 0xFFFfff, bg_dark*90 + 96);
|
2020-05-24 18:46:26 +02:00
|
|
|
|
top_icons.replace_color(0xffFFFfff, semi_white);
|
|
|
|
|
top_icons.replace_color(0xffCACBD6, MixColors(semi_white, 0, 220));
|
2018-05-02 18:32:29 +02:00
|
|
|
|
|
2020-05-24 18:46:26 +02:00
|
|
|
|
left_icons.replace_color(0xffFFFfff, sc.work);
|
|
|
|
|
left_icons.replace_color(0xffCACBD6, MixColors(sc.work, 0, 200));
|
2018-02-07 23:09:46 +01:00
|
|
|
|
|
2018-10-01 18:41:14 +02:00
|
|
|
|
//fix line and rectandle color for dark skins
|
2020-05-24 18:46:26 +02:00
|
|
|
|
if (bg_dark) left_icons.replace_color(0xff545454, 0xffD3D3D4);
|
2018-10-01 18:41:14 +02:00
|
|
|
|
|
|
|
|
|
EventSetActiveColor(1, color1);
|
|
|
|
|
|
2018-04-22 15:33:01 +02:00
|
|
|
|
if (!param[0]) {
|
|
|
|
|
image.create(32, 32);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-05-28 02:55:16 +02:00
|
|
|
|
open_image.load(#param);
|
|
|
|
|
open_image.convert_into(IMAGE_BPP24);
|
2018-04-22 15:33:01 +02:00
|
|
|
|
|
|
|
|
|
if (open_image.w*open_image.h>MAX_CELL_SIZE*MAX_CELL_SIZE) {
|
2020-04-25 16:36:28 +02:00
|
|
|
|
notify(T_ERROR_IMA_ICONEDIT);
|
2018-04-22 15:33:01 +02:00
|
|
|
|
ExitProcess();
|
2018-02-07 23:09:46 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2018-10-01 18:41:14 +02:00
|
|
|
|
image.create(open_image.h, open_image.w);
|
2018-04-22 15:33:01 +02:00
|
|
|
|
image.set_image(open_image.imgsrc);
|
2018-02-07 23:09:46 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
|
actionsHistory.init();
|
|
|
|
|
|
2018-03-14 19:22:55 +01:00
|
|
|
|
initTools();
|
|
|
|
|
setCurrentTool(TOOL_PENCIL);
|
|
|
|
|
|
2017-10-17 01:41:50 +02:00
|
|
|
|
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
|
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
|
loop() switch(WaitEvent())
|
|
|
|
|
{
|
2017-10-17 01:41:50 +02:00
|
|
|
|
case evMouse:
|
2018-05-07 18:17:53 +02:00
|
|
|
|
if (Window_CanvasReSize.thread_exists()) break;
|
2017-10-17 01:41:50 +02:00
|
|
|
|
mouse.get();
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
2018-03-23 11:23:58 +01:00
|
|
|
|
if (mouse.lkm) tool_color = color1;
|
|
|
|
|
if (mouse.pkm) tool_color = color2;
|
|
|
|
|
if (mouse.mkm) break;
|
|
|
|
|
|
2018-04-24 17:14:08 +02:00
|
|
|
|
hoverX = mouse.x - canvas.x / zoom.value;
|
|
|
|
|
hoverY = mouse.y - canvas.y / zoom.value;
|
|
|
|
|
if (hoverX<0) hoverX = 0;
|
|
|
|
|
if (hoverY<0) hoverY = 0;
|
|
|
|
|
if (hoverX>image.columns-1) hoverX = image.columns-1;
|
|
|
|
|
if (hoverY>image.rows-1) hoverY = image.rows-1;
|
|
|
|
|
canvasMouseMoved = false;
|
|
|
|
|
if (priorHoverX != hoverX) canvasMouseMoved = true;
|
|
|
|
|
if (priorHoverY != hoverY) canvasMouseMoved = true;
|
|
|
|
|
priorHoverX = hoverX;
|
|
|
|
|
priorHoverY = hoverY;
|
|
|
|
|
//DrawBar(Form.cwidth-100, 3, 80, 12, 0xFFFfff);
|
|
|
|
|
//WriteText(Form.cwidth-100, 3, 0x80, 0x000000,
|
|
|
|
|
// sprintf(#param, "%i %i", hoverX, hoverY));
|
|
|
|
|
|
2018-03-14 19:22:55 +01:00
|
|
|
|
if (currentTool != TOOL_NONE)
|
|
|
|
|
tools[currentTool].onMouseEvent(mouse.x, mouse.y, mouse.lkm, mouse.pkm);
|
|
|
|
|
|
2018-02-10 12:47:33 +01:00
|
|
|
|
if (mouse.vert) {
|
2018-04-19 16:16:32 +02:00
|
|
|
|
if (mouse.vert==65535) zoom.inc();
|
|
|
|
|
if (mouse.vert==1) zoom.dec();
|
2018-02-08 12:37:33 +01:00
|
|
|
|
DrawEditArea();
|
|
|
|
|
}
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
2018-04-29 22:42:03 +02:00
|
|
|
|
if (wrapper.hovered()) SetCursor();
|
|
|
|
|
else Cursor.Restore();
|
|
|
|
|
|
2018-03-21 16:14:21 +01:00
|
|
|
|
if (mouse.down) {
|
|
|
|
|
if (b_color_gradient.hovered())
|
|
|
|
|
|| (b_last_colors.hovered())
|
|
|
|
|
|| (b_default_palette.hovered()) {
|
|
|
|
|
if (mouse.key&MOUSE_LEFT) EventSetActiveColor(1, GetPixelUnderMouse());
|
|
|
|
|
if (mouse.key&MOUSE_RIGHT) EventSetActiveColor(2, GetPixelUnderMouse());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-05 20:13:37 +01:00
|
|
|
|
break;
|
2017-10-17 01:41:50 +02:00
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
|
case evButton:
|
2018-05-07 18:17:53 +02:00
|
|
|
|
if (Window_CanvasReSize.thread_exists()) break;
|
2018-02-05 20:13:37 +01:00
|
|
|
|
btn = GetButtonID();
|
2018-04-21 21:42:08 +02:00
|
|
|
|
|
2018-04-22 21:00:01 +02:00
|
|
|
|
if (zoom.click(btn)) DrawEditArea();
|
|
|
|
|
|
2018-11-01 22:48:33 +01:00
|
|
|
|
button.press(btn);
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
|
|
|
|
case evKey:
|
|
|
|
|
GetKeys();
|
2018-04-21 21:42:08 +02:00
|
|
|
|
|
2018-11-01 22:48:33 +01:00
|
|
|
|
if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) key.press(ECTRL + key_scancode);
|
2018-10-01 18:41:14 +02:00
|
|
|
|
|
|
|
|
|
if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
|
|
|
|
|
if (key_scancode == SCAN_CODE_DEL) EventCleanCanvas();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-21 21:42:08 +02:00
|
|
|
|
if (currentTool != TOOL_NONE) && (tools[currentTool].onKeyEvent != 0)
|
|
|
|
|
tools[currentTool].onKeyEvent(key_scancode);
|
|
|
|
|
|
2018-11-01 22:48:33 +01:00
|
|
|
|
key.press(key_scancode);
|
2018-05-01 16:35:58 +02:00
|
|
|
|
|
2018-05-03 15:40:26 +02:00
|
|
|
|
if (key_scancode == SCAN_CODE_KEY_Z) actionsHistory.undoLastAction();
|
|
|
|
|
if (key_scancode == SCAN_CODE_KEY_Y) actionsHistory.redoLastAction();
|
2018-04-21 21:42:08 +02:00
|
|
|
|
|
|
|
|
|
if (key_scancode == SCAN_CODE_MINUS) {zoom.dec(); DrawEditArea();}
|
2018-05-07 18:17:53 +02:00
|
|
|
|
if (key_scancode == SCAN_CODE_PLUS) {zoom.inc(); DrawEditArea();}
|
2018-03-22 18:03:56 +01:00
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evReDraw:
|
2018-05-07 18:17:53 +02:00
|
|
|
|
Window_CanvasReSize.thread_exists();
|
2020-04-13 15:16:55 +02:00
|
|
|
|
if (CheckActiveProcess(Form.ID)) EventCheckMenuItemSelected();
|
2018-05-08 20:35:13 +02:00
|
|
|
|
DrawWindow();
|
2017-10-12 01:19:28 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-12 10:58:31 +02:00
|
|
|
|
void DrawTopPanelButton1(dword _event, _hotkey, _x, _icon_n)
|
2017-10-17 01:41:50 +02:00
|
|
|
|
{
|
2018-04-22 21:00:01 +02:00
|
|
|
|
DrawWideRectangle(_x, 4, 22, 22, 3, semi_white);
|
2020-04-18 01:52:24 +02:00
|
|
|
|
PutPixel(_x,4,sc.work);
|
|
|
|
|
PutPixel(_x,4+21,sc.work);
|
|
|
|
|
PutPixel(_x+21,4,sc.work);
|
|
|
|
|
PutPixel(_x+21,4+21,sc.work);
|
2018-11-01 22:48:33 +01:00
|
|
|
|
DefineHiddenButton(_x, 4, 21, 21, button.add(_event));
|
2021-06-12 10:58:31 +02:00
|
|
|
|
img_draw stdcall(top_icons.image, -top_icons.w+16/2+_x+3, -top_icons.w+16/2+7, left_icons.w,
|
|
|
|
|
left_icons.w, 0, _icon_n*left_icons.w);
|
|
|
|
|
//DrawTopPanelButton(button.add(_event), _x, 5, _icon_n, false);
|
2018-11-01 22:48:33 +01:00
|
|
|
|
if (_hotkey) key.add_n(_hotkey, _event);
|
2017-10-17 01:41:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 22:48:33 +01:00
|
|
|
|
|
2018-10-10 16:44:01 +02:00
|
|
|
|
int DrawFlatPanelButton(dword _id, _x, _y, _text)
|
|
|
|
|
{
|
|
|
|
|
#define P 10
|
|
|
|
|
int w = strlen(_text)*6 + P + P;
|
|
|
|
|
DrawBar(_x, _y, w, 22, semi_white);
|
2020-04-18 01:52:24 +02:00
|
|
|
|
PutPixel(_x,_y,sc.work);
|
|
|
|
|
PutPixel(_x,_y+21,sc.work);
|
|
|
|
|
PutPixel(_x+w-1,_y,sc.work);
|
|
|
|
|
PutPixel(_x+w-1,_y+21,sc.work);
|
2018-10-10 16:44:01 +02:00
|
|
|
|
DefineHiddenButton(_x, _y, w, 21, _id);
|
2020-04-18 01:52:24 +02:00
|
|
|
|
WriteText(_x+P, _y+7, 0x80, sc.work_text, _text);
|
2018-10-10 16:44:01 +02:00
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 22:48:33 +01:00
|
|
|
|
void DrawLeftPanelButton(dword _event, _hotkey, _y, _icon_n)
|
2018-03-15 20:19:53 +01:00
|
|
|
|
{
|
|
|
|
|
int x = 5;
|
2021-06-12 10:58:31 +02:00
|
|
|
|
DrawRectangle(x, _y, left_icons.w + 5, left_icons.w + 5, sc.work);
|
|
|
|
|
DefineHiddenButton(x, _y, left_icons.w + 5, left_icons.w + 5, button.add(_event));
|
|
|
|
|
img_draw stdcall(left_icons.image, x+3, _y+3, left_icons.w,
|
|
|
|
|
left_icons.w, 0, _icon_n*left_icons.w);
|
2018-11-01 22:48:33 +01:00
|
|
|
|
key.add_n(_hotkey, _event);
|
2018-03-15 20:19:53 +01:00
|
|
|
|
}
|
2018-02-05 20:13:37 +01:00
|
|
|
|
void DrawStatusBar()
|
|
|
|
|
{
|
2018-04-19 16:16:32 +02:00
|
|
|
|
zoom.draw(wrapper.x, wrapper.y + wrapper.h + 6);
|
2018-02-07 17:02:34 +01:00
|
|
|
|
|
2018-05-08 20:35:13 +02:00
|
|
|
|
sprintf(#param,"%i x %i", image.columns, image.rows);
|
2018-05-07 18:17:53 +02:00
|
|
|
|
DrawCaptButton(
|
2018-05-08 20:35:13 +02:00
|
|
|
|
wrapper.x+wrapper.w-calc(strlen(#param)*8) -6 - 1,
|
2018-05-07 18:17:53 +02:00
|
|
|
|
zoom.y,
|
2018-05-08 20:35:13 +02:00
|
|
|
|
calc(strlen(#param)*8)+6,
|
2018-05-07 18:17:53 +02:00
|
|
|
|
18,
|
2018-11-01 22:48:33 +01:00
|
|
|
|
button.add(#EventCanvasResize),
|
2020-04-18 01:52:24 +02:00
|
|
|
|
sc.button,
|
|
|
|
|
sc.button_text,
|
2018-05-08 20:35:13 +02:00
|
|
|
|
#param
|
2018-05-07 18:17:53 +02:00
|
|
|
|
);
|
2018-02-05 20:13:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 22:48:33 +01:00
|
|
|
|
|
2018-05-08 20:35:13 +02:00
|
|
|
|
void DrawWindow()
|
2017-10-12 01:19:28 +02:00
|
|
|
|
{
|
2018-11-01 22:48:33 +01:00
|
|
|
|
#define GAPH 27
|
|
|
|
|
#define GAPV 28
|
2021-06-12 10:58:31 +02:00
|
|
|
|
#define GAP_S 26+5
|
|
|
|
|
#define GAP_B 26+18
|
2018-05-02 18:32:29 +02:00
|
|
|
|
#define BLOCK_SPACE 10
|
2017-10-17 01:41:50 +02:00
|
|
|
|
incn tx;
|
2018-11-01 22:48:33 +01:00
|
|
|
|
incn ty;
|
2020-04-18 01:52:24 +02:00
|
|
|
|
sc.get();
|
2018-05-06 17:02:12 +02:00
|
|
|
|
DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x73, NULL, T_TITLE, 0);
|
2017-10-12 01:19:28 +02:00
|
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
2021-06-26 09:59:13 +02:00
|
|
|
|
if (Form.status_window&ROLLED_UP) return;
|
2018-02-08 12:37:33 +01:00
|
|
|
|
if (Form.width < 560) { MoveSize(OLD,OLD,560,OLD); return; }
|
|
|
|
|
if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; }
|
2018-11-01 22:48:33 +01:00
|
|
|
|
button.init(40);
|
|
|
|
|
key.init(40);
|
2018-02-08 12:37:33 +01:00
|
|
|
|
|
2018-02-07 17:02:34 +01:00
|
|
|
|
right_bar.x = Form.cwidth - right_bar.w;
|
2018-03-21 16:14:21 +01:00
|
|
|
|
b_color_gradient.x = b_last_colors.x = b_default_palette.x = right_bar.x;
|
2020-04-18 01:52:24 +02:00
|
|
|
|
DrawBar(0, 0, Form.cwidth, TOPBAR_H-1, sc.work);
|
|
|
|
|
DrawBar(0, TOPBAR_H-1, Form.cwidth, 1, sc.work_graph);
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2021-06-12 10:58:31 +02:00
|
|
|
|
DrawTopPanelButton1(#EventCreateNewIcon, ECTRL + SCAN_CODE_KEY_N, tx.set(5), 2);
|
|
|
|
|
DrawTopPanelButton1(#EventOpenIcon, ECTRL + SCAN_CODE_KEY_O, tx.inc(GAP_S), 0);
|
|
|
|
|
DrawTopPanelButton1(#EventSaveIconToFile, ECTRL + SCAN_CODE_KEY_S, tx.inc(GAP_S), 5);
|
|
|
|
|
DrawTopPanelButton1(#EventMoveLeft, ECTRL + SCAN_CODE_LEFT, tx.inc(GAP_B), 30);
|
|
|
|
|
DrawTopPanelButton1(#EventMoveRight, ECTRL + SCAN_CODE_RIGHT, tx.inc(GAP_S), 31);
|
|
|
|
|
DrawTopPanelButton1(#EventMoveUp, ECTRL + SCAN_CODE_UP, tx.inc(GAP_S), 32);
|
|
|
|
|
DrawTopPanelButton1(#EventMoveDown, ECTRL + SCAN_CODE_DOWN, tx.inc(GAP_S), 33);
|
|
|
|
|
DrawTopPanelButton1(#EventFlipHor, 0, tx.inc(GAP_B), 34);
|
|
|
|
|
DrawTopPanelButton1(#EventFlipVer, 0, tx.inc(GAP_S), 35);
|
|
|
|
|
DrawTopPanelButton1(#EventRotateLeft, ECTRL + SCAN_CODE_KEY_L, tx.inc(GAP_S), 37);
|
|
|
|
|
DrawTopPanelButton1(#EventRotateRight, ECTRL + SCAN_CODE_KEY_R, tx.inc(GAP_S), 36);
|
|
|
|
|
DrawTopPanelButton1(#EventCrop, 0, tx.inc(GAP_B), 46);
|
|
|
|
|
|
|
|
|
|
image_menu_btn.x = tx.inc(GAP_B);
|
2018-11-01 22:48:33 +01:00
|
|
|
|
image_menu_btn.w = DrawFlatPanelButton(button.add(#EventShowImageMenu), image_menu_btn.x, image_menu_btn.y, T_MENU_IMAGE);
|
2018-10-10 16:44:01 +02:00
|
|
|
|
//tx.inc(image_menu_btn.w + BLOCK_SPACE);
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
2018-02-07 17:02:34 +01:00
|
|
|
|
DrawEditArea();
|
2017-10-17 01:41:50 +02:00
|
|
|
|
|
2021-06-12 10:58:31 +02:00
|
|
|
|
DrawBar(0, TOPBAR_H, leftbar_w-1, Form.cheight - TOPBAR_H, sc.work);
|
2018-11-01 22:48:33 +01:00
|
|
|
|
|
|
|
|
|
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);
|
2021-06-12 10:58:31 +02:00
|
|
|
|
key.add_n(ECTRL + SCAN_CODE_KEY_T, #EventTestIcon);
|
2018-05-07 18:17:53 +02:00
|
|
|
|
|
2018-05-06 17:02:12 +02:00
|
|
|
|
DrawBar(wrapper.x+wrapper.w, TOPBAR_H, Form.cwidth-wrapper.x-wrapper.w,
|
2020-04-18 01:52:24 +02:00
|
|
|
|
Form.cheight - TOPBAR_H, sc.work);
|
2018-02-09 17:46:59 +01:00
|
|
|
|
DrawActiveColor(right_bar.y);
|
2018-03-21 16:14:21 +01:00
|
|
|
|
DrawColorPallets();
|
2018-05-06 17:02:12 +02:00
|
|
|
|
DrawPreview();
|
2018-05-07 18:17:53 +02:00
|
|
|
|
|
2021-06-12 10:58:31 +02:00
|
|
|
|
DrawBar(leftbar_w-1, wrapper.y + wrapper.h, wrapper.w+1,
|
2020-04-18 01:52:24 +02:00
|
|
|
|
Form.cheight - wrapper.y - wrapper.h, sc.work);
|
2018-05-07 18:17:53 +02:00
|
|
|
|
DrawStatusBar();
|
2017-10-12 01:19:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 22:48:33 +01:00
|
|
|
|
void DrawLeftPanelSelection()
|
2018-03-15 20:19:53 +01:00
|
|
|
|
{
|
2021-06-12 10:58:31 +02:00
|
|
|
|
if (previousTool!=-1) DrawRectangle3D(5, previousTool*GAPV+right_bar.y-2, left_icons.w+5, left_icons.w+5, sc.work, sc.work);
|
|
|
|
|
DrawRectangle3D(5, currentTool*GAPV+right_bar.y-2, left_icons.w+5, left_icons.w+5, 0x333333, 0x777777);
|
2018-03-15 20:19:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 23:09:46 +01:00
|
|
|
|
void DrawEditArea()
|
2017-10-12 01:19:28 +02:00
|
|
|
|
{
|
2018-02-07 17:02:34 +01:00
|
|
|
|
dword color1=0xC0C0C0;
|
2018-02-09 17:46:59 +01:00
|
|
|
|
int top_side;
|
|
|
|
|
int left_side;
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2021-06-12 10:58:31 +02:00
|
|
|
|
wrapper.x = left_icons.w + 16;
|
2018-03-18 15:21:06 +01:00
|
|
|
|
wrapper.w = Form.cwidth - right_bar.w - 10 - wrapper.x;
|
2018-05-06 17:02:12 +02:00
|
|
|
|
wrapper.h = Form.cheight - TOPBAR_H - 35;
|
2018-02-05 20:13:37 +01:00
|
|
|
|
|
2018-02-07 17:02:34 +01:00
|
|
|
|
//canvas{
|
2018-02-07 23:09:46 +01:00
|
|
|
|
canvas.w = image.columns * zoom.value;
|
|
|
|
|
canvas.h = image.rows * zoom.value;
|
|
|
|
|
if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) {
|
2018-04-22 15:33:01 +02:00
|
|
|
|
zoom.value--;
|
2018-10-01 18:41:14 +02:00
|
|
|
|
if (zoom.x) zoom.redraw();
|
2018-02-07 23:09:46 +01:00
|
|
|
|
DrawEditArea();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
canvas.x = -zoom.value*image.columns+wrapper.w/2 + wrapper.x;
|
|
|
|
|
canvas.y = -zoom.value*image.rows+wrapper.h/2 + wrapper.y;
|
|
|
|
|
DrawCanvas();
|
2018-02-07 17:02:34 +01:00
|
|
|
|
//}
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
|
left_side = canvas.x-wrapper.x-1;
|
|
|
|
|
top_side = canvas.y-wrapper.y-1;
|
2018-02-05 20:13:37 +01:00
|
|
|
|
|
2020-04-18 01:52:24 +02:00
|
|
|
|
DrawRectangle(wrapper.x-1, wrapper.y-1, wrapper.w, wrapper.h, sc.work_graph);
|
2018-02-07 17:02:34 +01:00
|
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
|
if (left_side>0)
|
2018-02-07 17:02:34 +01:00
|
|
|
|
{
|
2018-02-09 17:46:59 +01:00
|
|
|
|
DrawBar(wrapper.x, wrapper.y, wrapper.w-1, top_side, color1); //top
|
|
|
|
|
DrawBar(wrapper.x, wrapper.y+wrapper.h-top_side-1, wrapper.w-1, top_side, color1); //bottom
|
2018-02-07 17:02:34 +01:00
|
|
|
|
}
|
2018-02-09 17:46:59 +01:00
|
|
|
|
if (top_side>0)
|
2018-02-07 17:02:34 +01:00
|
|
|
|
{
|
2018-03-16 21:34:44 +01:00
|
|
|
|
//left
|
|
|
|
|
DrawBar(wrapper.x, wrapper.y+top_side, left_side,
|
|
|
|
|
wrapper.h-top_side-top_side, color1);
|
|
|
|
|
//right
|
|
|
|
|
DrawBar(wrapper.x+wrapper.w-left_side-1, wrapper.y+top_side, left_side,
|
|
|
|
|
wrapper.h-top_side-top_side, color1);
|
2018-02-07 17:02:34 +01:00
|
|
|
|
}
|
2018-03-18 15:21:06 +01:00
|
|
|
|
DrawRectangle(canvas.x-1, canvas.y-1, canvas.w+1, canvas.h+1, 0x808080);
|
2017-10-12 01:19:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DrawActiveColor(dword iny)
|
|
|
|
|
{
|
2018-04-22 21:00:01 +02:00
|
|
|
|
#define CELL 20
|
2017-10-12 01:19:28 +02:00
|
|
|
|
static dword outy;
|
|
|
|
|
if (iny != NULL) outy = iny;
|
2018-04-22 21:00:01 +02:00
|
|
|
|
DrawFrame(right_bar.x, outy, CELL, CELL, NULL);
|
|
|
|
|
DrawBar(right_bar.x+2, outy+2, CELL-4, CELL-4, color1);
|
2018-10-01 18:41:14 +02:00
|
|
|
|
|
|
|
|
|
DrawFrame(right_bar.x+CELL+5, outy, CELL, CELL, NULL);
|
|
|
|
|
DrawBar(right_bar.x+CELL+5+2, outy+2, CELL-4, CELL-4, color2);
|
|
|
|
|
|
|
|
|
|
//sprintf(#param, "%A", color1);
|
2020-04-18 01:52:24 +02:00
|
|
|
|
//WriteTextWithBg(right_bar.x+30, outy+3, 0xD0, sc.work_text, #param+4, sc.work);
|
2018-10-01 18:41:14 +02:00
|
|
|
|
DrawCurrentColorGradient();
|
2018-03-18 15:21:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 18:41:14 +02:00
|
|
|
|
int lmax;
|
|
|
|
|
void GenerateCurrentColorGradient()
|
|
|
|
|
{
|
|
|
|
|
int i, avg, rmax;
|
|
|
|
|
|
|
|
|
|
rgb.DwordToRgb(color1);
|
|
|
|
|
avg = 255 - calc(rgb.r + rgb.g + rgb.b / 3);
|
|
|
|
|
|
|
|
|
|
lmax = b_color_gradient.w *avg/255 | 1;
|
|
|
|
|
rmax = b_color_gradient.w - lmax | 1;
|
|
|
|
|
if (lmax == 0) lmax=1;
|
|
|
|
|
if (rmax == 0) rmax=1;
|
|
|
|
|
|
|
|
|
|
for (i=0; i<lmax; i++) {
|
|
|
|
|
linear_gradient[i] = MixColors(color1,0xFFFfff,255*i/lmax);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i=0 ; i<=rmax; i++) {
|
|
|
|
|
linear_gradient[lmax+rmax - i] = MixColors(color1,0x000000,255*i/rmax);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-09 21:12:02 +02:00
|
|
|
|
int DrawGradientMarker(dword marker_x, marker_color)
|
|
|
|
|
{
|
|
|
|
|
if (marker_x > b_color_gradient.w - 1) marker_x = b_color_gradient.w - 1;
|
|
|
|
|
DrawBar(b_color_gradient.x + marker_x-2, b_color_gradient.y-3, 5, 1, marker_color);
|
|
|
|
|
DrawBar(b_color_gradient.x + marker_x-1, b_color_gradient.y-2, 3, 1, marker_color);
|
|
|
|
|
PutPixel(b_color_gradient.x + marker_x, b_color_gradient.y-1, marker_color);
|
|
|
|
|
return marker_x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int old_marker_pos;
|
2018-10-01 18:41:14 +02:00
|
|
|
|
void DrawCurrentColorGradient()
|
2018-03-18 15:21:06 +01:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2018-10-01 18:41:14 +02:00
|
|
|
|
for (i=0 ; i<b_color_gradient.w; i++) {
|
|
|
|
|
DrawBar(b_color_gradient.x+i, b_color_gradient.y, 1, b_color_gradient.h, linear_gradient[i]);
|
|
|
|
|
}
|
2020-04-18 01:52:24 +02:00
|
|
|
|
DrawGradientMarker(old_marker_pos, sc.work);
|
2018-10-09 21:12:02 +02:00
|
|
|
|
old_marker_pos = DrawGradientMarker(lmax, 0xFFFfff * bg_dark);
|
2017-10-12 01:19:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-21 16:14:21 +01:00
|
|
|
|
void DrawColorPallets()
|
2017-10-12 01:19:28 +02:00
|
|
|
|
{
|
2018-02-09 17:46:59 +01:00
|
|
|
|
int r, c, i=0;
|
|
|
|
|
//Last used colors
|
2018-10-01 18:41:14 +02:00
|
|
|
|
for (r = 0; r < LAST_USED_MAX/PAL_ITEMS_X_COUNT; r++)
|
2018-02-09 17:46:59 +01:00
|
|
|
|
{
|
2018-03-18 15:21:06 +01:00
|
|
|
|
for (c = 0; c < PAL_ITEMS_X_COUNT; c++, i++)
|
2018-02-09 17:46:59 +01:00
|
|
|
|
{
|
2018-03-21 16:14:21 +01:00
|
|
|
|
DrawBar(c*COLSIZE + b_last_colors.x, r*COLSIZE + b_last_colors.y,
|
|
|
|
|
COLSIZE, COLSIZE, last_used_colors[i]);
|
2018-02-09 17:46:59 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
i=0;
|
|
|
|
|
//Default colors
|
2017-10-12 01:19:28 +02:00
|
|
|
|
for (r = 0; r < 9; r++)
|
|
|
|
|
{
|
2018-03-18 15:21:06 +01:00
|
|
|
|
for (c = 0; c < PAL_ITEMS_X_COUNT; c++, i++)
|
2017-10-12 01:19:28 +02:00
|
|
|
|
{
|
2018-03-21 16:14:21 +01:00
|
|
|
|
DrawBar(c*COLSIZE + b_default_palette.x, r*COLSIZE + b_default_palette.y,
|
|
|
|
|
COLSIZE, COLSIZE, default_palette[PALLETE_SIZE-i]);
|
2018-02-09 17:46:59 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 17:14:08 +02:00
|
|
|
|
void DrawCanvasPixel(dword _r,_c,_color)
|
|
|
|
|
{
|
|
|
|
|
DrawBar(_c*zoom.value + canvas.x, _r*zoom.value + canvas.y,
|
|
|
|
|
zoom.value, zoom.value, _color);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
|
void DrawCanvas()
|
|
|
|
|
{
|
|
|
|
|
int r, c;
|
2018-04-24 17:14:08 +02:00
|
|
|
|
dword color;
|
|
|
|
|
|
|
|
|
|
if ((currentTool != TOOL_NONE) && (tools[currentTool].onCanvasDraw != 0))
|
|
|
|
|
{
|
|
|
|
|
tools[currentTool].onCanvasDraw();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
|
for (r = 0; r < image.rows; r++)
|
|
|
|
|
{
|
|
|
|
|
for (c = 0; c < image.columns; c++)
|
|
|
|
|
{
|
2018-04-24 17:14:08 +02:00
|
|
|
|
if (image.pixel_state.is_drawable(r,c))
|
|
|
|
|
DrawCanvasPixel(r, c, image.get_pixel(r,c));
|
2017-10-12 01:19:28 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-24 17:14:08 +02:00
|
|
|
|
image.pixel_state.reset_and_set_all_drawable();
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
2018-03-21 16:14:21 +01:00
|
|
|
|
DrawPreview();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DrawPreview()
|
|
|
|
|
{
|
|
|
|
|
int x = right_bar.x;
|
2018-10-09 21:12:02 +02:00
|
|
|
|
int y = b_default_palette.y + b_default_palette.h + 6;
|
|
|
|
|
int preview_h = Form.cheight - y;
|
|
|
|
|
|
|
|
|
|
if (image.columns > right_bar.w) return;
|
|
|
|
|
if (image.rows > preview_h) return;
|
|
|
|
|
|
|
|
|
|
_PutImage(right_bar.w - image.columns / 2 + x - 3,
|
|
|
|
|
preview_h - image.rows / 2 + y,
|
|
|
|
|
image.columns, image.rows, image.get_image()
|
|
|
|
|
);
|
2017-10-12 01:19:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-21 16:14:21 +01:00
|
|
|
|
dword GetPixelUnderMouse()
|
|
|
|
|
{
|
|
|
|
|
return GetPixelColorFromScreen(mouse.x + Form.left + 5, mouse.y + Form.top + skin_height);
|
|
|
|
|
}
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
2018-05-01 16:35:58 +02:00
|
|
|
|
int preview_size = 128;
|
|
|
|
|
void DrawImageWithBg(dword _x, _y, _col_to)
|
|
|
|
|
{
|
|
|
|
|
_x *= preview_size;
|
|
|
|
|
_y *= preview_size;
|
|
|
|
|
DrawWideRectangle(_x,_y, preview_size, preview_size, preview_size-image.columns/2, _col_to);
|
|
|
|
|
_PutImage(preview_size - image.columns / 2 + _x, preview_size - image.rows / 2 + _y,
|
|
|
|
|
image.columns, image.rows, image.get_image_with_replaced_color(color2, _col_to));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShowWindow_TestIcon()
|
|
|
|
|
{
|
2018-10-01 18:41:14 +02:00
|
|
|
|
if (image.rows>=preview_size) || (image.columns>=preview_size) {
|
2020-04-25 16:36:28 +02:00
|
|
|
|
notify(T_TOO_BIG_IMAGE_FOR_PREVIEW);
|
2018-10-01 18:41:14 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-05-01 16:35:58 +02:00
|
|
|
|
loop() switch(WaitEvent())
|
|
|
|
|
{
|
|
|
|
|
case evButton:
|
|
|
|
|
if (GetButtonID()) ExitProcess();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evKey:
|
|
|
|
|
GetKeys();
|
|
|
|
|
if (key_scancode == SCAN_CODE_ESC) ExitProcess();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case evReDraw:
|
|
|
|
|
DefineAndDrawWindow(Form.left+100, Form.top+100, preview_size*2+9,
|
2018-10-10 16:44:01 +02:00
|
|
|
|
preview_size*2+skin_height+4, 0x74, NULL, T_TEST_ICON, 0);
|
2018-05-01 16:35:58 +02:00
|
|
|
|
DrawImageWithBg(0, 0, 0x000000);
|
|
|
|
|
DrawImageWithBg(1, 0, 0xFFFfff);
|
|
|
|
|
DrawImageWithBg(0, 1, GetPixelColorFromScreen(0, 0));
|
2020-04-18 01:52:24 +02:00
|
|
|
|
DrawImageWithBg(1, 1, sc.work);
|
2018-05-01 16:35:58 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
|
//===================================================//
|
|
|
|
|
// //
|
|
|
|
|
// EVENTS //
|
|
|
|
|
// //
|
|
|
|
|
//===================================================//
|
|
|
|
|
|
2018-05-07 18:17:53 +02:00
|
|
|
|
void EventCreateNewIcon()
|
|
|
|
|
{
|
|
|
|
|
EventSaveIconToFile();
|
|
|
|
|
Window_CanvasReSize.create();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 18:41:14 +02:00
|
|
|
|
void EventOpenIcon()
|
|
|
|
|
{
|
|
|
|
|
RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path));
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 17:14:08 +02:00
|
|
|
|
void EventSaveIconToFile()
|
2018-02-07 17:02:34 +01:00
|
|
|
|
{
|
2018-04-24 17:14:08 +02:00
|
|
|
|
int i=0;
|
|
|
|
|
char save_file_name[4096];
|
|
|
|
|
char save_path_stable[4096];
|
|
|
|
|
strcpy(#save_path_stable, "/tmp0/1");
|
|
|
|
|
do {
|
|
|
|
|
i++;
|
|
|
|
|
sprintf(#save_file_name, "%s/saved_icon_%i.png", #save_path_stable, i);
|
|
|
|
|
} while (file_exists(#save_file_name));
|
|
|
|
|
save_image(image.get_image(), image.columns, image.rows, #save_file_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventCleanCanvas()
|
|
|
|
|
{
|
2018-05-07 18:17:53 +02:00
|
|
|
|
image.create(image.rows, image.columns);
|
|
|
|
|
actionsHistory.saveCurrentState();
|
2018-04-24 17:14:08 +02:00
|
|
|
|
DrawCanvas();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventExitIconEdit()
|
|
|
|
|
{
|
|
|
|
|
EventSaveIconToFile();
|
|
|
|
|
ExitProcess();
|
2018-02-07 17:02:34 +01:00
|
|
|
|
}
|
2018-02-07 23:09:46 +01:00
|
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
|
void EventSetActiveColor(int _number, _color)
|
2018-02-07 23:09:46 +01:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2018-10-01 18:41:14 +02:00
|
|
|
|
if (last_used_colors[0] == _color) return;
|
|
|
|
|
for (i=LAST_USED_MAX-1; i>0; i--) {
|
2018-02-09 17:46:59 +01:00
|
|
|
|
last_used_colors[i] = last_used_colors[i-1];
|
2018-02-07 23:09:46 +01:00
|
|
|
|
}
|
2018-02-09 17:46:59 +01:00
|
|
|
|
last_used_colors[0] = _color;
|
|
|
|
|
|
2018-03-23 11:23:58 +01:00
|
|
|
|
if (_number == 1) color1 = _color;
|
|
|
|
|
if (_number == 2) color2 = _color;
|
2018-02-09 17:46:59 +01:00
|
|
|
|
|
2018-10-01 18:41:14 +02:00
|
|
|
|
if (b_color_gradient.hovered()) {
|
|
|
|
|
lmax = mouse.x - b_color_gradient.x;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
GenerateCurrentColorGradient();
|
|
|
|
|
}
|
2018-02-09 17:46:59 +01:00
|
|
|
|
DrawActiveColor(NULL);
|
2018-03-21 16:14:21 +01:00
|
|
|
|
DrawColorPallets();
|
2018-02-10 12:47:33 +01:00
|
|
|
|
}
|
2018-04-24 17:14:08 +02:00
|
|
|
|
|
2018-05-01 16:35:58 +02:00
|
|
|
|
void EventTestIcon()
|
|
|
|
|
{
|
|
|
|
|
CreateThread(#ShowWindow_TestIcon, #test_icon_stak+4092);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-03 15:40:26 +02:00
|
|
|
|
void EventMove(dword _action)
|
|
|
|
|
{
|
2018-05-06 22:31:36 +02:00
|
|
|
|
if (selection.state) {
|
|
|
|
|
selection.buf.move(_action);
|
2018-05-06 17:02:12 +02:00
|
|
|
|
SelectTool_onCanvasDraw();
|
2018-05-03 15:40:26 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
image.move(_action);
|
|
|
|
|
DrawCanvas();
|
2018-05-06 17:02:12 +02:00
|
|
|
|
}
|
|
|
|
|
actionsHistory.saveCurrentState();
|
2018-05-03 15:40:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-08 20:35:13 +02:00
|
|
|
|
void EventCrop()
|
|
|
|
|
{
|
|
|
|
|
if (selection.state) {
|
|
|
|
|
EventSaveIconToFile();
|
|
|
|
|
image.create(selection.buf.rows, selection.buf.columns);
|
|
|
|
|
selection.move_to_point(0,0);
|
|
|
|
|
selection.apply_to_image();
|
|
|
|
|
selection.reset();
|
|
|
|
|
actionsHistory.init();
|
|
|
|
|
DrawWindow();
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-04-25 16:36:28 +02:00
|
|
|
|
notify(T_ERROR_CROP_TOOL);
|
2018-10-10 16:44:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventShowImageMenu()
|
|
|
|
|
{
|
2020-06-04 00:21:39 +02:00
|
|
|
|
open_lmenu(image_menu_btn.x, image_menu_btn.y + image_menu_btn.h,
|
|
|
|
|
MENU_TOP_LEFT, NULL, #image_menu_items);
|
2018-10-10 16:44:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-24 18:46:26 +02:00
|
|
|
|
void EventShowEditMenu()
|
|
|
|
|
{
|
2020-06-04 00:21:39 +02:00
|
|
|
|
open_lmenu(image_menu_btn.x, image_menu_btn.y + image_menu_btn.h,
|
|
|
|
|
MENU_TOP_LEFT, NULL, #edit_menu_items);
|
2020-05-24 18:46:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-10 16:44:01 +02:00
|
|
|
|
void EventCheckMenuItemSelected()
|
|
|
|
|
{
|
2020-04-13 15:16:55 +02:00
|
|
|
|
switch(get_menu_click()) {
|
|
|
|
|
case 1:
|
|
|
|
|
EventCountColorsUsed();
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
EventReplaceImageColors(color1, color2);
|
|
|
|
|
break;
|
2021-06-12 10:58:31 +02:00
|
|
|
|
case 3:
|
|
|
|
|
EventTestIcon();
|
|
|
|
|
break;
|
2018-10-10 16:44:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventCountColorsUsed()
|
|
|
|
|
{
|
|
|
|
|
char res_str[64];
|
|
|
|
|
int cur, prev;
|
|
|
|
|
int max = image.rows*image.columns;
|
|
|
|
|
int resi=0;
|
|
|
|
|
bool unic;
|
|
|
|
|
for (cur=0; cur<max; cur++) {
|
|
|
|
|
unic = true;
|
|
|
|
|
for (prev=0; prev<cur; prev++) {
|
|
|
|
|
if (image.mas[prev] == image.mas[cur]) {unic=false; break;}
|
|
|
|
|
}
|
|
|
|
|
if (unic) resi++;
|
|
|
|
|
}
|
2020-04-25 16:36:28 +02:00
|
|
|
|
notify( sprintf(#res_str, T_UNIC_COLORS_COUNT, resi) );
|
2018-10-10 16:44:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventReplaceImageColors(dword c1, c2)
|
|
|
|
|
{
|
|
|
|
|
int max = image.rows*image.columns;
|
|
|
|
|
int cur;
|
|
|
|
|
for (cur=0; cur<max; cur++) {
|
|
|
|
|
if (image.mas[cur] == color1) image.mas[cur] = color2;
|
2018-05-08 20:35:13 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 22:48:33 +01:00
|
|
|
|
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); }
|
|
|
|
|
|
2020-05-24 18:46:26 +02:00
|
|
|
|
void EventSelectToolPencil() { setCurrentTool(TOOL_PENCIL); }
|
|
|
|
|
void EventSelectToolPick() { setCurrentTool(TOOL_PIPETTE); }
|
|
|
|
|
void EventSelectToolFill() { setCurrentTool(TOOL_FILL); }
|
|
|
|
|
void EventSelectToolLine() { setCurrentTool(TOOL_LINE); }
|
|
|
|
|
void EventSelectToolRect() { setCurrentTool(TOOL_RECT); }
|
|
|
|
|
void EventSelectToolBar() { setCurrentTool(TOOL_BAR); }
|
|
|
|
|
void EventSelectToolSelect() { setCurrentTool(TOOL_SELECT); }
|
|
|
|
|
void EventSelectToolScrCopy() { setCurrentTool(TOOL_SCREEN_COPY); }
|
2018-11-01 22:48:33 +01:00
|
|
|
|
|
|
|
|
|
char test_icon_stak22[4096];
|
|
|
|
|
|
2018-05-01 16:35:58 +02:00
|
|
|
|
stop:
|
|
|
|
|
|
|
|
|
|
char test_icon_stak[4096];
|