From 1af9a3960a77cfafebc47e6414c0a6520fb88d32 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 27 May 2023 11:34:45 +0200 Subject: [PATCH] Integrated 4.0-dev branch (#288) * WARNING: Library redesign to support return result values REVIEWED: All example projects * REVIEWED: Cast values to improve Zig interconnection (#286) * Update version and header info * REVIEWED: `GuiListView()`, parameter order bug * Update raygui.h * REVIEWED: `GuiTabBar()` toggle logic * Update raygui.h * Update raygui.h --- .../controls_test_suite/controls_test_suite.c | 31 +- examples/custom_file_dialog/gui_file_dialog.h | 13 +- examples/image_exporter/image_exporter.c | 14 +- .../image_importer_raw/image_importer_raw.c | 6 +- examples/property_list/dm_property_list.h | 6 +- examples/property_list/property_list.c | 4 +- examples/scroll_panel/scroll_panel.c | 23 +- projects/VS2022/raygui.sln | 38 -- src/raygui.h | 475 +++++++++++------- 9 files changed, 340 insertions(+), 270 deletions(-) diff --git a/examples/controls_test_suite/controls_test_suite.c b/examples/controls_test_suite/controls_test_suite.c index 9d76ecc..c6414e7 100644 --- a/examples/controls_test_suite/controls_test_suite.c +++ b/examples/controls_test_suite/controls_test_suite.c @@ -84,8 +84,8 @@ int main() bool multiTextBoxEditMode = false; Color colorPickerValue = RED; - int sliderValue = 50; - int sliderBarValue = 60; + float sliderValue = 50.0f; + float sliderBarValue = 60; float progressValue = 0.4f; bool forceSquaredChecked = false; @@ -149,7 +149,7 @@ int main() // First GUI column //GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); - forceSquaredChecked = GuiCheckBox((Rectangle){ 25, 108, 15, 15 }, "FORCE CHECK!", forceSquaredChecked); + GuiCheckBox((Rectangle){ 25, 108, 15, 15 }, "FORCE CHECK!", &forceSquaredChecked); GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); //GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); @@ -171,7 +171,7 @@ int main() GuiSetState(STATE_NORMAL); //GuiUnlock(); - comboBoxActive = GuiComboBox((Rectangle){ 25, 470, 125, 30 }, "ONE;TWO;THREE;FOUR", comboBoxActive); + GuiComboBox((Rectangle){ 25, 470, 125, 30 }, "ONE;TWO;THREE;FOUR", &comboBoxActive); // NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding GuiUnlock(); @@ -182,27 +182,30 @@ int main() if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode; // Second GUI column - listViewActive = GuiListView((Rectangle){ 165, 25, 140, 140 }, "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey", &listViewScrollIndex, listViewActive); - listViewExActive = GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, 8, &listViewExFocus, &listViewExScrollIndex, listViewExActive); + GuiListView((Rectangle){ 165, 25, 140, 140 }, "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey", &listViewScrollIndex, &listViewActive); + GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, 8, &listViewExScrollIndex, &listViewExActive, &listViewExFocus); - toggleGroupActive = GuiToggleGroup((Rectangle){ 165, 400, 140, 25 }, "#1#ONE\n#3#TWO\n#8#THREE\n#23#", toggleGroupActive); + //GuiToggle((Rectangle){ 165, 400, 140, 25 }, "#1#ONE", &toggleGroupActive); + GuiToggleGroup((Rectangle){ 165, 400, 140, 25 }, "#1#ONE\n#3#TWO\n#8#THREE\n#23#", &toggleGroupActive); // Third GUI column GuiPanel((Rectangle){ 320, 25, 225, 140 }, "Panel Info"); - colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, NULL, colorPickerValue); + GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, NULL, &colorPickerValue); - sliderValue = GuiSlider((Rectangle){ 355, 400, 165, 20 }, "TEST", TextFormat("%2.2f", (float)sliderValue), sliderValue, -50, 100); - sliderBarValue = GuiSliderBar((Rectangle){ 320, 430, 200, 20 }, NULL, TextFormat("%i", (int)sliderBarValue), sliderBarValue, 0, 100); - progressValue = GuiProgressBar((Rectangle){ 320, 460, 200, 20 }, NULL, NULL, progressValue, 0, 1); + GuiSlider((Rectangle){ 355, 400, 165, 20 }, "TEST", TextFormat("%2.2f", sliderValue), &sliderValue, -50, 100); + GuiSliderBar((Rectangle){ 320, 430, 200, 20 }, NULL, TextFormat("%i", (int)sliderBarValue), &sliderBarValue, 0, 100); + GuiProgressBar((Rectangle){ 320, 460, 200, 20 }, NULL, NULL, &progressValue, 0, 1); // NOTE: View rectangle could be used to perform some scissor test - Rectangle view = GuiScrollPanel((Rectangle){ 560, 25, 102, 354 }, NULL, (Rectangle){ 560, 25, 300, 1200 }, &viewScroll); + Rectangle view = { 0 }; + GuiScrollPanel((Rectangle){ 560, 25, 102, 354 }, NULL, (Rectangle){ 560, 25, 300, 1200 }, &viewScroll, &view); - GuiGrid((Rectangle) { 560, 25 + 180 + 195, 100, 120 }, NULL, 20, 2); + Vector2 mouseCell = { 0 }; + GuiGrid((Rectangle) { 560, 25 + 180 + 195, 100, 120 }, NULL, 20, 2, &mouseCell); GuiStatusBar((Rectangle){ 0, (float)GetScreenHeight() - 20, (float)GetScreenWidth(), 20 }, "This is a status bar"); - alphaValue = GuiColorBarAlpha((Rectangle){ 320, 490, 200, 30 }, NULL, alphaValue); + GuiColorBarAlpha((Rectangle){ 320, 490, 200, 30 }, NULL, &alphaValue); if (showMessageBox) { diff --git a/examples/custom_file_dialog/gui_file_dialog.h b/examples/custom_file_dialog/gui_file_dialog.h index e89040a..ae68729 100644 --- a/examples/custom_file_dialog/gui_file_dialog.h +++ b/examples/custom_file_dialog/gui_file_dialog.h @@ -310,7 +310,8 @@ void GuiFileDialog(GuiFileDialogState *state) # if defined(USE_CUSTOM_LISTVIEW_FILEINFO) state->filesListActive = GuiListViewFiles((Rectangle){ state->position.x + 8, state->position.y + 48 + 20, state->windowBounds.width - 16, state->windowBounds.height - 60 - 16 - 68 }, fileInfo, state->dirFiles.count, &state->itemFocused, &state->filesListScrollIndex, state->filesListActive); # else - state->filesListActive = GuiListViewEx((Rectangle){ state->windowBounds.x + 8, state->windowBounds.y + 48 + 20, state->windowBounds.width - 16, state->windowBounds.height - 60 - 16 - 68 }, (const char**)dirFilesIcon, state->dirFiles.count, &state->itemFocused, &state->filesListScrollIndex, state->filesListActive); + GuiListViewEx((Rectangle){ state->windowBounds.x + 8, state->windowBounds.y + 48 + 20, state->windowBounds.width - 16, state->windowBounds.height - 60 - 16 - 68 }, + (const char**)dirFilesIcon, state->dirFiles.count, &state->filesListScrollIndex, &state->filesListActive, &state->itemFocused); # endif GuiSetStyle(LISTVIEW, TEXT_ALIGNMENT, prevTextAlignment); GuiSetStyle(LISTVIEW, LIST_ITEMS_HEIGHT, prevElementsHeight); @@ -372,7 +373,7 @@ void GuiFileDialog(GuiFileDialogState *state) } GuiLabel((Rectangle){ state->windowBounds.x + 8, state->windowBounds.y + state->windowBounds.height - 24 - 12, 68, 24 }, "File filter:"); - state->fileTypeActive = GuiComboBox((Rectangle){ state->windowBounds.x + 72, state->windowBounds.y + state->windowBounds.height - 24 - 12, state->windowBounds.width - 184, 24 }, "All files", state->fileTypeActive); + GuiComboBox((Rectangle){ state->windowBounds.x + 72, state->windowBounds.y + state->windowBounds.height - 24 - 12, state->windowBounds.width - 184, 24 }, "All files", &state->fileTypeActive); state->SelectFilePressed = GuiButton((Rectangle){ state->windowBounds.x + state->windowBounds.width - 96 - 8, state->windowBounds.y + state->windowBounds.height - 68, 96, 24 }, "Select"); @@ -462,11 +463,12 @@ static void ReloadDirectoryFiles(GuiFileDialogState *state) #if defined(USE_CUSTOM_LISTVIEW_FILEINFO) // List View control for files info with extended parameters -static int GuiListViewFiles(Rectangle bounds, FileInfo *files, int count, int *focus, int *scrollIndex, int active) +static int GuiListViewFiles(Rectangle bounds, FileInfo *files, int count, int *focus, int *scrollIndex, int *active) { + int result = 0; GuiState state = guiState; int itemFocused = (focus == NULL)? -1 : *focus; - int itemSelected = active; + int itemSelected = *active; // Check if we need a scroll bar bool useScrollBar = false; @@ -610,7 +612,8 @@ static int GuiListViewFiles(Rectangle bounds, FileInfo *files, int count, int *f if (focus != NULL) *focus = itemFocused; if (scrollIndex != NULL) *scrollIndex = startIndex; - return itemSelected; + *active = itemSelected; + return result; } #endif // USE_CUSTOM_LISTVIEW_FILEINFO diff --git a/examples/image_exporter/image_exporter.c b/examples/image_exporter/image_exporter.c index 3b967d6..8a95029 100644 --- a/examples/image_exporter/image_exporter.c +++ b/examples/image_exporter/image_exporter.c @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) float imageScale = 1.0f; Rectangle imageRec = { 0 }; - bool btnExport = false; + bool btnExportPressed = false; SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) UnloadDroppedFiles(droppedFiles); } - if (btnExport) + if (btnExportPressed) { if (imageLoaded) { @@ -163,17 +163,17 @@ int main(int argc, char *argv[]) windowBoxActive = !GuiWindowBox((Rectangle){ windowBoxRec.x, windowBoxRec.y, 220, 190 }, "Image Export Options"); GuiLabel((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 35, 60, 25 }, "File format:"); - fileFormatActive = GuiComboBox((Rectangle){ windowBoxRec.x + 80, windowBoxRec.y + 35, 130, 25 }, TextJoin(fileFormatTextList, 3, ";"), fileFormatActive); + GuiComboBox((Rectangle){ windowBoxRec.x + 80, windowBoxRec.y + 35, 130, 25 }, TextJoin(fileFormatTextList, 3, ";"), &fileFormatActive); GuiLabel((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 70, 63, 25 }, "Pixel format:"); - pixelFormatActive = GuiComboBox((Rectangle){ windowBoxRec.x + 80, windowBoxRec.y + 70, 130, 25 }, TextJoin(pixelFormatTextList, 7, ";"), pixelFormatActive); + GuiComboBox((Rectangle){ windowBoxRec.x + 80, windowBoxRec.y + 70, 130, 25 }, TextJoin(pixelFormatTextList, 7, ";"), &pixelFormatActive); GuiLabel((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 105, 50, 25 }, "File name:"); if (GuiTextBox((Rectangle){ windowBoxRec.x + 80, windowBoxRec.y + 105, 130, 25 }, fileName, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode; - btnExport = GuiButton((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 145, 200, 30 }, "Export Image"); + btnExportPressed = GuiButton((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 145, 200, 30 }, "Export Image"); } - else btnExport = false; + else btnExportPressed = false; - if (btnExport) DrawText("Image exported!", 20, screenHeight - 20, 20, RED); + if (btnExportPressed) DrawText("Image exported!", 20, screenHeight - 20, 20, RED); //----------------------------------------------------------------------------- EndDrawing(); diff --git a/examples/image_importer_raw/image_importer_raw.c b/examples/image_importer_raw/image_importer_raw.c index 2196520..0d6c36b 100644 --- a/examples/image_importer_raw/image_importer_raw.c +++ b/examples/image_importer_raw/image_importer_raw.c @@ -194,14 +194,14 @@ int main() if (GuiValueBox((Rectangle){ windowOffset.x + 60, windowOffset.y + 130, 80, 25 }, NULL, &heightValue, 0, 8192, heightEditMode)) heightEditMode = !heightEditMode; GuiLabel((Rectangle){ windowOffset.x + 145, windowOffset.y + 130, 30, 25 }, "pixels"); GuiGroupBox((Rectangle){ windowOffset.x + 10, windowOffset.y + 180, 180, 160 }, "Pixel Format"); - pixelFormatActive = GuiComboBox((Rectangle){ windowOffset.x + 20, windowOffset.y + 195, 160, 25 }, TextJoin(pixelFormatTextList, 8, ";"), pixelFormatActive); + GuiComboBox((Rectangle){ windowOffset.x + 20, windowOffset.y + 195, 160, 25 }, TextJoin(pixelFormatTextList, 8, ";"), &pixelFormatActive); GuiLine((Rectangle){ windowOffset.x + 20, windowOffset.y + 220, 160, 20 }, NULL); if (pixelFormatActive != 0) GuiDisable(); GuiLabel((Rectangle){ windowOffset.x + 20, windowOffset.y + 235, 50, 20 }, "Channels:"); - channelsActive = GuiToggleGroup((Rectangle){ windowOffset.x + 20, windowOffset.y + 255, 156/4, 25 }, TextJoin(channelsTextList, 4, ";"), channelsActive); + GuiToggleGroup((Rectangle){ windowOffset.x + 20, windowOffset.y + 255, 156/4, 25 }, TextJoin(channelsTextList, 4, ";"), &channelsActive); GuiLabel((Rectangle){ windowOffset.x + 20, windowOffset.y + 285, 50, 20 }, "Bit Depth:"); - bitDepthActive = GuiToggleGroup((Rectangle){ windowOffset.x + 20, windowOffset.y + 305, 160/3, 25 }, TextJoin(bitDepthTextList, 3, ";"), bitDepthActive); + GuiToggleGroup((Rectangle){ windowOffset.x + 20, windowOffset.y + 305, 160/3, 25 }, TextJoin(bitDepthTextList, 3, ";"), &bitDepthActive); GuiEnable(); GuiGroupBox((Rectangle){ windowOffset.x + 10, windowOffset.y + 355, 180, 50 }, "Header"); diff --git a/examples/property_list/dm_property_list.h b/examples/property_list/dm_property_list.h index c5599fe..1e59c23 100644 --- a/examples/property_list/dm_property_list.h +++ b/examples/property_list/dm_property_list.h @@ -543,7 +543,7 @@ void GuiDMPropertyList(Rectangle bounds, GuiDMProperty* props, int count, int* f // draw property value const bool locked = guiLocked; GuiLock(); // lock the checkbox since we changed the value manually - GuiCheckBox((Rectangle){propBounds.x+propBounds.width/2, propBounds.y + height/4, height/2, height/2}, props[p].value.vbool ? "Yes" : "No", props[p].value.vbool); + GuiCheckBox((Rectangle){propBounds.x+propBounds.width/2, propBounds.y + height/4, height/2, height/2}, props[p].value.vbool? "Yes" : "No", &props[p].value.vbool); if(!locked) GuiUnlock(); // only unlock when needed } break; @@ -584,8 +584,8 @@ void GuiDMPropertyList(Rectangle bounds, GuiDMProperty* props, int count, int* f // draw property name GuiDrawText(props[p].name, (Rectangle){propBounds.x + PROPERTY_PADDING, propBounds.y, propBounds.width/2-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_LEFT, textColor); // draw property value - props[p].value.vselect.active = GuiComboBox((Rectangle){propBounds.x+propBounds.width/2, propBounds.y + 1, propBounds.width/2, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 2}, - props[p].value.vselect.val, props[p].value.vselect.active); + GuiComboBox((Rectangle){propBounds.x+propBounds.width/2, propBounds.y + 1, propBounds.width/2, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 2}, + props[p].value.vselect.val, &props[p].value.vselect.active); } break; case GUI_PROP_VECTOR2: case GUI_PROP_VECTOR3: case GUI_PROP_VECTOR4: { diff --git a/examples/property_list/property_list.c b/examples/property_list/property_list.c index 31a0c09..304d12c 100644 --- a/examples/property_list/property_list.c +++ b/examples/property_list/property_list.c @@ -61,6 +61,8 @@ int main() // Tweak the default raygui style a bit GuiSetStyle(LISTVIEW, LIST_ITEMS_HEIGHT, 24); GuiSetStyle(LISTVIEW, SCROLLBAR_WIDTH, 12); + + Vector2 gridMouseCell = { 0 }; SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -74,7 +76,7 @@ int main() ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); - GuiGrid((Rectangle){0, 0, screenWidth, screenHeight}, "Property List", 20.0f, 2); // Draw a fancy grid + GuiGrid((Rectangle){0, 0, screenWidth, screenHeight}, "Property List", 20.0f, 2, &gridMouseCell); // Draw a fancy grid GuiDMPropertyList((Rectangle){(screenWidth - 180)/2, (screenHeight - 280)/2, 180, 280}, prop, SIZEOF(prop), &focus, &scroll); diff --git a/examples/scroll_panel/scroll_panel.c b/examples/scroll_panel/scroll_panel.c index a3cd89a..d3978cf 100644 --- a/examples/scroll_panel/scroll_panel.c +++ b/examples/scroll_panel/scroll_panel.c @@ -43,6 +43,7 @@ int main() Rectangle panelRec = { 20, 40, 200, 150 }; Rectangle panelContentRec = {0, 0, 340, 340 }; + Rectangle panelView = { 0 }; Vector2 panelScroll = { 99, -20 }; bool showContentArea = true; @@ -66,20 +67,20 @@ int main() DrawText(TextFormat("[%f, %f]", panelScroll.x, panelScroll.y), 4, 4, 20, RED); - Rectangle view = GuiScrollPanel(panelRec, NULL, panelContentRec, &panelScroll); + GuiScrollPanel(panelRec, NULL, panelContentRec, &panelScroll, &panelView); - BeginScissorMode(view.x, view.y, view.width, view.height); - GuiGrid((Rectangle){panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height}, NULL, 16, 3); + BeginScissorMode(panelView.x, panelView.y, panelView.width, panelView.height); + GuiGrid((Rectangle){panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height}, NULL, 16, 3, NULL); EndScissorMode(); if (showContentArea) DrawRectangle(panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height, Fade(RED, 0.1)); DrawStyleEditControls(); - showContentArea = GuiCheckBox((Rectangle){ 565, 80, 20, 20 }, "SHOW CONTENT AREA", showContentArea); + GuiCheckBox((Rectangle){ 565, 80, 20, 20 }, "SHOW CONTENT AREA", &showContentArea); - panelContentRec.width = GuiSliderBar((Rectangle){ 590, 385, 145, 15}, "WIDTH", TextFormat("%i", (int)panelContentRec.width), panelContentRec.width, 1, 600); - panelContentRec.height = GuiSliderBar((Rectangle){ 590, 410, 145, 15 }, "HEIGHT", TextFormat("%i", (int)panelContentRec.height), panelContentRec.height, 1, 400); + GuiSliderBar((Rectangle){ 590, 385, 145, 15}, "WIDTH", TextFormat("%i", (int)panelContentRec.width), &panelContentRec.width, 1, 600); + GuiSliderBar((Rectangle){ 590, 410, 145, 15 }, "HEIGHT", TextFormat("%i", (int)panelContentRec.height), &panelContentRec.height, 1, 400); EndDrawing(); //---------------------------------------------------------------------------------- @@ -115,8 +116,9 @@ static void DrawStyleEditControls(void) GuiSpinner((Rectangle){ 670, 240, 90, 20 }, NULL, &style, 0, 14, false); GuiSetStyle(SCROLLBAR, SLIDER_PADDING, style); - style = GuiCheckBox((Rectangle){ 565, 280, 20, 20 }, "ARROWS_VISIBLE", GuiGetStyle(SCROLLBAR, ARROWS_VISIBLE)); - GuiSetStyle(SCROLLBAR, ARROWS_VISIBLE, style); + bool scrollBarArrows = GuiGetStyle(SCROLLBAR, ARROWS_VISIBLE); + GuiCheckBox((Rectangle){ 565, 280, 20, 20 }, "ARROWS_VISIBLE", &scrollBarArrows); + GuiSetStyle(SCROLLBAR, ARROWS_VISIBLE, scrollBarArrows); style = GuiGetStyle(SCROLLBAR, SLIDER_PADDING); GuiLabel((Rectangle){ 555, 325, 110, 10 }, "SLIDER_PADDING"); @@ -129,8 +131,9 @@ static void DrawStyleEditControls(void) GuiSetStyle(SCROLLBAR, SLIDER_WIDTH, style); const char *text = GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE? "SCROLLBAR: LEFT" : "SCROLLBAR: RIGHT"; - style = GuiToggle((Rectangle){ 560, 110, 200, 35 }, text, GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE)); - GuiSetStyle(LISTVIEW, SCROLLBAR_SIDE, style); + bool toggleScrollBarSide = GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE); + GuiToggle((Rectangle){ 560, 110, 200, 35 }, text, &toggleScrollBarSide); + GuiSetStyle(LISTVIEW, SCROLLBAR_SIDE, toggleScrollBarSide); //---------------------------------------------------------- // ScrollBar style controls diff --git a/projects/VS2022/raygui.sln b/projects/VS2022/raygui.sln index 49d33e4..3122d84 100644 --- a/projects/VS2022/raygui.sln +++ b/projects/VS2022/raygui.sln @@ -19,12 +19,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "property_list", "examples\p EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scroll_panel", "examples\scroll_panel.vcxproj", "{56EE93DF-A3AF-4856-A4EC-E27358C6DA87}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "text_editor", "examples\text_editor.vcxproj", "{AB6D26C4-F5F4-420D-B15B-CE52619A5D36}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{5DC256E9-D698-4D07-8AD7-DFDAE9125DE3}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "textbox_selection", "examples\textbox_selection.vcxproj", "{B740AD57-ABF2-4421-96C0-FE220130A873}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "style_selector", "examples\style_selector.vcxproj", "{BCF5E746-FDBF-4CAC-9B95-44FE9A498430}" EndProject Global @@ -167,38 +163,6 @@ Global {56EE93DF-A3AF-4856-A4EC-E27358C6DA87}.Release|x64.Build.0 = Release|x64 {56EE93DF-A3AF-4856-A4EC-E27358C6DA87}.Release|x86.ActiveCfg = Release|Win32 {56EE93DF-A3AF-4856-A4EC-E27358C6DA87}.Release|x86.Build.0 = Release|Win32 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Debug.DLL|x64.ActiveCfg = Debug.DLL|x64 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Debug.DLL|x64.Build.0 = Debug.DLL|x64 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Debug.DLL|x86.ActiveCfg = Debug.DLL|Win32 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Debug.DLL|x86.Build.0 = Debug.DLL|Win32 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Debug|x64.ActiveCfg = Debug|x64 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Debug|x64.Build.0 = Debug|x64 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Debug|x86.ActiveCfg = Debug|Win32 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Debug|x86.Build.0 = Debug|Win32 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Release.DLL|x64.ActiveCfg = Release.DLL|x64 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Release.DLL|x64.Build.0 = Release.DLL|x64 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Release.DLL|x86.ActiveCfg = Release.DLL|Win32 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Release.DLL|x86.Build.0 = Release.DLL|Win32 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Release|x64.ActiveCfg = Release|x64 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Release|x64.Build.0 = Release|x64 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Release|x86.ActiveCfg = Release|Win32 - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36}.Release|x86.Build.0 = Release|Win32 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Debug.DLL|x64.ActiveCfg = Debug.DLL|x64 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Debug.DLL|x64.Build.0 = Debug.DLL|x64 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Debug.DLL|x86.ActiveCfg = Debug.DLL|Win32 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Debug.DLL|x86.Build.0 = Debug.DLL|Win32 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Debug|x64.ActiveCfg = Debug|x64 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Debug|x64.Build.0 = Debug|x64 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Debug|x86.ActiveCfg = Debug|Win32 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Debug|x86.Build.0 = Debug|Win32 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Release.DLL|x64.ActiveCfg = Release.DLL|x64 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Release.DLL|x64.Build.0 = Release.DLL|x64 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Release.DLL|x86.ActiveCfg = Release.DLL|Win32 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Release.DLL|x86.Build.0 = Release.DLL|Win32 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Release|x64.ActiveCfg = Release|x64 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Release|x64.Build.0 = Release|x64 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Release|x86.ActiveCfg = Release|Win32 - {B740AD57-ABF2-4421-96C0-FE220130A873}.Release|x86.Build.0 = Release|Win32 {BCF5E746-FDBF-4CAC-9B95-44FE9A498430}.Debug.DLL|x64.ActiveCfg = Debug.DLL|x64 {BCF5E746-FDBF-4CAC-9B95-44FE9A498430}.Debug.DLL|x64.Build.0 = Debug.DLL|x64 {BCF5E746-FDBF-4CAC-9B95-44FE9A498430}.Debug.DLL|x86.ActiveCfg = Debug.DLL|Win32 @@ -227,8 +191,6 @@ Global {FFDA97F5-4BAF-410A-AE87-0C8E3CB8C0D8} = {5DC256E9-D698-4D07-8AD7-DFDAE9125DE3} {D28301C9-C293-4F41-9F58-F2609F33134E} = {5DC256E9-D698-4D07-8AD7-DFDAE9125DE3} {56EE93DF-A3AF-4856-A4EC-E27358C6DA87} = {5DC256E9-D698-4D07-8AD7-DFDAE9125DE3} - {AB6D26C4-F5F4-420D-B15B-CE52619A5D36} = {5DC256E9-D698-4D07-8AD7-DFDAE9125DE3} - {B740AD57-ABF2-4421-96C0-FE220130A873} = {5DC256E9-D698-4D07-8AD7-DFDAE9125DE3} {BCF5E746-FDBF-4CAC-9B95-44FE9A498430} = {5DC256E9-D698-4D07-8AD7-DFDAE9125DE3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/src/raygui.h b/src/raygui.h index e6c93d5..b8d90c6 100644 --- a/src/raygui.h +++ b/src/raygui.h @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raygui v3.6 - A simple and easy-to-use immediate-mode gui library +* raygui v4.0-dev - A simple and easy-to-use immediate-mode gui library * * DESCRIPTION: * raygui is a tools-dev-focused immediate-mode-gui library based on raylib but also @@ -130,6 +130,23 @@ * Draw text bounds rectangles for debug * * VERSIONS HISTORY: +* 4.0 (xx-Jun-2023) REDESIGNED: GuiScrollPanel(), get parameters by reference and return result value +* REDESIGNED: GuiToggleGroup(), get parameters by reference and return result value +* REDESIGNED: GuiComboBox(), get parameters by reference and return result value +* REDESIGNED: GuiCheckBox(), get parameters by reference and return result value +* REDESIGNED: GuiSlider(), get parameters by reference and return result value +* REDESIGNED: GuiSliderBar(), get parameters by reference and return result value +* REDESIGNED: GuiProgressBar(), get parameters by reference and return result value +* REDESIGNED: GuiListView(), get parameters by reference and return result value +* REDESIGNED: GuiColorPicker(), get parameters by reference and return result value +* REDESIGNED: GuiColorPanel(), get parameters by reference and return result value +* REDESIGNED: GuiColorBarAlpha(), get parameters by reference and return result value +* REDESIGNED: GuiColorBarHue(), get parameters by reference and return result value +* REDESIGNED: GuiGrid(), get parameters by reference and return result value +* REDESIGNED: GuiGrid(), added extra parameter +* REDESIGNED: GuiListViewEx(), change parameters order +* REDESIGNED: All controls return result as int value +* * 3.6 (10-May-2023) ADDED: New icon: SAND_TIMER * ADDED: GuiLoadStyleFromMemory() (binary only) * REVIEWED: GuiScrollBar() horizontal movement key @@ -245,10 +262,10 @@ #ifndef RAYGUI_H #define RAYGUI_H -#define RAYGUI_VERSION_MAJOR 3 -#define RAYGUI_VERSION_MINOR 6 +#define RAYGUI_VERSION_MAJOR 4 +#define RAYGUI_VERSION_MINOR 0 #define RAYGUI_VERSION_PATCH 0 -#define RAYGUI_VERSION "3.6" +#define RAYGUI_VERSION "4.0-dev" #if !defined(RAYGUI_STANDALONE) #include "raylib.h" @@ -563,45 +580,8 @@ RAYGUIAPI void GuiSetFont(Font font); // Set gui custo RAYGUIAPI Font GuiGetFont(void); // Get gui custom font (global state) // Style set/get functions -RAYGUIAPI void GuiSetStyle(int control, int property, int value); // Set one style property -RAYGUIAPI int GuiGetStyle(int control, int property); // Get one style property - -// Container/separator controls, useful for controls organization -RAYGUIAPI bool GuiWindowBox(Rectangle bounds, const char *title); // Window Box control, shows a window that can be closed -RAYGUIAPI void GuiGroupBox(Rectangle bounds, const char *text); // Group Box control with text name -RAYGUIAPI void GuiLine(Rectangle bounds, const char *text); // Line separator control, could contain text -RAYGUIAPI void GuiPanel(Rectangle bounds, const char *text); // Panel control, useful to group controls -RAYGUIAPI int GuiTabBar(Rectangle bounds, const char **text, int count, int *active); // Tab Bar control, returns TAB to be closed or -1 -RAYGUIAPI Rectangle GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector2 *scroll); // Scroll Panel control - -// Basic controls set -RAYGUIAPI void GuiLabel(Rectangle bounds, const char *text); // Label control, shows text -RAYGUIAPI bool GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked -RAYGUIAPI bool GuiLabelButton(Rectangle bounds, const char *text); // Label button control, show true when clicked -RAYGUIAPI bool GuiToggle(Rectangle bounds, const char *text, bool active); // Toggle Button control, returns true when active -RAYGUIAPI int GuiToggleGroup(Rectangle bounds, const char *text, int active); // Toggle Group control, returns active toggle index -RAYGUIAPI bool GuiCheckBox(Rectangle bounds, const char *text, bool checked); // Check Box control, returns true when active -RAYGUIAPI int GuiComboBox(Rectangle bounds, const char *text, int active); // Combo Box control, returns selected item index -RAYGUIAPI bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode); // Dropdown Box control, returns selected item -RAYGUIAPI bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Spinner control, returns selected value -RAYGUIAPI bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers -RAYGUIAPI bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control, updates input text -RAYGUIAPI float GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); // Slider control, returns selected value -RAYGUIAPI float GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); // Slider Bar control, returns selected value -RAYGUIAPI float GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); // Progress Bar control, shows current progress value -RAYGUIAPI void GuiStatusBar(Rectangle bounds, const char *text); // Status Bar control, shows info text -RAYGUIAPI void GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders -RAYGUIAPI Vector2 GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs); // Grid control, returns mouse cell position - -// Advance controls set -RAYGUIAPI int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int active); // List View control, returns selected list item index -RAYGUIAPI int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active); // List View with extended parameters -RAYGUIAPI int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons); // Message Box control, displays a message -RAYGUIAPI int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text, int textMaxSize, int *secretViewActive); // Text Input Box control, ask for text, supports secret -RAYGUIAPI Color GuiColorPicker(Rectangle bounds, const char *text, Color color); // Color Picker control (multiple color controls) -RAYGUIAPI Color GuiColorPanel(Rectangle bounds, const char *text, Color color); // Color Panel control -RAYGUIAPI float GuiColorBarAlpha(Rectangle bounds, const char *text, float alpha); // Color Bar Alpha control -RAYGUIAPI float GuiColorBarHue(Rectangle bounds, const char *text, float value); // Color Bar Hue control +RAYGUIAPI void GuiSetStyle(int control, int property, int value); // Set one style property +RAYGUIAPI int GuiGetStyle(int control, int property); // Get one style property // Styles loading functions RAYGUIAPI void GuiLoadStyle(const char *fileName); // Load style file over global style variable (.rgs) @@ -614,12 +594,58 @@ RAYGUIAPI void GuiSetTooltip(const char *tooltip); // Set tooltip s // Icons functionality RAYGUIAPI const char *GuiIconText(int iconId, const char *text); // Get text with icon id prepended (if supported) - #if !defined(RAYGUI_NO_ICONS) RAYGUIAPI void GuiSetIconScale(int scale); // Set default icon drawing size RAYGUIAPI unsigned int *GuiGetIcons(void); // Get raygui icons data pointer RAYGUIAPI char **GuiLoadIcons(const char *fileName, bool loadIconsName); // Load raygui icons file (.rgi) into internal icons data RAYGUIAPI void GuiDrawIcon(int iconId, int posX, int posY, int pixelSize, Color color); // Draw icon using pixel size at specified position +#endif + + +// Controls +//---------------------------------------------------------------------------------------------------------- +// Container/separator controls, useful for controls organization +RAYGUIAPI int GuiWindowBox(Rectangle bounds, const char *title); // Window Box control, shows a window that can be closed +RAYGUIAPI int GuiGroupBox(Rectangle bounds, const char *text); // Group Box control with text name +RAYGUIAPI int GuiLine(Rectangle bounds, const char *text); // Line separator control, could contain text +RAYGUIAPI int GuiPanel(Rectangle bounds, const char *text); // Panel control, useful to group controls +RAYGUIAPI int GuiTabBar(Rectangle bounds, const char **text, int count, int *active); // Tab Bar control, returns TAB to be closed or -1 +RAYGUIAPI int GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector2 *scroll, Rectangle *view); // Scroll Panel control + +// Basic controls set +RAYGUIAPI int GuiLabel(Rectangle bounds, const char *text); // Label control, shows text +RAYGUIAPI int GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked +RAYGUIAPI int GuiLabelButton(Rectangle bounds, const char *text); // Label button control, show true when clicked +RAYGUIAPI int GuiToggle(Rectangle bounds, const char *text, bool *active); // Toggle Button control, returns true when active +RAYGUIAPI int GuiToggleGroup(Rectangle bounds, const char *text, int *active); // Toggle Group control, returns active toggle index +RAYGUIAPI int GuiCheckBox(Rectangle bounds, const char *text, bool *checked); // Check Box control, returns true when active +RAYGUIAPI int GuiComboBox(Rectangle bounds, const char *text, int *active); // Combo Box control, returns selected item index + +RAYGUIAPI int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode); // Dropdown Box control, returns selected item +RAYGUIAPI int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Spinner control, returns selected value +RAYGUIAPI int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers +RAYGUIAPI int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control, updates input text + +RAYGUIAPI int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Slider control, returns selected value +RAYGUIAPI int GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Slider Bar control, returns selected value +RAYGUIAPI int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Progress Bar control, shows current progress value +RAYGUIAPI int GuiStatusBar(Rectangle bounds, const char *text); // Status Bar control, shows info text +RAYGUIAPI int GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders +RAYGUIAPI int GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs, Vector2 *mouseCell); // Grid control, returns mouse cell position + +// Advance controls set +RAYGUIAPI int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int *active); // List View control, returns selected list item index +RAYGUIAPI int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollIndex, int *active, int *focus); // List View with extended parameters +RAYGUIAPI int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons); // Message Box control, displays a message +RAYGUIAPI int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text, int textMaxSize, bool *secretViewActive); // Text Input Box control, ask for text, supports secret +RAYGUIAPI int GuiColorPicker(Rectangle bounds, const char *text, Color *color); // Color Picker control (multiple color controls) +RAYGUIAPI int GuiColorPanel(Rectangle bounds, const char *text, Color *color); // Color Panel control +RAYGUIAPI int GuiColorBarAlpha(Rectangle bounds, const char *text, float *alpha); // Color Bar Alpha control +RAYGUIAPI int GuiColorBarHue(Rectangle bounds, const char *text, float *value); // Color Bar Hue control +//---------------------------------------------------------------------------------------------------------- + + +#if !defined(RAYGUI_NO_ICONS) #if !defined(RAYGUI_CUSTOM_ICONS) //---------------------------------------------------------------------------------- @@ -1426,7 +1452,7 @@ int GuiGetStyle(int control, int property) //---------------------------------------------------------------------------------- // Window Box control -bool GuiWindowBox(Rectangle bounds, const char *title) +int GuiWindowBox(Rectangle bounds, const char *title) { // Window title bar height (including borders) // NOTE: This define is also used by GuiMessageBox() and GuiTextInputBox() @@ -1434,8 +1460,8 @@ bool GuiWindowBox(Rectangle bounds, const char *title) #define RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT 24 #endif + int result = 0; //GuiState state = guiState; - bool clicked = false; int statusBarHeight = RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT; @@ -1464,22 +1490,23 @@ bool GuiWindowBox(Rectangle bounds, const char *title) #if defined(RAYGUI_NO_ICONS) clicked = GuiButton(closeButtonRec, "x"); #else - clicked = GuiButton(closeButtonRec, GuiIconText(ICON_CROSS_SMALL, NULL)); + result = GuiButton(closeButtonRec, GuiIconText(ICON_CROSS_SMALL, NULL)); #endif GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment); //-------------------------------------------------------------------- - return clicked; + return result; // Window close button clicked: result = 1 } // Group Box control with text name -void GuiGroupBox(Rectangle bounds, const char *text) +int GuiGroupBox(Rectangle bounds, const char *text) { #if !defined(RAYGUI_GROUPBOX_LINE_THICK) #define RAYGUI_GROUPBOX_LINE_THICK 1 #endif + int result = 0; GuiState state = guiState; // Draw control @@ -1490,10 +1517,12 @@ void GuiGroupBox(Rectangle bounds, const char *text) GuiLine(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, bounds.width, (float)GuiGetStyle(DEFAULT, TEXT_SIZE) }, text); //-------------------------------------------------------------------- + + return result; } // Line control -void GuiLine(Rectangle bounds, const char *text) +int GuiLine(Rectangle bounds, const char *text) { #if !defined(RAYGUI_LINE_ORIGIN_SIZE) #define RAYGUI_LINE_MARGIN_TEXT 12 @@ -1502,6 +1531,7 @@ void GuiLine(Rectangle bounds, const char *text) #define RAYGUI_LINE_TEXT_PADDING 4 #endif + int result = 0; GuiState state = guiState; Color color = Fade(GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED : LINE_COLOR)), guiAlpha); @@ -1523,15 +1553,18 @@ void GuiLine(Rectangle bounds, const char *text) GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + 12 + textBounds.width + 4, bounds.y + bounds.height/2, bounds.width - textBounds.width - RAYGUI_LINE_MARGIN_TEXT - RAYGUI_LINE_TEXT_PADDING, 1 }, 0, BLANK, color); } //-------------------------------------------------------------------- + + return result; } // Panel control -void GuiPanel(Rectangle bounds, const char *text) +int GuiPanel(Rectangle bounds, const char *text) { #if !defined(RAYGUI_PANEL_BORDER_WIDTH) #define RAYGUI_PANEL_BORDER_WIDTH 1 #endif + int result = 0; GuiState state = guiState; // Text will be drawn as a header bar (if provided) @@ -1552,6 +1585,8 @@ void GuiPanel(Rectangle bounds, const char *text) GuiDrawRectangle(bounds, RAYGUI_PANEL_BORDER_WIDTH, Fade(GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED: LINE_COLOR)), guiAlpha), Fade(GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BASE_COLOR_DISABLED : BACKGROUND_COLOR)), guiAlpha)); //-------------------------------------------------------------------- + + return result; } // Tab Bar control @@ -1560,9 +1595,9 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active) { #define RAYGUI_TABBAR_ITEM_WIDTH 160 + int result = -1; GuiState state = guiState; - int closing = -1; Rectangle tabBounds = { bounds.x, bounds.y, RAYGUI_TABBAR_ITEM_WIDTH, bounds.height }; if (*active < 0) *active = 0; @@ -1572,6 +1607,8 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active) offsetX = (*active + 2)*RAYGUI_TABBAR_ITEM_WIDTH - GetScreenWidth(); if (offsetX < 0) offsetX = 0; + bool toggle = false; // Required for individual toggles + // Draw control //-------------------------------------------------------------------- for (int i = 0; i < count; i++) @@ -1585,8 +1622,19 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active) int textPadding = GuiGetStyle(TOGGLE, TEXT_PADDING); GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT); GuiSetStyle(TOGGLE, TEXT_PADDING, 8); - if (i == *active) GuiToggle(tabBounds, GuiIconText(12, text[i]), true); - else if (GuiToggle(tabBounds, GuiIconText(12, text[i]), false) == true) *active = i; + + if (i == (*active)) + { + toggle = true; + GuiToggle(tabBounds, GuiIconText(12, text[i]), &toggle); + } + else + { + toggle = false; + GuiToggle(tabBounds, GuiIconText(12, text[i]), &toggle); + if (toggle) *active = i; + } + GuiSetStyle(TOGGLE, TEXT_PADDING, textPadding); GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, textAlignment); @@ -1597,9 +1645,9 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active) GuiSetStyle(BUTTON, BORDER_WIDTH, 1); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); #if defined(RAYGUI_NO_ICONS) - if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, "x")) closing = i; + if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, "x")) result = i; #else - if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, GuiIconText(ICON_CROSS_SMALL, NULL))) closing = i; + if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, GuiIconText(ICON_CROSS_SMALL, NULL))) result = i; #endif GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment); @@ -1610,12 +1658,13 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active) GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height - 1, bounds.width, 1 }, 0, BLANK, GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_NORMAL))); //-------------------------------------------------------------------- - return closing; // Return closing tab requested + return result; // Return as result the current TAB closing requested } // Scroll Panel control -Rectangle GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector2 *scroll) +int GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector2 *scroll, Rectangle *view) { + int result = 0; GuiState state = guiState; Vector2 scrollPos = { 0.0f, 0.0f }; @@ -1645,13 +1694,13 @@ Rectangle GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Rectangle verticalScrollBar = { (float)((GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? (float)bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH) : (float)bounds.x + bounds.width - verticalScrollBarWidth - GuiGetStyle(DEFAULT, BORDER_WIDTH)), (float)bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), (float)verticalScrollBarWidth, (float)bounds.height - horizontalScrollBarWidth - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) }; // Calculate view area (area without the scrollbars) - Rectangle view = (GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? + *view = (GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? RAYGUI_CLITERAL(Rectangle){ bounds.x + verticalScrollBarWidth + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - verticalScrollBarWidth, bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - horizontalScrollBarWidth } : RAYGUI_CLITERAL(Rectangle){ bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - verticalScrollBarWidth, bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - horizontalScrollBarWidth }; // Clip view area to the actual content size - if (view.width > content.width) view.width = content.width; - if (view.height > content.height) view.height = content.height; + if (view->width > content.width) view->width = content.width; + if (view->height > content.height) view->height = content.height; float horizontalMin = hasHorizontalScrollBar? ((GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? (float)-verticalScrollBarWidth : 0) - (float)GuiGetStyle(DEFAULT, BORDER_WIDTH) : (((float)GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? (float)-verticalScrollBarWidth : 0) - (float)GuiGetStyle(DEFAULT, BORDER_WIDTH); float horizontalMax = hasHorizontalScrollBar? content.width - bounds.width + (float)verticalScrollBarWidth + GuiGetStyle(DEFAULT, BORDER_WIDTH) - (((float)GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? (float)verticalScrollBarWidth : 0) : (float)-GuiGetStyle(DEFAULT, BORDER_WIDTH); @@ -1741,12 +1790,13 @@ Rectangle GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, if (scroll != NULL) *scroll = scrollPos; - return view; + return result; } // Label control -void GuiLabel(Rectangle bounds, const char *text) +int GuiLabel(Rectangle bounds, const char *text) { + int result = 0; GuiState state = guiState; // Update control @@ -1758,13 +1808,15 @@ void GuiLabel(Rectangle bounds, const char *text) //-------------------------------------------------------------------- GuiDrawText(text, GetTextBounds(LABEL, bounds), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(LABEL, TEXT + (state*3))), guiAlpha)); //-------------------------------------------------------------------- + + return result; } // Button control, returns true when clicked -bool GuiButton(Rectangle bounds, const char *text) +int GuiButton(Rectangle bounds, const char *text) { + int result = 0; GuiState state = guiState; - bool pressed = false; // Update control //-------------------------------------------------------------------- @@ -1778,7 +1830,7 @@ bool GuiButton(Rectangle bounds, const char *text) if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED; else state = STATE_FOCUSED; - if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) pressed = true; + if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) result = 1; } } //-------------------------------------------------------------------- @@ -1791,11 +1843,11 @@ bool GuiButton(Rectangle bounds, const char *text) if (state == STATE_FOCUSED) GuiTooltip(bounds); //------------------------------------------------------------------ - return pressed; + return result; // Button pressed: result = 1 } // Label button control -bool GuiLabelButton(Rectangle bounds, const char *text) +int GuiLabelButton(Rectangle bounds, const char *text) { GuiState state = guiState; bool pressed = false; @@ -1830,8 +1882,9 @@ bool GuiLabelButton(Rectangle bounds, const char *text) } // Toggle Button control, returns true when active -bool GuiToggle(Rectangle bounds, const char *text, bool active) +int GuiToggle(Rectangle bounds, const char *text, bool *active) { + int result = 0; GuiState state = guiState; // Update control @@ -1847,7 +1900,7 @@ bool GuiToggle(Rectangle bounds, const char *text, bool active) else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) { state = STATE_NORMAL; - active = !active; + *active = !(*active); } else state = STATE_FOCUSED; } @@ -1858,8 +1911,8 @@ bool GuiToggle(Rectangle bounds, const char *text, bool active) //-------------------------------------------------------------------- if (state == STATE_NORMAL) { - GuiDrawRectangle(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, (active? BORDER_COLOR_PRESSED : (BORDER + state*3)))), guiAlpha), Fade(GetColor(GuiGetStyle(TOGGLE, (active? BASE_COLOR_PRESSED : (BASE + state*3)))), guiAlpha)); - GuiDrawText(text, GetTextBounds(TOGGLE, bounds), GuiGetStyle(TOGGLE, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(TOGGLE, (active? TEXT_COLOR_PRESSED : (TEXT + state*3)))), guiAlpha)); + GuiDrawRectangle(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TOGGLE, ((*active)? BORDER_COLOR_PRESSED : (BORDER + state*3)))), guiAlpha), Fade(GetColor(GuiGetStyle(TOGGLE, ((*active)? BASE_COLOR_PRESSED : (BASE + state*3)))), guiAlpha)); + GuiDrawText(text, GetTextBounds(TOGGLE, bounds), GuiGetStyle(TOGGLE, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(TOGGLE, ((*active)? TEXT_COLOR_PRESSED : (TEXT + state*3)))), guiAlpha)); } else { @@ -1870,18 +1923,21 @@ bool GuiToggle(Rectangle bounds, const char *text, bool active) if (state == STATE_FOCUSED) GuiTooltip(bounds); //-------------------------------------------------------------------- - return active; + return result; } // Toggle Group control, returns toggled button codepointIndex -int GuiToggleGroup(Rectangle bounds, const char *text, int active) +int GuiToggleGroup(Rectangle bounds, const char *text, int *active) { #if !defined(RAYGUI_TOGGLEGROUP_MAX_ITEMS) #define RAYGUI_TOGGLEGROUP_MAX_ITEMS 32 #endif + int result = 0; float initBoundsX = bounds.x; + bool toggle = false; // Required for individual toggles + // Get substrings items from text (items pointers) int rows[RAYGUI_TOGGLEGROUP_MAX_ITEMS] = { 0 }; int itemCount = 0; @@ -1898,18 +1954,28 @@ int GuiToggleGroup(Rectangle bounds, const char *text, int active) prevRow = rows[i]; } - if (i == active) GuiToggle(bounds, items[i], true); - else if (GuiToggle(bounds, items[i], false) == true) active = i; + if (i == (*active)) + { + toggle = true; + GuiToggle(bounds, items[i], &toggle); + } + else + { + toggle = false; + GuiToggle(bounds, items[i], &toggle); + if (toggle) *active = i; + } bounds.x += (bounds.width + GuiGetStyle(TOGGLE, GROUP_PADDING)); } - return active; + return result; } // Check Box control, returns true when active -bool GuiCheckBox(Rectangle bounds, const char *text, bool checked) +int GuiCheckBox(Rectangle bounds, const char *text, bool *checked) { + int result = 0; GuiState state = guiState; Rectangle textBounds = { 0 }; @@ -1942,7 +2008,7 @@ bool GuiCheckBox(Rectangle bounds, const char *text, bool checked) if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED; else state = STATE_FOCUSED; - if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) checked = !checked; + if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) *checked = !(*checked); } } //-------------------------------------------------------------------- @@ -1951,7 +2017,7 @@ bool GuiCheckBox(Rectangle bounds, const char *text, bool checked) //-------------------------------------------------------------------- GuiDrawRectangle(bounds, GuiGetStyle(CHECKBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(CHECKBOX, BORDER + (state*3))), guiAlpha), BLANK); - if (checked) + if (*checked) { Rectangle check = { bounds.x + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, CHECK_PADDING), bounds.y + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, CHECK_PADDING), @@ -1963,12 +2029,13 @@ bool GuiCheckBox(Rectangle bounds, const char *text, bool checked) GuiDrawText(text, textBounds, (GuiGetStyle(CHECKBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT)? TEXT_ALIGN_LEFT : TEXT_ALIGN_RIGHT, Fade(GetColor(GuiGetStyle(LABEL, TEXT + (state*3))), guiAlpha)); //-------------------------------------------------------------------- - return checked; + return result; } // Combo Box control, returns selected item codepointIndex -int GuiComboBox(Rectangle bounds, const char *text, int active) +int GuiComboBox(Rectangle bounds, const char *text, int *active) { + int result = 0; GuiState state = guiState; bounds.width -= (GuiGetStyle(COMBOBOX, COMBO_BUTTON_WIDTH) + GuiGetStyle(COMBOBOX, COMBO_BUTTON_SPACING)); @@ -1980,8 +2047,8 @@ int GuiComboBox(Rectangle bounds, const char *text, int active) int itemCount = 0; const char **items = GuiTextSplit(text, ';', &itemCount, NULL); - if (active < 0) active = 0; - else if (active > itemCount - 1) active = itemCount - 1; + if (*active < 0) *active = 0; + else if (*active > (itemCount - 1)) *active = itemCount - 1; // Update control //-------------------------------------------------------------------- @@ -1994,8 +2061,8 @@ int GuiComboBox(Rectangle bounds, const char *text, int active) { if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { - active += 1; - if (active >= itemCount) active = 0; + *active += 1; + if (*active >= itemCount) *active = 0; // Cyclic combobox } if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED; @@ -2008,7 +2075,7 @@ int GuiComboBox(Rectangle bounds, const char *text, int active) //-------------------------------------------------------------------- // Draw combo box main GuiDrawRectangle(bounds, GuiGetStyle(COMBOBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COMBOBOX, BORDER + (state*3))), guiAlpha), Fade(GetColor(GuiGetStyle(COMBOBOX, BASE + (state*3))), guiAlpha)); - GuiDrawText(items[active], GetTextBounds(COMBOBOX, bounds), GuiGetStyle(COMBOBOX, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(COMBOBOX, TEXT + (state*3))), guiAlpha)); + GuiDrawText(items[*active], GetTextBounds(COMBOBOX, bounds), GuiGetStyle(COMBOBOX, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(COMBOBOX, TEXT + (state*3))), guiAlpha)); // Draw selector using a custom button // NOTE: BORDER_WIDTH and TEXT_ALIGNMENT forced values @@ -2017,20 +2084,22 @@ int GuiComboBox(Rectangle bounds, const char *text, int active) GuiSetStyle(BUTTON, BORDER_WIDTH, 1); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); - GuiButton(selector, TextFormat("%i/%i", active + 1, itemCount)); + GuiButton(selector, TextFormat("%i/%i", *active + 1, itemCount)); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlign); GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth); //-------------------------------------------------------------------- - return active; + return result; } // Dropdown Box control // NOTE: Returns mouse click -bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode) +int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode) { + int result = 0; GuiState state = guiState; + int itemSelected = *active; int itemFocused = -1; @@ -2043,8 +2112,6 @@ bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMo Rectangle itemBounds = bounds; - bool pressed = false; // Check mouse button pressed - // Update control //-------------------------------------------------------------------- if ((state != STATE_DISABLED) && (editMode || !guiLocked) && (itemCount > 1) && !guiSliderDragging) @@ -2058,11 +2125,11 @@ bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMo // Check if mouse has been pressed or released outside limits if (!CheckCollisionPointRec(mousePoint, boundsOpen)) { - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) pressed = true; + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) result = 1; } // Check if already selected item has been pressed again - if (CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true; + if (CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) result = 1; // Check focused and selected item for (int i = 0; i < itemCount; i++) @@ -2076,7 +2143,7 @@ bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMo if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) { itemSelected = i; - pressed = true; // Item selected, change to editMode = false + result = 1; // Item selected } break; } @@ -2090,7 +2157,7 @@ bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMo { if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { - pressed = true; + result = 1; state = STATE_PRESSED; } else state = STATE_FOCUSED; @@ -2139,18 +2206,24 @@ bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMo //-------------------------------------------------------------------- *active = itemSelected; - return pressed; + + // TODO: Use result to return more internal states: mouse-press out-of-bounds, mouse-press over selected-item... + return result; // Mouse click: result = 1 } // Text Box control // NOTE: Returns true on ENTER pressed (useful for data validation) -bool GuiTextBox(Rectangle bounds, char *text, int bufferSize, bool editMode) +int GuiTextBox(Rectangle bounds, char *text, int bufferSize, bool editMode) { - #define AUTO_CURSOR_COOLDOWN 40 // Frames to wait for autocursor movement - #define AUTO_CURSOR_DELAY 1 // Frames delay for autocursor movement + #if !defined(RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN) + #define RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN 40 // Frames to wait for autocursor movement + #endif + #if !defined(RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) + #define RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY 1 // Frames delay for autocursor movement + #endif + int result = 0; GuiState state = guiState; - bool pressed = false; Rectangle textBounds = GetTextBounds(TEXTBOX, bounds); int textWidth = GetTextWidth(text) - GetTextWidth(text + textBoxCursorIndex); @@ -2254,11 +2327,11 @@ bool GuiTextBox(Rectangle bounds, char *text, int bufferSize, bool editMode) } // Delete codepoint from text, after current cursor position - if ((textLength > textBoxCursorIndex) && (IsKeyPressed(KEY_DELETE) || (IsKeyDown(KEY_DELETE) && (autoCursorCooldownCounter >= AUTO_CURSOR_COOLDOWN)))) + if ((textLength > textBoxCursorIndex) && (IsKeyPressed(KEY_DELETE) || (IsKeyDown(KEY_DELETE) && (autoCursorCooldownCounter >= RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN)))) { autoCursorDelayCounter++; - if (IsKeyPressed(KEY_DELETE) || (autoCursorDelayCounter%AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames + if (IsKeyPressed(KEY_DELETE) || (autoCursorDelayCounter%RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames { int nextCodepointSize = 0; GetCodepointNext(text + textBoxCursorIndex, &nextCodepointSize); @@ -2274,11 +2347,11 @@ bool GuiTextBox(Rectangle bounds, char *text, int bufferSize, bool editMode) } // Delete codepoint from text, before current cursor position - if ((textLength > 0) && (IsKeyPressed(KEY_BACKSPACE) || (IsKeyDown(KEY_BACKSPACE) && (autoCursorCooldownCounter >= AUTO_CURSOR_COOLDOWN)))) + if ((textLength > 0) && (IsKeyPressed(KEY_BACKSPACE) || (IsKeyDown(KEY_BACKSPACE) && (autoCursorCooldownCounter >= RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN)))) { autoCursorDelayCounter++; - if (IsKeyPressed(KEY_BACKSPACE) || (autoCursorDelayCounter%AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames + if (IsKeyPressed(KEY_BACKSPACE) || (autoCursorDelayCounter%RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames { int prevCodepointSize = 0; GetCodepointPrevious(text + textBoxCursorIndex, &prevCodepointSize); @@ -2300,11 +2373,11 @@ bool GuiTextBox(Rectangle bounds, char *text, int bufferSize, bool editMode) // Move cursor position with keys //if (IsKeyDown(KEY_LEFT) && autoCursorMode) - if (IsKeyPressed(KEY_LEFT) || (IsKeyDown(KEY_LEFT) && (autoCursorCooldownCounter > AUTO_CURSOR_COOLDOWN))) + if (IsKeyPressed(KEY_LEFT) || (IsKeyDown(KEY_LEFT) && (autoCursorCooldownCounter > RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN))) { autoCursorDelayCounter++; - if (IsKeyPressed(KEY_LEFT) || (autoCursorDelayCounter%AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames + if (IsKeyPressed(KEY_LEFT) || (autoCursorDelayCounter%RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames { int prevCodepointSize = 0; GetCodepointPrevious(text + textBoxCursorIndex, &prevCodepointSize); @@ -2312,11 +2385,11 @@ bool GuiTextBox(Rectangle bounds, char *text, int bufferSize, bool editMode) if (textBoxCursorIndex >= prevCodepointSize) textBoxCursorIndex -= prevCodepointSize; } } - else if (IsKeyPressed(KEY_RIGHT) || (IsKeyDown(KEY_RIGHT) && (autoCursorCooldownCounter > AUTO_CURSOR_COOLDOWN))) + else if (IsKeyPressed(KEY_RIGHT) || (IsKeyDown(KEY_RIGHT) && (autoCursorCooldownCounter > RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN))) { autoCursorDelayCounter++; - if (IsKeyPressed(KEY_RIGHT) || (autoCursorDelayCounter%AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames + if (IsKeyPressed(KEY_RIGHT) || (autoCursorDelayCounter%RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames { int nextCodepointSize = 0; GetCodepointNext(text + textBoxCursorIndex, &nextCodepointSize); @@ -2339,8 +2412,8 @@ bool GuiTextBox(Rectangle bounds, char *text, int bufferSize, bool editMode) if ((!multiline && IsKeyPressed(KEY_ENTER)) || (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) { - pressed = true; // Exiting edit mode textBoxCursorIndex = 0; // GLOBAL: Reset the shared cursor index + result = 1; } } else @@ -2351,8 +2424,8 @@ bool GuiTextBox(Rectangle bounds, char *text, int bufferSize, bool editMode) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { - pressed = true; // Entering edit mode textBoxCursorIndex = strlen(text); // GLOBAL: Place cursor index to the end of current text + result = 1; } } } @@ -2384,7 +2457,7 @@ bool GuiTextBox(Rectangle bounds, char *text, int bufferSize, bool editMode) else if (state == STATE_FOCUSED) GuiTooltip(bounds); //-------------------------------------------------------------------- - return pressed; + return result; // Mouse button pressed: result = 1 } /* @@ -2409,11 +2482,11 @@ bool GuiTextBoxMulti(Rectangle bounds, char *text, int bufferSize, bool editMode */ // Spinner control, returns selected value -bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) +int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) { + int result = 1; GuiState state = guiState; - bool pressed = false; int tempValue = *value; Rectangle spinner = { bounds.x + GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH) + GuiGetStyle(SPINNER, SPIN_BUTTON_SPACING), bounds.y, @@ -2462,7 +2535,7 @@ bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, in // Draw control //-------------------------------------------------------------------- - pressed = GuiValueBox(spinner, NULL, &tempValue, minValue, maxValue, editMode); + result = GuiValueBox(spinner, NULL, &tempValue, minValue, maxValue, editMode); // Draw value selector custom buttons // NOTE: BORDER_WIDTH and TEXT_ALIGNMENT forced values @@ -2479,19 +2552,19 @@ bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, in //-------------------------------------------------------------------- *value = tempValue; - return pressed; + return result; } // Value Box control, updates input text with numbers // NOTE: Requires static variables: frameCounter -bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) +int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) { #if !defined(RAYGUI_VALUEBOX_MAX_CHARS) #define RAYGUI_VALUEBOX_MAX_CHARS 32 #endif + int result = 0; GuiState state = guiState; - bool pressed = false; char textValue[RAYGUI_VALUEBOX_MAX_CHARS + 1] = "\0"; sprintf(textValue, "%i", *value); @@ -2552,7 +2625,7 @@ bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, i //if (*value > maxValue) *value = maxValue; //else if (*value < minValue) *value = minValue; - if (IsKeyPressed(KEY_ENTER) || (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) pressed = true; + if (IsKeyPressed(KEY_ENTER) || (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) result = 1; } else { @@ -2562,7 +2635,7 @@ bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, i if (CheckCollisionPointRec(mousePoint, bounds)) { state = STATE_FOCUSED; - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true; + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) result = 1; } } } @@ -2590,16 +2663,17 @@ bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, i GuiDrawText(text, textBounds, (GuiGetStyle(VALUEBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT)? TEXT_ALIGN_LEFT : TEXT_ALIGN_RIGHT, Fade(GetColor(GuiGetStyle(LABEL, TEXT + (state*3))), guiAlpha)); //-------------------------------------------------------------------- - return pressed; + return result; } // Slider control with pro parameters // NOTE: Other GuiSlider*() controls use this one -float GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue, int sliderWidth) +int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, int sliderWidth) { + int result = 0; GuiState state = guiState; - int sliderValue = (int)(((value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))); + int sliderValue = (int)(((*value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))); Rectangle slider = { bounds.x, bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, SLIDER_PADDING), 0, bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - 2*GuiGetStyle(SLIDER, SLIDER_PADDING) }; @@ -2628,7 +2702,7 @@ float GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight if (CHECK_BOUNDS_ID(bounds, guiSliderActive)) { // Get equivalent value and slider position from mousePoint.x - value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue; + *value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue; } } else @@ -2646,7 +2720,7 @@ float GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight guiSliderActive = bounds; // Store bounds as an identifier when dragging starts // Get equivalent value and slider position from mousePoint.x - value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue; + *value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue; if (sliderWidth > 0) slider.x = mousePoint.x - slider.width/2; // Slider else if (sliderWidth == 0) slider.width = (float)sliderValue; // SliderBar @@ -2654,8 +2728,8 @@ float GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight else state = STATE_FOCUSED; } - if (value > maxValue) value = maxValue; - else if (value < minValue) value = minValue; + if (*value > maxValue) *value = maxValue; + else if (*value < minValue) *value = minValue; } // Bar limits check @@ -2702,24 +2776,25 @@ float GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight } //-------------------------------------------------------------------- - return value; + return result; } // Slider control extended, returns selected value and has text -float GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue) +int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue) { return GuiSliderPro(bounds, textLeft, textRight, value, minValue, maxValue, GuiGetStyle(SLIDER, SLIDER_WIDTH)); } // Slider Bar control extended, returns selected value -float GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue) +int GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue) { return GuiSliderPro(bounds, textLeft, textRight, value, minValue, maxValue, 0); } // Progress Bar control extended, shows current progress value -float GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue) +int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue) { + int result = 0; GuiState state = guiState; Rectangle progress = { bounds.x + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), @@ -2728,9 +2803,9 @@ float GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRig // Update control //-------------------------------------------------------------------- - if (value > maxValue) value = maxValue; + if (*value > maxValue) *value = maxValue; - if (state != STATE_DISABLED) progress.width = ((float)(value/(maxValue - minValue))*(float)(bounds.width - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH))); + if (state != STATE_DISABLED) progress.width = ((float)(*value/(maxValue - minValue))*(float)(bounds.width - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH))); //-------------------------------------------------------------------- // Draw control @@ -2765,12 +2840,13 @@ float GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRig } //-------------------------------------------------------------------- - return value; + return result; } // Status Bar control -void GuiStatusBar(Rectangle bounds, const char *text) +int GuiStatusBar(Rectangle bounds, const char *text) { + int result = 0; GuiState state = guiState; // Draw control @@ -2779,11 +2855,14 @@ void GuiStatusBar(Rectangle bounds, const char *text) Fade(GetColor(GuiGetStyle(STATUSBAR, (state != STATE_DISABLED)? BASE_COLOR_NORMAL : BASE_COLOR_DISABLED)), guiAlpha)); GuiDrawText(text, GetTextBounds(STATUSBAR, bounds), GuiGetStyle(STATUSBAR, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(STATUSBAR, (state != STATE_DISABLED)? TEXT_COLOR_NORMAL : TEXT_COLOR_DISABLED)), guiAlpha)); //-------------------------------------------------------------------- + + return result; } // Dummy rectangle control, intended for placeholding -void GuiDummyRec(Rectangle bounds, const char *text) +int GuiDummyRec(Rectangle bounds, const char *text) { + int result = 0; GuiState state = guiState; // Update control @@ -2806,25 +2885,32 @@ void GuiDummyRec(Rectangle bounds, const char *text) GuiDrawRectangle(bounds, 0, BLANK, Fade(GetColor(GuiGetStyle(DEFAULT, (state != STATE_DISABLED)? BASE_COLOR_NORMAL : BASE_COLOR_DISABLED)), guiAlpha)); GuiDrawText(text, GetTextBounds(DEFAULT, bounds), TEXT_ALIGN_CENTER, Fade(GetColor(GuiGetStyle(BUTTON, (state != STATE_DISABLED)? TEXT_COLOR_NORMAL : TEXT_COLOR_DISABLED)), guiAlpha)); //------------------------------------------------------------------ + + return result; } // List View control -int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int active) +int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int *active) { + int result = 0; int itemCount = 0; const char **items = NULL; if (text != NULL) items = GuiTextSplit(text, ';', &itemCount, NULL); - return GuiListViewEx(bounds, items, itemCount, NULL, scrollIndex, active); + result = GuiListViewEx(bounds, items, itemCount, scrollIndex, active, NULL); + + return result; } // List View control with extended parameters -int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active) +int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollIndex, int *active, int *focus) { + int result = 0; GuiState state = guiState; + int itemFocused = (focus == NULL)? -1 : *focus; - int itemSelected = active; + int itemSelected = *active; // Check if we need a scroll bar bool useScrollBar = false; @@ -2959,19 +3045,21 @@ int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, in if (focus != NULL) *focus = itemFocused; if (scrollIndex != NULL) *scrollIndex = startIndex; - return itemSelected; + *active = itemSelected; + return result; } // Color Panel control -Color GuiColorPanel(Rectangle bounds, const char *text, Color color) +int GuiColorPanel(Rectangle bounds, const char *text, Color *color) { - const Color colWhite = { 255, 255, 255, 255 }; - const Color colBlack = { 0, 0, 0, 255 }; - + int result = 0; GuiState state = guiState; Vector2 pickerSelector = { 0 }; - Vector3 vcolor = { (float)color.r/255.0f, (float)color.g/255.0f, (float)color.b/255.0f }; + const Color colWhite = { 255, 255, 255, 255 }; + const Color colBlack = { 0, 0, 0, 255 }; + + Vector3 vcolor = { (float)color->r/255.0f, (float)color->g/255.0f, (float)color->b/255.0f }; Vector3 hsv = ConvertRGBtoHSV(vcolor); pickerSelector.x = bounds.x + (float)hsv.y*bounds.width; // HSV: Saturation @@ -3009,10 +3097,10 @@ Color GuiColorPanel(Rectangle bounds, const char *text, Color color) Vector3 rgb = ConvertHSVtoRGB(hsv); // NOTE: Vector3ToColor() only available on raylib 1.8.1 - color = RAYGUI_CLITERAL(Color){ (unsigned char)(255.0f*rgb.x), + *color = RAYGUI_CLITERAL(Color){ (unsigned char)(255.0f*rgb.x), (unsigned char)(255.0f*rgb.y), (unsigned char)(255.0f*rgb.z), - (unsigned char)(255.0f*(float)color.a/255.0f) }; + (unsigned char)(255.0f*(float)color->a/255.0f) }; } else state = STATE_FOCUSED; @@ -3039,19 +3127,20 @@ Color GuiColorPanel(Rectangle bounds, const char *text, Color color) GuiDrawRectangle(bounds, GuiGetStyle(COLORPICKER, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)), guiAlpha), BLANK); //-------------------------------------------------------------------- - return color; + return result; } // Color Bar Alpha control // NOTE: Returns alpha value normalized [0..1] -float GuiColorBarAlpha(Rectangle bounds, const char *text, float alpha) +int GuiColorBarAlpha(Rectangle bounds, const char *text, float *alpha) { #if !defined(RAYGUI_COLORBARALPHA_CHECKED_SIZE) #define RAYGUI_COLORBARALPHA_CHECKED_SIZE 10 #endif + int result = 0; GuiState state = guiState; - Rectangle selector = { (float)bounds.x + alpha*bounds.width - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT)/2, (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_HEIGHT)/2, (float)bounds.y - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW), (float)GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT), (float)bounds.height + GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW)*2 }; // Update control //-------------------------------------------------------------------- @@ -3065,9 +3154,9 @@ float GuiColorBarAlpha(Rectangle bounds, const char *text, float alpha) { if (CHECK_BOUNDS_ID(bounds, guiSliderActive)) { - alpha = (mousePoint.x - bounds.x)/bounds.width; - if (alpha <= 0.0f) alpha = 0.0f; - if (alpha >= 1.0f) alpha = 1.0f; + *alpha = (mousePoint.x - bounds.x)/bounds.width; + if (*alpha <= 0.0f) *alpha = 0.0f; + if (*alpha >= 1.0f) *alpha = 1.0f; } } else @@ -3084,9 +3173,9 @@ float GuiColorBarAlpha(Rectangle bounds, const char *text, float alpha) guiSliderDragging = true; guiSliderActive = bounds; // Store bounds as an identifier when dragging starts - alpha = (mousePoint.x - bounds.x)/bounds.width; - if (alpha <= 0.0f) alpha = 0.0f; - if (alpha >= 1.0f) alpha = 1.0f; + *alpha = (mousePoint.x - bounds.x)/bounds.width; + if (*alpha <= 0.0f) *alpha = 0.0f; + if (*alpha >= 1.0f) *alpha = 1.0f; //selector.x = bounds.x + (int)(((alpha - 0)/(100 - 0))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))) - selector.width/2; } else state = STATE_FOCUSED; @@ -3122,7 +3211,7 @@ float GuiColorBarAlpha(Rectangle bounds, const char *text, float alpha) GuiDrawRectangle(selector, 0, BLANK, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)), guiAlpha)); //-------------------------------------------------------------------- - return alpha; + return result; } // Color Bar Hue control @@ -3131,10 +3220,11 @@ float GuiColorBarAlpha(Rectangle bounds, const char *text, float alpha) // Color GuiColorBarSat() [WHITE->color] // Color GuiColorBarValue() [BLACK->color], HSV/HSL // float GuiColorBarLuminance() [BLACK->WHITE] -float GuiColorBarHue(Rectangle bounds, const char *text, float hue) +int GuiColorBarHue(Rectangle bounds, const char *text, float *hue) { + int result = 0; GuiState state = guiState; - Rectangle selector = { (float)bounds.x - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW), (float)bounds.y + hue/360.0f*bounds.height - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT)/2, (float)bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW)*2, (float)GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT) }; + Rectangle selector = { (float)bounds.x - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW), (float)bounds.y + (*hue)/360.0f*bounds.height - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT)/2, (float)bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW)*2, (float)GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT) }; // Update control //-------------------------------------------------------------------- @@ -3148,9 +3238,9 @@ float GuiColorBarHue(Rectangle bounds, const char *text, float hue) { if (CHECK_BOUNDS_ID(bounds, guiSliderActive)) { - hue = (mousePoint.y - bounds.y)*360/bounds.height; - if (hue <= 0.0f) hue = 0.0f; - if (hue >= 359.0f) hue = 359.0f; + *hue = (mousePoint.y - bounds.y)*360/bounds.height; + if (*hue <= 0.0f) *hue = 0.0f; + if (*hue >= 359.0f) *hue = 359.0f; } } else @@ -3167,9 +3257,9 @@ float GuiColorBarHue(Rectangle bounds, const char *text, float hue) guiSliderDragging = true; guiSliderActive = bounds; // Store bounds as an identifier when dragging starts - hue = (mousePoint.y - bounds.y)*360/bounds.height; - if (hue <= 0.0f) hue = 0.0f; - if (hue >= 359.0f) hue = 359.0f; + *hue = (mousePoint.y - bounds.y)*360/bounds.height; + if (*hue <= 0.0f) *hue = 0.0f; + if (*hue >= 359.0f) *hue = 359.0f; } else state = STATE_FOCUSED; @@ -3208,7 +3298,7 @@ float GuiColorBarHue(Rectangle bounds, const char *text, float hue) GuiDrawRectangle(selector, 0, BLANK, Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)), guiAlpha)); //-------------------------------------------------------------------- - return hue; + return result; } // Color Picker control @@ -3217,21 +3307,25 @@ float GuiColorBarHue(Rectangle bounds, const char *text, float hue) // float GuiColorBarAlpha(Rectangle bounds, float alpha) // float GuiColorBarHue(Rectangle bounds, float value) // NOTE: bounds define GuiColorPanel() size -Color GuiColorPicker(Rectangle bounds, const char *text, Color color) +int GuiColorPicker(Rectangle bounds, const char *text, Color *color) { - color = GuiColorPanel(bounds, NULL, color); + int result = 0; + + GuiColorPanel(bounds, NULL, color); 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) }; - Vector3 hsv = ConvertRGBtoHSV(RAYGUI_CLITERAL(Vector3){ color.r/255.0f, color.g/255.0f, color.b/255.0f }); - hsv.x = GuiColorBarHue(boundsHue, NULL, hsv.x); + Vector3 hsv = ConvertRGBtoHSV(RAYGUI_CLITERAL(Vector3){ (*color).r/255.0f, (*color).g/255.0f, (*color).b/255.0f }); + + GuiColorBarHue(boundsHue, NULL, &hsv.x); + //color.a = (unsigned char)(GuiColorBarAlpha(boundsAlpha, (float)color.a/255.0f)*255.0f); 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 }; - return color; + return result; } // Message Box control @@ -3244,7 +3338,7 @@ int GuiMessageBox(Rectangle bounds, const char *title, const char *message, cons #define RAYGUI_MESSAGEBOX_BUTTON_PADDING 12 #endif - int clicked = -1; // Returns clicked button from buttons list, 0 refers to closed window button + int result = -1; // Returns clicked button from buttons list, 0 refers to closed window button int buttonCount = 0; const char **buttonsText = GuiTextSplit(buttons, ';', &buttonCount, NULL); @@ -3264,7 +3358,7 @@ int GuiMessageBox(Rectangle bounds, const char *title, const char *message, cons // Draw control //-------------------------------------------------------------------- - if (GuiWindowBox(bounds, title)) clicked = 0; + if (GuiWindowBox(bounds, title)) result = 0; int prevTextAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT); GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); @@ -3276,18 +3370,18 @@ int GuiMessageBox(Rectangle bounds, const char *title, const char *message, cons for (int i = 0; i < buttonCount; i++) { - if (GuiButton(buttonBounds, buttonsText[i])) clicked = i + 1; + if (GuiButton(buttonBounds, buttonsText[i])) result = i + 1; buttonBounds.x += (buttonBounds.width + RAYGUI_MESSAGEBOX_BUTTON_PADDING); } GuiSetStyle(BUTTON, TEXT_ALIGNMENT, prevTextAlignment); //-------------------------------------------------------------------- - return clicked; + return result; } // Text Input Box control, ask for text -int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text, int textMaxSize, int *secretViewActive) +int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text, int textMaxSize, bool *secretViewActive) { #if !defined(RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT) #define RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT 24 @@ -3303,7 +3397,7 @@ int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, co // WARNING: No more than one GuiTextInputBox() should be open at the same time static bool textEditMode = false; - int btnIndex = -1; + int result = -1; int buttonCount = 0; const char **buttonsText = GuiTextSplit(buttons, ';', &buttonCount, NULL); @@ -3336,7 +3430,7 @@ int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, co // Draw control //-------------------------------------------------------------------- - if (GuiWindowBox(bounds, title)) btnIndex = 0; + if (GuiWindowBox(bounds, title)) result = 0; // Draw message if available if (message != NULL) @@ -3353,7 +3447,7 @@ int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, co if (GuiTextBox(RAYGUI_CLITERAL(Rectangle){ textBoxBounds.x, textBoxBounds.y, textBoxBounds.width - 4 - RAYGUI_TEXTINPUTBOX_HEIGHT, textBoxBounds.height }, ((*secretViewActive == 1) || textEditMode)? text : stars, textMaxSize, textEditMode)) textEditMode = !textEditMode; - *secretViewActive = GuiToggle(RAYGUI_CLITERAL(Rectangle){ textBoxBounds.x + textBoxBounds.width - RAYGUI_TEXTINPUTBOX_HEIGHT, textBoxBounds.y, RAYGUI_TEXTINPUTBOX_HEIGHT, RAYGUI_TEXTINPUTBOX_HEIGHT }, (*secretViewActive == 1)? "#44#" : "#45#", *secretViewActive); + GuiToggle(RAYGUI_CLITERAL(Rectangle){ textBoxBounds.x + textBoxBounds.width - RAYGUI_TEXTINPUTBOX_HEIGHT, textBoxBounds.y, RAYGUI_TEXTINPUTBOX_HEIGHT, RAYGUI_TEXTINPUTBOX_HEIGHT }, (*secretViewActive == 1)? "#44#" : "#45#", secretViewActive); } else { @@ -3365,32 +3459,34 @@ int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, co for (int i = 0; i < buttonCount; i++) { - if (GuiButton(buttonBounds, buttonsText[i])) btnIndex = i + 1; + if (GuiButton(buttonBounds, buttonsText[i])) result = i + 1; buttonBounds.x += (buttonBounds.width + RAYGUI_MESSAGEBOX_BUTTON_PADDING); } - if (btnIndex >= 0) textEditMode = false; + if (result >= 0) textEditMode = false; GuiSetStyle(BUTTON, TEXT_ALIGNMENT, prevBtnTextAlignment); //-------------------------------------------------------------------- - return btnIndex; + return result; // Result is the pressed button index } // Grid control // NOTE: Returns grid mouse-hover selected cell // About drawing lines at subpixel spacing, simple put, not easy solution: // https://stackoverflow.com/questions/4435450/2d-opengl-drawing-lines-that-dont-exactly-fit-pixel-raster -Vector2 GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs) +int GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs, Vector2 *mouseCell) { // Grid lines alpha amount #if !defined(RAYGUI_GRID_ALPHA) #define RAYGUI_GRID_ALPHA 0.15f #endif + int result = 0; GuiState state = guiState; + Vector2 mousePoint = GetMousePosition(); - Vector2 currentCell = { -1, -1 }; + Vector2 currentMouseCell = { 0 }; int linesV = ((int)(bounds.width/spacing))*subdivs + 1; int linesH = ((int)(bounds.height/spacing))*subdivs + 1; @@ -3402,8 +3498,8 @@ Vector2 GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs) if (CheckCollisionPointRec(mousePoint, bounds)) { // NOTE: Cell values must be the upper left of the cell the mouse is in - currentCell.x = floorf((mousePoint.x - bounds.x)/spacing); - currentCell.y = floorf((mousePoint.y - bounds.y)/spacing); + currentMouseCell.x = floorf((mousePoint.x - bounds.x)/spacing); + currentMouseCell.y = floorf((mousePoint.y - bounds.y)/spacing); } } //-------------------------------------------------------------------- @@ -3434,7 +3530,8 @@ Vector2 GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs) default: break; } - return currentCell; + if (mouseCell != NULL) *mouseCell = currentMouseCell; + return result; } //----------------------------------------------------------------------------------