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