forked from KolibriOS/kolibrios
IconEdit 0.54.1: add current color marker in gradient pallet, reduce window blink when activate and deactivate it, fix ScreenCopy tool on screen corners, selection fixes and general code update
git-svn-id: svn://kolibrios.org@7271 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
02da1fd4f3
commit
5d72ec7c19
@ -1,6 +1,6 @@
|
||||
// Actions history
|
||||
|
||||
#define MAX_ACTIONS_COUNT 10
|
||||
#define MAX_ACTIONS_COUNT 15
|
||||
|
||||
struct _ActionsHistory {
|
||||
dword stack[MAX_ACTIONS_COUNT];
|
||||
|
@ -32,10 +32,10 @@ pipet aside color view
|
||||
// //
|
||||
//===================================================//
|
||||
|
||||
#define T_TITLE "Icon Editor 0.54 Alpha"
|
||||
#define T_TITLE "Icon Editor 0.54.1 Alpha"
|
||||
|
||||
#define TOOLBAR_H 24+8
|
||||
#define PANEL_LEFT_W 16+5+5+3+3
|
||||
#define TOPBAR_H 24+8
|
||||
#define LEFTBAR_W 16+5+5+3+3
|
||||
#define PALLETE_SIZE 116
|
||||
|
||||
#define PAL_ITEMS_X_COUNT 13
|
||||
@ -46,12 +46,12 @@ pipet aside color view
|
||||
#define TO_CANVAS_Y(yval) yval - canvas.y/zoom.value
|
||||
|
||||
block canvas = { NULL, NULL, NULL, NULL };
|
||||
block wrapper = { PANEL_LEFT_W, TOOLBAR_H, NULL, NULL };
|
||||
block right_bar = { NULL, 10+TOOLBAR_H, RIGHT_BAR_W+10, NULL };
|
||||
block wrapper = { LEFTBAR_W, TOPBAR_H, NULL, NULL };
|
||||
block right_bar = { NULL, 10+TOPBAR_H, RIGHT_BAR_W+10, NULL };
|
||||
|
||||
block b_color_gradient = {NULL, 40+TOOLBAR_H, RIGHT_BAR_W, 30};
|
||||
block b_last_colors = {NULL, 80+TOOLBAR_H, RIGHT_BAR_W, COLSIZE*2};
|
||||
block b_default_palette = {NULL, COLSIZE*2+10+80+TOOLBAR_H, RIGHT_BAR_W, COLSIZE*9};
|
||||
block b_color_gradient = {NULL, 40+TOPBAR_H, RIGHT_BAR_W, 30};
|
||||
block b_last_colors = {NULL, 80+TOPBAR_H, RIGHT_BAR_W, COLSIZE*2};
|
||||
block b_default_palette = {NULL, COLSIZE*2+10+80+TOPBAR_H, RIGHT_BAR_W, COLSIZE*9};
|
||||
|
||||
dword color1 = 0x000000;
|
||||
dword color2 = 0xBFCAD2;
|
||||
@ -305,7 +305,6 @@ void main()
|
||||
if (currentTool != TOOL_NONE) && (tools[currentTool].onKeyEvent != 0)
|
||||
tools[currentTool].onKeyEvent(key_scancode);
|
||||
|
||||
if (key_scancode == SCAN_CODE_ESC) setCurrentTool(TOOL_PENCIL);
|
||||
if (key_scancode == SCAN_CODE_KEY_P) setCurrentTool(TOOL_PENCIL);
|
||||
if (key_scancode == SCAN_CODE_KEY_I) setCurrentTool(TOOL_PIPETTE);
|
||||
if (key_scancode == SCAN_CODE_KEY_F) setCurrentTool(TOOL_FILL);
|
||||
@ -333,6 +332,10 @@ void main()
|
||||
void DrawTopPanelButton(dword _id, _x, _icon_n)
|
||||
{
|
||||
DrawWideRectangle(_x, 4, 22, 22, 3, semi_white);
|
||||
PutPixel(_x,4,system.color.work);
|
||||
PutPixel(_x,4+21,system.color.work);
|
||||
PutPixel(_x+21,4,system.color.work);
|
||||
PutPixel(_x+21,4+21,system.color.work);
|
||||
DefineHiddenButton(_x, 4, 21, 21, _id);
|
||||
img_draw stdcall(top_icons.image, _x+3, 7, 16, 16, 0, _icon_n*16);
|
||||
}
|
||||
@ -359,7 +362,7 @@ void draw_window()
|
||||
#define BLOCK_SPACE 10
|
||||
incn tx;
|
||||
system.color.get();
|
||||
DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x33, system.color.work, T_TITLE, 0);
|
||||
DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x73, NULL, T_TITLE, 0);
|
||||
GetProcessInfo(#Form, SelfInfo);
|
||||
if (Form.status_window>2) return;
|
||||
if (Form.width < 560) { MoveSize(OLD,OLD,560,OLD); return; }
|
||||
@ -367,7 +370,8 @@ void draw_window()
|
||||
|
||||
right_bar.x = Form.cwidth - right_bar.w;
|
||||
b_color_gradient.x = b_last_colors.x = b_default_palette.x = right_bar.x;
|
||||
DrawBar(0, TOOLBAR_H-1, Form.cwidth, 1, system.color.work_graph);
|
||||
DrawBar(0, 0, Form.cwidth, TOPBAR_H-1, system.color.work);
|
||||
DrawBar(0, TOPBAR_H-1, Form.cwidth, 1, system.color.work_graph);
|
||||
|
||||
tx.n = 5-GAP;
|
||||
DrawTopPanelButton(BTN_NEW, tx.inc(GAP), 2); //not implemented
|
||||
@ -385,14 +389,22 @@ void draw_window()
|
||||
// DrawTopPanelButton(BTN_ROTATE_LEFT, tx.inc(GAP), 36); //not implemented
|
||||
// DrawTopPanelButton(BTN_ROTATE_RIGHT, tx.inc(GAP), 37); //not implemented
|
||||
|
||||
DrawLeftPanel();
|
||||
|
||||
DrawEditArea();
|
||||
|
||||
//BG under LeftBar
|
||||
DrawBar(0, TOPBAR_H, LEFTBAR_W-1, Form.cheight - TOPBAR_H, system.color.work);
|
||||
//BG under RightBar
|
||||
DrawBar(wrapper.x+wrapper.w, TOPBAR_H, Form.cwidth-wrapper.x-wrapper.w,
|
||||
Form.cheight - TOPBAR_H, system.color.work);
|
||||
//BG under StatusBar
|
||||
DrawBar(LEFTBAR_W-1, wrapper.y + wrapper.h, wrapper.w+1,
|
||||
Form.cheight - wrapper.y - wrapper.h, system.color.work);
|
||||
|
||||
DrawLeftPanel();
|
||||
DrawActiveColor(right_bar.y);
|
||||
DrawColorPallets();
|
||||
|
||||
DrawStatusBar();
|
||||
DrawPreview();
|
||||
}
|
||||
|
||||
void DrawLeftPanel()
|
||||
@ -418,7 +430,7 @@ void DrawEditArea()
|
||||
int left_side;
|
||||
|
||||
wrapper.w = Form.cwidth - right_bar.w - 10 - wrapper.x;
|
||||
wrapper.h = Form.cheight - TOOLBAR_H - 35;
|
||||
wrapper.h = Form.cheight - TOPBAR_H - 35;
|
||||
|
||||
//canvas{
|
||||
canvas.w = image.columns * zoom.value;
|
||||
@ -481,6 +493,10 @@ void DrawCurrentColorGradientByLightness()
|
||||
for (i=0; i<w; i++)
|
||||
DrawBar(b_color_gradient.x+i, b_color_gradient.y,
|
||||
1, b_color_gradient.h, MixColors(color1,0xFFFfff,255*i/w));
|
||||
|
||||
//current color marker
|
||||
DrawBar(b_color_gradient.x+i-1, b_color_gradient.y-2, 3,2, 0x000000);
|
||||
|
||||
for (i=0 ; i<=w; i++)
|
||||
DrawBar(b_color_gradient.x+w+w-i, b_color_gradient.y,
|
||||
1, b_color_gradient.h, MixColors(color1,0x000000,255*i/w));
|
||||
@ -641,14 +657,14 @@ void EventTestIcon()
|
||||
void EventMove(dword _action)
|
||||
{
|
||||
if (selection_state) {
|
||||
//debugval("selection_state", selection_state);
|
||||
selection.move(_action);
|
||||
DrawSelection();
|
||||
SelectTool_onCanvasDraw();
|
||||
}
|
||||
else {
|
||||
image.move(_action);
|
||||
DrawCanvas();
|
||||
}
|
||||
actionsHistory.saveCurrentState();
|
||||
}
|
||||
|
||||
stop:
|
||||
|
@ -46,6 +46,7 @@ void initTools()
|
||||
tools[TOOL_PIPETTE].cursor = #CursorPipette;
|
||||
tools[TOOL_PIPETTE].activate = #PipetteTool_activate;
|
||||
tools[TOOL_PIPETTE].onMouseEvent = #PipetteTool_onMouseEvent;
|
||||
tools[TOOL_PIPETTE].onKeyEvent = #PipetteTool_onKeyEvent;
|
||||
|
||||
tools[TOOL_FILL].id = TOOL_FILL;
|
||||
tools[TOOL_FILL].cursor = #CursorFill;
|
||||
|
@ -3,6 +3,10 @@ void PipetteTool_activate() {
|
||||
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE);
|
||||
}
|
||||
|
||||
void PipetteTool_onKeyEvent() {
|
||||
if (key_scancode == SCAN_CODE_ESC) setCurrentTool(previousTool);
|
||||
}
|
||||
|
||||
void PipetteTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
||||
if (!canvas.hovered()) return; //TODO: option "Restrict pipette to canvas area"
|
||||
tool_color = GetPixelUnderMouse();
|
||||
|
@ -7,10 +7,19 @@ void ScreenCopy_activate() {
|
||||
|
||||
void ScreenCopy_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
||||
dword i;
|
||||
CopyScreen(screen_copy,
|
||||
mouse.x + Form.left + 5 - calc(image.columns/2),
|
||||
mouse.y + Form.top + skin_height - calc(image.rows/2),
|
||||
image.columns, image.rows);
|
||||
int x, y;
|
||||
|
||||
x = mouse.x + Form.left + 5 - calc(image.columns/2);
|
||||
y = mouse.y + Form.top + skin_height - calc(image.rows/2);
|
||||
|
||||
CopyScreen(
|
||||
screen_copy,
|
||||
math.in(x, 0, screen.width - image.columns),
|
||||
math.in(y, 0, screen.height - image.rows),
|
||||
image.columns,
|
||||
image.rows
|
||||
);
|
||||
|
||||
for (i = 0; i < image.columns*image.rows; i++;)
|
||||
{
|
||||
image.mas[i] = ESDWORD[i*3+screen_copy] & 0xFFFFFF;
|
||||
|
@ -37,19 +37,31 @@ void SelectTool_normalizeSelection() {
|
||||
}
|
||||
}
|
||||
|
||||
void reset_selection_moving() {
|
||||
if (STATE_SELECTED == selection_state) {
|
||||
SelectTool_drawBuffer(selection_start_x, selection_start_y, 1);
|
||||
void SelectTool_drawBufferToImage(int insert_x, int insert_y) {
|
||||
dword r, c;
|
||||
dword insert_to_x, insert_to_y;
|
||||
|
||||
insert_to_x = math.min(insert_x + selection.columns - 1, image.columns-1);
|
||||
insert_to_y = math.min(insert_y + selection.rows - 1, image.rows-1);
|
||||
|
||||
for (r = insert_y; r <= insert_to_y; r++) {
|
||||
for (c = insert_x; c <= insert_to_x; c++) {
|
||||
image.set_pixel(r, c, selection.get_pixel(r - insert_y, c - insert_x) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ApplySelectionToImage() {
|
||||
if (STATE_SELECTED != selection_state) return;
|
||||
|
||||
SelectTool_drawBufferToImage(selection_start_x, selection_start_y);
|
||||
|
||||
selection_pivot_x = -1;
|
||||
selection_pivot_y = -1;
|
||||
|
||||
selection_state = STATE_SELECTED;
|
||||
|
||||
actionsHistory.saveCurrentState();
|
||||
DrawCanvas();
|
||||
}
|
||||
}
|
||||
|
||||
bool is_selection_moving() {
|
||||
if (STATE_SELECTED == selection_state) return true;
|
||||
@ -57,7 +69,7 @@ bool is_selection_moving() {
|
||||
}
|
||||
|
||||
void reset_selection() {
|
||||
reset_selection_moving();
|
||||
ApplySelectionToImage();
|
||||
|
||||
selection_start_x = -1;
|
||||
selection_start_y = -1;
|
||||
@ -71,7 +83,7 @@ void SelectTool_activate() {
|
||||
}
|
||||
|
||||
void SelectTool_deactivate() {
|
||||
reset_selection_moving();
|
||||
ApplySelectionToImage();
|
||||
selection_state = STATE_INACTIVE;
|
||||
}
|
||||
|
||||
@ -111,9 +123,9 @@ void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
||||
selection_pivot_y = m_y;
|
||||
|
||||
GetKeys();
|
||||
|
||||
if ( !(key_modifier&KEY_LSHIFT) ) {
|
||||
DrawBarIcon(selection_start_x, selection_start_y, selection_end_x, selection_end_y, color2, TOIMAGE);
|
||||
if ( (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) ) {
|
||||
DrawBarIcon(selection_start_x, selection_start_y, selection_end_x,
|
||||
selection_end_y, color2, TOIMAGE);
|
||||
}
|
||||
|
||||
selection_state = STATE_SELECTED;
|
||||
@ -141,7 +153,6 @@ void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
||||
if (selection_end_y + dy >= image.rows)
|
||||
dy = image.rows-1 - selection_end_y;
|
||||
|
||||
|
||||
selection_start_x += dx;
|
||||
selection_end_x += dx;
|
||||
|
||||
@ -156,11 +167,8 @@ void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
||||
|
||||
if (STATE_CHOSING == selection_state)
|
||||
{
|
||||
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;
|
||||
mouseX = math.in(mouseX, canvas.x, canvas.x+canvas.w-zoom.value);
|
||||
mouseY = math.in(mouseY, canvas.y, canvas.y+canvas.h-zoom.value);
|
||||
|
||||
if (mouse.key) {
|
||||
selection_end_x = TO_CANVAS_X(mouseX);
|
||||
@ -172,12 +180,6 @@ void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
||||
}
|
||||
else {
|
||||
DrawCanvas();
|
||||
|
||||
/**if ((calc(TO_CANVAS_X(mouseX)) != selection_end_x)
|
||||
|| (calc(TO_CANVAS_Y(mouseY)) != selection_end_y))
|
||||
{
|
||||
DrawCanvas();
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
@ -196,54 +198,29 @@ void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
||||
}
|
||||
}
|
||||
|
||||
void SelectTool_onCanvasDraw() {
|
||||
if ((selection_start_x >= 0) && (selection_start_y >= 0) && (selection_end_x >= 0) && (selection_end_y >= 0)) {
|
||||
DrawSelection();
|
||||
}
|
||||
}
|
||||
|
||||
void SelectTool_drawBuffer(int insert_x, int insert_y, int target) {
|
||||
dword color;
|
||||
dword r, c;
|
||||
dword insert_to_x, insert_to_y;
|
||||
|
||||
if (STATE_INACTIVE != selection_state) {
|
||||
insert_to_x = insert_x + selection.columns - 1;
|
||||
|
||||
if (insert_to_x >= image.columns)
|
||||
insert_to_x = image.columns-1;
|
||||
|
||||
insert_to_y = insert_y + selection.rows - 1;
|
||||
|
||||
if (insert_to_y >= image.rows)
|
||||
insert_to_y = image.rows-1;
|
||||
|
||||
for (r = insert_y; r <= insert_to_y; r++) {
|
||||
for (c = insert_x; c <= insert_to_x; c++) {
|
||||
|
||||
color = selection.get_pixel(r - insert_y, c - insert_x);
|
||||
|
||||
if (TOIMAGE == target)
|
||||
image.set_pixel(r, c, color);
|
||||
else
|
||||
DrawCanvasPixel(r, c, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SelectTool_onKeyEvent(dword keycode) {
|
||||
dword r, c;
|
||||
|
||||
if (keycode == SCAN_CODE_KEY_V) {
|
||||
if (STATE_SELECTED == selection_state) {
|
||||
if (SCAN_CODE_DEL == keycode) {
|
||||
selection_start_x = -1;
|
||||
selection_start_y = -1;
|
||||
selection_end_x = -1;
|
||||
selection_end_y = -1;
|
||||
selection_state = STATE_INACTIVE;
|
||||
DrawCanvas();
|
||||
}
|
||||
|
||||
if (SCAN_CODE_ESC == keycode) {
|
||||
reset_selection();
|
||||
DrawCanvas();
|
||||
}
|
||||
|
||||
if (SCAN_CODE_KEY_V == keycode) {
|
||||
if (STATE_SELECTED == selection_state) {
|
||||
|
||||
selection_state = STATE_SELECTED;
|
||||
selection_start_x = 0;
|
||||
selection_end_x = selection.columns - 1;
|
||||
|
||||
selection_start_y = 0;
|
||||
selection_end_x = selection.columns - 1;
|
||||
selection_end_y = selection.rows - 1;
|
||||
|
||||
DrawCanvas();
|
||||
@ -251,29 +228,20 @@ void SelectTool_onKeyEvent(dword keycode) {
|
||||
}
|
||||
}
|
||||
|
||||
void DrawSelection() {
|
||||
void SelectTool_onCanvasDraw()
|
||||
{
|
||||
#define SELECTION_COLOR 0xAAE5EF
|
||||
int p1x, p1y, p2x, p2y, r, c, old_color, new_color;
|
||||
|
||||
if (selection_start_x <= selection_end_x) {
|
||||
p1x = selection_start_x;
|
||||
p2x = selection_end_x;
|
||||
}
|
||||
else {
|
||||
p1x = selection_end_x;
|
||||
p2x = selection_start_x;
|
||||
}
|
||||
if ((selection_start_x >= 0) && (selection_start_y >= 0) && (selection_end_x >= 0) && (selection_end_y >= 0)) {
|
||||
|
||||
if (selection_start_y <= selection_end_y) {
|
||||
p2y = selection_start_y;
|
||||
p1y = selection_end_y;
|
||||
}
|
||||
else {
|
||||
p2y = selection_end_y;
|
||||
p1y = selection_start_y;
|
||||
}
|
||||
p1x = math.min(selection_start_x, selection_end_x);
|
||||
p2x = math.max(selection_start_x, selection_end_x);
|
||||
|
||||
for (r = p1y; r >= p2y; r--) {
|
||||
p1y = math.min(selection_start_y, selection_end_y);
|
||||
p2y = math.max(selection_start_y, selection_end_y);
|
||||
|
||||
for (r = p1y; r <= p2y; r++) {
|
||||
for (c = p1x; c <= p2x; c++) {
|
||||
image.pixel_state.set_drawable_state(r, c, false);
|
||||
|
||||
@ -290,3 +258,6 @@ void DrawSelection() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,10 +53,10 @@ void SimpleFigureTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
|
||||
if ((figTool.startX >= 0)
|
||||
&& (figTool.startY >= 0)) {
|
||||
|
||||
x1 = figTool.startX - canvas.x/zoom.value;
|
||||
y1 = figTool.startY - canvas.y/zoom.value;
|
||||
x2 = mouseX - canvas.x/zoom.value;
|
||||
y2 = mouseY - canvas.y/zoom.value;
|
||||
x1 = TO_CANVAS_X(figTool.startX);
|
||||
y1 = TO_CANVAS_Y(figTool.startY);
|
||||
x2 = TO_CANVAS_X(mouseX);
|
||||
y2 = TO_CANVAS_Y(mouseY);
|
||||
|
||||
// Draw line from start position to current position
|
||||
if (currentTool == TOOL_LINE) {
|
||||
@ -88,10 +88,10 @@ void SimpleFigureTool_onCanvasDraw() {
|
||||
if ((figTool.startX >= 0)
|
||||
&& (figTool.startY >= 0) && (mouse.key)) {
|
||||
|
||||
x1 = figTool.startX - canvas.x/zoom.value;
|
||||
y1 = figTool.startY - canvas.y/zoom.value;
|
||||
x2 = mouseX_last - canvas.x/zoom.value;
|
||||
y2 = mouseY_last - canvas.y/zoom.value;
|
||||
x1 = TO_CANVAS_X(figTool.startX);
|
||||
y1 = TO_CANVAS_Y(figTool.startY);
|
||||
x2 = TO_CANVAS_X(mouseX_last);
|
||||
y2 = TO_CANVAS_Y(mouseY_last);
|
||||
|
||||
if (currentTool == TOOL_LINE)
|
||||
DrawLineIcon(x1, y1, x2, y2, tool_color, TOCANVAS);
|
||||
|
Loading…
Reference in New Issue
Block a user