sorta ready
[carveJwlIkooP6JGAAIwe30JlM.git] / gui.h
1 #ifndef GUI_H
2 #define GUI_H
3
4 #include "font.h"
5
6 struct{
7 struct gui_helper{
8 const char *bindstr, *text;
9 }
10 helpers[4];
11 u32 helper_count;
12
13 f32 factive;
14 font3d font;
15 }
16 static gui;
17
18 VG_STATIC
19 void gui_draw(void)
20 {
21 camera ortho;
22
23 float fl = 0.0f,
24 fr = vg.window_x,
25 fb = 0.0f,
26 ft = vg.window_y,
27 rl = 1.0f / (fr-fl),
28 tb = 1.0f / (ft-fb);
29
30 m4x4_zero( ortho.mtx.p );
31 ortho.mtx.p[0][0] = 2.0f * rl;
32 ortho.mtx.p[1][1] = 2.0f * tb;
33 ortho.mtx.p[3][0] = (fr + fl) * -rl;
34 ortho.mtx.p[3][1] = (ft + fb) * -tb;
35 ortho.mtx.p[3][3] = 1.0f;
36 m4x3_identity( ortho.transform );
37 camera_update_view( &ortho );
38 m4x4_mul( ortho.mtx.p, ortho.mtx.v, ortho.mtx.pv ); /* HACK */
39 camera_finalize( &ortho );
40
41 gui.factive = vg_lerpf( gui.factive, gui.helper_count?1.0f:0.0f,
42 vg.time_delta*2.0f );
43
44 if( gui.factive > 0.01f ){
45 /* draw bottom bar */
46 glEnable(GL_BLEND);
47 glDisable(GL_DEPTH_TEST);
48 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
49 glBlendEquation(GL_FUNC_ADD);
50
51 shader_blitcolour_use();
52 shader_blitcolour_uColour( (v4f){ 0.0f, 0.0f, 0.0f, gui.factive*0.8f } );
53 render_fsquad1();
54 }
55
56 font3d_bind( &gui.font, &ortho );
57
58 float dy = ft/0.79f,
59 scale = dy*0x1p-4f*0.75f;
60
61 m4x3f mmdl;
62 v4f q;
63 m3x3_identity( mmdl );
64 m3x3_scale( mmdl, (v3f){scale,scale,scale} );
65 v3_zero( mmdl[3] );
66
67 float pad = dy*0x1p-4f*0.125f;
68 mmdl[3][0] = pad*2.0f;
69 mmdl[3][1] = pad;
70
71 for( u32 i=0; i<gui.helper_count; i++ ){
72 struct gui_helper *helper = &gui.helpers[i];
73
74 shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
75
76 struct font3d_render render;
77 font3d_begin( &gui.font, 2, &ortho, mmdl, &render );
78
79 render.u8pch = (u8*)helper->bindstr;
80 font3d_draw( &render );
81
82 const char *make_smaller = "\x02\xaf\x03 ";
83 render.u8pch = (const u8*)make_smaller;
84 font3d_draw( &render );
85
86 render.u8pch = (u8*)helper->text;
87 font3d_draw( &render );
88
89 float w = render.offset[0]+1.0f;
90 mmdl[3][0] += w*scale;
91 }
92
93 gui.helper_count = 0;
94 }
95
96 VG_STATIC
97 void gui_helper_action( const char *bindstr, const char *text )
98 {
99 if( gui.helper_count >= vg_list_size(gui.helpers) )
100 vg_fatal_error( "Too many helpers\n" );
101
102 struct gui_helper *helper = &gui.helpers[ gui.helper_count ++ ];
103 helper->bindstr = bindstr;
104 helper->text = text;
105 }
106
107 VG_STATIC void gui_init(void)
108 {
109 font3d_load( &gui.font, "models/rs_font.mdl", vg_mem.rtmemory );
110 }
111
112 #endif /* GUI_H */