font works
[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 struct input_binding *bind;
9 const char *text;
10 }
11 helpers[4];
12 u32 helper_count;
13 }
14 static gui;
15
16 VG_STATIC
17 void gui_draw(void)
18 {
19 camera ortho;
20
21 float fl = 0.0f,
22 fr = vg.window_x,
23 fb = 0.0f,
24 ft = vg.window_y,
25 rl = 1.0f / (fr-fl),
26 tb = 1.0f / (ft-fb);
27
28 m4x4_zero( ortho.mtx.p );
29 ortho.mtx.p[0][0] = 2.0f * rl;
30 ortho.mtx.p[1][1] = 2.0f * tb;
31 ortho.mtx.p[3][0] = (fr + fl) * -rl;
32 ortho.mtx.p[3][1] = (ft + fb) * -tb;
33 ortho.mtx.p[3][3] = 1.0f;
34 m4x3_identity( ortho.transform );
35 camera_update_view( &ortho );
36 camera_finalize( &ortho );
37
38 if( gui.helper_count ){
39 /* draw bottom bar */
40 glEnable(GL_BLEND);
41 glDisable(GL_DEPTH_TEST);
42 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
43 glBlendEquation(GL_FUNC_ADD);
44
45 shader_blitcolour_use();
46 shader_blitcolour_uColour( (v4f){ 0.0f, 0.0f, 0.0f, 0.8f } );
47 render_fsquad1();
48 }
49 glDisable(GL_BLEND);
50
51 font3d *font = &world_global.font;
52 font3d_bind( font, &ortho );
53
54 float dy = ft/0.79f,
55 scale = dy*0x1p-4f*0.75f;
56
57 m4x3f mmdl;
58 v4f q;
59 m3x3_identity( mmdl );
60 m3x3_scale( mmdl, (v3f){scale,scale,scale} );
61 v3_zero( mmdl[3] );
62
63 float pad = dy*0x1p-4f*0.125f;
64 mmdl[3][0] = pad;
65 mmdl[3][1] = pad;
66
67 for( u32 i=0; i<gui.helper_count; i++ ){
68 struct gui_helper *helper = &gui.helpers[i];
69
70 shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
71
72 float w = font3d_simple_draw( font, 1, helper->text, &ortho, mmdl )+0.2f;
73 mmdl[3][0] += w*scale;
74 }
75
76 gui.helper_count = 0;
77 }
78
79 VG_STATIC
80 void gui_helper_action( struct input_binding *bind, const char *text )
81 {
82 if( gui.helper_count >= vg_list_size(gui.helpers) )
83 vg_fatal_error( "Too many helpers\n" );
84
85 struct gui_helper *helper = &gui.helpers[ gui.helper_count ++ ];
86 helper->bind = bind;
87 helper->text = text;
88 }
89
90 #endif /* GUI_H */