Skip to content

Commit

Permalink
Merge branch 'upstream-master' into system-clipboard-copy
Browse files Browse the repository at this point in the history
  • Loading branch information
madd-games committed Oct 14, 2024
2 parents 4c8335c + 8ae26ff commit bc14754
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 24 deletions.
8 changes: 8 additions & 0 deletions osx/goxel/goxel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
F037D5D61EA6069A00C96D10 /* shape.c in Sources */ = {isa = PBXBuildFile; fileRef = F037D5CE1EA6069A00C96D10 /* shape.c */; };
F03B4387224CCDDF00798CAB /* pathtracer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F03B4385224CCDDF00798CAB /* pathtracer.cpp */; };
F03B4388224CCDDF00798CAB /* yocto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F03B4386224CCDDF00798CAB /* yocto.cpp */; };
F03CC5A12CBD229700F49C01 /* colors.c in Sources */ = {isa = PBXBuildFile; fileRef = F03CC59F2CBD229700F49C01 /* colors.c */; };
F03CC5A22CBD229700F49C01 /* mirror.c in Sources */ = {isa = PBXBuildFile; fileRef = F03CC5A02CBD229700F49C01 /* mirror.c */; };
F056EAB32C3AD8D400E23BD3 /* edit_panel.c in Sources */ = {isa = PBXBuildFile; fileRef = F056EAB22C3AD8D400E23BD3 /* edit_panel.c */; };
F05D6E5D29D3E952004CA300 /* script.c in Sources */ = {isa = PBXBuildFile; fileRef = F05D6E5C29D3E952004CA300 /* script.c */; };
F05D6E8029D3EA36004CA300 /* volume.c in Sources */ = {isa = PBXBuildFile; fileRef = F05D6E7C29D3EA36004CA300 /* volume.c */; };
Expand Down Expand Up @@ -174,6 +176,8 @@
F037D5CE1EA6069A00C96D10 /* shape.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = shape.c; sourceTree = "<group>"; };
F03B4385224CCDDF00798CAB /* pathtracer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pathtracer.cpp; sourceTree = "<group>"; };
F03B4386224CCDDF00798CAB /* yocto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = yocto.cpp; sourceTree = "<group>"; };
F03CC59F2CBD229700F49C01 /* colors.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = colors.c; sourceTree = "<group>"; };
F03CC5A02CBD229700F49C01 /* mirror.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = mirror.c; sourceTree = "<group>"; };
F056EAB22C3AD8D400E23BD3 /* edit_panel.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = edit_panel.c; sourceTree = "<group>"; };
F05D6E5B29D3E7EC004CA300 /* voxelizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = voxelizer.h; sourceTree = "<group>"; };
F05D6E5C29D3E952004CA300 /* script.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = script.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -557,6 +561,8 @@
F0EDCB6A2BB2728B00D95B51 /* filters */ = {
isa = PBXGroup;
children = (
F03CC59F2CBD229700F49C01 /* colors.c */,
F03CC5A02CBD229700F49C01 /* mirror.c */,
F0EDCB6B2BB2728B00D95B51 /* wrap.c */,
);
path = filters;
Expand Down Expand Up @@ -677,6 +683,8 @@
F0BC9B362315550500B2A56A /* app.c in Sources */,
F0A160081E962F4600C6EF33 /* marchingcube.c in Sources */,
F00FC312226B2F7C0002F251 /* ini.c in Sources */,
F03CC5A12CBD229700F49C01 /* colors.c in Sources */,
F03CC5A22CBD229700F49C01 /* mirror.c in Sources */,
F0EEB7E41C8EC27C004AB676 /* action.c in Sources */,
F037D5D61EA6069A00C96D10 /* shape.c in Sources */,
F05D6E5D29D3E952004CA300 /* script.c in Sources */,
Expand Down
17 changes: 11 additions & 6 deletions src/filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
// stb array of registered filters.
static filter_t **g_filters = NULL;

static void a_filter_open(void *data)
static void a_filter_toggle(void *data)
{
filter_t *filter = data;
LOG_D("Open filter %s", filter->name);
goxel.gui.current_filter = (filter_t*)data;
if (filter->on_open) {
LOG_D("Toggle filter %s", filter->name);
filter->is_open = !filter->is_open;

if (filter->is_open && filter->on_open) {
filter->on_open(filter);
}

if (!filter->is_open && filter->on_close) {
filter->on_close(filter);
}
}

void filter_register_(filter_t *filter)
Expand All @@ -38,7 +43,7 @@ void filter_register_(filter_t *filter)
action = (action_t) {
.id = filter->action_id,
.default_shortcut = filter->default_shortcut,
.cfunc_data = a_filter_open,
.cfunc_data = a_filter_toggle,
.data = (void*)filter,
.flags = ACTION_CAN_EDIT_SHORTCUT,
};
Expand All @@ -48,7 +53,7 @@ void filter_register_(filter_t *filter)


void filters_iter_all(
void *arg, void (*f)(void *arg, const filter_t *filter))
void *arg, void (*f)(void *arg, filter_t *filter))
{
int i;
for (i = 0; i < arrlen(g_filters); i++) {
Expand Down
5 changes: 4 additions & 1 deletion src/filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef FILTERS_H
#define FILTERS_H

#include <stdbool.h>

typedef struct filter filter_t;

struct filter {
Expand All @@ -28,6 +30,7 @@ struct filter {
const char *name;
const char *action_id;
const char *default_shortcut;
bool is_open;
};

#define FILTER_REGISTER(id_, klass_, ...) \
Expand All @@ -47,6 +50,6 @@ void filter_register_(filter_t *filter);
* Iter all the registered filters
*/
void filters_iter_all(
void *arg, void (*f)(void *arg, const filter_t *filter));
void *arg, void (*f)(void *arg, filter_t *filter));

#endif // FILTERS_H
1 change: 0 additions & 1 deletion src/goxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ typedef struct goxel
int current_panel; // Index of the current visible control panel.
float panel_width;
float viewport[4];
filter_t *current_filter;
} gui;

char **recent_files; // stb arraw of most recently used files.
Expand Down
54 changes: 39 additions & 15 deletions src/gui/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* goxel. If not, see <http://www.gnu.org/licenses/>.
*/

#include "filters.h"
#include "goxel.h"

#include "../ext_src/stb/stb_ds.h"
Expand All @@ -36,6 +37,9 @@
# define YOCTO 1
#endif

#define INITIAL_FILTER_OFFSET 10
#define RELATIVE_FILTER_OFFSET 40

// Note: duplicated from gui.cpp! To remove.
static const float ITEM_HEIGHT = 18;

Expand Down Expand Up @@ -101,6 +105,13 @@ static struct {
#endif
};

typedef struct filter_layout_state filter_layout_state_t;

struct filter_layout_state {
int next_x;
int next_y;
};

static void on_click(void) {
if (DEFINED(GUI_SOUND))
sound_play("click", 1.0, 1.0);
Expand Down Expand Up @@ -157,14 +168,37 @@ static void render_hints(const hint_t *hints)
}
}

static void gui_filter_window(void *arg, filter_t *filter)
{
filter_layout_state_t *state = arg;

if (filter->is_open) {
gui_window_begin(filter->name, state->next_x, state->next_y,
goxel.gui.panel_width, 0, GUI_WINDOW_MOVABLE);

if (gui_panel_header(filter->name)) {
if (filter->on_close) {
filter->on_close(filter);
}
filter->is_open = false;
}
filter->gui_fn(filter);

gui_window_end();
}

state->next_x += RELATIVE_FILTER_OFFSET;
state->next_y += RELATIVE_FILTER_OFFSET;
}

void gui_app(void)
{
float x = 0, y = 0;
const char *name;
const float spacing = 8;
int flags;
int i;
filter_t *filter;
filter_layout_state_t filter_layout_state;

goxel.show_export_viewport = false;

Expand Down Expand Up @@ -216,20 +250,10 @@ void gui_app(void)
gui_window_end();
}

filter = goxel.gui.current_filter;
if (filter) {
// XXX: we should have a way to center the filter window.
gui_window_begin(filter->name, 100, 100, goxel.gui.panel_width, 0,
GUI_WINDOW_MOVABLE);
if (gui_panel_header(filter->name)) {
if (goxel.gui.current_filter->on_close) {
goxel.gui.current_filter->on_close(goxel.gui.current_filter);
}
goxel.gui.current_filter = NULL;
}
filter->gui_fn(filter);
gui_window_end();
}
filter_layout_state.next_x = x + goxel.gui.panel_width +
INITIAL_FILTER_OFFSET;
filter_layout_state.next_y = y;
filters_iter_all(&filter_layout_state, gui_filter_window);

goxel.pathtrace = goxel.pathtracer.status &&
(goxel.gui.current_panel == PANEL_RENDER ||
Expand Down
2 changes: 1 addition & 1 deletion src/gui/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void on_script(void *user, const char *name)
script_execute(name);
}

static void on_filter(void *user, const filter_t *filter)
static void on_filter(void *user, filter_t *filter)
{
const action_t *action;
if (gui_menu_item(0, filter->name, true)) {
Expand Down

0 comments on commit bc14754

Please sign in to comment.