stop appending repeat keys to the input buffer
[retroray] / src / modui.c
1 /*
2 RetroRay - integrated standalone vintage modeller/renderer
3 Copyright (C) 2023  John Tsiombikas <nuclear@mutantstargoat.com>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #include <assert.h>
19 #include "modui.h"
20 #include "app.h"
21 #include "rtk.h"
22
23 static const char *tbn_icon_name[] = {
24         "new", "open", "save", 0,
25         "sel", "move", "rot", "scale", 0,
26         "add", "remove", 0,
27         "union", "isect", "diff", 0,
28         "mtl", "rend", "rend-area", "viewrend", 0, "cfg"
29 };
30 static int tbn_icon_pos[][2] = {
31         {0,0}, {16,0}, {32,0}, {-1,-1},
32         {48,0}, {64,0}, {80,0}, {96,0}, {-1,-1},
33         {112,0}, {112,16}, {-1,-1},
34         {0,16}, {16,16}, {32,16}, {-1,-1},
35         {48,16}, {64,16}, {64, 32}, {80,16}, {-1,-1}, {96,16}
36 };
37 static int tbn_istool[] = {
38         0, 0, 0, 0,
39         1, 1, 1, 1, 0,
40         0, 0, 0,
41         1, 1, 1, 0,
42         0, 0, 1, 0, 0, 0
43 };
44 static rtk_icon *tbn_icons[NUM_TOOL_BUTTONS];
45 static rtk_widget *tbn_buttons[NUM_TOOL_BUTTONS];
46 static rtk_iconsheet *icons;
47
48 rtk_widget *toolbar, *mtlwin;
49 rtk_widget *tools[NUM_TOOLS];
50
51 static int create_toolbar(void);
52 static int create_mtlwin(void);
53
54 int modui_init(void)
55 {
56         if(!(icons = rtk_load_iconsheet("data/icons.png"))) {
57                 errormsg("failed to load iconsheet\n");
58                 return -1;
59         }
60
61         if(create_toolbar() == -1) {
62                 return -1;
63         }
64         if(create_mtlwin() == -1) {
65                 return -1;
66         }
67         return 0;
68 }
69
70 static int create_toolbar(void)
71 {
72         int i, toolidx;
73         rtk_widget *w;
74
75         for(i=0; i<NUM_TOOL_BUTTONS; i++) {
76                 if(tbn_icon_name[i]) {
77                         tbn_icons[i] = rtk_define_icon(icons, tbn_icon_name[i],
78                                         tbn_icon_pos[i][0], tbn_icon_pos[i][1], 16, 16);
79                 } else {
80                         tbn_icons[i] = 0;
81                 }
82         }
83
84         if(!(toolbar = rtk_create_window(0, "toolbar", 0, 0, win_width, TOOLBAR_HEIGHT, 0))) {
85                 return -1;
86         }
87         rtk_win_layout(toolbar, RTK_HBOX);
88
89         toolidx = 0;
90         for(i=0; i<NUM_TOOL_BUTTONS; i++) {
91                 if(!tbn_icons[i]) {
92                         rtk_create_separator(toolbar);
93                 } else {
94                         if(!(w = rtk_create_iconbutton(toolbar, tbn_icons[i], 0))) {
95                                 return -1;
96                         }
97                         tbn_buttons[i] = w;
98                         rtk_set_callback(w, tbn_callback, (void*)(intptr_t)i);
99                         if(tbn_istool[i]) {
100                                 rtk_bn_mode(w, RTK_TOGGLEBN);
101                                 tools[toolidx++] = w;
102                         }
103                         if(i == TBN_SEL) {
104                                 rtk_set_value(w, 1);
105                         }
106                 }
107         }
108         assert(toolidx == NUM_TOOLS);
109
110         return 0;
111 }
112
113 static int create_mtlwin(void)
114 {
115         if(!(mtlwin = rtk_create_window(0, "Materials", win_width / 2, 64, 256, 380,
116                                         RTK_WIN_FRAME | RTK_WIN_MOVABLE | RTK_WIN_RESIZABLE))) {
117                 return -1;
118         }
119
120         return 0;
121 }
122
123 void modui_cleanup(void)
124 {
125         rtk_free_widget(toolbar);
126         rtk_free_widget(mtlwin);
127         rtk_free_iconsheet(icons);
128 }