From eeae444b1da438298d9ad0e394db4b99902ddbf8 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Sat, 9 Mar 2024 11:03:27 -0500 Subject: [PATCH] Moved display_text_centered() into a separate file, since I could possibly extend this file with other raygui helper functions --- includes/raygui_helpers.hpp | 9 +++++++++ raygui_helpers.cpp | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 includes/raygui_helpers.hpp create mode 100644 raygui_helpers.cpp diff --git a/includes/raygui_helpers.hpp b/includes/raygui_helpers.hpp new file mode 100644 index 0000000..8ec7793 --- /dev/null +++ b/includes/raygui_helpers.hpp @@ -0,0 +1,9 @@ +#ifndef _RAYGUI_HELPERS_HPP +#define _RAYGUI_HELPERS_HPP +#include + +/* Display the given text, centered on the screen, as a label. +NEEDS RAYGUI LIBRARY. */ +void display_text_centered(std::string to_disp); + +#endif diff --git a/raygui_helpers.cpp b/raygui_helpers.cpp new file mode 100644 index 0000000..88dbfe2 --- /dev/null +++ b/raygui_helpers.cpp @@ -0,0 +1,13 @@ +#include "includes/raygui_helpers.hpp" +#include "includes/raygui/raygui.h" + +void display_text_centered(std::string to_disp) { + const char* to_disp_cstr = to_disp.c_str(); + Vector2 label_size = MeasureTextEx(GetFontDefault(), to_disp_cstr, GuiGetStyle(DEFAULT, TEXT_SIZE)+1, GuiGetStyle(DEFAULT, TEXT_SPACING)+1); // The '+1' is there to account for any rounding errors + + BeginDrawing(); + ClearBackground(BLACK); + GuiLabel(Rectangle{(GetScreenWidth()/2) - (label_size.x/2), (GetScreenHeight()/2) - (label_size.y/2), label_size.x, label_size.y}, to_disp_cstr); + EndDrawing(); + return; +}