Skip to content

Commit

Permalink
Add "Copy to placer" and "Move via placer" buttons to both Selection …
Browse files Browse the repository at this point in the history
…and Placer tools
  • Loading branch information
GrandyB committed Aug 10, 2024
1 parent aa2d022 commit 45455e9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ enum {
X(tool_set_move),
X(tool_set_placer),

X(placer_acquire_selection),

X(export_to_photos),

X(select_layer_under_cursor),
Expand Down
3 changes: 1 addition & 2 deletions src/goxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
#include <stdlib.h>
#include <string.h>

#define GOXEL_VERSION_STR "0.13.0-aos-0_2f"
#define GOXEL_VERSION_STR "0.13.0-aos-0_2g"
#ifndef GOXEL_DEFAULT_THEME
# define GOXEL_DEFAULT_THEME "dark"
#endif
Expand Down Expand Up @@ -678,7 +678,6 @@ int gox_iter_infos(const char *path,
*/
int box_edit(int snap, int mode, float transf[4][4], bool *first);


void settings_load(void);
void settings_save(void);

Expand Down
67 changes: 45 additions & 22 deletions src/tools/placer.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,37 +338,54 @@ static void post_import(tool_placer_t *placer) {
center_origin(placer);
}

static void placer_acquire_selection() {
tool_placer_t *placer = (tool_placer_t*) goxel.tool;
reset(placer);
volume_t* copy;
painter_t painter;
const float (*box)[4][4] = &goxel.selection;

copy = volume_copy(goxel.image->active_layer->volume);

// Use the mask (from fuzzy select) if there
if (!volume_is_empty(goxel.mask)) {
volume_merge(copy, goxel.mask, MODE_INTERSECT, NULL);
} else {
// Otherwise, use the selection box
painter = (painter_t) {
.shape = &shape_cube,
.mode = MODE_INTERSECT,
.color = {255, 255, 255, 255},
};
volume_op(copy, &painter, *box);
}

placer->imported_volume = copy;
post_import(placer);
}

static int gui(tool_t *tool)
{
tool_placer_t *placer = (tool_placer_t*)tool;
float rotation[4][4] = MAT4_IDENTITY;
int origin_x, origin_y, origin_z, offset_x, offset_y, offset_z;

if (!box_is_null(goxel.selection)) {
if (gui_button("Acquire selection", -1, 0)) {
reset(placer);
volume_t* copy;
painter_t painter;
const float (*box)[4][4] = &goxel.selection;

copy = volume_copy(goxel.image->active_layer->volume);

// Use the mask (from fuzzy select) if there
if (!volume_is_empty(goxel.mask)) {
volume_merge(copy, goxel.mask, MODE_INTERSECT, NULL);
} else {
// Otherwise, use the selection box
painter = (painter_t) {
.shape = &shape_cube,
.mode = MODE_INTERSECT,
.color = {255, 255, 255, 255},
};
volume_op(copy, &painter, *box);
if(gui_section_begin("Selection", true)) {
if(gui_button("Copy to placer", -1, 0)) {
// Just copy
placer_acquire_selection();
}
if(gui_button("Move via placer", -1, 0)) {
// Copy to placer, wipe the selection and voxels within
placer_acquire_selection();
action_exec(action_get(ACTION_tool_set_selection, true));
action_exec(action_get(ACTION_layer_clear, true));
action_exec(action_get(ACTION_tool_set_placer, true));
action_exec(action_get(ACTION_reset_selection, true));
}

placer->imported_volume = copy;
post_import(placer);
}
gui_section_end();
}

// Browse files
Expand Down Expand Up @@ -495,3 +512,9 @@ TOOL_REGISTER(TOOL_PLACER, placer, tool_placer_t,
.flags = TOOL_REQUIRE_CAN_EDIT,
.default_shortcut = "P"
)

ACTION_REGISTER(placer_acquire_selection,
.help = "Placer - acquire selection",
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = placer_acquire_selection
)
18 changes: 18 additions & 0 deletions src/tools/selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,24 @@ static int gui(tool_t *tool)
bbox_from_extents(*box,
VEC(x + w / 2., y + h / 2., z + d / 2.),
w / 2., h / 2., d / 2.);

if(gui_section_begin("Placer", true)) {
if(gui_button("Copy to placer", -1, 0)) {
// Copy to placer and switch to placer
action_exec(action_get(ACTION_tool_set_placer, true));
action_exec(action_get(ACTION_placer_acquire_selection, true));
}
if(gui_button("Move via placer", -1, 0)) {
// Copy to placer, switch to placer and wipe the selection
action_exec(action_get(ACTION_tool_set_placer, true));
action_exec(action_get(ACTION_placer_acquire_selection, true));
action_exec(action_get(ACTION_tool_set_selection, true));
action_exec(action_get(ACTION_layer_clear, true));
action_exec(action_get(ACTION_tool_set_placer, true));
mat4_copy(mat4_zero, *box);
}
}
gui_section_end();
return 0;
}

Expand Down

0 comments on commit 45455e9

Please sign in to comment.