#include "camera.h"
#include "shaders/model_font.h"
+
+enum efont_SRglyph{
+ k_SRglyph_end = 0, /* control characters */
+ k_SRglyph_ctrl_variant = 1,
+ k_SRglyph_mod_circle = 0x1e, /* surround and center next charater */
+ k_SRglyph_mod_square = 0x1f, /* surround and center next character */
+ k_SRglyph_ascii_min = 0x20, /* standard ascii */
+ k_SRglyph_ascii_max = 0x7e,
+ k_SRglyph_ps4_square = 0x7f,/* playstation buttons */
+ k_SRglyph_ps4_triangle = 0x80,
+ k_SRglyph_ps4_circle = 0x81,
+ k_SRglyph_ps4_cross = 0x82,
+ k_SRglyph_xb1_x = 0x83,/* xbox buttons */
+ k_SRglyph_xb1_y = 0x84,
+ k_SRglyph_xb1_b = 0x85,
+ k_SRglyph_xb1_a = 0x86,
+ k_SRglyph_gen_ls = 0x87,/* generic gamepad */
+ k_SRglyph_gen_lsh = 0x88,
+ k_SRglyph_gen_lsv = 0x89,
+ k_SRglyph_gen_lshv = 0x8a,
+ k_SRglyph_gen_rs = 0x8b,
+ k_SRglyph_gen_rsh = 0x8c,
+ k_SRglyph_gen_rsv = 0x8d,
+ k_SRglyph_gen_rshv = 0x8e,
+ k_SRglyph_gen_lt = 0x8f,
+ k_SRglyph_gen_rt = 0x90,
+ k_SRglyph_gen_lb = 0x91,
+ k_SRglyph_gen_rb = 0x92,
+ k_SRglyph_gen_left = 0x93,
+ k_SRglyph_gen_up = 0x94,
+ k_SRglyph_gen_right = 0x95,
+ k_SRglyph_gen_down = 0x96,
+ k_SRglyph_gen_options = 0x97,
+ k_SRglyph_gen_shareview = 0x98,
+ k_SRglyph_kbm_m0 = 0x99,/* mouse */
+ k_SRglyph_kbm_m1 = 0x9a,
+ k_SRglyph_kbm_m01 = 0x9b,
+ k_SRglyph_kbm_m2 = 0x9c,
+ k_SRglyph_kbm_m2s = 0x9d,
+ k_SRglyph_kbm_shift = 0x9e,/* modifiers */
+ k_SRglyph_kbm_ctrl = 0x9f,
+ k_SRglyph_kbm_alt = 0xa0,
+ k_SRglyph_kbm_space = 0xa1
+};
+
typedef struct font3d font3d;
struct font3d{
mdl_context mdl;
}
VG_STATIC
-void font3d_simple_draw( font3d *font, u32 variant_id, const char *text,
+float font3d_simple_draw( font3d *font, u32 variant_id, const char *text,
camera *cam, m4x3f transform )
{
v3f offset;
shader_model_font_uPvmPrev( prev_mtx );
shader_model_font_uMdl( transform );
+ const u8 *u8str = (u8*)text;
+
for( int i=0;; i++ ){
- u32 c = text[i];
+ u32 c = u8str[i];
if(!c) break;
+ if( c == k_SRglyph_ctrl_variant ){
+ variant_id = u8str[i+1];
+ continue;
+ }
+
ent_glyph *glyph = font3d_glyph( font, variant_id, c );
if( !glyph ) continue;
if( glyph->indice_count ){
- shader_model_font_uOffset( offset );
- mesh_drawn( glyph->indice_start, glyph->indice_count );
+ if( c == k_SRglyph_mod_square || c == k_SRglyph_mod_circle ){
+ u32 c1 = u8str[i+1];
+ if( c1 == '\0' ) break;
+
+ ent_glyph *glyph1 = font3d_glyph( font, variant_id, c1 );
+
+ if( glyph1 ){
+ if( glyph1->indice_count ){
+ v3f v0;
+ v2_sub( glyph->size, glyph1->size, v0 );
+ v2_muladds( offset, v0, -0.5f, v0 );
+ v0[2] = 0.0f;
+
+ shader_model_font_uOffset( v0 );
+ mesh_drawn( glyph->indice_start, glyph->indice_count );
+
+ shader_model_font_uOffset( offset );
+ mesh_drawn( glyph1->indice_start, glyph1->indice_count );
+ offset[0] += glyph1->size[0];
+ }
+ }
+
+ i ++;
+ continue;
+ }
+ else{
+ shader_model_font_uOffset( offset );
+ mesh_drawn( glyph->indice_start, glyph->indice_count );
+ }
}
offset[0] += glyph->size[0];
}
+
+ return offset[0];
}
VG_STATIC
#include "font.h"
-VG_STATIC void gui_example( void )
+struct{
+ struct gui_helper{
+ struct input_binding *bind;
+ const char *text;
+ }
+ helpers[4];
+ u32 helper_count;
+}
+static gui;
+
+VG_STATIC
+void gui_draw(void)
+{
+ camera ortho;
+
+ float fl = 0.0f,
+ fr = vg.window_x,
+ fb = 0.0f,
+ ft = vg.window_y,
+ rl = 1.0f / (fr-fl),
+ tb = 1.0f / (ft-fb);
+
+ m4x4_zero( ortho.mtx.p );
+ ortho.mtx.p[0][0] = 2.0f * rl;
+ ortho.mtx.p[1][1] = 2.0f * tb;
+ ortho.mtx.p[3][0] = (fr + fl) * -rl;
+ ortho.mtx.p[3][1] = (ft + fb) * -tb;
+ ortho.mtx.p[3][3] = 1.0f;
+ m4x3_identity( ortho.transform );
+ camera_update_view( &ortho );
+ camera_finalize( &ortho );
+
+ if( gui.helper_count ){
+ /* draw bottom bar */
+ glEnable(GL_BLEND);
+ glDisable(GL_DEPTH_TEST);
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+ glBlendEquation(GL_FUNC_ADD);
+
+ shader_blitcolour_use();
+ shader_blitcolour_uColour( (v4f){ 0.0f, 0.0f, 0.0f, 0.8f } );
+ render_fsquad1();
+ }
+ glDisable(GL_BLEND);
+
+ font3d *font = &world_global.font;
+ font3d_bind( font, &ortho );
+
+ float dy = ft/0.79f,
+ scale = dy*0x1p-4f*0.75f;
+
+ m4x3f mmdl;
+ v4f q;
+ m3x3_identity( mmdl );
+ m3x3_scale( mmdl, (v3f){scale,scale,scale} );
+ v3_zero( mmdl[3] );
+
+ float pad = dy*0x1p-4f*0.125f;
+ mmdl[3][0] = pad;
+ mmdl[3][1] = pad;
+
+ for( u32 i=0; i<gui.helper_count; i++ ){
+ struct gui_helper *helper = &gui.helpers[i];
+
+ shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
+
+ float w = font3d_simple_draw( font, 1, helper->text, &ortho, mmdl )+0.2f;
+ mmdl[3][0] += w*scale;
+ }
+
+ gui.helper_count = 0;
+}
+
+VG_STATIC
+void gui_helper_action( struct input_binding *bind, const char *text )
{
-
+ if( gui.helper_count >= vg_list_size(gui.helpers) )
+ vg_fatal_error( "Too many helpers\n" );
+
+ struct gui_helper *helper = &gui.helpers[ gui.helper_count ++ ];
+ helper->bind = bind;
+ helper->text = text;
}
#endif /* GUI_H */
}
float quad[] = {
- 0.00f,0.00f, 1.00f,1.00f, 0.00f,1.00f,
- 0.00f,0.00f, 1.00f,0.00f, 1.00f,1.00f,
+ 0.00f,0.00f, 1.00f,1.00f, 0.00f,1.00f, /* fsquad */
+ 0.00f,0.00f, 1.00f,0.00f, 1.00f,1.00f,
- 0.20f,0.00f, 0.80f,1.00f, 0.20f,1.00f,
- 0.20f,0.00f, 0.80f,0.00f, 0.80f,1.00f,
+ 0.00f,0.00f, 1.00f,0x1p-4f,0.00f,0x1p-4f, /* fsquad1 */
+ 0.00f,0.00f, 1.00f,0.00f, 1.00f,0x1p-4f,
/* 9x9 debug grid */
/* row0 */