void gaw_blend_func(int src, int dest);
void gaw_alpha_func(int func, float ref);
+void gaw_zoffset(float offs);
+
void gaw_clear_color(float r, float g, float b, float a);
void gaw_clear(unsigned int flags);
void gaw_depth_mask(int mask);
/* TODO */
}
+void gaw_zoffset(float offs)
+{
+ st.zoffs = offs;
+}
+
#define CLAMP(x, a, b) ((x) < (a) ? (a) : ((x) > (b) ? (b) : (x)))
void gaw_clear_color(float r, float g, float b, float a)
float oow = 1.0f / v[i].w;
v[i].x *= oow;
v[i].y *= oow;
+ v[i].z += st.zoffs;
if(st.opt & (1 << GAW_DEPTH_TEST)) {
v[i].z *= oow;
}
int vertex_nelem, texcoord_nelem, color_nelem;
int vertex_stride, normal_stride, texcoord_stride, color_stride;
+ float zoffs;
+
/* immediate mode */
int imm_prim;
int imm_numv, imm_pcount;
}
/* --- button functions --- */
+void rtk_bn_mode(rtk_widget *w, int mode)
+{
+ RTK_ASSERT_TYPE(w, RTK_BUTTON);
+ w->bn.mode = mode;
+}
void rtk_bn_set_icon(rtk_widget *w, rtk_icon *icon)
{
static void draw_button(rtk_widget *w)
{
+ int pressed;
rtk_rect rect;
widget_rect(w, &rect);
abs_pos(w, &rect.x, &rect.y);
+ if(w->bn.mode == RTK_TOGGLEBN) {
+ pressed = w->any.value;
+ } else {
+ pressed = w->any.flags & PRESS;
+ }
+
if(rect.width > 2 && rect.height > 2) {
- draw_frame(&rect, w->any.flags & PRESS ? FRM_INSET : FRM_OUTSET);
+ draw_frame(&rect, pressed ? FRM_INSET : FRM_OUTSET);
rect.x++;
rect.y++;
static void click(rtk_widget *w, int x, int y)
{
switch(w->type) {
- case RTK_CHECKBOX:
- w->any.value ^= 1;
case RTK_BUTTON:
+ if(w->bn.mode == RTK_TOGGLEBN) {
+ case RTK_CHECKBOX:
+ w->any.value ^= 1;
+ }
if(w->any.cbfunc) {
w->any.cbfunc(w, w->any.cbcls);
}
#define RTK_H_
/* widget type */
-enum { RTK_ANY, RTK_WIN, RTK_BUTTON, RTK_LABEL, RTK_CHECKBOX, RTK_SLIDER, RTK_SEP };
+enum {
+ RTK_ANY,
+ RTK_WIN,
+ RTK_BUTTON,
+ RTK_LABEL,
+ RTK_CHECKBOX,
+ RTK_SLIDER,
+ RTK_SEP
+};
/* window layout */
enum { RTK_NONE, RTK_VBOX, RTK_HBOX };
+/* button mode */
+enum { RTK_PUSHBN, RTK_TOGGLEBN };
typedef struct rtk_screen rtk_screen;
typedef union rtk_widget rtk_widget;
int rtk_win_has(rtk_widget *par, rtk_widget *child);
/* button functions */
+void rtk_bn_mode(rtk_widget *w, int mode);
void rtk_bn_set_icon(rtk_widget *w, rtk_icon *icon);
rtk_icon *rtk_bn_get_icon(rtk_widget *w);
typedef struct rtk_button {
rtk_any any;
+ int mode;
rtk_icon *icon;
} rtk_button;
{48,16}, {64,16}, {80,16}, {-1,-1}, {96,16}
};
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, NUM_TOOLS};
+
static int mdl_init(void);
static void mdl_destroy(void);
static float cam_theta, cam_phi = 20, cam_dist = 8;
+static int tool;
+static int selobj = -1;
+
static int mdl_init(void)
{
if(!(w = rtk_create_iconbutton(toolbar, tbn_icons[i], 0))) {
return -1;
}
+ tbn_buttons[i] = w;
rtk_set_callback(w, tbn_callback, (void*)i);
+ if(i >= TBN_SEL && i <= TBN_SCALE) {
+ rtk_bn_mode(w, RTK_TOGGLEBN);
+ }
+ if(i == TBN_SEL) {
+ rtk_set_value(w, 1);
+ }
}
}
draw_grid();
- gaw_poly_wire();
-
num = scn_num_objects(scn);
for(i=0; i<num; i++) {
struct object *obj = scn->objects[i];
case OBJ_SPHERE:
sph = (struct sphere*)obj;
gaw_scale(sph->rad, sph->rad, sph->rad);
+ gaw_zoffset(0.1);
+ cmesh_draw(mesh_sph);
+ gaw_zoffset(0);
+
+ gaw_save();
+ gaw_disable(GAW_LIGHTING);
+ gaw_poly_wire();
+ gaw_color3f(0, 1, 0);
cmesh_draw(mesh_sph);
+ gaw_poly_gouraud();
+ gaw_restore();
break;
default:
gaw_pop_matrix();
}
- gaw_poly_gouraud();
-
gaw_viewport(0, 0, win_width, win_height);
}
static void tbn_callback(rtk_widget *w, void *cls)
{
- int id = (intptr_t)cls;
+ int i, id = (intptr_t)cls;
+ int idx;
switch(id) {
+ case TBN_SEL:
+ case TBN_MOVE:
+ case TBN_ROT:
+ case TBN_SCALE:
+ tool = id - TBN_SEL;
+ for(i=0; i<NUM_TOOLS; i++) {
+ if(i != tool) {
+ rtk_set_value(tbn_buttons[i + TBN_SEL], 0);
+ }
+ }
+ break;
+
case TBN_ADD:
+ idx = scn_num_objects(scn);
add_sphere();
+ selobj = idx;
break;
default: