IconEdit 0.39: more flexible to use colors, optimizations

git-svn-id: svn://kolibrios.org@7207 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2018-03-23 10:23:58 +00:00
parent 4c0b3e3e85
commit e974c281d5

View File

@ -28,7 +28,7 @@ pipet aside color view
// // // //
//===================================================// //===================================================//
#define T_TITLE "Icon Editor 0.38" #define T_TITLE "Icon Editor 0.39"
#define TOOLBAR_H 24+8 #define TOOLBAR_H 24+8
#define PANEL_LEFT_W 16+5+5+3+3 #define PANEL_LEFT_W 16+5+5+3+3
@ -59,8 +59,9 @@ 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_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}; block b_default_palette = {NULL, COLSIZE*2+10+70+TOOLBAR_H, RIGHT_BAR_W, COLSIZE*9};
dword active_color_1 = 0x000000; dword color1 = 0x000000;
dword active_color_2 = 0xFFFfff; dword color2 = 0xFFFfff;
dword tool_color;
enum { enum {
BTN_NEW = 40, BTN_NEW = 40,
@ -163,31 +164,11 @@ void setCurrentTool(int index) {
//===================================================// //===================================================//
void FillTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { void FillTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
bool fill1=false; if (canvas.hovered()) && (currentTool==TOOL_FILL) && (mouse.up)
bool fill2=false;
if (canvas.hovered())
{ {
if (currentTool==TOOL_FILL)
{
if (mouse.key&MOUSE_LEFT)&&(mouse.up) fill1=true;
if (mouse.key&MOUSE_RIGHT)&&(mouse.up) fill2=true;
}
else
{
if (lkm) fill1=true;
if (pkm) fill2=true;
}
if (fill1)
EventFill(mouseY-canvas.y/zoom.value, EventFill(mouseY-canvas.y/zoom.value,
mouseX-canvas.x/zoom.value, active_color_1); mouseX-canvas.x/zoom.value, tool_color);
if (fill2)
EventFill(mouseY-canvas.y/zoom.value,
mouseX-canvas.x/zoom.value, active_color_2);
if ((fill1) || (fill2))
actionsHistory.saveCurrentState(); actionsHistory.saveCurrentState();
DrawCanvas(); DrawCanvas();
} }
} }
@ -197,12 +178,13 @@ void PipetteTool_activate() {
} }
void PipetteTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { void PipetteTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
active_color_1 = GetPixelUnderMouse(); tool_color = GetPixelUnderMouse();
DrawActiveColor(NULL); DrawBar(Form.cwidth-30, 5, 20, 20, tool_color);
if (mouse.down) && (mouse.key&MOUSE_LEFT) { if (mouse.down) {
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
EventSetActiveColor(1, active_color_1); if (mouse.key&MOUSE_LEFT) EventSetActiveColor(1, tool_color);
if (mouse.key&MOUSE_RIGHT) EventSetActiveColor(2, tool_color);
setCurrentTool(TOOL_PENCIL); setCurrentTool(TOOL_PENCIL);
} }
@ -213,21 +195,16 @@ bool PencilTool_Drawing = false;
void PencilTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { void PencilTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
if (canvas.hovered()) if (canvas.hovered())
{ {
if ((PencilTool_Drawing == true) && (!lkm) && (!pkm)) { if ((PencilTool_Drawing == true) && (!mouse.key)) {
actionsHistory.saveCurrentState(); actionsHistory.saveCurrentState();
PencilTool_Drawing = false; PencilTool_Drawing = false;
} }
if (lkm) if (mouse.key) {
image.set_pixel(mouseY-canvas.y/zoom.value, image.set_pixel(mouseY-canvas.y/zoom.value,
mouseX-canvas.x/zoom.value, active_color_1); mouseX-canvas.x/zoom.value, tool_color);
if (pkm)
image.set_pixel(mouseY-canvas.y/zoom.value,
mouseX-canvas.x/zoom.value, active_color_2);
if ((lkm) || (pkm))
PencilTool_Drawing = true; PencilTool_Drawing = true;
}
DrawCanvas(); DrawCanvas();
} }
} }
@ -275,7 +252,7 @@ void SimpleFigureTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
if (mouseX<canvas.x) mouseX = canvas.x; if (mouseX<canvas.x) mouseX = canvas.x;
if (mouseY<canvas.y) mouseY = canvas.y; if (mouseY<canvas.y) mouseY = canvas.y;
if (mouse.lkm) { if (mouse.key) {
if ((figTool_States[currentFigToolState].startX < 0) || (figTool_States[currentFigToolState].startY < 0)) { if ((figTool_States[currentFigToolState].startX < 0) || (figTool_States[currentFigToolState].startY < 0)) {
figTool_States[currentFigToolState].startX = mouseX; figTool_States[currentFigToolState].startX = mouseX;
figTool_States[currentFigToolState].startY = mouseY; figTool_States[currentFigToolState].startY = mouseY;
@ -298,14 +275,14 @@ void SimpleFigureTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
figTool_States[currentFigToolState].startY - canvas.y/zoom.value, figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX - canvas.x/zoom.value, mouseX - canvas.x/zoom.value,
mouseY - canvas.y/zoom.value, mouseY - canvas.y/zoom.value,
active_color_1, tool_color,
1); 1);
} }
else if (currentTool == TOOL_RECT) { else if (currentTool == TOOL_RECT) {
DrawRectangleInCanvas(figTool_States[currentFigToolState].startX - canvas.x/zoom.value, DrawRectangleInCanvas(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
figTool_States[currentFigToolState].startY - canvas.y/zoom.value, figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX - canvas.x/zoom.value, mouseX - canvas.x/zoom.value,
mouseY - canvas.y/zoom.value, active_color_1, 1); mouseY - canvas.y/zoom.value, tool_color, 1);
} }
DrawCanvas(); DrawCanvas();
@ -323,13 +300,13 @@ void SimpleFigureTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
} }
void SimpleFigureTool_onCanvasDraw() { void SimpleFigureTool_onCanvasDraw() {
if ((figTool_States[currentFigToolState].startX >= 0) && (figTool_States[currentFigToolState].startY >= 0) && (mouse.lkm)) { if ((figTool_States[currentFigToolState].startX >= 0) && (figTool_States[currentFigToolState].startY >= 0) && (mouse.key)) {
if (currentTool == TOOL_LINE) { if (currentTool == TOOL_LINE) {
DrawLine(figTool_States[currentFigToolState].startX - canvas.x/zoom.value, DrawLine(figTool_States[currentFigToolState].startX - canvas.x/zoom.value,
figTool_States[currentFigToolState].startY - canvas.y/zoom.value, figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX_last - canvas.x/zoom.value, mouseX_last - canvas.x/zoom.value,
mouseY_last - canvas.y/zoom.value, mouseY_last - canvas.y/zoom.value,
active_color_1, tool_color,
2); 2);
} }
else if (currentTool == TOOL_RECT) { else if (currentTool == TOOL_RECT) {
@ -337,7 +314,7 @@ void SimpleFigureTool_onCanvasDraw() {
figTool_States[currentFigToolState].startY - canvas.y/zoom.value, figTool_States[currentFigToolState].startY - canvas.y/zoom.value,
mouseX_last - canvas.x/zoom.value, mouseX_last - canvas.x/zoom.value,
mouseY_last - canvas.y/zoom.value, mouseY_last - canvas.y/zoom.value,
active_color_1, tool_color,
2); 2);
} }
@ -406,6 +383,10 @@ void main()
case evMouse: case evMouse:
mouse.get(); mouse.get();
if (mouse.lkm) tool_color = color1;
if (mouse.pkm) tool_color = color2;
if (mouse.mkm) break;
if (currentTool != TOOL_NONE) if (currentTool != TOOL_NONE)
tools[currentTool].onMouseEvent(mouse.x, mouse.y, mouse.lkm, mouse.pkm); tools[currentTool].onMouseEvent(mouse.x, mouse.y, mouse.lkm, mouse.pkm);
@ -639,13 +620,13 @@ void DrawActiveColor(dword iny)
{ {
static dword outy; static dword outy;
if (iny != NULL) outy = iny; if (iny != NULL) outy = iny;
DrawBar(right_bar.x, outy, 20, 20, active_color_1); DrawBar(right_bar.x, outy, 20, 20, color1);
sprintf(#param, "%A", active_color_1); sprintf(#param, "%A", color1);
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); DrawBar(right_bar.x+110, outy, 20, 20, color2);
sprintf(#param, "%A", active_color_2); sprintf(#param, "%A", color2);
EDI = system.color.work; EDI = system.color.work;
WriteText(right_bar.x+110 + 30, outy + 3, 0xD0, system.color.work_text, #param+4); WriteText(right_bar.x+110 + 30, outy + 3, 0xD0, system.color.work_text, #param+4);
DrawCurrentColorGradientByLightness(); DrawCurrentColorGradientByLightness();
@ -657,10 +638,10 @@ void DrawCurrentColorGradientByLightness()
int w = right_bar.w-10/2; int w = right_bar.w-10/2;
for (i=0; i<w; i++) for (i=0; i<w; i++)
DrawBar(b_color_gradient.x+i, b_color_gradient.y, DrawBar(b_color_gradient.x+i, b_color_gradient.y,
1, b_color_gradient.h, MixColors(active_color_1,0xFFFfff,255*i/w)); 1, b_color_gradient.h, MixColors(color1,0xFFFfff,255*i/w));
for (i=0 ; i<=w; i++) for (i=0 ; i<=w; i++)
DrawBar(b_color_gradient.x+w+w-i, b_color_gradient.y, DrawBar(b_color_gradient.x+w+w-i, b_color_gradient.y,
1, b_color_gradient.h, MixColors(active_color_1,0x000000,255*i/w)); 1, b_color_gradient.h, MixColors(color1,0x000000,255*i/w));
} }
void DrawColorPallets() void DrawColorPallets()
@ -765,8 +746,8 @@ void EventSetActiveColor(int _number, _color)
} }
last_used_colors[0] = _color; last_used_colors[0] = _color;
if (_number == 1) active_color_1 = _color; if (_number == 1) color1 = _color;
if (_number == 2) active_color_2 = _color; if (_number == 2) color2 = _color;
DrawActiveColor(NULL); DrawActiveColor(NULL);
DrawColorPallets(); DrawColorPallets();