Skip to content

Commit

Permalink
Move common selection actions into 'edit' panel
Browse files Browse the repository at this point in the history
I think it is a bit better like that, separating the selection tool from
the actions we perform on the selection.
  • Loading branch information
guillaumechereau committed Jul 7, 2024
1 parent da706e5 commit 7080566
Show file tree
Hide file tree
Showing 9 changed files with 1,520 additions and 1,485 deletions.
Binary file modified data/images/icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,909 changes: 1,469 additions & 1,440 deletions src/assets/images.inl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/goxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ enum {
X(ICON_SHAPE, 2, 4, 0),
X(ICON_CLOSE, 3, 4, 0),
X(ICON_THREE_DOTS, 4, 4, 0),
X(ICON_HAMMER, 5, 4, THEME_GROUP_ICON_EDIT),

X(ICON_TOOLS, 0, 5, THEME_GROUP_ICON_EDIT),
X(ICON_PALETTE, 1, 5, THEME_GROUP_ICON_EDIT),
Expand Down
3 changes: 3 additions & 0 deletions src/gui/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
// Note: duplicated from gui.cpp! To remove.
static const float ITEM_HEIGHT = 18;

void gui_edit_panel(void);
void gui_menu(void);
void gui_tools_panel(void);
void gui_top_bar(void);
Expand All @@ -58,6 +59,7 @@ enum {
PANEL_NULL,
PANEL_TOOLS,
PANEL_PALETTE,
PANEL_EDIT,
PANEL_LAYERS,
PANEL_SNAP,
PANEL_SYMMETRY,
Expand All @@ -79,6 +81,7 @@ static struct {
} PANELS[] = {
[PANEL_TOOLS] = {STR_TOOLS, ICON_TOOLS, gui_tools_panel},
[PANEL_PALETTE] = {STR_PALETTE, ICON_PALETTE, gui_palette_panel},
[PANEL_EDIT] = {STR_EDIT, ICON_HAMMER, gui_edit_panel},
[PANEL_LAYERS] = {STR_LAYERS, ICON_LAYERS, gui_layers_panel},
[PANEL_SNAP] = {STR_SNAP, ICON_SNAP, gui_snap_panel},
[PANEL_SYMMETRY] = {STR_SYMMETRY, ICON_SYMMETRY, gui_symmetry_panel},
Expand Down
38 changes: 38 additions & 0 deletions src/gui/edit_panel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Goxel 3D voxels editor
*
* copyright (c) 2024-present Guillaume Chereau <[email protected]>
*
* Goxel is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* Goxel is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* You should have received a copy of the GNU General Public License along with
* goxel. If not, see <http://www.gnu.org/licenses/>.
*/

#include "goxel.h"

void gui_edit_panel(void)
{
image_t *img = goxel.image;

gui_group_begin(NULL);
gui_enabled_begin(!box_is_null(img->selection_box));
gui_action_button(ACTION_fill_selection_box, _(FILL), 1.0);
gui_group_end();
gui_enabled_end();

gui_group_begin(NULL);
gui_enabled_begin(!volume_is_empty(goxel.image->selection_mask));
gui_action_button(ACTION_layer_clear, _(CLEAR), 1.0);
gui_action_button(ACTION_paint_selection, _(PAINT), 1.0);
gui_action_button(ACTION_cut_as_new_layer, "Cut as new layer", 1.0);
gui_enabled_end();
gui_group_end();
}
31 changes: 2 additions & 29 deletions src/tools/fuzzy_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static int on_click(gesture3d_t *gest)
if (img->selection_mask == NULL) img->selection_mask = volume_new();
volume_merge(img->selection_mask, sel, mode, NULL);
volume_delete(sel);
image_history_push(goxel.image);

return 0;
}

Expand All @@ -86,17 +88,6 @@ static int iter(tool_t *tool_, const painter_t *painter,
return 0;
}

static layer_t *cut_as_new_layer(image_t *img, layer_t *layer,
const volume_t *mask)
{
layer_t *new_layer;

new_layer = image_duplicate_layer(img, layer);
volume_merge(new_layer->volume, mask, MODE_INTERSECT, NULL);
volume_merge(layer->volume, mask, MODE_SUB, NULL);
return new_layer;
}

static int gui(tool_t *tool_)
{
tool_fuzzy_select_t *tool = (void*)tool_;
Expand All @@ -115,24 +106,6 @@ static int gui(tool_t *tool_)
if (volume_is_empty(img->selection_mask))
return 0;

volume_t *volume = img->active_layer->volume;

gui_group_begin(NULL);
// XXX: should use actions here?
if (gui_button(_(CLEAR), 1, 0)) {
volume_merge(volume, img->selection_mask, MODE_SUB, NULL);
image_history_push(goxel.image);
}
if (gui_button(_(FILL), 1, 0)) {
volume_merge(volume, img->selection_mask, MODE_OVER,
goxel.painter.color);
image_history_push(goxel.image);
}
if (gui_button(_(CUT_TO_NEW_LAYER), 1, 0)) {
cut_as_new_layer(img, img->active_layer, img->selection_mask);
image_history_push(goxel.image);
}
gui_group_end();
return 0;
}

Expand Down
7 changes: 0 additions & 7 deletions src/tools/rect_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ static int gui(tool_t *tool_)
{
tool_rect_select_t *tool = (void*)tool_;
tool_gui_mask_mode(&tool->mode);

gui_group_begin(NULL);
gui_action_button(ACTION_reset_selection, _(RESET), 1.0);
gui_action_button(ACTION_paint_selection, _(PAINT), 1.0);
gui_action_button(ACTION_cut_as_new_layer, _(CUT_TO_NEW_LAYER), 1.0);
gui_group_end();

return 0;
}

Expand Down
5 changes: 0 additions & 5 deletions src/tools/selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,6 @@ static int gui(tool_t *tool_)
tool_gui_mask_mode(&tool->mode);

if (box_is_null(*box)) return 0;
gui_group_begin(NULL);
gui_action_button(ACTION_fill_selection_box, _(FILL), 1.0);
gui_action_button(ACTION_paint_selection, _(PAINT), 1.0);
gui_action_button(ACTION_cut_as_new_layer, "Cut as new layer", 1.0);
gui_group_end();

// XXX: why not using gui_bbox here?
x_mag = fabs(get_magnitude(*box, 0));
Expand Down
11 changes: 7 additions & 4 deletions svg/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7080566

Please sign in to comment.