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-02-07 23:09:46 +01:00
|
|
|
/*
|
2018-02-10 12:47:33 +01:00
|
|
|
TODO:
|
|
|
|
window colors
|
|
|
|
enhance icon
|
2018-03-18 15:21:06 +01:00
|
|
|
pipet aside color view
|
2018-02-07 23:09:46 +01:00
|
|
|
*/
|
|
|
|
|
2017-10-17 01:41:50 +02:00
|
|
|
#define MEMSIZE 4096*40
|
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"
|
2017-10-17 01:41:50 +02:00
|
|
|
#include "../lib/obj/libimg.h"
|
2017-10-12 01:19:28 +02:00
|
|
|
#include "../lib/patterns/rgb.h"
|
|
|
|
|
2018-02-07 23:09:46 +01:00
|
|
|
#include "colors_mas.h"
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// DATA //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2018-03-23 11:23:58 +01:00
|
|
|
#define T_TITLE "Icon Editor 0.39"
|
2017-10-17 01:41:50 +02:00
|
|
|
|
2018-02-08 12:37:33 +01:00
|
|
|
#define TOOLBAR_H 24+8
|
2018-03-15 20:19:53 +01:00
|
|
|
#define PANEL_LEFT_W 16+5+5+3+3
|
2017-10-17 01:41:50 +02:00
|
|
|
#define PALLETE_SIZE 116
|
2018-03-15 20:19:53 +01:00
|
|
|
#define TB_ICON_PADDING 26
|
2017-10-12 01:19:28 +02:00
|
|
|
|
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-03-21 16:14:21 +01:00
|
|
|
block canvas = { NULL, NULL, NULL, NULL };
|
|
|
|
block wrapper = { PANEL_LEFT_W, TOOLBAR_H, NULL, NULL };
|
|
|
|
block right_bar = { NULL, TOOLBAR_H, RIGHT_BAR_W+10, NULL };
|
|
|
|
|
|
|
|
block b_color_gradient = {NULL, 30+TOOLBAR_H, RIGHT_BAR_W, 30};
|
|
|
|
block b_last_colors = {NULL, 70+TOOLBAR_H, RIGHT_BAR_W, COLSIZE*2};
|
|
|
|
block b_default_palette = {NULL, COLSIZE*2+10+70+TOOLBAR_H, RIGHT_BAR_W, COLSIZE*9};
|
2017-10-12 01:19:28 +02:00
|
|
|
|
2018-03-23 11:23:58 +01:00
|
|
|
dword color1 = 0x000000;
|
|
|
|
dword color2 = 0xFFFfff;
|
|
|
|
dword tool_color;
|
2017-10-12 01:19:28 +02:00
|
|
|
|
|
|
|
enum {
|
2017-10-17 01:41:50 +02:00
|
|
|
BTN_NEW = 40,
|
|
|
|
BTN_OPEN,
|
|
|
|
BTN_SAVE,
|
|
|
|
BTN_MOVE_LEFT,
|
|
|
|
BTN_MOVE_RIGHT,
|
|
|
|
BTN_MOVE_UP,
|
|
|
|
BTN_MOVE_DOWN,
|
|
|
|
BTN_FLIP_HOR,
|
|
|
|
BTN_FLIP_VER,
|
|
|
|
BTN_ROTATE_LEFT,
|
|
|
|
BTN_ROTATE_RIGHT,
|
2018-03-15 20:19:53 +01:00
|
|
|
BTN_PENCIL,
|
2017-10-17 01:41:50 +02:00
|
|
|
BTN_PICK,
|
2018-02-10 12:47:33 +01:00
|
|
|
BTN_FILL,
|
2018-03-14 19:22:55 +01:00
|
|
|
BTN_LINE,
|
|
|
|
BTN_RECT,
|
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-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-02-09 17:46:59 +01:00
|
|
|
dword last_used_colors[13*2] = {
|
2018-03-16 21:34:44 +01:00
|
|
|
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,
|
|
|
|
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,
|
|
|
|
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF
|
2018-02-09 17:46:59 +01:00
|
|
|
};
|
2017-10-12 01:19:28 +02:00
|
|
|
|
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"
|
|
|
|
|
2018-02-07 23:09:46 +01:00
|
|
|
libimg_image open_image;
|
2018-03-22 18:03:56 +01:00
|
|
|
_ActionsHistory actionsHistory;
|
2018-02-05 20:13:37 +01:00
|
|
|
|
2018-02-10 12:47:33 +01:00
|
|
|
enum {
|
2018-03-14 19:22:55 +01:00
|
|
|
TOOL_NONE = -1,
|
2018-03-15 20:19:53 +01:00
|
|
|
TOOL_PENCIL,
|
|
|
|
TOOL_PIPETTE,
|
|
|
|
TOOL_FILL,
|
|
|
|
TOOL_LINE,
|
|
|
|
TOOL_RECT,
|
2018-03-14 19:22:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Tool {
|
|
|
|
int id;
|
|
|
|
|
|
|
|
void (*activate)();
|
|
|
|
void (*deactivate)();
|
|
|
|
void (*onMouseEvent)(int x, int y, int lkm, int pkm);
|
|
|
|
void (*onCanvasDraw)();
|
2018-02-10 12:47:33 +01:00
|
|
|
};
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
|
|
Tool tools[5];
|
|
|
|
int currentTool = -1;
|
|
|
|
|
|
|
|
void resetCurrentTool() {
|
|
|
|
if ((currentTool != TOOL_NONE) && (tools[currentTool].deactivate != 0)) {
|
|
|
|
tools[currentTool].deactivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
currentTool = TOOL_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCurrentTool(int index) {
|
|
|
|
resetCurrentTool();
|
2018-03-22 18:03:56 +01:00
|
|
|
|
|
|
|
currentTool = index;
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
|
|
if ((index != TOOL_NONE) && (tools[index].activate != 0))
|
|
|
|
tools[index].activate();
|
2018-03-15 20:19:53 +01:00
|
|
|
|
|
|
|
DrawLeftPanel();
|
2018-03-14 19:22:55 +01:00
|
|
|
}
|
2018-02-10 12:47:33 +01:00
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// CODE //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2018-03-14 19:22:55 +01:00
|
|
|
void FillTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
2018-03-23 11:23:58 +01:00
|
|
|
if (canvas.hovered()) && (currentTool==TOOL_FILL) && (mouse.up)
|
2018-03-14 19:22:55 +01:00
|
|
|
{
|
2018-03-23 11:23:58 +01:00
|
|
|
EventFill(mouseY-canvas.y/zoom.value,
|
|
|
|
mouseX-canvas.x/zoom.value, tool_color);
|
|
|
|
actionsHistory.saveCurrentState();
|
2018-03-14 19:22:55 +01:00
|
|
|
DrawCanvas();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PipetteTool_activate() {
|
|
|
|
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PipetteTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
2018-03-23 11:23:58 +01:00
|
|
|
tool_color = GetPixelUnderMouse();
|
|
|
|
DrawBar(Form.cwidth-30, 5, 20, 20, tool_color);
|
2018-03-14 19:22:55 +01:00
|
|
|
|
2018-03-23 11:23:58 +01:00
|
|
|
if (mouse.down) {
|
2018-03-14 19:22:55 +01:00
|
|
|
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
|
2018-03-23 11:23:58 +01:00
|
|
|
if (mouse.key&MOUSE_LEFT) EventSetActiveColor(1, tool_color);
|
|
|
|
if (mouse.key&MOUSE_RIGHT) EventSetActiveColor(2, tool_color);
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
|
|
setCurrentTool(TOOL_PENCIL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
bool PencilTool_Drawing = false;
|
|
|
|
|
2018-03-14 19:22:55 +01:00
|
|
|
void PencilTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
2018-03-21 16:14:21 +01:00
|
|
|
if (canvas.hovered())
|
2018-03-14 19:22:55 +01:00
|
|
|
{
|
2018-03-23 11:23:58 +01:00
|
|
|
if ((PencilTool_Drawing == true) && (!mouse.key)) {
|
2018-03-22 18:03:56 +01:00
|
|
|
actionsHistory.saveCurrentState();
|
|
|
|
PencilTool_Drawing = false;
|
|
|
|
}
|
|
|
|
|
2018-03-23 11:23:58 +01:00
|
|
|
if (mouse.key) {
|
2018-03-14 19:22:55 +01:00
|
|
|
image.set_pixel(mouseY-canvas.y/zoom.value,
|
2018-03-23 11:23:58 +01:00
|
|
|
mouseX-canvas.x/zoom.value, tool_color);
|
2018-03-22 18:03:56 +01:00
|
|
|
PencilTool_Drawing = true;
|
2018-03-23 11:23:58 +01:00
|
|
|
}
|
2018-03-14 19:22:55 +01:00
|
|
|
DrawCanvas();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
void PencilTool_reset() {
|
|
|
|
PencilTool_Drawing = false;
|
|
|
|
}
|
|
|
|
|
2018-03-14 19:22:55 +01:00
|
|
|
// Line tool
|
2018-03-22 18:03:56 +01:00
|
|
|
struct SimpleFigureTool_State {
|
|
|
|
int startX, startY;
|
|
|
|
int lastTempPosX, lastTempPosY;
|
|
|
|
};
|
2018-03-14 19:22:55 +01:00
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
enum {
|
|
|
|
TOOL_LINE_STATE,
|
|
|
|
TOOL_RECT_STATE
|
|
|
|
};
|
2018-03-14 19:22:55 +01:00
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
dword currentFigToolState = -1;
|
|
|
|
SimpleFigureTool_State figTool_States[2];
|
|
|
|
|
|
|
|
void SimpleFigureTool_Reset() {
|
|
|
|
if (currentTool == TOOL_LINE)
|
|
|
|
currentFigToolState = TOOL_LINE_STATE;
|
|
|
|
else if (currentTool == TOOL_RECT)
|
|
|
|
currentFigToolState = TOOL_RECT_STATE;
|
|
|
|
|
|
|
|
figTool_States[currentFigToolState].startX = -1;
|
|
|
|
figTool_States[currentFigToolState].startY = -1;
|
|
|
|
figTool_States[currentFigToolState].lastTempPosX = -1;
|
|
|
|
figTool_States[currentFigToolState].lastTempPosY = -1;
|
2018-03-14 19:22:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-22 21:55:23 +01:00
|
|
|
int mouseX_last;
|
|
|
|
int mouseY_last;
|
|
|
|
bool first_click_in_canvas = false;
|
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
void SimpleFigureTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
2018-03-22 21:55:23 +01:00
|
|
|
if (mouse.down) && (canvas.hovered()) first_click_in_canvas = true;
|
|
|
|
if (first_click_in_canvas)
|
2018-03-14 19:22:55 +01:00
|
|
|
{
|
2018-03-22 21:55:23 +01:00
|
|
|
if (mouseX>canvas.x+canvas.w-zoom.value) mouseX = canvas.x+canvas.w-zoom.value;
|
|
|
|
if (mouseY>canvas.y+canvas.h-zoom.value) mouseY = canvas.y+canvas.h-zoom.value;
|
|
|
|
if (mouseX<canvas.x) mouseX = canvas.x;
|
|
|
|
if (mouseY<canvas.y) mouseY = canvas.y;
|
|
|
|
|
2018-03-23 11:23:58 +01:00
|
|
|
if (mouse.key) {
|
2018-03-22 18:03:56 +01:00
|
|
|
if ((figTool_States[currentFigToolState].startX < 0) || (figTool_States[currentFigToolState].startY < 0)) {
|
|
|
|
figTool_States[currentFigToolState].startX = mouseX;
|
|
|
|
figTool_States[currentFigToolState].startY = mouseY;
|
2018-03-14 19:22:55 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-03-22 18:03:56 +01:00
|
|
|
if ((calc(mouseX - canvas.x/zoom.value) != figTool_States[currentFigToolState].lastTempPosX)
|
|
|
|
|| (calc(mouseY - canvas.y/zoom.value) != figTool_States[currentFigToolState].lastTempPosY))
|
|
|
|
{
|
|
|
|
DrawCanvas();
|
|
|
|
}
|
2018-03-14 19:22:55 +01:00
|
|
|
}
|
2018-03-22 21:55:23 +01:00
|
|
|
mouseX_last = mouseX;
|
|
|
|
mouseY_last = mouseY;
|
2018-03-14 19:22:55 +01:00
|
|
|
}
|
2018-03-22 21:55:23 +01:00
|
|
|
if (mouse.up) {
|
2018-03-22 18:03:56 +01:00
|
|
|
if ((figTool_States[currentFigToolState].startX >= 0) && (figTool_States[currentFigToolState].startY >= 0)) {
|
|
|
|
// Draw line from start position to current position
|
|
|
|
if (currentTool == TOOL_LINE) {
|
|
|
|
DrawLine(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
|
|
|
|
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
|
|
|
|
mouseX - canvas.x/zoom.value,
|
|
|
|
mouseY - canvas.y/zoom.value,
|
2018-03-23 11:23:58 +01:00
|
|
|
tool_color,
|
2018-03-22 18:03:56 +01:00
|
|
|
1);
|
|
|
|
}
|
|
|
|
else if (currentTool == TOOL_RECT) {
|
|
|
|
DrawRectangleInCanvas(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
|
|
|
|
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
|
|
|
|
mouseX - canvas.x/zoom.value,
|
2018-03-23 11:23:58 +01:00
|
|
|
mouseY - canvas.y/zoom.value, tool_color, 1);
|
2018-03-22 18:03:56 +01:00
|
|
|
}
|
2018-03-14 19:22:55 +01:00
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
DrawCanvas();
|
2018-03-14 19:22:55 +01:00
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
actionsHistory.saveCurrentState();
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
|
|
// Reset start position
|
2018-03-22 18:03:56 +01:00
|
|
|
figTool_States[currentFigToolState].startX = -1;
|
|
|
|
figTool_States[currentFigToolState].startY = -1;
|
2018-03-22 21:55:23 +01:00
|
|
|
|
|
|
|
first_click_in_canvas = false;
|
2018-03-14 19:22:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
void SimpleFigureTool_onCanvasDraw() {
|
2018-03-23 11:23:58 +01:00
|
|
|
if ((figTool_States[currentFigToolState].startX >= 0) && (figTool_States[currentFigToolState].startY >= 0) && (mouse.key)) {
|
2018-03-22 18:03:56 +01:00
|
|
|
if (currentTool == TOOL_LINE) {
|
|
|
|
DrawLine(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
|
|
|
|
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
|
2018-03-22 21:55:23 +01:00
|
|
|
mouseX_last - canvas.x/zoom.value,
|
|
|
|
mouseY_last - canvas.y/zoom.value,
|
2018-03-23 11:23:58 +01:00
|
|
|
tool_color,
|
2018-03-22 18:03:56 +01:00
|
|
|
2);
|
|
|
|
}
|
|
|
|
else if (currentTool == TOOL_RECT) {
|
|
|
|
DrawRectangleInCanvas(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
|
|
|
|
figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
|
2018-03-22 21:55:23 +01:00
|
|
|
mouseX_last - canvas.x/zoom.value,
|
|
|
|
mouseY_last - canvas.y/zoom.value,
|
2018-03-23 11:23:58 +01:00
|
|
|
tool_color,
|
2018-03-22 21:55:23 +01:00
|
|
|
2);
|
2018-03-22 18:03:56 +01:00
|
|
|
}
|
|
|
|
|
2018-03-22 21:55:23 +01:00
|
|
|
figTool_States[currentFigToolState].lastTempPosX = mouseX_last - canvas.x/zoom.value;
|
|
|
|
figTool_States[currentFigToolState].lastTempPosY = mouseY_last - canvas.y/zoom.value;
|
2018-03-14 19:22:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void initTools()
|
|
|
|
{
|
2018-03-15 20:19:53 +01:00
|
|
|
tools[0].id = TOOL_PENCIL;
|
|
|
|
tools[0].onMouseEvent = #PencilTool_onMouseEvent;
|
2018-03-22 18:03:56 +01:00
|
|
|
tools[0].deactivate = #PencilTool_reset;
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
|
|
tools[1].id = TOOL_PIPETTE;
|
|
|
|
tools[1].activate = #PipetteTool_activate;
|
|
|
|
tools[1].onMouseEvent = #PipetteTool_onMouseEvent;
|
|
|
|
|
2018-03-15 20:19:53 +01:00
|
|
|
tools[2].id = TOOL_FILL;
|
|
|
|
tools[2].onMouseEvent = #FillTool_onMouseEvent;
|
2018-03-14 19:22:55 +01:00
|
|
|
|
2018-03-22 18:03:56 +01:00
|
|
|
tools[3].id = TOOL_LINE;
|
|
|
|
tools[3].activate = #SimpleFigureTool_Reset;
|
|
|
|
tools[3].deactivate = #SimpleFigureTool_Reset;
|
|
|
|
tools[3].onMouseEvent = #SimpleFigureTool_onMouseEvent;
|
|
|
|
tools[3].onCanvasDraw = #SimpleFigureTool_onCanvasDraw;
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
|
|
tools[4].id = TOOL_RECT;
|
2018-03-22 18:03:56 +01:00
|
|
|
tools[4].activate = #SimpleFigureTool_Reset;
|
|
|
|
tools[4].deactivate = #SimpleFigureTool_Reset;
|
|
|
|
tools[4].onMouseEvent = #SimpleFigureTool_onMouseEvent;
|
|
|
|
tools[4].onCanvasDraw = #SimpleFigureTool_onCanvasDraw;
|
2018-03-14 19:22:55 +01:00
|
|
|
}
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
word btn;
|
|
|
|
|
2017-10-17 01:41:50 +02:00
|
|
|
load_dll(libio, #libio_init, 1);
|
|
|
|
load_dll(libimg, #libimg_init, 1);
|
|
|
|
Libimg_LoadImage(#skin, "/sys/icons16.png");
|
2018-02-10 12:47:33 +01:00
|
|
|
//system.color.get();
|
2018-03-15 20:19:53 +01:00
|
|
|
//Libimg_ReplaceColor(tools_img.image, tools_img.w, tools_img.h, 0xFFF8C0D0, system.color.work);
|
2018-03-14 19:22:55 +01:00
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
image.create(32, 32);
|
2018-02-07 23:09:46 +01:00
|
|
|
|
2018-02-10 12:47:33 +01:00
|
|
|
if (param[0]) {
|
2018-02-07 23:09:46 +01:00
|
|
|
Libimg_LoadImage(#open_image, #param);
|
|
|
|
if (open_image.w==32) && (open_image.h==32) {
|
2018-02-10 12:47:33 +01:00
|
|
|
image.set_image(open_image.imgsrc);
|
2018-02-07 23:09:46 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-03-16 21:34:44 +01:00
|
|
|
notify("'Error: image format is unacceptable (PNG, 32x32x16b expected)' -E");
|
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:
|
|
|
|
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-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-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-02-05 20:13:37 +01:00
|
|
|
btn = GetButtonID();
|
2018-04-19 16:16:32 +02:00
|
|
|
if (zoom.click(btn)) DrawEditArea();
|
2017-10-17 01:41:50 +02:00
|
|
|
switch(btn)
|
|
|
|
{
|
2018-02-07 23:09:46 +01:00
|
|
|
case BTN_NEW:
|
2018-02-09 17:46:59 +01:00
|
|
|
image.create(32, 32);
|
2018-02-07 23:09:46 +01:00
|
|
|
DrawCanvas();
|
|
|
|
break;
|
|
|
|
case BTN_OPEN:
|
2018-03-16 21:34:44 +01:00
|
|
|
RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path));
|
2018-02-07 23:09:46 +01:00
|
|
|
break;
|
|
|
|
case BTN_SAVE:
|
|
|
|
EventSave();
|
|
|
|
break;
|
2017-10-17 01:41:50 +02:00
|
|
|
case BTN_MOVE_LEFT:
|
2018-02-07 23:09:46 +01:00
|
|
|
image.move(MOVE_LEFT);
|
|
|
|
DrawCanvas();
|
2017-10-17 01:41:50 +02:00
|
|
|
break;
|
|
|
|
case BTN_MOVE_RIGHT:
|
2018-02-07 23:09:46 +01:00
|
|
|
image.move(MOVE_RIGHT);
|
|
|
|
DrawCanvas();
|
2017-10-17 01:41:50 +02:00
|
|
|
break;
|
2018-02-05 00:12:35 +01:00
|
|
|
case BTN_MOVE_UP:
|
2018-02-07 23:09:46 +01:00
|
|
|
image.move(MOVE_UP);
|
|
|
|
DrawCanvas();
|
2018-02-05 00:12:35 +01:00
|
|
|
break;
|
|
|
|
case BTN_MOVE_DOWN:
|
2018-02-07 23:09:46 +01:00
|
|
|
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();
|
2018-02-05 00:12:35 +01:00
|
|
|
break;
|
2018-03-15 20:19:53 +01:00
|
|
|
case BTN_PENCIL:
|
|
|
|
setCurrentTool(TOOL_PENCIL);
|
|
|
|
break;
|
2017-10-17 01:41:50 +02:00
|
|
|
case BTN_PICK:
|
2018-03-14 19:22:55 +01:00
|
|
|
setCurrentTool(TOOL_PIPETTE);
|
|
|
|
//EventPickActivate();
|
2017-10-17 01:41:50 +02:00
|
|
|
break;
|
2018-02-10 12:47:33 +01:00
|
|
|
case BTN_FILL:
|
2018-03-14 19:22:55 +01:00
|
|
|
setCurrentTool(TOOL_FILL);
|
|
|
|
//EventFillActivate();
|
|
|
|
break;
|
|
|
|
case BTN_LINE:
|
|
|
|
setCurrentTool(TOOL_LINE);
|
|
|
|
break;
|
|
|
|
case BTN_RECT:
|
|
|
|
setCurrentTool(TOOL_RECT);
|
2018-02-10 12:47:33 +01:00
|
|
|
break;
|
2018-02-08 12:37:33 +01:00
|
|
|
case CLOSE_BTN:
|
|
|
|
ExitProcess();
|
|
|
|
break;
|
2017-10-12 01:19:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case evKey:
|
|
|
|
GetKeys();
|
2018-03-14 19:22:55 +01:00
|
|
|
if (key_scancode == SCAN_CODE_ESC) setCurrentTool(TOOL_PENCIL);
|
2018-03-15 20:19:53 +01:00
|
|
|
if (key_scancode == SCAN_CODE_KEY_P) setCurrentTool(TOOL_PENCIL);
|
2018-03-14 19:22:55 +01:00
|
|
|
if (key_scancode == SCAN_CODE_KEY_I) setCurrentTool(TOOL_PIPETTE);
|
2018-03-15 20:19:53 +01:00
|
|
|
if (key_scancode == SCAN_CODE_KEY_F) setCurrentTool(TOOL_FILL);
|
|
|
|
if (key_scancode == SCAN_CODE_KEY_L) setCurrentTool(TOOL_LINE);
|
|
|
|
if (key_scancode == SCAN_CODE_KEY_R) setCurrentTool(TOOL_RECT);
|
2018-03-22 18:03:56 +01:00
|
|
|
|
|
|
|
if (key_scancode == SCAN_CODE_KEY_S) actionsHistory.undoLastAction();
|
|
|
|
if (key_scancode == SCAN_CODE_KEY_C) actionsHistory.redoLastAction();
|
|
|
|
|
2018-04-19 16:16:32 +02:00
|
|
|
if (key_scancode == SCAN_CODE_MINUS) {zoom.inc(); DrawEditArea();}
|
|
|
|
if (key_scancode == SCAN_CODE_PLUS) {zoom.dec(); DrawEditArea();}
|
2017-10-12 01:19:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case evReDraw:
|
|
|
|
draw_window();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 01:41:50 +02:00
|
|
|
void DrawToolbarButton(dword _id, _x, _icon_n)
|
|
|
|
{
|
2018-02-08 12:37:33 +01:00
|
|
|
DrawWideRectangle(_x, 4, 22, 22, 3, 0xFFFfff);
|
|
|
|
DefineHiddenButton(_x, 4, 21, 21, _id);
|
|
|
|
img_draw stdcall(skin.image, _x+3, 7, 16, 16, 0, _icon_n*16);
|
2017-10-17 01:41:50 +02:00
|
|
|
}
|
|
|
|
|
2018-03-15 20:19:53 +01:00
|
|
|
void DrawLeftPanelButton(dword _id, _y, _icon_n)
|
|
|
|
{
|
|
|
|
int x = 5;
|
|
|
|
DrawWideRectangle(x, _y, 22, 22, 3, 0xFFFfff);
|
|
|
|
DefineHiddenButton(x, _y, 21, 21, _id);
|
|
|
|
img_draw stdcall(skin.image, x+3, _y+3, 16, 16, 0, _icon_n*16);
|
|
|
|
}
|
|
|
|
|
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-02-07 23:09:46 +01:00
|
|
|
sprintf(#param,"Canvas: %ix%i", image.rows, image.columns);
|
2018-02-07 17:02:34 +01:00
|
|
|
WriteText(wrapper.x+wrapper.w-calc(strlen(#param)*8), zoom.y+2, 0x90, system.color.work_text, #param);
|
2018-02-05 20:13:37 +01:00
|
|
|
}
|
|
|
|
|
2017-10-12 01:19:28 +02:00
|
|
|
void draw_window()
|
|
|
|
{
|
2017-10-17 01:41:50 +02:00
|
|
|
incn tx;
|
2017-10-12 01:19:28 +02:00
|
|
|
system.color.get();
|
2018-02-07 23:09:46 +01:00
|
|
|
DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x33, system.color.work, T_TITLE, 0);
|
2017-10-12 01:19:28 +02:00
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
2018-02-08 12:37:33 +01:00
|
|
|
if (Form.status_window>2) return;
|
|
|
|
if (Form.width < 560) { MoveSize(OLD,OLD,560,OLD); return; }
|
|
|
|
if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; }
|
|
|
|
|
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;
|
2017-10-12 01:19:28 +02:00
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
tx.n = 10-TB_ICON_PADDING;
|
2018-02-05 20:13:37 +01:00
|
|
|
DrawToolbarButton(BTN_NEW, tx.inc(TB_ICON_PADDING), 2); //not implemented
|
|
|
|
DrawToolbarButton(BTN_OPEN, tx.inc(TB_ICON_PADDING), 0); //not implemented
|
2018-02-07 23:09:46 +01:00
|
|
|
DrawToolbarButton(BTN_SAVE, tx.inc(TB_ICON_PADDING), 5);
|
2018-03-23 11:23:58 +01:00
|
|
|
DrawToolbarButton(BTN_MOVE_LEFT, tx.inc(TB_ICON_PADDING+8), 30);
|
2017-10-17 01:41:50 +02:00
|
|
|
DrawToolbarButton(BTN_MOVE_RIGHT, tx.inc(TB_ICON_PADDING), 31);
|
2018-02-05 00:12:35 +01:00
|
|
|
DrawToolbarButton(BTN_MOVE_UP, tx.inc(TB_ICON_PADDING), 32);
|
|
|
|
DrawToolbarButton(BTN_MOVE_DOWN, tx.inc(TB_ICON_PADDING), 33);
|
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
DrawToolbarButton(BTN_FLIP_HOR, tx.inc(TB_ICON_PADDING+8), 34);
|
|
|
|
DrawToolbarButton(BTN_FLIP_VER, tx.inc(TB_ICON_PADDING), 35);
|
|
|
|
// DrawToolbarButton(BTN_ROTATE_LEFT, tx.inc(TB_ICON_PADDING), 36); //not implemented
|
|
|
|
// DrawToolbarButton(BTN_ROTATE_RIGHT, tx.inc(TB_ICON_PADDING), 37); //not implemented
|
2018-02-05 20:13:37 +01:00
|
|
|
|
2018-03-15 20:19:53 +01:00
|
|
|
DrawLeftPanel();
|
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
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
DrawActiveColor(right_bar.y);
|
2018-03-21 16:14:21 +01:00
|
|
|
DrawColorPallets();
|
2017-10-12 01:19:28 +02:00
|
|
|
|
2018-02-05 20:13:37 +01:00
|
|
|
DrawStatusBar();
|
2017-10-12 01:19:28 +02:00
|
|
|
}
|
|
|
|
|
2018-03-15 20:19:53 +01:00
|
|
|
void DrawLeftPanel()
|
|
|
|
{
|
|
|
|
incn ty;
|
|
|
|
ty.n = TOOLBAR_H-TB_ICON_PADDING;
|
|
|
|
DrawLeftPanelButton(BTN_PENCIL, ty.inc(TB_ICON_PADDING), 38);
|
|
|
|
DrawLeftPanelButton(BTN_PICK, ty.inc(TB_ICON_PADDING), 39);
|
|
|
|
DrawLeftPanelButton(BTN_FILL, ty.inc(TB_ICON_PADDING), 40);
|
|
|
|
DrawLeftPanelButton(BTN_LINE, ty.inc(TB_ICON_PADDING), 41);
|
|
|
|
DrawLeftPanelButton(BTN_RECT, ty.inc(TB_ICON_PADDING), 42);
|
|
|
|
DrawRectangle3D(5, currentTool*TB_ICON_PADDING+TOOLBAR_H, 16+3+2, 16+3+2, 0x333333, 0x777777);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-03-18 15:21:06 +01:00
|
|
|
wrapper.w = Form.cwidth - right_bar.w - 10 - wrapper.x;
|
2018-02-07 17:02:34 +01:00
|
|
|
wrapper.h = Form.cheight - TOOLBAR_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-19 16:16:32 +02:00
|
|
|
zoom.dec();
|
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
|
|
|
|
2018-02-09 17:46:59 +01:00
|
|
|
DrawRectangle(wrapper.x-1, wrapper.y-1, wrapper.w, wrapper.h, system.color.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)
|
|
|
|
{
|
|
|
|
static dword outy;
|
|
|
|
if (iny != NULL) outy = iny;
|
2018-03-23 11:23:58 +01:00
|
|
|
DrawBar(right_bar.x, outy, 20, 20, color1);
|
|
|
|
sprintf(#param, "%A", color1);
|
2017-10-12 01:19:28 +02:00
|
|
|
EDI = system.color.work;
|
2018-02-05 20:13:37 +01:00
|
|
|
WriteText(right_bar.x + 30, outy + 3, 0xD0, system.color.work_text, #param+4);
|
2018-02-07 23:09:46 +01:00
|
|
|
|
2018-03-23 11:23:58 +01:00
|
|
|
DrawBar(right_bar.x+110, outy, 20, 20, color2);
|
|
|
|
sprintf(#param, "%A", color2);
|
2018-02-07 23:09:46 +01:00
|
|
|
EDI = system.color.work;
|
|
|
|
WriteText(right_bar.x+110 + 30, outy + 3, 0xD0, system.color.work_text, #param+4);
|
2018-03-21 16:14:21 +01:00
|
|
|
DrawCurrentColorGradientByLightness();
|
2018-03-18 15:21:06 +01:00
|
|
|
}
|
|
|
|
|
2018-03-21 16:14:21 +01:00
|
|
|
void DrawCurrentColorGradientByLightness()
|
2018-03-18 15:21:06 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int w = right_bar.w-10/2;
|
|
|
|
for (i=0; i<w; i++)
|
2018-03-21 16:14:21 +01:00
|
|
|
DrawBar(b_color_gradient.x+i, b_color_gradient.y,
|
2018-03-23 11:23:58 +01:00
|
|
|
1, b_color_gradient.h, MixColors(color1,0xFFFfff,255*i/w));
|
2018-03-18 15:21:06 +01:00
|
|
|
for (i=0 ; i<=w; i++)
|
2018-03-21 16:14:21 +01:00
|
|
|
DrawBar(b_color_gradient.x+w+w-i, b_color_gradient.y,
|
2018-03-23 11:23:58 +01:00
|
|
|
1, b_color_gradient.h, MixColors(color1,0x000000,255*i/w));
|
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
|
|
|
|
for (r = 0; r < 2; r++)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2017-10-12 01:19:28 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-14 19:22:55 +01:00
|
|
|
|
|
|
|
if ((currentTool != TOOL_NONE) && (tools[currentTool].onCanvasDraw != 0))
|
|
|
|
tools[currentTool].onCanvasDraw();
|
|
|
|
|
2018-03-21 16:14:21 +01:00
|
|
|
DrawPreview();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawPreview()
|
|
|
|
{
|
|
|
|
int x = right_bar.x;
|
|
|
|
int y = wrapper.y + wrapper.h - image.rows-2;
|
|
|
|
DrawRectangle(x, y, image.columns+1, image.rows+1, system.color.work_graph);
|
|
|
|
_PutImage(x+1,y+1, 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
|
|
|
|
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// EVENTS //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2018-02-07 23:09:46 +01:00
|
|
|
void EventSave()
|
2018-02-07 17:02:34 +01:00
|
|
|
{
|
2018-03-16 21:34:44 +01:00
|
|
|
dword encoded_data=0;
|
|
|
|
dword encoded_size=0;
|
|
|
|
dword image_ptr = 0;
|
|
|
|
|
|
|
|
image_ptr = create_image(Image_bpp24, 32, 32);
|
|
|
|
|
|
|
|
if (image_ptr == 0) {
|
|
|
|
notify("'Error saving file, probably not enought memory!' -E");
|
2018-02-07 23:09:46 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-03-16 21:34:44 +01:00
|
|
|
EDI = image_ptr;
|
|
|
|
memmov(EDI._Image.Data, image.get_image(), image.rows * image.columns * 3);
|
|
|
|
|
|
|
|
encoded_data = encode_image(image_ptr, LIBIMG_FORMAT_PNG, 0, #encoded_size);
|
|
|
|
|
|
|
|
img_destroy stdcall(image_ptr);
|
|
|
|
|
|
|
|
if(encoded_data == 0) {
|
|
|
|
notify("'Error saving file, incorrect data!' -E");
|
|
|
|
}
|
|
|
|
else {
|
2018-04-16 00:44:36 +02:00
|
|
|
if (CreateFile(encoded_size, encoded_data, "/rd/1/saved_image.png") == 0) {
|
2018-03-16 21:34:44 +01:00
|
|
|
notify("'File saved as /rd/1/saved_image.png' -O");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
notify("'Error saving file, probably not enought space on ramdisk!' -E");
|
|
|
|
}
|
|
|
|
}
|
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-02-09 17:46:59 +01:00
|
|
|
for (i=13*2-1; i>0; i--) {
|
|
|
|
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
|
|
|
|
|
|
|
DrawActiveColor(NULL);
|
2018-03-21 16:14:21 +01:00
|
|
|
DrawColorPallets();
|
2018-02-10 12:47:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventFill(dword _r, _c, _color)
|
|
|
|
{
|
|
|
|
#define MARKED 6
|
|
|
|
int r, c, i, restart;
|
|
|
|
|
|
|
|
dword old_color = image.get_pixel(_r, _c);
|
|
|
|
image.set_pixel(_r, _c, MARKED);
|
|
|
|
|
|
|
|
do {
|
|
|
|
restart=false;
|
|
|
|
for (r = 0; r < image.rows; r++)
|
|
|
|
for (c = 0; c < image.columns; c++)
|
|
|
|
{
|
|
|
|
IF (image.get_pixel(r,c) != old_color) continue;
|
|
|
|
IF (image.get_pixel(r,c) == MARKED) continue;
|
|
|
|
|
2018-03-18 15:21:06 +01:00
|
|
|
IF (c>0) && (image.get_pixel(r,c-1) == MARKED) image.set_pixel(r,c,MARKED);
|
|
|
|
IF (r>0) && (image.get_pixel(r-1,c) == MARKED) image.set_pixel(r,c,MARKED);
|
|
|
|
IF (c<image.columns-1) && (image.get_pixel(r,c+1) == MARKED) image.set_pixel(r,c,MARKED);
|
|
|
|
IF (r<image.rows-1) && (image.get_pixel(r+1,c) == MARKED) image.set_pixel(r,c,MARKED);
|
2018-02-10 12:47:33 +01:00
|
|
|
|
2018-03-18 15:21:06 +01:00
|
|
|
IF (image.get_pixel(r,c)==MARKED) restart=true;
|
2018-02-10 12:47:33 +01:00
|
|
|
}
|
|
|
|
}while(restart);
|
|
|
|
|
|
|
|
for (i=0; i<image.columns*image.rows; i++)
|
|
|
|
IF (image.mas[i]==MARKED) image.mas[i] = _color;
|
|
|
|
}
|
|
|
|
|
2018-03-14 19:22:55 +01:00
|
|
|
// target - image (1) or canvas (2)
|
|
|
|
void DrawLine(int x1, int y1, int x2, int y2, dword color, int target) {
|
|
|
|
int dx, dy, signX, signY, error, error2;
|
|
|
|
|
|
|
|
dx = x2 - x1;
|
|
|
|
|
|
|
|
if (dx < 0)
|
|
|
|
dx = -dx;
|
|
|
|
|
|
|
|
dy = y2 - y1;
|
|
|
|
|
|
|
|
if (dy < 0)
|
|
|
|
dy = -dy;
|
|
|
|
|
|
|
|
if (x1 < x2)
|
|
|
|
signX = 1;
|
|
|
|
else
|
|
|
|
signX = -1;
|
|
|
|
|
|
|
|
if (y1 < y2)
|
|
|
|
signY = 1;
|
|
|
|
else
|
|
|
|
signY = -1;
|
|
|
|
|
|
|
|
error = dx - dy;
|
|
|
|
|
|
|
|
if (target == 1)
|
|
|
|
image.set_pixel(y2, x2, color);
|
|
|
|
else
|
|
|
|
DrawBar(x2*zoom.value + canvas.x, y2*zoom.value + canvas.y,
|
|
|
|
zoom.value, zoom.value, color);
|
|
|
|
|
|
|
|
while((x1 != x2) || (y1 != y2))
|
|
|
|
{
|
|
|
|
if (target == 1)
|
|
|
|
image.set_pixel(y1, x1, color);
|
|
|
|
else
|
|
|
|
DrawBar(x1*zoom.value + canvas.x, y1*zoom.value + canvas.y,
|
|
|
|
zoom.value, zoom.value, color);
|
|
|
|
|
|
|
|
error2 = error * 2;
|
|
|
|
|
|
|
|
if(error2 > calc(-dy))
|
|
|
|
{
|
|
|
|
error -= dy;
|
|
|
|
x1 += signX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(error2 < dx)
|
|
|
|
{
|
|
|
|
error += dx;
|
|
|
|
y1 += signY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawRectangleInCanvas(int x1, int y1, int x2, int y2, dword color, int target) {
|
|
|
|
DrawLine(x1, y1, x2, y1, color, target);
|
|
|
|
DrawLine(x2, y1, x2, y2, color, target);
|
|
|
|
DrawLine(x2, y2, x1, y2, color, target);
|
|
|
|
DrawLine(x1, y2, x1, y1, color, target);
|
|
|
|
}
|