better color picker

isolation_bkp/dynres
Dominik Madarász 2021-05-15 17:48:15 +02:00
parent 0fdc718e44
commit 8623c18127
4 changed files with 833 additions and 914 deletions

Binary file not shown.

View File

@ -1,138 +1,56 @@
#define PARAM(k,n,v) { .kind = k, .name = n, .str = v }
static td_op default_ops[] = { static td_op default_ops[] = {
{ {
OP(TOP_CLEAR), OP(TOP_CLEAR),
.num_params = 1, .num_params = 1,
.params = (td_param[]) { .params = (td_param[]) {
{ PARAM(TPARAM_COLOR, "color", "ffffffff"),
.kind = TPARAM_COLOR,
.name = "color",
.str = "ffffffff"
}
} }
}, },
{ {
OP(TOP_DRAW_RECT), OP(TOP_DRAW_RECT),
.num_params = 5, .num_params = 5,
.params = (td_param[]) { .params = (td_param[]) {
{ PARAM(TPARAM_INT, "x", "0"),
.kind = TPARAM_INT, PARAM(TPARAM_INT, "y", "0"),
.name = "x", PARAM(TPARAM_INT, "w", "10"),
.str = "0" PARAM(TPARAM_INT, "h", "10"),
}, PARAM(TPARAM_COLOR, "color", "0"),
{
.kind = TPARAM_INT,
.name = "y",
.str = "0"
},
{
.kind = TPARAM_INT,
.name = "w",
.str = "10"
},
{
.kind = TPARAM_INT,
.name = "h",
.str = "10"
},
{
.kind = TPARAM_COLOR,
.name = "color",
.str = "ff0000ff"
},
} }
}, },
{ {
OP(TOP_DRAW_LINE), OP(TOP_DRAW_LINE),
.num_params = 5, .num_params = 5,
.params = (td_param[]) { .params = (td_param[]) {
{ PARAM(TPARAM_INT, "x1", "0"),
.kind = TPARAM_INT, PARAM(TPARAM_INT, "y1", "0"),
.name = "x1", PARAM(TPARAM_INT, "x2", "64"),
.str = "0" PARAM(TPARAM_INT, "y2", "64"),
}, PARAM(TPARAM_COLOR, "color", "0"),
{
.kind = TPARAM_INT,
.name = "y1",
.str = "0"
},
{
.kind = TPARAM_INT,
.name = "x2",
.str = "64"
},
{
.kind = TPARAM_INT,
.name = "y2",
.str = "64"
},
{
.kind = TPARAM_COLOR,
.name = "color",
.str = "ffff00ff"
},
} }
}, },
{ {
OP(TOP_DITHER), OP(TOP_DITHER),
.num_params = 4, .num_params = 4,
.params = (td_param[]) { .params = (td_param[]) {
{ PARAM(TPARAM_INT, "r_bpp", "8"),
.kind = TPARAM_INT, PARAM(TPARAM_INT, "g_bpp", "8"),
.name = "r_bpp", PARAM(TPARAM_INT, "b_bpp", "8"),
.str = "8", PARAM(TPARAM_INT, "a_bpp", "8"),
},
{
.kind = TPARAM_INT,
.name = "g_bpp",
.str = "8",
},
{
.kind = TPARAM_INT,
.name = "b_bpp",
.str = "8",
},
{
.kind = TPARAM_INT,
.name = "a_bpp",
.str = "8",
},
} }
}, },
{ {
OP(TOP_LOAD_IMAGE), OP(TOP_LOAD_IMAGE),
.num_params = 6, .num_params = 6,
.params = (td_param[]) { .params = (td_param[]) {
{ PARAM(TPARAM_STRING, "src", "art/natives/test.png"),
.kind = TPARAM_STRING, PARAM(TPARAM_INT, "x", "0"),
.name = "src", PARAM(TPARAM_INT, "y", "0"),
.str = "" PARAM(TPARAM_INT, "w", "-1"),
}, PARAM(TPARAM_INT, "h", "-1"),
{ PARAM(TPARAM_COLOR, "tint", "ffffffff"),
.kind = TPARAM_INT,
.name = "x",
.str = "0"
},
{
.kind = TPARAM_INT,
.name = "y",
.str = "0"
},
{
.kind = TPARAM_INT,
.name = "w",
.str = "-1"
},
{
.kind = TPARAM_INT,
.name = "h",
.str = "-1"
},
{
.kind = TPARAM_COLOR,
.name = "tint",
.str = "ffffffff",
},
} }
} }
}; };

View File

@ -182,13 +182,14 @@ void texed_draw_props_pane(zpl_aabb2 r) {
switch (p->kind) { switch (p->kind) {
case TPARAM_COLOR: { case TPARAM_COLOR: {
if (!p->edit_mode && GuiTextBox(aabb2_ray(tbox_r), p->str, 64, p->edit_mode)) { if (GuiTextBox(aabb2_ray(tbox_r), p->str, 64, p->edit_mode)) {
p->edit_mode = true; p->edit_mode = true;
} }
if (p->edit_mode) { if (p->edit_mode) {
zpl_aabb2 ok_r = zpl_aabb2_cut_left(&tbox_r, 50.0f); zpl_aabb2 extra_r = zpl_aabb2_add_bottom(&tbox_r, prop_height);
p->color = GuiColorPicker(aabb2_ray(tbox_r), p->color); zpl_aabb2 ok_r = zpl_aabb2_cut_left(&extra_r, 50.0f);
p->color = GuiColorPicker(aabb2_ray(extra_r), p->color);
if (GuiButton(aabb2_ray(ok_r), "OK")) { if (GuiButton(aabb2_ray(ok_r), "OK")) {
p->edit_mode = false; p->edit_mode = false;

400
code/vendors/raygui.h vendored
View File

@ -134,36 +134,36 @@
#define RAYGUI_VERSION "2.9-dev" #define RAYGUI_VERSION "2.9-dev"
#if !defined(RAYGUI_STANDALONE) #if !defined(RAYGUI_STANDALONE)
#include "raylib.h" #include "raylib.h"
#endif #endif
// Define functions scope to be used internally (static) or externally (extern) to the module including this file // Define functions scope to be used internally (static) or externally (extern) to the module including this file
#if defined(_WIN32) #if defined(_WIN32)
// Microsoft attibutes to tell compiler that symbols are imported/exported from a .dll // Microsoft attibutes to tell compiler that symbols are imported/exported from a .dll
#if defined(BUILD_LIBTYPE_SHARED) #if defined(BUILD_LIBTYPE_SHARED)
#define RAYGUIDEF __declspec(dllexport) // We are building raygui as a Win32 shared library (.dll) #define RAYGUIDEF __declspec(dllexport) // We are building raygui as a Win32 shared library (.dll)
#elif defined(USE_LIBTYPE_SHARED) #elif defined(USE_LIBTYPE_SHARED)
#define RAYGUIDEF __declspec(dllimport) // We are using raygui as a Win32 shared library (.dll) #define RAYGUIDEF __declspec(dllimport) // We are using raygui as a Win32 shared library (.dll)
#else
#define RAYGUIDEF // We are building or using raygui as a static library
#endif
#else #else
#define RAYGUIDEF // We are building or using raygui as a static library (or Linux shared library) #define RAYGUIDEF // We are building or using raygui as a static library
#endif
#else
#define RAYGUIDEF // We are building or using raygui as a static library (or Linux shared library)
#endif #endif
#if !defined(RAYGUI_MALLOC) && !defined(RAYGUI_CALLOC) && !defined(RAYGUI_FREE) #if !defined(RAYGUI_MALLOC) && !defined(RAYGUI_CALLOC) && !defined(RAYGUI_FREE)
#include <stdlib.h> // Required for: malloc(), calloc(), free() #include <stdlib.h> // Required for: malloc(), calloc(), free()
#endif #endif
// Allow custom memory allocators // Allow custom memory allocators
#ifndef RAYGUI_MALLOC #ifndef RAYGUI_MALLOC
#define RAYGUI_MALLOC(sz) malloc(sz) #define RAYGUI_MALLOC(sz) malloc(sz)
#endif #endif
#ifndef RAYGUI_CALLOC #ifndef RAYGUI_CALLOC
#define RAYGUI_CALLOC(n,sz) calloc(n,sz) #define RAYGUI_CALLOC(n,sz) calloc(n,sz)
#endif #endif
#ifndef RAYGUI_FREE #ifndef RAYGUI_FREE
#define RAYGUI_FREE(p) free(p) #define RAYGUI_FREE(p) free(p)
#endif #endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -179,17 +179,17 @@
extern "C" { // Prevents name mangling of functions extern "C" { // Prevents name mangling of functions
#endif #endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
// NOTE: Some types are required for RAYGUI_STANDALONE usage // NOTE: Some types are required for RAYGUI_STANDALONE usage
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#if defined(RAYGUI_STANDALONE) #if defined(RAYGUI_STANDALONE)
#ifndef __cplusplus #ifndef __cplusplus
// Boolean type // Boolean type
#ifndef true #ifndef true
typedef enum { false, true } bool; typedef enum { false, true } bool;
#endif #endif
#endif #endif
// Vector2 type // Vector2 type
typedef struct Vector2 { typedef struct Vector2 {
@ -244,30 +244,30 @@ extern "C" { // Prevents name mangling of functions
} Font; } Font;
#endif #endif
// Style property // Style property
typedef struct GuiStyleProp { typedef struct GuiStyleProp {
unsigned short controlId; unsigned short controlId;
unsigned short propertyId; unsigned short propertyId;
int propertyValue; int propertyValue;
} GuiStyleProp; } GuiStyleProp;
// Gui control state // Gui control state
typedef enum { typedef enum {
GUI_STATE_NORMAL = 0, GUI_STATE_NORMAL = 0,
GUI_STATE_FOCUSED, GUI_STATE_FOCUSED,
GUI_STATE_PRESSED, GUI_STATE_PRESSED,
GUI_STATE_DISABLED, GUI_STATE_DISABLED,
} GuiControlState; } GuiControlState;
// Gui control text alignment // Gui control text alignment
typedef enum { typedef enum {
GUI_TEXT_ALIGN_LEFT = 0, GUI_TEXT_ALIGN_LEFT = 0,
GUI_TEXT_ALIGN_CENTER, GUI_TEXT_ALIGN_CENTER,
GUI_TEXT_ALIGN_RIGHT, GUI_TEXT_ALIGN_RIGHT,
} GuiTextAlignment; } GuiTextAlignment;
// Gui controls // Gui controls
typedef enum { typedef enum {
DEFAULT = 0, DEFAULT = 0,
LABEL, // LABELBUTTON LABEL, // LABELBUTTON
BUTTON, // IMAGEBUTTON BUTTON, // IMAGEBUTTON
@ -284,10 +284,10 @@ typedef enum {
COLORPICKER, COLORPICKER,
SCROLLBAR, SCROLLBAR,
STATUSBAR STATUSBAR
} GuiControl; } GuiControl;
// Gui base properties for every control // Gui base properties for every control
typedef enum { typedef enum {
BORDER_COLOR_NORMAL = 0, BORDER_COLOR_NORMAL = 0,
BASE_COLOR_NORMAL, BASE_COLOR_NORMAL,
TEXT_COLOR_NORMAL, TEXT_COLOR_NORMAL,
@ -304,195 +304,195 @@ typedef enum {
TEXT_PADDING, TEXT_PADDING,
TEXT_ALIGNMENT, TEXT_ALIGNMENT,
RESERVED RESERVED
} GuiControlProperty; } GuiControlProperty;
// Gui extended properties depend on control // Gui extended properties depend on control
// NOTE: We reserve a fixed size of additional properties per control // NOTE: We reserve a fixed size of additional properties per control
// DEFAULT properties // DEFAULT properties
typedef enum { typedef enum {
TEXT_SIZE = 16, TEXT_SIZE = 16,
TEXT_SPACING, TEXT_SPACING,
LINE_COLOR, LINE_COLOR,
BACKGROUND_COLOR, BACKGROUND_COLOR,
} GuiDefaultProperty; } GuiDefaultProperty;
// Label // Label
//typedef enum { } GuiLabelProperty; //typedef enum { } GuiLabelProperty;
// Button // Button
//typedef enum { } GuiButtonProperty; //typedef enum { } GuiButtonProperty;
// Toggle / ToggleGroup // Toggle / ToggleGroup
typedef enum { typedef enum {
GROUP_PADDING = 16, GROUP_PADDING = 16,
} GuiToggleProperty; } GuiToggleProperty;
// Slider / SliderBar // Slider / SliderBar
typedef enum { typedef enum {
SLIDER_WIDTH = 16, SLIDER_WIDTH = 16,
SLIDER_PADDING SLIDER_PADDING
} GuiSliderProperty; } GuiSliderProperty;
// ProgressBar // ProgressBar
typedef enum { typedef enum {
PROGRESS_PADDING = 16, PROGRESS_PADDING = 16,
} GuiProgressBarProperty; } GuiProgressBarProperty;
// CheckBox // CheckBox
typedef enum { typedef enum {
CHECK_PADDING = 16 CHECK_PADDING = 16
} GuiCheckBoxProperty; } GuiCheckBoxProperty;
// ComboBox // ComboBox
typedef enum { typedef enum {
COMBO_BUTTON_WIDTH = 16, COMBO_BUTTON_WIDTH = 16,
COMBO_BUTTON_PADDING COMBO_BUTTON_PADDING
} GuiComboBoxProperty; } GuiComboBoxProperty;
// DropdownBox // DropdownBox
typedef enum { typedef enum {
ARROW_PADDING = 16, ARROW_PADDING = 16,
DROPDOWN_ITEMS_PADDING DROPDOWN_ITEMS_PADDING
} GuiDropdownBoxProperty; } GuiDropdownBoxProperty;
// TextBox / TextBoxMulti / ValueBox / Spinner // TextBox / TextBoxMulti / ValueBox / Spinner
typedef enum { typedef enum {
TEXT_INNER_PADDING = 16, TEXT_INNER_PADDING = 16,
TEXT_LINES_PADDING, TEXT_LINES_PADDING,
COLOR_SELECTED_FG, COLOR_SELECTED_FG,
COLOR_SELECTED_BG COLOR_SELECTED_BG
} GuiTextBoxProperty; } GuiTextBoxProperty;
// Spinner // Spinner
typedef enum { typedef enum {
SPIN_BUTTON_WIDTH = 16, SPIN_BUTTON_WIDTH = 16,
SPIN_BUTTON_PADDING, SPIN_BUTTON_PADDING,
} GuiSpinnerProperty; } GuiSpinnerProperty;
// ScrollBar // ScrollBar
typedef enum { typedef enum {
ARROWS_SIZE = 16, ARROWS_SIZE = 16,
ARROWS_VISIBLE, ARROWS_VISIBLE,
SCROLL_SLIDER_PADDING, SCROLL_SLIDER_PADDING,
SCROLL_SLIDER_SIZE, SCROLL_SLIDER_SIZE,
SCROLL_PADDING, SCROLL_PADDING,
SCROLL_SPEED, SCROLL_SPEED,
} GuiScrollBarProperty; } GuiScrollBarProperty;
// ScrollBar side // ScrollBar side
typedef enum { typedef enum {
SCROLLBAR_LEFT_SIDE = 0, SCROLLBAR_LEFT_SIDE = 0,
SCROLLBAR_RIGHT_SIDE SCROLLBAR_RIGHT_SIDE
} GuiScrollBarSide; } GuiScrollBarSide;
// ListView // ListView
typedef enum { typedef enum {
LIST_ITEMS_HEIGHT = 16, LIST_ITEMS_HEIGHT = 16,
LIST_ITEMS_PADDING, LIST_ITEMS_PADDING,
SCROLLBAR_WIDTH, SCROLLBAR_WIDTH,
SCROLLBAR_SIDE, SCROLLBAR_SIDE,
} GuiListViewProperty; } GuiListViewProperty;
// ColorPicker // ColorPicker
typedef enum { typedef enum {
COLOR_SELECTOR_SIZE = 16, COLOR_SELECTOR_SIZE = 16,
HUEBAR_WIDTH, // Right hue bar width HUEBAR_WIDTH, // Right hue bar width
HUEBAR_PADDING, // Right hue bar separation from panel HUEBAR_PADDING, // Right hue bar separation from panel
HUEBAR_SELECTOR_HEIGHT, // Right hue bar selector height HUEBAR_SELECTOR_HEIGHT, // Right hue bar selector height
HUEBAR_SELECTOR_OVERFLOW // Right hue bar selector overflow HUEBAR_SELECTOR_OVERFLOW // Right hue bar selector overflow
} GuiColorPickerProperty; } GuiColorPickerProperty;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// ... // ...
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Functions Declaration // Module Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// State modification functions // State modification functions
RAYGUIDEF void GuiEnable(void); // Enable gui controls (global state) RAYGUIDEF void GuiEnable(void); // Enable gui controls (global state)
RAYGUIDEF void GuiDisable(void); // Disable gui controls (global state) RAYGUIDEF void GuiDisable(void); // Disable gui controls (global state)
RAYGUIDEF void GuiLock(void); // Lock gui controls (global state) RAYGUIDEF void GuiLock(void); // Lock gui controls (global state)
RAYGUIDEF void GuiUnlock(void); // Unlock gui controls (global state) RAYGUIDEF void GuiUnlock(void); // Unlock gui controls (global state)
RAYGUIDEF void GuiFade(float alpha); // Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f RAYGUIDEF void GuiFade(float alpha); // Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f
RAYGUIDEF void GuiSetState(int state); // Set gui state (global state) RAYGUIDEF void GuiSetState(int state); // Set gui state (global state)
RAYGUIDEF int GuiGetState(void); // Get gui state (global state) RAYGUIDEF int GuiGetState(void); // Get gui state (global state)
// Font set/get functions // Font set/get functions
RAYGUIDEF void GuiSetFont(Font font); // Set gui custom font (global state) RAYGUIDEF void GuiSetFont(Font font); // Set gui custom font (global state)
RAYGUIDEF Font GuiGetFont(void); // Get gui custom font (global state) RAYGUIDEF Font GuiGetFont(void); // Get gui custom font (global state)
// Style set/get functions // Style set/get functions
RAYGUIDEF void GuiSetStyle(int control, int property, int value); // Set one style property RAYGUIDEF void GuiSetStyle(int control, int property, int value); // Set one style property
RAYGUIDEF int GuiGetStyle(int control, int property); // Get one style property RAYGUIDEF int GuiGetStyle(int control, int property); // Get one style property
// Container/separator controls, useful for controls organization // Container/separator controls, useful for controls organization
RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *title); // Window Box control, shows a window that can be closed RAYGUIDEF bool GuiWindowBox(Rectangle bounds, const char *title); // Window Box control, shows a window that can be closed
RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text); // Group Box control with text name RAYGUIDEF void GuiGroupBox(Rectangle bounds, const char *text); // Group Box control with text name
RAYGUIDEF void GuiLine(Rectangle bounds, const char *text); // Line separator control, could contain text RAYGUIDEF void GuiLine(Rectangle bounds, const char *text); // Line separator control, could contain text
RAYGUIDEF void GuiPanel(Rectangle bounds); // Panel control, useful to group controls RAYGUIDEF void GuiPanel(Rectangle bounds); // Panel control, useful to group controls
RAYGUIDEF Rectangle GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 *scroll); // Scroll Panel control RAYGUIDEF Rectangle GuiScrollPanel(Rectangle bounds, Rectangle content, Vector2 *scroll); // Scroll Panel control
// Basic controls set // Basic controls set
RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text); // Label control, shows text RAYGUIDEF void GuiLabel(Rectangle bounds, const char *text); // Label control, shows text
RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked RAYGUIDEF bool GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked
RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text); // Label button control, show true when clicked RAYGUIDEF bool GuiLabelButton(Rectangle bounds, const char *text); // Label button control, show true when clicked
RAYGUIDEF bool GuiImageButton(Rectangle bounds, const char *text, Texture2D texture); // Image button control, returns true when clicked RAYGUIDEF bool GuiImageButton(Rectangle bounds, const char *text, Texture2D texture); // Image button control, returns true when clicked
RAYGUIDEF bool GuiImageButtonEx(Rectangle bounds, const char *text, Texture2D texture, Rectangle texSource); // Image button extended control, returns true when clicked RAYGUIDEF bool GuiImageButtonEx(Rectangle bounds, const char *text, Texture2D texture, Rectangle texSource); // Image button extended control, returns true when clicked
RAYGUIDEF bool GuiToggle(Rectangle bounds, const char *text, bool active); // Toggle Button control, returns true when active RAYGUIDEF bool GuiToggle(Rectangle bounds, const char *text, bool active); // Toggle Button control, returns true when active
RAYGUIDEF int GuiToggleGroup(Rectangle bounds, const char *text, int active); // Toggle Group control, returns active toggle index RAYGUIDEF int GuiToggleGroup(Rectangle bounds, const char *text, int active); // Toggle Group control, returns active toggle index
RAYGUIDEF bool GuiCheckBox(Rectangle bounds, const char *text, bool checked); // Check Box control, returns true when active RAYGUIDEF bool GuiCheckBox(Rectangle bounds, const char *text, bool checked); // Check Box control, returns true when active
RAYGUIDEF int GuiComboBox(Rectangle bounds, const char *text, int active); // Combo Box control, returns selected item index RAYGUIDEF int GuiComboBox(Rectangle bounds, const char *text, int active); // Combo Box control, returns selected item index
RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode); // Dropdown Box control, returns selected item RAYGUIDEF bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode); // Dropdown Box control, returns selected item
RAYGUIDEF bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Spinner control, returns selected value RAYGUIDEF bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Spinner control, returns selected value
RAYGUIDEF bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers RAYGUIDEF bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers
RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control, updates input text RAYGUIDEF bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control, updates input text
RAYGUIDEF bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control with multiple lines RAYGUIDEF bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control with multiple lines
RAYGUIDEF float GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); // Slider control, returns selected value RAYGUIDEF float GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); // Slider control, returns selected value
RAYGUIDEF float GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); // Slider Bar control, returns selected value RAYGUIDEF float GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); // Slider Bar control, returns selected value
RAYGUIDEF float GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); // Progress Bar control, shows current progress value RAYGUIDEF float GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); // Progress Bar control, shows current progress value
RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text); // Status Bar control, shows info text RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text); // Status Bar control, shows info text
RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders
RAYGUIDEF int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue); // Scroll Bar control RAYGUIDEF int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue); // Scroll Bar control
RAYGUIDEF Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs); // Grid control RAYGUIDEF Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs); // Grid control
// Advance controls set // Advance controls set
RAYGUIDEF int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int active); // List View control, returns selected list item index RAYGUIDEF int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int active); // List View control, returns selected list item index
RAYGUIDEF int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active); // List View with extended parameters RAYGUIDEF int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active); // List View with extended parameters
RAYGUIDEF int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons); // Message Box control, displays a message RAYGUIDEF int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons); // Message Box control, displays a message
RAYGUIDEF int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text); // Text Input Box control, ask for text RAYGUIDEF int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text); // Text Input Box control, ask for text
RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color); // Color Picker control (multiple color controls) RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color); // Color Picker control (multiple color controls)
RAYGUIDEF Color GuiColorPanel(Rectangle bounds, Color color); // Color Panel control RAYGUIDEF Color GuiColorPanel(Rectangle bounds, Color color); // Color Panel control
RAYGUIDEF float GuiColorBarAlpha(Rectangle bounds, float alpha); // Color Bar Alpha control RAYGUIDEF float GuiColorBarAlpha(Rectangle bounds, float alpha); // Color Bar Alpha control
RAYGUIDEF float GuiColorBarHue(Rectangle bounds, float value); // Color Bar Hue control RAYGUIDEF float GuiColorBarHue(Rectangle bounds, float value); // Color Bar Hue control
// Styles loading functions // Styles loading functions
RAYGUIDEF void GuiLoadStyle(const char *fileName); // Load style file (.rgs) RAYGUIDEF void GuiLoadStyle(const char *fileName); // Load style file (.rgs)
RAYGUIDEF void GuiLoadStyleDefault(void); // Load style default over global style RAYGUIDEF void GuiLoadStyleDefault(void); // Load style default over global style
/* /*
typedef GuiStyle (unsigned int *) typedef GuiStyle (unsigned int *)
RAYGUIDEF GuiStyle LoadGuiStyle(const char *fileName); // Load style from file (.rgs) RAYGUIDEF GuiStyle LoadGuiStyle(const char *fileName); // Load style from file (.rgs)
RAYGUIDEF void UnloadGuiStyle(GuiStyle style); // Unload style RAYGUIDEF void UnloadGuiStyle(GuiStyle style); // Unload style
*/ */
RAYGUIDEF const char *GuiIconText(int iconId, const char *text); // Get text with icon id prepended (if supported) RAYGUIDEF const char *GuiIconText(int iconId, const char *text); // Get text with icon id prepended (if supported)
#if defined(RAYGUI_SUPPORT_ICONS) #if defined(RAYGUI_SUPPORT_ICONS)
// Gui icons functionality // Gui icons functionality
RAYGUIDEF void GuiDrawIcon(int iconId, Vector2 position, int pixelSize, Color color); RAYGUIDEF void GuiDrawIcon(int iconId, Vector2 position, int pixelSize, Color color);
RAYGUIDEF unsigned int *GuiGetIcons(void); // Get full icons data pointer RAYGUIDEF unsigned int *GuiGetIcons(void); // Get full icons data pointer
RAYGUIDEF unsigned int *GuiGetIconData(int iconId); // Get icon bit data RAYGUIDEF unsigned int *GuiGetIconData(int iconId); // Get icon bit data
RAYGUIDEF void GuiSetIconData(int iconId, unsigned int *data); // Set icon bit data RAYGUIDEF void GuiSetIconData(int iconId, unsigned int *data); // Set icon bit data
RAYGUIDEF void GuiSetIconPixel(int iconId, int x, int y); // Set icon pixel value RAYGUIDEF void GuiSetIconPixel(int iconId, int x, int y); // Set icon pixel value
RAYGUIDEF void GuiClearIconPixel(int iconId, int x, int y); // Clear icon pixel value RAYGUIDEF void GuiClearIconPixel(int iconId, int x, int y); // Clear icon pixel value
RAYGUIDEF bool GuiCheckIconPixel(int iconId, int x, int y); // Check icon pixel value RAYGUIDEF bool GuiCheckIconPixel(int iconId, int x, int y); // Check icon pixel value
#endif #endif
@ -511,8 +511,8 @@ RAYGUIDEF bool GuiCheckIconPixel(int iconId, int x, int y); // Check icon pi
#if defined(RAYGUI_IMPLEMENTATION) #if defined(RAYGUI_IMPLEMENTATION)
#if defined(RAYGUI_SUPPORT_ICONS) #if defined(RAYGUI_SUPPORT_ICONS)
#define RICONS_IMPLEMENTATION #define RICONS_IMPLEMENTATION
#include "ricons.h" // Required for: raygui icons data #include "ricons.h" // Required for: raygui icons data
#endif #endif
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fprintf(), feof(), fscanf(), vsprintf() #include <stdio.h> // Required for: FILE, fopen(), fclose(), fprintf(), feof(), fscanf(), vsprintf()
@ -520,13 +520,13 @@ RAYGUIDEF bool GuiCheckIconPixel(int iconId, int x, int y); // Check icon pi
#include <math.h> // Required for: roundf() on GuiColorPicker() #include <math.h> // Required for: roundf() on GuiColorPicker()
#if defined(RAYGUI_STANDALONE) #if defined(RAYGUI_STANDALONE)
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end() #include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
#define RAYGUI_CLITERAL(name) name #define RAYGUI_CLITERAL(name) name
#else #else
#define RAYGUI_CLITERAL(name) (name) #define RAYGUI_CLITERAL(name) (name)
#endif #endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -717,7 +717,7 @@ int GuiGetStyle(int control, int property)
bool GuiWindowBox(Rectangle bounds, const char *title) bool GuiWindowBox(Rectangle bounds, const char *title)
{ {
// NOTE: This define is also used by GuiMessageBox() and GuiTextInputBox() // NOTE: This define is also used by GuiMessageBox() and GuiTextInputBox()
#define WINDOW_STATUSBAR_HEIGHT 22 #define WINDOW_STATUSBAR_HEIGHT 22
//GuiControlState state = guiState; //GuiControlState state = guiState;
bool clicked = false; bool clicked = false;
@ -762,8 +762,8 @@ bool GuiWindowBox(Rectangle bounds, const char *title)
// Group Box control with text name // Group Box control with text name
void GuiGroupBox(Rectangle bounds, const char *text) void GuiGroupBox(Rectangle bounds, const char *text)
{ {
#define GROUPBOX_LINE_THICK 1 #define GROUPBOX_LINE_THICK 1
#define GROUPBOX_TEXT_PADDING 10 #define GROUPBOX_TEXT_PADDING 10
GuiControlState state = guiState; GuiControlState state = guiState;
@ -780,7 +780,7 @@ void GuiGroupBox(Rectangle bounds, const char *text)
// Line control // Line control
void GuiLine(Rectangle bounds, const char *text) void GuiLine(Rectangle bounds, const char *text)
{ {
#define LINE_TEXT_PADDING 10 #define LINE_TEXT_PADDING 10
GuiControlState state = guiState; GuiControlState state = guiState;
@ -808,7 +808,7 @@ void GuiLine(Rectangle bounds, const char *text)
// Panel control // Panel control
void GuiPanel(Rectangle bounds) void GuiPanel(Rectangle bounds)
{ {
#define PANEL_BORDER_WIDTH 1 #define PANEL_BORDER_WIDTH 1
GuiControlState state = guiState; GuiControlState state = guiState;
@ -1102,9 +1102,9 @@ bool GuiToggle(Rectangle bounds, const char *text, bool active)
// Toggle Group control, returns toggled button index // Toggle Group control, returns toggled button index
int GuiToggleGroup(Rectangle bounds, const char *text, int active) int GuiToggleGroup(Rectangle bounds, const char *text, int active)
{ {
#if !defined(TOGGLEGROUP_MAX_ELEMENTS) #if !defined(TOGGLEGROUP_MAX_ELEMENTS)
#define TOGGLEGROUP_MAX_ELEMENTS 32 #define TOGGLEGROUP_MAX_ELEMENTS 32
#endif #endif
float initBoundsX = bounds.x; float initBoundsX = bounds.x;
@ -1557,9 +1557,9 @@ bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, in
// NOTE: Requires static variables: framesCounter // NOTE: Requires static variables: framesCounter
bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode)
{ {
#if !defined(VALUEBOX_MAX_CHARS) #if !defined(VALUEBOX_MAX_CHARS)
#define VALUEBOX_MAX_CHARS 32 #define VALUEBOX_MAX_CHARS 32
#endif #endif
static int framesCounter = 0; // Required for blinking cursor static int framesCounter = 0; // Required for blinking cursor
@ -2391,7 +2391,7 @@ Color GuiColorPanel(Rectangle bounds, Color color)
// NOTE: Returns alpha value normalized [0..1] // NOTE: Returns alpha value normalized [0..1]
float GuiColorBarAlpha(Rectangle bounds, float alpha) float GuiColorBarAlpha(Rectangle bounds, float alpha)
{ {
#define COLORBARALPHA_CHECKED_SIZE 10 #define COLORBARALPHA_CHECKED_SIZE 10
GuiControlState state = guiState; GuiControlState state = guiState;
Rectangle selector = { (float)bounds.x + alpha*bounds.width - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW), (float)bounds.y - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW), (float)GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT), (float)bounds.height + GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW)*2 }; Rectangle selector = { (float)bounds.x + alpha*bounds.width - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW), (float)bounds.y - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW), (float)GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT), (float)bounds.height + GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW)*2 };
@ -2531,11 +2531,11 @@ Color GuiColorPicker(Rectangle bounds, Color color)
color = GuiColorPanel(bounds, color); color = GuiColorPanel(bounds, color);
Rectangle boundsHue = { (float)bounds.x + bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_PADDING), (float)bounds.y, (float)GuiGetStyle(COLORPICKER, HUEBAR_WIDTH), (float)bounds.height }; Rectangle boundsHue = { (float)bounds.x + bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_PADDING), (float)bounds.y, (float)GuiGetStyle(COLORPICKER, HUEBAR_WIDTH), (float)bounds.height };
//Rectangle boundsAlpha = { bounds.x, bounds.y + bounds.height + GuiGetStyle(COLORPICKER, BARS_PADDING), bounds.width, GuiGetStyle(COLORPICKER, BARS_THICK) }; Rectangle boundsAlpha = { bounds.x, bounds.y + bounds.height + GuiGetStyle(COLORPICKER, HUEBAR_PADDING), bounds.width, GuiGetStyle(COLORPICKER, HUEBAR_WIDTH) };
Vector3 hsv = ConvertRGBtoHSV(RAYGUI_CLITERAL(Vector3){ color.r/255.0f, color.g/255.0f, color.b/255.0f }); Vector3 hsv = ConvertRGBtoHSV(RAYGUI_CLITERAL(Vector3){ color.r/255.0f, color.g/255.0f, color.b/255.0f });
hsv.x = GuiColorBarHue(boundsHue, hsv.x); hsv.x = GuiColorBarHue(boundsHue, hsv.x);
//color.a = (unsigned char)(GuiColorBarAlpha(boundsAlpha, (float)color.a/255.0f)*255.0f); color.a = (unsigned char)(GuiColorBarAlpha(boundsAlpha, (float)color.a/255.0f)*255.0f);
Vector3 rgb = ConvertHSVtoRGB(hsv); Vector3 rgb = ConvertHSVtoRGB(hsv);
color = RAYGUI_CLITERAL(Color){ (unsigned char)roundf(rgb.x*255.0f), (unsigned char)roundf(rgb.y*255.0f), (unsigned char)roundf(rgb.z*255.0f), color.a }; color = RAYGUI_CLITERAL(Color){ (unsigned char)roundf(rgb.x*255.0f), (unsigned char)roundf(rgb.y*255.0f), (unsigned char)roundf(rgb.z*255.0f), color.a };
@ -2545,8 +2545,8 @@ Color GuiColorPicker(Rectangle bounds, Color color)
// Message Box control // Message Box control
int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons) int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons)
{ {
#define MESSAGEBOX_BUTTON_HEIGHT 24 #define MESSAGEBOX_BUTTON_HEIGHT 24
#define MESSAGEBOX_BUTTON_PADDING 10 #define MESSAGEBOX_BUTTON_PADDING 10
int clicked = -1; // Returns clicked button from buttons list, 0 refers to closed window button int clicked = -1; // Returns clicked button from buttons list, 0 refers to closed window button
@ -2593,11 +2593,11 @@ int GuiMessageBox(Rectangle bounds, const char *title, const char *message, cons
// Text Input Box control, ask for text // Text Input Box control, ask for text
int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text) int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text)
{ {
#define TEXTINPUTBOX_BUTTON_HEIGHT 24 #define TEXTINPUTBOX_BUTTON_HEIGHT 24
#define TEXTINPUTBOX_BUTTON_PADDING 10 #define TEXTINPUTBOX_BUTTON_PADDING 10
#define TEXTINPUTBOX_HEIGHT 30 #define TEXTINPUTBOX_HEIGHT 30
#define TEXTINPUTBOX_MAX_TEXT_LENGTH 256 #define TEXTINPUTBOX_MAX_TEXT_LENGTH 256
// Used to enable text edit mode // Used to enable text edit mode
// WARNING: No more than one GuiTextInputBox() should be open at the same time // WARNING: No more than one GuiTextInputBox() should be open at the same time
@ -2670,9 +2670,9 @@ int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, co
// https://stackoverflow.com/questions/4435450/2d-opengl-drawing-lines-that-dont-exactly-fit-pixel-raster // https://stackoverflow.com/questions/4435450/2d-opengl-drawing-lines-that-dont-exactly-fit-pixel-raster
Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs) Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs)
{ {
#if !defined(GRID_COLOR_ALPHA) #if !defined(GRID_COLOR_ALPHA)
#define GRID_COLOR_ALPHA 0.15f // Grid lines alpha amount #define GRID_COLOR_ALPHA 0.15f // Grid lines alpha amount
#endif #endif
GuiControlState state = guiState; GuiControlState state = guiState;
Vector2 mousePoint = GetMousePosition(); Vector2 mousePoint = GetMousePosition();
@ -3100,7 +3100,7 @@ char **GuiLoadIcons(const char *fileName, bool loadIconsName)
// Draw selected icon using rectangles pixel-by-pixel // Draw selected icon using rectangles pixel-by-pixel
void GuiDrawIcon(int iconId, Vector2 position, int pixelSize, Color color) void GuiDrawIcon(int iconId, Vector2 position, int pixelSize, Color color)
{ {
#define BIT_CHECK(a,b) ((a) & (1<<(b))) #define BIT_CHECK(a,b) ((a) & (1<<(b)))
for (int i = 0, y = 0; i < RICON_SIZE*RICON_SIZE/32; i++) for (int i = 0, y = 0; i < RICON_SIZE*RICON_SIZE/32; i++)
{ {
@ -3108,9 +3108,9 @@ void GuiDrawIcon(int iconId, Vector2 position, int pixelSize, Color color)
{ {
if (BIT_CHECK(guiIcons[iconId*RICON_DATA_ELEMENTS + i], k)) if (BIT_CHECK(guiIcons[iconId*RICON_DATA_ELEMENTS + i], k))
{ {
#if !defined(RAYGUI_STANDALONE) #if !defined(RAYGUI_STANDALONE)
DrawRectangle(position.x + (k%RICON_SIZE)*pixelSize, position.y + y*pixelSize, pixelSize, pixelSize, color); DrawRectangle(position.x + (k%RICON_SIZE)*pixelSize, position.y + y*pixelSize, pixelSize, pixelSize, color);
#endif #endif
} }
if ((k == 15) || (k == 31)) y++; if ((k == 15) || (k == 31)) y++;
@ -3140,7 +3140,7 @@ void GuiSetIconData(int iconId, unsigned int *data)
// Set icon pixel value // Set icon pixel value
void GuiSetIconPixel(int iconId, int x, int y) void GuiSetIconPixel(int iconId, int x, int y)
{ {
#define BIT_SET(a,b) ((a) |= (1<<(b))) #define BIT_SET(a,b) ((a) |= (1<<(b)))
// This logic works for any RICON_SIZE pixels icons, // This logic works for any RICON_SIZE pixels icons,
// For example, in case of 16x16 pixels, every 2 lines fit in one unsigned int data element // For example, in case of 16x16 pixels, every 2 lines fit in one unsigned int data element
@ -3150,7 +3150,7 @@ void GuiSetIconPixel(int iconId, int x, int y)
// Clear icon pixel value // Clear icon pixel value
void GuiClearIconPixel(int iconId, int x, int y) void GuiClearIconPixel(int iconId, int x, int y)
{ {
#define BIT_CLEAR(a,b) ((a) &= ~((1)<<(b))) #define BIT_CLEAR(a,b) ((a) &= ~((1)<<(b)))
// This logic works for any RICON_SIZE pixels icons, // This logic works for any RICON_SIZE pixels icons,
// For example, in case of 16x16 pixels, every 2 lines fit in one unsigned int data element // For example, in case of 16x16 pixels, every 2 lines fit in one unsigned int data element
@ -3160,7 +3160,7 @@ void GuiClearIconPixel(int iconId, int x, int y)
// Check icon pixel value // Check icon pixel value
bool GuiCheckIconPixel(int iconId, int x, int y) bool GuiCheckIconPixel(int iconId, int x, int y)
{ {
#define BIT_CHECK(a,b) ((a) & (1<<(b))) #define BIT_CHECK(a,b) ((a) & (1<<(b)))
return (BIT_CHECK(guiIcons[iconId*8 + y/2], x + (y%2*16))); return (BIT_CHECK(guiIcons[iconId*8 + y/2], x + (y%2*16)));
} }
@ -3243,7 +3243,7 @@ static const char *GetTextIcon(const char *text, int *iconId)
// Gui draw text using default font // Gui draw text using default font
static void GuiDrawText(const char *text, Rectangle bounds, int alignment, Color tint) static void GuiDrawText(const char *text, Rectangle bounds, int alignment, Color tint)
{ {
#define TEXT_VALIGN_PIXEL_OFFSET(h) ((int)h%2) // Vertical alignment for pixel perfect #define TEXT_VALIGN_PIXEL_OFFSET(h) ((int)h%2) // Vertical alignment for pixel perfect
if ((text != NULL) && (text[0] != '\0')) if ((text != NULL) && (text[0] != '\0'))
{ {
@ -3252,7 +3252,7 @@ static void GuiDrawText(const char *text, Rectangle bounds, int alignment, Color
// Get text position depending on alignment and iconId // Get text position depending on alignment and iconId
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
#define ICON_TEXT_PADDING 4 #define ICON_TEXT_PADDING 4
Vector2 position = { bounds.x, bounds.y }; Vector2 position = { bounds.x, bounds.y };
@ -3344,13 +3344,13 @@ static const char **GuiTextSplit(const char *text, int *count, int *textRow)
// 2. Maximum size of text to split is TEXTSPLIT_MAX_TEXT_LENGTH // 2. Maximum size of text to split is TEXTSPLIT_MAX_TEXT_LENGTH
// NOTE: Those definitions could be externally provided if required // NOTE: Those definitions could be externally provided if required
#if !defined(TEXTSPLIT_MAX_TEXT_LENGTH) #if !defined(TEXTSPLIT_MAX_TEXT_LENGTH)
#define TEXTSPLIT_MAX_TEXT_LENGTH 1024 #define TEXTSPLIT_MAX_TEXT_LENGTH 1024
#endif #endif
#if !defined(TEXTSPLIT_MAX_TEXT_ELEMENTS) #if !defined(TEXTSPLIT_MAX_TEXT_ELEMENTS)
#define TEXTSPLIT_MAX_TEXT_ELEMENTS 128 #define TEXTSPLIT_MAX_TEXT_ELEMENTS 128
#endif #endif
static const char *result[TEXTSPLIT_MAX_TEXT_ELEMENTS] = { NULL }; static const char *result[TEXTSPLIT_MAX_TEXT_ELEMENTS] = { NULL };
static char buffer[TEXTSPLIT_MAX_TEXT_LENGTH] = { 0 }; static char buffer[TEXTSPLIT_MAX_TEXT_LENGTH] = { 0 };
@ -3557,7 +3557,7 @@ static Color Fade(Color color, float alpha)
// Formatting of text with variables to 'embed' // Formatting of text with variables to 'embed'
static const char *TextFormat(const char *text, ...) static const char *TextFormat(const char *text, ...)
{ {
#define MAX_FORMATTEXT_LENGTH 64 #define MAX_FORMATTEXT_LENGTH 64
static char buffer[MAX_FORMATTEXT_LENGTH]; static char buffer[MAX_FORMATTEXT_LENGTH];