tools/atlas-editor.c

changeset 312
330fc71ad3c2
parent 309
8124d12deb04
child 313
e8119155c099
equal deleted inserted replaced
311:87ff4c57955d 312:330fc71ad3c2
25 * POSSIBILITY OF SUCH DAMAGE. 25 * POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include <ui/ui.h> 28 #include <ui/ui.h>
29 29
30 #define VAR_TILE_WIDTH "tile_width"
31 #define VAR_TILE_HEIGHT "tile_height"
32 #define VAR_SPACING "spacing"
33
34 static void *create_document(void) {
35 void *doc = ui_document_new(1); // TODO: actually we have zero additional data, but that probably does not work
36 UiContext *ctx = ui_document_context(doc);
37 ui_set(ui_int_new(ctx, VAR_TILE_WIDTH), 32);
38 ui_set(ui_int_new(ctx, VAR_TILE_HEIGHT), 32);
39 ui_set(ui_int_new(ctx, VAR_SPACING), 0);
40 return doc;
41 }
42
30 static void draw_atlas(UiEvent* evt, UiGraphics* g, void* data) { 43 static void draw_atlas(UiEvent* evt, UiGraphics* g, void* data) {
44 UiContext *doc_ctx = ui_document_context(evt->document);
45 int spacing = (int) ui_var_get_int(doc_ctx, VAR_SPACING);
46 int tile_width = (int) ui_var_get_int(doc_ctx, VAR_TILE_WIDTH);
47 int tile_height = (int) ui_var_get_int(doc_ctx, VAR_TILE_HEIGHT);
48
31 ui_graphics_color(g, 255, 128, 0); 49 ui_graphics_color(g, 255, 128, 0);
32 ui_draw_rect(g, 0, 0, g->width, g->height, true); 50 ui_draw_rect(g, 0, 0, g->width, g->height, true);
51 ui_graphics_color(g, 128, 128, 128);
52 for (int x = spacing ; x < g->width ; x += tile_width + spacing) {
53 for (int y = spacing ; y < g->height ; y += tile_height + spacing) {
54 ui_draw_rect(g, x, y, tile_width, tile_height, false);
55 }
56 }
33 } 57 }
34 58
35 static void application_startup([[maybe_unused]] UiEvent *event, [[maybe_unused]] void *data) { 59 static void application_startup([[maybe_unused]] UiEvent *event, void *data) {
36 UiObject *window = ui_window("Ascension - Texture Atlas Editor"); 60 UiObject *window = ui_window("Ascension - Texture Atlas Editor");
37 61
38 ui_grid(window, .columnspacing = 10, .margin = 10, .fill = true) { 62 ui_grid(window, .columnspacing = 10, .margin = 10, .fill = true) {
39 ui_frame(window, .hexpand = true, .hfill = true, .vexpand = true, .vfill = true, 63 ui_frame(window, .hexpand = true, .hfill = true, .vexpand = true, .vfill = true,
40 .subcontainer = UI_CONTAINER_NO_SUB) { 64 .subcontainer = UI_CONTAINER_NO_SUB) {
47 } 71 }
48 ui_button(window, .label = "Load Texture"); 72 ui_button(window, .label = "Load Texture");
49 ui_separator(window); 73 ui_separator(window);
50 ui_grid(window, .columnspacing = 10, .rowspacing = 2, .def_vfill = true) { 74 ui_grid(window, .columnspacing = 10, .rowspacing = 2, .def_vfill = true) {
51 ui_label(window, .label = "Tile Width:"); 75 ui_label(window, .label = "Tile Width:");
52 ui_textfield(window, .width = 20); // TODO: in current toolkit version, width is not accepted 76 ui_spinbox(window, .varname = VAR_TILE_WIDTH, .min = 8, .step = 8);
53 ui_label(window, .label = "Tile Height:"); 77 ui_label(window, .label = "Tile Height:");
54 ui_textfield(window, .width = 20); 78 ui_spinbox(window, .varname = VAR_TILE_HEIGHT, .min = 8, .step = 8);
79 ui_newline(window);
80 ui_label(window, .varname = VAR_SPACING, .label = "Spacing:");
81 ui_spinbox(window);
55 } 82 }
56 } 83 }
57 } 84 }
58 85
86 ui_attach_document(window->ctx, create_document());
87
59 ui_show(window); 88 ui_show(window);
60 } 89 }
61 90
62 int main(int argc, char** argv) { 91 int main(int argc, char** argv) {
63 ui_init("asc_atlas_editor", argc, argv); 92 ui_init("asc_atlas_editor", argc, argv);
64 ui_onstartup(application_startup, NULL); 93 ui_onstartup(application_startup, NULL);
65 ui_main(); 94 ui_main();
66 return 0; 95 return 0;
67 } 96 }

mercurial