summaryrefslogtreecommitdiff
path: root/src/gui/colorinput.cpp
blob: 1d649fbf9061eadc19ff5b983ae8800e74b6feca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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;
}