IconEdit 0.54: moving and flip actions can be applied to selection, code simplify

git-svn-id: svn://kolibrios.org@7268 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2018-05-03 14:46:27 +00:00
parent cec5c8a3a4
commit 1c7d02c7c7
2 changed files with 14 additions and 29 deletions

View File

@ -32,7 +32,7 @@ pipet aside color view
// // // //
//===================================================// //===================================================//
#define T_TITLE "Icon Editor 0.53.2 Alpha" #define T_TITLE "Icon Editor 0.54 Alpha"
#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

View File

@ -9,8 +9,7 @@ _image selection;
enum { enum {
STATE_INACTIVE=0, STATE_INACTIVE=0,
STATE_CHOSING=1, STATE_CHOSING=1,
STATE_SELECTED=2, STATE_SELECTED=2
STATE_MOVING=3
}; };
int selection_state = STATE_INACTIVE; int selection_state = STATE_INACTIVE;
@ -29,24 +28,17 @@ int selection_pivot_y = -1;
//===================================================// //===================================================//
void SelectTool_normalizeSelection() { void SelectTool_normalizeSelection() {
int t;
// Restructuring of the selection coordinates // Restructuring of the selection coordinates
if (selection_end_x < selection_start_x) { if (selection_end_x < selection_start_x) {
t = selection_start_x; selection_start_x >< selection_end_x;
selection_start_x = selection_end_x;
selection_end_x = t;
} }
if (selection_end_y < selection_start_y) { if (selection_end_y < selection_start_y) {
t = selection_end_y; selection_end_y >< selection_start_y;
selection_end_y = selection_start_y;
selection_start_y = t;
} }
} }
void reset_selection_moving() { void reset_selection_moving() {
if (STATE_MOVING == selection_state) { if (STATE_SELECTED == selection_state) {
SelectTool_drawBuffer(selection_start_x, selection_start_y, 1); SelectTool_drawBuffer(selection_start_x, selection_start_y, 1);
selection_pivot_x = -1; selection_pivot_x = -1;
@ -60,7 +52,7 @@ void reset_selection_moving() {
} }
bool is_selection_moving() { bool is_selection_moving() {
if (STATE_MOVING == selection_state) return true; if (STATE_SELECTED == selection_state) return true;
return false; return false;
} }
@ -106,15 +98,12 @@ void SelectTool_copyToBuffer() {
} }
void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
int dx, dy, m_x, m_y, r, c; int dx, dy, m_x, m_y;
dword pixel;
m_x = TO_CANVAS_X(mouseX); m_x = TO_CANVAS_X(mouseX);
m_y = TO_CANVAS_Y(mouseY); m_y = TO_CANVAS_Y(mouseY);
if (mouse.down) if (mouse.down) && (canvas.hovered())
&& (canvas.hovered())
&& ((STATE_INACTIVE == selection_state) || (STATE_CHOSING == selection_state) || (STATE_SELECTED == selection_state) || (STATE_MOVING == selection_state))
{ {
if (selection_start_x != -1) && (SelectTool_pointInSelection(m_x, m_y)) { if (selection_start_x != -1) && (SelectTool_pointInSelection(m_x, m_y)) {
if (selection_pivot_x == -1) { if (selection_pivot_x == -1) {
@ -123,14 +112,11 @@ void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
GetKeys(); GetKeys();
if (STATE_MOVING != selection_state) && ( !(key_modifier&KEY_LSHIFT) ) { if ( !(key_modifier&KEY_LSHIFT) ) {
for (r = selection_start_y; r <= selection_end_y; r++) DrawBarIcon(selection_start_x, selection_start_y, selection_end_x, selection_end_y, color2, TOIMAGE);
for (c = selection_start_x; c <= selection_end_x; c++) {
image.set_pixel(r, c, color2);
}
} }
selection_state = STATE_MOVING; selection_state = STATE_SELECTED;
} }
} }
else { else {
@ -240,8 +226,7 @@ void SelectTool_drawBuffer(int insert_x, int insert_y, int target) {
if (TOIMAGE == target) if (TOIMAGE == target)
image.set_pixel(r, c, color); image.set_pixel(r, c, color);
else else
DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y, DrawCanvasPixel(r, c, color);
zoom.value, zoom.value, color);
} }
} }
} }
@ -254,7 +239,7 @@ void SelectTool_onKeyEvent(dword keycode) {
if (STATE_SELECTED == selection_state) { if (STATE_SELECTED == selection_state) {
reset_selection(); reset_selection();
selection_state = STATE_MOVING; selection_state = STATE_SELECTED;
selection_start_x = 0; selection_start_x = 0;
selection_end_x = selection.columns - 1; selection_end_x = selection.columns - 1;
@ -292,7 +277,7 @@ void DrawSelection() {
for (c = p1x; c <= p2x; c++) { for (c = p1x; c <= p2x; c++) {
image.pixel_state.set_drawable_state(r, c, false); image.pixel_state.set_drawable_state(r, c, false);
if (STATE_MOVING == selection_state) && (SelectTool_pointInSelection(c, r)) { if (STATE_SELECTED == selection_state) && (SelectTool_pointInSelection(c, r)) {
old_color = selection.get_pixel(r - selection_start_y, c - selection_start_x); old_color = selection.get_pixel(r - selection_start_y, c - selection_start_x);
} }
else { else {