diff options
Diffstat (limited to 'src/gui/colorinput.cpp')
| -rw-r--r-- | src/gui/colorinput.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/gui/colorinput.cpp b/src/gui/colorinput.cpp new file mode 100644 index 0000000..1d649fb --- /dev/null +++ b/src/gui/colorinput.cpp @@ -0,0 +1,59 @@ +#include "base.h" +#include <stdio.h> + +void gui_colorinput_draw_fn( void* ptr ) { + GUI_COLORINPUT* input = (GUI_COLORINPUT*)ptr; + + I32 x = gui_relx( input ); + I32 y = gui_rely( input ); + + gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, input->name ); + + CLR val = *(CLR*)input->pval; + char hex[16]; + sprintf( hex, "#%02x%02x%02x", + (I32)(val.r * 255.f), + (I32)(val.g * 255.f), + (I32)(val.b * 255.f) + ); + + gui_draw_str( x + input->w, y, ALIGN_R, FNT_JPN12, ui_clr.txt, hex ); + + CLR border = { + 1.f - val.r, + 1.f - val.g, + 1.f - val.b, + 1.f + }; + + gui_draw_frect( x + input->w - 21, y + 14, 22, 22, border ); + gui_draw_frect( x + input->w - 19, y + 16, 18, 18, CLR::BLACK() ); + gui_draw_frect( x + input->w - 19, y + 16, 18, 18, *(CLR*)(input->pval) ); + + GUI_VIEW* inputview = input->inputview; + inputview->draw_fn( inputview ); +} + +GUI_COLORINPUT* gui_colorinput( I32 x, I32 y, I32 w, const char* title, CLR* pval, U8 showalpha ) { + if( !gui_check_target() ) return 0; + + GUI_COLORINPUT* input = new GUI_COLORINPUT; + + __gui_internal_vectorinput_init( + input, + x, y, + w - 26, + title, + (F32*)pval, + showalpha? 4 : 3, + 0.f, + 1.f, + 1.f / 255.f, + "rgba", + "%.02f" + ); + + input->xbound = input->w = w; + input->draw_fn = gui_colorinput_draw_fn; + return input; +} |
