colourpicker api
authorhgn <hgodden00@gmail.com>
Wed, 19 Mar 2025 03:18:27 +0000 (03:18 +0000)
committerhgn <hgodden00@gmail.com>
Wed, 19 Mar 2025 03:18:27 +0000 (03:18 +0000)
vg_framebuffer.c
vg_framebuffer.h
vg_ui/imgui.c
vg_ui/imgui.h

index 253c3a59599b7bb55c305a28b37712bcdaf37bf1..d227c7c68e880d9c69f0646dd8813929bcdc5198 100644 (file)
@@ -227,8 +227,7 @@ static void vg_framebuffer_allocate_texture( vg_framebuffer *fb,
    }
 }
 
-vg_framebuffer *vg_framebuffer_allocate( void *alloc,
-                                         u32 attachment_count, bool track )
+vg_framebuffer *vg_framebuffer_allocate( void *alloc, u32 attachment_count, bool track )
 {
    vg_framebuffer *fb = vg_linear_alloc( alloc, sizeof(vg_framebuffer) );
 
@@ -244,8 +243,7 @@ vg_framebuffer *vg_framebuffer_allocate( void *alloc,
       }
    }
 
-   fb->attachments = vg_linear_alloc( alloc, 
-                     sizeof(vg_framebuffer_attachment) * attachment_count );
+   fb->attachments = vg_linear_alloc( alloc, sizeof(vg_framebuffer_attachment) * attachment_count );
    fb->attachment_count = attachment_count;
 
    return fb;
index 90500e02d5b3e47393e7a0e72e8a9858c1144f81..8bf177dada7212f0ddbf73d7dd604191e5185501 100644 (file)
@@ -87,8 +87,7 @@ void vg_framebuffer_bind_texture( vg_framebuffer *fb, int attachment, int slot )
  * Allocation of a framebuffer memory. Optionally, track this framebuffer in 
  * debugging systems.
  */
-vg_framebuffer *vg_framebuffer_allocate( void *alloc, 
-                                         u32 attachment_count, bool track );
+vg_framebuffer *vg_framebuffer_allocate( void *alloc, u32 attachment_count, bool track );
 
 /*
  * Allocate graphics memory and initialize 
index ab0915b9910a0637dcd502508e80145f3be8a0b2..bddbbcde6a7a39f765b45d1a6a92753bccdd84fb 100644 (file)
@@ -1067,8 +1067,7 @@ bool ui_slider( ui_context *ctx, ui_rect inout_panel, const char *str_label,
  * -----------------------------------------------------------------------------
  */
 
-void ui_colourpicker( ui_context *ctx,
-                      ui_rect inout_panel, const char *str_label, v4f value )
+bool ui_colourpicker( ui_context *ctx, ui_rect inout_panel, const char *str_label, v4f value, enum ui_colour_type type )
 {
    ui_rect widget, left, right;
    ui_standard_widget( ctx, inout_panel, widget, 8 );
@@ -1087,11 +1086,15 @@ void ui_colourpicker( ui_context *ctx,
 
    for( u32 i=0; i<4; i ++ )
    {
-      modified |= ui_slider_standard( ctx, sliders[i], 0.0f, 1.0f, hsv+i,
-                     (const char *[]){ "hue %.2f",
-                                       "sat %.2f",
-                                       "lum %.2f",
-                                       "alpha %.2f" }[i] );
+      const char *labels[] = { "hue %.2f", "sat %.2f", "lum %.2f", "alpha %.2f" };
+
+      if( (i == 3) && (type == k_ui_colour_type_rgb) )
+      {
+         ui_fill( ctx, sliders[i], ui_colour( ctx, k_ui_bg ) );
+         ui_text( ctx, sliders[i], "alpha 1.0", 1, k_ui_align_middle_center, ui_colour( ctx, k_ui_bg+3 ) );
+      }
+      else
+         modified |= ui_slider_standard( ctx, sliders[i], 0.0f, 1.0f, hsv+i, labels[i] );
    }
 
    ui_rect preview, square;
@@ -1117,15 +1120,13 @@ void ui_colourpicker( ui_context *ctx,
       hsv[2] = 1.0f-hsv[2];
    }
 
-   if( modified & (k_ui_button_click|k_ui_button_holding_inside|
-                   k_ui_button_holding_outside) )
+   if( modified & (k_ui_button_click|k_ui_button_holding_inside|k_ui_button_holding_outside) )
    {
       vg_hsv_rgb( hsv, value );
       value[3] = hsv[3];
    }
 
-   ui_outline( ctx, square, 
-               1, ui_colour(ctx, state? k_ui_fg+3: k_ui_bg+3 ), 0 );
+   ui_outline( ctx, square, 1, ui_colour(ctx, state? k_ui_fg+3: k_ui_bg+3 ), 0 );
 
    /* preview colour */
    v4f colour;
@@ -1153,6 +1154,8 @@ void ui_colourpicker( ui_context *ctx,
    ui_fill( ctx, marker, ui_colour(ctx, k_ui_fg ) );
    ui_fill( ctx, lx, ui_colour(ctx, k_ui_fg ) );
    ui_fill( ctx, ly, ui_colour(ctx, k_ui_fg ) );
+
+   return modified? 1: 0;
 }
 
 /*
index 8279b9ba07ead219749aaa5e5564f98a92cdca10..1f405539769ff2b1c62eb093be30180e4ab9b87e 100644 (file)
@@ -300,8 +300,7 @@ u32 ui_opacity( u32 colour, f32 opacity );
 
 /* standard widgets & controls */
 ui_px ui_standard_widget_height( ui_context *ctx, ui_px count );
-void ui_standard_widget( ui_context *ctx, 
-                         ui_rect inout_panel, ui_rect out_rect, ui_px count );
+void ui_standard_widget( ui_context *ctx, ui_rect inout_panel, ui_rect out_rect, ui_px count );
 void ui_panel( ui_context *ctx, ui_rect in_rect, ui_rect out_panel );
 void ui_label( ui_context *ctx,
                ui_rect rect, const char *text, ui_px size,
@@ -324,27 +323,25 @@ enum ui_button_state ui_colourbutton_text(
 enum ui_button_state ui_button_text( ui_context *ctx, ui_rect rect, const char *string, ui_px scale );
 enum ui_button_state ui_button( ui_context *ctx, ui_rect inout_panel, const char *string );
 void ui_postrender( ui_context *ctx, f32 delta_time );
-enum ui_button_state ui_checkbox_base( ui_context *ctx, 
-                                       ui_rect box, i32 *data );
-int ui_checkbox( ui_context *ctx, 
-                 ui_rect inout_panel, const char *str_label, i32 *data );
+enum ui_button_state ui_checkbox_base( ui_context *ctx, ui_rect box, i32 *data );
+int ui_checkbox( ui_context *ctx, ui_rect inout_panel, const char *str_label, i32 *data );
 void ui_enum( ui_context *ctx, ui_rect inout_panel, const char *str_label, 
               struct ui_enum_opt *options, u32 len, i32 *value );
 
-enum ui_button_state ui_slider_base( 
-      ui_context *ctx,
-      ui_rect box, enum ui_axis axis, f32 min, f32 max, f32 *value, f32 *out_t );
-void ui_slider_text( ui_context *ctx,
-                     ui_rect box, const char *format, f32 value );
-bool ui_slider_standard( ui_context *ctx,
-                         ui_rect box, f32 min, f32 max, f32 *value,
-                         const char *format );
-bool ui_slider( ui_context *ctx, ui_rect inout_panel, const char *str_label, 
-                f32 min, f32 max, f32 *value );
-void ui_colourpicker( ui_context *ctx,
-                      ui_rect inout_panel, const char *str_label, v4f value );
-void _ui_textbox_move_cursor( ui_context *ctx, int *cursor0, int *cursor1, 
-                              int dir, int snap_together );
+enum ui_button_state ui_slider_base( ui_context *ctx,
+                                     ui_rect box, enum ui_axis axis, f32 min, f32 max, f32 *value, f32 *out_t );
+void ui_slider_text( ui_context *ctx, ui_rect box, const char *format, f32 value );
+bool ui_slider_standard( ui_context *ctx, ui_rect box, f32 min, f32 max, f32 *value, const char *format );
+bool ui_slider( ui_context *ctx, ui_rect inout_panel, const char *str_label, f32 min, f32 max, f32 *value );
+
+enum ui_colour_type
+{
+   k_ui_colour_type_rgba,
+   k_ui_colour_type_rgb
+};
+
+bool ui_colourpicker( ui_context *ctx, ui_rect inout_panel, const char *str_label, v4f value, enum ui_colour_type type );
+void _ui_textbox_move_cursor( ui_context *ctx, int *cursor0, int *cursor1, int dir, int snap_together );
 int _ui_textbox_delete_char( ui_context *ctx, int direction );
 void ui_start_modal( ui_context *ctx, const char *message, u32 options );