// ===========================================================================================================
// Opengl
-GLuint ui_glyph_texture;
+int ui_glyph_override = 0;
+ui_px ui_glyph_spacing_x = 6;
+GLuint ui_glyph_texture = 0;
GLuint ui_vao;
GLuint ui_vbo;
GLuint ui_ebo;
// Initialization
// ===========================================================================================================
+static void ui_override_font( GLuint new_tex, ui_px space_x )
+{
+ if( ui_glyph_texture )
+ glDeleteTextures( 1, &ui_glyph_texture );
+
+ ui_glyph_texture = new_tex;
+ ui_glyph_override = 1;
+ ui_glyph_spacing_x = space_x;
+}
+
static void ui_default_init(void)
{
- // Load font
+ // Load default font
+ if( !ui_glyph_override )
{
u32 compressed[] = {
#include "fonts/weiholmir.h"
static void ui_default_free(void)
{
- glDeleteTextures( 1, &ui_glyph_texture );
+ if( !ui_glyph_override )
+ glDeleteTextures( 1, &ui_glyph_texture );
glDeleteVertexArrays( 1, &ui_vao );
glDeleteBuffers( 1, &ui_vbo );
static struct ui_vert *ui_fill_rect( ui_ctx *ctx, ui_rect rect, u32 colour )
{
- return ui_fill_rect_uv( ctx, rect, colour, (ui_px[4]){ 66, 66, 66, 66 } );
+ return ui_fill_rect_uv( ctx, rect, colour, (ui_px[4]){ 66, 72-66, 66, 72-66 } );
}
static void ui_text( ui_ctx *ctx, const char *str, ui_px scale, int alignment )
glyph_base[0] *= 7;
glyph_base[1] *= 7;
- ui_fill_rect_uv( ctx, text_cursor, current_colour, (ui_px[4]){glyph_base[0],glyph_base[1],glyph_base[0]+7,glyph_base[1]+7} );
+ ui_fill_rect_uv( ctx, text_cursor, current_colour, (ui_px[4]){glyph_base[0],72-glyph_base[1],glyph_base[0]+7,72-(glyph_base[1]+7)} );
}
else if( c == '\x1B' )
{
}
}
- text_cursor[0] += 6*scale;
+ text_cursor[0] += ui_glyph_spacing_x*scale;
}
}
{
ui_capture_mouse( ctx, __COUNTER__ );
- //ui_fill_rect( ctx, ctx->cursor, 0xff333333 );
-
// Drag bar
ctx->cursor[3] = 25;
ui_new_node( ctx );
return 1;
}
-
-static void ui_test(void)
-{
- /*
- +------------------------------------------------------+
- | Central Market [x]|
- +------+--------------+-+------------------------------+
- | Buy | Balance |#| [filters] [favorites] |
- | <>_ | () 2,356 |#|----------------------------+-+
- |------|--------------|#| [] potion of madness 4 |#|
- | Sell | \ Main sword |#|----------------------------|#|
- | _*^ |--------------|#| [] Balance of time 23 | |
- |------| * Side arm |#|----------------------------| |
- | 235 |--------------| | [] Strength 5,300 | |
- | | () Sheild | |----------------------------| |
- | |--------------| | [] Bewilder 2,126 | |
- | [ & Spells ] |----------------------------| |
- | |--------------| | [] Eternal flames 6 | |
- +------+--------------+-+----------------------------+-+
- */
-
- ui_begin( &ui_global_ctx, vg_window_x, vg_window_y );
-
- // TODO: Find a more elegent form for this
- int mouse_state = 0;
- if( vg_get_button( "primary" ) ) mouse_state = 2;
- if( vg_get_button_down( "primary" ) ) mouse_state = 1;
- if( vg_get_button_up( "primary" ) ) mouse_state = 3;
-
- ui_set_mouse( &ui_global_ctx, vg_mouse[0], vg_mouse[1], mouse_state );
-
- /*
- static struct ui_window window =
- {
- .transform = { 20, 20, 500, 350 },
- .title = "Central Market"
- };
-
- if( ui_window( &ui_global_ctx, &window, __COUNTER__ ) )
- {
- // Contents
- //ui_text( &ui_global_ctx, "A slice of heaven. O for awesome, this chocka \nfull cuzzie is as rip-off as a cracker.\nMeanwhile, in behind the bicycle shed, Hercules Morse,\nas big as a horse and Mrs Falani were up to no \ngood with a bunch of crook pikelets. Meanwhile, \nat the black singlet woolshed party, not even au,\nsort your drinking out.", 1, 0 );
- ui_global_ctx.cursor[2] = 75;
- ui_fill_y( &ui_global_ctx );
-
- ui_new_node( &ui_global_ctx );
- {
- ui_global_ctx.cursor[3] = 75;
-
- if( ui_button( &ui_global_ctx, __COUNTER__ ) )
- vg_info( "Buy\n" );
- {
- ui_rect_pad( ui_global_ctx.cursor, 4 );
- ui_text( &ui_global_ctx, "Buy", 2, 0 );
- }
- ui_end_down( &ui_global_ctx );
-
- if( ui_button( &ui_global_ctx, __COUNTER__ ) )
- vg_info( "Sell\n" );
- {
- ui_rect_pad( ui_global_ctx.cursor, 4 );
- ui_text( &ui_global_ctx, "Sell", 2, 0 );
- }
- ui_end_down( &ui_global_ctx );
- }
- ui_end_right( &ui_global_ctx );
-
- ui_global_ctx.cursor[2] = 200;
- ui_new_node( &ui_global_ctx );
- {
-
- }
- ui_end_right( &ui_global_ctx );
- }
- ui_end( &ui_global_ctx );
- */
-
- ui_rect rbf;
- ui_rect_copy( ui_global_ctx.cursor, rbf );
-
- ui_global_ctx.cursor[0] = 6;
- ui_global_ctx.cursor[3] = 21;
- ui_fill_x( &ui_global_ctx );
- ui_align_bottom( &ui_global_ctx );
- ui_text( &ui_global_ctx, "Marble computer build 2 -- development version -- (C) Harry Godden 2021\nAknowledgements: 'credits' in console (`)", 1, 0 );
-
- ui_resolve( &ui_global_ctx );
-
- m3x3f view = M3X3_IDENTITY;
- m3x3_translate( view, (v3f){ -1.0f, 1.0f, 0.0f } );
- m3x3_scale( view, (v3f){ 1.0f/((float)vg_window_x*0.5f), -1.0f/((float)vg_window_y*0.5f), 1.0f } );
- //vg_lines_drawall( (float*)view );
-
- ui_draw( &ui_global_ctx );
-
- ui_rect_copy( rbf, ui_global_ctx.cursor );
-}