1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
#include "editor.h"
#include "../game/objlist.h"
#include "../game/world/draw.h"
#include "../game/world/bsp_draw.h"
#include "../game.h"
const I32 EDITORVIEW_TITLE_OFFSET = 15;
const I32 EDITORVIEW_TOOLBAR_OFFSET = 20;
void gui_editor_3dview_draw_showpos( GUI_EDITOR_3DVIEW* view ) {
I32 x = gui_relx( view );
I32 y = gui_rely( view ) + EDITORVIEW_TITLE_OFFSET;
VEC3 pos = objl->pl->pos;
gui_draw_str(
x + view->w - 2, y + 2,
ALIGN_R,
FNT_JPN12,
ui_clr.txt,
"pos: %.02f %.02f %.02f",
pos.x, pos.y, pos.z
);
gui_draw_str(
x + view->w - 2, y + 18,
ALIGN_R,
FNT_JPN12,
ui_clr.txt,
"rot: %.02f %.02f",
objl->pl->rot.y,
objl->pl->rot.x
);
if( input.mouselock ) {
gui_draw_str(
x + 2, y + 2,
ALIGN_L,
FNT_JPN12,
ui_clr.txt,
"[capturing mouse]"
);
}
}
void gui_editor_3dview_draw_fn( void* ptr ) {
GUI_EDITOR_3DVIEW* view = (GUI_EDITOR_3DVIEW*)ptr;
if( !objl->pl )
return;
I32 x = gui_relx( view );
I32 y = gui_rely( view );
gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, "3d view" );
y += EDITORVIEW_TITLE_OFFSET;
VEC2 wnd = { (F32)x, (F32)y };
VEC2 winsize = { (F32)view->w, (F32)view->h };
CLR col = gui_is_fg_window( view )? ui_clr.border : ui_clr.border_inactive;
gui_draw_frect( x-1, y-1, view->w+2, view->h+2, col );
gui_draw_frect( x, y, view->w, view->h, CLR::BLACK() );
if( editor->drawbsp && editor->map->bsp )
bsp_draw( editor->map->bsp, editor->game, wnd, winsize );
else
world_draw( editor->game, objl->world, wnd, winsize );
gui_draw_push_clip( x, y, view->w, view->h );
view->children.each( fn( GUI_BASE** childptr ) {
GUI_BASE* child = *childptr;
if( !child->enabled ) return;
if( child->draw_fn ) child->draw_fn( child );
else dlog( "gui_view_draw_fn(): child %p no draw_fn\n", child );
} );
gui_draw_pop_clip();
gui_editor_3dview_draw_showpos( view );
}
void gui_editor_3dview_input_fn( void* ptr ) {
GUI_EDITOR_3DVIEW* view = (GUI_EDITOR_3DVIEW*)ptr;
if( !input.mouselock )
gui_base_input_fn( view );
if( !objl->pl )
return;
if( input.mouse.left ) {
I32 view_x = gui_relx( view );
I32 view_y = gui_rely( view ) + EDITORVIEW_TITLE_OFFSET;
if( input.mouse.pos.x >= view_x && input.mouse.pos.x < view_x + view->w &&
input.mouse.pos.y >= view_y && input.mouse.pos.y < view_y + view->h - EDITORVIEW_TOOLBAR_OFFSET ) {
if( !input.mouselock && !view->heldoutbounds )
input_capture_mouse( true );
} else {
view->heldoutbounds = 1;
}
} else view->heldoutbounds = 0;
game_on_tick( editor->game );
}
void gui_editor_3dview_create_toolbar( GUI_EDITOR_3DVIEW* view ) {
GAME_EDITOR* e = editor;
I32 x = 1, y = view->h - 4;
gui_button( x, y, 90, 18, "compile bsp", pfn( void* b ) {
if( editor->map->bsp )
bsp_free( editor->map->bsp );
editor->map->bsp = bsp_build_map( editor->map );
} ); x += 100;
gui_checkbox( x, y, "draw bsp", &e->drawbsp );
}
GUI_EDITOR_3DVIEW* gui_editor_3dview( I32 x, I32 y, I32 w, I32 h ) {
GUI_EDITOR_3DVIEW* view = new GUI_EDITOR_3DVIEW;
view->x = x;
view->y = y;
view->xbound = view->w = w;
view->h = h;
view->ybound = h + EDITORVIEW_TITLE_OFFSET;
view->draw_fn = gui_editor_3dview_draw_fn;
view->input_fn = gui_editor_3dview_input_fn;
strcpy( view->name, "EDITOR_3D_VIEW" );
GUI_BASE* parent = gui_get_view();
if( !parent )
parent = gui_get_window();
parent->children.push( view );
view->parent = parent;
gui_set_view( view );
gui_editor_3dview_create_toolbar( view );
gui_set_view( (GUI_VIEW*)parent );
return view;
}
|