small compression
[carveJwlIkooP6JGAAIwe30JlM.git] / gui.h
diff --git a/gui.h b/gui.h
index 18b3dbd5eac91d28b4cd5e8cbf36ecab56710571..7c2dbb6e5f34e5ee0c795338a18650744881c9a8 100644 (file)
--- a/gui.h
+++ b/gui.h
@@ -11,6 +11,8 @@ enum gui_icon {
    k_gui_icon_board,
    k_gui_icon_world,
    k_gui_icon_rift,
+   k_gui_icon_rift_run,
+   k_gui_icon_friend,
 
    k_gui_icon_count,
 };
@@ -25,9 +27,13 @@ struct{
    struct icon_call {
       enum gui_icon icon;
       v4f location;
+      v4f colour;
+      int colour_changed;
    }
    icon_draw_buffer[32];
    u32 icon_draw_count;
+   v4f cur_icon_colour;
+   int colour_changed;
 
    char location[64];
    f64  location_time;
@@ -52,7 +58,7 @@ struct{
 
    mdl_submesh *icons[ k_gui_icon_count ];
 }
-static gui;
+static gui = {.cur_icon_colour = {1.0f,1.0f,1.0f,1.0f},.colour_changed=1};
 
 static 
 void gui_helper_action( const char *bindstr, const char *text ){
@@ -66,9 +72,7 @@ void gui_helper_action( const char *bindstr, const char *text ){
    helper->text = text;
 }
 
-static
-void gui_draw(void)
-{
+static void gui_draw(void){
    if( v3_dist2(localplayer.rb.co,gui.trick_co) > 2.0f ){
       gui.trick_type = k_guitrick_type_none;
    }
@@ -113,23 +117,24 @@ void gui_draw(void)
    camera_finalize( &ortho );
 
 
-
-
-
    /* icons */
-   font3d_bind( &gui.font, &ortho );
+   font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &ortho );
+   mesh_bind( &gui.icons_mesh );
+
    m4x3f mmdl;
    m4x3_identity( mmdl );
    shader_model_font_uMdl( mmdl );
 
-   mesh_bind( &gui.icons_mesh );
-   shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
    glActiveTexture( GL_TEXTURE0 );
    glBindTexture( GL_TEXTURE_2D, gui.icons_texture );
    shader_model_font_uTexMain( 0 );
 
    for( u32 i=0; i<gui.icon_draw_count; i++ ){
       struct icon_call *call = &gui.icon_draw_buffer[i];
+
+      if( call->colour_changed )
+         shader_model_font_uColour( call->colour );
+
       shader_model_font_uOffset( call->location );
 
       mdl_submesh *sm = gui.icons[ call->icon ];
@@ -141,8 +146,6 @@ void gui_draw(void)
 
 
 
-
-
    gui.factive = vg_lerpf( gui.factive, gui.helper_count?1.0f:0.0f,
                            vg.time_frame_delta*2.0f );
 
@@ -181,18 +184,17 @@ void gui_draw(void)
       v3_zero( mmdl[3] );
 
       f32 pad = dy*0x1p-4f*0.125f;
-      f32 w = font3d_string_width( &gui.font,2,gui.location );
+      f32 w = font3d_string_width( 2, gui.location );
 
       mmdl[3][0] = fr*0.5f - w*scale*0.5f;
       mmdl[3][1] = 0.3f*ft+pad*2.0f;
 
-      font3d_bind( &gui.font, &ortho );
+      font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &ortho );
       shader_model_font_uColour( (v4f){1.2f,1.2f,1.2f,o} );
-      font3d_simple_draw( &gui.font, 2, k_font_shader_default,
-                           gui.location, &ortho, mmdl );
+      font3d_simple_draw( 2, gui.location, &ortho, mmdl );
    }
-
-   font3d_bind( &gui.font, &ortho );
+   else
+      font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &ortho );
 
    float dy    = ft/0.79f,
          scale = dy*0x1p-4f*0.75f;
@@ -208,32 +210,21 @@ void gui_draw(void)
    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} );
-
-      struct font3d_render render = {
-         .font = &gui.font,
-         .variant_id = 2,
-         .shader = k_font_shader_default
-      };
-      font3d_begin( helper->bindstr, &ortho, mmdl, &render );
-      font3d_draw( &render );
+      font3d_setcolour( (v4f){1.0f,1.0f,1.0f,1.0f} );
+      font3d_simple_draw( 2, helper->bindstr, &ortho, mmdl );
 
       const char *make_smaller = "\x02\xaf\x03 ";
-      render.u8pch = (const u8*)make_smaller;
-      font3d_draw( &render );
-
-      render.u8pch = (u8*)helper->text;
-      font3d_draw( &render );
+      font3d_draw( make_smaller );
+      font3d_draw( helper->text );
       
-      float w = render.offset[0]+1.0f;
+      float w = gui_font3d.offset[0]+1.0f;
       mmdl[3][0] += w*scale;
    }
 
    gui.helper_count = 0;
 }
 
-static
-int gui_location_print_ccmd( int argc, const char *argv[] ){
+static int gui_location_print_ccmd( int argc, const char *argv[] ){
    if( argc > 0 ){
       char new_loc[64];
       vg_str str;
@@ -276,6 +267,15 @@ static void gui_draw_icon( enum gui_icon icon, v2f co, f32 size ){
    call->location[1] = co[1] * (f32)vg.window_y;
    call->location[2] = 0.0f;
    call->location[3] = size * (f32)vg.window_x;
+
+   v4_copy( gui.cur_icon_colour, call->colour );
+   call->colour_changed = gui.colour_changed;
+   gui.colour_changed = 0;
+}
+
+static void gui_icon_setcolour( v4f colour ){
+   gui.colour_changed = 1;
+   v4_copy( colour, gui.cur_icon_colour );
 }
 
 static mdl_submesh *gui_find_icon( const char *name ){
@@ -304,6 +304,8 @@ static void gui_init(void){
    gui.icons[ k_gui_icon_board ] = gui_find_icon( "icon_board" );
    gui.icons[ k_gui_icon_world ] = gui_find_icon( "icon_world" );
    gui.icons[ k_gui_icon_rift ] = gui_find_icon( "icon_rift" );
+   gui.icons[ k_gui_icon_rift_run ] = gui_find_icon( "icon_rift_run" );
+   gui.icons[ k_gui_icon_friend ] = gui_find_icon( "icon_friend" );
 
    vg_linear_clear( vg_mem.scratch );
    if( !mdl_arrcount( &gui.model_icons.textures ) )