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 "gaw/gaw.h"
#include "app.h"
#include "rtk.h"
#include "meshgen.h"
#include "font.h"
#include "rend.h"
-
-enum {
- TBN_NEW, TBN_OPEN, TBN_SAVE, TBN_SEP1,
- TBN_SEL, TBN_MOVE, TBN_ROT, TBN_SCALE, TBN_SEP2,
- TBN_ADD, TBN_RM, TBN_SEP3,
- TBN_UNION, TBN_ISECT, TBN_DIFF, TBN_SEP4,
- TBN_MTL, TBN_REND, TBN_REND_AREA, TBN_VIEWREND, TBN_SEP5, TBN_CFG,
-
- NUM_TOOL_BUTTONS
-};
-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];
-
-#define TOOLBAR_HEIGHT 26
-
-enum {
- TOOL_SEL, TOOL_MOVE, TOOL_ROT, TOOL_SCALE,
- TOOL_UNION, TOOL_ISECT, TOOL_DIFF, TOOL_REND_AREA,
- NUM_TOOLS
-};
-static rtk_widget *tools[NUM_TOOLS];
+#include "modui.h"
static int vpdirty;
+static rtk_rect totalrend;
static int mdl_init(void);
static void draw_object(struct object *obj);
static void setup_material(struct material *mtl);
static void draw_grid(void);
-static void tbn_callback(rtk_widget *w, void *cls);
static void act_settool(int tidx);
static void act_addobj(void);
static void act_rmobj(void);
-static void fix_rect(rtk_rect *rect);
-static void draw_rband(void);
static void moveobj(struct object *obj, int px0, int py0, int px1, int py1);
static void inval_vport(void);
mdl_keyb, mdl_mouse, mdl_motion
};
-static rtk_widget *toolbar;
-static rtk_iconsheet *icons;
static struct cmesh *mesh_sph;
static int mdl_init(void)
{
- int i, toolidx;
- rtk_widget *w;
-
- if(!(icons = rtk_load_iconsheet("data/icons.png"))) {
- errormsg("failed to load iconsheet\n");
+ if(modui_init() == -1) {
+ errormsg("failed to initialize modeller UI\n");
return -1;
}
- 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))) {
- 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);
if(!(mesh_sph = cmesh_alloc())) {
errormsg("failed to allocate sphere vis mesh\n");
static void mdl_destroy(void)
{
cmesh_free(mesh_sph);
- rtk_free_iconsheet(icons);
+ modui_cleanup();
}
static int mdl_start(void)
/* dirty all GUI windows */
rtk_invalidate(toolbar);
+ rtk_invalidate(mtlwin);
}
/* render layer */
if(rendering) {
if(!render(framebuf)) {
rendering = 0;
- vpdirty = 1;
}
app_redisplay(rendrect.x, rendrect.y, rendrect.width, rendrect.height);
}
/* GUI */
rtk_draw_widget(toolbar);
-
- if(rband_valid) {
- draw_rband();
- }
+ rtk_draw_widget(mtlwin);
}
static void draw_object(struct object *obj)
cgm_minverse(proj_matrix_inv);
rtk_resize(toolbar, win_width, TOOLBAR_HEIGHT);
+
+ inval_vport();
}
static void mdl_keyb(int key, int press)
if(rband_valid) {
rband_valid = 0;
+ app_rband(0, 0, 0, 0);
if(cur_tool == TOOL_REND_AREA) {
- if(prev_tool >= 0) {
- act_settool(prev_tool);
+ if(rband.width && rband.height) {
+ rendering = 1;
+ rend_size(win_width, win_height);
+ rtk_fix_rect(&rband);
+ rendrect = rband;
+ rend_begin(rband.x, rband.y, rband.width, rband.height);
+ app_redisplay(rband.x, rband.y, rband.width, rband.height);
+
+ if(totalrend.width) {
+ rtk_rect_union(&totalrend, &rband);
+ } else {
+ totalrend = rband;
+ }
}
- rendering = 1;
- rend_size(win_width, win_height);
- fix_rect(&rband);
- rendrect = rband;
- rend_begin(rband.x, rband.y, rband.width, rband.height);
}
- app_redisplay(rband.x, rband.y, rband.width, rband.height);
} else if(bn == 0 && x == rband.x && y == rband.y) {
primray(&pickray, x, y);
rband.width = x - rband.x;
rband.height = y - rband.y;
rband_valid = 1;
+ app_rband(rband.x, rband.y, rband.width, rband.height);
}
break;
scn_add_object(scn, obj);
}
-static void tbn_callback(rtk_widget *w, void *cls)
+void tbn_callback(rtk_widget *w, void *cls)
{
int id = (intptr_t)cls;
switch(id) {
+ case TBN_NEW:
+ scn_clear(scn);
+ inval_vport();
+ break;
+
case TBN_SEL:
case TBN_MOVE:
case TBN_ROT:
case TBN_DIFF:
act_settool(id - TBN_UNION + TOOL_UNION);
break;
+
+ case TBN_MTL:
+ if(rtk_visible(mtlwin)) {
+ rtk_hide(mtlwin);
+ inval_vport();
+ } else {
+ rtk_show(mtlwin);
+ }
+ break;
+
case TBN_REND_AREA:
act_settool(TOOL_REND_AREA);
break;
int i;
rtk_rect r;
+ if(tidx == cur_tool) return;
+
+ if(cur_tool == TOOL_REND_AREA) {
+ totalrend.width = 0;
+ app_redisplay(totalrend.x, totalrend.y, totalrend.width, totalrend.height);
+ inval_vport();
+ }
+
prev_tool = cur_tool;
cur_tool = tidx;
for(i=0; i<NUM_TOOLS; i++) {
}
}
-static void fix_rect(rtk_rect *rect)
-{
- int x, y, w, h;
-
- x = rband.x;
- y = rband.y;
-
- if(rband.width < 0) {
- w = -rband.width;
- x += rband.width;
- } else {
- w = rband.width;
- }
- if(rband.height < 0) {
- h = -rband.height;
- y += rband.height;
- } else {
- h = rband.height;
- }
-
- rect->x = x;
- rect->y = y;
- rect->width = w;
- rect->height = h;
-}
-
-static void draw_rband(void)
-{
- int i;
- rtk_rect rect;
- uint32_t *fbptr, *bptr;
-
- rect = rband;
- fix_rect(&rect);
-
- fbptr = framebuf + rect.y * win_width + rect.x;
- bptr = fbptr + win_width * (rect.height - 1);
-
- for(i=0; i<rect.width; i++) {
- fbptr[i] ^= 0xffffff;
- bptr[i] ^= 0xffffff;
- }
- fbptr += win_width;
- for(i=0; i<rect.height-2; i++) {
- fbptr[0] ^= 0xffffff;
- fbptr[rect.width - 1] ^= 0xffffff;
- fbptr += win_width;
- }
- app_redisplay(rect.x, rect.y, rect.width, rect.height);
-}
void primray(cgm_ray *ray, int x, int y)
{