diff --git a/.clangd b/.clangd index 122ab09..e6defe1 100644 --- a/.clangd +++ b/.clangd @@ -1,2 +1,4 @@ CompileFlags: - CompilationDatabase: bin \ No newline at end of file + CompilationDatabase: bin +Diagnostics: + MissingIncludes: None \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 40c633c..b8632cf 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,9 +139,9 @@ if (WIN32) "${MSYS2_UCRT64}/include/c++/13.2.0/x86_64-w64-mingw32" ) - file(WRITE ${CMAKE_CURRENT_LIST_DIR}/.clangd "CompileFlags:\n CompilationDatabase: bin\n Add: [\"--target=x86_64-w64-mingw32\"]") + file(WRITE ${CMAKE_CURRENT_LIST_DIR}/.clangd "CompileFlags:\n CompilationDatabase: bin\n Add: [\"--target=x86_64-w64-mingw32\"]\nDiagnostics:\n MissingIncludes: None") else() - file(WRITE ${CMAKE_CURRENT_LIST_DIR}/.clangd "CompileFlags:\n CompilationDatabase: bin") + file(WRITE ${CMAKE_CURRENT_LIST_DIR}/.clangd "CompileFlags:\n CompilationDatabase: bin\nDiagnostics:\n MissingIncludes: None") endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/extra/img.png b/extra/img.png new file mode 100644 index 0000000..334eece Binary files /dev/null and b/extra/img.png differ diff --git a/other/TODO.txt b/other/TODO.txt index 5bdf893..4039f0a 100644 --- a/other/TODO.txt +++ b/other/TODO.txt @@ -13,11 +13,11 @@ ***Fix: Text rendering bug in labels ***Implement callback for state changes in checkbox ***FIX: WindowOutputHandler text rendering +***Implement wrappers in Renderer2D to take a center and size for rects +***find a way to add fixed update to gui::Window Add theme caching -find a way to add fixed update to gui::Window Implement global scale (probably query desktop scale and adjust accordingly) Implement show/hide functionality for widgets -Implement wrappers in Renderer2D to take a center and size for rects Implement Panel title Create reliable default stylesheet @@ -43,6 +43,7 @@ Implement following widgets: Progressbar Save/Open File Dialogs (and folder dialogs) Tab Panel + Hex Editor Layouts Vertical Horizontal diff --git a/other/build.nr b/other/build.nr index f11718f..d90a27d 100644 --- a/other/build.nr +++ b/other/build.nr @@ -1 +1 @@ -2062 +2065 diff --git a/src/ogfx/gui/Events.hpp b/src/ogfx/gui/Events.hpp index d8bc734..87f3738 100644 --- a/src/ogfx/gui/Events.hpp +++ b/src/ogfx/gui/Events.hpp @@ -32,17 +32,17 @@ namespace ogfx class WindowResizedData : public ostd::BaseObject { public: - inline WindowResizedData(WindowCore& parent, int32_t _oldx, int32_t _oldy, int32_t _newx, int32_t _newy) : parentWindow(parent), old_width(_oldx), old_height(_oldy), new_width(_newx), new_height(_newy) + inline WindowResizedData(WindowCore& parent, i32 _oldx, i32 _oldy, i32 _newx, i32 _newy) : parentWindow(parent), old_width(_oldx), old_height(_oldy), new_width(_newx), new_height(_newy) { setTypeName("ogfx::WindowResizedData"); validate(); } public: - int32_t new_width; - int32_t new_height; - int32_t old_width; - int32_t old_height; + i32 new_width; + i32 new_height; + i32 old_width; + i32 old_height; WindowCore& parentWindow; }; class MouseEventData : public ostd::BaseObject @@ -50,15 +50,15 @@ namespace ogfx public: enum class eButton { None = 0, Left, Middle, Right }; public: enum class eScrollDirection { None = 0, Up, Down }; public: - inline MouseEventData(WindowCore& parent, float mousex, float mousey, eButton btn) : parentWindow(parent), position_x(mousex), position_y(mousey), button(btn) + inline MouseEventData(WindowCore& parent, f32 mousex, f32 mousey, eButton btn) : parentWindow(parent), position_x(mousex), position_y(mousey), button(btn) { setTypeName("ogfx::MouseEventData"); validate(); } public: - float position_x; - float position_y; + f32 position_x; + f32 position_y; eButton button; eScrollDirection scroll { eScrollDirection::None }; gui::Widget* mousePressedOnWidget { nullptr }; @@ -68,14 +68,14 @@ namespace ogfx { public: enum class eKeyEvent { Pressed = 0, Released, Text }; public: - inline KeyEventData(WindowCore& parent, int32_t key, char _text, eKeyEvent evt) : parentWindow(parent), keyCode(key), text(_text), eventType(evt) + inline KeyEventData(WindowCore& parent, i32 key, char _text, eKeyEvent evt) : parentWindow(parent), keyCode(key), text(_text), eventType(evt) { setTypeName("ogfx::KeyEventData"); validate(); } public: - int32_t keyCode; + i32 keyCode; char text; eKeyEvent eventType; WindowCore& parentWindow; @@ -93,7 +93,7 @@ namespace ogfx public: eDropType dropType; WindowCore& parentWindow; - ostd::String textOrFilePath { "" }; + String textOrFilePath { "" }; ostd::BaseObject* userObject { nullptr }; }; namespace gui @@ -111,7 +111,7 @@ namespace ogfx MouseEventData* mouse { nullptr }; KeyEventData* keyboard { nullptr }; DropEventData drop; - uint32_t __original_signal_id { 0 }; + u32 __original_signal_id { 0 }; private: bool m_handled { false }; diff --git a/src/ogfx/gui/RawTextInput.cpp b/src/ogfx/gui/RawTextInput.cpp index 4cd5c47..1b5b258 100644 --- a/src/ogfx/gui/RawTextInput.cpp +++ b/src/ogfx/gui/RawTextInput.cpp @@ -62,8 +62,8 @@ namespace ogfx onSignalHandled(signal); return; } - ostd::String s1 = parent.m_text.new_substr(0, parent.m_cursorPosition); - ostd::String s2 = ""; + String s1 = parent.m_text.new_substr(0, parent.m_cursorPosition); + String s2 = ""; if (parent.m_cursorPosition < parent.m_text.len()) s2 = parent.m_text.new_substr(parent.m_cursorPosition); s1.addChar(data.text).add(s2); @@ -101,8 +101,8 @@ namespace ogfx onSignalHandled(signal); return; } - ostd::String s1 = parent.m_text.new_substr(0, parent.m_cursorPosition - 1); - ostd::String s2 = ""; + String s1 = parent.m_text.new_substr(0, parent.m_cursorPosition - 1); + String s2 = ""; if (parent.m_cursorPosition < parent.m_text.len()) s2 = parent.m_text.new_substr(parent.m_cursorPosition); parent.m_text = s1 + s2; @@ -146,7 +146,7 @@ namespace ogfx else if (signal.ID == ostd::BuiltinSignals::MouseMoved) { auto& data = (ogfx::MouseEventData&)signal.userData; - if (parent.contains((float)data.position_x, (float)data.position_y)) + if (parent.contains((f32)data.position_x, (f32)data.position_y)) parent.m_mouseInside = true; else parent.m_mouseInside = false; @@ -156,27 +156,27 @@ namespace ogfx auto& data = (ogfx::MouseEventData&)signal.userData; if (data.button == ogfx::MouseEventData::eButton::Left && parent.m_gfx != nullptr && parent.m_mouseInside) { - ostd::String text = parent.m_text; - ostd::Vec2 relativePosition = { (float)data.position_x, (float)data.position_y }; + String text = parent.m_text; + ostd::Vec2 relativePosition = { (f32)data.position_x, (f32)data.position_y }; relativePosition -= (parent.getPosition() + parent.m_paddingX + parent.m_theme.extraPaddingLeft); if (text.len() > 0) { - ostd::String tmpStr1 = ""; - ostd::String tmpStr2 = ""; + String tmpStr1 = ""; + String tmpStr2 = ""; bool found = false; - for (int32_t i = 0; i < text.len(); i++) + for (i32 i = 0; i < text.len(); i++) { tmpStr2 = ""; char c = text[i]; tmpStr1 += c; - int32_t strWidth1 = parent.m_gfx->getStringDimensions(tmpStr1, parent.m_fontSize).x; + i32 strWidth1 = parent.m_gfx->getStringDimensions(tmpStr1, parent.m_fontSize).x; if (relativePosition.x > strWidth1) continue; found = true; tmpStr2 = tmpStr1.new_substr(0, tmpStr1.len() - 1); - int32_t strWidth2 = (tmpStr2.len() > 0 ? parent.m_gfx->getStringDimensions(tmpStr2, parent.m_fontSize).x : 0); - int32_t d1 = (int32_t)std::abs(relativePosition.x - strWidth2); - int32_t d2 = (int32_t)std::abs(strWidth1 - relativePosition.x); + i32 strWidth2 = (tmpStr2.len() > 0 ? parent.m_gfx->getStringDimensions(tmpStr2, parent.m_fontSize).x : 0); + i32 d1 = (i32)std::abs(relativePosition.x - strWidth2); + i32 d2 = (i32)std::abs(strWidth1 - relativePosition.x); if (d1 > d2) parent.m_cursorPosition = tmpStr1.len(); else @@ -196,7 +196,7 @@ namespace ogfx - RawTextInput& RawTextInput::create(const ostd::Vec2& position, const ostd::Vec2& size, const ostd::String& name) + RawTextInput& RawTextInput::create(const ostd::Vec2& position, const ostd::Vec2& size, const String& name) { setPosition(position); setSize(size); @@ -212,15 +212,15 @@ namespace ogfx void RawTextInput::render(ogfx::BasicRenderer2D& gfx) { m_gfx = &gfx; - double text_size_scale = 0.66666666666666; + f64 text_size_scale = 0.66666666666666; m_paddingX = (4.0f * geth()) / 30.0f; - m_fontSize = (int32_t)(geth() * 0.66); - float cursor_height_scale = 0.75f; + m_fontSize = (i32)(geth() * 0.66); + f32 cursor_height_scale = 0.75f; ostd::IPoint strSize { 0, 0 }; if (m_cursorPosition > 0 && m_text != "") { - ostd::String s1 = m_text.new_substr(0, m_cursorPosition); + String s1 = m_text.new_substr(0, m_cursorPosition); strSize = gfx.getStringDimensions(s1, m_fontSize); } @@ -229,7 +229,7 @@ namespace ogfx gfx.drawString(m_text, getPosition() + ostd::Vec2 { m_paddingX + m_theme.extraPaddingLeft, m_paddingX + m_theme.extraPaddingTop}, m_theme.textColor, m_fontSize); if (m_cursorState || !m_theme.cursorBlink) - gfx.fillRect({ getx() + m_paddingX + m_theme.extraPaddingLeft + strSize.x - 1, gety() + m_paddingX + m_theme.extraPaddingTop, (float)m_theme.cursorWidth, (float)m_fontSize * cursor_height_scale }, m_theme.cursorColor); + gfx.fillRect({ getx() + m_paddingX + m_theme.extraPaddingLeft + strSize.x - 1, gety() + m_paddingX + m_theme.extraPaddingTop, (f32)m_theme.cursorWidth, (f32)m_fontSize * cursor_height_scale }, m_theme.cursorColor); onRender(gfx); } @@ -254,19 +254,19 @@ namespace ogfx onFixedUpdate(); } - void RawTextInput::setText(const ostd::String& text) + void RawTextInput::setText(const String& text) { m_text = text; m_cursorPosition = m_text.len(); } - void RawTextInput::appendText(const ostd::String& text) + void RawTextInput::appendText(const String& text) { m_text.add(text); m_cursorPosition = m_text.len(); } - void RawTextInput::setCursorPosition(uint16_t cursorPos) + void RawTextInput::setCursorPosition(u16 cursorPos) { if (cursorPos > m_text.len()) cursorPos = m_text.len(); diff --git a/src/ogfx/gui/RawTextInput.hpp b/src/ogfx/gui/RawTextInput.hpp index 76074e3..7713f34 100644 --- a/src/ogfx/gui/RawTextInput.hpp +++ b/src/ogfx/gui/RawTextInput.hpp @@ -55,9 +55,9 @@ namespace ogfx ostd::Color backgroundColor { 0, 0, 0, 0 }; ostd::Color cursorColor { 0, 0, 0, 0 }; - uint8_t cursorWidth { 0 }; - uint8_t extraPaddingTop { 0 }; - uint8_t extraPaddingLeft { 0 }; + u8 cursorWidth { 0 }; + u8 extraPaddingTop { 0 }; + u8 extraPaddingLeft { 0 }; bool cursorBlink { true }; ostd::Counter cursorBlinkCounter { 30 }; @@ -95,7 +95,7 @@ namespace ogfx public: class ActionEventData : public ostd::BaseObject { public: - inline ActionEventData(RawTextInput& _sender, const ostd::String& _senderName, eActionEventType _eventType, ostd::BaseObject& _userData) : + inline ActionEventData(RawTextInput& _sender, const String& _senderName, eActionEventType _eventType, ostd::BaseObject& _userData) : sender(_sender), senderName(_senderName), eventType(_eventType), @@ -107,15 +107,15 @@ namespace ogfx public: RawTextInput& sender; - ostd::String senderName { "" }; + String senderName { "" }; eActionEventType eventType { eActionEventType::None }; ostd::BaseObject& userData { ostd::BaseObject::InvalidRef() }; }; public: inline RawTextInput(void) { create({ 0.0f, 0.0f }, { 200.0f, 30.0f }, "UnnamedRawTextInput"); } - inline RawTextInput(const ostd::Vec2& position, const ostd::Vec2& size, const ostd::String& name) { create(position, size, name); } - RawTextInput& create(const ostd::Vec2& position, const ostd::Vec2& size, const ostd::String& name); + inline RawTextInput(const ostd::Vec2& position, const ostd::Vec2& size, const String& name) { create(position, size, name); } + RawTextInput& create(const ostd::Vec2& position, const ostd::Vec2& size, const String& name); virtual void render(ogfx::BasicRenderer2D& gfx); virtual void update(void); @@ -125,47 +125,47 @@ namespace ogfx virtual inline void onUpdate(void) { } virtual inline void onFixedUpdate(void) { } - void setText(const ostd::String& text); - void appendText(const ostd::String& text); - void setCursorPosition(uint16_t cursorPos); + void setText(const String& text); + void appendText(const String& text); + void setCursorPosition(u16 cursorPos); void setTheme(Theme theme); inline void setEventListener(EventListener& evtl) { m_eventListener = &evtl; } inline void setCharacterFilter(CharacterFilter& chrf) { m_charFilter = &chrf; } - inline void setName(const ostd::String& name) { m_name = name; } + inline void setName(const String& name) { m_name = name; } inline EventListener* getEventListener(void) const { return m_eventListener; } inline CharacterFilter* getCharacterFilter(void) const { return m_charFilter; } - inline ostd::String getText(void) const { return m_text; } - inline uint16_t getCursorPosition(void) const { return m_cursorPosition; } + inline String getText(void) const { return m_text; } + inline u16 getCursorPosition(void) const { return m_cursorPosition; } inline Theme& getTheme(void) { return m_theme; } - inline ostd::String getName(void) const { return m_name; } + inline String getName(void) const { return m_name; } inline bool isMouseInside(void) const { return m_mouseInside; } private: EventListener* m_eventListener { nullptr }; CharacterFilter* m_charFilter { nullptr }; ogfx::BasicRenderer2D* m_gfx { nullptr }; - int32_t m_fontSize { 20 }; - float m_paddingX { 0 }; + i32 m_fontSize { 20 }; + f32 m_paddingX { 0 }; protected: - ostd::String m_name { "" }; + String m_name { "" }; - ostd::String m_text { "" }; - uint16_t m_cursorPosition { 0 }; + String m_text { "" }; + u16 m_cursorPosition { 0 }; bool m_cursorState { true }; ostd::Counter m_keyRepeatCounter { 1 }; char m_lastChar { 0 }; - int32_t m_lastKeyCode { 0 }; + i32 m_lastKeyCode { 0 }; Theme m_theme; bool m_mouseInside { false }; public: - inline static const uint32_t actionEventSignalID { ostd::SignalHandler::newCustomSignal(11400) }; + inline static const u32 actionEventSignalID { ostd::SignalHandler::newCustomSignal(11400) }; }; class RawTextInputEventListener : public RawTextInput::EventListener { diff --git a/src/ogfx/gui/WidgetManager.cpp b/src/ogfx/gui/WidgetManager.cpp index bc7747c..47d9efc 100644 --- a/src/ogfx/gui/WidgetManager.cpp +++ b/src/ogfx/gui/WidgetManager.cpp @@ -81,10 +81,10 @@ namespace ogfx Widget* next = nullptr; Widget* smallest = nullptr; - int32_t currentTabIndex = (m_focused != nullptr ? m_focused->m_tabIndex : std::numeric_limits::max()); + i32 currentTabIndex = (m_focused != nullptr ? m_focused->m_tabIndex : std::numeric_limits::max()); for (Widget* w : m_widgetList) { - int tab_i = w->m_tabIndex; + i32 tab_i = w->m_tabIndex; if (tab_i < 0) continue; if (!smallest || tab_i < smallest->m_tabIndex) smallest = w; @@ -133,7 +133,7 @@ namespace ogfx void WidgetManager::onMousePressed(const Event& event) { - for (int32_t i = m_widgetList.size() - 1; i >= 0; i--) + for (i32 i = m_widgetList.size() - 1; i >= 0; i--) { Widget* w = m_widgetList[i]; if (w == nullptr) continue; @@ -155,7 +155,7 @@ namespace ogfx m_mousePressedOnWidget->__onMouseReleased(event); // processDragAndDrop(m_mousePressedOnWidget, event); } - for (int32_t i = m_widgetList.size() - 1; i >= 0; i--) + for (i32 i = m_widgetList.size() - 1; i >= 0; i--) { Widget* w = m_widgetList[i]; if (w == nullptr) continue; @@ -173,7 +173,7 @@ namespace ogfx void WidgetManager::onMouseMoved(const Event& event) { - for (int32_t i = m_widgetList.size() - 1; i >= 0; i--) + for (i32 i = m_widgetList.size() - 1; i >= 0; i--) { Widget* w = m_widgetList[i]; if (w == nullptr) continue; @@ -202,7 +202,7 @@ namespace ogfx if (event.isHandled() || w->m_stopEvents) { bool mouseOut = false; - for (int32_t j = i - 1; j >= 0; j--) + for (i32 j = i - 1; j >= 0; j--) { Widget* ww = m_widgetList[j]; if (ww->m_mouseInside) @@ -218,7 +218,7 @@ namespace ogfx void WidgetManager::onMouseScrolled(const Event& event) { - for (int32_t i = m_widgetList.size() - 1; i >= 0; i--) + for (i32 i = m_widgetList.size() - 1; i >= 0; i--) { Widget* w = m_widgetList[i]; if (w == nullptr) continue; @@ -233,7 +233,7 @@ namespace ogfx void WidgetManager::onMouseDragged(const Event& event) { - for (int32_t i = m_widgetList.size() - 1; i >= 0; i--) + for (i32 i = m_widgetList.size() - 1; i >= 0; i--) { Widget* w = m_widgetList[i]; if (w == nullptr) continue; diff --git a/src/ogfx/gui/WidgetManager.hpp b/src/ogfx/gui/WidgetManager.hpp index 1a65a9e..325760b 100644 --- a/src/ogfx/gui/WidgetManager.hpp +++ b/src/ogfx/gui/WidgetManager.hpp @@ -59,7 +59,7 @@ namespace ogfx void onWindowFocused(const Event& event); void onWindowFocusLost(const Event& event); - inline int32_t widgetCount(void) const { return m_widgetList.size(); } + inline i32 widgetCount(void) const { return m_widgetList.size(); } inline WindowCore& getWindow(void) { return m_window; } private: @@ -68,7 +68,7 @@ namespace ogfx private: WindowCore& m_window; Widget& m_owner; - std::vector m_widgetList; + stdvec m_widgetList; Widget* m_focused { nullptr }; bool m_tabNavigationEnabled { true }; Widget* m_mousePressedOnWidget { nullptr }; diff --git a/src/ogfx/gui/Window.cpp b/src/ogfx/gui/Window.cpp index 5f161ac..cac5189 100644 --- a/src/ogfx/gui/Window.cpp +++ b/src/ogfx/gui/Window.cpp @@ -27,7 +27,8 @@ namespace ogfx { const Uint32 REDRAW_EVENT = SDL_RegisterEvents(1); - inline static const ostd::String DefaultThemeStyle = \ + //TODO: Temporary + inline static const String DefaultThemeStyle = \ "window.backgroundColor = Color(#000000FF)\n" \ "label.textColor = Color(#FFFFFFFF)\n" \ "label.backgroundColor = Color(#00000000)\n" \ @@ -69,7 +70,7 @@ namespace ogfx SDLSysten::release(); } - void WindowCore::initialize(int32_t width, int32_t height, const ostd::String& title) + void WindowCore::initialize(i32 width, i32 height, const String& title) { if (m_initialized) return; SDLSysten::acquire(); @@ -158,14 +159,14 @@ namespace ogfx ostd::SignalHandler::emitSignal(ostd::BuiltinSignals::WindowClosed, ostd::Signal::Priority::Normal, *this); } - void WindowCore::setSize(int32_t width, int32_t height) + void WindowCore::setSize(i32 width, i32 height) { if (!isInitialized()) return; SDL_SetWindowSize(m_window, width, height); ostd::SignalHandler::emitSignal(ostd::BuiltinSignals::WindowResized, ostd::Signal::Priority::RealTime); } - void WindowCore::setTitle(const ostd::String& title) + void WindowCore::setTitle(const String& title) { if (!isInitialized()) return; m_title = title; @@ -174,72 +175,72 @@ namespace ogfx void WindowCore::setCursor(eCursor cursor) { - switch (cursor) - { - case eCursor::Default: - SDL_SetCursor(m_cursor_Default); - break; - case eCursor::Text: - SDL_SetCursor(m_cursor_Text); - break; - case eCursor::Wait: - SDL_SetCursor(m_cursor_Wait); - break; - case eCursor::Crosshair: - SDL_SetCursor(m_cursor_Crosshair); - break; - case eCursor::Progress: - SDL_SetCursor(m_cursor_Progress); - break; - case eCursor::NWSE_Resize: - SDL_SetCursor(m_cursor_NWSE_Resize); - break; - case eCursor::NESW_Resize: - SDL_SetCursor(m_cursor_NESW_Resize); - break; - case eCursor::EW_Resize: - SDL_SetCursor(m_cursor_EW_Resize); - break; - case eCursor::NS_Resize: - SDL_SetCursor(m_cursor_NS_Resize); - break; - case eCursor::Move: - SDL_SetCursor(m_cursor_Move); - break; - case eCursor::NotAllowed: - SDL_SetCursor(m_cursor_NotAllowed); - break; - case eCursor::Pointer: - SDL_SetCursor(m_cursor_Pointer); - break; - case eCursor::NW_Resize: - SDL_SetCursor(m_cursor_NW_Resize); - break; - case eCursor::N_Resize: - SDL_SetCursor(m_cursor_N_Resize); - break; - case eCursor::NE_Resize: - SDL_SetCursor(m_cursor_NE_Resize); - break; - case eCursor::E_Resize: - SDL_SetCursor(m_cursor_E_Resize); - break; - case eCursor::SE_Resize: - SDL_SetCursor(m_cursor_SE_Resize); - break; - case eCursor::S_Resize: - SDL_SetCursor(m_cursor_S_Resize); - break; - case eCursor::SW_Resize: - SDL_SetCursor(m_cursor_SW_Resize); - break; - case eCursor::W_Resize: - SDL_SetCursor(m_cursor_W_Resize); - break; - default: - SDL_SetCursor(m_cursor_Default); - break; - } + switch (cursor) + { + case eCursor::Default: + SDL_SetCursor(m_cursor_Default); + break; + case eCursor::Text: + SDL_SetCursor(m_cursor_Text); + break; + case eCursor::Wait: + SDL_SetCursor(m_cursor_Wait); + break; + case eCursor::Crosshair: + SDL_SetCursor(m_cursor_Crosshair); + break; + case eCursor::Progress: + SDL_SetCursor(m_cursor_Progress); + break; + case eCursor::NWSE_Resize: + SDL_SetCursor(m_cursor_NWSE_Resize); + break; + case eCursor::NESW_Resize: + SDL_SetCursor(m_cursor_NESW_Resize); + break; + case eCursor::EW_Resize: + SDL_SetCursor(m_cursor_EW_Resize); + break; + case eCursor::NS_Resize: + SDL_SetCursor(m_cursor_NS_Resize); + break; + case eCursor::Move: + SDL_SetCursor(m_cursor_Move); + break; + case eCursor::NotAllowed: + SDL_SetCursor(m_cursor_NotAllowed); + break; + case eCursor::Pointer: + SDL_SetCursor(m_cursor_Pointer); + break; + case eCursor::NW_Resize: + SDL_SetCursor(m_cursor_NW_Resize); + break; + case eCursor::N_Resize: + SDL_SetCursor(m_cursor_N_Resize); + break; + case eCursor::NE_Resize: + SDL_SetCursor(m_cursor_NE_Resize); + break; + case eCursor::E_Resize: + SDL_SetCursor(m_cursor_E_Resize); + break; + case eCursor::SE_Resize: + SDL_SetCursor(m_cursor_SE_Resize); + break; + case eCursor::S_Resize: + SDL_SetCursor(m_cursor_S_Resize); + break; + case eCursor::SW_Resize: + SDL_SetCursor(m_cursor_SW_Resize); + break; + case eCursor::W_Resize: + SDL_SetCursor(m_cursor_W_Resize); + break; + default: + SDL_SetCursor(m_cursor_Default); + break; + } } void WindowCore::enableResizable(bool enable) @@ -248,7 +249,7 @@ namespace ogfx m_resizeable = enable; } - void WindowCore::setIcon(const ostd::String& iconFilePath) + void WindowCore::setIcon(const String& iconFilePath) { SDL_Surface* appIcon = IMG_Load(iconFilePath); if (appIcon == nullptr) @@ -260,14 +261,14 @@ namespace ogfx SDL_DestroySurface(appIcon); } - void WindowCore::setBlockingEventsRefreshFPS(uint32_t fps) + void WindowCore::setBlockingEventsRefreshFPS(u32 fps) { if (fps == 0 || fps > MaxBlockingEventsFPS) { setBlockingEventsRefreshFPS(DefaultBlockingEventsFPS); return; } - m_blockingEventsDelay = static_cast(std::floor((1.0 / (double)fps) * 1000)); + m_blockingEventsDelay = cast(std::floor((1.0 / (f64)fps) * 1000)); } void WindowCore::requestRedraw(void) @@ -285,8 +286,8 @@ namespace ogfx MouseEventData WindowCore::get_mouse_state(void) { - float mx = 0, my = 0; - uint32_t btn = SDL_GetMouseState(&mx, &my); + f32 mx = 0, my = 0; + u32 btn = SDL_GetMouseState(&mx, &my); MouseEventData::eButton button = MouseEventData::eButton::None; switch (btn) { @@ -403,12 +404,12 @@ namespace ogfx } else if (event.type == SDL_EVENT_KEY_DOWN) { - KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Pressed); + KeyEventData ked(*this, (i32)event.key.key, 0, KeyEventData::eKeyEvent::Pressed); ostd::SignalHandler::emitSignal(ostd::BuiltinSignals::KeyPressed, ostd::Signal::Priority::RealTime, ked); } else if (event.type == SDL_EVENT_KEY_UP) { - KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Released); + KeyEventData ked(*this, (i32)event.key.key, 0, KeyEventData::eKeyEvent::Released); ostd::SignalHandler::emitSignal(ostd::BuiltinSignals::KeyReleased, ostd::Signal::Priority::RealTime, ked); } else if (event.type == SDL_EVENT_TEXT_INPUT) @@ -422,26 +423,26 @@ namespace ogfx void WindowCore::__load_default_stylesheet_variables(void) { // Cursors - m_defaultStylesheetVariables["cursor_default"] = { ostd::String("").add(static_cast(eCursor::Default)), true }; - m_defaultStylesheetVariables["cursor_text"] = { ostd::String("").add(static_cast(eCursor::Text)), true }; - m_defaultStylesheetVariables["cursor_wait"] = { ostd::String("").add(static_cast(eCursor::Wait)), true }; - m_defaultStylesheetVariables["cursor_crosshair"] = { ostd::String("").add(static_cast(eCursor::Crosshair)), true }; - m_defaultStylesheetVariables["cursor_progress"] = { ostd::String("").add(static_cast(eCursor::Progress)), true }; - m_defaultStylesheetVariables["cursor_nwse_resize"] = { ostd::String("").add(static_cast(eCursor::NWSE_Resize)), true }; - m_defaultStylesheetVariables["cursor_nesw_resize"] = { ostd::String("").add(static_cast(eCursor::NESW_Resize)), true }; - m_defaultStylesheetVariables["cursor_ew_resize"] = { ostd::String("").add(static_cast(eCursor::EW_Resize)), true }; - m_defaultStylesheetVariables["cursor_ns_resize"] = { ostd::String("").add(static_cast(eCursor::NS_Resize)), true }; - m_defaultStylesheetVariables["cursor_move"] = { ostd::String("").add(static_cast(eCursor::Move)), true }; - m_defaultStylesheetVariables["cursor_no_allowed"] = { ostd::String("").add(static_cast(eCursor::NotAllowed)), true }; - m_defaultStylesheetVariables["cursor_pointer"] = { ostd::String("").add(static_cast(eCursor::Pointer)), true }; - m_defaultStylesheetVariables["cursor_nw_resize"] = { ostd::String("").add(static_cast(eCursor::NW_Resize)), true }; - m_defaultStylesheetVariables["cursor_n_resize"] = { ostd::String("").add(static_cast(eCursor::N_Resize)), true }; - m_defaultStylesheetVariables["cursor_ne_resize"] = { ostd::String("").add(static_cast(eCursor::NE_Resize)), true }; - m_defaultStylesheetVariables["cursor_e_resize"] = { ostd::String("").add(static_cast(eCursor::E_Resize)), true }; - m_defaultStylesheetVariables["cursor_se_resize"] = { ostd::String("").add(static_cast(eCursor::SE_Resize)), true }; - m_defaultStylesheetVariables["cursor_s_resize"] = { ostd::String("").add(static_cast(eCursor::S_Resize)), true }; - m_defaultStylesheetVariables["cursor_sw_resize"] = { ostd::String("").add(static_cast(eCursor::SW_Resize)), true }; - m_defaultStylesheetVariables["cursor_w_resize"] = { ostd::String("").add(static_cast(eCursor::W_Resize)), true }; + m_defaultStylesheetVariables["cursor_default"] = { String("").add(cast(eCursor::Default)), true }; + m_defaultStylesheetVariables["cursor_text"] = { String("").add(cast(eCursor::Text)), true }; + m_defaultStylesheetVariables["cursor_wait"] = { String("").add(cast(eCursor::Wait)), true }; + m_defaultStylesheetVariables["cursor_crosshair"] = { String("").add(cast(eCursor::Crosshair)), true }; + m_defaultStylesheetVariables["cursor_progress"] = { String("").add(cast(eCursor::Progress)), true }; + m_defaultStylesheetVariables["cursor_nwse_resize"] = { String("").add(cast(eCursor::NWSE_Resize)), true }; + m_defaultStylesheetVariables["cursor_nesw_resize"] = { String("").add(cast(eCursor::NESW_Resize)), true }; + m_defaultStylesheetVariables["cursor_ew_resize"] = { String("").add(cast(eCursor::EW_Resize)), true }; + m_defaultStylesheetVariables["cursor_ns_resize"] = { String("").add(cast(eCursor::NS_Resize)), true }; + m_defaultStylesheetVariables["cursor_move"] = { String("").add(cast(eCursor::Move)), true }; + m_defaultStylesheetVariables["cursor_no_allowed"] = { String("").add(cast(eCursor::NotAllowed)), true }; + m_defaultStylesheetVariables["cursor_pointer"] = { String("").add(cast(eCursor::Pointer)), true }; + m_defaultStylesheetVariables["cursor_nw_resize"] = { String("").add(cast(eCursor::NW_Resize)), true }; + m_defaultStylesheetVariables["cursor_n_resize"] = { String("").add(cast(eCursor::N_Resize)), true }; + m_defaultStylesheetVariables["cursor_ne_resize"] = { String("").add(cast(eCursor::NE_Resize)), true }; + m_defaultStylesheetVariables["cursor_e_resize"] = { String("").add(cast(eCursor::E_Resize)), true }; + m_defaultStylesheetVariables["cursor_se_resize"] = { String("").add(cast(eCursor::SE_Resize)), true }; + m_defaultStylesheetVariables["cursor_s_resize"] = { String("").add(cast(eCursor::S_Resize)), true }; + m_defaultStylesheetVariables["cursor_sw_resize"] = { String("").add(cast(eCursor::SW_Resize)), true }; + m_defaultStylesheetVariables["cursor_w_resize"] = { String("").add(cast(eCursor::W_Resize)), true }; // Colors m_defaultStylesheetVariables["color_transparent"] = { "Color(" + ostd::Colors::Transparent.hexString(true, "#") + ")", true }; @@ -499,18 +500,18 @@ namespace ogfx - void GraphicsWindow::__on_window_init(int32_t width, int32_t height, const ostd::String& title) + void GraphicsWindow::__on_window_init(i32 width, i32 height, const String& title) { SDL_SetWindowResizable(m_window, false); - m_fixedUpdateTImer.create(60.0, [this](double frameTime_s){ + m_fixedUpdateTImer.create(60.0, [this](f64 frameTime_s){ this->onFixedUpdate(frameTime_s); }); - m_fpsUpdateTimer.create(1.0, [this](double frameTime_s){ + m_fpsUpdateTimer.create(1.0, [this](f64 frameTime_s){ if (this->m_frameCount == 0) return; if (this->m_frameTimeAcc == 0) return; - this->m_fps = (int32_t)(1.0f / (static_cast(this->m_frameTimeAcc) / static_cast(this->m_frameCount))); + this->m_fps = (i32)(1.0f / (cast(this->m_frameTimeAcc) / cast(this->m_frameCount))); this->m_frameTimeAcc = 0; this->m_frameCount = 0; }); @@ -569,14 +570,19 @@ namespace ogfx m_rootWidget.__applyTheme(theme, true); } - void Window::__on_window_init(int32_t width, int32_t height, const ostd::String& title) + void Window::__on_window_init(i32 width, i32 height, const String& title) { enableBlockingEvents(); setTypeName("ogfx::gui::Window"); m_gfx.init(*this); loadDefaultTHeme(); + + m_fixedUpdateTimer.create(60.0, [this](f64 dt) { + __on_fixed_update(); + }); + m_lastFrameTime = ostd::StepTimer::Clock::now(); onInitialize(); - m_rootWidget.setSize(static_cast(width), static_cast(height)); + m_rootWidget.setSize(cast(width), cast(height)); } void Window::__on_window_close(void) @@ -588,6 +594,16 @@ namespace ogfx { while (isRunning()) { + auto now = ostd::StepTimer::Clock::now(); + f64 delta = std::chrono::duration(now - m_lastFrameTime).count(); + m_lastFrameTime = now; + + if (delta > 0.25) + delta = 0.25; + + m_fixedUpdateTimer.update(); + __on_update(delta); + handle_events(); before_render(); m_rootWidget.__update(); @@ -688,6 +704,16 @@ namespace ogfx onSignal(signal); } + void Window::__on_update(f64 delta) + { + onUpdate(delta); + } + + void Window::__on_fixed_update(void) + { + onFixedUpdate(); + } + void Window::__on_event(SDL_Event& event) { onSDLEvent(event); diff --git a/src/ogfx/gui/Window.hpp b/src/ogfx/gui/Window.hpp index ad32664..b45b450 100644 --- a/src/ogfx/gui/Window.hpp +++ b/src/ogfx/gui/Window.hpp @@ -34,44 +34,44 @@ namespace ogfx { class WindowCore : public ostd::BaseObject { - public: enum class eCursor : uint8_t + public: enum class eCursor : u8 { - Default = 0, - Text, - Wait, - Crosshair, - Progress, - NWSE_Resize, - NESW_Resize, - EW_Resize, - NS_Resize, - Move, - NotAllowed, - Pointer, - NW_Resize, - N_Resize, - NE_Resize, - E_Resize, - SE_Resize, - S_Resize, - SW_Resize, - W_Resize, + Default = 0, + Text, + Wait, + Crosshair, + Progress, + NWSE_Resize, + NESW_Resize, + EW_Resize, + NS_Resize, + Move, + NotAllowed, + Pointer, + NW_Resize, + N_Resize, + NE_Resize, + E_Resize, + SE_Resize, + S_Resize, + SW_Resize, + W_Resize, - Count + Count }; public: inline WindowCore(void) { } virtual ~WindowCore(void); - inline WindowCore(int32_t width, int32_t height, const ostd::String& title) { initialize(width, height, title); } - void initialize(int32_t width, int32_t height, const ostd::String& title); + inline WindowCore(i32 width, i32 height, const String& title) { initialize(width, height, title); } + void initialize(i32 width, i32 height, const String& title); void mainLoop(void); void close(void); - void setSize(int32_t width, int32_t height); - void setTitle(const ostd::String& title); + void setSize(i32 width, i32 height); + void setTitle(const String& title); void setCursor(eCursor cursor); void enableResizable(bool enable = true); - void setIcon(const ostd::String& iconFilePath); - void setBlockingEventsRefreshFPS(uint32_t fps); + void setIcon(const String& iconFilePath); + void setBlockingEventsRefreshFPS(u32 fps); void requestRedraw(void); void handleSignal(ostd::Signal& signal) override; @@ -86,9 +86,9 @@ namespace ogfx inline bool isResizeable(void) const { return m_resizeable; } inline void hide(void) { SDL_HideWindow(m_window); m_visible = false; } inline void show(void) { SDL_ShowWindow(m_window); m_visible = true; } - inline ostd::String getTitle(void) const { return m_title; } - inline int32_t getWindowWidth(void) const { return m_windowWidth; } - inline int32_t getWindowHeight(void) const { return m_windowHeight; } + inline String getTitle(void) const { return m_title; } + inline i32 getWindowWidth(void) const { return m_windowWidth; } + inline i32 getWindowHeight(void) const { return m_windowHeight; } inline ostd::Color getClearColor(void) const { return m_clearColor; } inline void setClearColor(const ostd::Color& color) { m_clearColor = color; } inline SDL_Renderer* getSDLRenderer(void) { return m_renderer; } @@ -103,10 +103,12 @@ namespace ogfx virtual void before_render(void); virtual void after_render(void); inline virtual void __on_event(SDL_Event& event) { } - inline virtual void __on_window_init(int32_t width, int32_t height, const ostd::String& title) { } + inline virtual void __on_window_init(i32 width, i32 height, const String& title) { } inline virtual void __on_window_destroy(void) { } inline virtual void __on_window_close(void) { } inline virtual void __on_signal(ostd::Signal& signal) { } + inline virtual void __on_update(f64 delta) { } + inline virtual void __on_fixed_update(void) { } inline virtual void __main_loop(void) = 0; private: @@ -123,10 +125,10 @@ namespace ogfx private: ostd::Color m_clearColor { 10, 10, 10, 255 }; - int32_t m_windowWidth { 0 }; - int32_t m_windowHeight { 0 }; - ostd::String m_title { "" }; - int32_t m_blockingEventsDelay { 33 }; + i32 m_windowWidth { 0 }; + i32 m_windowHeight { 0 }; + String m_title { "" }; + i32 m_blockingEventsDelay { 33 }; bool m_running { false }; bool m_initialized { false }; @@ -157,33 +159,33 @@ namespace ogfx SDL_Cursor* m_cursor_W_Resize { nullptr }; public: - inline static constexpr int32_t MaxBlockingEventsFPS { 240 }; - inline static constexpr int32_t DefaultBlockingEventsFPS { 30 }; + inline static constexpr i32 MaxBlockingEventsFPS { 240 }; + inline static constexpr i32 DefaultBlockingEventsFPS { 30 }; private: inline static ostd::Stylesheet DefaultTheme; - std::unordered_map> m_defaultStylesheetVariables; + stdumap> m_defaultStylesheetVariables; }; class GraphicsWindow : public WindowCore { public: inline GraphicsWindow(void) { } - inline GraphicsWindow(int32_t width, int32_t height, const ostd::String& title) { initialize(width, height, title); } + inline GraphicsWindow(i32 width, i32 height, const String& title) { initialize(width, height, title); } inline virtual void onRender(void) { } inline virtual void onUpdate(void) { } - inline virtual void onFixedUpdate(double frameTime_s) { } + inline virtual void onFixedUpdate(f64 frameTime_s) { } inline virtual void onInitialize(void) { } inline virtual void onDestroy(void) { } inline virtual void onClose(void) { } inline virtual void onSDLEvent(SDL_Event& event) { } inline virtual void onSignal(ostd::Signal& signal) { } - inline int32_t getFPS(void) const { return m_fps; } + inline i32 getFPS(void) const { return m_fps; } protected: - void __on_window_init(int32_t width, int32_t height, const ostd::String& title) override; + void __on_window_init(i32 width, i32 height, const String& title) override; void __on_event(SDL_Event& event) override; void __on_window_destroy(void) override; void __on_window_close(void) override; @@ -191,12 +193,12 @@ namespace ogfx void __on_signal(ostd::Signal& signal) override; private: - int32_t m_fps { 0 }; + i32 m_fps { 0 }; ostd::StepTimer m_fixedUpdateTImer; ostd::StepTimer m_fpsUpdateTimer; ostd::Timer m_fpsUpdateClock; - uint64_t m_frameTimeAcc { 0 }; - int32_t m_frameCount { 0 }; + u64 m_frameTimeAcc { 0 }; + i32 m_frameCount { 0 }; }; namespace gui { @@ -204,7 +206,7 @@ namespace ogfx { public: inline Window(void) { } - inline Window(int32_t width, int32_t height, const ostd::String& title) { initialize(width, height, title); } + inline Window(i32 width, i32 height, const String& title) { initialize(width, height, title); } void addWidget(Widget& widget); void setTheme(const ostd::Stylesheet& theme) override; @@ -213,20 +215,25 @@ namespace ogfx inline virtual void onClose(void) { } inline virtual void onSDLEvent(SDL_Event& event) { } inline virtual void onRedraw(BasicRenderer2D& gfx) { } - inline virtual void onUpdate(double delta) { } + inline virtual void onUpdate(f64 delta) { } + inline virtual void onFixedUpdate(void) { } inline virtual void onSignal(ostd::Signal& signal) { } protected: - void __on_window_init(int32_t width, int32_t height, const ostd::String& title) override; + void __on_window_init(i32 width, i32 height, const String& title) override; void __on_event(SDL_Event& event) override; void __on_window_destroy(void) override; void __on_window_close(void) override; void __main_loop(void) override; void __on_signal(ostd::Signal& signal) override; + void __on_update(f64 delta) override; + void __on_fixed_update(void) override; protected: BasicRenderer2D m_gfx; widgets::RootWidget m_rootWidget { *this }; + ostd::StepTimer m_fixedUpdateTimer; + ostd::StepTimer::TimePoint m_lastFrameTime; }; } } diff --git a/src/ogfx/gui/WindowOutputHandler.cpp b/src/ogfx/gui/WindowOutputHandler.cpp index 05baf7a..f30bd23 100644 --- a/src/ogfx/gui/WindowOutputHandler.cpp +++ b/src/ogfx/gui/WindowOutputHandler.cpp @@ -108,7 +108,7 @@ namespace ogfx m_defaultForegroundColor = color; } - void GraphicsWindowOutputHandler::setTabWidth(uint8_t tw) + void GraphicsWindowOutputHandler::setTabWidth(u8 tw) { m_tabWidth = tw; } @@ -116,24 +116,24 @@ namespace ogfx - void GraphicsWindowOutputHandler::setFontSize(int32_t fontSize) + void GraphicsWindowOutputHandler::setFontSize(i32 fontSize) { m_fontSize = fontSize; m_renderer.setFontSize(m_fontSize); __update_char_size(); } - int32_t GraphicsWindowOutputHandler::getFontSize(void) + i32 GraphicsWindowOutputHandler::getFontSize(void) { return m_fontSize; } - Vec2 GraphicsWindowOutputHandler::getCharacterSize(int32_t fontSize) + Vec2 GraphicsWindowOutputHandler::getCharacterSize(i32 fontSize) { if (fontSize > 0) { auto size = m_renderer.getStringDimensions("A", fontSize); - return { (float)size.x, (float)size.y }; + return { (f32)size.x, (f32)size.y }; } return m_charSize; } @@ -163,15 +163,15 @@ namespace ogfx return m_defaultForegroundColor; } - uint8_t GraphicsWindowOutputHandler::getTabWidth(void) + u8 GraphicsWindowOutputHandler::getTabWidth(void) { return m_tabWidth; } Rectangle GraphicsWindowOutputHandler::getConsoleBounds(void) { - float console_w = ((float)m_consoleSize.x * getCharacterSize().x) + getPadding().x + getPadding().w; - float console_h = ((float)m_consoleSize.y * getCharacterSize().y) + getPadding().y + getPadding().h; + f32 console_w = ((f32)m_consoleSize.x * getCharacterSize().x) + getPadding().x + getPadding().w; + f32 console_h = ((f32)m_consoleSize.y * getCharacterSize().y) + getPadding().y + getPadding().h; return { getConsolePosition().x - getPadding().x, getConsolePosition().y - getPadding().y, console_w, console_h }; } @@ -216,7 +216,7 @@ namespace ogfx GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pChar(char c) { - __print_string(ostd::String("").addChar(c)); + __print_string(String("").addChar(c)); return *this; } @@ -230,7 +230,7 @@ namespace ogfx if (!styled.validate()) return *this; Color oldBgCol = m_backgroundColor; Color oldFgCol = m_foregroundColor; - for (int32_t i = 0; i < styled.text.len(); i++) + for (i32 i = 0; i < styled.text.len(); i++) bg(styled.backgroundColors[i].fullColor).fg(styled.foregroundColors[i].fullColor).pChar(styled.text[i]); m_backgroundColor = oldBgCol; m_foregroundColor = oldFgCol; @@ -261,63 +261,63 @@ namespace ogfx return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint8_t i) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(u8 i) { - __print_string(ostd::String("").add(i)); + __print_string(String("").add(i)); return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int8_t i) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(i8 i) { - __print_string(ostd::String("").add(i)); + __print_string(String("").add(i)); return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint16_t i) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(u16 i) { - __print_string(ostd::String("").add(i)); + __print_string(String("").add(i)); return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int16_t i) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(i16 i) { - __print_string(ostd::String("").add(i)); + __print_string(String("").add(i)); return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint32_t i) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(u32 i) { - __print_string(ostd::String("").add(i)); + __print_string(String("").add(i)); return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int32_t i) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(i32 i) { - __print_string(ostd::String("").add(i)); + __print_string(String("").add(i)); return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint64_t i) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(u64 i) { - __print_string(ostd::String("").add(i)); + __print_string(String("").add(i)); return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int64_t i) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(i64 i) { - __print_string(ostd::String("").add(i)); + __print_string(String("").add(i)); return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(float f, uint8_t precision) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(f32 f, u8 precision) { - __print_string(ostd::String("").add(f, precision)); + __print_string(String("").add(f, precision)); return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(double f, uint8_t precision) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(f64 f, u8 precision) { - __print_string(ostd::String("").add(f, precision)); + __print_string(String("").add(f, precision)); return *this; } @@ -333,14 +333,14 @@ namespace ogfx { if (m_curosrPosition.x == 0) { - __print_string(ostd::String("").fixedLength(m_tabWidth, ' ', "")); + __print_string(String("").fixedLength(m_tabWidth, ' ', "")); return *this; } - int32_t restTab = m_tabWidth - ((int32_t)m_curosrPosition.x % m_tabWidth); + i32 restTab = m_tabWidth - ((i32)m_curosrPosition.x % m_tabWidth); if (m_curosrPosition.x + restTab > m_consoleSize.x) restTab = m_consoleSize.x - m_curosrPosition.x; if (restTab == 0) return *this; - __print_string(ostd::String("").fixedLength(restTab, ' ', "")); + __print_string(String("").fixedLength(restTab, ' ', "")); return *this; } @@ -362,53 +362,53 @@ namespace ogfx GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::xy(IPoint position) { - m_curosrPosition = { (float)position.x, (float)position.y }; + m_curosrPosition = { (f32)position.x, (f32)position.y }; return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::xy(int32_t x, int32_t y) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::xy(i32 x, i32 y) { - m_curosrPosition = { (float)x, (float)y }; + m_curosrPosition = { (f32)x, (f32)y }; return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::x(int32_t x) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::x(i32 x) { - m_curosrPosition.x = (float)x; + m_curosrPosition.x = (f32)x; return *this; } - GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::y(int32_t y) + GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::y(i32 y) { - m_curosrPosition.y = (float)y; + m_curosrPosition.y = (f32)y; return *this; } IPoint GraphicsWindowOutputHandler::getCursorPosition(void) { - return { (int32_t)std::round(m_curosrPosition.x), (int32_t)std::round(m_curosrPosition.y) }; + return { (i32)std::round(m_curosrPosition.x), (i32)std::round(m_curosrPosition.y) }; } - void GraphicsWindowOutputHandler::getCursorPosition(int32_t& outX, int32_t& outY) + void GraphicsWindowOutputHandler::getCursorPosition(i32& outX, i32& outY) { - outX = (int32_t)std::round(m_curosrPosition.x); - outY = (int32_t)std::round(m_curosrPosition.y); + outX = (i32)std::round(m_curosrPosition.x); + outY = (i32)std::round(m_curosrPosition.y); } - int32_t GraphicsWindowOutputHandler::getCursorX(void) + i32 GraphicsWindowOutputHandler::getCursorX(void) { - return (int32_t)std::round(m_curosrPosition.x); + return (i32)std::round(m_curosrPosition.x); } - int32_t GraphicsWindowOutputHandler::getCursorY(void) + i32 GraphicsWindowOutputHandler::getCursorY(void) { - return (int32_t)std::round(m_curosrPosition.y); + return (i32)std::round(m_curosrPosition.y); } - void GraphicsWindowOutputHandler::getConsoleSize(int32_t& outColumns, int32_t& outRows) + void GraphicsWindowOutputHandler::getConsoleSize(i32& outColumns, i32& outRows) { - int32_t console_rows = std::numeric_limits::max(); - int32_t console_cols = std::numeric_limits::max(); + i32 console_rows = std::numeric_limits::max(); + i32 console_cols = std::numeric_limits::max(); if (m_consoleSize.x > 0) console_cols = m_consoleSize.x; if (m_consoleSize.y > 0) console_rows = m_consoleSize.y; outColumns = console_cols; @@ -417,8 +417,8 @@ namespace ogfx IPoint GraphicsWindowOutputHandler::getConsoleSize(void) { - int32_t console_rows = std::numeric_limits::max(); - int32_t console_cols = std::numeric_limits::max(); + i32 console_rows = std::numeric_limits::max(); + i32 console_cols = std::numeric_limits::max(); if (m_consoleSize.x > 0) console_cols = m_consoleSize.x; if (m_consoleSize.y > 0) console_rows = m_consoleSize.y; return { console_cols, console_rows }; @@ -427,7 +427,7 @@ namespace ogfx void GraphicsWindowOutputHandler::__update_char_size(void) { auto size = m_renderer.getStringDimensions("A", m_fontSize); - m_charSize = { (float)size.x, (float)size.y }; + m_charSize = { (f32)size.x, (f32)size.y }; } void GraphicsWindowOutputHandler::__print_string(const String& str) @@ -439,7 +439,7 @@ namespace ogfx auto l_print = [&](const String& string) { if (l_endOfConsole()) return; if (string.len() == 0) return; - float vertical_margin = 4; + f32 vertical_margin = 4; Vec2 pos = m_consolePosition + ostd::Vec2 { m_charSize.x * m_curosrPosition.x, m_charSize.y * m_curosrPosition.y }; if (m_backgroundColor.a > 0) m_renderer.fillRect({ pos.x, pos.y + vertical_margin, m_charSize.x * string.len(), m_charSize.y - vertical_margin }, m_backgroundColor); @@ -449,8 +449,8 @@ namespace ogfx if (m_curosrPosition.x >= getConsoleSize().x) nl(); }; - int32_t string_length = str.len(); - int32_t lineLen = m_curosrPosition.x + string_length; + i32 string_length = str.len(); + i32 lineLen = m_curosrPosition.x + string_length; if (lineLen <= getConsoleSize().x) { l_print(str); @@ -458,24 +458,24 @@ namespace ogfx } if (m_wrapMode == eWrapMode::TripleDots) { - int32_t fixedLen = getConsoleSize().x - m_curosrPosition.x; + i32 fixedLen = getConsoleSize().x - m_curosrPosition.x; l_print(str.new_fixedLength(fixedLen, ' ', "...")); } else if (m_wrapMode == eWrapMode::NewLine) { - int32_t restOfLine = getConsoleSize().x - m_curosrPosition.x; - ostd::String tmp = str.new_substr(0, restOfLine); + i32 restOfLine = getConsoleSize().x - m_curosrPosition.x; + String tmp = str.new_substr(0, restOfLine); l_print(tmp); tmp = str.new_substr(restOfLine); - int32_t nlines = tmp.len() / getConsoleSize().x; + i32 nlines = tmp.len() / getConsoleSize().x; if (nlines == 0) { l_print(tmp); return; } - for (int32_t i = 0; i < nlines; i++) + for (i32 i = 0; i < nlines; i++) { - ostd::String line = tmp.new_substr(0, getConsoleSize().x); + String line = tmp.new_substr(0, getConsoleSize().x); l_print(line); tmp.substr(getConsoleSize().x); } diff --git a/src/ogfx/gui/WindowOutputHandler.hpp b/src/ogfx/gui/WindowOutputHandler.hpp index 8c6423f..5355222 100644 --- a/src/ogfx/gui/WindowOutputHandler.hpp +++ b/src/ogfx/gui/WindowOutputHandler.hpp @@ -33,56 +33,56 @@ namespace ogfx public: GraphicsWindowOutputHandler(void); void attachWindow(WindowCore& window); - void setMonospaceFont(const ostd::String& filePath); - ostd::Vec2 getStringSize(const ostd::String& str); + void setMonospaceFont(const String& filePath); + ostd::Vec2 getStringSize(const String& str); bool isReady(void); void resetCursorPosition(void); void resetColors(void); void beginFrame(void); - void setFontSize(int32_t fontSize); + void setFontSize(i32 fontSize); void setConsoleMaxCharacters(const ostd::IPoint& size); void setConsolePosition(const ostd::Vec2& pos); void setWrapMode(eWrapMode wrapMode); void setPadding(const ostd::Rectangle& rect); void setDefaultForegroundColor(const ostd::Color& color); void setDefaultBackgorundColor(const ostd::Color& color); - void setTabWidth(uint8_t tw); + void setTabWidth(u8 tw); - int32_t getFontSize(void); - ostd::Vec2 getCharacterSize(int32_t fontSize = 0); + i32 getFontSize(void); + ostd::Vec2 getCharacterSize(i32 fontSize = 0); ostd::Vec2 getConsolePosition(void); eWrapMode getWrapMode(void); ostd::Rectangle getPadding(void); ostd::Color getDefaultBackgroundColor(void); ostd::Color getDefaultForegroundColor(void); - uint8_t getTabWidth(void); + u8 getTabWidth(void); ostd::Rectangle getConsoleBounds(void); GraphicsWindowOutputHandler& bg(const ostd::Color& color) override; GraphicsWindowOutputHandler& bg(const ostd::ConsoleColors::tConsoleColor& color) override; - GraphicsWindowOutputHandler& bg(const ostd::String& color) override; + GraphicsWindowOutputHandler& bg(const String& color) override; GraphicsWindowOutputHandler& fg(const ostd::Color& color) override; GraphicsWindowOutputHandler& fg(const ostd::ConsoleColors::tConsoleColor& color) override; - GraphicsWindowOutputHandler& fg(const ostd::String& color) override; + GraphicsWindowOutputHandler& fg(const String& color) override; GraphicsWindowOutputHandler& pChar(char c) override; - GraphicsWindowOutputHandler& pStyled(const ostd::String& styled) override; + GraphicsWindowOutputHandler& pStyled(const String& styled) override; GraphicsWindowOutputHandler& pStyled(const ostd::TextStyleParser::tStyledString& styled) override; GraphicsWindowOutputHandler& pStyled(ostd::TextStyleBuilder::IRichStringBase& styled) override; GraphicsWindowOutputHandler& pObject(const ostd::BaseObject& bo) override; - GraphicsWindowOutputHandler& p(const ostd::String& se) override; - GraphicsWindowOutputHandler& p(uint8_t i) override; - GraphicsWindowOutputHandler& p(int8_t i) override; - GraphicsWindowOutputHandler& p(uint16_t i) override; - GraphicsWindowOutputHandler& p(int16_t i) override; - GraphicsWindowOutputHandler& p(uint32_t i) override; - GraphicsWindowOutputHandler& p(int32_t i) override; - GraphicsWindowOutputHandler& p(uint64_t i) override; - GraphicsWindowOutputHandler& p(int64_t i) override; - GraphicsWindowOutputHandler& p(float f, uint8_t precision = 0) override; - GraphicsWindowOutputHandler& p(double f, uint8_t precision = 0) override; + GraphicsWindowOutputHandler& p(const String& se) override; + GraphicsWindowOutputHandler& p(u8 i) override; + GraphicsWindowOutputHandler& p(i8 i) override; + GraphicsWindowOutputHandler& p(u16 i) override; + GraphicsWindowOutputHandler& p(i16 i) override; + GraphicsWindowOutputHandler& p(u32 i) override; + GraphicsWindowOutputHandler& p(i32 i) override; + GraphicsWindowOutputHandler& p(u64 i) override; + GraphicsWindowOutputHandler& p(i64 i) override; + GraphicsWindowOutputHandler& p(f32 f, u8 precision = 0) override; + GraphicsWindowOutputHandler& p(f64 f, u8 precision = 0) override; GraphicsWindowOutputHandler& nl(void) override; GraphicsWindowOutputHandler& tab(void) override; @@ -91,21 +91,21 @@ namespace ogfx GraphicsWindowOutputHandler& reset(void) override; GraphicsWindowOutputHandler& xy(ostd::IPoint position) override; - GraphicsWindowOutputHandler& xy(int32_t x, int32_t y) override; - GraphicsWindowOutputHandler& x(int32_t x) override; - GraphicsWindowOutputHandler& y(int32_t y) override; + GraphicsWindowOutputHandler& xy(i32 x, i32 y) override; + GraphicsWindowOutputHandler& x(i32 x) override; + GraphicsWindowOutputHandler& y(i32 y) override; ostd::IPoint getCursorPosition(void) override; - void getCursorPosition(int32_t& outX, int32_t& outY) override; - int32_t getCursorX(void) override; - int32_t getCursorY(void) override; + void getCursorPosition(i32& outX, i32& outY) override; + i32 getCursorX(void) override; + i32 getCursorY(void) override; - void getConsoleSize(int32_t& outColumns, int32_t& outRows) override; + void getConsoleSize(i32& outColumns, i32& outRows) override; ostd::IPoint getConsoleSize(void) override; private: void __update_char_size(void); - void __print_string(const ostd::String& str); + void __print_string(const String& str); private: ostd::Color m_backgroundColor; @@ -115,13 +115,13 @@ namespace ogfx ostd::Vec2 m_curosrPosition; BasicRenderer2D m_renderer; WindowCore* m_window { nullptr }; - int32_t m_fontSize { 20 }; + i32 m_fontSize { 20 }; ostd::Vec2 m_charSize; ostd::IPoint m_consoleSize { 0, 0 }; bool m_ready { false }; ostd::Vec2 m_consolePosition { 0.0f, 0.0f }; eWrapMode m_wrapMode { eWrapMode::TripleDots }; ostd::Rectangle m_padding { 10, 10, 10, 10 }; - uint8_t m_tabWidth { 8 }; + u8 m_tabWidth { 8 }; }; } diff --git a/src/ogfx/gui/widgets/CheckBox.cpp b/src/ogfx/gui/widgets/CheckBox.cpp index 433f045..b610de4 100644 --- a/src/ogfx/gui/widgets/CheckBox.cpp +++ b/src/ogfx/gui/widgets/CheckBox.cpp @@ -27,7 +27,7 @@ namespace ogfx { namespace widgets { - CheckBox& CheckBox::create(const ostd::String& text) + CheckBox& CheckBox::create(const String& text) { setText(text); setPadding({ 5, 5, 5, 5 }); @@ -45,16 +45,16 @@ namespace ogfx setCheckBoxColor(getThemeValue(theme, "checkbox.checkBoxColor", ostd::Colors::White)); setTextColor(getThemeValue(theme, "checkbox.textColor", ostd::Colors::Black)); setBackGroundColor(getThemeValue(theme, "checkbox.backgroundColor", ostd::Colors::Transparent)); - setFontSize(getThemeValue(theme, "checkbox.fontSize", 28)); - setBorderRadius(getThemeValue(theme, "checkbox.borderRadius", 10)); - setBorderWidth(getThemeValue(theme, "checkbox.borderWidth", 2)); + setFontSize(getThemeValue(theme, "checkbox.fontSize", 28)); + setBorderRadius(getThemeValue(theme, "checkbox.borderRadius", 10)); + setBorderWidth(getThemeValue(theme, "checkbox.borderWidth", 2)); enableBorder(getThemeValue(theme, "checkbox.showBorder", false)); setBorderColor(getThemeValue(theme, "checkbox.borderColor", ostd::Colors::White)); enableBackground(getThemeValue(theme, "checkbox.showBackground", false)); setPadding(getThemeValue(theme, "checkbox.padding", { 5, 5, 5, 5 })); setMargin(getThemeValue(theme, "checkbox.margin", { 0, 0, 0, 0 })); - m_checkBorderRadius = getThemeValue(theme, "checkbox.checkBorderRadius", 5); - m_checkBorderWidth = getThemeValue(theme, "checkbox.checkBorderWidth", 1); + m_checkBorderRadius = getThemeValue(theme, "checkbox.checkBorderRadius", 5); + m_checkBorderWidth = getThemeValue(theme, "checkbox.checkBorderWidth", 1); } void CheckBox::onDraw(ogfx::BasicRenderer2D& gfx) @@ -74,7 +74,7 @@ namespace ogfx setChecked(!isChecked()); } - void CheckBox::setText(const ostd::String& text) + void CheckBox::setText(const String& text) { m_text = text; m_textChanged = true; @@ -82,7 +82,9 @@ namespace ogfx void CheckBox::setChecked(bool checked) { - m_checked = !m_checked; + if (m_checked == checked) + return; + m_checked = checked; setThemeQualifier("active", m_checked); if (callback_onStateChanged) callback_onStateChanged(*this, m_checked); @@ -91,13 +93,13 @@ namespace ogfx void CheckBox::__update_size(ogfx::BasicRenderer2D& gfx) { auto size = gfx.getStringDimensions(getText(), getFontSize()); - m_checkSize = { static_cast(size.y), static_cast(size.y) }; + m_checkSize = { cast(size.y), cast(size.y) }; size.x += m_spacing + m_checkSize.x; size.x += getPadding().left(); size.x += getPadding().right(); size.y += getPadding().top(); size.y += getPadding().bottom(); - setSize({ static_cast(size.x), static_cast(size.y) }); + setSize({ cast(size.x), cast(size.y) }); m_textChanged = false; } } diff --git a/src/ogfx/gui/widgets/CheckBox.hpp b/src/ogfx/gui/widgets/CheckBox.hpp index e3b8a5f..de48b62 100644 --- a/src/ogfx/gui/widgets/CheckBox.hpp +++ b/src/ogfx/gui/widgets/CheckBox.hpp @@ -34,22 +34,22 @@ namespace ogfx { public: inline CheckBox(WindowCore& window) : Widget({ 0, 0, 0, 0 }, window) { create(""); } - inline CheckBox(WindowCore& window, const ostd::String& text) : Widget({ 0, 0, 0, 0 }, window) { create(text); } - CheckBox& create(const ostd::String& text); + inline CheckBox(WindowCore& window, const String& text) : Widget({ 0, 0, 0, 0 }, window) { create(text); } + CheckBox& create(const String& text); void applyTheme(const ostd::Stylesheet& theme) override; void onDraw(ogfx::BasicRenderer2D& gfx) override; void onMouseReleased(const Event& event) override; - void setText(const ostd::String& text); + void setText(const String& text); void setChecked(bool checked); - inline ostd::String getText(void) const { return m_text; } + inline String getText(void) const { return m_text; } inline ostd::Color getCheckBorderColor(void) const { return m_checkBorderColor; } inline void setCheckBorderColor(const ostd::Color& color) { m_checkBorderColor = color; } inline ostd::Color getCheckBoxColor(void) const { return m_checkBoxColor; } inline void setCheckBoxColor(const ostd::Color& color) { m_checkBoxColor = color; } inline ostd::Color getTextColor(void) const { return m_textColor; } inline void setTextColor(const ostd::Color& color) { m_textColor = color; } - inline int32_t getFontSize(void) const { return m_fontSize; } - inline void setFontSize(int32_t fontSize) { m_fontSize = fontSize; } + inline i32 getFontSize(void) const { return m_fontSize; } + inline void setFontSize(i32 fontSize) { m_fontSize = fontSize; } inline bool isChecked(void) const { return m_checked; } inline void setStateChangedCallback(std::function callback) { callback_onStateChanged = callback; } @@ -58,14 +58,14 @@ namespace ogfx private: bool m_checked { false }; - ostd::String m_text { "" }; + String m_text { "" }; bool m_textChanged { false }; - int32_t m_fontSize { 20 }; + i32 m_fontSize { 20 }; ostd::Color m_textColor { 255, 255, 255 }; - float m_spacing { 10 }; + f32 m_spacing { 10 }; ostd::Vec2 m_checkSize { 0, 0 }; - int32_t m_checkBorderRadius { 5 }; - int32_t m_checkBorderWidth { 1 }; + i32 m_checkBorderRadius { 5 }; + i32 m_checkBorderWidth { 1 }; ostd::Color m_checkBorderColor { 255, 255, 255 }; ostd::Color m_checkBoxColor { 255, 255, 255 }; diff --git a/src/ogfx/gui/widgets/Containers.cpp b/src/ogfx/gui/widgets/Containers.cpp index 3612303..33bc6dc 100644 --- a/src/ogfx/gui/widgets/Containers.cpp +++ b/src/ogfx/gui/widgets/Containers.cpp @@ -41,15 +41,15 @@ namespace ogfx void Panel::applyTheme(const ostd::Stylesheet& theme) { setBackGroundColor(getThemeValue(theme, "panel.backgroundColor", ostd::Colors::Gray)); - setBorderRadius(getThemeValue(theme, "panel.borderRadius", 8)); - setBorderWidth(getThemeValue(theme, "panel.borderWidth", 2)); + setBorderRadius(getThemeValue(theme, "panel.borderRadius", 8)); + setBorderWidth(getThemeValue(theme, "panel.borderWidth", 2)); enableBorder(getThemeValue(theme, "panel.showBorder", true)); enableBackground(getThemeValue(theme, "panel.showBackground", true)); setBorderColor(getThemeValue(theme, "panel.borderColor", ostd::Colors::Black)); m_titleColor = getThemeValue(theme, "panel.titleColor", ostd::Colors::Black); m_showTitle = getThemeValue(theme, "panel.showTitle", false); - m_titleHeight = getThemeValue(theme, "panel.titleHeight", 30); - m_titleType = getThemeValue(theme, "panel.titleHeight", "text"); + m_titleHeight = getThemeValue(theme, "panel.titleHeight", 30); + m_titleType = getThemeValue(theme, "panel.titleHeight", "text"); setPadding(getThemeValue(theme, "panel.padding", { 15, 15, 15, 15 })); } diff --git a/src/ogfx/gui/widgets/Containers.hpp b/src/ogfx/gui/widgets/Containers.hpp index c8951ca..d841c3e 100644 --- a/src/ogfx/gui/widgets/Containers.hpp +++ b/src/ogfx/gui/widgets/Containers.hpp @@ -41,8 +41,8 @@ namespace ogfx private: ostd::Color m_titleColor { 0, 0, 0 }; bool m_showTitle { false }; - ostd::String m_titleType = "full"; - float m_titleHeight { 30 }; + String m_titleType = "full"; + f32 m_titleHeight { 30 }; }; } } diff --git a/src/ogfx/gui/widgets/Label.cpp b/src/ogfx/gui/widgets/Label.cpp index 3426336..36f6e92 100644 --- a/src/ogfx/gui/widgets/Label.cpp +++ b/src/ogfx/gui/widgets/Label.cpp @@ -27,7 +27,7 @@ namespace ogfx { namespace widgets { - Label& Label::create(const ostd::String& text) + Label& Label::create(const String& text) { setText(text); setPadding({ 5, 5, 5, 5 }); @@ -43,9 +43,9 @@ namespace ogfx { setColor(getThemeValue(theme, "label.textColor", ostd::Colors::White)); setBackGroundColor(getThemeValue(theme, "label.backgroundColor", ostd::Colors::Transparent)); - setFontSize(getThemeValue(theme, "label.fontSize", 20)); - setBorderRadius(getThemeValue(theme, "label.borderRadius", 10)); - setBorderWidth(getThemeValue(theme, "label.borderWidth", 2)); + setFontSize(getThemeValue(theme, "label.fontSize", 20)); + setBorderRadius(getThemeValue(theme, "label.borderRadius", 10)); + setBorderWidth(getThemeValue(theme, "label.borderWidth", 2)); enableBorder(getThemeValue(theme, "label.showBorder", false)); setBorderColor(getThemeValue(theme, "label.borderColor", ostd::Colors::White)); enableBackground(getThemeValue(theme, "label.showBackground", false)); @@ -60,7 +60,7 @@ namespace ogfx gfx.drawString(getText(), getGlobalContentPosition(), getColor(), getFontSize()); } - void Label::setText(const ostd::String& text) + void Label::setText(const String& text) { m_text = text; m_textChanged = true; @@ -73,7 +73,7 @@ namespace ogfx size.x += getPadding().right(); size.y += getPadding().top(); size.y += getPadding().bottom(); - setSize({ static_cast(size.x), static_cast(size.y) }); + setSize({ cast(size.x), cast(size.y) }); m_textChanged = false; } } diff --git a/src/ogfx/gui/widgets/Label.hpp b/src/ogfx/gui/widgets/Label.hpp index 529c6c5..455adcf 100644 --- a/src/ogfx/gui/widgets/Label.hpp +++ b/src/ogfx/gui/widgets/Label.hpp @@ -33,24 +33,24 @@ namespace ogfx { public: inline Label(WindowCore& window) : Widget({ 0, 0, 0, 0 }, window) { create(""); } - inline Label(WindowCore& window, const ostd::String& text) : Widget({ 0, 0, 0, 0 }, window) { create(text); } - Label& create(const ostd::String& text); + inline Label(WindowCore& window, const String& text) : Widget({ 0, 0, 0, 0 }, window) { create(text); } + Label& create(const String& text); void applyTheme(const ostd::Stylesheet& theme) override; void onDraw(ogfx::BasicRenderer2D& gfx) override; - void setText(const ostd::String& text); - inline ostd::String getText(void) const { return m_text; } + void setText(const String& text); + inline String getText(void) const { return m_text; } inline ostd::Color getColor(void) const { return m_color; } inline void setColor(const ostd::Color& color) { m_color = color; } - inline int32_t getFontSize(void) const { return m_fontSize; } - inline void setFontSize(int32_t fontSize) { m_fontSize = fontSize; } + inline i32 getFontSize(void) const { return m_fontSize; } + inline void setFontSize(i32 fontSize) { m_fontSize = fontSize; } private: void __update_size(ogfx::BasicRenderer2D& gfx); private: - ostd::String m_text { "" }; + String m_text { "" }; bool m_textChanged { false }; - int32_t m_fontSize { 20 }; + i32 m_fontSize { 20 }; ostd::Color m_color { 255, 255, 255 }; }; } diff --git a/src/ogfx/gui/widgets/RootWidget.cpp b/src/ogfx/gui/widgets/RootWidget.cpp index 098ca12..3840368 100644 --- a/src/ogfx/gui/widgets/RootWidget.cpp +++ b/src/ogfx/gui/widgets/RootWidget.cpp @@ -32,13 +32,13 @@ namespace ogfx { disableDrawBox(); m_rootChild = true; - setSize(static_cast(window.getWindowWidth()), static_cast(window.getWindowHeight())); + setSize(cast(window.getWindowWidth()), cast(window.getWindowHeight())); setTypeName("ogfx::gui::widgets::RootWidget"); } void RootWidget::onWindowResized(const Event& event) { - setSize(static_cast(event.windowResized->new_width), static_cast(event.windowResized->new_height)); + setSize(cast(event.windowResized->new_width), cast(event.windowResized->new_height)); } void RootWidget::applyTheme(const ostd::Stylesheet& theme) @@ -48,7 +48,7 @@ namespace ogfx void RootWidget::onDraw(ogfx::BasicRenderer2D& gfx) { - gfx.fillRect({ 0, 0, static_cast(getWindow().getWindowWidth()), static_cast(getWindow().getWindowHeight()) }, m_color); + gfx.fillRect({ 0, 0, cast(getWindow().getWindowWidth()), cast(getWindow().getWindowHeight()) }, m_color); } } } diff --git a/src/ogfx/gui/widgets/Widget.cpp b/src/ogfx/gui/widgets/Widget.cpp index a6471e4..6f4956b 100644 --- a/src/ogfx/gui/widgets/Widget.cpp +++ b/src/ogfx/gui/widgets/Widget.cpp @@ -86,7 +86,7 @@ namespace ogfx setThemeQualifier("disabled", !enable); } - void Widget::addThemeOverride(const ostd::String& fullKey, ostd::Stylesheet::TypeVariant value) + void Widget::addThemeOverride(const String& fullKey, ostd::Stylesheet::TypeVariant value) { m_themeOverrides.push_back({ fullKey, value }); } @@ -103,10 +103,10 @@ namespace ogfx struct tBackup { const ostd::Stylesheet::TypeVariant* ptr; ostd::Stylesheet::TypeVariant val; - ostd::String key; + String key; }; - std::vector backup; + stdvec backup; for (auto& rule : m_themeOverrides) { auto currentValuePtr = theme.getFull(rule.fullKey); @@ -126,7 +126,7 @@ namespace ogfx } } - void Widget::setThemeQualifier(const ostd::String& qualifier, bool value) + void Widget::setThemeQualifier(const String& qualifier, bool value) { for (auto& [name, state] : m_qualifierList) { @@ -140,7 +140,7 @@ namespace ogfx } } - bool Widget::getThemeQualifier(const ostd::String& qualifier) const + bool Widget::getThemeQualifier(const String& qualifier) const { for (auto& [name, state] : m_qualifierList) { @@ -150,7 +150,7 @@ namespace ogfx return false; } - bool Widget::addThemeID(const ostd::String& id) + bool Widget::addThemeID(const String& id) { if (STDVEC_CONTAINS(m_themeIDList, id)) return false; @@ -158,7 +158,7 @@ namespace ogfx return true; } - bool Widget::removeThemeID(const ostd::String& id) + bool Widget::removeThemeID(const String& id) { if (!STDVEC_CONTAINS(m_themeIDList, id)) return false; diff --git a/src/ogfx/gui/widgets/Widget.hpp b/src/ogfx/gui/widgets/Widget.hpp index 9cf5c7c..40f5e87 100644 --- a/src/ogfx/gui/widgets/Widget.hpp +++ b/src/ogfx/gui/widgets/Widget.hpp @@ -35,7 +35,7 @@ namespace ogfx { private: struct ThemeOverride { - ostd::String fullKey; + String fullKey; ostd::Stylesheet::TypeVariant value; }; public: using EventCallback = std::function; @@ -51,12 +51,12 @@ namespace ogfx bool contains(ostd::Vec2 p, bool includeBounds = false) const override; void enable(bool enable = true); virtual void applyTheme(const ostd::Stylesheet& theme) = 0; - void addThemeOverride(const ostd::String& fullKey, ostd::Stylesheet::TypeVariant value); + void addThemeOverride(const String& fullKey, ostd::Stylesheet::TypeVariant value); void reloadTheme(void); - void setThemeQualifier(const ostd::String& qualifier, bool value = true); - bool getThemeQualifier(const ostd::String& qualifier) const; - bool addThemeID(const ostd::String& id); - bool removeThemeID(const ostd::String& id); + void setThemeQualifier(const String& qualifier, bool value = true); + bool getThemeQualifier(const String& qualifier) const; + bool addThemeID(const String& id); + bool removeThemeID(const String& id); inline const ostd::Stylesheet::QualifierList& getThemeQualifierList(void) const { return m_qualifierList; } inline virtual void onDraw(ogfx::BasicRenderer2D& gfx) { } @@ -117,12 +117,12 @@ namespace ogfx inline bool hasChildren(void) const { return m_allowChildren && m_widgets.widgetCount() > 0; } inline virtual bool isInvalid(void) const override { return ostd::BaseObject::isInvalid() || (m_parent == nullptr && !m_rootChild); } - inline void setTabIndex(int32_t tabIndex) { m_tabIndex = tabIndex; } - inline int32_t getTabIndex(void) const { return m_tabIndex; } + inline void setTabIndex(i32 tabIndex) { m_tabIndex = tabIndex; } + inline i32 getTabIndex(void) const { return m_tabIndex; } inline bool isFocused(void) const { return m_focused; } inline WindowCore& getWindow(void) { return *m_window; } inline Widget* getParent(void) { return m_parent; } - inline int32_t getZIndex(void) const { return m_zIndex; } + inline i32 getZIndex(void) const { return m_zIndex; } inline bool isChildrenEnabled(void) const { return m_allowChildren; } inline void setPadding(const ostd::Rectangle& pad) { m_padding = pad; } inline void setMargin(const ostd::Rectangle& margin) { m_margin = margin; } @@ -130,7 +130,7 @@ namespace ogfx inline Rectangle getMargin(void) const { return m_margin; } inline bool isMouseInside(void) const { return m_mouseInside; } inline ogfx::MouseEventData::eButton getPressedMouseButton(void) const { return m_pressedButton; } - inline const std::vector& getThemeIDList(void) const { return m_themeIDList; } + inline const stdvec& getThemeIDList(void) const { return m_themeIDList; } inline bool isEnabled(void) const { return m_enabled; } inline bool isFocusEnabled(void) const { return m_allowFocus; } inline void enableFocus(bool enable = true) { m_allowFocus = enable; } @@ -148,13 +148,13 @@ namespace ogfx inline ostd::Color getBorderColor(void) { return m_borderColor; } inline void enableBorder(bool enable = true) { m_showBorder = enable; } inline bool isBorderEnabled(void) const { return m_showBorder; } - inline void setBorderRadius(int32_t br) { m_borderRadius = br; } - inline int32_t getBorderRadius(void) const { return m_borderRadius; } - inline void setBorderWidth(int32_t bw) { m_borderWidth = bw; } - inline int32_t getBorderWidth(void) const { return m_borderWidth; } + inline void setBorderRadius(i32 br) { m_borderRadius = br; } + inline i32 getBorderRadius(void) const { return m_borderRadius; } + inline void setBorderWidth(i32 bw) { m_borderWidth = bw; } + inline i32 getBorderWidth(void) const { return m_borderWidth; } template - inline T getThemeValue(const ostd::Stylesheet &theme, const ostd::String& key, const T& fallback) + inline T getThemeValue(const ostd::Stylesheet &theme, const String& key, const T& fallback) { return theme.get(key, fallback, getThemeIDList(), getThemeQualifierList()); } @@ -173,8 +173,8 @@ namespace ogfx protected: bool m_rootChild { false }; - int32_t m_borderRadius { 10 }; - int32_t m_borderWidth { 2 }; + i32 m_borderRadius { 10 }; + i32 m_borderWidth { 2 }; ostd::Color m_borderColor { 255, 255, 255 }; bool m_showBorder { false }; ostd::Color m_backgroundColor { ostd::Colors::Transparent }; @@ -200,8 +200,8 @@ namespace ogfx WindowCore* m_window { nullptr }; Widget* m_parent { nullptr }; bool m_focused { false }; - int32_t m_tabIndex { -1 }; - int32_t m_zIndex { -1 }; + i32 m_tabIndex { -1 }; + i32 m_zIndex { -1 }; WidgetManager m_widgets; bool m_allowChildren { true }; bool m_mouseInside { false }; @@ -212,7 +212,7 @@ namespace ogfx bool m_acceptDragAndDrop { false }; MouseEventData::eButton m_pressedButton { MouseEventData::eButton::None }; - std::vector m_themeIDList; + stdvec m_themeIDList; ostd::Stylesheet::QualifierList m_qualifierList { { "disabled", false }, { "pressed", false }, @@ -220,7 +220,7 @@ namespace ogfx { "focused", false }, { "active", false } }; - std::vector m_themeOverrides; + stdvec m_themeOverrides; bool m_drawBox { true }; ostd::Color m_drawBoxColor { 255, 0, 0 }; diff --git a/src/ogfx/render/BasicRenderer.cpp b/src/ogfx/render/BasicRenderer.cpp index 7f29435..29966a8 100644 --- a/src/ogfx/render/BasicRenderer.cpp +++ b/src/ogfx/render/BasicRenderer.cpp @@ -56,7 +56,7 @@ namespace ogfx closeFont(); } - int32_t BasicRenderer2D::init(WindowCore& window) + i32 BasicRenderer2D::init(WindowCore& window) { m_window = &window; if (m_initialized) return set_error_state(tErrors::NoError); @@ -107,10 +107,10 @@ namespace ogfx m_clipStack.push_back(finalRect); SDL_Rect r; - r.x = (int)std::round(finalRect.x); - r.y = (int)std::round(finalRect.y); - r.w = (int)std::round(finalRect.w); - r.h = (int)std::round(finalRect.h); + r.x = (i32)std::round(finalRect.x); + r.y = (i32)std::round(finalRect.y); + r.w = (i32)std::round(finalRect.w); + r.h = (i32)std::round(finalRect.h); SDL_SetRenderClipRect(m_window->getSDLRenderer(), &r); } @@ -132,15 +132,15 @@ namespace ogfx const auto& rect = m_clipStack.back(); SDL_Rect r; - r.x = (int)std::round(rect.x); - r.y = (int)std::round(rect.y); - r.w = (int)std::round(rect.w); - r.h = (int)std::round(rect.h); + r.x = (i32)std::round(rect.x); + r.y = (i32)std::round(rect.y); + r.w = (i32)std::round(rect.w); + r.h = (i32)std::round(rect.h); SDL_SetRenderClipRect(m_window->getSDLRenderer(), &r); } - int32_t BasicRenderer2D::loadDefaultFont(int32_t fontSize) + i32 BasicRenderer2D::loadDefaultFont(i32 fontSize) { return openFont(ubuntu_mono_regular_ttf_data, ubuntu_mono_regular_ttf_size, fontSize); } @@ -157,7 +157,7 @@ namespace ogfx set_error_state(tErrors::NoError); } - int32_t BasicRenderer2D::openFont(const ostd::String& fontPath, int32_t fontSize) + i32 BasicRenderer2D::openFont(const String& fontPath, i32 fontSize) { if (!m_initialized) return set_error_state(tErrors::Uninitialized); if (m_fontOpen) closeFont(); @@ -176,7 +176,7 @@ namespace ogfx return set_error_state(tErrors::NoError); } - int32_t BasicRenderer2D::openFont(const ostd::UByte resource_data[], uint32_t data_size, int32_t fontSize) + i32 BasicRenderer2D::openFont(const ostd::UByte resource_data[], u32 data_size, i32 fontSize) { if (!m_initialized) return set_error_state(tErrors::Uninitialized); if (data_size < 100) // Arbitrary 100 bytes @@ -198,7 +198,7 @@ namespace ogfx return set_error_state(tErrors::NoError); } - int32_t BasicRenderer2D::setFontSize(int32_t fontSize) + i32 BasicRenderer2D::setFontSize(i32 fontSize) { if (!m_initialized) return set_error_state(tErrors::Uninitialized); @@ -212,24 +212,24 @@ namespace ogfx return set_error_state(tErrors::NoError); } - ostd::Vec2 BasicRenderer2D::getStringDimensions(const ostd::String& message, int32_t fontSize, TTF_Font* font) + ostd::Vec2 BasicRenderer2D::getStringDimensions(const String& message, i32 fontSize, TTF_Font* font) { if (!isValid()) return { 0, 0 }; if (fontSize <= 0) fontSize = m_fontSize; if (!font) font = m_font; - int32_t oldFontSize = getFontSize(); + i32 oldFontSize = getFontSize(); setFontSize(fontSize); auto glyphs = m_fontGlyphAtlas.processString(message, font, fontSize); if (glyphs.empty()) return { 0, 0 }; - float totalWidth = 0; + f32 totalWidth = 0; for (size_t i = 0; i < glyphs.size(); i++) { totalWidth += glyphs[i]->advance; if (i > 0) { - int kern = 0; + i32 kern = 0; TTF_GetGlyphKerning(font, glyphs[i - 1]->codepoint, glyphs[i]->codepoint, &kern); totalWidth += kern; } @@ -256,7 +256,7 @@ namespace ogfx ostd::Vec2 texSize = image.getSize(); // 1. Resolve source rectangle - float sx, sy, sw, sh; + f32 sx, sy, sw, sh; if (srcRect.w == 0 && srcRect.h == 0) { // Use entire texture @@ -274,14 +274,14 @@ namespace ogfx } // 2. Resolve destination rectangle - float dx = position.x; - float dy = position.y; - float dw = (size.x == 0) ? sw : size.x; - float dh = (size.y == 0) ? sh : size.y; - float x1 = dx; - float y1 = dy; - float x2 = dx + dw; - float y2 = dy + dh; + f32 dx = position.x; + f32 dy = position.y; + f32 dw = (size.x == 0) ? sw : size.x; + f32 dh = (size.y == 0) ? sh : size.y; + f32 x1 = dx; + f32 y1 = dy; + f32 x2 = dx + dw; + f32 y2 = dy + dh; // 3. Build quad vertices ostd::Vec2 verts[4] = { @@ -300,7 +300,7 @@ namespace ogfx }; // 5. Push quad - uint32_t inds[6] = QUAD_INDICES_ARR; + u32 inds[6] = QUAD_INDICES_ARR; push_polygon(verts, uvs, 4, inds, 6, ostd::Colors::White, tex); } @@ -313,19 +313,19 @@ namespace ogfx drawImage(img, position, size, anim.getFrameRect()); } - void BasicRenderer2D::drawString(const ostd::String& str, const ostd::Vec2& position, const ostd::Color& color, int32_t fontSize, float scale) + void BasicRenderer2D::drawString(const String& str, const ostd::Vec2& position, const ostd::Color& color, i32 fontSize, f32 scale) { if (!isValid()) return; if (fontSize <= 0) fontSize = m_fontSize; - int32_t oldFontSize = m_fontSize; + i32 oldFontSize = m_fontSize; setFontSize(fontSize); auto glyphs = m_fontGlyphAtlas.processString(str, m_font, fontSize); if (glyphs.empty()) return; - float x = position.x; - float y = position.y; + f32 x = position.x; + f32 y = position.y; for (size_t i = 0; i < glyphs.size(); i++) @@ -345,7 +345,7 @@ namespace ogfx { x + g->size.x * scale, y + g->size.y * scale }, { x, y + g->size.y * scale } }; - uint32_t inds[6] = QUAD_INDICES_ARR; + u32 inds[6] = QUAD_INDICES_ARR; push_polygon(verts, g->uvs, 4, inds, 6, color, g->atlas); x += (g->advance * scale); @@ -353,13 +353,13 @@ namespace ogfx setFontSize(oldFontSize); } - void BasicRenderer2D::drawCenteredString(const ostd::String& str, const ostd::Vec2& center, const ostd::Color& color, int32_t fontSize, float scale) + void BasicRenderer2D::drawCenteredString(const String& str, const ostd::Vec2& center, const ostd::Color& color, i32 fontSize, f32 scale) { auto dims = getStringDimensions(str, fontSize); drawString(str, { center.x - (dims.x * scale) * 0.5f, center.y - (dims.y * scale) * 0.5f }, color, fontSize, scale); } - void BasicRenderer2D::drawCenteredString(const ostd::String& str, const ostd::Rectangle& bounds, const ostd::Color& color, int32_t fontSize, float scale) + void BasicRenderer2D::drawCenteredString(const String& str, const ostd::Rectangle& bounds, const ostd::Color& color, i32 fontSize, f32 scale) { drawCenteredString(str, ostd::Vec2 { bounds.x + bounds.w * 0.5f, bounds.y + bounds.h * 0.5f }, color, fontSize, scale); } @@ -370,7 +370,7 @@ namespace ogfx // ===================================================== PRIMITIVES ===================================================== - void BasicRenderer2D::drawLine(const ostd::FLine& line, const ostd::Color& color, int32_t thickness, bool rounded) + void BasicRenderer2D::drawLine(const ostd::FLine& line, const ostd::Color& color, i32 thickness, bool rounded) { if (!m_initialized || thickness <= 0) return; @@ -381,7 +381,7 @@ namespace ogfx Vec2 dir = (p2 - p1).normalize(); Vec2 perp = { -dir.y, dir.x }; // 90° rotation - float half = thickness * 0.5f; + f32 half = thickness * 0.5f; Vec2 off = perp * half; std::array verts = {{ @@ -390,30 +390,30 @@ namespace ogfx p2 + off, p2 - off }}; - std::array inds = QUAD_INDICES_ARR; + std::array inds = QUAD_INDICES_ARR; push_polygon(verts.data(), nullptr, 4, inds.data(), 6, color, nullptr); if (!rounded || thickness < 4) return; - int segments = std::max(6, int(thickness * 0.75f)); + i32 segments = std::max(6, i32(thickness * 0.75f)); generate_half_circle(p1, -dir, half, segments, color); generate_half_circle(p2, dir, half, segments, color); } - void BasicRenderer2D::drawRect(const ostd::Rectangle& rect, const ostd::Color& color, int32_t thickness) + void BasicRenderer2D::drawRect(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness) { if (!m_initialized || thickness <= 0) return; - float half = thickness * 0.5f; + f32 half = thickness * 0.5f; // Inset rectangle so the outline stays inside the original bounds - float x1 = rect.x + half; - float y1 = rect.y + half; - float x2 = rect.x + rect.w - half; - float y2 = rect.y + rect.h - half; + f32 x1 = rect.x + half; + f32 y1 = rect.y + half; + f32 x2 = rect.x + rect.w - half; + f32 y2 = rect.y + rect.h - half; // Top drawLine({ {x1, y1}, {x2, y1} }, color, thickness, false); @@ -428,7 +428,12 @@ namespace ogfx drawLine({ {x1, y2 + half}, {x1, y1 - half} }, color, thickness, false); } - void BasicRenderer2D::drawRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, float radius, int32_t thickness) + void BasicRenderer2D::drawRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, i32 thickness) + { + drawRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, color, thickness); + } + + void BasicRenderer2D::drawRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, f32 radius, i32 thickness) { if (!m_initialized || thickness <= 0) return; @@ -436,13 +441,13 @@ namespace ogfx // Clamp radius so it never exceeds half the smallest dimension radius = std::max(0.0f, std::min(radius, std::min(rect.w, rect.h) * 0.5f)); - float half = thickness * 0.5f; + f32 half = thickness * 0.5f; // Inset rectangle so the border stays INSIDE the given bounds - float x1 = rect.x + half; - float y1 = rect.y + half; - float x2 = rect.x + rect.w - half; - float y2 = rect.y + rect.h - half; + f32 x1 = rect.x + half; + f32 y1 = rect.y + half; + f32 x2 = rect.x + rect.w - half; + f32 y2 = rect.y + rect.h - half; // Corner centers ostd::Vec2 TL { x1 + radius, y1 + radius }; @@ -457,7 +462,7 @@ namespace ogfx drawLine({ {x1, y2 - radius}, {x1, y1 + radius} }, color, thickness, false); // left // Number of segments for smooth arcs - int segments = std::max(6, int(radius * 0.75f)); + i32 segments = std::max(6, i32(radius * 0.75f)); // Quarter‑ellipse strokes (each is 90°) generate_ellipse_stroke(TL, radius, radius, thickness, M_PI, M_PI + M_PI * 0.5f, color, segments); // TL @@ -466,15 +471,20 @@ namespace ogfx generate_ellipse_stroke(BL, radius, radius, thickness, M_PI * 0.5f, M_PI, color, segments); // BL } - void BasicRenderer2D::drawCircle(const ostd::Vec2& center, float radius, const ostd::Color& color, int32_t thickness) + void BasicRenderer2D::drawRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, f32 radius, i32 thickness) + { + drawRoundRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, color, radius, thickness); + } + + void BasicRenderer2D::drawCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& color, i32 thickness) { if (!m_initialized || thickness <= 0) return; - int segments = std::max(12, int(radius * 0.75f)); + i32 segments = std::max(12, i32(radius * 0.75f)); generate_ellipse_stroke(center, radius, radius, thickness, 0.0f, 2.0f * M_PI, color, segments); } - void BasicRenderer2D::drawCircle(const ostd::Rectangle& rect, const ostd::Color& color, int32_t thickness) + void BasicRenderer2D::drawCircle(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness) { if (!m_initialized || thickness <= 0) return; @@ -484,20 +494,20 @@ namespace ogfx rect.y + rect.h * 0.5f }; - float radius = std::min(rect.w, rect.h) * 0.5f; + f32 radius = std::min(rect.w, rect.h) * 0.5f; drawCircle(center, radius, color, thickness); } - void BasicRenderer2D::drawEllipse(const ostd::Rectangle& rect, const ostd::Color& color, int32_t thickness) + void BasicRenderer2D::drawEllipse(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness) { if (!m_initialized || thickness <= 0) return; ostd::Vec2 center = { rect.x + rect.w*0.5f, rect.y + rect.h*0.5f }; - float rx = rect.w * 0.5f; - float ry = rect.h * 0.5f; + f32 rx = rect.w * 0.5f; + f32 ry = rect.h * 0.5f; - int segments = std::max(12, int(std::max(rx, ry) * 0.75f)); + i32 segments = std::max(12, i32(std::max(rx, ry) * 0.75f)); generate_ellipse_stroke(center, rx, ry, thickness, 0.0f, 2.0f * M_PI, color, segments); } @@ -506,10 +516,10 @@ namespace ogfx if (!m_initialized) return; - float x1 = rect.x; - float y1 = rect.y; - float x2 = rect.x + rect.w; - float y2 = rect.y + rect.h; + f32 x1 = rect.x; + f32 y1 = rect.y; + f32 x2 = rect.x + rect.w; + f32 y2 = rect.y + rect.h; ostd::Vec2 verts[4] = { { x1, y1 }, @@ -517,11 +527,16 @@ namespace ogfx { x2, y2 }, { x1, y2 } }; - uint32_t inds[6] = QUAD_INDICES_ARR; + u32 inds[6] = QUAD_INDICES_ARR; push_polygon(verts, nullptr, 4, inds, 6, color, nullptr); } - void BasicRenderer2D::fillRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, float radius) + void BasicRenderer2D::fillRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color) + { + fillRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, color); + } + + void BasicRenderer2D::fillRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, f32 radius) { if (!m_initialized) return; @@ -529,18 +544,18 @@ namespace ogfx // Clamp radius radius = std::max(0.0f, std::min(radius, std::min(rect.w, rect.h) * 0.5f)); - float x1 = rect.x; - float y1 = rect.y; - float x2 = rect.x + rect.w; - float y2 = rect.y + rect.h; + f32 x1 = rect.x; + f32 y1 = rect.y; + f32 x2 = rect.x + rect.w; + f32 y2 = rect.y + rect.h; - float cx1 = x1 + radius; - float cy1 = y1 + radius; - float cx2 = x2 - radius; - float cy2 = y2 - radius; + f32 cx1 = x1 + radius; + f32 cy1 = y1 + radius; + f32 cx2 = x2 - radius; + f32 cy2 = y2 - radius; // Number of segments for smooth corners - int segments = std::max(6, int(radius * 0.75f)); + i32 segments = std::max(6, i32(radius * 0.75f)); // // 1. Fill the center rectangle @@ -552,7 +567,7 @@ namespace ogfx { cx2, cy2 }, { cx1, cy2 } }; - uint32_t inds[6] = { 0,1,2, 2,3,0 }; + u32 inds[6] = { 0,1,2, 2,3,0 }; push_polygon(verts, nullptr, 4, inds, 6, color, nullptr); } @@ -569,7 +584,7 @@ namespace ogfx { x2 - radius, y1 + radius }, { x1 + radius, y1 + radius } }; - uint32_t inds[6] = { 0,1,2, 2,3,0 }; + u32 inds[6] = { 0,1,2, 2,3,0 }; push_polygon(verts, nullptr, 4, inds, 6, color, nullptr); } @@ -581,7 +596,7 @@ namespace ogfx { x2 - radius, y2 }, { x1 + radius, y2 } }; - uint32_t inds[6] = { 0,1,2, 2,3,0 }; + u32 inds[6] = { 0,1,2, 2,3,0 }; push_polygon(verts, nullptr, 4, inds, 6, color, nullptr); } @@ -593,7 +608,7 @@ namespace ogfx { x1 + radius, y2 - radius }, { x1, y2 - radius } }; - uint32_t inds[6] = { 0,1,2, 2,3,0 }; + u32 inds[6] = { 0,1,2, 2,3,0 }; push_polygon(verts, nullptr, 4, inds, 6, color, nullptr); } @@ -605,7 +620,7 @@ namespace ogfx { x2, y2 - radius }, { x2 - radius, y2 - radius } }; - uint32_t inds[6] = { 0,1,2, 2,3,0 }; + u32 inds[6] = { 0,1,2, 2,3,0 }; push_polygon(verts, nullptr, 4, inds, 6, color, nullptr); } @@ -619,12 +634,17 @@ namespace ogfx generate_filled_ellipse_stroke({cx1, cy2}, radius, radius, 0.5f * M_PI, color, segments); // BL } - void BasicRenderer2D::fillCircle(const ostd::Vec2& center, float radius, const ostd::Color& color) + void BasicRenderer2D::fillRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, f32 radius) + { + fillRoundRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, color, radius); + } + + void BasicRenderer2D::fillCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& color) { if (!m_initialized) return; - int segments = std::max(12, int(radius * 0.75f)); + i32 segments = std::max(12, i32(radius * 0.75f)); generate_filled_ellipse(center, radius, radius, color, segments); } @@ -638,7 +658,7 @@ namespace ogfx rect.y + rect.h * 0.5f }; - float radius = std::min(rect.w, rect.h) * 0.5f; + f32 radius = std::min(rect.w, rect.h) * 0.5f; fillCircle(center, radius, color); } @@ -652,14 +672,14 @@ namespace ogfx rect.y + rect.h * 0.5f }; - float radiusX = rect.w * 0.5f; - float radiusY = rect.h * 0.5f; + f32 radiusX = rect.w * 0.5f; + f32 radiusY = rect.h * 0.5f; - int segments = std::max(12, int(std::max(radiusX, radiusY) * 0.75f)); + i32 segments = std::max(12, i32(std::max(radiusX, radiusY) * 0.75f)); generate_filled_ellipse(center, radiusX, radiusY, color, segments); } - void BasicRenderer2D::outlinedRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness) + void BasicRenderer2D::outlinedRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness) { if (!m_initialized) return; ostd::Rectangle offset = { 1, 1, -2, -2 }; @@ -667,7 +687,12 @@ namespace ogfx drawRect(rect, outlineColor, outlineThickness); } - void BasicRenderer2D::outlinedRoundRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, float radius, int32_t outlineThickness) + void BasicRenderer2D::outlinedRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness) + { + outlinedRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, fillColor, outlineColor, outlineThickness); + } + + void BasicRenderer2D::outlinedRoundRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, f32 radius, i32 outlineThickness) { if (!m_initialized) return; ostd::Rectangle offset = { 1, 1, -2, -2 }; @@ -675,14 +700,19 @@ namespace ogfx drawRoundRect(rect, outlineColor, radius, outlineThickness); } - void BasicRenderer2D::outlinedCircle(const ostd::Vec2& center, float radius, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness) + void BasicRenderer2D::outlinedRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& fillColor, const ostd::Color& outlineColor, f32 radius, i32 outlineThickness) + { + outlinedRoundRect({ center.x - size.x * 0.5f, center.y - size.y * 0.5f, size.x, size.y }, fillColor, outlineColor, radius, outlineThickness); + } + + void BasicRenderer2D::outlinedCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness) { if (!m_initialized) return; fillCircle(center, radius - 1, fillColor); drawCircle(center, radius, outlineColor, outlineThickness); } - void BasicRenderer2D::outlinedCircle(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness) + void BasicRenderer2D::outlinedCircle(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness) { if (!m_initialized) return; @@ -692,11 +722,11 @@ namespace ogfx rect.y + rect.h * 0.5f }; - float radius = std::min(rect.w, rect.h) * 0.5f; + f32 radius = std::min(rect.w, rect.h) * 0.5f; outlinedCircle(center, radius, fillColor, outlineColor, outlineThickness); } - void BasicRenderer2D::outlinedEllipse(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness) + void BasicRenderer2D::outlinedEllipse(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness) { if (!m_initialized) return; ostd::Rectangle offset = { 1, 1, -2, -2 }; @@ -722,7 +752,7 @@ namespace ogfx i = 0; } - void BasicRenderer2D::generate_half_circle(const ostd::Vec2& center, const ostd::Vec2& dir, float radius, int segments, const ostd::Color& color) + void BasicRenderer2D::generate_half_circle(const ostd::Vec2& center, const ostd::Vec2& dir, f32 radius, i32 segments, const ostd::Color& color) { // Ensure we have room if (m_vertexCount + segments + 2 >= MaxVertices || m_indexCount + segments * 3 >= MaxIndices) @@ -731,7 +761,7 @@ namespace ogfx SDL_FColor col = COLOR_CAST(color); // Index of the center vertex - int centerIndex = m_vertexCount; + i32 centerIndex = m_vertexCount; // Push center vertex m_vertices[m_vertexCount++] = { @@ -741,20 +771,20 @@ namespace ogfx }; // Compute the base angle from the direction vector - float baseAngle = std::atan2(dir.y, dir.x); + f32 baseAngle = std::atan2(dir.y, dir.x); // Half circle spans 180 degrees - float startAngle = baseAngle - M_PI * 0.5f; - float endAngle = baseAngle + M_PI * 0.5f; + f32 startAngle = baseAngle - M_PI * 0.5f; + f32 endAngle = baseAngle + M_PI * 0.5f; // Generate arc vertices - for (int i = 0; i <= segments; i++) + for (i32 i = 0; i <= segments; i++) { - float t = float(i) / float(segments); - float angle = startAngle + t * (endAngle - startAngle); + f32 t = f32(i) / f32(segments); + f32 angle = startAngle + t * (endAngle - startAngle); - float x = center.x + std::cos(angle) * radius; - float y = center.y + std::sin(angle) * radius; + f32 x = center.x + std::cos(angle) * radius; + f32 y = center.y + std::sin(angle) * radius; m_vertices[m_vertexCount++] = { { x, y }, @@ -764,7 +794,7 @@ namespace ogfx } // Generate triangle fan indices - for (int i = 0; i < segments; i++) + for (i32 i = 0; i < segments; i++) { m_indices[m_indexCount++] = centerIndex; m_indices[m_indexCount++] = centerIndex + 1 + i; @@ -772,12 +802,12 @@ namespace ogfx } } - void BasicRenderer2D::generate_quarter_circle(const ostd::Vec2& center, float radius, float thickness, float startAngle, const ostd::Color& color, int segments) + void BasicRenderer2D::generate_quarter_circle(const ostd::Vec2& center, f32 radius, f32 thickness, f32 startAngle, const ostd::Color& color, i32 segments) { - float half = thickness * 0.5f; + f32 half = thickness * 0.5f; - float outerR = radius + half; - float innerR = radius - half; + f32 outerR = radius + half; + f32 innerR = radius - half; if (innerR < 0.0f) innerR = 0.0f; @@ -788,18 +818,18 @@ namespace ogfx SDL_FColor col = COLOR_CAST(color); - int base = m_vertexCount; + i32 base = m_vertexCount; - float endAngle = startAngle + M_PI * 0.5f; + f32 endAngle = startAngle + M_PI * 0.5f; // Generate vertices: outer arc + inner arc - for (int i = 0; i <= segments; i++) + for (i32 i = 0; i <= segments; i++) { - float t = float(i) / float(segments); - float angle = startAngle + t * (endAngle - startAngle); + f32 t = f32(i) / f32(segments); + f32 angle = startAngle + t * (endAngle - startAngle); - float cs = std::cos(angle); - float sn = std::sin(angle); + f32 cs = std::cos(angle); + f32 sn = std::sin(angle); // Outer arc m_vertices[m_vertexCount++] = { @@ -817,12 +847,12 @@ namespace ogfx } // Generate indices (triangle strip converted to triangles) - for (int i = 0; i < segments; i++) + for (i32 i = 0; i < segments; i++) { - int o0 = base + i * 2; - int i0 = o0 + 1; - int o1 = o0 + 2; - int i1 = o0 + 3; + i32 o0 = base + i * 2; + i32 i0 = o0 + 1; + i32 o1 = o0 + 2; + i32 i1 = o0 + 3; // Triangle 1 m_indices[m_indexCount++] = o0; @@ -836,12 +866,12 @@ namespace ogfx } } - void BasicRenderer2D::generate_circle_stroke(const ostd::Vec2& center, float radius, float thickness, const ostd::Color& color, int segments) + void BasicRenderer2D::generate_circle_stroke(const ostd::Vec2& center, f32 radius, f32 thickness, const ostd::Color& color, i32 segments) { - float half = thickness * 0.5f; + f32 half = thickness * 0.5f; - float outerR = radius + half; - float innerR = radius - half; + f32 outerR = radius + half; + f32 innerR = radius - half; if (innerR < 0.0f) innerR = 0.0f; @@ -851,16 +881,16 @@ namespace ogfx SDL_FColor col = COLOR_CAST(color); - int base = m_vertexCount; + i32 base = m_vertexCount; // Generate vertices: outer arc + inner arc - for (int i = 0; i <= segments; i++) + for (i32 i = 0; i <= segments; i++) { - float t = float(i) / float(segments); - float angle = t * (2.0f * M_PI); + f32 t = f32(i) / f32(segments); + f32 angle = t * (2.0f * M_PI); - float cs = std::cos(angle); - float sn = std::sin(angle); + f32 cs = std::cos(angle); + f32 sn = std::sin(angle); // Outer arc m_vertices[m_vertexCount++] = { @@ -878,12 +908,12 @@ namespace ogfx } // Generate indices (triangle strip → triangles) - for (int i = 0; i < segments; i++) + for (i32 i = 0; i < segments; i++) { - int o0 = base + i * 2; - int i0 = o0 + 1; - int o1 = o0 + 2; - int i1 = o0 + 3; + i32 o0 = base + i * 2; + i32 i0 = o0 + 1; + i32 o1 = o0 + 2; + i32 i1 = o0 + 3; // Triangle 1 m_indices[m_indexCount++] = o0; @@ -897,14 +927,14 @@ namespace ogfx } } - void BasicRenderer2D::generate_ellipse_stroke(const ostd::Vec2& center, float radiusX, float radiusY, float thickness, float startAngle, float endAngle, const ostd::Color& color, int segments) + void BasicRenderer2D::generate_ellipse_stroke(const ostd::Vec2& center, f32 radiusX, f32 radiusY, f32 thickness, f32 startAngle, f32 endAngle, const ostd::Color& color, i32 segments) { - float half = thickness * 0.5f; + f32 half = thickness * 0.5f; - float outerRX = radiusX + half; - float outerRY = radiusY + half; - float innerRX = std::max(0.0f, radiusX - half); - float innerRY = std::max(0.0f, radiusY - half); + f32 outerRX = radiusX + half; + f32 outerRY = radiusY + half; + f32 innerRX = std::max(0.0f, radiusX - half); + f32 innerRY = std::max(0.0f, radiusY - half); // Ensure capacity if (m_vertexCount + (segments + 1) * 2 >= MaxVertices || @@ -915,18 +945,18 @@ namespace ogfx SDL_FColor col = COLOR_CAST(color); - int base = m_vertexCount; + i32 base = m_vertexCount; - float angleRange = endAngle - startAngle; + f32 angleRange = endAngle - startAngle; // Generate vertices: outer arc + inner arc - for (int i = 0; i <= segments; i++) + for (i32 i = 0; i <= segments; i++) { - float t = float(i) / float(segments); - float angle = startAngle + t * angleRange; + f32 t = f32(i) / f32(segments); + f32 angle = startAngle + t * angleRange; - float cs = std::cos(angle); - float sn = std::sin(angle); + f32 cs = std::cos(angle); + f32 sn = std::sin(angle); // Outer arc m_vertices[m_vertexCount++] = { @@ -944,12 +974,12 @@ namespace ogfx } // Generate indices (triangle strip → triangles) - for (int i = 0; i < segments; i++) + for (i32 i = 0; i < segments; i++) { - int o0 = base + i * 2; - int i0 = o0 + 1; - int o1 = o0 + 2; - int i1 = o0 + 3; + i32 o0 = base + i * 2; + i32 i0 = o0 + 1; + i32 o1 = o0 + 2; + i32 i1 = o0 + 3; // Triangle 1 m_indices[m_indexCount++] = o0; @@ -963,7 +993,7 @@ namespace ogfx } } - void BasicRenderer2D::generate_filled_ellipse_stroke(const ostd::Vec2& center, float radiusX, float radiusY, float startAngle, const ostd::Color& color, int segments) + void BasicRenderer2D::generate_filled_ellipse_stroke(const ostd::Vec2& center, f32 radiusX, f32 radiusY, f32 startAngle, const ostd::Color& color, i32 segments) { // Ensure capacity if (m_vertexCount + segments + 2 >= MaxVertices || m_indexCount + segments * 3 >= MaxIndices) @@ -971,7 +1001,7 @@ namespace ogfx SDL_FColor col = COLOR_CAST(color); - int base = m_vertexCount; + i32 base = m_vertexCount; // Center vertex m_vertices[m_vertexCount++] = { @@ -980,15 +1010,15 @@ namespace ogfx { 0, 0 } }; - float endAngle = startAngle + M_PI * 0.5f; + f32 endAngle = startAngle + M_PI * 0.5f; - for (int i = 0; i <= segments; i++) + for (i32 i = 0; i <= segments; i++) { - float t = float(i) / float(segments); - float angle = startAngle + t * (endAngle - startAngle); + f32 t = f32(i) / f32(segments); + f32 angle = startAngle + t * (endAngle - startAngle); - float x = center.x + std::cos(angle) * radiusX; - float y = center.y + std::sin(angle) * radiusY; + f32 x = center.x + std::cos(angle) * radiusX; + f32 y = center.y + std::sin(angle) * radiusY; m_vertices[m_vertexCount++] = { { x, y }, @@ -998,7 +1028,7 @@ namespace ogfx } // Triangle fan indices - for (int i = 0; i < segments; i++) + for (i32 i = 0; i < segments; i++) { m_indices[m_indexCount++] = base; m_indices[m_indexCount++] = base + 1 + i; @@ -1006,7 +1036,7 @@ namespace ogfx } } - void BasicRenderer2D::generate_filled_ellipse(const ostd::Vec2& center, float radiusX, float radiusY, const ostd::Color& color, int segments) + void BasicRenderer2D::generate_filled_ellipse(const ostd::Vec2& center, f32 radiusX, f32 radiusY, const ostd::Color& color, i32 segments) { // Ensure capacity if (m_vertexCount + segments + 2 >= MaxVertices || m_indexCount + segments * 3 >= MaxIndices) @@ -1014,7 +1044,7 @@ namespace ogfx SDL_FColor col = COLOR_CAST(color); - int base = m_vertexCount; + i32 base = m_vertexCount; // Center vertex m_vertices[m_vertexCount++] = { @@ -1024,13 +1054,13 @@ namespace ogfx }; // Outer ring vertices - for (int i = 0; i <= segments; i++) + for (i32 i = 0; i <= segments; i++) { - float t = float(i) / float(segments); - float angle = t * (2.0f * M_PI); + f32 t = f32(i) / f32(segments); + f32 angle = t * (2.0f * M_PI); - float x = center.x + std::cos(angle) * radiusX; - float y = center.y + std::sin(angle) * radiusY; + f32 x = center.x + std::cos(angle) * radiusX; + f32 y = center.y + std::sin(angle) * radiusY; m_vertices[m_vertexCount++] = { { x, y }, @@ -1040,7 +1070,7 @@ namespace ogfx } // Triangle fan indices - for (int i = 0; i < segments; i++) + for (i32 i = 0; i < segments; i++) { m_indices[m_indexCount++] = base; m_indices[m_indexCount++] = base + 1 + i; @@ -1048,7 +1078,7 @@ namespace ogfx } } - void BasicRenderer2D::push_polygon(const ostd::Vec2* verts, const ostd::Vec2* texCoords, uint32_t vertCount, const uint32_t* inds, uint32_t indexCount, const ostd::Color& color, SDL_Texture* texture) + void BasicRenderer2D::push_polygon(const ostd::Vec2* verts, const ostd::Vec2* texCoords, u32 vertCount, const u32* inds, u32 indexCount, const ostd::Color& color, SDL_Texture* texture) { if (!m_initialized || vertCount <= 0 || indexCount <= 0) return; @@ -1066,9 +1096,9 @@ namespace ogfx SDL_FColor col = COLOR_CAST(color); - int base = m_vertexCount; + i32 base = m_vertexCount; bool hasTexCoords = texCoords != nullptr; - for (int i = 0; i < vertCount; i++) + for (i32 i = 0; i < vertCount; i++) { ostd::Vec2 tc { 0.0f, 0.0f }; if (hasTexCoords) @@ -1079,13 +1109,13 @@ namespace ogfx { tc.x, tc.y }, }; } - for (int i = 0; i < indexCount; i++) + for (i32 i = 0; i < indexCount; i++) m_indices[m_indexCount++] = base + inds[i]; } - void BasicRenderer2D::print_ttf_error(const ostd::String& funcName) + void BasicRenderer2D::print_ttf_error(const String& funcName) { - m_out.fg(ostd::ConsoleColors::Red).p(funcName).p("(...) failed: ").p(ostd::String(SDL_GetError())).reset().nl(); + m_out.fg(ostd::ConsoleColors::Red).p(funcName).p("(...) failed: ").p(String(SDL_GetError())).reset().nl(); } // ===================================================== PRIVATE HELPERS ===================================================== } diff --git a/src/ogfx/render/BasicRenderer.hpp b/src/ogfx/render/BasicRenderer.hpp index dfd5b0a..9ce521d 100644 --- a/src/ogfx/render/BasicRenderer.hpp +++ b/src/ogfx/render/BasicRenderer.hpp @@ -34,16 +34,16 @@ namespace ogfx { public: struct tErrors { - inline static constexpr int32_t NoError = 0; - inline static constexpr int32_t FailedToLoad = 1; - inline static constexpr int32_t FailedToOpenFontFile = 2; - inline static constexpr int32_t Uninitialized = 3; - inline static constexpr int32_t InvalidState = 5; - inline static constexpr int32_t TTFRenderTextBlendedFail = 6; - inline static constexpr int32_t TTFCreateTextureFromSurfaceFail = 7; - inline static constexpr int32_t NullFont = 8; - inline static constexpr int32_t NoFont = 9; - inline static constexpr int32_t FailedToOpenFontByteStrean = 10; + inline static constexpr i32 NoError = 0; + inline static constexpr i32 FailedToLoad = 1; + inline static constexpr i32 FailedToOpenFontFile = 2; + inline static constexpr i32 Uninitialized = 3; + inline static constexpr i32 InvalidState = 5; + inline static constexpr i32 TTFRenderTextBlendedFail = 6; + inline static constexpr i32 TTFCreateTextureFromSurfaceFail = 7; + inline static constexpr i32 NullFont = 8; + inline static constexpr i32 NoFont = 9; + inline static constexpr i32 FailedToOpenFontByteStrean = 10; }; private: class SignalHandler : public ostd::BaseObject { @@ -57,25 +57,25 @@ namespace ogfx public: inline BasicRenderer2D(void) { } ~BasicRenderer2D(void); - int32_t init(WindowCore& window); + i32 init(WindowCore& window); SDL_Renderer* getSDLRenderer(void) const; void flushBatch(void); void endFrame(void); void pushClippingRect(const ostd::Rectangle& rect, bool additive = false); void popClippingRect(void); - int32_t loadDefaultFont(int32_t fontSize = 0); + i32 loadDefaultFont(i32 fontSize = 0); void closeFont(void); - int32_t openFont(const ostd::String& fontPath, int32_t fontSize = 0); - int32_t openFont(const ostd::UByte resource_data[], uint32_t data_size, int32_t fontSize = 0); - int32_t setFontSize(int32_t fontSize); - ostd::Vec2 getStringDimensions(const ostd::String& message, int32_t fontSize = 0, TTF_Font* font = nullptr); + i32 openFont(const String& fontPath, i32 fontSize = 0); + i32 openFont(const ostd::UByte resource_data[], u32 data_size, i32 fontSize = 0); + i32 setFontSize(i32 fontSize); + ostd::Vec2 getStringDimensions(const String& message, i32 fontSize = 0, TTF_Font* font = nullptr); - inline uint32_t getDrawCallCount(void) { return m_drawCallCount; } + inline u32 getDrawCallCount(void) { return m_drawCallCount; } inline bool hasOpenFont(void) { return m_fontOpen; } inline TTF_Font* getSDLFont(void) { return m_font; } inline bool isValid(void) const { return m_initialized && m_fontOpen && (m_font != nullptr || m_fontFromMemory); } - inline int32_t geterrorState(void) { return m_errorState; } - inline int32_t getFontSize(void) { return m_fontSize; } + inline i32 geterrorState(void) { return m_errorState; } + inline i32 getFontSize(void) { return m_fontSize; } inline WindowCore& getWindow(void) { return *m_window; } inline bool isInitialized(void) { return m_initialized; } inline FontGlyphAtlas& getFontGlyphAtlas(void) { return m_fontGlyphAtlas; } @@ -83,67 +83,73 @@ namespace ogfx void drawImage(const ogfx::Image& image, const ostd::Vec2& position, const ostd::Vec2& size = { 0, 0 }, const ostd::Rectangle& srcRect = { 0, 0, 0, 0 }); void drawAnimation(const Animation& anim, const ostd::Vec2& position, const ostd::Vec2& size = { 0, 0 }); - void drawString(const ostd::String& str, const ostd::Vec2& position, const ostd::Color& color, int32_t fontSize = 0, float scale = 1.0f); - void drawCenteredString(const ostd::String& str, const ostd::Vec2& center, const ostd::Color& color, int32_t fontSize = 0, float scale = 1.0f); - void drawCenteredString(const ostd::String& str, const ostd::Rectangle& bounds, const ostd::Color& color, int32_t fontSize = 0, float scale = 1.0f); + void drawString(const String& str, const ostd::Vec2& position, const ostd::Color& color, i32 fontSize = 0, f32 scale = 1.0f); + void drawCenteredString(const String& str, const ostd::Vec2& center, const ostd::Color& color, i32 fontSize = 0, f32 scale = 1.0f); + void drawCenteredString(const String& str, const ostd::Rectangle& bounds, const ostd::Color& color, i32 fontSize = 0, f32 scale = 1.0f); + void drawLine(const ostd::FLine& line, const ostd::Color& color, i32 thickness = 1, bool rounded = true); - void drawLine(const ostd::FLine& line, const ostd::Color& color, int32_t thickness = 1, bool rounded = true); - - void drawRect(const ostd::Rectangle& rect, const ostd::Color& color, int32_t thickness = 1); - void drawRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, float radius, int32_t thickness = 1); - void drawCircle(const ostd::Vec2& center, float radius, const ostd::Color& color, int32_t thickness = 1); - void drawCircle(const ostd::Rectangle& rect, const ostd::Color& color, int32_t thickness = 1); - void drawEllipse(const ostd::Rectangle& rect, const ostd::Color& color, int32_t thickness = 1); + void drawRect(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness = 1); + void drawRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, i32 thickness = 1); + void drawRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, f32 radius, i32 thickness = 1); + void drawRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, f32 radius, i32 thickness = 1); + void drawCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& color, i32 thickness = 1); + void drawCircle(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness = 1); + void drawEllipse(const ostd::Rectangle& rect, const ostd::Color& color, i32 thickness = 1); void fillRect(const ostd::Rectangle& rect, const ostd::Color& color); - void fillRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, float radius); - void fillCircle(const ostd::Vec2& center, float radius, const ostd::Color& color); + void fillRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color); + void fillRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, f32 radius); + void fillRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& color, f32 radius); + void fillCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& color); void fillCircle(const ostd::Rectangle& rect, const ostd::Color& color); void fillEllipse(const ostd::Rectangle& rect, const ostd::Color& color); - void outlinedRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness = 1); - void outlinedRoundRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, float radius, int32_t outlineThickness = 1); - void outlinedCircle(const ostd::Vec2& center, float radius, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness = 1); - void outlinedCircle(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness = 1); - void outlinedEllipse(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness = 1); + void outlinedRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness = 1); + void outlinedRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness = 1); + void outlinedRoundRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, f32 radius, i32 outlineThickness = 1); + void outlinedRoundRect(const ostd::Vec2& center, const ostd::Vec2& size, const ostd::Color& fillColor, const ostd::Color& outlineColor, f32 radius, i32 outlineThickness = 1); + void outlinedCircle(const ostd::Vec2& center, f32 radius, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness = 1); + void outlinedCircle(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness = 1); + void outlinedEllipse(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, i32 outlineThickness = 1); private: void init_arrays(void); - void generate_half_circle(const ostd::Vec2& center, const ostd::Vec2& dir, float radius, int segments, const ostd::Color& color); - void generate_quarter_circle(const ostd::Vec2& center, float radius, float thickness, float startAngle, const ostd::Color& color, int segments); - void generate_circle_stroke(const ostd::Vec2& center, float radius, float thickness, const ostd::Color& color, int segments); - void generate_ellipse_stroke(const ostd::Vec2& center, float radiusX, float radiusY, float thickness, float startAngle, float endAngle, const ostd::Color& color, int segments); - void generate_filled_ellipse_stroke(const ostd::Vec2& center, float radiusX, float radiusY, float startAngle, const ostd::Color& color, int segments); - void generate_filled_ellipse(const ostd::Vec2& center, float radiusX, float radiusY, const ostd::Color& color, int segments); - void push_polygon(const ostd::Vec2* verts, const ostd::Vec2* texCoords, uint32_t vertCount, const uint32_t* inds, uint32_t indexCount, const ostd::Color& color, SDL_Texture* texture); - void print_ttf_error(const ostd::String& funcName); - inline int32_t set_error_state(int32_t err) { m_errorState = err; return m_errorState; } + void generate_half_circle(const ostd::Vec2& center, const ostd::Vec2& dir, f32 radius, i32 segments, const ostd::Color& color); + void generate_quarter_circle(const ostd::Vec2& center, f32 radius, f32 thickness, f32 startAngle, const ostd::Color& color, i32 segments); + void generate_circle_stroke(const ostd::Vec2& center, f32 radius, f32 thickness, const ostd::Color& color, i32 segments); + void generate_ellipse_stroke(const ostd::Vec2& center, f32 radiusX, f32 radiusY, f32 thickness, f32 startAngle, f32 endAngle, const ostd::Color& color, i32 segments); + void generate_filled_ellipse_stroke(const ostd::Vec2& center, f32 radiusX, f32 radiusY, f32 startAngle, const ostd::Color& color, i32 segments); + void generate_filled_ellipse(const ostd::Vec2& center, f32 radiusX, f32 radiusY, const ostd::Color& color, i32 segments); + void push_polygon(const ostd::Vec2* verts, const ostd::Vec2* texCoords, u32 vertCount, const u32* inds, u32 indexCount, const ostd::Color& color, SDL_Texture* texture); + void print_ttf_error(const String& funcName); + inline i32 set_error_state(i32 err) { m_errorState = err; return m_errorState; } public: - inline static constexpr int32_t MaxVertices { 8192 }; - inline static constexpr int32_t MaxIndices { (int32_t)(MaxVertices * 1.5f) }; + inline static constexpr i32 MaxVertices { 8192 }; + inline static constexpr i32 MaxIndices { (i32)(MaxVertices * 1.5f) }; private: WindowCore* m_window { nullptr }; ostd::ConsoleOutputHandler m_out; bool m_initialized { false }; - std::vector m_clipStack; + stdvec m_clipStack; std::array m_vertices; - std::array m_indices; - int32_t m_vertexCount { 0 }; - int32_t m_indexCount { 0 }; + std::array m_indices; + i32 m_vertexCount { 0 }; + i32 m_indexCount { 0 }; SDL_Texture* m_texture { nullptr }; - uint32_t m_drawCallCount { 0 }; + u32 m_drawCallCount { 0 }; bool m_fontOpen { false }; TTF_Font* m_font { nullptr }; - int32_t m_errorState { tErrors::NoError }; - int32_t m_fontSize { DefaultFontSize }; + i32 m_errorState { tErrors::NoError }; + i32 m_fontSize { DefaultFontSize }; bool m_fontFromMemory { false }; FontGlyphAtlas m_fontGlyphAtlas; + SignalHandler m_sigHandler { *this }; - inline static constexpr int32_t DefaultFontSize { 16 }; + inline static constexpr i32 DefaultFontSize { 16 }; }; } diff --git a/src/ogfx/render/FontGlyphAtlas.cpp b/src/ogfx/render/FontGlyphAtlas.cpp index 529486d..6f9b0ee 100644 --- a/src/ogfx/render/FontGlyphAtlas.cpp +++ b/src/ogfx/render/FontGlyphAtlas.cpp @@ -31,14 +31,14 @@ namespace ogfx { m_renderer = &renderer; m_uvs.reserve(4096); - for (int32_t i = 0; i < FontGlyphAtlas::MaxAtlasCount; i++) + for (i32 i = 0; i < FontGlyphAtlas::MaxAtlasCount; i++) m_atlases[i] = nullptr; m_currentAtlasCount = 0; create_new_atlas(); return *this; } - const std::vector FontGlyphAtlas::processString(const ostd::String& str, TTF_Font* font, uint32_t fontSize) + const stdvec FontGlyphAtlas::processString(const String& str, TTF_Font* font, u32 fontSize) { if (m_currentAtlasCount <= 0) return {}; @@ -47,24 +47,24 @@ namespace ogfx for (auto& c : str) { const GlyphInfo* dummy; - if (!rasterize_glyph(ostd::String("").addChar(c), font, fontSize, &dummy)) + if (!rasterize_glyph(String("").addChar(c), font, fontSize, &dummy)) return {}; } // Pass 2: collect stable pointers (no more insertions, no rehash risk) - std::vector glyphs; + stdvec glyphs; glyphs.reserve(str.len()); for (auto& c : str) { - auto cps = ostd::String("").addChar(c).getUTF8Codepoints(); + auto cps = String("").addChar(c).getUTF8Codepoints(); if (cps.size() != 1) return {}; - GlyphKey key { cps[0], uint64_t(font), fontSize }; + GlyphKey key { cps[0], u64(font), fontSize }; glyphs.push_back(&m_uvs[key]); } return glyphs; } - bool FontGlyphAtlas::rasterize_glyph(const ostd::String& glyphStr, TTF_Font* font, uint32_t fontSize, const GlyphInfo** outGlyph) + bool FontGlyphAtlas::rasterize_glyph(const String& glyphStr, TTF_Font* font, u32 fontSize, const GlyphInfo** outGlyph) { if (!font || m_currentAtlasCount <= 0) return false; @@ -73,9 +73,9 @@ namespace ogfx if (cps.size() != 1) return false; - uint32_t codepoint = cps[0]; + u32 codepoint = cps[0]; - GlyphKey key { codepoint, uint64_t(font), fontSize }; + GlyphKey key { codepoint, u64(font), fontSize }; auto it = m_uvs.find(key); if (it != m_uvs.end()) { @@ -87,10 +87,10 @@ namespace ogfx if (!surf) return false; - int gw = surf->w; - int gh = surf->h; + i32 gw = surf->w; + i32 gh = surf->h; - int minx, maxx, miny, maxy, advance; + i32 minx, maxx, miny, maxy, advance; TTF_GetGlyphMetrics(font, codepoint, &minx, &maxx, &miny, &maxy, &advance); GlyphInfo glyph; @@ -99,14 +99,14 @@ namespace ogfx SDL_Texture* atlas = m_atlases[m_currentAtlasCount - 1]; - if (m_penX + gw > int(AtlasTextureDimension)) + if (m_penX + gw > i32(AtlasTextureDimension)) { m_penX = 0; m_penY += m_rowHeight; m_rowHeight = 0; } - if (m_penY + gh > int(AtlasTextureDimension)) + if (m_penY + gh > i32(AtlasTextureDimension)) { SDL_DestroySurface(surf); @@ -126,17 +126,17 @@ namespace ogfx SDL_DestroySurface(surf); - float u0 = float(m_penX) / float(AtlasTextureDimension); - float v0 = float(m_penY) / float(AtlasTextureDimension); - float u1 = float(m_penX + gw) / float(AtlasTextureDimension); - float v1 = float(m_penY + gh) / float(AtlasTextureDimension); + f32 u0 = f32(m_penX) / f32(AtlasTextureDimension); + f32 v0 = f32(m_penY) / f32(AtlasTextureDimension); + f32 u1 = f32(m_penX + gw) / f32(AtlasTextureDimension); + f32 v1 = f32(m_penY + gh) / f32(AtlasTextureDimension); glyph.atlas = atlas; glyph.uvs[0] = { u0, v0 }; glyph.uvs[1] = { u1, v0 }; glyph.uvs[2] = { u1, v1 }; glyph.uvs[3] = { u0, v1 }; - glyph.size = { static_cast(gw), static_cast(gh) }; + glyph.size = { cast(gw), cast(gh) }; m_uvs[key] = glyph; *outGlyph = &(m_uvs[key]); @@ -148,7 +148,7 @@ namespace ogfx bool FontGlyphAtlas::create_new_atlas(void) { - if (m_currentAtlasCount >= int(MaxAtlasCount)) + if (m_currentAtlasCount >= i32(MaxAtlasCount)) return false; if (!m_renderer) @@ -168,7 +168,7 @@ namespace ogfx { // Clear the texture to transparent void* pixels = nullptr; - int pitch = 0; + i32 pitch = 0; if (SDL_LockTexture(tex, nullptr, &pixels, &pitch) == 0) { memset(pixels, 0x00, pitch * AtlasTextureDimension); diff --git a/src/ogfx/render/FontGlyphAtlas.hpp b/src/ogfx/render/FontGlyphAtlas.hpp index a090e8d..a113dc1 100644 --- a/src/ogfx/render/FontGlyphAtlas.hpp +++ b/src/ogfx/render/FontGlyphAtlas.hpp @@ -34,14 +34,14 @@ namespace ogfx ostd::Vec2 uvs[4]; SDL_Texture* atlas { nullptr }; ostd::Vec2 size; - uint32_t codepoint { 0 }; - int32_t advance { 0 }; + u32 codepoint { 0 }; + i32 advance { 0 }; }; struct GlyphKey { - uint32_t codepoint; - uint64_t fontID; - uint32_t pixelSize; + u32 codepoint; + u64 fontID; + u32 pixelSize; bool operator==(const GlyphKey& other) const noexcept { @@ -54,9 +54,9 @@ namespace ogfx { size_t operator()(const GlyphKey& k) const noexcept { - size_t h = std::hash()(k.codepoint); - h ^= std::hash()(k.fontID) + 0x9e3779b9 + (h << 6) + (h >> 2); - h ^= std::hash()(k.pixelSize) + 0x9e3779b9 + (h << 6) + (h >> 2); + size_t h = std::hash()(k.codepoint); + h ^= std::hash()(k.fontID) + 0x9e3779b9 + (h << 6) + (h >> 2); + h ^= std::hash()(k.pixelSize) + 0x9e3779b9 + (h << 6) + (h >> 2); return h; } }; @@ -64,23 +64,23 @@ namespace ogfx inline FontGlyphAtlas(void) { } inline FontGlyphAtlas(BasicRenderer2D& renderer) { init(renderer); } FontGlyphAtlas init(BasicRenderer2D& renderer); - const std::vector processString(const ostd::String& str, TTF_Font* font, uint32_t fontSize); + const stdvec processString(const String& str, TTF_Font* font, u32 fontSize); private: - bool rasterize_glyph(const ostd::String& glyphStr, TTF_Font* font, uint32_t fontSize, const GlyphInfo** outGlyph); + bool rasterize_glyph(const String& glyphStr, TTF_Font* font, u32 fontSize, const GlyphInfo** outGlyph); bool create_new_atlas(void); public: - inline static constexpr uint32_t AtlasTextureDimension { 8192 }; - inline static constexpr uint32_t MaxAtlasCount { 16 }; + inline static constexpr u32 AtlasTextureDimension { 8192 }; + inline static constexpr u32 MaxAtlasCount { 16 }; public: std::unordered_map m_uvs; SDL_Texture* m_atlases[FontGlyphAtlas::MaxAtlasCount]; - int32_t m_currentAtlasCount { 0 }; + i32 m_currentAtlasCount { 0 }; BasicRenderer2D* m_renderer { nullptr }; - int32_t m_penX { 0 }; - int32_t m_penY { 0 }; - int32_t m_rowHeight { 0 }; + i32 m_penX { 0 }; + i32 m_penY { 0 }; + i32 m_rowHeight { 0 }; }; } diff --git a/src/ogfx/render/PixelRenderer.cpp b/src/ogfx/render/PixelRenderer.cpp index 43d518c..2f63700 100644 --- a/src/ogfx/render/PixelRenderer.cpp +++ b/src/ogfx/render/PixelRenderer.cpp @@ -31,18 +31,18 @@ namespace ogfx characterMap[c] = getCharacterIndex(c); } - bool PixelRenderer::TextRenderer::drawString(ostd::String str, uint32_t column, uint32_t row, uint32_t* screenPixels, int32_t screenWidth, int32_t screenHeight, uint32_t* fontPixels, ostd::Color color, ostd::Color background) + bool PixelRenderer::TextRenderer::drawString(const String& str, u32 column, u32 row, u32* screenPixels, i32 screenWidth, i32 screenHeight, u32* fontPixels, const ostd::Color& color, const ostd::Color& background) { - ostd::String se(str); + String se(str); if (se == "") return false; if (row >= CONSOLE_CHARS_V) return false; if (column >= CONSOLE_CHARS_H) return false; if (column + str.len() > CONSOLE_CHARS_H) return false; - int32_t x = column * FONT_CHAR_W; - int32_t y = row * FONT_CHAR_H; + i32 x = column * FONT_CHAR_W; + i32 y = row * FONT_CHAR_H; for (auto& c : str) { - drawCharacter((uint8_t*)screenPixels, screenWidth, screenHeight, (uint8_t*)fontPixels, x, y, c, color, background); + drawCharacter((u8*)screenPixels, screenWidth, screenHeight, (u8*)fontPixels, x, y, c, color, background); x += FONT_CHAR_W; } s_cursor_pos_x = x; @@ -51,11 +51,11 @@ namespace ogfx return true; } - int32_t PixelRenderer::TextRenderer::getCharacterIndex(char c) + i32 PixelRenderer::TextRenderer::getCharacterIndex(char c) { using namespace ostd; - int32_t charIndex = (int)c - 32; + i32 charIndex = (i32)c - 32; IPoint charCoords = CONVERT_1D_2D(charIndex, FONT_H_CHARS); charCoords.x *= FONT_CHAR_W * 4; charCoords.y *= FONT_CHAR_H; @@ -64,37 +64,37 @@ namespace ogfx return charIndex; } - ostd::Color PixelRenderer::TextRenderer::applyTint(ostd::Color baseColor, ostd::Color tintColor) + ostd::Color PixelRenderer::TextRenderer::applyTint(const ostd::Color& baseColor, const ostd::Color& tintColor) { auto nBase = baseColor.getNormalizedColor(); auto nTint = tintColor.getNormalizedColor(); - float r = nBase.r * nTint.r; - float g = nBase.r * nTint.g; - float b = nBase.r * nTint.b; + f32 r = nBase.r * nTint.r; + f32 g = nBase.r * nTint.g; + f32 b = nBase.r * nTint.b; ostd::Color::FloatCol nTinted(r, g, b, 1.0f); return ostd::Color(nTinted); } - void PixelRenderer::TextRenderer::drawCharacter(uint8_t* screenPixels, int32_t screenWidth, int32_t screenHeight, uint8_t* fontPixels, int32_t x, int32_t y, char c, ostd::Color color, ostd::Color background) + void PixelRenderer::TextRenderer::drawCharacter(u8* screenPixels, i32 screenWidth, i32 screenHeight, u8* fontPixels, i32 x, i32 y, char c, const ostd::Color& color, const ostd::Color& background) { using namespace ostd; - int32_t charIndex = characterMap[c]; + i32 charIndex = characterMap[c]; IPoint charCoords = CONVERT_1D_2D(charIndex, (FONT_CHAR_W * FONT_H_CHARS * 4)); - int32_t screenx = x * 4, screeny = y; + i32 screenx = x * 4, screeny = y; ostd::Color tintedColor; bool applyBackground = false; - for (int32_t y = charCoords.y; y < charCoords.y + (FONT_CHAR_H); y += 1) + for (i32 y = charCoords.y; y < charCoords.y + (FONT_CHAR_H); y += 1) { - for (int32_t x = charCoords.x; x < charCoords.x + (FONT_CHAR_W * 4); x += 4) + for (i32 x = charCoords.x; x < charCoords.x + (FONT_CHAR_W * 4); x += 4) { - int32_t index = CONVERT_2D_1D(x, y, (FONT_CHAR_W * FONT_H_CHARS * 4)); - int32_t screenIndex = CONVERT_2D_1D(screenx, screeny, (screenWidth * 4)); + i32 index = CONVERT_2D_1D(x, y, (FONT_CHAR_W * FONT_H_CHARS * 4)); + i32 screenIndex = CONVERT_2D_1D(screenx, screeny, (screenWidth * 4)); screenx += 4; if (fontPixels[index] == 0x00 && fontPixels[index + 1] == 0x00 && fontPixels[index + 2] == 0x00) { @@ -138,7 +138,7 @@ namespace ogfx if (!parent.isValid() || !parent.isInitialized()) return; //TODO: Error m_parent = &parent; - m_pixels = ostd::Memory::createArray(parent.getWindowWidth() * parent.getWindowHeight()); + m_pixels = ostd::Memory::createArray(parent.getWindowWidth() * parent.getWindowHeight()); m_texture = SDL_CreateTexture(parent.getSDLRenderer(), SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, parent.getWindowWidth(), parent.getWindowHeight()); m_windowWidth = parent.getWindowWidth(); m_windowHeight = parent.getWindowHeight(); @@ -153,7 +153,7 @@ namespace ogfx if (isInvalid()) return; if (signal.ID == ostd::BuiltinSignals::WindowResized) { - m_pixels = ostd::Memory::resizeArray(m_pixels, m_parent->getWindowWidth() * m_parent->getWindowHeight()); + m_pixels = ostd::Memory::resizeArray(m_pixels, m_parent->getWindowWidth() * m_parent->getWindowHeight()); SDL_DestroyTexture(m_texture); m_texture = SDL_CreateTexture(m_parent->getSDLRenderer(), SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, m_parent->getWindowWidth(), m_parent->getWindowHeight()); m_windowWidth = m_parent->getWindowWidth(); @@ -172,18 +172,18 @@ namespace ogfx void PixelRenderer::displayBuffer(void) { if (isInvalid()) return; - SDL_FRect rect { 0, 0, static_cast(m_windowWidth), static_cast(m_windowHeight) }; + SDL_FRect rect { 0, 0, cast(m_windowWidth), cast(m_windowHeight) }; SDL_RenderTexture(m_parent->getSDLRenderer(), m_texture, NULL, &rect); } void PixelRenderer::clear(const ostd::Color& color) { if (isInvalid()) return; - for (int32_t y = 0; y < m_windowHeight; y++) + for (i32 y = 0; y < m_windowHeight; y++) { - for (uint32_t x = 0; x < m_windowWidth; x++) + for (u32 x = 0; x < m_windowWidth; x++) { - int32_t index = CONVERT_2D_1D(x, y, m_windowWidth); + i32 index = CONVERT_2D_1D(x, y, m_windowWidth); m_pixels[index] = color.asInteger(ostd::Color::eColorFormat::ARGB); } } diff --git a/src/ogfx/render/PixelRenderer.hpp b/src/ogfx/render/PixelRenderer.hpp index 700c21b..41080f6 100644 --- a/src/ogfx/render/PixelRenderer.hpp +++ b/src/ogfx/render/PixelRenderer.hpp @@ -24,7 +24,7 @@ #include #include #include -#include + namespace ogfx { @@ -34,42 +34,42 @@ namespace ogfx public: class TextRenderer { private: - inline static std::unordered_map characterMap; + inline static stdumap characterMap; public: static void initialize(void); - static bool drawString(ostd::String str, uint32_t column, uint32_t row, uint32_t* screenPixels, int32_t screenWidth, int32_t screenHeight, uint32_t* fontPixels, ostd::Color color = { 255, 255, 255, 255 }, ostd::Color background = { 255, 255, 255, 0 }); + static bool drawString(const String& str, u32 column, u32 row, u32* screenPixels, i32 screenWidth, i32 screenHeight, u32* fontPixels, const ostd::Color& color = { 255, 255, 255, 255 }, const ostd::Color& background = { 255, 255, 255, 0 }); private: - static int32_t getCharacterIndex(char c); - static ostd::Color applyTint(ostd::Color baseColor, ostd::Color tintColor); - static void drawCharacter(uint8_t* screenPixels, int32_t screenWidth, int32_t screenHeight, uint8_t* fontPixels, int32_t x, int32_t y, char c, ostd::Color color = { 255, 255, 255, 255 }, ostd::Color background = { 255, 255, 255, 0 }); + static i32 getCharacterIndex(char c); + static ostd::Color applyTint(const ostd::Color& baseColor, const ostd::Color& tintColor); + static void drawCharacter(u8* screenPixels, i32 screenWidth, i32 screenHeight, u8* fontPixels, i32 x, i32 y, char c, const ostd::Color& color = { 255, 255, 255, 255 }, const ostd::Color& background = { 255, 255, 255, 0 }); public: - inline static constexpr int32_t FONT_CHAR_W = 11; - inline static constexpr int32_t FONT_CHAR_H = 26; - inline static constexpr int32_t FONT_V_CHARS = 6; - inline static constexpr int32_t FONT_H_CHARS = 16; - inline static constexpr int32_t CONSOLE_CHARS_H = 90; - inline static constexpr int32_t CONSOLE_CHARS_V = 21; + inline static constexpr i32 FONT_CHAR_W = 11; + inline static constexpr i32 FONT_CHAR_H = 26; + inline static constexpr i32 FONT_V_CHARS = 6; + inline static constexpr i32 FONT_H_CHARS = 16; + inline static constexpr i32 CONSOLE_CHARS_H = 90; + inline static constexpr i32 CONSOLE_CHARS_V = 21; - inline static int8_t s_cursor_pos_x = 0; + inline static i8 s_cursor_pos_x = 0; }; public: class Font { public: inline Font(void) { } - inline Font(const ostd::String& fontPath) + inline Font(const String& fontPath) { init(fontPath); } - inline void init(const ostd::String& fontPath) + inline void init(const String& fontPath) { ostd::ConsoleOutputHandler out; m_fontSurface = SDL_LoadBMP(fontPath.c_str()); if (m_fontSurface == NULL) out.bg(ostd::ConsoleColors::Red).p("Error loading pixel font.").reset().nl(); - m_fontPixels = (uint32_t*)m_fontSurface->pixels; + m_fontPixels = (u32*)m_fontSurface->pixels; } inline ~Font(void) { @@ -78,7 +78,7 @@ namespace ogfx public: SDL_Surface* m_fontSurface { nullptr }; - uint32_t* m_fontPixels { nullptr }; + u32* m_fontPixels { nullptr }; }; public: inline PixelRenderer(void) { invalidate(); } @@ -87,15 +87,15 @@ namespace ogfx void handleSignal(ostd::Signal& signal) override; void updateBuffer(void); void displayBuffer(void); - inline uint32_t* getScreenPixels(void) { return m_pixels; } + inline u32* getScreenPixels(void) { return m_pixels; } void clear(const ostd::Color& color); private: - uint32_t* m_pixels { nullptr }; + u32* m_pixels { nullptr }; SDL_Texture* m_texture { nullptr }; WindowCore* m_parent { nullptr }; - int32_t m_windowWidth { 0 }; - int32_t m_windowHeight { 0 }; + i32 m_windowWidth { 0 }; + i32 m_windowHeight { 0 }; }; } diff --git a/src/ogfx/resources/Image.cpp b/src/ogfx/resources/Image.cpp index f05f635..5f1cb0a 100644 --- a/src/ogfx/resources/Image.cpp +++ b/src/ogfx/resources/Image.cpp @@ -34,7 +34,7 @@ namespace ogfx m_height = 0; } - Image& Image::loadFromFile(const ostd::String& filePath, BasicRenderer2D& gfx) + Image& Image::loadFromFile(const String& filePath, BasicRenderer2D& gfx) { if (!gfx.isInitialized()) return *this; //TODO: Error diff --git a/src/ogfx/resources/Image.hpp b/src/ogfx/resources/Image.hpp index 7156e46..3ab631b 100644 --- a/src/ogfx/resources/Image.hpp +++ b/src/ogfx/resources/Image.hpp @@ -31,18 +31,18 @@ namespace ogfx { public: inline Image(void) { invalidate(); } - inline Image(const ostd::String& filePath, BasicRenderer2D& gfx) { loadFromFile(filePath, gfx); } + inline Image(const String& filePath, BasicRenderer2D& gfx) { loadFromFile(filePath, gfx); } inline ~Image(void) { destroy(); } void destroy(void); - Image& loadFromFile(const ostd::String& filePath, BasicRenderer2D& gfx); + Image& loadFromFile(const String& filePath, BasicRenderer2D& gfx); inline ostd::Vec2 getSize(void) const { return { m_width, m_height }; } inline bool isLoaded(void) const { return m_loaded; } inline SDL_Texture* getSDLTexture(void) const { return m_sdl_texture; } private: SDL_Texture* m_sdl_texture { nullptr }; - float m_width { 0 }; - float m_height { 0 }; + f32 m_width { 0 }; + f32 m_height { 0 }; bool m_loaded { false }; }; } diff --git a/src/ogfx/resources/UbuntuMonoRegularTTF.cpp b/src/ogfx/resources/UbuntuMonoRegularTTF.cpp index 54770c0..8eb1801 100644 --- a/src/ogfx/resources/UbuntuMonoRegularTTF.cpp +++ b/src/ogfx/resources/UbuntuMonoRegularTTF.cpp @@ -35,7 +35,7 @@ namespace ogfx { - const uint32_t ubuntu_mono_regular_ttf_size = 189892; + const u32 ubuntu_mono_regular_ttf_size = 189892; const ostd::UByte ubuntu_mono_regular_ttf_data[189892] = { 0, 1, 0, 0, 0, 16, 1, 0, 0, 4, 0, 0, 71, 83, 85, 66, 172, 54, 149, 231, 0, 0, 34, 204, 0, 0, 16, 50, 79, 83, 47, 50, 136, 193, 253, 210, 0, 0, 1, 144, diff --git a/src/ogfx/resources/UbuntuMonoRegularTTF.hpp b/src/ogfx/resources/UbuntuMonoRegularTTF.hpp index d0ea5e2..14cf7b6 100644 --- a/src/ogfx/resources/UbuntuMonoRegularTTF.hpp +++ b/src/ogfx/resources/UbuntuMonoRegularTTF.hpp @@ -24,6 +24,6 @@ namespace ogfx { - extern const uint32_t ubuntu_mono_regular_ttf_size; + extern const u32 ubuntu_mono_regular_ttf_size; extern const ostd::UByte ubuntu_mono_regular_ttf_data[]; } diff --git a/src/ogfx/utils/Animation.cpp b/src/ogfx/utils/Animation.cpp index 94064d2..3cb9cb5 100644 --- a/src/ogfx/utils/Animation.cpp +++ b/src/ogfx/utils/Animation.cpp @@ -28,7 +28,7 @@ namespace ogfx create(0, 0, 0, 0, 0); } - Animation::Animation(int frames, int columns, int rows, int frame_width, int frame_height) + Animation::Animation(i32 frames, i32 columns, i32 rows, i32 frame_width, i32 frame_height) { create(frames, columns, rows, frame_width, frame_height); } @@ -49,7 +49,7 @@ namespace ogfx m_random = false; } - void Animation::create(int frames, int columns, int rows, int frame_width, int frame_height) + void Animation::create(i32 frames, i32 columns, i32 rows, i32 frame_width, i32 frame_height) { m_frames = frames; m_columns = columns; @@ -107,11 +107,11 @@ namespace ogfx } else if (m_still) m_current_frame = 1; //TODO: Hardcoded value - int x = ((m_current_frame % m_columns) + m_column_offset) * m_frame_width; - int y = m_row_offset * m_frame_height; + i32 x = ((m_current_frame % m_columns) + m_column_offset) * m_frame_width; + i32 y = m_row_offset * m_frame_height; if (m_rows > 1) y = ((m_current_frame / m_columns) + m_row_offset) * m_frame_height; - m_frame_rect = { static_cast(x), static_cast(y), static_cast(m_frame_width), static_cast(m_frame_height) }; + m_frame_rect = { cast(x), cast(y), cast(m_frame_width), cast(m_frame_height) }; } } diff --git a/src/ogfx/utils/Animation.hpp b/src/ogfx/utils/Animation.hpp index fa7413d..8654742 100644 --- a/src/ogfx/utils/Animation.hpp +++ b/src/ogfx/utils/Animation.hpp @@ -29,18 +29,18 @@ namespace ogfx class Animation { public: struct AnimationData { - int32_t length; - int32_t speed; - int32_t still_frame; + i32 length; + i32 speed; + i32 still_frame; - int32_t row_offset; - int32_t column_offset; + i32 row_offset; + i32 column_offset; - int32_t rows; - int32_t columns; + i32 rows; + i32 columns; - int32_t frame_width; - int32_t frame_height; + i32 frame_width; + i32 frame_height; bool still; bool backwards; @@ -64,28 +64,28 @@ namespace ogfx }; public: Animation(void); - Animation(int32_t frames, int32_t columns, int32_t rows, int32_t frame_width, int32_t frame_height); + Animation(i32 frames, i32 columns, i32 rows, i32 frame_width, i32 frame_height); Animation(AnimationData& ad); - void create(int32_t frames, int32_t columns, int32_t rows, int32_t frame_width, int32_t frame_height); + void create(i32 frames, i32 columns, i32 rows, i32 frame_width, i32 frame_height); void create(AnimationData& ad); void update(void); void resetAnimation(void); - inline void setFrameNumber(int32_t n) { m_frames = n; } - inline void setColumnNumber(int32_t n) { m_columns = n; } + inline void setFrameNumber(i32 n) { m_frames = n; } + inline void setColumnNumber(i32 n) { m_columns = n; } inline void setBackwards(bool b) { m_backwards = b; } - inline void setSpeed(int32_t d) { m_frame_time = d; } - inline void setColumnOffset(int32_t o) { m_column_offset = o; } - inline void setRowOffset(int32_t o) { m_row_offset = o; } + inline void setSpeed(i32 d) { m_frame_time = d; } + inline void setColumnOffset(i32 o) { m_column_offset = o; } + inline void setRowOffset(i32 o) { m_row_offset = o; } inline void setStill(bool s) { m_still = s; } inline void setSpriteSheet(Image& img) { m_spriteSheet = &img; } - inline int32_t getFrameNumber(void) const { return m_frames; } - inline int32_t getColumnNumber(void) const { return m_columns; } + inline i32 getFrameNumber(void) const { return m_frames; } + inline i32 getColumnNumber(void) const { return m_columns; } inline bool getBackwards(void) const { return m_backwards; } - inline int32_t getDelay(void) const { return m_frame_time; } - inline int32_t getColumnOffset(void) const { return m_column_offset; } - inline int32_t getRowOffset(void) const { return m_row_offset; } + inline i32 getDelay(void) const { return m_frame_time; } + inline i32 getColumnOffset(void) const { return m_column_offset; } + inline i32 getRowOffset(void) const { return m_row_offset; } inline bool isStill(void) const { return m_still; } inline ostd::Rectangle getFrameRect(void) const { return m_frame_rect; } inline const Image& getSpriteSheet(void) const { return (m_spriteSheet != nullptr ? *m_spriteSheet : InvalidImage); } @@ -96,18 +96,18 @@ namespace ogfx Image* m_spriteSheet { nullptr }; inline static Image InvalidImage; - int32_t m_frames; - int32_t m_rows; - int32_t m_columns; - int32_t m_frame_width; - int32_t m_frame_height; + i32 m_frames; + i32 m_rows; + i32 m_columns; + i32 m_frame_width; + i32 m_frame_height; - int32_t m_column_offset; - int32_t m_row_offset; + i32 m_column_offset; + i32 m_row_offset; - int32_t m_frame_time; - int32_t m_current_time; - int32_t m_current_frame; + i32 m_frame_time; + i32 m_current_time; + i32 m_current_frame; bool m_backwards; bool m_back; diff --git a/src/ogfx/utils/Keycodes.hpp b/src/ogfx/utils/Keycodes.hpp index 5b590cd..9754023 100644 --- a/src/ogfx/utils/Keycodes.hpp +++ b/src/ogfx/utils/Keycodes.hpp @@ -26,261 +26,261 @@ namespace ogfx { struct KeyCode { - inline static constexpr uint32_t Unknown { SDLK_UNKNOWN }; - inline static constexpr uint32_t Return { SDLK_RETURN }; - inline static constexpr uint32_t Escape { SDLK_ESCAPE }; - inline static constexpr uint32_t Backspace { SDLK_BACKSPACE }; - inline static constexpr uint32_t Tab { SDLK_TAB }; - inline static constexpr uint32_t Space { SDLK_SPACE }; - inline static constexpr uint32_t Exclaim { SDLK_EXCLAIM }; - inline static constexpr uint32_t Dblapostrophe { SDLK_DBLAPOSTROPHE }; - inline static constexpr uint32_t Hash { SDLK_HASH }; - inline static constexpr uint32_t Dollar { SDLK_DOLLAR }; - inline static constexpr uint32_t Percent { SDLK_PERCENT }; - inline static constexpr uint32_t Ampersand { SDLK_AMPERSAND }; - inline static constexpr uint32_t Apostrophe { SDLK_APOSTROPHE }; - inline static constexpr uint32_t Leftparen { SDLK_LEFTPAREN }; - inline static constexpr uint32_t Rightparen { SDLK_RIGHTPAREN }; - inline static constexpr uint32_t Asterisk { SDLK_ASTERISK }; - inline static constexpr uint32_t Plus { SDLK_PLUS }; - inline static constexpr uint32_t Comma { SDLK_COMMA }; - inline static constexpr uint32_t Minus { SDLK_MINUS }; - inline static constexpr uint32_t Period { SDLK_PERIOD }; - inline static constexpr uint32_t Slash { SDLK_SLASH }; - inline static constexpr uint32_t Num0 { SDLK_0 }; - inline static constexpr uint32_t Num1 { SDLK_1 }; - inline static constexpr uint32_t Num2 { SDLK_2 }; - inline static constexpr uint32_t Num3 { SDLK_3 }; - inline static constexpr uint32_t Num4 { SDLK_4 }; - inline static constexpr uint32_t Num5 { SDLK_5 }; - inline static constexpr uint32_t Num6 { SDLK_6 }; - inline static constexpr uint32_t Num7 { SDLK_7 }; - inline static constexpr uint32_t Num8 { SDLK_8 }; - inline static constexpr uint32_t Num9 { SDLK_9 }; - inline static constexpr uint32_t Colon { SDLK_COLON }; - inline static constexpr uint32_t Semicolon { SDLK_SEMICOLON }; - inline static constexpr uint32_t Less { SDLK_LESS }; - inline static constexpr uint32_t Equals { SDLK_EQUALS }; - inline static constexpr uint32_t Greater { SDLK_GREATER }; - inline static constexpr uint32_t Question { SDLK_QUESTION }; - inline static constexpr uint32_t At { SDLK_AT }; - inline static constexpr uint32_t LeftBracket { SDLK_LEFTBRACKET }; - inline static constexpr uint32_t Backslash { SDLK_BACKSLASH }; - inline static constexpr uint32_t RightBracket { SDLK_RIGHTBRACKET }; - inline static constexpr uint32_t Caret { SDLK_CARET }; - inline static constexpr uint32_t Underscore { SDLK_UNDERSCORE }; - inline static constexpr uint32_t Grave { SDLK_GRAVE }; - inline static constexpr uint32_t A { SDLK_A }; - inline static constexpr uint32_t B { SDLK_B }; - inline static constexpr uint32_t C { SDLK_C }; - inline static constexpr uint32_t D { SDLK_D }; - inline static constexpr uint32_t E { SDLK_E }; - inline static constexpr uint32_t F { SDLK_F }; - inline static constexpr uint32_t G { SDLK_G }; - inline static constexpr uint32_t H { SDLK_H }; - inline static constexpr uint32_t I { SDLK_I }; - inline static constexpr uint32_t J { SDLK_J }; - inline static constexpr uint32_t K { SDLK_K }; - inline static constexpr uint32_t L { SDLK_L }; - inline static constexpr uint32_t M { SDLK_M }; - inline static constexpr uint32_t N { SDLK_N }; - inline static constexpr uint32_t O { SDLK_O }; - inline static constexpr uint32_t P { SDLK_P }; - inline static constexpr uint32_t Q { SDLK_Q }; - inline static constexpr uint32_t R { SDLK_R }; - inline static constexpr uint32_t S { SDLK_S }; - inline static constexpr uint32_t T { SDLK_T }; - inline static constexpr uint32_t U { SDLK_U }; - inline static constexpr uint32_t V { SDLK_V }; - inline static constexpr uint32_t W { SDLK_W }; - inline static constexpr uint32_t X { SDLK_X }; - inline static constexpr uint32_t Y { SDLK_Y }; - inline static constexpr uint32_t Z { SDLK_Z }; - inline static constexpr uint32_t Leftbrace { SDLK_LEFTBRACE }; - inline static constexpr uint32_t Pipe { SDLK_PIPE }; - inline static constexpr uint32_t Rightbrace { SDLK_RIGHTBRACE }; - inline static constexpr uint32_t Tilde { SDLK_TILDE }; - inline static constexpr uint32_t Delete { SDLK_DELETE }; - inline static constexpr uint32_t Plusminus { SDLK_PLUSMINUS }; - inline static constexpr uint32_t Capslock { SDLK_CAPSLOCK }; - inline static constexpr uint32_t F1 { SDLK_F1 }; - inline static constexpr uint32_t F2 { SDLK_F2 }; - inline static constexpr uint32_t F3 { SDLK_F3 }; - inline static constexpr uint32_t F4 { SDLK_F4 }; - inline static constexpr uint32_t F5 { SDLK_F5 }; - inline static constexpr uint32_t F6 { SDLK_F6 }; - inline static constexpr uint32_t F7 { SDLK_F7 }; - inline static constexpr uint32_t F8 { SDLK_F8 }; - inline static constexpr uint32_t F9 { SDLK_F9 }; - inline static constexpr uint32_t F10 { SDLK_F10 }; - inline static constexpr uint32_t F11 { SDLK_F11 }; - inline static constexpr uint32_t F12 { SDLK_F12 }; - inline static constexpr uint32_t Printscreen { SDLK_PRINTSCREEN }; - inline static constexpr uint32_t Scrolllock { SDLK_SCROLLLOCK }; - inline static constexpr uint32_t Pause { SDLK_PAUSE }; - inline static constexpr uint32_t Insert { SDLK_INSERT }; - inline static constexpr uint32_t Home { SDLK_HOME }; - inline static constexpr uint32_t Pageup { SDLK_PAGEUP }; - inline static constexpr uint32_t End { SDLK_END }; - inline static constexpr uint32_t Pagedown { SDLK_PAGEDOWN }; - inline static constexpr uint32_t Right { SDLK_RIGHT }; - inline static constexpr uint32_t Left { SDLK_LEFT }; - inline static constexpr uint32_t Down { SDLK_DOWN }; - inline static constexpr uint32_t Up { SDLK_UP }; - inline static constexpr uint32_t Numlockclear { SDLK_NUMLOCKCLEAR }; - inline static constexpr uint32_t KpDivide { SDLK_KP_DIVIDE }; - inline static constexpr uint32_t KpMultiply { SDLK_KP_MULTIPLY }; - inline static constexpr uint32_t KpMinus { SDLK_KP_MINUS }; - inline static constexpr uint32_t KpPlus { SDLK_KP_PLUS }; - inline static constexpr uint32_t KpEnter { SDLK_KP_ENTER }; - inline static constexpr uint32_t Kp1 { SDLK_KP_1 }; - inline static constexpr uint32_t Kp2 { SDLK_KP_2 }; - inline static constexpr uint32_t Kp3 { SDLK_KP_3 }; - inline static constexpr uint32_t Kp4 { SDLK_KP_4 }; - inline static constexpr uint32_t Kp5 { SDLK_KP_5 }; - inline static constexpr uint32_t Kp6 { SDLK_KP_6 }; - inline static constexpr uint32_t Kp7 { SDLK_KP_7 }; - inline static constexpr uint32_t Kp8 { SDLK_KP_8 }; - inline static constexpr uint32_t Kp9 { SDLK_KP_9 }; - inline static constexpr uint32_t Kp0 { SDLK_KP_0 }; - inline static constexpr uint32_t KpPeriod { SDLK_KP_PERIOD }; - inline static constexpr uint32_t Application { SDLK_APPLICATION }; - inline static constexpr uint32_t Power { SDLK_POWER }; - inline static constexpr uint32_t KpEquals { SDLK_KP_EQUALS }; - inline static constexpr uint32_t F13 { SDLK_F13 }; - inline static constexpr uint32_t F14 { SDLK_F14 }; - inline static constexpr uint32_t F15 { SDLK_F15 }; - inline static constexpr uint32_t F16 { SDLK_F16 }; - inline static constexpr uint32_t F17 { SDLK_F17 }; - inline static constexpr uint32_t F18 { SDLK_F18 }; - inline static constexpr uint32_t F19 { SDLK_F19 }; - inline static constexpr uint32_t F20 { SDLK_F20 }; - inline static constexpr uint32_t F21 { SDLK_F21 }; - inline static constexpr uint32_t F22 { SDLK_F22 }; - inline static constexpr uint32_t F23 { SDLK_F23 }; - inline static constexpr uint32_t F24 { SDLK_F24 }; - inline static constexpr uint32_t Execute { SDLK_EXECUTE }; - inline static constexpr uint32_t Help { SDLK_HELP }; - inline static constexpr uint32_t Menu { SDLK_MENU }; - inline static constexpr uint32_t Select { SDLK_SELECT }; - inline static constexpr uint32_t Stop { SDLK_STOP }; - inline static constexpr uint32_t Again { SDLK_AGAIN }; - inline static constexpr uint32_t Undo { SDLK_UNDO }; - inline static constexpr uint32_t Cut { SDLK_CUT }; - inline static constexpr uint32_t Copy { SDLK_COPY }; - inline static constexpr uint32_t Paste { SDLK_PASTE }; - inline static constexpr uint32_t Find { SDLK_FIND }; - inline static constexpr uint32_t Mute { SDLK_MUTE }; - inline static constexpr uint32_t Volumeup { SDLK_VOLUMEUP }; - inline static constexpr uint32_t Volumedown { SDLK_VOLUMEDOWN }; - inline static constexpr uint32_t KpComma { SDLK_KP_COMMA }; - inline static constexpr uint32_t KpEqualsas400 { SDLK_KP_EQUALSAS400 }; - inline static constexpr uint32_t Alterase { SDLK_ALTERASE }; - inline static constexpr uint32_t Sysreq { SDLK_SYSREQ }; - inline static constexpr uint32_t Cancel { SDLK_CANCEL }; - inline static constexpr uint32_t Clear { SDLK_CLEAR }; - inline static constexpr uint32_t Prior { SDLK_PRIOR }; - inline static constexpr uint32_t Return2 { SDLK_RETURN2 }; - inline static constexpr uint32_t Separator { SDLK_SEPARATOR }; - inline static constexpr uint32_t Out { SDLK_OUT }; - inline static constexpr uint32_t Oper { SDLK_OPER }; - inline static constexpr uint32_t Clearagain { SDLK_CLEARAGAIN }; - inline static constexpr uint32_t Crsel { SDLK_CRSEL }; - inline static constexpr uint32_t Exsel { SDLK_EXSEL }; - inline static constexpr uint32_t Kp00 { SDLK_KP_00 }; - inline static constexpr uint32_t Kp000 { SDLK_KP_000 }; - inline static constexpr uint32_t Thousandsseparator { SDLK_THOUSANDSSEPARATOR }; - inline static constexpr uint32_t Decimalseparator { SDLK_DECIMALSEPARATOR }; - inline static constexpr uint32_t Currencyunit { SDLK_CURRENCYUNIT }; - inline static constexpr uint32_t Currencysubunit { SDLK_CURRENCYSUBUNIT }; - inline static constexpr uint32_t KpLeftparen { SDLK_KP_LEFTPAREN }; - inline static constexpr uint32_t KpRightparen { SDLK_KP_RIGHTPAREN }; - inline static constexpr uint32_t KpLeftbrace { SDLK_KP_LEFTBRACE }; - inline static constexpr uint32_t KpRightbrace { SDLK_KP_RIGHTBRACE }; - inline static constexpr uint32_t KpTab { SDLK_KP_TAB }; - inline static constexpr uint32_t KpBackspace { SDLK_KP_BACKSPACE }; - inline static constexpr uint32_t KpA { SDLK_KP_A }; - inline static constexpr uint32_t KpB { SDLK_KP_B }; - inline static constexpr uint32_t KpC { SDLK_KP_C }; - inline static constexpr uint32_t KpD { SDLK_KP_D }; - inline static constexpr uint32_t KpE { SDLK_KP_E }; - inline static constexpr uint32_t KpF { SDLK_KP_F }; - inline static constexpr uint32_t KpXor { SDLK_KP_XOR }; - inline static constexpr uint32_t KpPower { SDLK_KP_POWER }; - inline static constexpr uint32_t KpPercent { SDLK_KP_PERCENT }; - inline static constexpr uint32_t KpLess { SDLK_KP_LESS }; - inline static constexpr uint32_t KpGreater { SDLK_KP_GREATER }; - inline static constexpr uint32_t KpAmpersand { SDLK_KP_AMPERSAND }; - inline static constexpr uint32_t KpDblampersand { SDLK_KP_DBLAMPERSAND }; - inline static constexpr uint32_t KpVerticalbar { SDLK_KP_VERTICALBAR }; - inline static constexpr uint32_t KpDblverticalbar { SDLK_KP_DBLVERTICALBAR }; - inline static constexpr uint32_t KpColon { SDLK_KP_COLON }; - inline static constexpr uint32_t KpHash { SDLK_KP_HASH }; - inline static constexpr uint32_t KpSpace { SDLK_KP_SPACE }; - inline static constexpr uint32_t KpAt { SDLK_KP_AT }; - inline static constexpr uint32_t KpExclam { SDLK_KP_EXCLAM }; - inline static constexpr uint32_t KpMemstore { SDLK_KP_MEMSTORE }; - inline static constexpr uint32_t KpMemrecall { SDLK_KP_MEMRECALL }; - inline static constexpr uint32_t KpMemclear { SDLK_KP_MEMCLEAR }; - inline static constexpr uint32_t KpMemadd { SDLK_KP_MEMADD }; - inline static constexpr uint32_t KpMemsubtract { SDLK_KP_MEMSUBTRACT }; - inline static constexpr uint32_t KpMemmultiply { SDLK_KP_MEMMULTIPLY }; - inline static constexpr uint32_t KpMemdivide { SDLK_KP_MEMDIVIDE }; - inline static constexpr uint32_t KpPlusminus { SDLK_KP_PLUSMINUS }; - inline static constexpr uint32_t KpClear { SDLK_KP_CLEAR }; - inline static constexpr uint32_t KpClearentry { SDLK_KP_CLEARENTRY }; - inline static constexpr uint32_t KpBinary { SDLK_KP_BINARY }; - inline static constexpr uint32_t KpOctal { SDLK_KP_OCTAL }; - inline static constexpr uint32_t KpDecimal { SDLK_KP_DECIMAL }; - inline static constexpr uint32_t KpHexadecimal { SDLK_KP_HEXADECIMAL }; - inline static constexpr uint32_t Lctrl { SDLK_LCTRL }; - inline static constexpr uint32_t Lshift { SDLK_LSHIFT }; - inline static constexpr uint32_t Lalt { SDLK_LALT }; - inline static constexpr uint32_t Lgui { SDLK_LGUI }; - inline static constexpr uint32_t Rctrl { SDLK_RCTRL }; - inline static constexpr uint32_t Rshift { SDLK_RSHIFT }; - inline static constexpr uint32_t Ralt { SDLK_RALT }; - inline static constexpr uint32_t Rgui { SDLK_RGUI }; - inline static constexpr uint32_t Mode { SDLK_MODE }; - inline static constexpr uint32_t Sleep { SDLK_SLEEP }; - inline static constexpr uint32_t Wake { SDLK_WAKE }; - inline static constexpr uint32_t ChannelIncrement { SDLK_CHANNEL_INCREMENT }; - inline static constexpr uint32_t ChannelDecrement { SDLK_CHANNEL_DECREMENT }; - inline static constexpr uint32_t MediaPlay { SDLK_MEDIA_PLAY }; - inline static constexpr uint32_t MediaPause { SDLK_MEDIA_PAUSE }; - inline static constexpr uint32_t MediaRecord { SDLK_MEDIA_RECORD }; - inline static constexpr uint32_t MediaFastForward { SDLK_MEDIA_FAST_FORWARD }; - inline static constexpr uint32_t MediaRewind { SDLK_MEDIA_REWIND }; - inline static constexpr uint32_t MediaNextTrack { SDLK_MEDIA_NEXT_TRACK }; - inline static constexpr uint32_t MediaPreviousTrack { SDLK_MEDIA_PREVIOUS_TRACK }; - inline static constexpr uint32_t MediaStop { SDLK_MEDIA_STOP }; - inline static constexpr uint32_t MediaEject { SDLK_MEDIA_EJECT }; - inline static constexpr uint32_t MediaPlayPause { SDLK_MEDIA_PLAY_PAUSE }; - inline static constexpr uint32_t MediaSelect { SDLK_MEDIA_SELECT }; - inline static constexpr uint32_t AcNew { SDLK_AC_NEW }; - inline static constexpr uint32_t AcOpen { SDLK_AC_OPEN }; - inline static constexpr uint32_t AcClose { SDLK_AC_CLOSE }; - inline static constexpr uint32_t AcExit { SDLK_AC_EXIT }; - inline static constexpr uint32_t AcSave { SDLK_AC_SAVE }; - inline static constexpr uint32_t AcPrint { SDLK_AC_PRINT }; - inline static constexpr uint32_t AcProperties { SDLK_AC_PROPERTIES }; - inline static constexpr uint32_t AcSearch { SDLK_AC_SEARCH }; - inline static constexpr uint32_t AcHome { SDLK_AC_HOME }; - inline static constexpr uint32_t AcBack { SDLK_AC_BACK }; - inline static constexpr uint32_t AcForward { SDLK_AC_FORWARD }; - inline static constexpr uint32_t AcStop { SDLK_AC_STOP }; - inline static constexpr uint32_t AcRefresh { SDLK_AC_REFRESH }; - inline static constexpr uint32_t AcBookmarks { SDLK_AC_BOOKMARKS }; - inline static constexpr uint32_t Softleft { SDLK_SOFTLEFT }; - inline static constexpr uint32_t Softright { SDLK_SOFTRIGHT }; - inline static constexpr uint32_t Call { SDLK_CALL }; - inline static constexpr uint32_t Endcall { SDLK_ENDCALL }; - inline static constexpr uint32_t LeftTab { SDLK_LEFT_TAB }; - inline static constexpr uint32_t Level5Shift { SDLK_LEVEL5_SHIFT }; - inline static constexpr uint32_t MultiKeyCompose { SDLK_MULTI_KEY_COMPOSE }; - inline static constexpr uint32_t Lmeta { SDLK_LMETA }; - inline static constexpr uint32_t Rmeta { SDLK_RMETA }; - inline static constexpr uint32_t Lhyper { SDLK_LHYPER }; - inline static constexpr uint32_t Rhyper { SDLK_RHYPER }; + inline static constexpr u32 Unknown { SDLK_UNKNOWN }; + inline static constexpr u32 Return { SDLK_RETURN }; + inline static constexpr u32 Escape { SDLK_ESCAPE }; + inline static constexpr u32 Backspace { SDLK_BACKSPACE }; + inline static constexpr u32 Tab { SDLK_TAB }; + inline static constexpr u32 Space { SDLK_SPACE }; + inline static constexpr u32 Exclaim { SDLK_EXCLAIM }; + inline static constexpr u32 Dblapostrophe { SDLK_DBLAPOSTROPHE }; + inline static constexpr u32 Hash { SDLK_HASH }; + inline static constexpr u32 Dollar { SDLK_DOLLAR }; + inline static constexpr u32 Percent { SDLK_PERCENT }; + inline static constexpr u32 Ampersand { SDLK_AMPERSAND }; + inline static constexpr u32 Apostrophe { SDLK_APOSTROPHE }; + inline static constexpr u32 Leftparen { SDLK_LEFTPAREN }; + inline static constexpr u32 Rightparen { SDLK_RIGHTPAREN }; + inline static constexpr u32 Asterisk { SDLK_ASTERISK }; + inline static constexpr u32 Plus { SDLK_PLUS }; + inline static constexpr u32 Comma { SDLK_COMMA }; + inline static constexpr u32 Minus { SDLK_MINUS }; + inline static constexpr u32 Period { SDLK_PERIOD }; + inline static constexpr u32 Slash { SDLK_SLASH }; + inline static constexpr u32 Num0 { SDLK_0 }; + inline static constexpr u32 Num1 { SDLK_1 }; + inline static constexpr u32 Num2 { SDLK_2 }; + inline static constexpr u32 Num3 { SDLK_3 }; + inline static constexpr u32 Num4 { SDLK_4 }; + inline static constexpr u32 Num5 { SDLK_5 }; + inline static constexpr u32 Num6 { SDLK_6 }; + inline static constexpr u32 Num7 { SDLK_7 }; + inline static constexpr u32 Num8 { SDLK_8 }; + inline static constexpr u32 Num9 { SDLK_9 }; + inline static constexpr u32 Colon { SDLK_COLON }; + inline static constexpr u32 Semicolon { SDLK_SEMICOLON }; + inline static constexpr u32 Less { SDLK_LESS }; + inline static constexpr u32 Equals { SDLK_EQUALS }; + inline static constexpr u32 Greater { SDLK_GREATER }; + inline static constexpr u32 Question { SDLK_QUESTION }; + inline static constexpr u32 At { SDLK_AT }; + inline static constexpr u32 LeftBracket { SDLK_LEFTBRACKET }; + inline static constexpr u32 Backslash { SDLK_BACKSLASH }; + inline static constexpr u32 RightBracket { SDLK_RIGHTBRACKET }; + inline static constexpr u32 Caret { SDLK_CARET }; + inline static constexpr u32 Underscore { SDLK_UNDERSCORE }; + inline static constexpr u32 Grave { SDLK_GRAVE }; + inline static constexpr u32 A { SDLK_A }; + inline static constexpr u32 B { SDLK_B }; + inline static constexpr u32 C { SDLK_C }; + inline static constexpr u32 D { SDLK_D }; + inline static constexpr u32 E { SDLK_E }; + inline static constexpr u32 F { SDLK_F }; + inline static constexpr u32 G { SDLK_G }; + inline static constexpr u32 H { SDLK_H }; + inline static constexpr u32 I { SDLK_I }; + inline static constexpr u32 J { SDLK_J }; + inline static constexpr u32 K { SDLK_K }; + inline static constexpr u32 L { SDLK_L }; + inline static constexpr u32 M { SDLK_M }; + inline static constexpr u32 N { SDLK_N }; + inline static constexpr u32 O { SDLK_O }; + inline static constexpr u32 P { SDLK_P }; + inline static constexpr u32 Q { SDLK_Q }; + inline static constexpr u32 R { SDLK_R }; + inline static constexpr u32 S { SDLK_S }; + inline static constexpr u32 T { SDLK_T }; + inline static constexpr u32 U { SDLK_U }; + inline static constexpr u32 V { SDLK_V }; + inline static constexpr u32 W { SDLK_W }; + inline static constexpr u32 X { SDLK_X }; + inline static constexpr u32 Y { SDLK_Y }; + inline static constexpr u32 Z { SDLK_Z }; + inline static constexpr u32 Leftbrace { SDLK_LEFTBRACE }; + inline static constexpr u32 Pipe { SDLK_PIPE }; + inline static constexpr u32 Rightbrace { SDLK_RIGHTBRACE }; + inline static constexpr u32 Tilde { SDLK_TILDE }; + inline static constexpr u32 Delete { SDLK_DELETE }; + inline static constexpr u32 Plusminus { SDLK_PLUSMINUS }; + inline static constexpr u32 Capslock { SDLK_CAPSLOCK }; + inline static constexpr u32 F1 { SDLK_F1 }; + inline static constexpr u32 F2 { SDLK_F2 }; + inline static constexpr u32 F3 { SDLK_F3 }; + inline static constexpr u32 F4 { SDLK_F4 }; + inline static constexpr u32 F5 { SDLK_F5 }; + inline static constexpr u32 F6 { SDLK_F6 }; + inline static constexpr u32 F7 { SDLK_F7 }; + inline static constexpr u32 F8 { SDLK_F8 }; + inline static constexpr u32 F9 { SDLK_F9 }; + inline static constexpr u32 F10 { SDLK_F10 }; + inline static constexpr u32 F11 { SDLK_F11 }; + inline static constexpr u32 F12 { SDLK_F12 }; + inline static constexpr u32 Printscreen { SDLK_PRINTSCREEN }; + inline static constexpr u32 Scrolllock { SDLK_SCROLLLOCK }; + inline static constexpr u32 Pause { SDLK_PAUSE }; + inline static constexpr u32 Insert { SDLK_INSERT }; + inline static constexpr u32 Home { SDLK_HOME }; + inline static constexpr u32 Pageup { SDLK_PAGEUP }; + inline static constexpr u32 End { SDLK_END }; + inline static constexpr u32 Pagedown { SDLK_PAGEDOWN }; + inline static constexpr u32 Right { SDLK_RIGHT }; + inline static constexpr u32 Left { SDLK_LEFT }; + inline static constexpr u32 Down { SDLK_DOWN }; + inline static constexpr u32 Up { SDLK_UP }; + inline static constexpr u32 Numlockclear { SDLK_NUMLOCKCLEAR }; + inline static constexpr u32 KpDivide { SDLK_KP_DIVIDE }; + inline static constexpr u32 KpMultiply { SDLK_KP_MULTIPLY }; + inline static constexpr u32 KpMinus { SDLK_KP_MINUS }; + inline static constexpr u32 KpPlus { SDLK_KP_PLUS }; + inline static constexpr u32 KpEnter { SDLK_KP_ENTER }; + inline static constexpr u32 Kp1 { SDLK_KP_1 }; + inline static constexpr u32 Kp2 { SDLK_KP_2 }; + inline static constexpr u32 Kp3 { SDLK_KP_3 }; + inline static constexpr u32 Kp4 { SDLK_KP_4 }; + inline static constexpr u32 Kp5 { SDLK_KP_5 }; + inline static constexpr u32 Kp6 { SDLK_KP_6 }; + inline static constexpr u32 Kp7 { SDLK_KP_7 }; + inline static constexpr u32 Kp8 { SDLK_KP_8 }; + inline static constexpr u32 Kp9 { SDLK_KP_9 }; + inline static constexpr u32 Kp0 { SDLK_KP_0 }; + inline static constexpr u32 KpPeriod { SDLK_KP_PERIOD }; + inline static constexpr u32 Application { SDLK_APPLICATION }; + inline static constexpr u32 Power { SDLK_POWER }; + inline static constexpr u32 KpEquals { SDLK_KP_EQUALS }; + inline static constexpr u32 F13 { SDLK_F13 }; + inline static constexpr u32 F14 { SDLK_F14 }; + inline static constexpr u32 F15 { SDLK_F15 }; + inline static constexpr u32 F16 { SDLK_F16 }; + inline static constexpr u32 F17 { SDLK_F17 }; + inline static constexpr u32 F18 { SDLK_F18 }; + inline static constexpr u32 F19 { SDLK_F19 }; + inline static constexpr u32 F20 { SDLK_F20 }; + inline static constexpr u32 F21 { SDLK_F21 }; + inline static constexpr u32 F22 { SDLK_F22 }; + inline static constexpr u32 F23 { SDLK_F23 }; + inline static constexpr u32 F24 { SDLK_F24 }; + inline static constexpr u32 Execute { SDLK_EXECUTE }; + inline static constexpr u32 Help { SDLK_HELP }; + inline static constexpr u32 Menu { SDLK_MENU }; + inline static constexpr u32 Select { SDLK_SELECT }; + inline static constexpr u32 Stop { SDLK_STOP }; + inline static constexpr u32 Again { SDLK_AGAIN }; + inline static constexpr u32 Undo { SDLK_UNDO }; + inline static constexpr u32 Cut { SDLK_CUT }; + inline static constexpr u32 Copy { SDLK_COPY }; + inline static constexpr u32 Paste { SDLK_PASTE }; + inline static constexpr u32 Find { SDLK_FIND }; + inline static constexpr u32 Mute { SDLK_MUTE }; + inline static constexpr u32 Volumeup { SDLK_VOLUMEUP }; + inline static constexpr u32 Volumedown { SDLK_VOLUMEDOWN }; + inline static constexpr u32 KpComma { SDLK_KP_COMMA }; + inline static constexpr u32 KpEqualsas400 { SDLK_KP_EQUALSAS400 }; + inline static constexpr u32 Alterase { SDLK_ALTERASE }; + inline static constexpr u32 Sysreq { SDLK_SYSREQ }; + inline static constexpr u32 Cancel { SDLK_CANCEL }; + inline static constexpr u32 Clear { SDLK_CLEAR }; + inline static constexpr u32 Prior { SDLK_PRIOR }; + inline static constexpr u32 Return2 { SDLK_RETURN2 }; + inline static constexpr u32 Separator { SDLK_SEPARATOR }; + inline static constexpr u32 Out { SDLK_OUT }; + inline static constexpr u32 Oper { SDLK_OPER }; + inline static constexpr u32 Clearagain { SDLK_CLEARAGAIN }; + inline static constexpr u32 Crsel { SDLK_CRSEL }; + inline static constexpr u32 Exsel { SDLK_EXSEL }; + inline static constexpr u32 Kp00 { SDLK_KP_00 }; + inline static constexpr u32 Kp000 { SDLK_KP_000 }; + inline static constexpr u32 Thousandsseparator { SDLK_THOUSANDSSEPARATOR }; + inline static constexpr u32 Decimalseparator { SDLK_DECIMALSEPARATOR }; + inline static constexpr u32 Currencyunit { SDLK_CURRENCYUNIT }; + inline static constexpr u32 Currencysubunit { SDLK_CURRENCYSUBUNIT }; + inline static constexpr u32 KpLeftparen { SDLK_KP_LEFTPAREN }; + inline static constexpr u32 KpRightparen { SDLK_KP_RIGHTPAREN }; + inline static constexpr u32 KpLeftbrace { SDLK_KP_LEFTBRACE }; + inline static constexpr u32 KpRightbrace { SDLK_KP_RIGHTBRACE }; + inline static constexpr u32 KpTab { SDLK_KP_TAB }; + inline static constexpr u32 KpBackspace { SDLK_KP_BACKSPACE }; + inline static constexpr u32 KpA { SDLK_KP_A }; + inline static constexpr u32 KpB { SDLK_KP_B }; + inline static constexpr u32 KpC { SDLK_KP_C }; + inline static constexpr u32 KpD { SDLK_KP_D }; + inline static constexpr u32 KpE { SDLK_KP_E }; + inline static constexpr u32 KpF { SDLK_KP_F }; + inline static constexpr u32 KpXor { SDLK_KP_XOR }; + inline static constexpr u32 KpPower { SDLK_KP_POWER }; + inline static constexpr u32 KpPercent { SDLK_KP_PERCENT }; + inline static constexpr u32 KpLess { SDLK_KP_LESS }; + inline static constexpr u32 KpGreater { SDLK_KP_GREATER }; + inline static constexpr u32 KpAmpersand { SDLK_KP_AMPERSAND }; + inline static constexpr u32 KpDblampersand { SDLK_KP_DBLAMPERSAND }; + inline static constexpr u32 KpVerticalbar { SDLK_KP_VERTICALBAR }; + inline static constexpr u32 KpDblverticalbar { SDLK_KP_DBLVERTICALBAR }; + inline static constexpr u32 KpColon { SDLK_KP_COLON }; + inline static constexpr u32 KpHash { SDLK_KP_HASH }; + inline static constexpr u32 KpSpace { SDLK_KP_SPACE }; + inline static constexpr u32 KpAt { SDLK_KP_AT }; + inline static constexpr u32 KpExclam { SDLK_KP_EXCLAM }; + inline static constexpr u32 KpMemstore { SDLK_KP_MEMSTORE }; + inline static constexpr u32 KpMemrecall { SDLK_KP_MEMRECALL }; + inline static constexpr u32 KpMemclear { SDLK_KP_MEMCLEAR }; + inline static constexpr u32 KpMemadd { SDLK_KP_MEMADD }; + inline static constexpr u32 KpMemsubtract { SDLK_KP_MEMSUBTRACT }; + inline static constexpr u32 KpMemmultiply { SDLK_KP_MEMMULTIPLY }; + inline static constexpr u32 KpMemdivide { SDLK_KP_MEMDIVIDE }; + inline static constexpr u32 KpPlusminus { SDLK_KP_PLUSMINUS }; + inline static constexpr u32 KpClear { SDLK_KP_CLEAR }; + inline static constexpr u32 KpClearentry { SDLK_KP_CLEARENTRY }; + inline static constexpr u32 KpBinary { SDLK_KP_BINARY }; + inline static constexpr u32 KpOctal { SDLK_KP_OCTAL }; + inline static constexpr u32 KpDecimal { SDLK_KP_DECIMAL }; + inline static constexpr u32 KpHexadecimal { SDLK_KP_HEXADECIMAL }; + inline static constexpr u32 Lctrl { SDLK_LCTRL }; + inline static constexpr u32 Lshift { SDLK_LSHIFT }; + inline static constexpr u32 Lalt { SDLK_LALT }; + inline static constexpr u32 Lgui { SDLK_LGUI }; + inline static constexpr u32 Rctrl { SDLK_RCTRL }; + inline static constexpr u32 Rshift { SDLK_RSHIFT }; + inline static constexpr u32 Ralt { SDLK_RALT }; + inline static constexpr u32 Rgui { SDLK_RGUI }; + inline static constexpr u32 Mode { SDLK_MODE }; + inline static constexpr u32 Sleep { SDLK_SLEEP }; + inline static constexpr u32 Wake { SDLK_WAKE }; + inline static constexpr u32 ChannelIncrement { SDLK_CHANNEL_INCREMENT }; + inline static constexpr u32 ChannelDecrement { SDLK_CHANNEL_DECREMENT }; + inline static constexpr u32 MediaPlay { SDLK_MEDIA_PLAY }; + inline static constexpr u32 MediaPause { SDLK_MEDIA_PAUSE }; + inline static constexpr u32 MediaRecord { SDLK_MEDIA_RECORD }; + inline static constexpr u32 MediaFastForward { SDLK_MEDIA_FAST_FORWARD }; + inline static constexpr u32 MediaRewind { SDLK_MEDIA_REWIND }; + inline static constexpr u32 MediaNextTrack { SDLK_MEDIA_NEXT_TRACK }; + inline static constexpr u32 MediaPreviousTrack { SDLK_MEDIA_PREVIOUS_TRACK }; + inline static constexpr u32 MediaStop { SDLK_MEDIA_STOP }; + inline static constexpr u32 MediaEject { SDLK_MEDIA_EJECT }; + inline static constexpr u32 MediaPlayPause { SDLK_MEDIA_PLAY_PAUSE }; + inline static constexpr u32 MediaSelect { SDLK_MEDIA_SELECT }; + inline static constexpr u32 AcNew { SDLK_AC_NEW }; + inline static constexpr u32 AcOpen { SDLK_AC_OPEN }; + inline static constexpr u32 AcClose { SDLK_AC_CLOSE }; + inline static constexpr u32 AcExit { SDLK_AC_EXIT }; + inline static constexpr u32 AcSave { SDLK_AC_SAVE }; + inline static constexpr u32 AcPrint { SDLK_AC_PRINT }; + inline static constexpr u32 AcProperties { SDLK_AC_PROPERTIES }; + inline static constexpr u32 AcSearch { SDLK_AC_SEARCH }; + inline static constexpr u32 AcHome { SDLK_AC_HOME }; + inline static constexpr u32 AcBack { SDLK_AC_BACK }; + inline static constexpr u32 AcForward { SDLK_AC_FORWARD }; + inline static constexpr u32 AcStop { SDLK_AC_STOP }; + inline static constexpr u32 AcRefresh { SDLK_AC_REFRESH }; + inline static constexpr u32 AcBookmarks { SDLK_AC_BOOKMARKS }; + inline static constexpr u32 Softleft { SDLK_SOFTLEFT }; + inline static constexpr u32 Softright { SDLK_SOFTRIGHT }; + inline static constexpr u32 Call { SDLK_CALL }; + inline static constexpr u32 Endcall { SDLK_ENDCALL }; + inline static constexpr u32 LeftTab { SDLK_LEFT_TAB }; + inline static constexpr u32 Level5Shift { SDLK_LEVEL5_SHIFT }; + inline static constexpr u32 MultiKeyCompose { SDLK_MULTI_KEY_COMPOSE }; + inline static constexpr u32 Lmeta { SDLK_LMETA }; + inline static constexpr u32 Rmeta { SDLK_RMETA }; + inline static constexpr u32 Lhyper { SDLK_LHYPER }; + inline static constexpr u32 Rhyper { SDLK_RHYPER }; }; } diff --git a/src/ogfx/utils/SDLInclude.hpp b/src/ogfx/utils/SDLInclude.hpp index 4a959b8..533c045 100644 --- a/src/ogfx/utils/SDLInclude.hpp +++ b/src/ogfx/utils/SDLInclude.hpp @@ -74,11 +74,11 @@ namespace ogfx } private: - inline static int s_refCount { 0 }; + inline static i32 s_refCount { 0 }; public: - inline static constexpr int32_t ErrorSDLInitFailed { 1 }; - inline static constexpr int32_t ErrorSDLTTFInitFailed { 2 }; + inline static constexpr i32 ErrorSDLInitFailed { 1 }; + inline static constexpr i32 ErrorSDLTTFInitFailed { 2 }; }; } diff --git a/src/ostd/data/BaseObject.cpp b/src/ostd/data/BaseObject.cpp index 66be66e..3db6805 100755 --- a/src/ostd/data/BaseObject.cpp +++ b/src/ostd/data/BaseObject.cpp @@ -41,7 +41,7 @@ namespace ostd return getTypeName().add("->uid=").add(getID()).add("/oid=").add(getCompareOID()).add("/valid=").add(STR_BOOL(isValid())); } - void BaseObject::connectSignal(uint32_t signal_id) + void BaseObject::connectSignal(u32 signal_id) { SignalHandler::connect(*this, signal_id); } diff --git a/src/ostd/data/BaseObject.hpp b/src/ostd/data/BaseObject.hpp index b32cc16..231fa4a 100755 --- a/src/ostd/data/BaseObject.hpp +++ b/src/ostd/data/BaseObject.hpp @@ -37,8 +37,8 @@ namespace ostd virtual BaseObject& operator=(const BaseObject& copy); inline void setSignalCallback(SignalCallback callback) { callback_signal = callback; } - virtual inline uint64_t getID(void) const { return m_uid; } - virtual inline void setID(uint64_t id) { m_uid = id; } + virtual inline u64 getID(void) const { return m_uid; } + virtual inline void setID(u64 id) { m_uid = id; } virtual inline bool isValid(void) const { return !isInvalid(); } virtual inline bool isInvalid(void) const { return !m_valid || m_oid == 0; } @@ -46,7 +46,7 @@ namespace ostd virtual inline void validate(void) { m_valid = true; } virtual inline void setValid(bool valid) { m_valid = valid; } - inline uint64_t getCompareOID(void) const { return m_oid; } + inline u64 getCompareOID(void) const { return m_oid; } inline bool compareByOID(const BaseObject& other) const { return m_oid == other.m_oid; } inline static BaseObject& InvalidRef(void) { return BaseObject::s_invalid_obj; } @@ -62,7 +62,7 @@ namespace ostd virtual void print(bool newLine = true, OutputHandlerBase* __destination = nullptr) const; virtual inline void handleSignal(Signal& signal) { } - void connectSignal(uint32_t signal_id); + void connectSignal(u32 signal_id); void __handle_signal(Signal& signal); @@ -72,14 +72,14 @@ namespace ostd inline BaseObject(bool __valid) { m_uid = -1; m_valid = __valid; m_oid = 0; } private: - uint64_t m_uid; - uint64_t m_oid; + u64 m_uid; + u64 m_oid; bool m_valid; String m_typeName; bool m_signalsEnabled { true }; SignalCallback callback_signal { nullptr }; - inline static uint64_t s_next_oid { 1024 }; + inline static u64 s_next_oid { 1024 }; static BaseObject s_invalid_obj; }; } diff --git a/src/ostd/data/Bitfields.hpp b/src/ostd/data/Bitfields.hpp index d7eb3b9..4027174 100755 --- a/src/ostd/data/Bitfields.hpp +++ b/src/ostd/data/Bitfields.hpp @@ -1,39 +1,40 @@ /* - OmniaFramework - A collection of useful functionality - Copyright (C) 2025 OmniaX-Dev + OmniaFramework - A collection of useful functionality + Copyright (C) 2025 OmniaX-Dev - This file is part of OmniaFramework. + This file is part of OmniaFramework. - OmniaFramework is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + OmniaFramework is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - OmniaFramework is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + OmniaFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with OmniaFramework. If not, see . + You should have received a copy of the GNU General Public License + along with OmniaFramework. If not, see . */ #pragma once #include #include +#include -#define get_bit(__bit_field, __bit_n ) __bit_field.bits.b##__bit_n -#define set_bit(__bit_field, __bit_n ) __bit_field.bits.b##__bit_n = true -#define clr_bit(__bit_field, __bit_n ) __bit_field.bits.b##__bit_n = false -#define tgl_bit(__bit_field, __bit_n ) __bit_field.bits.b##__bit_n = !__bit_field.bits.b##__bit_n -#define val_bit(__bit_field, __bit_n, __val ) __bit_field.bits.b##__bit_n = __val +#define get_bit(__bit_field, __bit_n ) __bit_field.bits.b##__bit_n +#define set_bit(__bit_field, __bit_n ) __bit_field.bits.b##__bit_n = true +#define clr_bit(__bit_field, __bit_n ) __bit_field.bits.b##__bit_n = false +#define tgl_bit(__bit_field, __bit_n ) __bit_field.bits.b##__bit_n = !__bit_field.bits.b##__bit_n +#define val_bit(__bit_field, __bit_n, __val ) __bit_field.bits.b##__bit_n = __val namespace ostd { union BitField_8 { - uint8_t value = 0; + u8 value = 0; struct { bool b0 : 1; bool b1 : 1; @@ -47,7 +48,7 @@ namespace ostd }; union BitField_16 { - uint16_t value = 0; + u16 value = 0; struct { bool b0 : 1; bool b1 : 1; @@ -69,7 +70,7 @@ namespace ostd }; union BitField_32 { - uint32_t value = 0; + u32 value = 0; struct { bool b0 : 1; bool b1 : 1; @@ -107,7 +108,7 @@ namespace ostd }; union BitField_64 { - uint64_t value = 0; + u64 value = 0; struct { bool b0 : 1; bool b1 : 1; @@ -180,7 +181,7 @@ namespace ostd { public: //8-Bit field - static inline bool get(const BitField_8& bf, const uint8_t& bit) + static inline bool get(const BitField_8& bf, const u8& bit) { switch (bit) { @@ -195,7 +196,7 @@ namespace ostd default: return false; } } - static inline void set(BitField_8& bf, const uint8_t& bit) + static inline void set(BitField_8& bf, const u8& bit) { switch (bit) { @@ -210,7 +211,7 @@ namespace ostd default: break; } } - static inline void clr(BitField_8& bf, const uint8_t& bit) + static inline void clr(BitField_8& bf, const u8& bit) { switch (bit) { @@ -225,7 +226,7 @@ namespace ostd default: break; } } - static inline void tgl(BitField_8& bf, const uint8_t& bit) + static inline void tgl(BitField_8& bf, const u8& bit) { switch (bit) { @@ -240,7 +241,7 @@ namespace ostd default: break; } } - static inline void val(BitField_8& bf, const uint8_t& bit, bool value) + static inline void val(BitField_8& bf, const u8& bit, bool value) { switch (bit) { @@ -257,7 +258,7 @@ namespace ostd } //16-Bit field - static inline bool get(const BitField_16& bf, const uint8_t& bit) + static inline bool get(const BitField_16& bf, const u8& bit) { switch (bit) { @@ -280,7 +281,7 @@ namespace ostd default: return false; } } - static inline void set(BitField_16& bf, const uint8_t& bit) + static inline void set(BitField_16& bf, const u8& bit) { switch (bit) { @@ -303,7 +304,7 @@ namespace ostd default: break; } } - static inline void clr(BitField_16& bf, const uint8_t& bit) + static inline void clr(BitField_16& bf, const u8& bit) { switch (bit) { @@ -326,7 +327,7 @@ namespace ostd default: break; } } - static inline void tgl(BitField_16& bf, const uint8_t& bit) + static inline void tgl(BitField_16& bf, const u8& bit) { switch (bit) { @@ -349,7 +350,7 @@ namespace ostd default: break; } } - static inline void val(BitField_16& bf, const uint8_t& bit, bool value) + static inline void val(BitField_16& bf, const u8& bit, bool value) { switch (bit) { @@ -374,7 +375,7 @@ namespace ostd } //32-Bit field - static inline bool get(const BitField_32& bf, const uint8_t& bit) + static inline bool get(const BitField_32& bf, const u8& bit) { switch (bit) { @@ -413,7 +414,7 @@ namespace ostd default: return false; } } - static inline void set(BitField_32& bf, const uint8_t& bit) + static inline void set(BitField_32& bf, const u8& bit) { switch (bit) { @@ -452,7 +453,7 @@ namespace ostd default: break; } } - static inline void clr(BitField_32& bf, const uint8_t& bit) + static inline void clr(BitField_32& bf, const u8& bit) { switch (bit) { @@ -491,7 +492,7 @@ namespace ostd default: break; } } - static inline void tgl(BitField_32& bf, const uint8_t& bit) + static inline void tgl(BitField_32& bf, const u8& bit) { switch (bit) { @@ -530,7 +531,7 @@ namespace ostd default: break; } } - static inline void val(BitField_32& bf, const uint8_t& bit, bool value) + static inline void val(BitField_32& bf, const u8& bit, bool value) { switch (bit) { @@ -571,7 +572,7 @@ namespace ostd } //64-Bit field - static inline bool get(const BitField_64& bf, const uint8_t& bit) + static inline bool get(const BitField_64& bf, const u8& bit) { switch (bit) { @@ -642,7 +643,7 @@ namespace ostd default: return false; } } - static inline void set(BitField_64& bf, const uint8_t& bit) + static inline void set(BitField_64& bf, const u8& bit) { switch (bit) { @@ -713,7 +714,7 @@ namespace ostd default: break; } } - static inline void clr(BitField_64& bf, const uint8_t& bit) + static inline void clr(BitField_64& bf, const u8& bit) { switch (bit) { @@ -784,7 +785,7 @@ namespace ostd default: break; } } - static inline void tgl(BitField_64& bf, const uint8_t& bit) + static inline void tgl(BitField_64& bf, const u8& bit) { switch (bit) { @@ -855,7 +856,7 @@ namespace ostd default: break; } } - static inline void val(BitField_64& bf, const uint8_t& bit, bool value) + static inline void val(BitField_64& bf, const u8& bit, bool value) { switch (bit) { diff --git a/src/ostd/data/Color.cpp b/src/ostd/data/Color.cpp index a34a7fa..7c9ba51 100755 --- a/src/ostd/data/Color.cpp +++ b/src/ostd/data/Color.cpp @@ -12,14 +12,14 @@ namespace ostd BaseObject::setValid(true); } - Color::Color(uint8_t rgb_single_value, uint8_t alpha) : r(*this), g(*this), b(*this), a(*this) + Color::Color(u8 rgb_single_value, u8 alpha) : r(*this), g(*this), b(*this), a(*this) { set(rgb_single_value, alpha); setTypeName("ox::Color"); BaseObject::setValid(true); } - Color::Color(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t alpha) : r(*this), g(*this), b(*this), a(*this) + Color::Color(u8 _r, u8 _g, u8 _b, u8 alpha) : r(*this), g(*this), b(*this), a(*this) { set(_r, _g, _b, alpha); setTypeName("ox::Color"); @@ -42,10 +42,10 @@ namespace ostd Color::Color(const Color& copy) : BaseObject(copy), r(*this), g(*this), b(*this), a(*this) { - r = static_cast(copy.r); - g = static_cast(copy.g); - b = static_cast(copy.b); - a = static_cast(copy.a); + r = cast(copy.r); + g = cast(copy.g); + b = cast(copy.b); + a = cast(copy.a); } bool Color::operator==(const Color& col2) @@ -61,10 +61,10 @@ namespace ostd Color& Color::operator=(const Color& copy) { BaseObject::operator=(copy); - r = static_cast(copy.r); - g = static_cast(copy.g); - b = static_cast(copy.b); - a = static_cast(copy.a); + r = cast(copy.r); + g = cast(copy.g); + b = cast(copy.b); + a = cast(copy.a); return *this; } @@ -77,7 +77,7 @@ namespace ostd return *this; } - Color& Color::set(uint8_t rgb_single_value, uint8_t alpha) + Color& Color::set(u8 rgb_single_value, u8 alpha) { r = rgb_single_value; g = rgb_single_value; @@ -86,7 +86,7 @@ namespace ostd return *this; } - Color& Color::set(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t alpha) + Color& Color::set(u8 _r, u8 _g, u8 _b, u8 alpha) { r = _r; g = _g; @@ -111,12 +111,12 @@ namespace ostd } if (se.startsWith("0x")) { - int64_t ic = se.toInt(); + i64 ic = se.toInt(); union uC32 { - uint8_t data[4]; - uint32_t value; + u8 data[4]; + u32 value; } c32_u; - c32_u.value = static_cast(ic); + c32_u.value = cast(ic); a = c32_u.data[0]; b = c32_u.data[1]; g = c32_u.data[2]; @@ -147,14 +147,14 @@ namespace ostd Color& Color::set(const FloatCol& normalized_color) { - r = static_cast(std::round(normalized_color.r * 255)); - g = static_cast(std::round(normalized_color.g * 255)); - b = static_cast(std::round(normalized_color.b * 255)); - a = static_cast(std::round(normalized_color.a * 255)); + r = cast(std::round(normalized_color.r * 255)); + g = cast(std::round(normalized_color.g * 255)); + b = cast(std::round(normalized_color.b * 255)); + a = cast(std::round(normalized_color.a * 255)); return *this; } - String Color::hexString(bool include_alpha, String prefix) const + String Color::hexString(bool include_alpha, const String& prefix) const { String hex = ""; hex += String::getHexStr(r, false, 1); @@ -181,11 +181,11 @@ namespace ostd return rgb; } - uint32_t Color::asInteger(eColorFormat format) const + u32 Color::asInteger(eColorFormat format) const { union uC32 { - uint8_t data[4]; - uint32_t value; + u8 data[4]; + u32 value; } c32_u; if (format == eColorFormat::RGBA) { @@ -235,11 +235,11 @@ namespace ostd } } - void Color::RGBtoHSV(float r, float g, float b, float& h, float& s, float& v) + void Color::RGBtoHSV(f32 r, f32 g, f32 b, f32& h, f32& s, f32& v) { - float max = std::max({r, g, b}); - float min = std::min({r, g, b}); - float d = max - min; + f32 max = std::max({r, g, b}); + f32 min = std::min({r, g, b}); + f32 d = max - min; v = max; @@ -259,13 +259,13 @@ namespace ostd h /= 6.0f; } - void Color::HSVtoRGB(float h, float s, float v, float& r, float& g, float& b) + void Color::HSVtoRGB(f32 h, f32 s, f32 v, f32& r, f32& g, f32& b) { - int i = static_cast(h * 6); - float f = h * 6 - i; - float p = v * (1 - s); - float q = v * (1 - f * s); - float t = v * (1 - (1 - f) * s); + i32 i = cast(h * 6); + f32 f = h * 6 - i; + f32 p = v * (1 - s); + f32 q = v * (1 - f * s); + f32 t = v * (1 - (1 - f) * s); switch (i % 6) { diff --git a/src/ostd/data/Color.hpp b/src/ostd/data/Color.hpp index 8ba44f8..2553893 100755 --- a/src/ostd/data/Color.hpp +++ b/src/ostd/data/Color.hpp @@ -1,26 +1,25 @@ /* - OmniaFramework - A collection of useful functionality - Copyright (C) 2025 OmniaX-Dev + OmniaFramework - A collection of useful functionality + Copyright (C) 2025 OmniaX-Dev - This file is part of OmniaFramework. + This file is part of OmniaFramework. - OmniaFramework is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + OmniaFramework is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - OmniaFramework is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + OmniaFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with OmniaFramework. If not, see . + You should have received a copy of the GNU General Public License + along with OmniaFramework. If not, see . */ #pragma once -#include #include #include #include @@ -31,26 +30,26 @@ namespace ostd { public: struct FloatCol { - float r; - float g; - float b; - float a; + f32 r; + f32 g; + f32 b; + f32 a; FloatCol(void) : r(0.0f), g(0.0f), b(0.0f), a(1.0f) { } - FloatCol(float _r, float _g, float _b, float _a) : r(_r), g(_g), b(_b), a(_a) { } + FloatCol(f32 _r, f32 _g, f32 _b, f32 _a) : r(_r), g(_g), b(_b), a(_a) { } }; public: struct Channel { - uint8_t value; + u8 value; Color& parent; inline Channel(Color& _parent) : parent(_parent) { value = 0; } - inline operator uint8_t() const { return value; } - inline Channel& operator=(uint8_t v) + inline operator u8() const { return value; } + inline Channel& operator=(u8 v) { - value = v; - parent.m_dirty = true; - return *this; + value = v; + parent.m_dirty = true; + return *this; } }; @@ -58,8 +57,8 @@ namespace ostd public: Color(void); - Color(uint8_t rgb_single_value, uint8_t alpha = 255); - Color(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t alpha = 255); + Color(u8 rgb_single_value, u8 alpha = 255); + Color(u8 _r, u8 _g, u8 _b, u8 alpha = 255); Color(const String& color_string); Color(const FloatCol& normalized_color); Color(const Color& copy); @@ -69,14 +68,14 @@ namespace ostd Color& operator=(const Color& copy); Color& set(void); - Color& set(uint8_t rgb_single_value, uint8_t alpha = 255); - Color& set(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t alpha = 255); + Color& set(u8 rgb_single_value, u8 alpha = 255); + Color& set(u8 _r, u8 _g, u8 _b, u8 alpha = 255); Color& set(const String& color_string); Color& set(const FloatCol& normalized_color); - String hexString(bool include_alpha = false, String prefix = "0x") const; + String hexString(bool include_alpha = false, const String& prefix = "0x") const; String rgbString(bool include_parenthesis = true, bool include_alpha = false) const; - uint32_t asInteger(eColorFormat format = eColorFormat::RGBA) const; + u32 asInteger(eColorFormat format = eColorFormat::RGBA) const; FloatCol getNormalizedColor(void) const; String toString(void) const override; @@ -84,8 +83,8 @@ namespace ostd inline void invalidate(void) override { } inline void setValid(bool valid) override { } - static void RGBtoHSV(float r, float g, float b, float& h, float& s, float& v); - static void HSVtoRGB(float h, float s, float v, float& r, float& g, float& b); + static void RGBtoHSV(f32 r, f32 g, f32 b, f32& h, f32& s, f32& v); + static void HSVtoRGB(f32 h, f32 s, f32 v, f32& r, f32& g, f32& b); public: Channel r; @@ -95,7 +94,7 @@ namespace ostd private: mutable bool m_dirty { true }; - mutable FloatCol m_cachedFloat { 0, 0, 0, 0 }; + mutable FloatCol m_cachedFloat { 0, 0, 0, 0 }; public: }; diff --git a/src/ostd/data/Types.hpp b/src/ostd/data/Types.hpp index 589878c..d73d4a6 100755 --- a/src/ostd/data/Types.hpp +++ b/src/ostd/data/Types.hpp @@ -1,21 +1,21 @@ /* - OmniaFramework - A collection of useful functionality - Copyright (C) 2025 OmniaX-Dev + OmniaFramework - A collection of useful functionality + Copyright (C) 2025 OmniaX-Dev - This file is part of OmniaFramework. + This file is part of OmniaFramework. - OmniaFramework is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + OmniaFramework is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - OmniaFramework is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + OmniaFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with OmniaFramework. If not, see . + You should have received a copy of the GNU General Public License + along with OmniaFramework. If not, see . */ #pragma once @@ -23,45 +23,67 @@ #include #include #include +#include #include +typedef int8_t i8; +typedef int16_t i16; +typedef int32_t i32; +typedef int64_t i64; +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; +typedef i8 b8; +typedef float f32; +typedef double f64; +typedef unsigned char uchar; + +template +using stdvec = std::vector; +template +using stdumap = std::unordered_map; + +#define cast static_cast + namespace ostd { typedef std::string cpp_string; - typedef int64_t QWord; - typedef int32_t DWord; - typedef int16_t Word; - typedef int8_t Byte; + typedef i64 QWord; + typedef i32 DWord; + typedef i16 Word; + typedef i8 Byte; + + typedef u64 UQWord; + typedef u32 UDWord; + typedef u16 UWord; + typedef u8 UByte; - typedef uint64_t UQWord; - typedef uint32_t UDWord; - typedef uint16_t UWord; - typedef uint8_t UByte; typedef uint32_t StreamIndex; typedef union { - float val; - Byte data[4]; - int32_t raw; + f32 val; + i8 data[4]; + i32 raw; } __float_parser; typedef union { - double val; - Byte data[8]; - int64_t raw; + f64 val; + i8 data[8]; + i64 raw; } __double_parser; struct tTypeSize { - static inline const uint8_t BYTE = 1; - static inline const uint8_t WORD = 2; - static inline const uint8_t DWORD = 4; - static inline const uint8_t QWORD = 8; - static inline const uint8_t ADDR = 4; - static inline const uint8_t FLOAT = 4; - static inline const uint8_t DOUBLE = 8; + static inline const u8 BYTE = 1; + static inline const u8 WORD = 2; + static inline const u8 DWORD = 4; + static inline const u8 QWORD = 8; + static inline const u8 ADDR = 4; + static inline const u8 FLOAT = 4; + static inline const u8 DOUBLE = 8; }; - typedef std::vector ByteStream; + typedef stdvec ByteStream; } diff --git a/src/ostd/io/Console.cpp b/src/ostd/io/Console.cpp index 10e460c..35f5bc0 100644 --- a/src/ostd/io/Console.cpp +++ b/src/ostd/io/Console.cpp @@ -31,7 +31,7 @@ void BasicConsole::clearConsole(void) SetConsoleCursorPosition( hStdOut, homeCoords ); } -void BasicConsole::getConsoleSize(int32_t& outColumns, int32_t& outRows) +void BasicConsole::getConsoleSize(i32& outColumns, i32& outRows) { CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); @@ -39,7 +39,7 @@ void BasicConsole::getConsoleSize(int32_t& outColumns, int32_t& outRows) outRows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; } -void BasicConsole::setConsoleCursorPosition(int32_t x, int32_t y) +void BasicConsole::setConsoleCursorPosition(i32 x, i32 y) { COORD coord; coord.X = x; coord.Y = y; @@ -63,7 +63,7 @@ void BasicConsole::clearConsole(void) { if (!cur_term) { - int result; + i32 result; setupterm(NULL, STDOUT_FILENO, &result); if (result <= 0) return; } @@ -71,7 +71,7 @@ void BasicConsole::clearConsole(void) putp(tigetstr( "clear" )); } -void BasicConsole::getConsoleSize(int32_t& outColumns, int32_t& outRows) +void BasicConsole::getConsoleSize(i32& outColumns, i32& outRows) { struct winsize w; ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); @@ -79,7 +79,7 @@ void BasicConsole::getConsoleSize(int32_t& outColumns, int32_t& outRows) outColumns = w.ws_col; } -void BasicConsole::setConsoleCursorPosition(int32_t x, int32_t y) +void BasicConsole::setConsoleCursorPosition(i32 x, i32 y) { printf("\033[%d;%dH",y+1,x+1); } @@ -100,7 +100,7 @@ IPoint BasicConsole::getConsoleCursorPosition(void) std::fflush(stdout); // Read response: ESC [ row ; col R - int row = 0, col = 0; + i32 row = 0, col = 0; if (std::scanf("\033[%d;%dR", &row, &col) != 2) { // Failed to parse row = col = -1; @@ -126,7 +126,7 @@ void BasicConsole::clearConsole(void) std::fflush(stdout); } -void BasicConsole::getConsoleSize(int32_t& outColumns, int32_t& outRows) +void BasicConsole::getConsoleSize(i32& outColumns, i32& outRows) { struct winsize w; ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); @@ -134,7 +134,7 @@ void BasicConsole::getConsoleSize(int32_t& outColumns, int32_t& outRows) outColumns = w.ws_col; } -void BasicConsole::setConsoleCursorPosition(int32_t x, int32_t y) +void BasicConsole::setConsoleCursorPosition(i32 x, i32 y) { // ANSI escape sequence: move cursor to (y+1, x+1) std::printf("\033[%d;%dH", y + 1, x + 1); @@ -157,7 +157,7 @@ IPoint BasicConsole::getConsoleCursorPosition(void) std::fflush(stdout); // Read response: ESC [ row ; col R - int row = 0, col = 0; + i32 row = 0, col = 0; if (std::scanf("\033[%d;%dR", &row, &col) != 2) { // Failed to parse row = col = -1; @@ -173,16 +173,16 @@ IPoint BasicConsole::getConsoleCursorPosition(void) #endif -int32_t BasicConsole::getConsoleWidth(void) +i32 BasicConsole::getConsoleWidth(void) { - int32_t rows = 0, cols = 0; + i32 rows = 0, cols = 0; getConsoleSize(cols, rows); return cols; } -int32_t BasicConsole::getConsoleHeight(void) +i32 BasicConsole::getConsoleHeight(void) { - int32_t rows = 0, cols = 0; + i32 rows = 0, cols = 0; getConsoleSize(rows, cols); return rows; } @@ -263,55 +263,55 @@ OutputHandlerBase& InteractiveConsole::p(const String& se) return *this; } -OutputHandlerBase& InteractiveConsole::p(uint8_t i) +OutputHandlerBase& InteractiveConsole::p(u8 i) { - std::cout << (uint8_t)i; + std::cout << (u8)i; return *this; } -OutputHandlerBase& InteractiveConsole::p(int8_t i) +OutputHandlerBase& InteractiveConsole::p(i8 i) { - std::cout << (int8_t)i; + std::cout << (i8)i; return *this; } -OutputHandlerBase& InteractiveConsole::p(uint16_t i) +OutputHandlerBase& InteractiveConsole::p(u16 i) { - std::cout << (uint16_t)i; + std::cout << (u16)i; return *this; } -OutputHandlerBase& InteractiveConsole::p(int16_t i) +OutputHandlerBase& InteractiveConsole::p(i16 i) { - std::cout << (int16_t)i; + std::cout << (i16)i; return *this; } -OutputHandlerBase& InteractiveConsole::p(uint32_t i) +OutputHandlerBase& InteractiveConsole::p(u32 i) { - std::cout << (uint32_t)i; + std::cout << (u32)i; return *this; } -OutputHandlerBase& InteractiveConsole::p(int32_t i) +OutputHandlerBase& InteractiveConsole::p(i32 i) { - std::cout << (int32_t)i; + std::cout << (i32)i; return *this; } -OutputHandlerBase& InteractiveConsole::p(uint64_t i) +OutputHandlerBase& InteractiveConsole::p(u64 i) { - std::cout << (uint64_t)i; + std::cout << (u64)i; return *this; } -OutputHandlerBase& InteractiveConsole::p(int64_t i) +OutputHandlerBase& InteractiveConsole::p(i64 i) { - std::cout << (int64_t)i; + std::cout << (i64)i; return *this; } -OutputHandlerBase& InteractiveConsole::p(float f, uint8_t precision) +OutputHandlerBase& InteractiveConsole::p(f32 f, u8 precision) { if (precision == 0) { @@ -326,7 +326,7 @@ OutputHandlerBase& InteractiveConsole::p(float f, uint8_t precision) return *this; } -OutputHandlerBase& InteractiveConsole::p(double f, uint8_t precision) +OutputHandlerBase& InteractiveConsole::p(f64 f, u8 precision) { if (precision == 0) { @@ -365,14 +365,14 @@ OutputHandlerBase& InteractiveConsole::clear(void) return *this; } -void InteractiveConsole::getConsoleSize(int32_t& outColumns, int32_t& outRows) +void InteractiveConsole::getConsoleSize(i32& outColumns, i32& outRows) { BasicConsole::getConsoleSize(outColumns, outRows); } IPoint InteractiveConsole::getConsoleSize(void) { - int32_t x = 0, y = 0; + i32 x = 0, y = 0; BasicConsole::getConsoleSize(x, y); return { x, y }; } @@ -397,7 +397,7 @@ void InteractiveConsole::__construct_buffer(void) return; } m_oldConsoleSize = console_size; - int32_t linear_size = m_oldConsoleSize.x * m_oldConsoleSize.y; + i32 linear_size = m_oldConsoleSize.x * m_oldConsoleSize.y; m_buffer.resize(linear_size); m_secondBuffer.resize(linear_size); m_validBuffer = false; @@ -414,7 +414,7 @@ void InteractiveConsole::__swap_buffers(void) void InteractiveConsole::__validate_and_clear_buffers(void) { if (m_validBuffer) return; - for (int32_t i = 0; i < m_buffer.size(); i++) + for (i32 i = 0; i < m_buffer.size(); i++) m_buffer[i] = m_secondBuffer[i] = m_emptyChar; m_validBuffer = true; } diff --git a/src/ostd/io/Console.hpp b/src/ostd/io/Console.hpp index 676802f..a65e344 100644 --- a/src/ostd/io/Console.hpp +++ b/src/ostd/io/Console.hpp @@ -30,7 +30,6 @@ #else #include #endif -#include namespace ostd { @@ -38,11 +37,11 @@ namespace ostd { public: static void clearConsole(void); - static void getConsoleSize(int32_t& outColumns, int32_t& outRows); - static void setConsoleCursorPosition(int32_t x, int32_t y); + static void getConsoleSize(i32& outColumns, i32& outRows); + static void setConsoleCursorPosition(i32 x, i32 y); static IPoint getConsoleCursorPosition(void); - static int32_t getConsoleWidth(void); - static int32_t getConsoleHeight(void); + static i32 getConsoleWidth(void); + static i32 getConsoleHeight(void); }; class InteractiveConsole : public OutputHandlerBase @@ -69,16 +68,16 @@ namespace ostd OutputHandlerBase& pObject(const BaseObject& bo) override; OutputHandlerBase& p(const String& se) override; - OutputHandlerBase& p(uint8_t i) override; - OutputHandlerBase& p(int8_t i) override; - OutputHandlerBase& p(uint16_t i) override; - OutputHandlerBase& p(int16_t i) override; - OutputHandlerBase& p(uint32_t i) override; - OutputHandlerBase& p(int32_t i) override; - OutputHandlerBase& p(uint64_t i) override; - OutputHandlerBase& p(int64_t i) override; - OutputHandlerBase& p(float f, uint8_t precision = 0) override; - OutputHandlerBase& p(double f, uint8_t precision = 0) override; + OutputHandlerBase& p(u8 i) override; + OutputHandlerBase& p(i8 i) override; + OutputHandlerBase& p(u16 i) override; + OutputHandlerBase& p(i16 i) override; + OutputHandlerBase& p(u32 i) override; + OutputHandlerBase& p(i32 i) override; + OutputHandlerBase& p(u64 i) override; + OutputHandlerBase& p(i64 i) override; + OutputHandlerBase& p(f32 f, u8 precision = 0) override; + OutputHandlerBase& p(f64 f, u8 precision = 0) override; OutputHandlerBase& nl(void) override; OutputHandlerBase& flush(void) override; @@ -86,17 +85,17 @@ namespace ostd OutputHandlerBase& clear(void) override; inline OutputHandlerBase& xy(IPoint position) override { m_cursorPosition = position; __set_cursor(); return *this; } - inline OutputHandlerBase& xy(int32_t x, int32_t y) override { m_cursorPosition = { x, y }; __set_cursor(); return *this; } - inline OutputHandlerBase& x(int32_t x) override { m_cursorPosition.x = x; __set_cursor(); return *this; } - inline OutputHandlerBase& y(int32_t y) override { m_cursorPosition.y = y; __set_cursor(); return *this; } + inline OutputHandlerBase& xy(i32 x, i32 y) override { m_cursorPosition = { x, y }; __set_cursor(); return *this; } + inline OutputHandlerBase& x(i32 x) override { m_cursorPosition.x = x; __set_cursor(); return *this; } + inline OutputHandlerBase& y(i32 y) override { m_cursorPosition.y = y; __set_cursor(); return *this; } - void getConsoleSize(int32_t& outColumns, int32_t& outRows) override; + void getConsoleSize(i32& outColumns, i32& outRows) override; IPoint getConsoleSize(void) override; inline IPoint getCursorPosition(void) override { return m_cursorPosition; } - inline void getCursorPosition(int32_t& outX, int32_t& outY) override { outX = m_cursorPosition.x; outY = m_cursorPosition.y; } - inline int32_t getCursorX(void) override { return m_cursorPosition.x; } - inline int32_t getCursorY(void) override { return m_cursorPosition.y; } + inline void getCursorPosition(i32& outX, i32& outY) override { outX = m_cursorPosition.x; outY = m_cursorPosition.y; } + inline i32 getCursorX(void) override { return m_cursorPosition.x; } + inline i32 getCursorY(void) override { return m_cursorPosition.y; } //InteractiveConsole inline void enableDirectMode(void) { m_mode = eMode::Direct; } @@ -117,8 +116,8 @@ namespace ostd IPoint m_cursorPosition { 0, 0 }; IPoint m_oldConsoleSize { 0, 0 }; eMode m_mode { eMode::Direct }; - std::vector m_buffer; - std::vector m_secondBuffer; + stdvec m_buffer; + stdvec m_secondBuffer; bool m_validBuffer { false }; tRichChar m_emptyChar { @@ -202,17 +201,17 @@ namespace ostd String flushKeyBuffer(void); #ifndef WINDOWS_OS - int kbhit(void); - int getch(void); + i32 kbhit(void); + i32 getch(void); #endif private: #ifndef WINDOWS_OS struct termios initial_settings, new_settings; - int peek_character; + i32 peek_character; #endif - std::vector m_key_buff; + stdvec m_key_buff; String m_cmd; bool m_output_enabled; bool m_cmd_buffer_enabled; diff --git a/src/ostd/io/Errors.cpp b/src/ostd/io/Errors.cpp index 8e73e85..65b321b 100755 --- a/src/ostd/io/Errors.cpp +++ b/src/ostd/io/Errors.cpp @@ -4,7 +4,7 @@ namespace ostd { - RuntimeError& RuntimeError::create(uint8_t group, uint64_t code, uint8_t level, const String &msg) + RuntimeError& RuntimeError::create(u8 group, u64 code, u8 level, const String &msg) { m_errGroup = group; m_errCode = code; @@ -15,7 +15,7 @@ namespace ostd return *this; } - void RuntimeError::fire(const String& extraMessage, OutputHandlerBase* outputHandler, BaseObject& userData, int32_t _line_num, const String& _file_name) + void RuntimeError::fire(const String& extraMessage, OutputHandlerBase* outputHandler, BaseObject& userData, i32 _line_num, const String& _file_name) { if (isInvalid() || m_errGroup == 0x0 || m_errLevel == tErrorLevel::NoError || m_errCode == 0x0) return; String errorMessage = m_message + "\n"; diff --git a/src/ostd/io/Errors.hpp b/src/ostd/io/Errors.hpp index 90a6e06..633960b 100755 --- a/src/ostd/io/Errors.hpp +++ b/src/ostd/io/Errors.hpp @@ -29,25 +29,25 @@ namespace ostd { struct tErrorLevel { - inline static constexpr uint8_t NoError = 0x00; - inline static constexpr uint8_t Warning = 0x01; - inline static constexpr uint8_t Error = 0x02; - inline static constexpr uint8_t Fatal = 0x03; + inline static constexpr u8 NoError = 0x00; + inline static constexpr u8 Warning = 0x01; + inline static constexpr u8 Error = 0x02; + inline static constexpr u8 Fatal = 0x03; }; class RuntimeError : public BaseObject { public: inline RuntimeError(void) { invalidate(); } - inline RuntimeError(uint8_t group, uint64_t code, uint8_t level, const String& msg) { create(group, code, level, msg); } - RuntimeError& create(uint8_t group, uint64_t code, uint8_t level, const String& msg); + inline RuntimeError(u8 group, u64 code, u8 level, const String& msg) { create(group, code, level, msg); } + RuntimeError& create(u8 group, u64 code, u8 level, const String& msg); - void fire(const String& extraMessage = "", OutputHandlerBase* outputHandler = nullptr, BaseObject& userData = BaseObject::InvalidRef(), int32_t _line_num = 0, const String& _file_name = ""); + void fire(const String& extraMessage = "", OutputHandlerBase* outputHandler = nullptr, BaseObject& userData = BaseObject::InvalidRef(), i32 _line_num = 0, const String& _file_name = ""); private: - uint8_t m_errGroup { 0x00 }; - uint8_t m_errLevel { tErrorLevel::NoError }; - uint64_t m_errCode { 0x0000000000000000 }; + u8 m_errGroup { 0x00 }; + u8 m_errLevel { tErrorLevel::NoError }; + u64 m_errCode { 0x0000000000000000 }; String m_message { "" }; }; diff --git a/src/ostd/io/File.cpp b/src/ostd/io/File.cpp index b006c24..332ad7c 100755 --- a/src/ostd/io/File.cpp +++ b/src/ostd/io/File.cpp @@ -38,7 +38,7 @@ namespace ostd return *this; } - std::vector TextFileBuffer::getLines(const String& separator, bool trim_tokens, bool allow_white_space_only_tokens) + stdvec TextFileBuffer::getLines(const String& separator, bool trim_tokens, bool allow_white_space_only_tokens) { if (!exists()) return { }; auto st = String(m_buffer); diff --git a/src/ostd/io/File.hpp b/src/ostd/io/File.hpp index ca6c347..a4896b7 100755 --- a/src/ostd/io/File.hpp +++ b/src/ostd/io/File.hpp @@ -21,7 +21,7 @@ #pragma once #include -#include + #include #include @@ -42,7 +42,7 @@ namespace ostd inline const String& name(void) const { return m_name; } inline const String& rawContent(void) { return m_buffer; } - std::vector getLines(const String& separator = "\n", bool trim_tokens = true, bool allow_white_space_only_tokens = false); + stdvec getLines(const String& separator = "\n", bool trim_tokens = true, bool allow_white_space_only_tokens = false); inline bool exists(void) { return isValid(); } diff --git a/src/ostd/io/FileSystem.cpp b/src/ostd/io/FileSystem.cpp index 5018dd3..25155ac 100644 --- a/src/ostd/io/FileSystem.cpp +++ b/src/ostd/io/FileSystem.cpp @@ -5,9 +5,9 @@ namespace ostd { - std::vector FileSystem::listFilesInDirectory(const String& directoryPath) + stdvec FileSystem::listFilesInDirectory(const String& directoryPath) { - std::vector list; + stdvec list; for (const auto& file : std::filesystem::directory_iterator(directoryPath.cpp_str())) { if (!std::filesystem::is_directory(file.path())) @@ -16,9 +16,9 @@ namespace ostd return list; } - std::vector FileSystem::listDirectoriesInDirectory(const String& directoryPath) + stdvec FileSystem::listDirectoriesInDirectory(const String& directoryPath) { - std::vector list; + stdvec list; for (const auto& file : std::filesystem::directory_iterator(directoryPath.cpp_str())) { if (std::filesystem::is_directory(file.path())) @@ -27,17 +27,17 @@ namespace ostd return list; } - std::vector FileSystem::listDirectory(const String& directoryPath) + stdvec FileSystem::listDirectory(const String& directoryPath) { - std::vector list; + stdvec list; for (const auto& file : std::filesystem::directory_iterator(directoryPath.cpp_str())) list.push_back(file.path()); return list; } - std::vector FileSystem::listFilesInDirectoryRecursive(const String& directoryPath) + stdvec FileSystem::listFilesInDirectoryRecursive(const String& directoryPath) { - std::vector list; + stdvec list; for (const auto& file : std::filesystem::recursive_directory_iterator(directoryPath.cpp_str())) { if (!std::filesystem::is_directory(file.path())) @@ -46,9 +46,9 @@ namespace ostd return list; } - std::vector FileSystem::listDirectoriesInDirectoryRecursive(const String& directoryPath) + stdvec FileSystem::listDirectoriesInDirectoryRecursive(const String& directoryPath) { - std::vector list; + stdvec list; for (const auto& file : std::filesystem::recursive_directory_iterator(directoryPath.cpp_str())) { if (std::filesystem::is_directory(file.path())) @@ -57,9 +57,9 @@ namespace ostd return list; } - std::vector FileSystem::listDirectoryRecursive(const String& directoryPath) + stdvec FileSystem::listDirectoryRecursive(const String& directoryPath) { - std::vector list; + stdvec list; for (const auto& file : std::filesystem::recursive_directory_iterator(directoryPath.cpp_str())) list.push_back(file.path()); return list; @@ -245,7 +245,7 @@ namespace ostd } } - bool FileSystem::isValidFileCreationPath(const ostd::String& filePath) + bool FileSystem::isValidFileCreationPath(const String& filePath) { namespace fs = std::filesystem; try @@ -268,7 +268,7 @@ namespace ostd } } - bool FileSystem::isValidDirectoryCreationPath(const ostd::String& directoryPath) + bool FileSystem::isValidDirectoryCreationPath(const String& directoryPath) { namespace fs = std::filesystem; try { @@ -290,7 +290,7 @@ namespace ostd } } - FileSystem::ePathStatus FileSystem::getPathStatus(const ostd::String& path) + FileSystem::ePathStatus FileSystem::getPathStatus(const String& path) { if (directoryExists(path)) return ePathStatus::ExistingDirectory; @@ -302,7 +302,7 @@ namespace ostd } - bool FileSystem::readTextFile(String fileName, std::vector& outLines) + bool FileSystem::readTextFile(const String& fileName, stdvec& outLines) { String line; std::ifstream file(fileName.cpp_str()); @@ -313,9 +313,9 @@ namespace ostd return true; } - bool FileSystem::readTextFileRaw(String fileName, String& outString) + bool FileSystem::readTextFileRaw(const String& fileName, String& outString) { - std::vector lines; + stdvec lines; if (!readTextFile(fileName, lines)) return false; outString.clr(); @@ -324,7 +324,7 @@ namespace ostd return true; } - bool FileSystem::writeTextFile(const ostd::String& filePath, const std::vector& lines, bool truncate) + bool FileSystem::writeTextFile(const String& filePath, const stdvec& lines, bool truncate) { namespace fs = std::filesystem; ePathStatus status = getPathStatus(filePath); @@ -356,18 +356,18 @@ namespace ostd } - bool FileSystem::writeTextFileRaw(const ostd::String& filePath, const ostd::String& lines, bool truncate) + bool FileSystem::writeTextFileRaw(const String& filePath, const String& lines, bool truncate) { auto _lines = lines.tokenize("\n", false, true).getRawData(); return writeTextFile(filePath, _lines, truncate); } - bool FileSystem::loadFileFromHppResource(String output_file_path, const char* resource_buffer, unsigned int size) + bool FileSystem::loadFileFromHppResource(const String& output_file_path, const char* resource_buffer, u32 size) { - unsigned char ext_len = resource_buffer[0]; + uchar ext_len = resource_buffer[0]; String ext = ""; - for (unsigned char i = 0; i < ext_len; i++) + for (uchar i = 0; i < ext_len; i++) ext += (char)(resource_buffer[i + 1]); if (String(output_file_path).trim().toLower().endsWith(ext)) ext = ""; diff --git a/src/ostd/io/FileSystem.hpp b/src/ostd/io/FileSystem.hpp index df7dd0b..53c3c8d 100644 --- a/src/ostd/io/FileSystem.hpp +++ b/src/ostd/io/FileSystem.hpp @@ -20,7 +20,7 @@ #pragma once -#include + #include #include @@ -31,12 +31,12 @@ namespace ostd public: enum class ePathStatus { Invalid = 0, ExistingDirectory, ExistingFile, ValidNewPath }; public: - static std::vector listFilesInDirectory(const String& directoryPath); - static std::vector listDirectoriesInDirectory(const String& directoryPath); - static std::vector listDirectory(const String& directoryPath); - static std::vector listFilesInDirectoryRecursive(const String& directoryPath); - static std::vector listDirectoriesInDirectoryRecursive(const String& directoryPath); - static std::vector listDirectoryRecursive(const String& directoryPath); + static stdvec listFilesInDirectory(const String& directoryPath); + static stdvec listDirectoriesInDirectory(const String& directoryPath); + static stdvec listDirectory(const String& directoryPath); + static stdvec listFilesInDirectoryRecursive(const String& directoryPath); + static stdvec listDirectoriesInDirectoryRecursive(const String& directoryPath); + static stdvec listDirectoryRecursive(const String& directoryPath); static std::filesystem::path getHomeDirPath(void); static std::filesystem::path getWorkingDirPath(void); @@ -49,15 +49,15 @@ namespace ostd static bool directoryExists(const String& directoryPath); static bool fileExists(const String& filePath); static bool pathExists(const String& path); - static bool isValidFileCreationPath(const ostd::String& filePath); - static bool isValidDirectoryCreationPath(const ostd::String& directoryPath); - static ePathStatus getPathStatus(const ostd::String& path); + static bool isValidFileCreationPath(const String& filePath); + static bool isValidDirectoryCreationPath(const String& directoryPath); + static ePathStatus getPathStatus(const String& path); - static bool readTextFile(String fileName, std::vector& outLines); - static bool readTextFileRaw(String fileName, String& outString); - static bool writeTextFile(const ostd::String& filePath, const std::vector& lines, bool truncate = true); - static bool writeTextFileRaw(const ostd::String& filePath, const ostd::String& lines, bool truncate = true); + static bool readTextFile(const String& fileName, stdvec& outLines); + static bool readTextFileRaw(const String& fileName, String& outString); + static bool writeTextFile(const String& filePath, const stdvec& lines, bool truncate = true); + static bool writeTextFileRaw(const String& filePath, const String& lines, bool truncate = true); - static bool loadFileFromHppResource(String output_file_path, const char* resource_buffer, unsigned int size); + static bool loadFileFromHppResource(const String& output_file_path, const char* resource_buffer, u32 size); }; } diff --git a/src/ostd/io/IOHandlers.hpp b/src/ostd/io/IOHandlers.hpp index baf9a4b..4eeba36 100644 --- a/src/ostd/io/IOHandlers.hpp +++ b/src/ostd/io/IOHandlers.hpp @@ -150,16 +150,16 @@ namespace ostd inline virtual OutputHandlerBase& pObject(const BaseObject& bo) { return *this; } inline virtual OutputHandlerBase& p(const String& se) { return *this; } - inline virtual OutputHandlerBase& p(uint8_t i) { return *this; } - inline virtual OutputHandlerBase& p(int8_t i) { return *this; } - inline virtual OutputHandlerBase& p(uint16_t i) { return *this; } - inline virtual OutputHandlerBase& p(int16_t i) { return *this; } - inline virtual OutputHandlerBase& p(uint32_t i) { return *this; } - inline virtual OutputHandlerBase& p(int32_t i) { return *this; } - inline virtual OutputHandlerBase& p(uint64_t i) { return *this; } - inline virtual OutputHandlerBase& p(int64_t i) { return *this; } - inline virtual OutputHandlerBase& p(float f, uint8_t precision = 0) { return *this; } - inline virtual OutputHandlerBase& p(double f, uint8_t precision = 0) { return *this; } + inline virtual OutputHandlerBase& p(u8 i) { return *this; } + inline virtual OutputHandlerBase& p(i8 i) { return *this; } + inline virtual OutputHandlerBase& p(u16 i) { return *this; } + inline virtual OutputHandlerBase& p(i16 i) { return *this; } + inline virtual OutputHandlerBase& p(u32 i) { return *this; } + inline virtual OutputHandlerBase& p(i32 i) { return *this; } + inline virtual OutputHandlerBase& p(u64 i) { return *this; } + inline virtual OutputHandlerBase& p(i64 i) { return *this; } + inline virtual OutputHandlerBase& p(f32 f, u8 precision = 0) { return *this; } + inline virtual OutputHandlerBase& p(f64 f, u8 precision = 0) { return *this; } inline virtual OutputHandlerBase& nl(void) { return *this; } inline virtual OutputHandlerBase& tab(void) { return *this; } @@ -168,16 +168,16 @@ namespace ostd inline virtual OutputHandlerBase& clear(void) { return *this; } inline virtual OutputHandlerBase& xy(IPoint position) { return *this; } - inline virtual OutputHandlerBase& xy(int32_t x, int32_t y) { return *this; } - inline virtual OutputHandlerBase& x(int32_t x) { return *this; } - inline virtual OutputHandlerBase& y(int32_t y) { return *this; } + inline virtual OutputHandlerBase& xy(i32 x, i32 y) { return *this; } + inline virtual OutputHandlerBase& x(i32 x) { return *this; } + inline virtual OutputHandlerBase& y(i32 y) { return *this; } inline virtual IPoint getCursorPosition(void) { return { 0, 0 }; } - inline virtual void getCursorPosition(int32_t& outX, int32_t& outY) { } - inline virtual int32_t getCursorX(void) { return 0; } - inline virtual int32_t getCursorY(void) { return 0; } + inline virtual void getCursorPosition(i32& outX, i32& outY) { } + inline virtual i32 getCursorX(void) { return 0; } + inline virtual i32 getCursorY(void) { return 0; } - inline virtual void getConsoleSize(int32_t& outColumns, int32_t& outRows) { } + inline virtual void getConsoleSize(i32& outColumns, i32& outRows) { } inline virtual IPoint getConsoleSize(void) { return { 0, 0 }; } }; @@ -198,16 +198,16 @@ namespace ostd OutputHandlerBase& pObject(const BaseObject& bo) override; OutputHandlerBase& p(const String& se) override; - OutputHandlerBase& p(uint8_t i) override; - OutputHandlerBase& p(int8_t i) override; - OutputHandlerBase& p(uint16_t i) override; - OutputHandlerBase& p(int16_t i) override; - OutputHandlerBase& p(uint32_t i) override; - OutputHandlerBase& p(int32_t i) override; - OutputHandlerBase& p(uint64_t i) override; - OutputHandlerBase& p(int64_t i) override; - OutputHandlerBase& p(float f, uint8_t precision = 0) override; - OutputHandlerBase& p(double f, uint8_t precision = 0) override; + OutputHandlerBase& p(u8 i) override; + OutputHandlerBase& p(i8 i) override; + OutputHandlerBase& p(u16 i) override; + OutputHandlerBase& p(i16 i) override; + OutputHandlerBase& p(u32 i) override; + OutputHandlerBase& p(i32 i) override; + OutputHandlerBase& p(u64 i) override; + OutputHandlerBase& p(i64 i) override; + OutputHandlerBase& p(f32 f, u8 precision = 0) override; + OutputHandlerBase& p(f64 f, u8 precision = 0) override; OutputHandlerBase& nl(void) override; OutputHandlerBase& flush(void) override; @@ -215,16 +215,16 @@ namespace ostd OutputHandlerBase& clear(void) override; OutputHandlerBase& xy(IPoint position) override; - OutputHandlerBase& xy(int32_t x, int32_t y) override; - OutputHandlerBase& x(int32_t x) override; - OutputHandlerBase& y(int32_t y) override; + OutputHandlerBase& xy(i32 x, i32 y) override; + OutputHandlerBase& x(i32 x) override; + OutputHandlerBase& y(i32 y) override; IPoint getCursorPosition(void) override; - void getCursorPosition(int32_t& outX, int32_t& outY) override; - int32_t getCursorX(void) override; - int32_t getCursorY(void) override; + void getCursorPosition(i32& outX, i32& outY) override; + i32 getCursorX(void) override; + i32 getCursorY(void) override; - void getConsoleSize(int32_t& outColumns, int32_t& outRows) override; + void getConsoleSize(i32& outColumns, i32& outRows) override; IPoint getConsoleSize(void) override; }; } diff --git a/src/ostd/io/Json.cpp b/src/ostd/io/Json.cpp index 122cc83..09ecd34 100644 --- a/src/ostd/io/Json.cpp +++ b/src/ostd/io/Json.cpp @@ -19,31 +19,31 @@ namespace ostd catch (const json::exception&) { return false; } } }; - // ----- int ---------------------------------------------------------- - template<> struct Getter + // ----- i32 ---------------------------------------------------------- + template<> struct Getter { - static int exec_impl(const std::string& p, const json& root) + static i32 exec_impl(const std::string& p, const json& root) { - try { return root.at(p).get(); } + try { return root.at(p).get(); } catch (const json::exception&) { return 0; } } }; - // ----- double ------------------------------------------------------- - template<> struct Getter + // ----- f64 ------------------------------------------------------- + template<> struct Getter { - static double exec_impl(const std::string& p, const json& root) + static f64 exec_impl(const std::string& p, const json& root) { - try { return root.at(p).get(); } + try { return root.at(p).get(); } catch (const json::exception&) { return 0.0; } } }; - // ----- ostd::String ------------------------------------------------- - template<> struct Getter + // ----- String ------------------------------------------------- + template<> struct Getter { - static ostd::String exec_impl(const std::string& p, const json& root) + static String exec_impl(const std::string& p, const json& root) { - try { return ostd::String(root.at(p).get().c_str()); } - catch (const json::exception&) { return ostd::String(""); } + try { return String(root.at(p).get().c_str()); } + catch (const json::exception&) { return String(""); } } }; // ----- ostd::Color ------------------------------------------------- @@ -66,11 +66,11 @@ namespace ostd // Case 2: Array of integers if (node.is_array() && !node.empty()) { - std::vector vals; + stdvec vals; for (const auto& v : node) { if (!v.is_number_integer()) return ostd::Color(); - int iv = v.get(); + i32 iv = v.get(); if (iv < 0 || iv > 255) return ostd::Color(); vals.push_back(iv); } @@ -100,13 +100,13 @@ namespace ostd const json& node = root.at(p); if (node.is_array() && node.size() == 4) { - std::vector vals; + stdvec vals; vals.reserve(4); for (const auto& v : node) { if (!v.is_number_float() && !v.is_number_integer()) return ostd::Rectangle(); - vals.push_back(v.get()); + vals.push_back(v.get()); } return ostd::Rectangle(vals[0], vals[1], vals[2], vals[3]); } @@ -118,12 +118,12 @@ namespace ostd } } }; - // ----- std::vector ---------------------------------------- - template<> struct Getter> + // ----- stdvec ---------------------------------------- + template<> struct Getter> { - static std::vector exec_impl(const std::string& p, const json& root) + static stdvec exec_impl(const std::string& p, const json& root) { - std::vector result; + stdvec result; try { const json& arr = root.at(p); @@ -131,18 +131,18 @@ namespace ostd for (const auto& v : arr) { if (v.is_number_integer()) - result.push_back(v.get()); + result.push_back(v.get()); } } catch (...) {} return result; } }; - // ----- std::vector ----------------------------------------- - template<> struct Getter> + // ----- stdvec ----------------------------------------- + template<> struct Getter> { - static std::vector exec_impl(const std::string& p, const json& root) + static stdvec exec_impl(const std::string& p, const json& root) { - std::vector result; + stdvec result; try { const json& arr = root.at(p); @@ -150,18 +150,18 @@ namespace ostd for (const auto& v : arr) { if (v.is_number()) - result.push_back(v.get()); + result.push_back(v.get()); } } catch (...) {} return result; } }; - // ----- std::vector ----------------------------------- - template<> struct Getter> + // ----- stdvec ----------------------------------- + template<> struct Getter> { - static std::vector exec_impl(const std::string& p, const json& root) + static stdvec exec_impl(const std::string& p, const json& root) { - std::vector result; + stdvec result; try { const json& arr = root.at(p); @@ -175,12 +175,12 @@ namespace ostd return result; } }; - // ----- std::vector ----------------------------------- - template<> struct Getter> + // ----- stdvec ----------------------------------- + template<> struct Getter> { - static std::vector exec_impl(const std::string& p, const json& root) + static stdvec exec_impl(const std::string& p, const json& root) { - std::vector result; + stdvec result; try { const json& node = root.at(p); @@ -203,7 +203,7 @@ namespace ostd } } }; - // ----- std::vector ----------------------------------- + // ----- stdvec ----------------------------------- template<> struct Getter { static ostd::Vec2 exec_impl(const std::string& p, const json& root) @@ -213,7 +213,7 @@ namespace ostd const json& arr = root.at(p); if (!arr.is_array() || arr.size() != 2) return ostd::Vec2(); - return ostd::Vec2(arr[0].get(), arr[1].get()); + return ostd::Vec2(arr[0].get(), arr[1].get()); } catch (...) { @@ -221,12 +221,12 @@ namespace ostd } } }; - // ----- std::vector ----------------------------------- - template<> struct Getter> + // ----- stdvec ----------------------------------- + template<> struct Getter> { - static std::vector exec_impl(const std::string& p, const json& root) + static stdvec exec_impl(const std::string& p, const json& root) { - std::vector result; + stdvec result; try { const json& node = root.at(p); @@ -269,10 +269,10 @@ namespace ostd } }; - // ----- int ---------------------------------------------------------- - template<> struct Setter + // ----- i32 ---------------------------------------------------------- + template<> struct Setter { - static bool exec_impl(const std::string& p, json& root, int value) + static bool exec_impl(const std::string& p, json& root, i32 value) { try { @@ -283,10 +283,10 @@ namespace ostd } }; - // ----- double ------------------------------------------------------- - template<> struct Setter + // ----- f64 ------------------------------------------------------- + template<> struct Setter { - static bool exec_impl(const std::string& p, json& root, double value) + static bool exec_impl(const std::string& p, json& root, f64 value) { try { @@ -297,10 +297,10 @@ namespace ostd } }; - // ----- ostd::String ------------------------------------------------- - template<> struct Setter + // ----- String ------------------------------------------------- + template<> struct Setter { - static bool exec_impl(const std::string& p, json& root, const ostd::String& value) + static bool exec_impl(const std::string& p, json& root, const String& value) { try { @@ -318,16 +318,16 @@ namespace ostd try { json arr = json::array(); - arr.push_back(static_cast(value.r)); - arr.push_back(static_cast(value.g)); - arr.push_back(static_cast(value.b)); - if (value.a != 255) arr.push_back(static_cast(value.a)); + arr.push_back(cast(value.r)); + arr.push_back(cast(value.g)); + arr.push_back(cast(value.b)); + if (value.a != 255) arr.push_back(cast(value.a)); root[p] = arr; return true; } catch (...) { return false; } } }; - // ----- std::vector ----------------------------------- + // ----- stdvec ----------------------------------- template<> struct Setter { static bool exec_impl(const std::string& p, json& root, const ostd::Vec2& value) @@ -367,38 +367,38 @@ namespace ostd } } }; - // ----- std::vector ---------------------------------------- - template<> struct Setter> + // ----- stdvec ---------------------------------------- + template<> struct Setter> { - static bool exec_impl(const std::string& p, json& root, const std::vector& value) + static bool exec_impl(const std::string& p, json& root, const stdvec& value) { try { json arr = json::array(); - for (int32_t v : value) arr.push_back(v); + for (i32 v : value) arr.push_back(v); root[p] = arr; return true; } catch (...) { return false; } } }; - // ----- std::vector ----------------------------------------- - template<> struct Setter> + // ----- stdvec ----------------------------------------- + template<> struct Setter> { - static bool exec_impl(const std::string& p, json& root, const std::vector& value) + static bool exec_impl(const std::string& p, json& root, const stdvec& value) { try { json arr = json::array(); - for (double v : value) arr.push_back(v); + for (f64 v : value) arr.push_back(v); root[p] = arr; return true; } catch (...) { return false; } } }; - // ----- std::vector ----------------------------------- - template<> struct Setter> + // ----- stdvec ----------------------------------- + template<> struct Setter> { - static bool exec_impl(const std::string& p, json& root, const std::vector& value) + static bool exec_impl(const std::string& p, json& root, const stdvec& value) { try { @@ -409,10 +409,10 @@ namespace ostd } catch (...) { return false; } } }; - // ----- std::vector ----------------------------------- - template<> struct Setter> + // ----- stdvec ----------------------------------- + template<> struct Setter> { - static bool exec_impl(const std::string& p, json& root, const std::vector& value) + static bool exec_impl(const std::string& p, json& root, const stdvec& value) { try { @@ -428,10 +428,10 @@ namespace ostd } } }; - // ----- std::vector ----------------------------------- - template<> struct Setter> + // ----- stdvec ----------------------------------- + template<> struct Setter> { - static bool exec_impl(const std::string& p, json& root, const std::vector& value) + static bool exec_impl(const std::string& p, json& root, const stdvec& value) { try { @@ -457,7 +457,7 @@ namespace ostd } - static inline bool __navigate_json_path(const ostd::String& path, json*& outSource, ostd::String& outName) + static inline bool __navigate_json_path(const String& path, json*& outSource, String& outName) { auto tokens = path.tokenize("."); if (tokens.count() <= 1) @@ -468,7 +468,7 @@ namespace ostd return true; } - ostd::String key = ""; + String key = ""; while (tokens.hasNext()) { key = tokens.next(); @@ -490,10 +490,10 @@ namespace ostd } template - T JsonFile::get(const ostd::String& name) + T JsonFile::get(const String& name) { json* source = &m_json; - ostd::String settingName = ""; + String settingName = ""; if (__navigate_json_path(name, source, settingName)) return detail::Getter::exec_impl(settingName, *source); else @@ -501,7 +501,7 @@ namespace ostd return detail::Getter::exec_impl(settingName, *source); } template - bool JsonFile::set(const ostd::String& name, T value) + bool JsonFile::set(const String& name, T value) { if (!m_loaded) return false; if (!m_writeable) return false; @@ -510,7 +510,7 @@ namespace ostd if (tokens.count() == 0) return false; json* current = &m_json; - ostd::String key; + String key; while (tokens.hasNext()) { @@ -530,34 +530,34 @@ namespace ostd return false; } - bool JsonFile::get_bool(const ostd::String& name) { return get(name); } - int JsonFile::get_int(const ostd::String& name) { return get(name); } - double JsonFile::get_double(const ostd::String& name) { return get(name); } - ostd::String JsonFile::get_string(const ostd::String& name) { return get(name); } - ostd::Color JsonFile::get_color(const ostd::String& name) { return get(name); } - ostd::Vec2 JsonFile::get_vec2(const ostd::String& name) { return get(name); } - ostd::Rectangle JsonFile::get_rect(const ostd::String& name) { return get(name); } - std::vector JsonFile::get_int_array(const ostd::String& name) { return get>(name); } - std::vector JsonFile::get_double_array(const ostd::String& name) { return get>(name); } - std::vector JsonFile::get_string_array(const ostd::String& name) { return get>(name); } - std::vector JsonFile::get_color_array(const ostd::String& name) { return get>(name); } - std::vector JsonFile::get_rect_array(const ostd::String& name) { return get>(name); } + bool JsonFile::get_bool(const String& name) { return get(name); } + i32 JsonFile::get_int(const String& name) { return get(name); } + f64 JsonFile::get_double(const String& name) { return get(name); } + String JsonFile::get_string(const String& name) { return get(name); } + ostd::Color JsonFile::get_color(const String& name) { return get(name); } + ostd::Vec2 JsonFile::get_vec2(const String& name) { return get(name); } + ostd::Rectangle JsonFile::get_rect(const String& name) { return get(name); } + stdvec JsonFile::get_int_array(const String& name) { return get>(name); } + stdvec JsonFile::get_double_array(const String& name) { return get>(name); } + stdvec JsonFile::get_string_array(const String& name) { return get>(name); } + stdvec JsonFile::get_color_array(const String& name) { return get>(name); } + stdvec JsonFile::get_rect_array(const String& name) { return get>(name); } - bool JsonFile::set_bool(const ostd::String& name, bool value) { return set(name, value); } - bool JsonFile::set_int(const ostd::String& name, int32_t value) { return set(name, value); } - bool JsonFile::set_double(const ostd::String& name, double value) { return set(name, value); } - bool JsonFile::set_string(const ostd::String& name, const ostd::String& value) { return set(name, value); } - bool JsonFile::set_color(const ostd::String& name, const ostd::Color& value) { return set(name, value); } - bool JsonFile::set_vec2(const ostd::String& name, const ostd::Vec2& value) { return set(name, value); } - bool JsonFile::set_rect(const ostd::String& name, const ostd::Rectangle& value) { return set(name, value); } - bool JsonFile::set_int_array(const ostd::String& name, const std::vector& value) { return set>(name, value); } - bool JsonFile::set_double_array(const ostd::String& name, const std::vector& value) { return set>(name, value); } - bool JsonFile::set_string_array(const ostd::String& name, const std::vector& value) { return set>(name, value); } - bool JsonFile::set_color_array(const ostd::String& name, const std::vector& value) { return set>(name, value); } - bool JsonFile::set_rect_array(const ostd::String& name, const std::vector& value) { return set>(name, value); } + bool JsonFile::set_bool(const String& name, bool value) { return set(name, value); } + bool JsonFile::set_int(const String& name, i32 value) { return set(name, value); } + bool JsonFile::set_double(const String& name, f64 value) { return set(name, value); } + bool JsonFile::set_string(const String& name, const String& value) { return set(name, value); } + bool JsonFile::set_color(const String& name, const ostd::Color& value) { return set(name, value); } + bool JsonFile::set_vec2(const String& name, const ostd::Vec2& value) { return set(name, value); } + bool JsonFile::set_rect(const String& name, const ostd::Rectangle& value) { return set(name, value); } + bool JsonFile::set_int_array(const String& name, const stdvec& value) { return set>(name, value); } + bool JsonFile::set_double_array(const String& name, const stdvec& value) { return set>(name, value); } + bool JsonFile::set_string_array(const String& name, const stdvec& value) { return set>(name, value); } + bool JsonFile::set_color_array(const String& name, const stdvec& value) { return set>(name, value); } + bool JsonFile::set_rect_array(const String& name, const stdvec& value) { return set>(name, value); } - bool JsonFile::init(const ostd::String& filePath, bool writeable, const json* obj) + bool JsonFile::init(const String& filePath, bool writeable, const json* obj) { m_filePath = filePath; m_rawJson = ""; diff --git a/src/ostd/io/Json.hpp b/src/ostd/io/Json.hpp index 1bf2fea..59dae30 100644 --- a/src/ostd/io/Json.hpp +++ b/src/ostd/io/Json.hpp @@ -33,52 +33,52 @@ namespace ostd { public: inline JsonFile(void) { m_loaded = false; } - inline JsonFile(const ostd::String& filePath) { init(filePath); } - bool init(const ostd::String& filePath, bool writeable = true, const json* obj = nullptr); + inline JsonFile(const String& filePath) { init(filePath); } + bool init(const String& filePath, bool writeable = true, const json* obj = nullptr); inline bool isLoaded(void) const { return m_loaded; } - template T get(const ostd::String& name); - template bool set(const ostd::String& name, T value); + template T get(const String& name); + template bool set(const String& name, T value); // --- GETTERS --- - bool get_bool(const ostd::String& name); - int32_t get_int(const ostd::String& name); - double get_double(const ostd::String& name); - ostd::String get_string(const ostd::String& name); - ostd::Color get_color(const ostd::String& name); - ostd::Vec2 get_vec2(const ostd::String& name); - ostd::Rectangle get_rect(const ostd::String& name); - std::vector get_int_array(const ostd::String& name); - std::vector get_double_array(const ostd::String& name); - std::vector get_string_array(const ostd::String& name); - std::vector get_color_array(const ostd::String& name); - std::vector get_rect_array(const ostd::String& name); + bool get_bool(const String& name); + i32 get_int(const String& name); + f64 get_double(const String& name); + String get_string(const String& name); + ostd::Color get_color(const String& name); + ostd::Vec2 get_vec2(const String& name); + ostd::Rectangle get_rect(const String& name); + stdvec get_int_array(const String& name); + stdvec get_double_array(const String& name); + stdvec get_string_array(const String& name); + stdvec get_color_array(const String& name); + stdvec get_rect_array(const String& name); // --- SETTERS --- - bool set_bool(const ostd::String& name, bool value); - bool set_int(const ostd::String& name, int32_t value); - bool set_double(const ostd::String& name, double value); - bool set_string(const ostd::String& name, const ostd::String& value); - bool set_color(const ostd::String& name, const ostd::Color& value); - bool set_vec2(const ostd::String& name, const ostd::Vec2& value); - bool set_rect(const ostd::String& name, const ostd::Rectangle& value); - bool set_int_array(const ostd::String& name, const std::vector& value); - bool set_double_array(const ostd::String& name, const std::vector& value); - bool set_string_array(const ostd::String& name, const std::vector& value); - bool set_color_array(const ostd::String& name, const std::vector& value); - bool set_rect_array(const ostd::String& name, const std::vector& value); + bool set_bool(const String& name, bool value); + bool set_int(const String& name, i32 value); + bool set_double(const String& name, f64 value); + bool set_string(const String& name, const String& value); + bool set_color(const String& name, const ostd::Color& value); + bool set_vec2(const String& name, const ostd::Vec2& value); + bool set_rect(const String& name, const ostd::Rectangle& value); + bool set_int_array(const String& name, const stdvec& value); + bool set_double_array(const String& name, const stdvec& value); + bool set_string_array(const String& name, const stdvec& value); + bool set_color_array(const String& name, const stdvec& value); + bool set_rect_array(const String& name, const stdvec& value); // --- WRAPPERS --- - inline float get_float(const ostd::String& name) { return static_cast(get_double(name)); } + inline f32 get_float(const String& name) { return cast(get_double(name)); } private: void __validate_settings(void); bool __write_to_file(const json* obj = nullptr); private: - ostd::String m_rawJson { "" }; - ostd::String m_filePath { "" }; + String m_rawJson { "" }; + String m_filePath { "" }; json m_json; bool m_loaded { false }; bool m_writeable { true }; diff --git a/src/ostd/io/Keyboard.cpp b/src/ostd/io/Keyboard.cpp index 5940820..fa871ff 100644 --- a/src/ostd/io/Keyboard.cpp +++ b/src/ostd/io/Keyboard.cpp @@ -32,10 +32,10 @@ namespace ostd } #ifndef WINDOWS_OS - int KeyboardController::kbhit(void) + i32 KeyboardController::kbhit(void) { - unsigned char ch; - int nread; + uchar ch; + i32 nread; if (peek_character != -1) return 1; new_settings.c_cc[VMIN] = 0; tcsetattr(0, TCSANOW, &new_settings); @@ -51,7 +51,7 @@ namespace ostd return 0; } - int KeyboardController::getch(void) + i32 KeyboardController::getch(void) { char ch; @@ -110,7 +110,7 @@ namespace ostd eKeys KeyboardController::getPressedKey(void) { - int k1 = 0, k2 = 0, k3 = 0; + i32 k1 = 0, k2 = 0, k3 = 0; eKeys key; if(kbhit()) { diff --git a/src/ostd/io/Logger.cpp b/src/ostd/io/Logger.cpp index eaa9cf5..925a3a2 100755 --- a/src/ostd/io/Logger.cpp +++ b/src/ostd/io/Logger.cpp @@ -7,7 +7,7 @@ namespace ostd { OutputHandlerBase* Logger::m_out = new ConsoleOutputHandler; - void Logger::__log_output(uint8_t log_level, String message, ...) + void Logger::__log_output(u8 log_level, String message, ...) { String level_str[6] = { "[ FATAL ]: ", "[ ERROR ]: ", "[ WARNING ]: ", "[ INFO ]: ", "[ DEBUG ]: ", "[ TRACE ]: " }; diff --git a/src/ostd/io/Logger.hpp b/src/ostd/io/Logger.hpp index 239b5e9..c085213 100755 --- a/src/ostd/io/Logger.hpp +++ b/src/ostd/io/Logger.hpp @@ -26,19 +26,19 @@ namespace ostd { struct tLogLevel { - inline static const uint8_t Fatal = 0; - inline static const uint8_t Error = 1; - inline static const uint8_t Warning = 2; - inline static const uint8_t Info = 3; - inline static const uint8_t Debug = 4; - inline static const uint8_t Trace = 5; + inline static const u8 Fatal = 0; + inline static const u8 Error = 1; + inline static const u8 Warning = 2; + inline static const u8 Info = 3; + inline static const u8 Debug = 4; + inline static const u8 Trace = 5; }; class OutputHandlerBase; class Logger { public: - static void __log_output(uint8_t log_level, String message, ...); + static void __log_output(u8 log_level, String message, ...); static void setOutputHandler(OutputHandlerBase& __destination); static void destroy(void); static inline OutputHandlerBase& getOutputHandler(void) { return *m_out; } diff --git a/src/ostd/io/Memory.cpp b/src/ostd/io/Memory.cpp index c11af87..40a81c0 100644 --- a/src/ostd/io/Memory.cpp +++ b/src/ostd/io/Memory.cpp @@ -23,7 +23,7 @@ namespace ostd { - void Memory::printByteStream(const ByteStream& data, StreamIndex start, uint8_t line_len, uint16_t n_rows, OutputHandlerBase& out, int32_t addrHighlight, uint32_t highlightRange, const String& title) + void Memory::printByteStream(const ByteStream& data, StreamIndex start, u8 line_len, u16 n_rows, OutputHandlerBase& out, i32 addrHighlight, u32 highlightRange, const String& title) { StreamIndex end = start + (n_rows * line_len); if (end > data.size()) end = data.size(); @@ -32,21 +32,21 @@ namespace ostd titleEdit = titleEdit.substr(0, 12); else if (titleEdit.len() < 12) { - int32_t diff = 12 - titleEdit.len(); - for (int32_t i = 0; i < diff; i++) + i32 diff = 12 - titleEdit.len(); + for (i32 i = 0; i < diff; i++) titleEdit.addChar(' '); } bool highlight = addrHighlight >= 0; - uint8_t i = 1; + u8 i = 1; ByteStream tmp; - uint16_t linew = 1 + 1 + 6 + 1 + 1 + 2 + ((2 + 2) * line_len) + 1 + 4; + u16 linew = 1 + 1 + 6 + 1 + 1 + 2 + ((2 + 2) * line_len) + 1 + 4; out.fg(ConsoleColors::BrightBlue).p(String::duplicateChar('=', linew)).nl(); if (line_len <= 0xFF) { out.fg(ConsoleColors::BrightBlue).p("|"); out.fg(ConsoleColors::BrightMagenta).p(titleEdit); out.fg(ConsoleColors::BrightBlue).p("| "); - for (int32_t i = 0; i < line_len; i++) + for (i32 i = 0; i < line_len; i++) out.fg(ConsoleColors::Green).p(String::getHexStr(i, false, 1)).p(" "); out.fg(ConsoleColors::BrightBlue).p("|").nl(); out.fg(ConsoleColors::BrightBlue).p(String::duplicateChar('=', linew)).nl(); @@ -57,7 +57,7 @@ namespace ostd for (StreamIndex addr = start; addr < end; addr++) { tmp.push_back(data[addr]); - if (highlight && (addr >= (uint32_t)addrHighlight && addr < (uint32_t)(addrHighlight + highlightRange))) + if (highlight && (addr >= (u32)addrHighlight && addr < (u32)(addrHighlight + highlightRange))) out.fg(ConsoleColors::Red); else if (data[addr] == 0) out.fg(ConsoleColors::BrightGray); @@ -102,7 +102,7 @@ namespace ostd { std::ifstream rf(filePath.cpp_str(), std::ios::out | std::ios::binary); if(!rf) return false; //TODO: Error - uint8_t cell = 0; + u8 cell = 0; while(rf.read((char*)&cell, sizeof(cell))) outStream.push_back(cell); if (outStream.size() == 0) return false; //TODO: Error @@ -113,14 +113,14 @@ namespace ostd { ByteStream bstream; for (auto& c : data) - bstream.push_back((int8_t)c); + bstream.push_back((i8)c); return bstream; } String Memory::byteStreamToString(const ByteStream& data) { String out_string = ""; - for (int64_t i = 0; i < data.size(); i++) + for (i64 i = 0; i < data.size(); i++) { if (data[i] == 0) break; out_string.addChar((char)data[i]); diff --git a/src/ostd/io/Memory.hpp b/src/ostd/io/Memory.hpp index 71d09a5..0393372 100644 --- a/src/ostd/io/Memory.hpp +++ b/src/ostd/io/Memory.hpp @@ -32,7 +32,7 @@ namespace ostd class Memory { public: - static void printByteStream(const ByteStream& data, StreamIndex start, uint8_t line_len, uint16_t n_rows, OutputHandlerBase& out, int32_t addrHighlight = -1, uint32_t highlightRange = 1, const String& title = ""); + static void printByteStream(const ByteStream& data, StreamIndex start, u8 line_len, u16 n_rows, OutputHandlerBase& out, i32 addrHighlight = -1, u32 highlightRange = 1, const String& title = ""); static bool saveByteStreamToFile(const ByteStream& stream, const String& filePath); static bool loadByteStreamFromFile(const String& filePath, ByteStream& outStream); static ByteStream stringToByteStream(const String& data); diff --git a/src/ostd/io/Midi.cpp b/src/ostd/io/Midi.cpp index 036f1ce..b3b8c69 100644 --- a/src/ostd/io/Midi.cpp +++ b/src/ostd/io/Midi.cpp @@ -1,5 +1,5 @@ #include "Midi.hpp" -#include + #include #include #include @@ -8,7 +8,7 @@ namespace ostd { //TODO: Errors - std::vector MidiParser::parseFile(const ostd::String& filePath) + stdvec MidiParser::parseFile(const String& filePath) { smf::MidiFile midi; @@ -23,10 +23,10 @@ namespace ostd midi.doTimeAnalysis(); midi.linkNotePairs(); - std::vector notes; + stdvec notes; notes.reserve(256); - for (int e = 0; e < midi[0].size(); ++e) + for (i32 e = 0; e < midi[0].size(); ++e) { auto& ev = midi[0][e]; if (ev.isNoteOn()) @@ -46,7 +46,7 @@ namespace ostd } NoteEvent* notePtr = nullptr; - double noteTime = 0.0; + f64 noteTime = 0.0; for (auto& note : notes) { if (note.endTime > noteTime) @@ -74,7 +74,7 @@ namespace ostd return notes; } - MidiParser::NoteInfo MidiParser::getNoteInfo(int midiPitch) + MidiParser::NoteInfo MidiParser::getNoteInfo(i32 midiPitch) { static const std::array noteNames = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; diff --git a/src/ostd/io/Midi.hpp b/src/ostd/io/Midi.hpp index 9ab5028..648a92b 100644 --- a/src/ostd/io/Midi.hpp +++ b/src/ostd/io/Midi.hpp @@ -29,12 +29,12 @@ namespace ostd public: class NoteEvent { public: - int32_t pitch { 0 }; // MIDI note number (0-127) - double startTime { 0.0 }; // Start time in seconds - double endTime { 0.0 }; // Start time in seconds - double duration { 0.0 }; // Duration in seconds - int32_t velocity { 0 }; // Attack velocity (1-127) - int32_t channel { 0 }; // MIDI channel (0-15) + i32 pitch { 0 }; // MIDI note number (0-127) + f64 startTime { 0.0 }; // Start time in seconds + f64 endTime { 0.0 }; // Start time in seconds + f64 duration { 0.0 }; // Duration in seconds + i32 velocity { 0 }; // Attack velocity (1-127) + i32 channel { 0 }; // MIDI channel (0-15) bool hit { false }; bool rightHand { false }; @@ -48,9 +48,9 @@ namespace ostd return pitch < other.pitch; return startTime < other.startTime; } - inline ostd::String toString(void) const + inline String toString(void) const { - ostd::String str = "Pitch: "; + String str = "Pitch: "; str.add(pitch); str.add("\nstartTime: ").add(startTime); str.add("\nendTime: ").add(endTime); @@ -64,10 +64,10 @@ namespace ostd public: class NoteInfo { public: - ostd::String name { "" }; // e.g., "A", "C#", "F" - int octave { 0 }; // e.g., 4 for C4 - int noteInOctave { 0 }; // 0-11 - int keyIndex { 0 }; // 0-based index for 88-key piano (A0=0), -1 if out of range + String name { "" }; // e.g., "A", "C#", "F" + i32 octave { 0 }; // e.g., 4 for C4 + i32 noteInOctave { 0 }; // 0-11 + i32 keyIndex { 0 }; // 0-based index for 88-key piano (A0=0), -1 if out of range public: inline bool isWhiteKey(void) const @@ -77,9 +77,9 @@ namespace ostd noteInOctave == 11; } inline bool isBlackKey(void) const { return !isWhiteKey(); } - inline ostd::String toString(void) const + inline String toString(void) const { - ostd::String str = "NOTE INFO: "; + String str = "NOTE INFO: "; str.add(name).add(octave); str.add(" - noteInOctave: ").add(noteInOctave); str.add(" - keyIndex: ").add(keyIndex); @@ -87,19 +87,19 @@ namespace ostd return str; } - static inline bool isWhiteKey(int32_t noteInOctave) + static inline bool isWhiteKey(i32 noteInOctave) { return noteInOctave == 0 || noteInOctave == 2 || noteInOctave == 4 || noteInOctave == 5 || noteInOctave == 7 || noteInOctave == 9 || noteInOctave == 11; } - static inline bool isBlackKey(int32_t noteInOctave) { return !NoteInfo::isWhiteKey(noteInOctave); } + static inline bool isBlackKey(i32 noteInOctave) { return !NoteInfo::isWhiteKey(noteInOctave); } }; public: // Parses a single-track MIDI file and returns a vector of NoteEvents - static std::vector parseFile(const ostd::String& filePath); + static stdvec parseFile(const String& filePath); // Convert MIDI pitch to NoteInfo - static NoteInfo getNoteInfo(int midiPitch); + static NoteInfo getNoteInfo(i32 midiPitch); }; } diff --git a/src/ostd/io/OutputHandlers.cpp b/src/ostd/io/OutputHandlers.cpp index 9495963..13485ff 100755 --- a/src/ostd/io/OutputHandlers.cpp +++ b/src/ostd/io/OutputHandlers.cpp @@ -55,7 +55,7 @@ namespace ostd OutputHandlerBase& ConsoleOutputHandler::bg(const Color& color) { - std::cout << "\033[48;2;" << (int)color.r << ";" << (int)color.g << ";" << (int)color.b << "m"; + std::cout << "\033[48;2;" << (i32)color.r << ";" << (i32)color.g << ";" << (i32)color.b << "m"; return *this; } @@ -73,7 +73,7 @@ namespace ostd OutputHandlerBase& ConsoleOutputHandler::fg(const Color& color) { - std::cout << "\033[38;2;" << (int)color.r << ";" << (int)color.g << ";" << (int)color.b << "m"; + std::cout << "\033[38;2;" << (i32)color.r << ";" << (i32)color.g << ";" << (i32)color.b << "m"; return *this; } @@ -124,55 +124,55 @@ namespace ostd return *this; } - OutputHandlerBase& ConsoleOutputHandler::p(uint8_t i) + OutputHandlerBase& ConsoleOutputHandler::p(u8 i) { - std::cout << (uint8_t)i; + std::cout << (u8)i; return *this; } - OutputHandlerBase& ConsoleOutputHandler::p(int8_t i) + OutputHandlerBase& ConsoleOutputHandler::p(i8 i) { - std::cout << (int8_t)i; + std::cout << (i8)i; return *this; } - OutputHandlerBase& ConsoleOutputHandler::p(uint16_t i) + OutputHandlerBase& ConsoleOutputHandler::p(u16 i) { - std::cout << (uint16_t)i; + std::cout << (u16)i; return *this; } - OutputHandlerBase& ConsoleOutputHandler::p(int16_t i) + OutputHandlerBase& ConsoleOutputHandler::p(i16 i) { - std::cout << (int16_t)i; + std::cout << (i16)i; return *this; } - OutputHandlerBase& ConsoleOutputHandler::p(uint32_t i) + OutputHandlerBase& ConsoleOutputHandler::p(u32 i) { - std::cout << (uint32_t)i; + std::cout << (u32)i; return *this; } - OutputHandlerBase& ConsoleOutputHandler::p(int32_t i) + OutputHandlerBase& ConsoleOutputHandler::p(i32 i) { - std::cout << (int32_t)i; + std::cout << (i32)i; return *this; } - OutputHandlerBase& ConsoleOutputHandler::p(uint64_t i) + OutputHandlerBase& ConsoleOutputHandler::p(u64 i) { - std::cout << (uint64_t)i; + std::cout << (u64)i; return *this; } - OutputHandlerBase& ConsoleOutputHandler::p(int64_t i) + OutputHandlerBase& ConsoleOutputHandler::p(i64 i) { - std::cout << (int64_t)i; + std::cout << (i64)i; return *this; } - OutputHandlerBase& ConsoleOutputHandler::p(float f, uint8_t precision) + OutputHandlerBase& ConsoleOutputHandler::p(f32 f, u8 precision) { if (precision == 0) { @@ -187,7 +187,7 @@ namespace ostd return *this; } - OutputHandlerBase& ConsoleOutputHandler::p(double f, uint8_t precision) + OutputHandlerBase& ConsoleOutputHandler::p(f64 f, u8 precision) { if (precision == 0) { @@ -232,21 +232,21 @@ namespace ostd return *this; } - OutputHandlerBase& ConsoleOutputHandler::xy(int32_t x, int32_t y) + OutputHandlerBase& ConsoleOutputHandler::xy(i32 x, i32 y) { BasicConsole::setConsoleCursorPosition(x, y); return *this; } - OutputHandlerBase& ConsoleOutputHandler::x(int32_t x) + OutputHandlerBase& ConsoleOutputHandler::x(i32 x) { - int32_t y = getCursorPosition().y; + i32 y = getCursorPosition().y; return xy(x, y); } - OutputHandlerBase& ConsoleOutputHandler::y(int32_t y) + OutputHandlerBase& ConsoleOutputHandler::y(i32 y) { - int32_t x = getCursorPosition().x; + i32 x = getCursorPosition().x; return xy(x, y); } @@ -255,26 +255,26 @@ namespace ostd return BasicConsole::getConsoleCursorPosition(); } - void ConsoleOutputHandler::getCursorPosition(int32_t& outX, int32_t& outY) + void ConsoleOutputHandler::getCursorPosition(i32& outX, i32& outY) { auto pos = BasicConsole::getConsoleCursorPosition();; outX = pos.x; outY = pos.y; } - int32_t ConsoleOutputHandler::getCursorX(void) + i32 ConsoleOutputHandler::getCursorX(void) { auto pos = BasicConsole::getConsoleCursorPosition();; return pos.x; } - int32_t ConsoleOutputHandler::getCursorY(void) + i32 ConsoleOutputHandler::getCursorY(void) { auto pos = BasicConsole::getConsoleCursorPosition();; return pos.y; } - void ConsoleOutputHandler::getConsoleSize(int32_t& outColumns, int32_t& outRows) + void ConsoleOutputHandler::getConsoleSize(i32& outColumns, i32& outRows) { BasicConsole::getConsoleSize(outColumns, outRows); } diff --git a/src/ostd/io/Serial.cpp b/src/ostd/io/Serial.cpp index 6b2a739..bdf7b6b 100755 --- a/src/ostd/io/Serial.cpp +++ b/src/ostd/io/Serial.cpp @@ -5,10 +5,10 @@ namespace ostd { namespace serial { - bool SerialIO::init(uint64_t size, uint8_t endianness) + bool SerialIO::init(u64 size, u8 endianness) { if (size < 1) return false; - for (uint64_t i = 0; i < size; i++) + for (u64 i = 0; i < size; i++) m_data.push_back(0); m_endianness = endianness; return true; @@ -110,7 +110,7 @@ namespace ostd return true; } - bool SerialIO::r_Float(StreamIndex addr, float& outVal) + bool SerialIO::r_Float(StreamIndex addr, f32& outVal) { if (!is_validAddr(addr, tTypeSize::FLOAT)) return false; __float_parser fp; @@ -133,7 +133,7 @@ namespace ostd return true; } - bool SerialIO::r_Double(StreamIndex addr, double& outVal) + bool SerialIO::r_Double(StreamIndex addr, f64& outVal) { if (!is_validAddr(addr, tTypeSize::DOUBLE)) return false; __double_parser dp; @@ -167,7 +167,7 @@ namespace ostd bool SerialIO::r_ByteStream(StreamIndex addr, ByteStream& outStream) { if (!is_validAddr(addr, tTypeSize::ADDR)) return false; - uint32_t stream_size; + u32 stream_size; if (!r_Addr(addr, stream_size)) return false; addr += tTypeSize::ADDR; if (!is_validAddr(addr, stream_size)) return false; @@ -178,7 +178,7 @@ namespace ostd return true; } - bool SerialIO::r_ByteStream(StreamIndex addr, ByteStream& outStream, uint32_t size) + bool SerialIO::r_ByteStream(StreamIndex addr, ByteStream& outStream, u32 size) { if (!is_validAddr(addr, size)) return false; outStream.clear(); @@ -191,7 +191,7 @@ namespace ostd bool SerialIO::r_String(StreamIndex addr, String& outString) { if (!is_validAddr(addr, tTypeSize::ADDR)) return false; - uint32_t stream_size; + u32 stream_size; if (!r_Addr(addr, stream_size)) return false; addr += tTypeSize::ADDR; if (!is_validAddr(addr, stream_size)) return false; @@ -201,7 +201,7 @@ namespace ostd return true; } - bool SerialIO::r_String(StreamIndex addr, String& outString, uint32_t size) + bool SerialIO::r_String(StreamIndex addr, String& outString, u32 size) { if (!is_validAddr(addr, size)) return false; outString = ""; @@ -213,7 +213,7 @@ namespace ostd bool SerialIO::r_NullTerminatedString(StreamIndex addr, String& outString) { outString = ""; - int8_t c = 0; + i8 c = 0; if (!r_Byte(addr, c)) return false; addr += tTypeSize::BYTE; while (c != 0) @@ -326,7 +326,7 @@ namespace ostd return true; } - bool SerialIO::w_Float(StreamIndex addr, float val) + bool SerialIO::w_Float(StreamIndex addr, f32 val) { m_statuWriting = true; if (!is_validAddr(addr, tTypeSize::FLOAT)) return false; @@ -350,7 +350,7 @@ namespace ostd return true; } - bool SerialIO::w_Double(StreamIndex addr, double val) + bool SerialIO::w_Double(StreamIndex addr, f64 val) { m_statuWriting = true; if (!is_validAddr(addr, tTypeSize::DOUBLE)) return false; @@ -385,7 +385,7 @@ namespace ostd bool SerialIO::w_ByteStream(StreamIndex addr, const ByteStream& stream, bool store_size) { m_statuWriting = true; - uint32_t stream_size = stream.size(); + u32 stream_size = stream.size(); if (store_size) { if (!is_validAddr(addr, tTypeSize::ADDR + stream_size)) return false; @@ -402,7 +402,7 @@ namespace ostd { m_statuWriting = true; auto stream = Memory::stringToByteStream(str); - uint32_t stream_size = stream.size(); + u32 stream_size = stream.size(); if (store_size && !null_terminate) { if (!is_validAddr(addr, tTypeSize::ADDR + stream_size)) return false; @@ -425,7 +425,7 @@ namespace ostd { if (isAutoResizeEnabled() && m_statuWriting) { - for (uint32_t i = 0; i <= m_resizeAmount; i++) + for (u32 i = 0; i <= m_resizeAmount; i++) m_data.push_back(0); m_statuWriting = false; return true; @@ -442,8 +442,8 @@ namespace ostd void SerialIO::print(StreamIndex start, OutputHandlerBase& out) { - uint32_t line_len = 32; - uint64_t power = 1; + u32 line_len = 32; + u64 power = 1; while(power < size()) power *= 2; Memory::printByteStream(m_data, start, line_len, power / line_len, out); diff --git a/src/ostd/io/Serial.hpp b/src/ostd/io/Serial.hpp index 57aebb2..6af5c1e 100755 --- a/src/ostd/io/Serial.hpp +++ b/src/ostd/io/Serial.hpp @@ -33,26 +33,26 @@ namespace ostd class SerialIO { public: struct tEndianness { - inline static constexpr uint8_t LittleEndian = 0x00; - inline static constexpr uint8_t BigEndian = 0x01; + inline static constexpr u8 LittleEndian = 0x00; + inline static constexpr u8 BigEndian = 0x01; }; public: inline SerialIO(void) { init(); } - inline SerialIO(uint64_t size, uint8_t endianness = tEndianness::BigEndian) { init(size, endianness); } - inline SerialIO(ByteStream& data, uint8_t endianness = tEndianness::BigEndian) { m_data = data; m_endianness = endianness; } - bool init(uint64_t size = SerialIO::DefaultMaxSize, uint8_t endianness = tEndianness::BigEndian); + inline SerialIO(u64 size, u8 endianness = tEndianness::BigEndian) { init(size, endianness); } + inline SerialIO(ByteStream& data, u8 endianness = tEndianness::BigEndian) { m_data = data; m_endianness = endianness; } + bool init(u64 size = SerialIO::DefaultMaxSize, u8 endianness = tEndianness::BigEndian); bool r_QWord(StreamIndex addr, QWord& outVal); bool r_DWord(StreamIndex addr, DWord& outVal); bool r_Word(StreamIndex addr, Word& outVal); bool r_Byte(StreamIndex addr, Byte& outVal); bool r_Addr(StreamIndex addr, StreamIndex& outVal); - bool r_Float(StreamIndex addr, float& outVal); - bool r_Double(StreamIndex addr, double& outVal); + bool r_Float(StreamIndex addr, f32& outVal); + bool r_Double(StreamIndex addr, f64& outVal); bool r_ByteStream(StreamIndex addr, ByteStream& outStream); - bool r_ByteStream(StreamIndex addr, ByteStream& outStream, uint32_t size); + bool r_ByteStream(StreamIndex addr, ByteStream& outStream, u32 size); bool r_String(StreamIndex addr, String& outString); - bool r_String(StreamIndex addr, String& outString, uint32_t size); + bool r_String(StreamIndex addr, String& outString, u32 size); bool r_NullTerminatedString(StreamIndex addr, String& outString); bool w_QWord(StreamIndex addr, QWord val); @@ -60,33 +60,33 @@ namespace ostd bool w_Word(StreamIndex addr, Word val); bool w_Byte(StreamIndex addr, Byte val); bool w_Addr(StreamIndex addr, StreamIndex val); - bool w_Float(StreamIndex addr, float val); - bool w_Double(StreamIndex addr, double val); + bool w_Float(StreamIndex addr, f32 val); + bool w_Double(StreamIndex addr, f64 val); bool w_ByteStream(StreamIndex addr, const ByteStream& stream, bool store_size = true); bool w_String(StreamIndex addr, const String& str, bool store_size = false, bool null_terminate = true); bool is_validAddr(StreamIndex addr, StreamIndex offset = 1); - inline uint64_t size(void) { return m_data.size(); } + inline u64 size(void) { return m_data.size(); } inline ByteStream& getData(void) { return m_data; } void print(StreamIndex start, OutputHandlerBase& out); bool saveToFile(const String& filePath); - inline uint8_t getEndianness(void) const { return m_endianness; } + inline u8 getEndianness(void) const { return m_endianness; } inline bool isLittleEndian(void) const { return m_endianness == tEndianness::LittleEndian; } inline bool isBigEndian(void) const { return m_endianness == tEndianness::BigEndian; } inline bool isAutoResizeEnabled(void) const { return m_autoResize; } - inline void enableAutoResize(bool val = true, int32_t resizeAmount = 1024) { m_autoResize = val; if (!val) return; m_resizeAmount = resizeAmount; } + inline void enableAutoResize(bool val = true, i32 resizeAmount = 1024) { m_autoResize = val; if (!val) return; m_resizeAmount = resizeAmount; } private: ByteStream m_data; - uint8_t m_endianness { tEndianness::BigEndian }; + u8 m_endianness { tEndianness::BigEndian }; bool m_autoResize { true }; - int32_t m_resizeAmount { 1024 }; + i32 m_resizeAmount { 1024 }; bool m_statuWriting { false }; public: - inline static constexpr uint64_t DefaultMaxSize = 512; + inline static constexpr u64 DefaultMaxSize = 512; }; } } diff --git a/src/ostd/io/Stylesheet.cpp b/src/ostd/io/Stylesheet.cpp index c65c5d8..92aceae 100644 --- a/src/ostd/io/Stylesheet.cpp +++ b/src/ostd/io/Stylesheet.cpp @@ -34,32 +34,32 @@ namespace ostd return *this; } - Stylesheet& Stylesheet::loadFromFile(const ostd::String& filePath, bool clearCurrentRules, VariableList variable) + Stylesheet& Stylesheet::loadFromFile(const String& filePath, bool clearCurrentRules, VariableList variable) { - ostd::String outContent = ""; + String outContent = ""; ostd::FileSystem::readTextFileRaw(filePath, outContent); return loadFromString(outContent, filePath, clearCurrentRules, variable); } - Stylesheet& Stylesheet::loadFromString(const ostd::String& content, const ostd::String& filePath, bool clearCurrentRules, VariableList variables) + Stylesheet& Stylesheet::loadFromString(const String& content, const String& filePath, bool clearCurrentRules, VariableList variables) { if (clearCurrentRules) m_values.clear(); - std::vector lines = content.tokenize("\n", false, true).getRawData(); - std::vector originalLines = lines; + stdvec lines = content.tokenize("\n", false, true).getRawData(); + stdvec originalLines = lines; auto richLines = getRichStringLines(lines); - uint32_t lineNumber = 0; - auto l_warn = [&](const ostd::String& msg) -> void { + u32 lineNumber = 0; + auto l_warn = [&](const String& msg) -> void { OX_WARN("%s in theme line. File: <%s:%d>", msg.c_str(), filePath.c_str(), lineNumber, originalLines[lineNumber - 1].c_str()); }; - auto l_parseLine = [&](ostd::String& line) -> void { + auto l_parseLine = [&](String& line) -> void { if (!parseThemeFileLine(line, variables)) l_warn("Error"); }; - uint8_t lineNumberMaxWidth = ostd::String("").add(static_cast(lines.size())).len(); - ostd::String groupSelector = ""; + u8 lineNumberMaxWidth = String("").add(cast(lines.size())).len(); + String groupSelector = ""; bool groupLines = true; - std::vector group; + stdvec group; bool debug_print = false; for (auto& line : lines) { @@ -85,8 +85,8 @@ namespace ostd l_warn("Invalid variable"); goto custom_continue; } - ostd::String varName = line.new_substr(0, line.indexOf("=")).trim(); - ostd::String varValue = line.new_substr(line.indexOf("=") + 1).trim(); + String varName = line.new_substr(0, line.indexOf("=")).trim(); + String varValue = line.new_substr(line.indexOf("=") + 1).trim(); if (!varName.regexMatches(m_validNameRegex)) { l_warn("Invalid variable name"); @@ -110,7 +110,7 @@ namespace ostd groupLines = false; auto newLines = parseGroup(groupSelector, group); lineNumber -= newLines.size(); - for (int32_t i = 0; i < newLines.size(); i++) + for (i32 i = 0; i < newLines.size(); i++) { auto& l = newLines[i]; l_parseLine(l); @@ -136,7 +136,7 @@ namespace ostd l_warn("Invalid group selector"); goto custom_continue; } - ostd::String rawSelector = line.new_substr(1, line.indexOf(")")).trim(); + String rawSelector = line.new_substr(1, line.indexOf(")")).trim(); groupSelector = parseGroupSelector(rawSelector); if (groupSelector == "") { @@ -159,38 +159,38 @@ namespace ostd continue; custom_continue: if (debug_print) - std::cout << ostd::String("").add(lineNumber).addLeftPadding(lineNumberMaxWidth, ' ') << "| " << richLines[lineNumber - 1] << "\n"; + std::cout << String("").add(lineNumber).addLeftPadding(lineNumberMaxWidth, ' ') << "| " << richLines[lineNumber - 1] << "\n"; } return *this; } - void Stylesheet::set(const std::string& key, TypeVariant value, const ostd::String& themeID) + void Stylesheet::set(const std::string& key, TypeVariant value, const String& themeID) { - ostd::String fullKey = "@" + themeID + "." + key; + String fullKey = "@" + themeID + "." + key; // std::cout << "SET: " << fullKey << "\n"; setFull(fullKey, value); } - void Stylesheet::removeRule(const ostd::String& fullKey) + void Stylesheet::removeRule(const String& fullKey) { m_values.erase(fullKey); } - void Stylesheet::setFull(const ostd::String& fullKey, TypeVariant value) + void Stylesheet::setFull(const String& fullKey, TypeVariant value) { m_values[fullKey] = std::move(value); } - const Stylesheet::TypeVariant* Stylesheet::getVariant(const ostd::String& key, const std::vector& themeIDList, const QualifierList& qualifierList) const + const Stylesheet::TypeVariant* Stylesheet::getVariant(const String& key, const stdvec& themeIDList, const QualifierList& qualifierList) const { - std::vector emptyThemeIDList { "" }; - const std::vector& __themeIDList = (themeIDList.size() == 0 ? emptyThemeIDList : themeIDList); + stdvec emptyThemeIDList { "" }; + const stdvec& __themeIDList = (themeIDList.size() == 0 ? emptyThemeIDList : themeIDList); for (const auto&[qualifier, state] : qualifierList) { const TypeVariant* v = nullptr; - for (int32_t i = __themeIDList.size() - 1; i >= 0; i--) + for (i32 i = __themeIDList.size() - 1; i >= 0; i--) { - const ostd::String& themeID = __themeIDList[i]; + const String& themeID = __themeIDList[i]; v = (state ? getFull("@" + themeID + ":" + qualifier + "." + key) : nullptr); if (v) return v; @@ -202,9 +202,9 @@ custom_continue: if (v) return v; } - for (int32_t i = __themeIDList.size() - 1; i >= 0; i--) + for (i32 i = __themeIDList.size() - 1; i >= 0; i--) { - const ostd::String& themeID = __themeIDList[i]; + const String& themeID = __themeIDList[i]; if (auto v = getFull("@" + themeID + "." + key)) return v; } @@ -213,7 +213,7 @@ custom_continue: return nullptr; } - const Stylesheet::TypeVariant* Stylesheet::getFull(const ostd::String& fullKey) const + const Stylesheet::TypeVariant* Stylesheet::getFull(const String& fullKey) const { auto it = m_values.find(fullKey); // if (it != m_values.end()) @@ -221,16 +221,16 @@ custom_continue: return it != m_values.end() ? &it->second : nullptr; } - bool Stylesheet::parseThemeFileLine(const ostd::String& line, const VariableList& variables, bool exitCondition) + bool Stylesheet::parseThemeFileLine(const String& line, const VariableList& variables, bool exitCondition) { if (!line.contains("=")) return false; - ostd::String key = line.new_substr(0, line.indexOf("=")).trim(); - ostd::String valuePreserveCase = line.new_substr(line.indexOf("=") + 1).trim(); - ostd::String value = line.new_substr(line.indexOf("=") + 1).trim().toLower(); + String key = line.new_substr(0, line.indexOf("=")).trim(); + String valuePreserveCase = line.new_substr(line.indexOf("=") + 1).trim(); + String value = line.new_substr(line.indexOf("=") + 1).trim().toLower(); if (key == "") return false; - ostd::String themeID = ""; + String themeID = ""; if (key.startsWith("@")) { if (key.indexOf(" ") < 2) @@ -239,7 +239,7 @@ custom_continue: key.substr(key.indexOf(" ") + 1).trim(); } if (value.isInt()) - set(key, static_cast(value.toInt()), themeID); + set(key, cast(value.toInt()), themeID); else if (value.isNumeric(true)) set(key, value.toFloat(), themeID); else if (value == "true" || value == "false") @@ -260,7 +260,7 @@ custom_continue: auto tokens = value.tokenize(","); if (tokens.count() != 2) return false; - std::vector vec; + stdvec vec; for (const auto& tok : tokens) { if (!tok.isNumeric(true)) @@ -275,7 +275,7 @@ custom_continue: auto tokens = value.tokenize(","); if (tokens.count() != 4) return false; - std::vector vec; + stdvec vec; for (const auto& tok : tokens) { if (!tok.isNumeric(true)) @@ -288,7 +288,7 @@ custom_continue: { if (exitCondition) return false; - ostd::String lineCopy = line; + String lineCopy = line; for (const auto&[var, val] : variables) { if (lineCopy.contains(var)) @@ -302,13 +302,13 @@ custom_continue: return true; } - ostd::String Stylesheet::parseGroupSelector(const ostd::String& rawSelector) const + String Stylesheet::parseGroupSelector(const String& rawSelector) const { - ostd::String sel = rawSelector.new_trim(); + String sel = rawSelector.new_trim(); if (sel == "") return ""; - ostd::String id = ""; - ostd::String name = sel; - ostd::String qual = ""; + String id = ""; + String name = sel; + String qual = ""; if (sel.contains(" ")) { id = sel.new_substr(0, sel.indexOf(" ")).trim(); @@ -332,11 +332,11 @@ custom_continue: return id; } - std::vector Stylesheet::parseGroup(const ostd::String& selector, const std::vector& group) + stdvec Stylesheet::parseGroup(const String& selector, const stdvec& group) { if (selector.new_trim() == "" || group.size() == 0) return {}; - std::vector newLines; + stdvec newLines; for (const auto& property : group) newLines.push_back(selector.new_add(".").new_add(property)); return newLines; @@ -351,15 +351,15 @@ custom_continue: std::cout << "\n"; } - ostd::String Stylesheet::typeVariantToString(const TypeVariant& v) + String Stylesheet::typeVariantToString(const TypeVariant& v) { - if (auto p = std::get_if(&v)) + if (auto p = std::get_if(&v)) return String("").add(*p); - else if (auto p = std::get_if(&v)) + else if (auto p = std::get_if(&v)) return String("").add(*p); else if (auto p = std::get_if(&v)) return STR_BOOL(*p); - else if (auto p = std::get_if(&v)) + else if (auto p = std::get_if(&v)) return *p; else if (auto p = std::get_if(&v)) return *p; @@ -370,9 +370,9 @@ custom_continue: return ""; } - std::vector Stylesheet::getRichStringLines(const std::vector& lines) + stdvec Stylesheet::getRichStringLines(const stdvec& lines) { - std::vector richLines; + stdvec richLines; for (auto line : lines) { ostd::RegexRichString rgxrstr(line); diff --git a/src/ostd/io/Stylesheet.hpp b/src/ostd/io/Stylesheet.hpp index 383371f..afeeee2 100644 --- a/src/ostd/io/Stylesheet.hpp +++ b/src/ostd/io/Stylesheet.hpp @@ -20,32 +20,32 @@ #pragma once -#include "string/TextStyleParser.hpp" +#include #include #include #include -#include + namespace ostd { class Stylesheet { - public: using QualifierList = std::vector>; - public: using VariableList = std::unordered_map>; - public: using TypeVariant = std::variant; + public: using QualifierList = stdvec>; + public: using VariableList = stdumap>; + public: using TypeVariant = std::variant; public: Stylesheet(void); Stylesheet& clear(void); - Stylesheet& loadFromFile(const ostd::String& filePath, bool clearCurrentRules = true, VariableList variables = {}); - Stylesheet& loadFromString(const ostd::String& content, const ostd::String& filePath = "memory://", bool clearCurrentRules = true, VariableList variables = {}); - void set(const std::string& key, TypeVariant value, const ostd::String& themeID); - void removeRule(const ostd::String& fullKey); - void setFull(const ostd::String& fullKey, TypeVariant value); - const TypeVariant* getVariant(const ostd::String& key, const std::vector& themeIDList, const QualifierList& qualifierList) const; - const TypeVariant* getFull(const ostd::String& fullKey) const; + Stylesheet& loadFromFile(const String& filePath, bool clearCurrentRules = true, VariableList variables = {}); + Stylesheet& loadFromString(const String& content, const String& filePath = "memory://", bool clearCurrentRules = true, VariableList variables = {}); + void set(const std::string& key, TypeVariant value, const String& themeID); + void removeRule(const String& fullKey); + void setFull(const String& fullKey, TypeVariant value); + const TypeVariant* getVariant(const String& key, const stdvec& themeIDList, const QualifierList& qualifierList) const; + const TypeVariant* getFull(const String& fullKey) const; template - inline T get(const ostd::String& key, const T& fallback, const std::vector& themeIDList, const QualifierList& qualifierList) const + inline T get(const String& key, const T& fallback, const stdvec& themeIDList, const QualifierList& qualifierList) const { if (auto v = getVariant(key, themeIDList, qualifierList)) { @@ -56,16 +56,16 @@ namespace ostd } void debugPrint(void); - ostd::String typeVariantToString(const TypeVariant& v); - std::vector getRichStringLines(const std::vector& lines); + String typeVariantToString(const TypeVariant& v); + stdvec getRichStringLines(const stdvec& lines); private: - bool parseThemeFileLine(const ostd::String& line, const VariableList& variables, bool exitCondition = false); - ostd::String parseGroupSelector(const ostd::String& rawSelector) const; - std::vector parseGroup(const ostd::String& selector, const std::vector& group); + bool parseThemeFileLine(const String& line, const VariableList& variables, bool exitCondition = false); + String parseGroupSelector(const String& rawSelector) const; + stdvec parseGroup(const String& selector, const stdvec& group); private: - std::unordered_map m_values; - const ostd::String m_validNameRegex { "^[A-Za-z_][A-Za-z0-9_]*$" }; + stdumap m_values; + const String m_validNameRegex { "^[A-Za-z_][A-Za-z0-9_]*$" }; }; } diff --git a/src/ostd/math/Geometry.hpp b/src/ostd/math/Geometry.hpp index 494469e..86d042d 100755 --- a/src/ostd/math/Geometry.hpp +++ b/src/ostd/math/Geometry.hpp @@ -22,15 +22,14 @@ #include #include -#include #include #define PI 3.1415926535898f #define TWO_PI PI * 2.0f #define HALF_PI PI / 2.0f #define QUARTER_PI PI / 4.0f -#define DEG_TO_RAD(deg) (float)(deg * (PI / 180.0f)) -#define RAD_TO_DEG(rad) (float)(rad * (180.0f / PI)) +#define DEG_TO_RAD(deg) (f32)(deg * (PI / 180.0f)) +#define RAD_TO_DEG(rad) (f32)(rad * (180.0f / PI)) #define LERP(n1, n2, f) (n2 - n1) * f + n1 #define CAP(n, max) (n > max ? max : n) @@ -48,22 +47,22 @@ namespace ostd struct Vec2 : public __i_stringeable { //======================== Data ======================== - float x; - float y; + f32 x; + f32 y; //====================================================== //==================== Construction ==================== - inline Vec2(float xx = 0, float yy = 0) : x(xx), y(yy) { } + inline Vec2(f32 xx = 0, f32 yy = 0) : x(xx), y(yy) { } inline Vec2(const Vec2& v2) { set(v2); } inline Vec2& set(const Vec2& v2) { x = v2.x; y = v2.y; return *this; } - inline Vec2& set(float xx, float yy) { x = xx; y = yy; return *this; } + inline Vec2& set(f32 xx, f32 yy) { x = xx; y = yy; return *this; } //====================================================== //================== Static Functions ================== - inline static Vec2 fromAngle(float angle) { return Vec2(std::cos(angle), std::sin(angle)); } - inline static float angleBetween(const Vec2& v1, const Vec2& v2) { return std::acos(v1.dot(v2) / (v1.mag() * v2.mag())); } + inline static Vec2 fromAngle(f32 angle) { return Vec2(std::cos(angle), std::sin(angle)); } + inline static f32 angleBetween(const Vec2& v1, const Vec2& v2) { return std::acos(v1.dot(v2) / (v1.mag() * v2.mag())); } //====================================================== @@ -75,37 +74,37 @@ namespace ostd //===================== Operations ===================== - inline float mag(void) const { return std::sqrt((x * x) + (y * y)); } + inline f32 mag(void) const { return std::sqrt((x * x) + (y * y)); } inline Vec2 add(Vec2 v2) const { return { x + v2.x, y + v2.y }; } - inline Vec2 add(float x2, float y2) const { return { x + x2, y + y2 }; } + inline Vec2 add(f32 x2, f32 y2) const { return { x + x2, y + y2 }; } inline Vec2 sub(Vec2 v2) const { return { x - v2.x, y - v2.y }; } - inline Vec2 sub(float x2, float y2) const { return { x - x2, y - y2 }; } - inline Vec2 mul(float scalar) const { return { x * scalar, y * scalar }; } - inline Vec2 div(float scalar) const { return { x / scalar, y / scalar }; } + inline Vec2 sub(f32 x2, f32 y2) const { return { x - x2, y - y2 }; } + inline Vec2 mul(f32 scalar) const { return { x * scalar, y * scalar }; } + inline Vec2 div(f32 scalar) const { return { x / scalar, y / scalar }; } - inline Vec2 normalize(void) const { float m = _zp(mag()); return { x / m, y / m }; } - inline float dist(Vec2 v2) const { return std::sqrt((float)((v2.x - x) * (v2.x - x)) + ((v2.y - y) * (v2.y - y))); } - inline float heading(void) const { return std::atan2(y, x); } - inline Vec2 rotate(float angle) const { return Vec2(*this).rotate(angle); } - inline float dot(const Vec2& v2) const { return (x * v2.x) + (y * v2.y); } - inline float cross(const Vec2& v2) const { return (x * v2.y) - (v2.x * y); } + inline Vec2 normalize(void) const { f32 m = _zp(mag()); return { x / m, y / m }; } + inline f32 dist(Vec2 v2) const { return std::sqrt((f32)((v2.x - x) * (v2.x - x)) + ((v2.y - y) * (v2.y - y))); } + inline f32 heading(void) const { return std::atan2(y, x); } + inline Vec2 rotate(f32 angle) const { return Vec2(*this).rotate(angle); } + inline f32 dot(const Vec2& v2) const { return (x * v2.x) + (y * v2.y); } + inline f32 cross(const Vec2& v2) const { return (x * v2.y) - (v2.x * y); } //====================================================== //===================== Modifiers ====================== inline Vec2& addm(const Vec2& v2) { x += v2.x; y += v2.y; return *this; } - inline Vec2& addm(const float& x2, const float& y2) { x += x2; y += y2; return *this; } + inline Vec2& addm(const f32& x2, const f32& y2) { x += x2; y += y2; return *this; } inline Vec2& subm(const Vec2& v2) { x -= v2.x; y -= v2.y; return *this; } - inline Vec2& subm(const float& x2, const float& y2) { x -= x2; y -= y2; return *this; } - inline Vec2& mulm(const float& scalar) { x *= scalar; y *= scalar; return *this; } - inline Vec2& divm(const float& scalar) { x /= scalar; y /= scalar; return *this; } + inline Vec2& subm(const f32& x2, const f32& y2) { x -= x2; y -= y2; return *this; } + inline Vec2& mulm(const f32& scalar) { x *= scalar; y *= scalar; return *this; } + inline Vec2& divm(const f32& scalar) { x /= scalar; y /= scalar; return *this; } - inline Vec2& normalizem(void) { float m = _zp(mag()); x /= m; y /= m; return *this; } - inline Vec2& setMag(const float& mag) { return normalizem().mulm(mag); } - inline Vec2& setHeading(const float& angle) { float m = mag(); set(m * std::cos(angle), m * std::sin(angle)); return *this; } - inline Vec2& rotate(const float& angle) { return setHeading(heading() + angle); } - inline Vec2& limit(const float& max) { float msq = mag(); msq *= msq; if (msq > (max * max)) divm(std::sqrt(msq)).mulm(max); return *this; } + inline Vec2& normalizem(void) { f32 m = _zp(mag()); x /= m; y /= m; return *this; } + inline Vec2& setMag(const f32& mag) { return normalizem().mulm(mag); } + inline Vec2& setHeading(const f32& angle) { f32 m = mag(); set(m * std::cos(angle), m * std::sin(angle)); return *this; } + inline Vec2& rotate(const f32& angle) { return setHeading(heading() + angle); } + inline Vec2& limit(const f32& max) { f32 msq = mag(); msq *= msq; if (msq > (max * max)) divm(std::sqrt(msq)).mulm(max); return *this; } //====================================================== @@ -115,22 +114,22 @@ namespace ostd inline Vec2 operator-() const { return { -x, -y }; } inline Vec2 operator+ (const Vec2& op2 ) const { return add(op2); } inline Vec2 operator- (const Vec2& op2 ) const { return sub(op2); } - inline Vec2 operator+ (const float& op2) const { return add(op2, op2); } - inline Vec2 operator- (const float& op2) const { return sub(op2, op2); } - inline Vec2 operator* (const float& op2) const { return mul(op2); } - inline Vec2 operator/ (const float& op2) const { return div(op2); } + inline Vec2 operator+ (const f32& op2) const { return add(op2, op2); } + inline Vec2 operator- (const f32& op2) const { return sub(op2, op2); } + inline Vec2 operator* (const f32& op2) const { return mul(op2); } + inline Vec2 operator/ (const f32& op2) const { return div(op2); } inline Vec2& operator= (const Vec2& val ) { return set(val); } - inline Vec2& operator= (const float& val) { return set(val, val); } + inline Vec2& operator= (const f32& val) { return set(val, val); } inline Vec2& operator+=(const Vec2& op2 ) { return addm(op2); } inline Vec2& operator-=(const Vec2& op2 ) { return subm(op2); } - inline Vec2& operator+=(const float& op2) { return addm(op2, op2); } - inline Vec2& operator-=(const float& op2) { return subm(op2, op2); } - inline Vec2& operator*=(const float& op2) { return mulm(op2); } - inline Vec2& operator/=(const float& op2) { return divm(op2); } + inline Vec2& operator+=(const f32& op2) { return addm(op2, op2); } + inline Vec2& operator-=(const f32& op2) { return subm(op2, op2); } + inline Vec2& operator*=(const f32& op2) { return mulm(op2); } + inline Vec2& operator/=(const f32& op2) { return divm(op2); } //====================================================== private: - inline float _zp(float n1) const { return (n1 == 0 ? 1 : n1); } + inline f32 _zp(f32 n1) const { return (n1 == 0 ? 1 : n1); } }; @@ -146,12 +145,12 @@ namespace ostd inline Point(T xx, T yy) : x(xx), y(yy) {} inline Point(const Vec2& vec) { x = vec.x; y = vec.y; } inline Point& set(const Point& v2) { x = v2.x; y = v2.y; return *this; } - inline Point& set(float xx, float yy) { x = xx; y = yy; return *this; } + inline Point& set(f32 xx, f32 yy) { x = xx; y = yy; return *this; } //===================== Operators ====================== inline bool operator==(const Point& op2 ) const { return (x == op2.x && y == op2.y); } inline bool operator!=(const Point& op2 ) const { return (x != op2.x || y != op2.y); } - inline operator Vec2() const { return { static_cast(x), static_cast(y) }; } + inline operator Vec2() const { return { cast(x), cast(y) }; } inline Point operator+ (const Point& op2 ) const { return { x + op2.x, y + op2.y }; } inline Point operator- (const Point& op2 ) const { return { x - op2.x, y - op2.y }; } inline Point operator+ (const T& op2) const { return { x + op2, y + op2 }; } @@ -174,31 +173,31 @@ namespace ostd y = (T2)(copy.y); } - inline Vec2 asVec2(void) const { return { static_cast(x), static_cast(y) }; } + inline Vec2 asVec2(void) const { return { cast(x), cast(y) }; } inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(" }"); } }; - typedef Point FPoint; - typedef Point DPoint; - typedef Point UIPoint; - typedef Point UI64Point; - typedef Point UI16Point; - typedef Point UI8Point; - typedef Point IPoint; - typedef Point I64Point; - typedef Point I16Point; - typedef Point I8Point; + typedef Point FPoint; + typedef Point DPoint; + typedef Point UIPoint; + typedef Point UI64Point; + typedef Point UI16Point; + typedef Point UI8Point; + typedef Point IPoint; + typedef Point I64Point; + typedef Point I16Point; + typedef Point I8Point; struct Vec3 : public __i_stringeable { - inline Vec3(float xx = 0, float yy = 0, float zz = 0) + inline Vec3(f32 xx = 0, f32 yy = 0, f32 zz = 0) { x = xx; y = yy; z = zz; } - inline Vec3(const Vec2& xy, float _z = 0.0f) { x = xy.x; y = xy.y; z = _z; } + inline Vec3(const Vec2& xy, f32 _z = 0.0f) { x = xy.x; y = xy.y; z = _z; } inline Vec2 xy(void) const { return Vec2(x, y); } inline Vec2 yz(void) const { return Vec2(y, z); } inline Vec2 zx(void) const { return Vec2(z, x); } @@ -207,22 +206,22 @@ namespace ostd inline bool operator!=(const Vec3& op2 ) const { return (x != op2.x || y != op2.y || op2.z != z); } inline Vec3& operator+=(const Vec3& op2 ) { x += op2.x; y += op2.y; z += op2.z; return *this; } - float x; - float y; - float z; + f32 x; + f32 y; + f32 z; }; struct Vec4 : public __i_stringeable { - inline Vec4(float xx = 0, float yy = 0, float zz = 0, float ww = 0) + inline Vec4(f32 xx = 0, f32 yy = 0, f32 zz = 0, f32 ww = 0) { x = xx; y = yy; z = zz; w = ww; } - inline Vec4(const Vec2& xy, float _z = 0.0f, float _w = 0.0f) { x = xy.x; y = xy.y; z = _z; w = _w; } - inline Vec4(const Vec3& xyz, float _w = 0.0f) { x = xyz.x; y = xyz.y; z = xyz.z; w = _w; } + inline Vec4(const Vec2& xy, f32 _z = 0.0f, f32 _w = 0.0f) { x = xy.x; y = xy.y; z = _z; w = _w; } + inline Vec4(const Vec3& xyz, f32 _w = 0.0f) { x = xyz.x; y = xyz.y; z = xyz.z; w = _w; } inline Vec4(const Vec2& xy, const Vec2& zw) { x = xy.x; y = xy.y; z = zw.x; w = zw.y; } inline Vec2 xy(void) const { return Vec2(x, y); } inline Vec2 yz(void) const { return Vec2(y, z); } @@ -230,10 +229,10 @@ namespace ostd inline Vec2 wx(void) const { return Vec2(w, x); } inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(", ").add(z).add(", ").add(w).add(" }"); } - float x; - float y; - float z; - float w; + f32 x; + f32 y; + f32 z; + f32 w; }; struct Triangle : public __i_stringeable @@ -248,7 +247,7 @@ namespace ostd vB = b; vC = c; } - inline Triangle(float ax, float ay, float bx, float by, float cx, float cy) + inline Triangle(f32 ax, f32 ay, f32 bx, f32 by, f32 cx, f32 cy) { vA.x = ax; vA.y = ay; @@ -259,7 +258,7 @@ namespace ostd } inline bool contains(Vec2 p) { - float d1, d2, d3; + f32 d1, d2, d3; bool has_neg, has_pos; d1 = __sign(p, vA, vB); @@ -274,7 +273,7 @@ namespace ostd inline String toString(void) const override { return String("{ A: ").add(vA.toString()).add(", B: ").add(vB.toString()).add(", C: ").add(vC.toString()).add(" }"); } private: - inline float __sign(Vec2 p1, Vec2 p2, Vec2 p3) + inline f32 __sign(Vec2 p1, Vec2 p2, Vec2 p3) { return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y); } @@ -284,10 +283,10 @@ namespace ostd { public: inline Rectangle(void) : x(0), y(0), w(0), h(0) {} - inline Rectangle(float xx, float yy, float ww, float hh) : x(xx), y(yy), w(ww), h(hh) {} - inline Rectangle(float xw, float yh, bool position = true) { if (position) { x = xw; y = yh; } else { w = xw; h = yh; } } - inline Rectangle(float xx, float yy, Vec2 size) { x = xx; y = yy; w = size.x; h = size.y; } - inline Rectangle(Vec2 position, float ww, float hh) { x = position.x; y = position.y; w = ww; h = hh; } + inline Rectangle(f32 xx, f32 yy, f32 ww, f32 hh) : x(xx), y(yy), w(ww), h(hh) {} + inline Rectangle(f32 xw, f32 yh, bool position = true) { if (position) { x = xw; y = yh; } else { w = xw; h = yh; } } + inline Rectangle(f32 xx, f32 yy, Vec2 size) { x = xx; y = yy; w = size.x; h = size.y; } + inline Rectangle(Vec2 position, f32 ww, f32 hh) { x = position.x; y = position.y; w = ww; h = hh; } inline Rectangle(Vec2 position, Vec2 size) { x = position.x; y = position.y; w = size.x; h = size.y; } virtual ~Rectangle(void) = default; @@ -295,75 +294,75 @@ namespace ostd inline bool operator!=(const Rectangle& op2) const { return !(*this == op2); } inline Rectangle operator+(const Rectangle& op2) const { return { x + op2.x, y + op2.y, w + op2.w, h + op2.h }; } inline Rectangle operator-(const Rectangle& op2) const { return { x - op2.x, y - op2.y, w - op2.w, h - op2.h }; } - inline Rectangle operator+(float s) const { return { x + s, y + s, w + s, h + s }; } - inline Rectangle operator-(float s) const { return { x - s, y - s, w - s, h - s }; } - inline Rectangle operator*(float s) const { return { x * s, y * s, w * s, h * s }; } - inline Rectangle operator/(float s) const { return { x / s, y / s, w / s, h / s }; } + inline Rectangle operator+(f32 s) const { return { x + s, y + s, w + s, h + s }; } + inline Rectangle operator-(f32 s) const { return { x - s, y - s, w - s, h - s }; } + inline Rectangle operator*(f32 s) const { return { x * s, y * s, w * s, h * s }; } + inline Rectangle operator/(f32 s) const { return { x / s, y / s, w / s, h / s }; } inline Rectangle& operator=(const Rectangle& r) { x = r.x; y = r.y; w = r.w; h = r.h; return *this; } - inline Rectangle& operator=(float s) { x = s; y = s; w = s; h = s; return *this; } + inline Rectangle& operator=(f32 s) { x = s; y = s; w = s; h = s; return *this; } inline Rectangle& operator+=(const Rectangle& op2) { x += op2.x; y += op2.y; w += op2.w; h += op2.h; return *this; } inline Rectangle& operator-=(const Rectangle& op2) { x -= op2.x; y -= op2.y; w -= op2.w; h -= op2.h; return *this; } - inline Rectangle& operator+=(float s) { x += s; y += s; w += s; h += s; return *this; } - inline Rectangle& operator-=(float s) { x -= s; y -= s; w -= s; h -= s; return *this; } - inline Rectangle& operator*=(float s) { x *= s; y *= s; w *= s; h *= s; return *this; } - inline Rectangle& operator/=(float s) { x /= s; y /= s; w /= s; h /= s; return *this; } + inline Rectangle& operator+=(f32 s) { x += s; y += s; w += s; h += s; return *this; } + inline Rectangle& operator-=(f32 s) { x -= s; y -= s; w -= s; h -= s; return *this; } + inline Rectangle& operator*=(f32 s) { x *= s; y *= s; w *= s; h *= s; return *this; } + inline Rectangle& operator/=(f32 s) { x /= s; y /= s; w /= s; h /= s; return *this; } - inline virtual float getx(void) const { return x; } - inline virtual float gety(void) const { return y; } - inline virtual float getw(void) const { return w; } - inline virtual float geth(void) const { return h; } - inline virtual float getCenterX(void) const { return getx() + getw() / 2; } - inline virtual float getCenterY(void) const { return gety() + geth() / 2; } + inline virtual f32 getx(void) const { return x; } + inline virtual f32 gety(void) const { return y; } + inline virtual f32 getw(void) const { return w; } + inline virtual f32 geth(void) const { return h; } + inline virtual f32 getCenterX(void) const { return getx() + getw() / 2; } + inline virtual f32 getCenterY(void) const { return gety() + geth() / 2; } - inline virtual void setx(float xx) { x = xx; } - inline virtual void sety(float yy) { y = yy; } - inline virtual void setw(float ww) { w = ww; } - inline virtual void seth(float hh) { h = hh; } + inline virtual void setx(f32 xx) { x = xx; } + inline virtual void sety(f32 yy) { y = yy; } + inline virtual void setw(f32 ww) { w = ww; } + inline virtual void seth(f32 hh) { h = hh; } inline virtual Vec2 getPosition(void) const { return Vec2(getx(), gety()); } inline virtual Vec2 getSize(void) const { return Vec2(getw(), geth()); } inline virtual Vec2 getCenter(void) const { return Vec2(getx() + getw() / 2, gety() + geth() / 2); } inline virtual void setPosition(Vec2 pos) { setx(pos.x); sety(pos.y); } - inline virtual void setPosition(float xx, float yy) { setx(xx); sety(yy); } + inline virtual void setPosition(f32 xx, f32 yy) { setx(xx); sety(yy); } inline virtual void setSize(Vec2 size) { setw(size.x); seth(size.y); } - inline virtual void setSize(float ww, float hh) { setw(ww); seth(hh); } - inline virtual void setBounds(float xx, float yy, float ww, float hh) { setx(xx); sety(yy); setw(ww); seth(hh); } + inline virtual void setSize(f32 ww, f32 hh) { setw(ww); seth(hh); } + inline virtual void setBounds(f32 xx, f32 yy, f32 ww, f32 hh) { setx(xx); sety(yy); setw(ww); seth(hh); } - inline virtual float addx(float xx) { setx(getx() + xx); return getx(); } - inline virtual float addy(float yy) { sety(gety() + yy); return gety(); } - inline virtual Vec2 addPos(float xx, float yy) { return Vec2(addx(xx), addy(yy)); } + inline virtual f32 addx(f32 xx) { setx(getx() + xx); return getx(); } + inline virtual f32 addy(f32 yy) { sety(gety() + yy); return gety(); } + inline virtual Vec2 addPos(f32 xx, f32 yy) { return Vec2(addx(xx), addy(yy)); } inline virtual Vec2 addPos(Vec2 pos) { return addPos(pos.x, pos.y); } - inline virtual float addw(float ww) { setw(getw() + ww); return getw(); } - inline virtual float addh(float hh) { seth(geth() + hh); return geth(); } - inline virtual Vec2 addSize(float ww, float hh) { return Vec2(addw(ww), addh(hh)); } + inline virtual f32 addw(f32 ww) { setw(getw() + ww); return getw(); } + inline virtual f32 addh(f32 hh) { seth(geth() + hh); return geth(); } + inline virtual Vec2 addSize(f32 ww, f32 hh) { return Vec2(addw(ww), addh(hh)); } inline virtual Vec2 addSize(Vec2 size) { return addPos(size.x, size.y); } - inline virtual float subx(float xx) { setx(getx() - xx); return getx(); } - inline virtual float suby(float yy) { sety(gety() - yy); return gety(); } - inline virtual Vec2 subPos(float xx, float yy) { return Vec2(subx(xx), suby(yy)); } + inline virtual f32 subx(f32 xx) { setx(getx() - xx); return getx(); } + inline virtual f32 suby(f32 yy) { sety(gety() - yy); return gety(); } + inline virtual Vec2 subPos(f32 xx, f32 yy) { return Vec2(subx(xx), suby(yy)); } inline virtual Vec2 subPos(Vec2 pos) { return subPos(pos.x, pos.y); } - inline virtual float subw(float ww) { setw(getw() - ww); return getw(); } - inline virtual float subh(float hh) { seth(geth() - hh); return geth(); } - inline virtual Vec2 subSize(float ww, float hh) { return Vec2(subw(ww), subh(hh)); } + inline virtual f32 subw(f32 ww) { setw(getw() - ww); return getw(); } + inline virtual f32 subh(f32 hh) { seth(geth() - hh); return geth(); } + inline virtual Vec2 subSize(f32 ww, f32 hh) { return Vec2(subw(ww), subh(hh)); } inline virtual Vec2 subSize(Vec2 size) { return subPos(size.x, size.y); } - inline virtual float mulx(float xx) { setx(getx() * xx); return getx(); } - inline virtual float muly(float yy) { sety(gety() * yy); return gety(); } - inline virtual Vec2 mulPos(float xx, float yy) { return Vec2(mulx(xx), muly(yy)); } + inline virtual f32 mulx(f32 xx) { setx(getx() * xx); return getx(); } + inline virtual f32 muly(f32 yy) { sety(gety() * yy); return gety(); } + inline virtual Vec2 mulPos(f32 xx, f32 yy) { return Vec2(mulx(xx), muly(yy)); } inline virtual Vec2 mulPos(Vec2 pos) { return mulPos(pos.x, pos.y); } - inline virtual float mulw(float ww) { setw(getw() * ww); return getw(); } - inline virtual float mulh(float hh) { seth(geth() * hh); return geth(); } - inline virtual Vec2 mulSize(float ww, float hh) { return Vec2(mulw(ww), mulh(hh)); } + inline virtual f32 mulw(f32 ww) { setw(getw() * ww); return getw(); } + inline virtual f32 mulh(f32 hh) { seth(geth() * hh); return geth(); } + inline virtual Vec2 mulSize(f32 ww, f32 hh) { return Vec2(mulw(ww), mulh(hh)); } inline virtual Vec2 mulSize(Vec2 size) { return mulPos(size.x, size.y); } - inline virtual float divx(float xx) { setx(getx() / xx); return getx(); } - inline virtual float divy(float yy) { sety(gety() / yy); return gety(); } - inline virtual Vec2 divPos(float xx, float yy) { return Vec2(divx(xx), divy(yy)); } + inline virtual f32 divx(f32 xx) { setx(getx() / xx); return getx(); } + inline virtual f32 divy(f32 yy) { sety(gety() / yy); return gety(); } + inline virtual Vec2 divPos(f32 xx, f32 yy) { return Vec2(divx(xx), divy(yy)); } inline virtual Vec2 divPos(Vec2 pos) { return divPos(pos.x, pos.y); } - inline virtual float divw(float ww) { setw(getw() / ww); return getw(); } - inline virtual float divh(float hh) { seth(geth() / hh); return geth(); } - inline virtual Vec2 divSize(float ww, float hh) { return Vec2(divw(ww), divh(hh)); } + inline virtual f32 divw(f32 ww) { setw(getw() / ww); return getw(); } + inline virtual f32 divh(f32 hh) { seth(geth() / hh); return geth(); } + inline virtual Vec2 divSize(f32 ww, f32 hh) { return Vec2(divw(ww), divh(hh)); } inline virtual Vec2 divSize(Vec2 size) { return divPos(size.x, size.y); } inline virtual Vec2 topLeft(void) const { return getPosition(); } @@ -371,10 +370,10 @@ namespace ostd inline virtual Vec2 bottomLeft(void) const { return Vec2(getx(), gety() + geth()); } inline virtual Vec2 bottomRight(void) const { return Vec2(getx() + getw(), gety() + geth()); } - inline virtual float left(void) const { return getx(); } - inline virtual float right(void) const { return getw(); } - inline virtual float top(void) const { return gety(); } - inline virtual float bottom(void) const { return geth(); } + inline virtual f32 left(void) const { return getx(); } + inline virtual f32 right(void) const { return getw(); } + inline virtual f32 top(void) const { return gety(); } + inline virtual f32 bottom(void) const { return geth(); } inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(", ").add(w).add(", ").add(h).add(" }"); } @@ -400,10 +399,10 @@ namespace ostd { if (!intersects(rect, includeBounds)) return Rectangle(); - float leftX = std::max(x, rect.x); - float rightX = std::min(x + w, rect.x + rect.w); - float topY = std::max(y, rect.y); - float bottomY = std::min(y + h, rect.y + rect.h); + f32 leftX = std::max(x, rect.x); + f32 rightX = std::min(x + w, rect.x + rect.w); + f32 topY = std::max(y, rect.y); + f32 bottomY = std::min(y + h, rect.y + rect.h); return { leftX, topY, rightX - leftX, bottomY - topY }; } inline virtual bool contains(Vec2 p, bool includeBounds = false) const @@ -413,15 +412,15 @@ namespace ostd else return p.x > x && p.y > y && p.x < x + w && p.y < y + h; } - inline bool contains(float xx, float yy, bool includeBounds = false) const { return contains({ xx, yy }, includeBounds); } + inline bool contains(f32 xx, f32 yy, bool includeBounds = false) const { return contains({ xx, yy }, includeBounds); } - inline virtual float getDistance(Vec2 p) const { return sqrt(fabs((p.x - getx()) * (p.x - getx()) + (p.y - gety()) * (p.y - gety()))); } + inline virtual f32 getDistance(Vec2 p) const { return sqrt(fabs((p.x - getx()) * (p.x - getx()) + (p.y - gety()) * (p.y - gety()))); } public: - float x; - float y; - float w; - float h; + f32 x; + f32 y; + f32 w; + f32 h; }; template @@ -439,16 +438,16 @@ namespace ostd Point size; }; - typedef Rect FRect; - typedef Rect DRect; - typedef Rect UIRect; - typedef Rect UI64Rect; - typedef Rect UI16Rect; - typedef Rect UI8Rect; - typedef Rect IRect; - typedef Rect I64Rect; - typedef Rect I16Rect; - typedef Rect I8Rect; + typedef Rect FRect; + typedef Rect DRect; + typedef Rect UIRect; + typedef Rect UI64Rect; + typedef Rect UI16Rect; + typedef Rect UI8Rect; + typedef Rect IRect; + typedef Rect I64Rect; + typedef Rect I16Rect; + typedef Rect I8Rect; template class Line : public __i_stringeable @@ -465,14 +464,14 @@ namespace ostd Point p2; }; - typedef Line FLine; - typedef Line DLine; - typedef Line UILine; - typedef Line UI64Line; - typedef Line UI16Line; - typedef Line UI8Line; - typedef Line ILine; - typedef Line I64Line; - typedef Line I16Line; - typedef Line I8Line; + typedef Line FLine; + typedef Line DLine; + typedef Line UILine; + typedef Line UI64Line; + typedef Line UI16Line; + typedef Line UI8Line; + typedef Line ILine; + typedef Line I64Line; + typedef Line I16Line; + typedef Line I8Line; } diff --git a/src/ostd/math/MathUtils.cpp b/src/ostd/math/MathUtils.cpp index 5e90585..67bc7e8 100644 --- a/src/ostd/math/MathUtils.cpp +++ b/src/ostd/math/MathUtils.cpp @@ -23,9 +23,9 @@ namespace ostd { - float MathUtils::map_value(float input, float input_start, float input_end, float output_start, float output_end) + f32 MathUtils::map_value(f32 input, f32 input_start, f32 input_end, f32 output_start, f32 output_end) { - float slope = 1.0 * (output_end - output_start) / (input_end - input_start); + f32 slope = 1.0 * (output_end - output_start) / (input_end - input_start); return output_start + round(slope * (input - input_start)); } } diff --git a/src/ostd/math/MathUtils.hpp b/src/ostd/math/MathUtils.hpp index 0865c84..62cfa25 100644 --- a/src/ostd/math/MathUtils.hpp +++ b/src/ostd/math/MathUtils.hpp @@ -27,8 +27,8 @@ namespace ostd class MathUtils { public: - static float map_value(float input, float input_start, float input_end, float output_start, float output_end); + static f32 map_value(f32 input, f32 input_start, f32 input_end, f32 output_start, f32 output_end); //Implemented in - static int32_t solveIntegerExpression(const String& expr); + static i32 solveIntegerExpression(const String& expr); }; } diff --git a/src/ostd/math/Random.cpp b/src/ostd/math/Random.cpp index bf1013b..e3d648e 100755 --- a/src/ostd/math/Random.cpp +++ b/src/ostd/math/Random.cpp @@ -3,7 +3,7 @@ namespace ostd { - void RandomGenerator::seed(int64_t _seed) + void RandomGenerator::seed(i64 _seed) { m_engine.seed(_seed); m_noiseGen.SetSeed(_seed); @@ -17,89 +17,89 @@ namespace ostd m_noiseGen.SetSeed(m_seed); } - int64_t RandomGenerator::getSeed(void) + i64 RandomGenerator::getSeed(void) { return m_seed; } - float RandomGenerator::getf32(float min, float max) + f32 RandomGenerator::getf32(f32 min, f32 max) { - __swap_if_first_is_bigger(min, max); - std::uniform_real_distribution dist(min, max); + __swap_if_first_is_bigger(min, max); + std::uniform_real_distribution dist(min, max); return dist(m_engine); } - double RandomGenerator::getf64(double min, double max) + f64 RandomGenerator::getf64(f64 min, f64 max) { - __swap_if_first_is_bigger(min, max); - std::uniform_real_distribution dist(min, max); + __swap_if_first_is_bigger(min, max); + std::uniform_real_distribution dist(min, max); return dist(m_engine); } - uint64_t RandomGenerator::getui64(uint64_t min, uint64_t max) + u64 RandomGenerator::getui64(u64 min, u64 max) { - __swap_if_first_is_bigger(min, max); - std::uniform_int_distribution dist(min, max); + __swap_if_first_is_bigger(min, max); + std::uniform_int_distribution dist(min, max); return dist(m_engine); } - uint32_t RandomGenerator::getui32(uint32_t min, uint32_t max) + u32 RandomGenerator::getui32(u32 min, u32 max) { - __swap_if_first_is_bigger(min, max); - std::uniform_int_distribution dist(min, max); + __swap_if_first_is_bigger(min, max); + std::uniform_int_distribution dist(min, max); return dist(m_engine); } - uint16_t RandomGenerator::getui16(uint16_t min, uint16_t max) + u16 RandomGenerator::getui16(u16 min, u16 max) { - __swap_if_first_is_bigger(min, max); - std::uniform_int_distribution dist(min, max); + __swap_if_first_is_bigger(min, max); + std::uniform_int_distribution dist(min, max); return dist(m_engine); } - uint8_t RandomGenerator::getui8(uint8_t min, uint8_t max) + u8 RandomGenerator::getui8(u8 min, u8 max) { - __swap_if_first_is_bigger(min, max); - std::uniform_int_distribution dist(min, max); + __swap_if_first_is_bigger(min, max); + std::uniform_int_distribution dist(min, max); return dist(m_engine); } - int64_t RandomGenerator::geti64(int64_t min, int64_t max) + i64 RandomGenerator::geti64(i64 min, i64 max) { - __swap_if_first_is_bigger(min, max); - std::uniform_int_distribution dist(min, max); + __swap_if_first_is_bigger(min, max); + std::uniform_int_distribution dist(min, max); return dist(m_engine); } - int32_t RandomGenerator::geti32(int32_t min, int32_t max) + i32 RandomGenerator::geti32(i32 min, i32 max) { - __swap_if_first_is_bigger(min, max); - std::uniform_int_distribution dist(min, max); + __swap_if_first_is_bigger(min, max); + std::uniform_int_distribution dist(min, max); return dist(m_engine); } - int16_t RandomGenerator::geti16(int16_t min, int16_t max) + i16 RandomGenerator::geti16(i16 min, i16 max) { - __swap_if_first_is_bigger(min, max); - std::uniform_int_distribution dist(min, max); + __swap_if_first_is_bigger(min, max); + std::uniform_int_distribution dist(min, max); return dist(m_engine); } - int8_t RandomGenerator::geti8(int8_t min, int8_t max) + i8 RandomGenerator::geti8(i8 min, i8 max) { - __swap_if_first_is_bigger(min, max); - std::uniform_int_distribution dist(min, max); + __swap_if_first_is_bigger(min, max); + std::uniform_int_distribution dist(min, max); return dist(m_engine); } - bool RandomGenerator::getb(float true_percentage) + bool RandomGenerator::getb(f32 true_percentage) { return getf32() >= (1.0f - std::clamp(true_percentage, 0.0f, 1.0f)); } - Vec2 RandomGenerator::getVec2(float min, float max, bool match_xy) + Vec2 RandomGenerator::getVec2(f32 min, f32 max, bool match_xy) { - float x = getf32(min, max); + f32 x = getf32(min, max); return { x, (match_xy ? x : getf32(min, max)) }; } @@ -108,7 +108,7 @@ namespace ostd return { getf32(minmax_x.x, minmax_x.y), getf32(minmax_y.x, minmax_y.y) }; } - float RandomGenerator::getOpenSimplex2D(float x, float y) + f32 RandomGenerator::getOpenSimplex2D(f32 x, f32 y) { m_noiseGen.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2); return m_noiseGen.GetNoise(x, y); diff --git a/src/ostd/math/Random.hpp b/src/ostd/math/Random.hpp index 93e466e..6db1d23 100755 --- a/src/ostd/math/Random.hpp +++ b/src/ostd/math/Random.hpp @@ -31,33 +31,33 @@ namespace ostd { public: inline RandomGenerator(bool auto_seed = true) { if (auto_seed) autoSeed(); } - inline RandomGenerator(int64_t _seed) { seed(_seed); } + inline RandomGenerator(i64 _seed) { seed(_seed); } - void seed(int64_t _seed); + void seed(i64 _seed); void autoSeed(void); - int64_t getSeed(void); + i64 getSeed(void); - float getf32(float min = 0.0f, float max = 1.0f); - double getf64(double min = 0.0f, double max = 1.0f); - int64_t geti64(int64_t min = LLONG_MIN, int64_t max = LLONG_MAX); - int32_t geti32(int32_t min = INT_MIN, int32_t max = INT_MAX); - int16_t geti16(int16_t min = SHRT_MIN, int16_t max = SHRT_MAX); - int8_t geti8(int8_t min = CHAR_MIN, int8_t max = CHAR_MAX); - uint64_t getui64(uint64_t min = 0, uint64_t max = ULLONG_MAX); - uint32_t getui32(uint32_t min = 0, uint32_t max = UINT_MAX); - uint16_t getui16(uint16_t min = 0, uint16_t max = USHRT_MAX); - uint8_t getui8(uint8_t min = 0, uint8_t max = UCHAR_MAX); - bool getb(float true_percentage = 0.5f); - Vec2 getVec2(float min = 0.0f, float max = 1.0f, bool match_xy = false); + f32 getf32(f32 min = 0.0f, f32 max = 1.0f); + f64 getf64(f64 min = 0.0f, f64 max = 1.0f); + i64 geti64(i64 min = LLONG_MIN, i64 max = LLONG_MAX); + i32 geti32(i32 min = INT_MIN, i32 max = INT_MAX); + i16 geti16(i16 min = SHRT_MIN, i16 max = SHRT_MAX); + i8 geti8(i8 min = CHAR_MIN, i8 max = CHAR_MAX); + u64 getui64(u64 min = 0, u64 max = ULLONG_MAX); + u32 getui32(u32 min = 0, u32 max = UINT_MAX); + u16 getui16(u16 min = 0, u16 max = USHRT_MAX); + u8 getui8(u8 min = 0, u8 max = UCHAR_MAX); + bool getb(f32 true_percentage = 0.5f); + Vec2 getVec2(f32 min = 0.0f, f32 max = 1.0f, bool match_xy = false); Vec2 getVec2(Vec2 minmax_x = { 0.0f, 1.0f }, Vec2 minmax_y = { 0.0f, 1.0f }); - float getOpenSimplex2D(float x, float y); + f32 getOpenSimplex2D(f32 x, f32 y); inline FastNoiseLite& getNoiseGenerator(void) { return m_noiseGen; } template - inline T& getFromStdVec(std::vector& list) + inline T& getFromStdVec(stdvec& list) { - uint64_t index = static_cast(geti64(0, list.size())); + u64 index = cast(geti64(0, list.size())); return list[index]; } @@ -72,7 +72,7 @@ namespace ostd } private: - int64_t m_seed { 0 }; + i64 m_seed { 0 }; std::mt19937_64 m_engine; FastNoiseLite m_noiseGen; }; @@ -80,27 +80,27 @@ namespace ostd class Random { public: - inline static void seed(int64_t _seed) { Random::s_gen.seed(_seed); } + inline static void seed(i64 _seed) { Random::s_gen.seed(_seed); } inline static void autoSeed(void) { Random::s_gen.autoSeed(); } - inline static int64_t getSeed(void) { return Random::s_gen.getSeed(); } + inline static i64 getSeed(void) { return Random::s_gen.getSeed(); } - inline static float getf32(float min = 0.0f, float max = 1.0f) { return Random::s_gen.getf32(min, max); } - inline static double getf64(double min = 0.0f, double max = 1.0f) { return Random::s_gen.getf64(min, max); } - inline static int64_t geti64(int64_t min = LLONG_MIN, int64_t max = LLONG_MAX) { return Random::s_gen.geti64(min, max); } - inline static int32_t geti32(int32_t min = INT_MIN, int32_t max = INT_MAX) { return Random::s_gen.geti32(min, max); } - inline static int16_t geti16(int16_t min = SHRT_MIN, int16_t max = SHRT_MAX) { return Random::s_gen.geti16(min, max); } - inline static int8_t geti8(int8_t min = CHAR_MIN, int8_t max = CHAR_MAX) { return Random::s_gen.geti8(min, max); } - inline static uint64_t getui64(uint64_t min = 0, uint64_t max = ULLONG_MAX) { return Random::s_gen.getui64(min, max); } - inline static uint32_t getui32(uint32_t min = 0, uint32_t max = UINT_MAX) { return Random::s_gen.getui32(min, max); } - inline static uint16_t getui16(uint16_t min = 0, uint16_t max = USHRT_MAX) { return Random::s_gen.getui16(min, max); } - inline static uint8_t getui8(uint8_t min = 0, uint8_t max = UCHAR_MAX) { return Random::s_gen.getui8(min, max); } - inline static bool getb(float true_percentage = 0.5f) { return Random::s_gen.getb(true_percentage); } - inline static Vec2 getVec2(float min = 0.0f, float max = 1.0f, bool match_xy = false) { return Random::s_gen.getVec2(min, max, match_xy); } + inline static f32 getf32(f32 min = 0.0f, f32 max = 1.0f) { return Random::s_gen.getf32(min, max); } + inline static f64 getf64(f64 min = 0.0f, f64 max = 1.0f) { return Random::s_gen.getf64(min, max); } + inline static i64 geti64(i64 min = LLONG_MIN, i64 max = LLONG_MAX) { return Random::s_gen.geti64(min, max); } + inline static i32 geti32(i32 min = INT_MIN, i32 max = INT_MAX) { return Random::s_gen.geti32(min, max); } + inline static i16 geti16(i16 min = SHRT_MIN, i16 max = SHRT_MAX) { return Random::s_gen.geti16(min, max); } + inline static i8 geti8(i8 min = CHAR_MIN, i8 max = CHAR_MAX) { return Random::s_gen.geti8(min, max); } + inline static u64 getui64(u64 min = 0, u64 max = ULLONG_MAX) { return Random::s_gen.getui64(min, max); } + inline static u32 getui32(u32 min = 0, u32 max = UINT_MAX) { return Random::s_gen.getui32(min, max); } + inline static u16 getui16(u16 min = 0, u16 max = USHRT_MAX) { return Random::s_gen.getui16(min, max); } + inline static u8 getui8(u8 min = 0, u8 max = UCHAR_MAX) { return Random::s_gen.getui8(min, max); } + inline static bool getb(f32 true_percentage = 0.5f) { return Random::s_gen.getb(true_percentage); } + inline static Vec2 getVec2(f32 min = 0.0f, f32 max = 1.0f, bool match_xy = false) { return Random::s_gen.getVec2(min, max, match_xy); } inline static Vec2 getVec2(Vec2 minmax_x = { 0.0f, 1.0f }, Vec2 minmax_y = { 0.0f, 1.0f }) { return Random::s_gen.getVec2(minmax_x, minmax_y); } - inline static float getOpenSimplex2D(float x, float y) { return Random::s_gen.getOpenSimplex2D(x, y); } + inline static f32 getOpenSimplex2D(f32 x, f32 y) { return Random::s_gen.getOpenSimplex2D(x, y); } template - inline static T& getFromStdVec(std::vector& list) { return Random::s_gen.getFromStdVec(list); } + inline static T& getFromStdVec(stdvec& list) { return Random::s_gen.getFromStdVec(list); } private: inline static RandomGenerator s_gen; diff --git a/src/ostd/math/ShuntingYard.cpp b/src/ostd/math/ShuntingYard.cpp index ed8259b..5d29e6e 100644 --- a/src/ostd/math/ShuntingYard.cpp +++ b/src/ostd/math/ShuntingYard.cpp @@ -1,7 +1,7 @@ #include "MathUtils.hpp" #include "../string/String.hpp" #include -#include + #include #include #include @@ -25,7 +25,7 @@ namespace ostd Token(Type type, const std::string& s, - int precedence = -1, + i32 precedence = -1, bool rightAssociative = false, bool unary = false ) @@ -38,7 +38,7 @@ namespace ostd const Type type; const std::string str; - const int precedence; + const i32 precedence; const bool rightAssociative; const bool unary; }; @@ -95,13 +95,13 @@ namespace ostd exit(0); return {}; } - int64_t tmpInt = String(s).toInt(); + i64 tmpInt = String(s).toInt(); //------------------------------------------------- tokens.push_back(Token { Token::Type::Number, String().add(tmpInt) }); --p; } else { Token::Type t = Token::Type::Unknown; - int precedence = -1; + i32 precedence = -1; bool rightAssociative = false; bool unary = false; char c = *p; @@ -145,7 +145,7 @@ namespace ostd std::deque shuntingYard(const std::deque& tokens) { std::deque queue; - std::vector stack; + stdvec stack; // While there are tokens to be read: for(auto token : tokens) { @@ -253,15 +253,15 @@ namespace ostd return queue; } - int32_t MathUtils::solveIntegerExpression(const String& expr) + i32 MathUtils::solveIntegerExpression(const String& expr) { // printf("Tokenize\n"); // printf(reportFmt, "Token", "Queue", "Stack", ""); const auto tokens = exprToTokens(expr); auto queue = shuntingYard(tokens); - std::vector stack; + stdvec stack; - // printf("\nCalculation\n"); + // pri32f("\nCalculation\n"); // printf(reportFmt, "Token", "Queue", "Stack", ""); while(! queue.empty()) { @@ -304,7 +304,7 @@ namespace ostd exit(0); break; case '^': - stack.push_back(static_cast(pow(lhs, rhs))); + stack.push_back(cast(pow(lhs, rhs))); break; case '*': stack.push_back(lhs * rhs); diff --git a/src/ostd/math/SineWave.cpp b/src/ostd/math/SineWave.cpp index 7bfcce9..859e9aa 100755 --- a/src/ostd/math/SineWave.cpp +++ b/src/ostd/math/SineWave.cpp @@ -2,9 +2,9 @@ namespace ostd { - float AdditiveWave::evaluate(float x) + f32 AdditiveWave::evaluate(f32 x) { - float y = 0.0f; + f32 y = 0.0f; for (auto& wave : waves) y += wave.evaluate(x); for (auto& wave : additiveWaves) diff --git a/src/ostd/math/SineWave.hpp b/src/ostd/math/SineWave.hpp index c00edee..070189e 100755 --- a/src/ostd/math/SineWave.hpp +++ b/src/ostd/math/SineWave.hpp @@ -20,7 +20,6 @@ #pragma once -#include #include #include @@ -30,14 +29,14 @@ namespace ostd { public: inline SineWave(void) { period = 1.0f; phase = 0.0f; amplitude = 1.0f; } - inline SineWave(float pr, float am, float ph = 0.0f) { set(pr, am, ph); } - inline SineWave& set(float pr, float am, float ph = 0.0f) { period = pr; phase = ph; amplitude = am; return *this; } - inline float evaluate(float x) { return std::sin(phase + TWO_PI * x / period) * amplitude; } + inline SineWave(f32 pr, f32 am, f32 ph = 0.0f) { set(pr, am, ph); } + inline SineWave& set(f32 pr, f32 am, f32 ph = 0.0f) { period = pr; phase = ph; amplitude = am; return *this; } + inline f32 evaluate(f32 x) { return std::sin(phase + TWO_PI * x / period) * amplitude; } public: - float period; - float phase; - float amplitude; + f32 period; + f32 phase; + f32 amplitude; }; class AdditiveWave : public SineWave @@ -46,10 +45,10 @@ namespace ostd inline AdditiveWave(void) { waves.clear(); } inline AdditiveWave& addWave(SineWave wave) { waves.push_back(wave); return *this; } inline AdditiveWave& addWave(AdditiveWave wave) { additiveWaves.push_back(wave); return *this; } - float evaluate(float x); + f32 evaluate(f32 x); public: - std::vector waves; - std::vector additiveWaves; + stdvec waves; + stdvec additiveWaves; }; } diff --git a/src/ostd/math/Spline.cpp b/src/ostd/math/Spline.cpp index 817d0f8..ae2b4ab 100755 --- a/src/ostd/math/Spline.cpp +++ b/src/ostd/math/Spline.cpp @@ -16,10 +16,10 @@ namespace ostd // } // if (signal.ID == BuiltinSignals::MousePressed) // { - // ogfx::MouseEventData& evt = static_cast(signal.userData); + // ogfx::MouseEventData& evt = cast(signal.userData); // for (auto& node : m_points) // { - // if (ostd::Rectangle(node.position.x - 20, node.position.y - 20, 40, 40).contains((float)evt.position_x, (float)evt.position_y)) + // if (ostd::Rectangle(node.position.x - 20, node.position.y - 20, 40, 40).contains((f32)evt.position_x, (f32)evt.position_y)) // { // m_selectedNode = &node; // return; @@ -34,91 +34,91 @@ namespace ostd // } // else if (signal.ID == BuiltinSignals::MouseMoved) // { - // ogfx::MouseEventData& evt = static_cast(signal.userData); + // ogfx::MouseEventData& evt = cast(signal.userData); // if (m_selectedNode != nullptr) - // m_selectedNode->position = { (float)evt.position_x, (float)evt.position_y }; + // m_selectedNode->position = { (f32)evt.position_x, (f32)evt.position_y }; // } } - tSplineNode Spline::getPoint(float t) + tSplineNode Spline::getPoint(f32 t) { - int32_t p0, p1, p2, p3; + i32 p0, p1, p2, p3; if (!isLooping()) { - p1 = (int32_t)t + 1; + p1 = (i32)t + 1; p2 = p1 + 1; p3 = p2 + 1; p0 = p1 - 1; } else { - p1 = (int32_t)t; + p1 = (i32)t; p2 = (p1 + 1) % m_points.size(); p3 = (p2 + 1) % m_points.size(); p0 = p1 >= 1 ? p1 - 1 : m_points.size() - 1; } - t = t - (int32_t)t; + t = t - (i32)t; - float tt = t * t; - float ttt = tt * t; + f32 tt = t * t; + f32 ttt = tt * t; - float q1 = -ttt + 2.0f*tt - t; - float q2 = 3.0f*ttt - 5.0f*tt + 2.0f; - float q3 = -3.0f*ttt + 4.0f*tt + t; - float q4 = ttt - tt; + f32 q1 = -ttt + 2.0f*tt - t; + f32 q2 = 3.0f*ttt - 5.0f*tt + 2.0f; + f32 q3 = -3.0f*ttt + 4.0f*tt + t; + f32 q4 = ttt - tt; - float tx = 0.5f * (m_points[p0].position.x * q1 + m_points[p1].position.x * q2 + m_points[p2].position.x * q3 + m_points[p3].position.x * q4); - float ty = 0.5f * (m_points[p0].position.y * q1 + m_points[p1].position.y * q2 + m_points[p2].position.y * q3 + m_points[p3].position.y * q4); + f32 tx = 0.5f * (m_points[p0].position.x * q1 + m_points[p1].position.x * q2 + m_points[p2].position.x * q3 + m_points[p3].position.x * q4); + f32 ty = 0.5f * (m_points[p0].position.y * q1 + m_points[p1].position.y * q2 + m_points[p2].position.y * q3 + m_points[p3].position.y * q4); return { { tx, ty }, 0.0f }; } - tSplineNode Spline::getGradient(float t) + tSplineNode Spline::getGradient(f32 t) { - int32_t p0, p1, p2, p3; + i32 p0, p1, p2, p3; if (!isLooping()) { - p1 = (int32_t)t + 1; + p1 = (i32)t + 1; p2 = p1 + 1; p3 = p2 + 1; p0 = p1 - 1; } else { - p1 = (int32_t)t; + p1 = (i32)t; p2 = (p1 + 1) % m_points.size(); p3 = (p2 + 1) % m_points.size(); p0 = p1 >= 1 ? p1 - 1 : m_points.size() - 1; } - t = t - (int32_t)t; + t = t - (i32)t; - float tt = t * t; - float ttt = tt * t; + f32 tt = t * t; + f32 ttt = tt * t; - float q1 = -3.0f * tt + 4.0f*t - 1; - float q2 = 9.0f*tt - 10.0f*t; - float q3 = -9.0f*tt + 8.0f*t + 1.0f; - float q4 = 3.0f*tt - 2.0f*t; + f32 q1 = -3.0f * tt + 4.0f*t - 1; + f32 q2 = 9.0f*tt - 10.0f*t; + f32 q3 = -9.0f*tt + 8.0f*t + 1.0f; + f32 q4 = 3.0f*tt - 2.0f*t; - float tx = 0.5f * (m_points[p0].position.x * q1 + m_points[p1].position.x * q2 + m_points[p2].position.x * q3 + m_points[p3].position.x * q4); - float ty = 0.5f * (m_points[p0].position.y * q1 + m_points[p1].position.y * q2 + m_points[p2].position.y * q3 + m_points[p3].position.y * q4); + f32 tx = 0.5f * (m_points[p0].position.x * q1 + m_points[p1].position.x * q2 + m_points[p2].position.x * q3 + m_points[p3].position.x * q4); + f32 ty = 0.5f * (m_points[p0].position.y * q1 + m_points[p1].position.y * q2 + m_points[p2].position.y * q3 + m_points[p3].position.y * q4); return { { tx, ty }, 0.0f }; } - float Spline::updateSegmentLength(int32_t node) + f32 Spline::updateSegmentLength(i32 node) { - float fLength = 0.0f; - float fStepSize = 0.005; + f32 fLength = 0.0f; + f32 fStepSize = 0.005; tSplineNode old_point, new_point; - old_point = getPoint((float)node); + old_point = getPoint((f32)node); - for (float t = 0; t < 1.0f; t += fStepSize) + for (f32 t = 0; t < 1.0f; t += fStepSize) { - new_point = getGradient((float)node + t); + new_point = getGradient((f32)node + t); fLength += std::sqrt((new_point.position.x - old_point.position.x)*(new_point.position.x - old_point.position.x) + (new_point.position.y - old_point.position.y)*(new_point.position.y - old_point.position.y)); old_point = new_point; @@ -126,15 +126,15 @@ namespace ostd return fLength; } - float Spline::getNormalisedOffset(float p) + f32 Spline::getNormalisedOffset(f32 p) { - int32_t i = 0; + i32 i = 0; while (p > m_points[i].length) { p -= m_points[i].length; i++; } - return (float)i + (p / m_points[i].length); + return (f32)i + (p / m_points[i].length); } void Spline::connectSignals(void) @@ -149,7 +149,7 @@ namespace ostd void Spline::updateTotalLength(void) { m_totalLength = 0.0f; - for (int i = 0; i < m_points.size(); i++) + for (i32 i = 0; i < m_points.size(); i++) { m_totalLength += (m_points[i].length = updateSegmentLength(i)); } diff --git a/src/ostd/math/Spline.hpp b/src/ostd/math/Spline.hpp index 2f380ba..88e5a64 100755 --- a/src/ostd/math/Spline.hpp +++ b/src/ostd/math/Spline.hpp @@ -29,33 +29,33 @@ namespace ostd struct tSplineNode { Vec2 position; - float length; + f32 length; }; class Spline : public BaseObject { public: using EventHandlerCallback = std::function; - using DrawCallback = std::function; + using DrawCallback = std::function; public: Spline(void); void handleSignal(Signal& signal) override; - tSplineNode getPoint(float t); - tSplineNode getGradient(float t); - float updateSegmentLength(int32_t node); - float getNormalisedOffset(float p); + tSplineNode getPoint(f32 t); + tSplineNode getGradient(f32 t); + f32 updateSegmentLength(i32 node); + f32 getNormalisedOffset(f32 p); void connectSignals(void); void updateTotalLength(void); - inline void draw(float resolution = 0.01f, float lineWidth = 4.0f, float controlPointSize = 9.0f) { if (m_drawCallback) m_drawCallback(resolution, lineWidth, controlPointSize); } + inline void draw(f32 resolution = 0.01f, f32 lineWidth = 4.0f, f32 controlPointSize = 9.0f) { if (m_drawCallback) m_drawCallback(resolution, lineWidth, controlPointSize); } inline bool exists(void) { return m_points.size() > 1; } inline void addPoint(Vec2 position) { m_points.push_back({ position, 0.0f }); updateTotalLength(); } - inline float getTotalLength(void) { return m_totalLength; } + inline f32 getTotalLength(void) { return m_totalLength; } inline bool isEditable(void) { return m_editable; } inline bool isLooping(void) { return m_looping; } inline void setEditable(bool e) { m_editable = e; } inline void setLooping(bool l) { m_looping = l; } - inline uint32_t getPointCount(void) { return m_points.size(); } + inline u32 getPointCount(void) { return m_points.size(); } inline void clear(void) { m_points.clear(); } inline bool isEnabled(void) { return m_enabled; } inline void enable(bool e = true) { m_enabled = e; } @@ -64,8 +64,8 @@ namespace ostd inline void setDrawCallback(DrawCallback drawCallback) { m_drawCallback = drawCallback; } protected: - std::vector m_points; - float m_totalLength = 0.0f; + stdvec m_points; + f32 m_totalLength = 0.0f; tSplineNode* m_selectedNode { nullptr }; bool m_editable { false }; bool m_looping { true }; diff --git a/src/ostd/string/String.cpp b/src/ostd/string/String.cpp index ab2bfd9..411eb29 100644 --- a/src/ostd/string/String.cpp +++ b/src/ostd/string/String.cpp @@ -22,7 +22,7 @@ namespace ostd String& String::ltrim(void) { - m_data.erase(m_data.begin(), std::find_if(m_data.begin(), m_data.end(), [](unsigned char ch) { + m_data.erase(m_data.begin(), std::find_if(m_data.begin(), m_data.end(), [](uchar ch) { return !std::isspace(ch); })); return *this; @@ -30,7 +30,7 @@ namespace ostd String& String::rtrim(void) { - m_data.erase(std::find_if(m_data.rbegin(), m_data.rend(), [](unsigned char ch) { + m_data.erase(std::find_if(m_data.rbegin(), m_data.rend(), [](uchar ch) { return !std::isspace(ch); }).base(), m_data.end()); return *this; @@ -43,22 +43,22 @@ namespace ostd String& String::toLower(void) { - std::transform(m_data.begin(), m_data.end(), m_data.begin(), [](unsigned char c){ return std::tolower(c); }); + std::transform(m_data.begin(), m_data.end(), m_data.begin(), [](uchar c){ return std::tolower(c); }); return *this; } String& String::toUpper(void) { - std::transform(m_data.begin(), m_data.end(), m_data.begin(), [](unsigned char c){ return std::toupper(c); }); + std::transform(m_data.begin(), m_data.end(), m_data.begin(), [](uchar c){ return std::toupper(c); }); return *this; } - String& String::addPadding(uint32_t new_string_length, char c, ePaddingBehavior padding_behavior) + String& String::addPadding(u32 new_string_length, char c, ePaddingBehavior padding_behavior) { if (len() - 1 >= new_string_length) return *this; - uint32_t diff = new_string_length - len(); - int32_t leftPadding = 0; - int32_t rightPadding = 0; + u32 diff = new_string_length - len(); + i32 leftPadding = 0; + i32 rightPadding = 0; switch (padding_behavior) { case ePaddingBehavior::ForceEvenNegative: @@ -96,7 +96,7 @@ namespace ostd return addLeftPadding(len() + leftPadding, c).addRightPadding(len() + rightPadding, c); } - String& String::addLeftPadding(uint32_t new_string_length, char c) + String& String::addLeftPadding(u32 new_string_length, char c) { reverse(); while (len() < new_string_length) @@ -105,7 +105,7 @@ namespace ostd return *this; } - String& String::addRightPadding(uint32_t new_string_length, char c) + String& String::addRightPadding(u32 new_string_length, char c) { while (len() < new_string_length) m_data += c; @@ -127,7 +127,7 @@ namespace ostd String& String::replaceFirst(const String& what, const String& with) { - int32_t index = indexOf(what); + i32 index = indexOf(what); if (index == -1) return *this; m_data.replace(index, what.len(), with.cpp_str()); return *this; @@ -149,26 +149,26 @@ namespace ostd return *this; } - String& String::put(uint32_t index, char c) + String& String::put(u32 index, char c) { if (index < m_data.length()) m_data[index] = c; return *this; } - String& String::substr(uint32_t start, int32_t end) + String& String::substr(u32 start, i32 end) { if (end < 0) m_data = m_data.substr(start); else m_data = m_data.substr(start, end - start); return *this; } - String& String::fixedLength(uint32_t length, char fill_character, const String& truncate_indicator) + String& String::fixedLength(u32 length, char fill_character, const String& truncate_indicator) { if (length < truncate_indicator.len()) return *this; if (len() > length) { - int32_t tr_len = truncate_indicator.len(); + i32 tr_len = truncate_indicator.len(); substr(0, length - tr_len); return add(truncate_indicator); } @@ -190,55 +190,55 @@ namespace ostd return *this; } - String& String::add(uint8_t i) + String& String::add(u8 i) { m_data += std::to_string(i); return *this; } - String& String::add(int8_t i) + String& String::add(i8 i) { m_data += std::to_string(i); return *this; } - String& String::add(uint16_t i) + String& String::add(u16 i) { m_data += std::to_string(i); return *this; } - String& String::add(int16_t i) + String& String::add(i16 i) { m_data += std::to_string(i); return *this; } - String& String::add(uint32_t i) + String& String::add(u32 i) { m_data += std::to_string(i); return *this; } - String& String::add(int32_t i) + String& String::add(i32 i) { m_data += std::to_string(i); return *this; } - String& String::add(uint64_t i) + String& String::add(u64 i) { m_data += std::to_string(i); return *this; } - String& String::add(int64_t i) + String& String::add(i64 i) { m_data += std::to_string(i); return *this; } - String& String::add(float f, uint8_t precision) + String& String::add(f32 f, u8 precision) { std::stringstream stream; if (precision != 0) @@ -249,7 +249,7 @@ namespace ostd return add(s); } - String& String::add(double f, uint8_t precision) + String& String::add(f64 f, u8 precision) { std::stringstream stream; if (precision != 0) @@ -293,19 +293,19 @@ namespace ostd return __str.toUpper(); } - String String::new_addPadding(uint32_t new_string_length, char c, ePaddingBehavior padding_behavior) const + String String::new_addPadding(u32 new_string_length, char c, ePaddingBehavior padding_behavior) const { String __str = m_data; return __str.addPadding(new_string_length, c, padding_behavior); } - String String::new_addLeftPadding(uint32_t new_string_length, char c) const + String String::new_addLeftPadding(u32 new_string_length, char c) const { String __str = m_data; return __str.addLeftPadding(new_string_length, c); } - String String::new_addRightPadding(uint32_t new_string_length, char c) const + String String::new_addRightPadding(u32 new_string_length, char c) const { String __str = m_data; return __str.addRightPadding(new_string_length, c); @@ -335,19 +335,19 @@ namespace ostd return __str.regexReplace(regex_pattern, replace_with, case_insensitive); } - String String::new_put(uint32_t index, char c) const + String String::new_put(u32 index, char c) const { String __str = m_data; return __str.put(index, c); } - String String::new_substr(uint32_t start, int32_t end) const + String String::new_substr(u32 start, i32 end) const { String __str = m_data; return __str.substr(start, end); } - String String::new_fixedLength(uint32_t length, char fill_character, const String& truncate_indicator) const + String String::new_fixedLength(u32 length, char fill_character, const String& truncate_indicator) const { String __str = m_data; return __str.fixedLength(length, fill_character, truncate_indicator); @@ -366,61 +366,61 @@ namespace ostd return __str.add(se); } - String String::new_add(uint8_t i) const + String String::new_add(u8 i) const { String __str = m_data; return __str.add(i); } - String String::new_add(int8_t i) const + String String::new_add(i8 i) const { String __str = m_data; return __str.add(i); } - String String::new_add(uint16_t i) const + String String::new_add(u16 i) const { String __str = m_data; return __str.add(i); } - String String::new_add(int16_t i) const + String String::new_add(i16 i) const { String __str = m_data; return __str.add(i); } - String String::new_add(uint32_t i) const + String String::new_add(u32 i) const { String __str = m_data; return __str.add(i); } - String String::new_add(int32_t i) const + String String::new_add(i32 i) const { String __str = m_data; return __str.add(i); } - String String::new_add(uint64_t i) const + String String::new_add(u64 i) const { String __str = m_data; return __str.add(i); } - String String::new_add(int64_t i) const + String String::new_add(i64 i) const { String __str = m_data; return __str.add(i); } - String String::new_add(float f, uint8_t precision) const + String String::new_add(f32 f, u8 precision) const { String __str = m_data; return __str.add(f, precision); } - String String::new_add(double f, uint8_t precision) const + String String::new_add(f64 f, u8 precision) const { String __str = m_data; return __str.add(f, precision); @@ -429,12 +429,12 @@ namespace ostd //Utility - int64_t String::toInt(void) const + i64 String::toInt(void) const { if (!isNumeric(false)) return 0; - ostd::String str = String(m_data).trim().toLower(); + String str = String(m_data).trim().toLower(); if (!str.isInt()) return 0; - int32_t base = 10; + i32 base = 10; if (str.cpp_str().rfind("0x", 0) == 0) { str = str.substr(2); @@ -448,13 +448,13 @@ namespace ostd return strtoul(str.c_str(), NULL, base); } - float String::toFloat(void) const + f32 String::toFloat(void) const { if (!isNumeric(true)) return 0; return std::stof(m_data); } - double String::toDouble(void) const + f64 String::toDouble(void) const { if (!isNumeric(true)) return 0; return std::stod(m_data); @@ -465,7 +465,7 @@ namespace ostd if (decimal) { std::istringstream iss(m_data); - double f; + f64 f; iss >> std::noskipws >> f; return iss.eof() && !iss.fail(); } @@ -474,20 +474,20 @@ namespace ostd bool String::isInt(void) const { - ostd::String str = String(m_data).trim().toLower(); + String str = String(m_data).trim().toLower(); bool isNumber = std::ranges::all_of(str.begin(), str.end(), [](char c){ return isdigit(c) != 0; }); return str.isHex() || str.isBin() || isNumber; } bool String::isHex(void) const { - ostd::String hex = String(m_data).trim().toLower(); + String hex = String(m_data).trim().toLower(); return hex.cpp_str().compare(0, 2, "0x") == 0 && hex.cpp_str().size() > 2 && hex.cpp_str().find_first_not_of("0123456789abcdef", 2) == std::string::npos; } bool String::isBin(void) const { - ostd::String bin = String(m_data).trim().toLower(); + String bin = String(m_data).trim().toLower(); return bin.cpp_str().compare(0, 2, "0b") == 0 && bin.cpp_str().size() > 2 && bin.cpp_str().find_first_not_of("01", 2) == std::string::npos; } @@ -513,56 +513,56 @@ namespace ostd bool String::regexMatches(const String& regex_pattern, bool case_insensitive) const { - try - { - boost::regex rgx(regex_pattern.cpp_str(), case_insensitive ? boost::regex_constants::icase : boost::regex_constants::normal); - return boost::regex_search(m_data, rgx); - } - catch (const boost::regex_error& err) - { - std::cerr << err.what() << '\n'; //TODO: Better error handling - return false; - } + try + { + boost::regex rgx(regex_pattern.cpp_str(), case_insensitive ? boost::regex_constants::icase : boost::regex_constants::normal); + return boost::regex_search(m_data, rgx); + } + catch (const boost::regex_error& err) + { + std::cerr << err.what() << '\n'; //TODO: Better error handling + return false; + } } - uint32_t String::count(const String& str) const + u32 String::count(const String& str) const { Tokens tok = tokenize(str, false, true); if (tok.count() < 1) return 0; return tok.count() - 1; } - int32_t String::indexOf(char c, uint32_t start) const + i32 String::indexOf(char c, u32 start) const { cpp_string cc = ""; cc += c; - int32_t pos = m_data.find(cc.c_str(), start); + i32 pos = m_data.find(cc.c_str(), start); if (pos == std::string::npos) return -1; return pos; } - int32_t String::indexOf(const String& str, uint32_t start) const + i32 String::indexOf(const String& str, u32 start) const { - int32_t pos = m_data.find(str.c_str(), start); + i32 pos = m_data.find(str.c_str(), start); if (pos == std::string::npos) return -1; return pos; } - int32_t String::lastIndexOf(char c) const + i32 String::lastIndexOf(char c) const { String se(m_data); se.reverse(); - int32_t pos = se.indexOf(c); + i32 pos = se.indexOf(c); if (pos < 0) return -1; return len() - pos - 1; } - int32_t String::lastIndexOf(const String& str) const + i32 String::lastIndexOf(const String& str) const { String se(m_data); se.reverse(); String se2(str); - int32_t pos = se.indexOf(se2.new_reverse()); + i32 pos = se.indexOf(se2.new_reverse()); if (pos < 0) return -1; return len() - pos - str.len(); } @@ -570,8 +570,8 @@ namespace ostd String::Tokens String::tokenize(const String& delimiter, bool trim_tokens, bool allow_white_space_only_tokens) const { Tokens tokens; - int32_t sindex = 0; - int32_t eindex = 0; + i32 sindex = 0; + i32 eindex = 0; String __token = ""; while ((eindex = indexOf(delimiter, sindex)) != -1) { @@ -608,91 +608,91 @@ namespace ostd return tokens; } - String String::getHexStr(uint64_t value, bool prefix, uint8_t nbytes) + String String::getHexStr(u64 value, bool prefix, u8 nbytes) { union { - uint64_t val; - uint8_t bytes[8]; + u64 val; + u8 bytes[8]; } __tmp_editor; __tmp_editor.val = value; if (nbytes < 1 || nbytes > 8) nbytes = 1; std::ostringstream oss; if (prefix) oss << "0x"; - for (int8_t b = nbytes - 1; b >= 0; b--) - oss << std::setw(2) << std::setfill('0') << std::uppercase << std::hex << (int)__tmp_editor.bytes[b]; + for (i8 b = nbytes - 1; b >= 0; b--) + oss << std::setw(2) << std::setfill('0') << std::uppercase << std::hex << (i32)__tmp_editor.bytes[b]; return oss.str(); } - String String::getBinStr(uint64_t value, bool prefix, uint8_t nbytes) + String String::getBinStr(u64 value, bool prefix, u8 nbytes) { union { - uint64_t val; - uint8_t bytes[8]; + u64 val; + u8 bytes[8]; } __tmp_editor; __tmp_editor.val = value; if (nbytes < 1 || nbytes > 8) nbytes = 1; std::ostringstream oss; if (prefix) oss << "0b "; - for (int8_t b = nbytes - 1; b >= 0; b--) + for (i8 b = nbytes - 1; b >= 0; b--) oss << std::bitset<8>((char)__tmp_editor.bytes[b]) << " "; return oss.str(); } - String String::duplicateChar(unsigned char c, uint16_t count) + String String::duplicateChar(uchar c, u16 count) { String str = ""; - for (uint16_t i = 0; i < count; i++) + for (u16 i = 0; i < count; i++) str = str += c; return str; } - std::vector String::decodeUTF8(const ostd::String& s) + stdvec String::decodeUTF8(const String& s) { - std::vector out; - const char* p = s.m_data.data(); - const char* end = p + s.m_data.size(); + stdvec out; + const char* p = s.m_data.data(); + const char* end = p + s.m_data.size(); - while (p < end) - out.push_back(utf8_next(p, end)); + while (p < end) + out.push_back(utf8_next(p, end)); - return out; + return out; } - uint32_t String::utf8_next(const char*& p, const char* end) + u32 String::utf8_next(const char*& p, const char* end) { - uint8_t c = static_cast(*p++); + u8 c = cast(*p++); - // ASCII fast path - if (c < 0x80) - return c; + // ASCII fast path + if (c < 0x80) + return c; - // 2-byte sequence - if ((c >> 5) == 0x6) { - uint32_t cp = (c & 0x1F) << 6; - cp |= (static_cast(*p++) & 0x3F); - return cp; - } + // 2-byte sequence + if ((c >> 5) == 0x6) { + u32 cp = (c & 0x1F) << 6; + cp |= (cast(*p++) & 0x3F); + return cp; + } - // 3-byte sequence - if ((c >> 4) == 0xE) { - uint32_t cp = (c & 0x0F) << 12; - cp |= (static_cast(*p++) & 0x3F) << 6; - cp |= (static_cast(*p++) & 0x3F); - return cp; - } + // 3-byte sequence + if ((c >> 4) == 0xE) { + u32 cp = (c & 0x0F) << 12; + cp |= (cast(*p++) & 0x3F) << 6; + cp |= (cast(*p++) & 0x3F); + return cp; + } - // 4-byte sequence - if ((c >> 3) == 0x1E) { - uint32_t cp = (c & 0x07) << 18; - cp |= (static_cast(*p++) & 0x3F) << 12; - cp |= (static_cast(*p++) & 0x3F) << 6; - cp |= (static_cast(*p++) & 0x3F); - return cp; - } + // 4-byte sequence + if ((c >> 3) == 0x1E) { + u32 cp = (c & 0x07) << 18; + cp |= (cast(*p++) & 0x3F) << 12; + cp |= (cast(*p++) & 0x3F) << 6; + cp |= (cast(*p++) & 0x3F); + return cp; + } - // Invalid byte → return replacement character - return 0xFFFD; + // Invalid byte → return replacement character + return 0xFFFD; } String operator+(const cpp_string& str1, const String& str) diff --git a/src/ostd/string/String.hpp b/src/ostd/string/String.hpp index 0f5c389..1f26975 100644 --- a/src/ostd/string/String.hpp +++ b/src/ostd/string/String.hpp @@ -1,21 +1,21 @@ /* - OmniaFramework - A collection of useful functionality - Copyright (C) 2025 OmniaX-Dev + OmniaFramework - A collection of useful functionality + Copyright (C) 2025 OmniaX-Dev - This file is part of OmniaFramework. + This file is part of OmniaFramework. - OmniaFramework is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + OmniaFramework is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - OmniaFramework is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + OmniaFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with OmniaFramework. If not, see . + You should have received a copy of the GNU General Public License + along with OmniaFramework. If not, see . */ #pragma once @@ -38,9 +38,9 @@ namespace ostd inline bool hasPrevious(void) { return m_tokens.size() > 0 && m_current_index > 0; } String next(void); String previous(void); - inline uint32_t count(void) { return m_tokens.size(); } - inline std::vector getRawData(void) { return m_tokens; } - inline uint32_t getCurrentIndex(void) { return m_current_index; } + inline u32 count(void) { return m_tokens.size(); } + inline stdvec getRawData(void) { return m_tokens; } + inline u32 getCurrentIndex(void) { return m_current_index; } inline void cycle(void) { m_current_index = 0; } inline auto begin(void) { return m_tokens.begin(); } @@ -54,8 +54,8 @@ namespace ostd inline Tokens(void) { m_current_index = 0; } private: - std::vector m_tokens; - uint32_t m_current_index; + stdvec m_tokens; + u32 m_current_index; friend class String; }; @@ -69,11 +69,11 @@ namespace ostd inline cpp_string cpp_str(void) const { return m_data; } inline cpp_string& cpp_str_ref(void) { return m_data; } inline const char* c_str(void) const { return m_data.c_str(); } - inline char at(uint32_t index) const { return m_data[index]; } - inline uint32_t len(void) const { return m_data.length(); } - inline char operator[](uint32_t index) const { return m_data[index]; } + inline char at(u32 index) const { return m_data[index]; } + inline u32 len(void) const { return m_data.length(); } + inline char operator[](u32 index) const { return m_data[index]; } inline bool operator== (const char* str2) const { return std::strcmp(c_str(), str2) == 0; } - inline bool operator!= (const char* str2) const { return std::strcmp(c_str(), str2) != 0; } + inline bool operator!= (const char* str2) const { return std::strcmp(c_str(), str2) != 0; } inline String operator+(const String& str2) const { return m_data + str2.cpp_str(); } friend String operator+(const cpp_string& str1, const String& str); inline String& operator+=(const String& str2) { m_data += str2.cpp_str(); return *this; } @@ -83,7 +83,7 @@ namespace ostd inline operator std::filesystem::path() const { return cpp_str(); } inline String& clr(void) { m_data = ""; return *this; } inline String& set(const cpp_string& str) { m_data = str; return *this; } - inline std::vector getUTF8Codepoints(void) const { return decodeUTF8(m_data); } + inline stdvec getUTF8Codepoints(void) const { return decodeUTF8(m_data); } inline auto begin(void) { return m_data.begin(); } inline auto end(void) { return m_data.end(); } @@ -98,29 +98,29 @@ namespace ostd String& trim(void); String& toLower(void); String& toUpper(void); - String& addPadding(uint32_t new_string_length, char c = ' ', ePaddingBehavior padding_behavior = ePaddingBehavior::ForceEvenPositive); - String& addLeftPadding(uint32_t new_string_length, char c = ' '); - String& addRightPadding(uint32_t new_string_length, char c = ' '); + String& addPadding(u32 new_string_length, char c = ' ', ePaddingBehavior padding_behavior = ePaddingBehavior::ForceEvenPositive); + String& addLeftPadding(u32 new_string_length, char c = ' '); + String& addRightPadding(u32 new_string_length, char c = ' '); String& reverse(void); String& replaceAll(const String& what, const String& with); String& replaceFirst(const String& what, const String& with); String& regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive = false); - String& put(uint32_t index, char c); - String& substr(uint32_t start, int32_t end = -1); - String& fixedLength(uint32_t length, char fill_character = ' ', const String& truncate_indicator = "... "); + String& put(u32 index, char c); + String& substr(u32 start, i32 end = -1); + String& fixedLength(u32 length, char fill_character = ' ', const String& truncate_indicator = "... "); String& addChar(char c); String& add(const String& se); - String& add(uint8_t i); - String& add(int8_t i); - String& add(uint16_t i); - String& add(int16_t i); - String& add(uint32_t i); - String& add(int32_t i); - String& add(uint64_t i); - String& add(int64_t i); - String& add(float f, uint8_t precision = 0); - String& add(double f, uint8_t precision = 0); + String& add(u8 i); + String& add(i8 i); + String& add(u16 i); + String& add(i16 i); + String& add(u32 i); + String& add(i32 i); + String& add(u64 i); + String& add(i64 i); + String& add(f32 f, u8 precision = 0); + String& add(f64 f, u8 precision = 0); //New String String new_ltrim(void) const; @@ -128,34 +128,34 @@ namespace ostd String new_trim(void) const; String new_toLower(void) const; String new_toUpper(void) const; - String new_addPadding(uint32_t new_string_length, char c = ' ', ePaddingBehavior padding_behavior = ePaddingBehavior::ForceEvenPositive) const; - String new_addLeftPadding(uint32_t new_string_length, char c = ' ') const; - String new_addRightPadding(uint32_t new_string_length, char c = ' ') const; + String new_addPadding(u32 new_string_length, char c = ' ', ePaddingBehavior padding_behavior = ePaddingBehavior::ForceEvenPositive) const; + String new_addLeftPadding(u32 new_string_length, char c = ' ') const; + String new_addRightPadding(u32 new_string_length, char c = ' ') const; String new_reverse(void) const; String new_replaceAll(const String& what, const String& with) const; String new_replaceFirst(const String& what, const String& with) const; String new_regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive = false) const; - String new_put(uint32_t index, char c) const; - String new_substr(uint32_t start, int32_t end = -1) const; - String new_fixedLength(uint32_t length, char fill_character = ' ', const String& truncate_indicator = "... ") const; + String new_put(u32 index, char c) const; + String new_substr(u32 start, i32 end = -1) const; + String new_fixedLength(u32 length, char fill_character = ' ', const String& truncate_indicator = "... ") const; String new_addChar(char c) const; String new_add(const String& se) const; - String new_add(uint8_t i) const; - String new_add(int8_t i) const; - String new_add(uint16_t i) const; - String new_add(int16_t i) const; - String new_add(uint32_t i) const; - String new_add(int32_t i) const; - String new_add(uint64_t i) const; - String new_add(int64_t i) const; - String new_add(float f, uint8_t precision = 0) const; - String new_add(double f, uint8_t precision = 0) const; + String new_add(u8 i) const; + String new_add(i8 i) const; + String new_add(u16 i) const; + String new_add(i16 i) const; + String new_add(u32 i) const; + String new_add(i32 i) const; + String new_add(u64 i) const; + String new_add(i64 i) const; + String new_add(f32 f, u8 precision = 0) const; + String new_add(f64 f, u8 precision = 0) const; //Utility - int64_t toInt(void) const; - float toFloat(void) const; - double toDouble(void) const; + i64 toInt(void) const; + f32 toFloat(void) const; + f64 toDouble(void) const; bool isNumeric(bool decimal = false) const; bool isInt(void) const; bool isHex(void) const; @@ -165,22 +165,22 @@ namespace ostd bool startsWith(const String& str) const; bool endsWith(const String& str) const; bool regexMatches(const String& regex_pattern, bool case_insensitive = false) const; - uint32_t count(const String& str) const; - int32_t indexOf(char c, uint32_t start = 0) const; - int32_t indexOf(const String& str, uint32_t start = 0) const; - int32_t lastIndexOf(char c) const; - int32_t lastIndexOf(const String& str) const; + u32 count(const String& str) const; + i32 indexOf(char c, u32 start = 0) const; + i32 indexOf(const String& str, u32 start = 0) const; + i32 lastIndexOf(char c) const; + i32 lastIndexOf(const String& str) const; Tokens tokenize(const String& delimiter = " ", bool trim_tokens = true, bool allow_white_space_only_tokens = false) const; - static String getHexStr(uint64_t value, bool prefix = true, uint8_t nbytes = 1); - static String getBinStr(uint64_t value, bool prefix = true, uint8_t nbytes = 1); - static String duplicateChar(unsigned char c, uint16_t count); - static std::vector decodeUTF8(const ostd::String& s); + static String getHexStr(u64 value, bool prefix = true, u8 nbytes = 1); + static String getBinStr(u64 value, bool prefix = true, u8 nbytes = 1); + static String duplicateChar(uchar c, u16 count); + static stdvec decodeUTF8(const String& s); friend std::ostream& operator<<(std::ostream& out, const String& val); private: - static uint32_t utf8_next(const char*& p, const char* end); + static u32 utf8_next(const char*& p, const char* end); private: ostd::cpp_string m_data; @@ -201,12 +201,12 @@ namespace ostd } } - +using String = ostd::String; template <> -struct std::hash +struct std::hash { - std::size_t operator()(const ostd::String& str) const + std::size_t operator()(const String& str) const { hash hasher; return hasher(str.cpp_str()); diff --git a/src/ostd/string/TextStyleParser.cpp b/src/ostd/string/TextStyleParser.cpp index 233bc20..058ee6d 100644 --- a/src/ostd/string/TextStyleParser.cpp +++ b/src/ostd/string/TextStyleParser.cpp @@ -7,7 +7,7 @@ namespace ostd { if (!str.validate()) return os; ostd::ConsoleOutputHandler out; - for (int32_t i = 0; i < str.text.len(); i++) + for (i32 i = 0; i < str.text.len(); i++) out.bg(str.backgroundColors[i].consoleColor).fg(str.foregroundColors[i].consoleColor).pChar(str.text[i]); out.reset(); return os; @@ -33,7 +33,7 @@ namespace ostd text += str; background.background = true; foreground.background = false; - for (int32_t i = 0; i < str.len(); i++) + for (i32 i = 0; i < str.len(); i++) { backgroundColors.push_back(background); foregroundColors.push_back(foreground); @@ -55,7 +55,7 @@ namespace ostd tStyledString rstring; bool insideBlock = false; bool validBlockStart = false; - int32_t countBlockStart = 0; + i32 countBlockStart = 0; defaultBackgorundColor.background = true; defaultForegroundColor.background = false; s_defaultBackgroundColor = defaultBackgorundColor; @@ -64,7 +64,7 @@ namespace ostd tColor bgcol = defaultBackgorundColor; String blockText = ""; String _styledString = String(styledString).trim(); - for (int32_t i = 0; i < _styledString.len(); i++) + for (i32 i = 0; i < _styledString.len(); i++) { char c = _styledString[i]; if (c == '[') @@ -223,70 +223,70 @@ namespace ostd return *this; } - TextStyleBuilder::Console& TextStyleBuilder::Console::add(uint8_t i) + TextStyleBuilder::Console& TextStyleBuilder::Console::add(u8 i) { String edit(""); edit.add(i); return add(edit); } - TextStyleBuilder::Console& TextStyleBuilder::Console::add(int8_t i) + TextStyleBuilder::Console& TextStyleBuilder::Console::add(i8 i) { String edit(""); edit.add(i); return add(edit); } - TextStyleBuilder::Console& TextStyleBuilder::Console::add(uint16_t i) + TextStyleBuilder::Console& TextStyleBuilder::Console::add(u16 i) { String edit(""); edit.add(i); return add(edit); } - TextStyleBuilder::Console& TextStyleBuilder::Console::add(int16_t i) + TextStyleBuilder::Console& TextStyleBuilder::Console::add(i16 i) { String edit(""); edit.add(i); return add(edit); } - TextStyleBuilder::Console& TextStyleBuilder::Console::add(uint32_t i) + TextStyleBuilder::Console& TextStyleBuilder::Console::add(u32 i) { String edit(""); edit.add(i); return add(edit); } - TextStyleBuilder::Console& TextStyleBuilder::Console::add(int32_t i) + TextStyleBuilder::Console& TextStyleBuilder::Console::add(i32 i) { String edit(""); edit.add(i); return add(edit); } - TextStyleBuilder::Console& TextStyleBuilder::Console::add(uint64_t i) + TextStyleBuilder::Console& TextStyleBuilder::Console::add(u64 i) { String edit(""); edit.add(i); return add(edit); } - TextStyleBuilder::Console& TextStyleBuilder::Console::add(int64_t i) + TextStyleBuilder::Console& TextStyleBuilder::Console::add(i64 i) { String edit(""); edit.add(i); return add(edit); } - TextStyleBuilder::Console& TextStyleBuilder::Console::add(float f) + TextStyleBuilder::Console& TextStyleBuilder::Console::add(f32 f) { String edit(""); edit.add(f); return add(edit); } - TextStyleBuilder::Console& TextStyleBuilder::Console::add(double f) + TextStyleBuilder::Console& TextStyleBuilder::Console::add(f64 f) { String edit(""); edit.add(f); diff --git a/src/ostd/string/TextStyleParser.hpp b/src/ostd/string/TextStyleParser.hpp index c0b6040..ca8d12b 100644 --- a/src/ostd/string/TextStyleParser.hpp +++ b/src/ostd/string/TextStyleParser.hpp @@ -37,8 +37,8 @@ namespace ostd public: struct tStyledString { String text { "" }; - std::vector backgroundColors; - std::vector foregroundColors; + stdvec backgroundColors; + stdvec foregroundColors; void add(const String& str, tColor background, tColor foreground); bool validate(void) const; @@ -71,9 +71,9 @@ namespace ostd friend std::ostream& operator<<(std::ostream&, IRichStringBase const&); inline void setDefaultBackgroundColor(TextStyleParser::tColor color) { m_defaultBackgroundColor = color; } - inline void setDefaultBackgroundColor(Color color) { m_defaultBackgroundColor = { color, "", true }; } + inline void setDefaultBackgroundColor(const Color& color) { m_defaultBackgroundColor = { color, "", true }; } inline void setDefaultForegroundColor(TextStyleParser::tColor color) { m_defaultForegroundColor = color; } - inline void setDefaultForegroundColor(Color color) { m_defaultForegroundColor = { color, "", true }; } + inline void setDefaultForegroundColor(const Color& color) { m_defaultForegroundColor = { color, "", true }; } inline TextStyleParser::tColor getDefaultBackgroundColor(void) { return m_defaultBackgroundColor; } inline TextStyleParser::tColor getDefaultForegroundColor(void) { return m_defaultForegroundColor; } @@ -90,16 +90,16 @@ namespace ostd Console& fg(const String& consoleColor); Console& clr(void); Console& add(const String& text); - Console& add(uint8_t i); - Console& add(int8_t i); - Console& add(uint16_t i); - Console& add(int16_t i); - Console& add(uint32_t i); - Console& add(int32_t i); - Console& add(uint64_t i); - Console& add(int64_t i); - Console& add(float f); - Console& add(double f); + Console& add(u8 i); + Console& add(i8 i); + Console& add(u16 i); + Console& add(i16 i); + Console& add(u32 i); + Console& add(i32 i); + Console& add(u64 i); + Console& add(i64 i); + Console& add(f32 f); + Console& add(f64 f); Console& addc(char c); Console& print(OutputHandlerBase& out); diff --git a/src/ostd/utils/Defines.hpp b/src/ostd/utils/Defines.hpp index 120c73e..5cb93a0 100755 --- a/src/ostd/utils/Defines.hpp +++ b/src/ostd/utils/Defines.hpp @@ -55,5 +55,5 @@ #define OX_RELEASE_BUILD #endif #else - #define _DEBUG(n) std::cout << (int)n << "\n"; + #define _DEBUG(n) std::cout << (i32)n << "\n"; #endif diff --git a/src/ostd/utils/Hash.cpp b/src/ostd/utils/Hash.cpp index 67a1e39..f8b50e6 100644 --- a/src/ostd/utils/Hash.cpp +++ b/src/ostd/utils/Hash.cpp @@ -27,61 +27,61 @@ // Rotation amounts namespace { - constexpr uint32_t S11 = 7; - constexpr uint32_t S12 = 12; - constexpr uint32_t S13 = 17; - constexpr uint32_t S14 = 22; - constexpr uint32_t S21 = 5; - constexpr uint32_t S22 = 9; - constexpr uint32_t S23 = 14; - constexpr uint32_t S24 = 20; - constexpr uint32_t S31 = 4; - constexpr uint32_t S32 = 11; - constexpr uint32_t S33 = 16; - constexpr uint32_t S34 = 23; - constexpr uint32_t S41 = 6; - constexpr uint32_t S42 = 10; - constexpr uint32_t S43 = 15; - constexpr uint32_t S44 = 21; + constexpr u32 S11 = 7; + constexpr u32 S12 = 12; + constexpr u32 S13 = 17; + constexpr u32 S14 = 22; + constexpr u32 S21 = 5; + constexpr u32 S22 = 9; + constexpr u32 S23 = 14; + constexpr u32 S24 = 20; + constexpr u32 S31 = 4; + constexpr u32 S32 = 11; + constexpr u32 S33 = 16; + constexpr u32 S34 = 23; + constexpr u32 S41 = 6; + constexpr u32 S42 = 10; + constexpr u32 S43 = 15; + constexpr u32 S44 = 21; - inline uint32_t F(uint32_t x, uint32_t y, uint32_t z) { return (x & y) | (~x & z); } - inline uint32_t G(uint32_t x, uint32_t y, uint32_t z) { return (x & z) | (y & ~z); } - inline uint32_t H(uint32_t x, uint32_t y, uint32_t z) { return x ^ y ^ z; } - inline uint32_t I(uint32_t x, uint32_t y, uint32_t z) { return y ^ (x | ~z); } + inline u32 F(u32 x, u32 y, u32 z) { return (x & y) | (~x & z); } + inline u32 G(u32 x, u32 y, u32 z) { return (x & z) | (y & ~z); } + inline u32 H(u32 x, u32 y, u32 z) { return x ^ y ^ z; } + inline u32 I(u32 x, u32 y, u32 z) { return y ^ (x | ~z); } - inline uint32_t rotate_left(uint32_t x, uint32_t n) { return (x << n) | (x >> (32 - n)); } + inline u32 rotate_left(u32 x, u32 n) { return (x << n) | (x >> (32 - n)); } - inline void FF(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) { + inline void FF(u32& a, u32 b, u32 c, u32 d, u32 x, u32 s, u32 ac) { a += F(b, c, d) + x + ac; a = rotate_left(a, s); a += b; } - inline void GG(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) { + inline void GG(u32& a, u32 b, u32 c, u32 d, u32 x, u32 s, u32 ac) { a += G(b, c, d) + x + ac; a = rotate_left(a, s); a += b; } - inline void HH(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) { + inline void HH(u32& a, u32 b, u32 c, u32 d, u32 x, u32 s, u32 ac) { a += H(b, c, d) + x + ac; a = rotate_left(a, s); a += b; } - inline void II(uint32_t& a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) { + inline void II(u32& a, u32 b, u32 c, u32 d, u32 x, u32 s, u32 ac) { a += I(b, c, d) + x + ac; a = rotate_left(a, s); a += b; } } -ostd::String ostd::Hash::md5(const ostd::String& _str) { +String ostd::Hash::md5(const String& _str) { std::string str = _str.cpp_str(); // Initial state (RFC 1321) - uint32_t state[4] = { + u32 state[4] = { 0x67452301u, 0xefcdab89u, 0x98badcfeu, 0x10325476u }; // Process input in 64-byte blocks - const uint8_t* input = reinterpret_cast(str.data()); + const u8* input = reinterpret_cast(str.data()); size_t inputLen = str.size(); // Process full 64-byte chunks @@ -91,7 +91,7 @@ ostd::String ostd::Hash::md5(const ostd::String& _str) { } // Buffer for remaining bytes + padding + length - uint8_t buffer[64]; + u8 buffer[64]; size_t rem = inputLen - i; std::memset(buffer, 0, sizeof(buffer)); if (rem > 0) { @@ -113,32 +113,32 @@ ostd::String ostd::Hash::md5(const ostd::String& _str) { } // Append original length in bits, little-endian - uint64_t bitLen = static_cast(inputLen) * 8ull; - for (int j = 0; j < 8; ++j) { - buffer[56 + j] = static_cast((bitLen >> (8 * j)) & 0xFF); + u64 bitLen = cast(inputLen) * 8ull; + for (i32 j = 0; j < 8; ++j) { + buffer[56 + j] = cast((bitLen >> (8 * j)) & 0xFF); } // Final transform __md5_transform(buffer, state); // Output digest (little-endian) - uint8_t digest[16]; + u8 digest[16]; __md5_encode(digest, state, 16); std::ostringstream oss; oss << std::hex << std::setfill('0'); - for (int j = 0; j < 16; ++j) { - oss << std::setw(2) << static_cast(digest[j]); + for (i32 j = 0; j < 16; ++j) { + oss << std::setw(2) << cast(digest[j]); } return oss.str(); } -void ostd::Hash::__md5_transform(const uint8_t block[64], uint32_t state[4]) { - uint32_t a = state[0]; - uint32_t b = state[1]; - uint32_t c = state[2]; - uint32_t d = state[3]; - uint32_t x[16]; +void ostd::Hash::__md5_transform(const u8 block[64], u32 state[4]) { + u32 a = state[0]; + u32 b = state[1]; + u32 c = state[2]; + u32 d = state[3]; + u32 x[16]; __md5_decode(x, block, 64); @@ -220,22 +220,22 @@ void ostd::Hash::__md5_transform(const uint8_t block[64], uint32_t state[4]) { state[3] += d; } -void ostd::Hash::__md5_encode(uint8_t* output, const uint32_t* input, size_t len) { +void ostd::Hash::__md5_encode(u8* output, const u32* input, size_t len) { // Convert 32-bit words to bytes (little-endian) for (size_t i = 0, j = 0; j < len; ++i, j += 4) { - output[j + 0] = static_cast( input[i] & 0xFF); - output[j + 1] = static_cast((input[i] >> 8) & 0xFF); - output[j + 2] = static_cast((input[i] >> 16) & 0xFF); - output[j + 3] = static_cast((input[i] >> 24) & 0xFF); + output[j + 0] = cast( input[i] & 0xFF); + output[j + 1] = cast((input[i] >> 8) & 0xFF); + output[j + 2] = cast((input[i] >> 16) & 0xFF); + output[j + 3] = cast((input[i] >> 24) & 0xFF); } } -void ostd::Hash::__md5_decode(uint32_t* output, const uint8_t* input, size_t len) { +void ostd::Hash::__md5_decode(u32* output, const u8* input, size_t len) { // Convert bytes to 32-bit words (little-endian) for (size_t i = 0, j = 0; j < len; ++i, j += 4) { - output[i] = static_cast(input[j + 0]) - | (static_cast(input[j + 1]) << 8) - | (static_cast(input[j + 2]) << 16) - | (static_cast(input[j + 3]) << 24); + output[i] = cast(input[j + 0]) + | (cast(input[j + 1]) << 8) + | (cast(input[j + 2]) << 16) + | (cast(input[j + 3]) << 24); } } diff --git a/src/ostd/utils/Hash.hpp b/src/ostd/utils/Hash.hpp index 5f70de2..3263217 100644 --- a/src/ostd/utils/Hash.hpp +++ b/src/ostd/utils/Hash.hpp @@ -30,8 +30,8 @@ namespace ostd static String md5(const String& str); private: - static void __md5_transform(const uint8_t block[64], uint32_t state[4]); - static void __md5_encode(uint8_t* output, const uint32_t* input, size_t len); - static void __md5_decode(uint32_t* output, const uint8_t* input, size_t len); + static void __md5_transform(const u8 block[64], u32 state[4]); + static void __md5_encode(u8* output, const u32* input, size_t len); + static void __md5_decode(u32* output, const u8* input, size_t len); }; } diff --git a/src/ostd/utils/Logic.cpp b/src/ostd/utils/Logic.cpp index a95a783..d8586ac 100755 --- a/src/ostd/utils/Logic.cpp +++ b/src/ostd/utils/Logic.cpp @@ -1,21 +1,21 @@ /* - OmniaFramework - A collection of useful functionality - Copyright (C) 2025 OmniaX-Dev + OmniaFramework - A collection of useful functionality + Copyright (C) 2025 OmniaX-Dev - This file is part of OmniaFramework. + This file is part of OmniaFramework. - OmniaFramework is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + OmniaFramework is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - OmniaFramework is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + OmniaFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with OmniaFramework. If not, see . + You should have received a copy of the GNU General Public License + along with OmniaFramework. If not, see . */ #include "Logic.hpp" @@ -26,28 +26,27 @@ namespace ostd { - bool LogicEvaluator::eval(String exp) + bool LogicEvaluator::eval(const String& _exp) { - String se(exp); - se = se.replaceAll("true", "1"); - se = se.replaceAll("false", "0"); - se = se.replaceAll("and", "&"); - se = se.replaceAll("or", "+"); - se = se.replaceAll("xor", "^"); - se = se.replaceAll("nand", "%"); - se = se.replaceAll("nor", "*"); - se = se.replaceAll("xnor", ">"); - se = se.replaceAll("not", "!"); - se = se.replaceAll(" ", ""); - se = se.replaceAll("!1", "0"); - se = se.replaceAll("!0", "1"); - se = se.trim(); - exp = se; + String exp(_exp); + exp.replaceAll("true", "1"); + exp.replaceAll("false", "0"); + exp.replaceAll("and", "&"); + exp.replaceAll("or", "+"); + exp.replaceAll("xor", "^"); + exp.replaceAll("nand", "%"); + exp.replaceAll("nor", "*"); + exp.replaceAll("xnor", ">"); + exp.replaceAll("not", "!"); + exp.replaceAll(" ", ""); + exp.replaceAll("!1", "0"); + exp.replaceAll("!0", "1"); + exp.trim(); std::stack values; std::stack ops; char c = 0; - for (unsigned int i = 0; i < exp.len(); i++) + for (u32 i = 0; i < exp.len(); i++) { c = exp[i]; if (c == ' ' || c == '#') continue; diff --git a/src/ostd/utils/Logic.hpp b/src/ostd/utils/Logic.hpp index 2486b21..6c12790 100755 --- a/src/ostd/utils/Logic.hpp +++ b/src/ostd/utils/Logic.hpp @@ -43,7 +43,7 @@ namespace ostd class LogicEvaluator { public: - static bool eval(String exp); + static bool eval(const String& exp); private: static bool applyOp(bool a, bool b, eLogicOp op); diff --git a/src/ostd/utils/PathFinder.cpp b/src/ostd/utils/PathFinder.cpp index 788e857..e7fc4ab 100755 --- a/src/ostd/utils/PathFinder.cpp +++ b/src/ostd/utils/PathFinder.cpp @@ -4,7 +4,7 @@ namespace ostd { - KeyNode::KeyNode(int32_t xx, int32_t yy, float f) + KeyNode::KeyNode(i32 xx, i32 yy, f32 f) { x = xx; y = yy; @@ -56,12 +56,12 @@ namespace ostd return false; } - const KeyNode& OpenSet::operator[](uint32_t index) const + const KeyNode& OpenSet::operator[](u32 index) const { return m_list[index]; } - int32_t OpenSet::size(void) const + i32 OpenSet::size(void) const { return m_list.size(); } @@ -71,7 +71,7 @@ namespace ostd remove(m_lowest_index); } - void OpenSet::remove(uint32_t index) + void OpenSet::remove(u32 index) { if (isEmpty() || index >= size()) return; if (size() == 1) @@ -84,7 +84,7 @@ namespace ostd { m_lowest = &m_list[0]; m_lowest_index = 0; - for (uint32_t i = 1; i < m_list.size(); i++) + for (u32 i = 1; i < m_list.size(); i++) { auto& k = m_list[i]; if (k.fscore < m_lowest->fscore) @@ -108,7 +108,7 @@ namespace ostd return *m_lowest; } - int32_t OpenSet::getLowestIndex(void) + i32 OpenSet::getLowestIndex(void) { return m_lowest_index; } @@ -120,7 +120,7 @@ namespace ostd init(32, 32); } - void PathFinder::init(int32_t w, int32_t h, eHeuristicType ht) + void PathFinder::init(i32 w, i32 h, eHeuristicType ht) { m_initialized = true; openSet.clear(); @@ -130,21 +130,21 @@ namespace ostd __ht = ht; m_width = w; m_height = h; - for (int32_t y = 0; y < h; y++) + for (i32 y = 0; y < h; y++) { - for (int32_t x = 0; x < w; x++) + for (i32 x = 0; x < w; x++) { - gscores[{x, y, 0}] = std::numeric_limits::infinity(); + gscores[{x, y, 0}] = std::numeric_limits::infinity(); } } } - void PathFinder::setObstacle(int32_t x, int32_t y, bool obst) + void PathFinder::setObstacle(i32 x, i32 y, bool obst) { obstacle[{x, y, 0}] = obst; } - void PathFinder::setKeyPoints(int32_t startx, int32_t starty, int32_t endx, int32_t endy) + void PathFinder::setKeyPoints(i32 startx, i32 starty, i32 endx, i32 endy) { if (!m_initialized) return; init(m_width, m_height, __ht); @@ -173,13 +173,13 @@ namespace ostd return path; } openSet.removeLowest(); - int32_t tmpx = current.x; - int32_t tmpy = current.y; - float tg = 0; + i32 tmpx = current.x; + i32 tmpy = current.y; + f32 tg = 0; KeyNode neighbor; - for (int8_t x = -1; x <= 1; x++) + for (i8 x = -1; x <= 1; x++) { - for (int8_t y = -1; y <= 1; y++) + for (i8 y = -1; y <= 1; y++) { if (x == 0 && y == 0) continue; if (tmpx + x < 0 || tmpx + x >= m_width || tmpy + y < 0 || tmpy + y >= m_height) continue; @@ -201,13 +201,13 @@ namespace ostd return std::deque(); } - float PathFinder::heuristics(KeyNode n) + f32 PathFinder::heuristics(KeyNode n) { - float hh = 0; + f32 hh = 0; switch (__ht) { case eHeuristicType::Euclidean: - hh = (float)std::sqrt(std::pow(n.x - __goal.x, 2) + std::pow(n.y - __goal.y, 2)); + hh = (f32)std::sqrt(std::pow(n.x - __goal.x, 2) + std::pow(n.y - __goal.y, 2)); break; case eHeuristicType::Manhattan: hh = std::abs(n.x - __goal.x) + std::abs(n.y - __goal.y); diff --git a/src/ostd/utils/PathFinder.hpp b/src/ostd/utils/PathFinder.hpp index b629b4c..4473def 100755 --- a/src/ostd/utils/PathFinder.hpp +++ b/src/ostd/utils/PathFinder.hpp @@ -1,29 +1,28 @@ /* - OmniaFramework - A collection of useful functionality - Copyright (C) 2025 OmniaX-Dev + OmniaFramework - A collection of useful functionality + Copyright (C) 2025 OmniaX-Dev - This file is part of OmniaFramework. + This file is part of OmniaFramework. - OmniaFramework is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + OmniaFramework is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - OmniaFramework is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + OmniaFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with OmniaFramework. If not, see . + You should have received a copy of the GNU General Public License + along with OmniaFramework. If not, see . */ #pragma once -#include #include #include -#include +#include #include namespace ostd @@ -37,11 +36,11 @@ namespace ostd struct KeyNode { - int32_t x; - int32_t y; - float fscore; + i32 x; + i32 y; + f32 fscore; - KeyNode(int32_t xx = 0, int32_t yy = 0, float f = 0.0f); + KeyNode(i32 xx = 0, i32 yy = 0, f32 f = 0.0f); bool operator==(const KeyNode &other) const; bool operator<(const KeyNode &other) const; @@ -57,17 +56,17 @@ namespace ostd bool isEmpty(void) const; void push(const KeyNode& k); bool contains(const KeyNode& k); - const KeyNode& operator[](uint32_t index) const; - int32_t size(void) const; + const KeyNode& operator[](u32 index) const; + i32 size(void) const; void removeLowest(void); - void remove(uint32_t index); + void remove(u32 index); void clear(void); KeyNode& getLowest(void); - int32_t getLowestIndex(void); + i32 getLowestIndex(void); private: - int32_t m_lowest_index; - std::vector m_list; + i32 m_lowest_index; + stdvec m_list; KeyNode* m_lowest; }; @@ -75,16 +74,16 @@ namespace ostd { public: PathFinder(void); - void init(int32_t w, int32_t h, eHeuristicType ht = eHeuristicType::Euclidean); - void setObstacle(int32_t x, int32_t y, bool obst = true); - void setKeyPoints(int32_t startx, int32_t starty, int32_t endx, int32_t endy); + void init(i32 w, i32 h, eHeuristicType ht = eHeuristicType::Euclidean); + void setObstacle(i32 x, i32 y, bool obst = true); + void setKeyPoints(i32 startx, i32 starty, i32 endx, i32 endy); std::deque findPath(void); private: - float heuristics(KeyNode n); + f32 heuristics(KeyNode n); private: - std::unordered_map gscores; + std::unordered_map gscores; std::unordered_map pathMap; std::unordered_map obstacle; OpenSet openSet; @@ -93,8 +92,8 @@ namespace ostd KeyNode __goal; eHeuristicType __ht; - int32_t m_width; - int32_t m_height; + i32 m_width; + i32 m_height; bool m_initialized; }; diff --git a/src/ostd/utils/QuadTree.cpp b/src/ostd/utils/QuadTree.cpp index 535bc3d..b2bfaa8 100755 --- a/src/ostd/utils/QuadTree.cpp +++ b/src/ostd/utils/QuadTree.cpp @@ -32,7 +32,7 @@ namespace ostd setValid(false); } - void QuadTree::create(Rectangle bounds, uint16_t capacity) + void QuadTree::create(Rectangle bounds, u16 capacity) { m_bounds = bounds; m_capacity = capacity; @@ -89,11 +89,11 @@ namespace ostd return false; } - void QuadTree::query(Rectangle range, std::vector& list) + void QuadTree::query(Rectangle range, stdvec& list) { if (!m_bounds.intersects(range, true)) return; - for (uint16_t i = 0; i < m_currentSize; i++) + for (u16 i = 0; i < m_currentSize; i++) { auto& elem = m_points[i]; if (range.contains({ elem.pos.x, elem.pos.y })) diff --git a/src/ostd/utils/QuadTree.hpp b/src/ostd/utils/QuadTree.hpp index e8e58d8..0f626d9 100755 --- a/src/ostd/utils/QuadTree.hpp +++ b/src/ostd/utils/QuadTree.hpp @@ -20,7 +20,6 @@ #pragma once -#include #include #include #include @@ -41,18 +40,18 @@ namespace ostd m_se(nullptr),m_ne(nullptr), m_subdivided(false), m_capacity(0), m_currentSize(0) { invalidate(); } - inline QuadTree(Rectangle bounds, uint16_t capacity) { create(bounds, capacity); } + inline QuadTree(Rectangle bounds, u16 capacity) { create(bounds, capacity); } inline ~QuadTree(void) { destroy(); } void destroy(void); - void create(Rectangle bounds, uint16_t capacity); + void create(Rectangle bounds, u16 capacity); void subdivide(void); bool insert(Vec2 point, void* data = nullptr); - void query(Rectangle range, std::vector& list); + void query(Rectangle range, stdvec& list); private: tElement* m_points; - uint16_t m_currentSize; - uint16_t m_capacity; + u16 m_currentSize; + u16 m_capacity; Rectangle m_bounds; bool m_subdivided; std::unique_ptr m_nw; diff --git a/src/ostd/utils/Signals.cpp b/src/ostd/utils/Signals.cpp index 22def90..4f080ab 100755 --- a/src/ostd/utils/Signals.cpp +++ b/src/ostd/utils/Signals.cpp @@ -1,5 +1,6 @@ #include "Signals.hpp" #include "../data/BaseObject.hpp" +#include "io/Memory.hpp" namespace ostd { @@ -20,7 +21,7 @@ namespace ostd m_DelegateRecievers.clear(); } - void SignalHandler::emitSignal(uint32_t signal_id, uint8_t prio, BaseObject& userData) + void SignalHandler::emitSignal(u32 signal_id, u8 prio, BaseObject& userData) { if (prio == Signal::Priority::Normal) { @@ -37,8 +38,16 @@ namespace ostd } } - void SignalHandler::connect(BaseObject& object, uint32_t signal_id) + void SignalHandler::connect(BaseObject& object, u32 signal_id) { m_recievers[signal_id].push_back(&object); } + + void SignalHandler::disconnect(BaseObject& object, u32 signal_id) + { + auto it = m_recievers.find(signal_id); + if (it == m_recievers.end()) + return; + STDVEC_REMOVE(it->second, &object); + } } diff --git a/src/ostd/utils/Signals.hpp b/src/ostd/utils/Signals.hpp index 946c380..b2dc09a 100755 --- a/src/ostd/utils/Signals.hpp +++ b/src/ostd/utils/Signals.hpp @@ -1,96 +1,97 @@ /* - OmniaFramework - A collection of useful functionality - Copyright (C) 2025 OmniaX-Dev + OmniaFramework - A collection of useful functionality + Copyright (C) 2025 OmniaX-Dev - This file is part of OmniaFramework. + This file is part of OmniaFramework. - OmniaFramework is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + OmniaFramework is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - OmniaFramework is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + OmniaFramework is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with OmniaFramework. If not, see . + You should have received a copy of the GNU General Public License + along with OmniaFramework. If not, see . */ #pragma once #include #include -#include -#include + + namespace ostd { struct BuiltinSignals { - inline static constexpr uint32_t NoSignal = 0x0000; + inline static constexpr u32 NoSignal = 0x0000; /** Builtin Signals **/ - inline static constexpr uint32_t KeyPressed = 0x0001; - inline static constexpr uint32_t KeyReleased = 0x0002; - inline static constexpr uint32_t MousePressed = 0x0003; - inline static constexpr uint32_t MouseReleased = 0x0004; - inline static constexpr uint32_t MouseMoved = 0x0005; - inline static constexpr uint32_t MouseDragged = 0x0006; - inline static constexpr uint32_t TextEntered = 0x0007; - inline static constexpr uint32_t MouseScrolled = 0x0008; + inline static constexpr u32 KeyPressed = 0x0001; + inline static constexpr u32 KeyReleased = 0x0002; + inline static constexpr u32 MousePressed = 0x0003; + inline static constexpr u32 MouseReleased = 0x0004; + inline static constexpr u32 MouseMoved = 0x0005; + inline static constexpr u32 MouseDragged = 0x0006; + inline static constexpr u32 TextEntered = 0x0007; + inline static constexpr u32 MouseScrolled = 0x0008; - inline static constexpr uint32_t OnGuiEvent = 0x2001; - inline static constexpr uint32_t FileDragAndDropped = 0x2002; - inline static constexpr uint32_t TextDragAndDropped = 0x2003; + inline static constexpr u32 OnGuiEvent = 0x2001; + inline static constexpr u32 FileDragAndDropped = 0x2002; + inline static constexpr u32 TextDragAndDropped = 0x2003; - inline static constexpr uint32_t BeforeSDLShutdown = 0x3001; + inline static constexpr u32 BeforeSDLShutdown = 0x3001; - inline static constexpr uint32_t WindowResized = 0x1001; - inline static constexpr uint32_t WindowClosed = 0x1002; - inline static constexpr uint32_t WindowFocused = 0x1003; - inline static constexpr uint32_t WindowLostFocus = 0x1004; + inline static constexpr u32 WindowResized = 0x1001; + inline static constexpr u32 WindowClosed = 0x1002; + inline static constexpr u32 WindowFocused = 0x1003; + inline static constexpr u32 WindowLostFocus = 0x1004; /*********************/ - inline static constexpr uint32_t CustomSignalBase = 0xFF0000; + inline static constexpr u32 CustomSignalBase = 0xFF0000; }; struct Signal { struct Priority { - inline static constexpr uint8_t RealTime = 0; - inline static constexpr uint8_t Normal = 1; + inline static constexpr u8 RealTime = 0; + inline static constexpr u8 Normal = 1; }; - const uint8_t priority; - const uint32_t ID; + const u8 priority; + const u32 ID; bool handled { false }; BaseObject& userData; - inline Signal(uint32_t id, BaseObject& _userData = BaseObject::InvalidRef(), uint8_t prio = Signal::Priority::Normal) : priority(prio), ID(id), userData(_userData) { } + inline Signal(u32 id, BaseObject& _userData = BaseObject::InvalidRef(), u8 prio = Signal::Priority::Normal) : priority(prio), ID(id), userData(_userData) { } }; class SignalHandler { private: struct DelegateSignal { - uint32_t id; + u32 id; BaseObject& ud; - inline DelegateSignal(uint32_t _id, BaseObject& _ud) : id(_id), ud(_ud) { } + inline DelegateSignal(u32 _id, BaseObject& _ud) : id(_id), ud(_ud) { } }; public: static void init(bool allow_reinit = false); static void handleDelegateSignals(void); - static void emitSignal(uint32_t signal_id, uint8_t prio = Signal::Priority::RealTime, BaseObject& userData = BaseObject::InvalidRef()); - static void connect(BaseObject& object, uint32_t signal_id); - inline static uint32_t newCustomSignal(uint32_t sub_id) { return BuiltinSignals::CustomSignalBase + sub_id; } + static void emitSignal(u32 signal_id, u8 prio = Signal::Priority::RealTime, BaseObject& userData = BaseObject::InvalidRef()); + static void connect(BaseObject& object, u32 signal_id); + static void disconnect(BaseObject& object, u32 signal_id); + inline static u32 newCustomSignal(u32 sub_id) { return BuiltinSignals::CustomSignalBase + sub_id; } private: - inline static std::unordered_map> m_recievers; - inline static std::vector m_DelegateRecievers; - inline static constexpr uint16_t __SIGNAL_BUFFER_START_SIZE { 2048 }; - inline static constexpr uint16_t __DELEGATE_SIGNALS_BUFFER_START_SIZE { 2048 }; + inline static stdumap> m_recievers; + inline static stdvec m_DelegateRecievers; + inline static constexpr u16 __SIGNAL_BUFFER_START_SIZE { 2048 }; + inline static constexpr u16 __DELEGATE_SIGNALS_BUFFER_START_SIZE { 2048 }; inline static bool m_initialized { false }; }; } diff --git a/src/ostd/utils/Time.cpp b/src/ostd/utils/Time.cpp index 148ff0e..713e3b6 100644 --- a/src/ostd/utils/Time.cpp +++ b/src/ostd/utils/Time.cpp @@ -20,10 +20,10 @@ namespace ostd m_totalSeconds = 0.0f; } - const float& GameClock::start(void) + const f32& GameClock::start(void) { m_rtClock.start(false, "", eTimeUnits::Seconds); - m_timeOfDay = CAP((1.0f / ((float)(TM_G_MINUTES_FOR_G_HOUR * TM_G_HOURS_FOR_G_DAY))) * ((hours * TM_G_MINUTES_FOR_G_HOUR) + (minutes)), 1.0f); + m_timeOfDay = CAP((1.0f / ((f32)(TM_G_MINUTES_FOR_G_HOUR * TM_G_HOURS_FOR_G_DAY))) * ((hours * TM_G_MINUTES_FOR_G_HOUR) + (minutes)), 1.0f); return m_timeOfDay; } @@ -31,13 +31,13 @@ namespace ostd { std::ostringstream ss; ss << "Time: " << getFormattedTime() << " / "; - ss << (int32_t)(days + 1) << " " << convertMonth() << " " << (int32_t)(years); + ss << (i32)(days + 1) << " " << convertMonth() << " " << (i32)(years); return String(ss.str()); } void GameClock::update(void) { - int64_t elapsed = m_rtClock.start(false, "", eTimeUnits::Seconds); + i64 elapsed = m_rtClock.start(false, "", eTimeUnits::Seconds); if (hours == 255) hours = TM_G_HOURS_FOR_G_DAY - 1; else if (hours >= TM_G_HOURS_FOR_G_DAY) @@ -51,26 +51,26 @@ namespace ostd if (hours >= TM_G_HOURS_FOR_G_DAY) { days++; - if ((months == (uint8_t)eMonths::January || months == (uint8_t)eMonths::March || - months == (uint8_t)eMonths::May || months == (uint8_t)eMonths::July || - months == (uint8_t)eMonths::August || months == (uint8_t)eMonths::October || - months == (uint8_t)eMonths::December) && days >= TM_G_DAYS_FOR_G_LONG_MONTH) + if ((months == (u8)eMonths::January || months == (u8)eMonths::March || + months == (u8)eMonths::May || months == (u8)eMonths::July || + months == (u8)eMonths::August || months == (u8)eMonths::October || + months == (u8)eMonths::December) && days >= TM_G_DAYS_FOR_G_LONG_MONTH) { months++; - if (months > (uint8_t)eMonths::December) + if (months > (u8)eMonths::December) { years++; - months = (uint8_t)eMonths::January; + months = (u8)eMonths::January; } days = 0; } - else if ((months == (uint8_t)eMonths::April || months == (uint8_t)eMonths::June || - months == (uint8_t)eMonths::September || months == (uint8_t)eMonths::November) && days >= TM_G_DAYS_FOR_G_MEDIUM_MONTH) + else if ((months == (u8)eMonths::April || months == (u8)eMonths::June || + months == (u8)eMonths::September || months == (u8)eMonths::November) && days >= TM_G_DAYS_FOR_G_MEDIUM_MONTH) { months++; days = 0; } - else if (months == (uint8_t)eMonths::February) + else if (months == (u8)eMonths::February) { if ((years % 4 == 0 && days >= TM_G_DAYS_FOR_G_SHORT_MONTH + 1) || (years % 4 != 0 && days >= TM_G_DAYS_FOR_G_SHORT_MONTH)) @@ -85,16 +85,16 @@ namespace ostd } m_totalSeconds += elapsed; m_rtClock.start(false, "", eTimeUnits::Seconds); - m_timeOfDay = CAP((1.0f / ((float)(TM_G_MINUTES_FOR_G_HOUR * TM_G_HOURS_FOR_G_DAY))) * ((hours * TM_G_MINUTES_FOR_G_HOUR) + (minutes)), 1.0f); + m_timeOfDay = CAP((1.0f / ((f32)(TM_G_MINUTES_FOR_G_HOUR * TM_G_HOURS_FOR_G_DAY))) * ((hours * TM_G_MINUTES_FOR_G_HOUR) + (minutes)), 1.0f); } } String GameClock::getFormattedTime(void) { - bool zh = (int32_t)(hours / 10) < 1; - bool zm = (int32_t)(minutes / 10) < 1; + bool zh = (i32)(hours / 10) < 1; + bool zm = (i32)(minutes / 10) < 1; std::ostringstream ss; - ss << (zh ? "0" : "") << (int32_t)hours << ":" << (zm ? "0" : "") << (int32_t)minutes; + ss << (zh ? "0" : "") << (i32)hours << ":" << (zm ? "0" : "") << (i32)minutes; return String(ss.str()); } @@ -102,29 +102,29 @@ namespace ostd { switch (months) { - case (uint8_t)eMonths::January: + case (u8)eMonths::January: return "January"; - case (uint8_t)eMonths::February: + case (u8)eMonths::February: return "February"; - case (uint8_t)eMonths::March: + case (u8)eMonths::March: return "March"; - case (uint8_t)eMonths::April: + case (u8)eMonths::April: return "April"; - case (uint8_t)eMonths::May: + case (u8)eMonths::May: return "May"; - case (uint8_t)eMonths::June: + case (u8)eMonths::June: return "June"; - case (uint8_t)eMonths::July: + case (u8)eMonths::July: return "July"; - case (uint8_t)eMonths::August: + case (u8)eMonths::August: return "August"; - case (uint8_t)eMonths::September: + case (u8)eMonths::September: return "September"; - case (uint8_t)eMonths::October: + case (u8)eMonths::October: return "October"; - case (uint8_t)eMonths::November: + case (u8)eMonths::November: return "November"; - case (uint8_t)eMonths::December: + case (u8)eMonths::December: return "December"; default: break; @@ -154,43 +154,43 @@ namespace ostd return ss.str(); } - int32_t LocalTime::hours(void) const + i32 LocalTime::hours(void) const { __get_local_time(); return __now_t->tm_hour; } - int32_t LocalTime::minutes(void) const + i32 LocalTime::minutes(void) const { __get_local_time(); return __now_t->tm_min; } - int32_t LocalTime::seconds(void) const + i32 LocalTime::seconds(void) const { __get_local_time(); return __now_t->tm_sec; } - int32_t LocalTime::day(void) const + i32 LocalTime::day(void) const { __get_local_time(); return __now_t->tm_mday; } - int32_t LocalTime::month(void) const + i32 LocalTime::month(void) const { __get_local_time(); return __now_t->tm_mon + 1; } - int32_t LocalTime::year(void) const + i32 LocalTime::year(void) const { __get_local_time(); return __now_t->tm_year + 1900; } - int32_t LocalTime::weekDay(void) const + i32 LocalTime::weekDay(void) const { __get_local_time(); return __now_t->tm_wday; @@ -199,78 +199,78 @@ namespace ostd String LocalTime::shours(bool leading_zero) const { std::ostringstream ss; - int32_t h = hours(); + i32 h = hours(); if (leading_zero && h < 10) - ss << "0" << (int32_t)h; + ss << "0" << (i32)h; else - ss << (int32_t)h; + ss << (i32)h; return ss.str(); } String LocalTime::sminutes(bool leading_zero) const { std::ostringstream ss; - int32_t h = minutes(); + i32 h = minutes(); if (leading_zero && h < 10) - ss << "0" << (int32_t)h; + ss << "0" << (i32)h; else - ss << (int32_t)h; + ss << (i32)h; return ss.str(); } String LocalTime::sseconds(bool leading_zero) const { std::ostringstream ss; - int32_t h = seconds(); + i32 h = seconds(); if (leading_zero && h < 10) - ss << "0" << (int32_t)h; + ss << "0" << (i32)h; else - ss << (int32_t)h; + ss << (i32)h; return ss.str(); } String LocalTime::sday(bool leading_zero) const { std::ostringstream ss; - int32_t h = day(); + i32 h = day(); if (leading_zero && h < 10) - ss << "0" << (int32_t)h; + ss << "0" << (i32)h; else - ss << (int32_t)h; + ss << (i32)h; return ss.str(); } String LocalTime::smonth(bool leading_zero, bool month_name) const { - int32_t h = month(); + i32 h = month(); if (month_name) return monthToText(h); std::ostringstream ss; if (leading_zero && h < 10) - ss << "0" << (int32_t)h; + ss << "0" << (i32)h; else - ss << (int32_t)h; + ss << (i32)h; return ss.str(); } String LocalTime::syear(void) const { std::ostringstream ss; - int32_t h = year(); - ss << (int32_t)h; + i32 h = year(); + ss << (i32)h; return ss.str(); } String LocalTime::sWeekDay(bool day_name) const { - int32_t h = weekDay(); + i32 h = weekDay(); if (day_name) return weekDayToText(h); std::ostringstream ss; - ss << (int32_t)h; + ss << (i32)h; return ss.str(); } - String LocalTime::monthToText(int32_t month) const + String LocalTime::monthToText(i32 month) const { switch (month) { @@ -290,7 +290,7 @@ namespace ostd } } - String LocalTime::weekDayToText(int32_t day) const + String LocalTime::weekDayToText(i32 day) const { switch (day) { @@ -305,7 +305,7 @@ namespace ostd } } - String LocalTime_IT::monthToText(int32_t month) const + String LocalTime_IT::monthToText(i32 month) const { switch (month) { @@ -325,7 +325,7 @@ namespace ostd } } - String LocalTime_IT::weekDayToText(int32_t day) const + String LocalTime_IT::weekDayToText(i32 day) const { switch (day) { @@ -340,7 +340,7 @@ namespace ostd } } - String LocalTime_ES::monthToText(int32_t month) const + String LocalTime_ES::monthToText(i32 month) const { switch (month) { @@ -360,7 +360,7 @@ namespace ostd } } - String LocalTime_ES::weekDayToText(int32_t day) const + String LocalTime_ES::weekDayToText(i32 day) const { switch (day) { @@ -375,7 +375,7 @@ namespace ostd } } - String LocalTime_DE::monthToText(int32_t month) const + String LocalTime_DE::monthToText(i32 month) const { switch (month) { @@ -395,7 +395,7 @@ namespace ostd } } - String LocalTime_DE::weekDayToText(int32_t day) const + String LocalTime_DE::weekDayToText(i32 day) const { switch (day) { @@ -412,7 +412,7 @@ namespace ostd - uint64_t Timer::start(bool print, String name, eTimeUnits timeUnit, OutputHandlerBase* __destination) + u64 Timer::start(bool print, const String& name, eTimeUnits timeUnit, OutputHandlerBase* __destination) { m_timeUnit = timeUnit; m_started = true; @@ -459,7 +459,7 @@ namespace ostd return 0; } - uint64_t Timer::startCount(eTimeUnits timeUnit) + u64 Timer::startCount(eTimeUnits timeUnit) { m_timeUnit = timeUnit; m_started = true; @@ -483,12 +483,12 @@ namespace ostd return 0; } - uint64_t Timer::end(bool print) + u64 Timer::end(bool print) { if (!m_started) return 0; m_started = false; m_dest = nullptr; - int64_t diff; + i64 diff; String unit; switch (m_timeUnit) { @@ -537,11 +537,11 @@ namespace ostd return diff; } - uint64_t Timer::endCount(bool stop) + u64 Timer::endCount(bool stop) { if (!m_started) return 0; m_started = !stop; - int64_t diff; + i64 diff; switch (m_timeUnit) { case eTimeUnits::Nanoseconds: @@ -562,19 +562,19 @@ namespace ostd return diff; } - uint64_t Timer::restart(eTimeUnits timeUnit) + u64 Timer::restart(eTimeUnits timeUnit) { if (!m_started) { startCount(timeUnit); return 0; } - uint64_t elapsed = endCount(); + u64 elapsed = endCount(); startCount(timeUnit); return elapsed; } - uint64_t Timer::getEpoch(eTimeUnits timeUnit) + u64 Timer::getEpoch(eTimeUnits timeUnit) { switch (timeUnit) { @@ -597,7 +597,7 @@ namespace ostd - StepTimer& StepTimer::create(double updatesPerSecond, StepTimer::Callback callback) + StepTimer& StepTimer::create(f64 updatesPerSecond, StepTimer::Callback callback) { m_targetDt = 1.0 / updatesPerSecond; m_callback = std::move(callback); @@ -616,10 +616,10 @@ namespace ostd m_prevTime = currentTime; // Convert to seconds - double frameTime = std::chrono::duration(frameDuration).count(); + f64 frameTime = std::chrono::duration(frameDuration).count(); // Clamp to prevent spiral of death (5 FPS minimum) - constexpr double MAX_FRAME_TIME = 0.2; + constexpr f64 MAX_FRAME_TIME = 0.2; if (frameTime > MAX_FRAME_TIME) frameTime = MAX_FRAME_TIME; @@ -649,7 +649,7 @@ namespace ostd s_startTime_ms = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); } - void Time::sleep(uint32_t __time, eTimeUnits __unit) + void Time::sleep(u32 __time, eTimeUnits __unit) { switch (__unit) { @@ -669,16 +669,16 @@ namespace ostd } } - uint64_t Time::getRunningTime_ms(void) + u64 Time::getRunningTime_ms(void) { return std::chrono::duration_cast (std::chrono::system_clock::now().time_since_epoch()).count() - s_startTime_ms; } - String Time::secondsToFormattedString(int32_t totalSeconds) + String Time::secondsToFormattedString(i32 totalSeconds) { - int32_t hours = totalSeconds / 3600; - int32_t minutes = (totalSeconds % 3600) / 60; - int32_t seconds = totalSeconds % 60; + i32 hours = totalSeconds / 3600; + i32 minutes = (totalSeconds % 3600) / 60; + i32 seconds = totalSeconds % 60; String fmtstr = ""; fmtstr.add(String("").add(hours).addLeftPadding(2, '0')).add(":"); fmtstr.add(String("").add(minutes).addLeftPadding(2, '0')).add(":"); diff --git a/src/ostd/utils/Time.hpp b/src/ostd/utils/Time.hpp index 640ab1c..ec576d4 100644 --- a/src/ostd/utils/Time.hpp +++ b/src/ostd/utils/Time.hpp @@ -87,29 +87,29 @@ namespace ostd bool m_counting { false }; }; - typedef _Counter Counter; - typedef _Counter FloatCounter; - typedef _Counter DoubleCounter; + typedef _Counter Counter; + typedef _Counter FloatCounter; + typedef _Counter DoubleCounter; class OutputHandlerBase; class Timer { public: inline Timer(void) { m_started = false; m_current = 0; m_timeUnit = eTimeUnits::Nanoseconds; m_dest = nullptr; } - uint64_t start(bool print = true, String name = "", eTimeUnits timeUnit = eTimeUnits::Nanoseconds, OutputHandlerBase* __destination = nullptr); - uint64_t startCount(eTimeUnits timeUnit = eTimeUnits::Nanoseconds); - uint64_t end(bool print = true); - uint64_t endCount(bool stop = true); - uint64_t restart(eTimeUnits timeUnit = eTimeUnits::Nanoseconds); + u64 start(bool print = true, const String& name = "", eTimeUnits timeUnit = eTimeUnits::Nanoseconds, OutputHandlerBase* __destination = nullptr); + u64 startCount(eTimeUnits timeUnit = eTimeUnits::Nanoseconds); + u64 end(bool print = true); + u64 endCount(bool stop = true); + u64 restart(eTimeUnits timeUnit = eTimeUnits::Nanoseconds); - static uint64_t getEpoch(eTimeUnits timeUnit = eTimeUnits::Milliseconds); + static u64 getEpoch(eTimeUnits timeUnit = eTimeUnits::Milliseconds); inline const String& getName(void) const { return m_name; } - inline uint64_t read(void) { if (!m_started) return 0; return endCount(false); } + inline u64 read(void) { if (!m_started) return 0; return endCount(false); } private: bool m_started; - int64_t m_current; + i64 m_current; eTimeUnits m_timeUnit; String m_name; OutputHandlerBase* m_dest; @@ -118,26 +118,26 @@ namespace ostd class StepTimer { public: - using Callback = std::function; + using Callback = std::function; using Clock = std::chrono::high_resolution_clock; using TimePoint = Clock::time_point; using Duration = Clock::duration; public: StepTimer() = default; - inline StepTimer(double updatesPerSecond, Callback callback) { create(updatesPerSecond, callback); } - StepTimer& create(double updatesPerSecond, Callback callback); + inline StepTimer(f64 updatesPerSecond, Callback callback) { create(updatesPerSecond, callback); } + StepTimer& create(f64 updatesPerSecond, Callback callback); void update(void); void reset(void); - inline double getInterpolationAlpha(void) const { return m_valid && m_targetDt > 0.0 ? m_accumulator / m_targetDt : 0.0; } + inline f64 getInterpolationAlpha(void) const { return m_valid && m_targetDt > 0.0 ? m_accumulator / m_targetDt : 0.0; } inline void invalidate(void) { m_valid = false; } inline bool isValid(void) const { return m_valid; } private: TimePoint m_prevTime; - double m_targetDt { 0.0 }; + f64 m_targetDt { 0.0 }; Callback m_callback { nullptr }; - double m_accumulator { 0.0 }; + f64 m_accumulator { 0.0 }; bool m_valid { false }; }; @@ -145,8 +145,8 @@ namespace ostd { public: GameClock(void); - const float& start(void); - inline const float& getTimeOfDay(void) const { return m_timeOfDay; } + const f32& start(void); + inline const f32& getTimeOfDay(void) const { return m_timeOfDay; } String asString(void); void update(void); @@ -155,16 +155,16 @@ namespace ostd String convertMonth(void); public: - uint8_t minutes; - uint8_t hours; - uint16_t days; - uint8_t months; - uint16_t years; + u8 minutes; + u8 hours; + u16 days; + u8 months; + u16 years; private: Timer m_rtClock; - float m_timeOfDay; - float m_totalSeconds; + f32 m_timeOfDay; + f32 m_totalSeconds; }; class LocalTime @@ -173,13 +173,13 @@ namespace ostd String getFullString(bool include_date = true, bool include_time = true, bool day_name = true, bool month_as_name = true, bool include_seconds = true) const; inline String getDateString(bool day_name = true, bool month_as_name = true) { return getFullString(true, false, day_name, month_as_name, false); } inline String getTimeString(bool include_seconds = true) { return getFullString(false, true, false, false, include_seconds); } - int32_t hours(void) const; - int32_t minutes(void) const; - int32_t seconds(void) const; - int32_t day(void) const; - int32_t month(void) const; - int32_t year(void) const; - int32_t weekDay(void) const; + i32 hours(void) const; + i32 minutes(void) const; + i32 seconds(void) const; + i32 day(void) const; + i32 month(void) const; + i32 year(void) const; + i32 weekDay(void) const; String shours(bool leading_zero = true) const; String sminutes(bool leading_zero = true) const; String sseconds(bool leading_zero = true) const; @@ -189,40 +189,40 @@ namespace ostd String sWeekDay(bool day_name = true) const; protected: - virtual String monthToText(int32_t month) const; - virtual String weekDayToText(int32_t day) const; + virtual String monthToText(i32 month) const; + virtual String weekDayToText(i32 day) const; }; typedef LocalTime LocalTime_EN; class LocalTime_IT : public LocalTime { protected: - String monthToText(int32_t month) const override; - String weekDayToText(int32_t day) const override; + String monthToText(i32 month) const override; + String weekDayToText(i32 day) const override; }; class LocalTime_ES : public LocalTime { protected: - String monthToText(int32_t month) const override; - String weekDayToText(int32_t day) const override; + String monthToText(i32 month) const override; + String weekDayToText(i32 day) const override; }; class LocalTime_DE : public LocalTime { protected: - String monthToText(int32_t month) const override; - String weekDayToText(int32_t day) const override; + String monthToText(i32 month) const override; + String weekDayToText(i32 day) const override; }; class Time { public: static void startRunningTimer(void); - static inline const uint64_t getStartTime(void) { return s_startTime_ms; } - static void sleep(uint32_t __time, eTimeUnits __unit = eTimeUnits::Milliseconds); - static uint64_t getRunningTime_ms(void); - static String secondsToFormattedString(int32_t totalSeconds); + static inline const u64 getStartTime(void) { return s_startTime_ms; } + static void sleep(u32 __time, eTimeUnits __unit = eTimeUnits::Milliseconds); + static u64 getRunningTime_ms(void); + static String secondsToFormattedString(i32 totalSeconds); private: - inline static uint64_t s_startTime_ms; + inline static u64 s_startTime_ms; }; } diff --git a/src/test/GraphicsWindowTest.cpp b/src/test/GraphicsWindowTest.cpp index e94fec5..a2cb886 100644 --- a/src/test/GraphicsWindowTest.cpp +++ b/src/test/GraphicsWindowTest.cpp @@ -47,16 +47,16 @@ class Window : public ogfx::GraphicsWindow { auto l_rndPoint = [&](void) -> ostd::FPoint { using rnd = ostd::Random; - return rnd::getVec2({ 0, (float)getWindowWidth() }, { 0, (float)getWindowHeight() }); + return rnd::getVec2({ 0, (f32)getWindowWidth() }, { 0, (f32)getWindowHeight() }); }; - for (int32_t i = 0; i < 10000; i++) + for (i32 i = 0; i < 10000; i++) m_gfx.drawLine({ l_rndPoint(), l_rndPoint() }, ostd::Colors::Crimson, 10); m_gfx.endFrame(); } - inline void onFixedUpdate(double frameTime_s) override + inline void onFixedUpdate(f64 frameTime_s) override { - std::cout << (int)getFPS() << "\n"; + std::cout << (i32)getFPS() << "\n"; } inline void onUpdate(void) override @@ -67,7 +67,7 @@ class Window : public ogfx::GraphicsWindow ogfx::BasicRenderer2D m_gfx; }; -int main(int argc, char** argv) +i32 main(i32 argc, char** argv) { Window window; window.initialize(800, 600, "OmniaFramework - Test Window"); diff --git a/src/test/GuiTest.cpp b/src/test/GuiTest.cpp index 2207a9a..da47a18 100644 --- a/src/test/GuiTest.cpp +++ b/src/test/GuiTest.cpp @@ -31,6 +31,20 @@ class Window : public ogfx::gui::Window inline Window(void) { } inline void onInitialize(void) override { + m_img.loadFromFile("./img.png", m_gfx); + ogfx::Animation::AnimationData ad; + ad.backwards = false; + ad.columns = 9; + ad.rows = 4; + ad.frame_width = 256; + ad.frame_height = 256; + ad.length = 36; + ad.random = false; + ad.still = false; + ad.speed = 0; + m_anim.create(ad); + m_anim.setSpriteSheet(m_img); + m_panel1.setSize(300, 140); m_panel1.setPosition(350, 50); m_panel1.setMousePressedCallback([&](const ogfx::gui::Event& event) -> void { @@ -103,7 +117,7 @@ class Window : public ogfx::gui::Window m_label2.setDragAndDropCallback([&](const ogfx::gui::Event& event) -> void { if (event.drop.userObject->getTypeName() == "ogfx::gui::widgets::Label") { - std::cout << static_cast(*event.drop.userObject).getText() << "!\n"; + std::cout << cast(*event.drop.userObject).getText() << "!\n"; } }); m_panel1.addChild(m_label2); @@ -138,9 +152,15 @@ class Window : public ogfx::gui::Window void onRedraw(ogfx::BasicRenderer2D& gfx) override { + gfx.drawAnimation(m_anim, { 200, 200 }); wout().xy(100, 100).fg(ostd::Colors::Crimson).p("CIAO BELLA").resetColors(); } + void onFixedUpdate(void) override + { + m_anim.update(); + } + private: ogfx::gui::widgets::Label m_label1 { *this }; ogfx::gui::widgets::Label m_label2 { *this }; @@ -150,9 +170,11 @@ class Window : public ogfx::gui::Window ogfx::gui::widgets::CheckBox m_check1 { *this }; ostd::Stylesheet m_theme; ostd::Vec2 pos { 0, 0 }; + ogfx::Animation m_anim; + ogfx::Image m_img; }; -int main(int argc, char** argv) +i32 main(i32 argc, char** argv) { ostd::initialize(); Window window;