-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental support for filters
Filters are a bit similar to tools, with a few difference: - they only have a UI callback, but no ability to draw (for now at least). - They don't require any icon or fixed action id, so we can more easily add filters: just need to add a c file with the FILTER_REGISTER macro. - They show up in a special menu, instead of in the tool panel. The idea is to use the filters for operations that don't require a full drawing tool, like color correction, voxel effects, etc. Still a work in progress.
- Loading branch information
1 parent
cb56198
commit c591d94
Showing
6 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Goxel 3D voxels editor | ||
* | ||
* copyright (c) 2024 Guillaume Chereau <guillaume@noctua-software.com> | ||
* | ||
* 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" | ||
#include "../ext_src/stb/stb_ds.h" | ||
|
||
// stb array of registered filters. | ||
static filter_t **g_filters = NULL; | ||
|
||
static void a_filter_open(void *data) | ||
{ | ||
filter_t *filter = data; | ||
LOG_D("Open filter %s", filter->name); | ||
goxel.gui.current_filter = (filter_t*)data; | ||
} | ||
|
||
void filter_register_(filter_t *filter) | ||
{ | ||
action_t action; | ||
action = (action_t) { | ||
.id = filter->action_id, | ||
.default_shortcut = filter->default_shortcut, | ||
.cfunc_data = a_filter_open, | ||
.data = (void*)filter, | ||
.flags = ACTION_CAN_EDIT_SHORTCUT, | ||
}; | ||
action_register(&action, 0); | ||
arrput(g_filters, filter); | ||
} | ||
|
||
|
||
void filters_iter_all( | ||
void *arg, void (*f)(void *arg, const filter_t *filter)) | ||
{ | ||
int i; | ||
for (i = 0; i < arrlen(g_filters); i++) { | ||
f(arg, g_filters[i]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Goxel 3D voxels editor | ||
* | ||
* copyright (c) 2024 Guillaume Chereau <guillaume@noctua-software.com> | ||
* | ||
* 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/>. | ||
*/ | ||
|
||
#ifndef FILTERS_H | ||
#define FILTERS_H | ||
|
||
typedef struct filter filter_t; | ||
|
||
struct filter { | ||
int (*gui_fn)(filter_t *filter); | ||
const char *name; | ||
const char *action_id; | ||
const char *default_shortcut; | ||
}; | ||
|
||
#define FILTER_REGISTER(id_, klass_, ...) \ | ||
static klass_ GOX_filter_##id_ = {\ | ||
.filter = { \ | ||
.action_id = "filter_open_" #id_, __VA_ARGS__ \ | ||
} \ | ||
}; \ | ||
__attribute__((constructor)) \ | ||
static void GOX_register_filter_##id_(void) { \ | ||
filter_register_(&GOX_filter_##id_.filter); \ | ||
} | ||
|
||
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)); | ||
|
||
#endif // FILTERS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Goxel 3D voxels editor | ||
* | ||
* copyright (c) 2024-present Guillaume Chereau <guillaume@noctua-software.com> | ||
* | ||
* 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" | ||
|
||
/* | ||
* Dummy filter, just here for now until we have real filters. | ||
*/ | ||
|
||
typedef struct { | ||
filter_t filter; | ||
int x; | ||
} filter_dummy_t; | ||
|
||
static int gui(filter_t *filter) | ||
{ | ||
filter_dummy_t *dummy = (void*)filter; | ||
gui_text_wrapped("Just a test of a filter that does nothing."); | ||
gui_input_int("X", &dummy->x, 0, 0); | ||
return 0; | ||
} | ||
|
||
FILTER_REGISTER(dummy, filter_dummy_t, | ||
.name = "Dummy", | ||
.gui_fn = gui, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters