+/*
+RetroRay - integrated standalone vintage modeller/renderer
+Copyright (C) 2023 John Tsiombikas <nuclear@mutantstargoat.com>
+
+This program 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.
+
+This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+#include <assert.h>
+#include "modui.h"
+#include "app.h"
+#include "rtk.h"
+
+static const char *tbn_icon_name[] = {
+ "new", "open", "save", 0,
+ "sel", "move", "rot", "scale", 0,
+ "add", "remove", 0,
+ "union", "isect", "diff", 0,
+ "mtl", "rend", "rend-area", "viewrend", 0, "cfg"
+};
+static int tbn_icon_pos[][2] = {
+ {0,0}, {16,0}, {32,0}, {-1,-1},
+ {48,0}, {64,0}, {80,0}, {96,0}, {-1,-1},
+ {112,0}, {112,16}, {-1,-1},
+ {0,16}, {16,16}, {32,16}, {-1,-1},
+ {48,16}, {64,16}, {64, 32}, {80,16}, {-1,-1}, {96,16}
+};
+static int tbn_istool[] = {
+ 0, 0, 0, 0,
+ 1, 1, 1, 1, 0,
+ 0, 0, 0,
+ 1, 1, 1, 0,
+ 0, 0, 1, 0, 0, 0
+};
+static rtk_icon *tbn_icons[NUM_TOOL_BUTTONS];
+static rtk_widget *tbn_buttons[NUM_TOOL_BUTTONS];
+static rtk_iconsheet *icons;
+
+rtk_widget *toolbar, *mtlwin;
+rtk_widget *tools[NUM_TOOLS];
+
+static int create_toolbar(void);
+static int create_mtlwin(void);
+
+int modui_init(void)
+{
+ if(!(icons = rtk_load_iconsheet("data/icons.png"))) {
+ errormsg("failed to load iconsheet\n");
+ return -1;
+ }
+
+ if(create_toolbar() == -1) {
+ return -1;
+ }
+ if(create_mtlwin() == -1) {
+ return -1;
+ }
+ return 0;
+}
+
+static int create_toolbar(void)
+{
+ int i, toolidx;
+ rtk_widget *w;
+
+ for(i=0; i<NUM_TOOL_BUTTONS; i++) {
+ if(tbn_icon_name[i]) {
+ tbn_icons[i] = rtk_define_icon(icons, tbn_icon_name[i],
+ tbn_icon_pos[i][0], tbn_icon_pos[i][1], 16, 16);
+ } else {
+ tbn_icons[i] = 0;
+ }
+ }
+
+ if(!(toolbar = rtk_create_window(0, "toolbar", 0, 0, win_width, TOOLBAR_HEIGHT, 0))) {
+ return -1;
+ }
+ rtk_win_layout(toolbar, RTK_HBOX);
+
+ toolidx = 0;
+ for(i=0; i<NUM_TOOL_BUTTONS; i++) {
+ if(!tbn_icons[i]) {
+ rtk_create_separator(toolbar);
+ } else {
+ if(!(w = rtk_create_iconbutton(toolbar, tbn_icons[i], 0))) {
+ return -1;
+ }
+ tbn_buttons[i] = w;
+ rtk_set_callback(w, tbn_callback, (void*)(intptr_t)i);
+ if(tbn_istool[i]) {
+ rtk_bn_mode(w, RTK_TOGGLEBN);
+ tools[toolidx++] = w;
+ }
+ if(i == TBN_SEL) {
+ rtk_set_value(w, 1);
+ }
+ }
+ }
+ assert(toolidx == NUM_TOOLS);
+
+ return 0;
+}
+
+static int create_mtlwin(void)
+{
+ if(!(mtlwin = rtk_create_window(0, "Materials", win_width / 2, 64, 256, 380,
+ RTK_WIN_FRAME | RTK_WIN_MOVABLE | RTK_WIN_RESIZABLE))) {
+ return -1;
+ }
+
+ return 0;
+}
+
+void modui_cleanup(void)
+{
+ rtk_free_widget(toolbar);
+ rtk_free_widget(mtlwin);
+ rtk_free_iconsheet(icons);
+}