Added ogfx::WindowBaseOutputHandler class
This commit is contained in:
parent
3990a50b00
commit
025d089bcb
15 changed files with 794 additions and 203 deletions
|
|
@ -75,7 +75,8 @@ list(APPEND OGFX_SOURCE_FILES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/WindowBase.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/WindowBase.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/BasicRenderer.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/BasicRenderer.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/RawTextInput.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/RawTextInput.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/Image.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/Image.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/WindowBaseOutputHandler.cpp
|
||||||
)
|
)
|
||||||
list(APPEND TEST_SOURCE_FILES
|
list(APPEND TEST_SOURCE_FILES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/test.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/test.cpp
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
1940
|
1959
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
[0.2.1958]
|
||||||
|
Added ostd::OutputHandlerBase::tab() virtual function
|
||||||
|
Added ogfx::WindowBaseOutputHandler class
|
||||||
|
|
||||||
[0.2.1936]
|
[0.2.1936]
|
||||||
Added JsonFile class to handle Json files
|
Added JsonFile class to handle Json files
|
||||||
Added MidiParser class to parse Midi files
|
Added MidiParser class to parse Midi files
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#include "BasicRenderer.hpp"
|
#include "BasicRenderer.hpp"
|
||||||
#include "WindowBase.hpp"
|
#include "WindowBase.hpp"
|
||||||
#include "SDLInclude.hpp"
|
|
||||||
|
|
||||||
namespace ogfx
|
namespace ogfx
|
||||||
{
|
{
|
||||||
|
|
|
||||||
465
src/ogfx/WindowBaseOutputHandler.cpp
Normal file
465
src/ogfx/WindowBaseOutputHandler.cpp
Normal file
|
|
@ -0,0 +1,465 @@
|
||||||
|
#include "WindowBaseOutputHandler.hpp"
|
||||||
|
#include "BasicRenderer.hpp"
|
||||||
|
#include "TextStyleParser.hpp"
|
||||||
|
|
||||||
|
namespace ogfx
|
||||||
|
{
|
||||||
|
using namespace ostd;
|
||||||
|
|
||||||
|
WindowBaseOutputHandler::WindowBaseOutputHandler(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::attachWindow(ogfx::WindowBase& window)
|
||||||
|
{
|
||||||
|
if (m_window != nullptr) return;
|
||||||
|
m_window = &window;
|
||||||
|
m_renderer.init(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::setMonospaceFont(const String& filePath)
|
||||||
|
{
|
||||||
|
m_renderer.setFont(filePath);
|
||||||
|
m_renderer.setFontSize(m_fontSize);
|
||||||
|
__update_char_size();
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 WindowBaseOutputHandler::getStringSize(const String& str)
|
||||||
|
{
|
||||||
|
Vec2 size = { 0.0f, m_charSize.y };
|
||||||
|
if (str.len() == 0) return size;
|
||||||
|
size.x = str.len() * m_charSize.x;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WindowBaseOutputHandler::isReady(void)
|
||||||
|
{
|
||||||
|
return m_window != nullptr && m_renderer.getTTFRenderer().hasOpenFont() && m_fontSize > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::resetCursorPosition(void)
|
||||||
|
{
|
||||||
|
m_curosrPosition = { 0, 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::resetColors(void)
|
||||||
|
{
|
||||||
|
m_foregroundColor = m_defaultForegroundColor;
|
||||||
|
m_backgroundColor = m_defaultBackgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::beginFrame(void)
|
||||||
|
{
|
||||||
|
resetColors();
|
||||||
|
resetCursorPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::setConsoleMaxCharacters(const IPoint& size)
|
||||||
|
{
|
||||||
|
m_consoleSize = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::setConsolePosition(const Vec2& pos)
|
||||||
|
{
|
||||||
|
m_consolePosition = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::setWrapMode(eWrapMode wrapMode)
|
||||||
|
{
|
||||||
|
m_wrapMode = wrapMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::setPadding(const Rectangle& rect)
|
||||||
|
{
|
||||||
|
m_padding = rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::setDefaultBackgorundColor(const Color& color)
|
||||||
|
{
|
||||||
|
m_defaultBackgroundColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::setDefaultForegroundColor(const Color& color)
|
||||||
|
{
|
||||||
|
m_defaultForegroundColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::setTabWidth(uint8_t tw)
|
||||||
|
{
|
||||||
|
m_tabWidth = tw;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::setFontSize(int32_t fontSize)
|
||||||
|
{
|
||||||
|
m_fontSize = fontSize;
|
||||||
|
m_renderer.setFontSize(m_fontSize);
|
||||||
|
__update_char_size();
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t WindowBaseOutputHandler::getFontSize(void)
|
||||||
|
{
|
||||||
|
return m_fontSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 WindowBaseOutputHandler::getCharacterSize(int32_t fontSize)
|
||||||
|
{
|
||||||
|
if (fontSize > 0)
|
||||||
|
{
|
||||||
|
auto size = m_renderer.getStringSize("A", fontSize);
|
||||||
|
return { (float)size.x, (float)size.y };
|
||||||
|
}
|
||||||
|
return m_charSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 WindowBaseOutputHandler::getConsolePosition(void)
|
||||||
|
{
|
||||||
|
return m_consolePosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler::eWrapMode WindowBaseOutputHandler::getWrapMode(void)
|
||||||
|
{
|
||||||
|
return m_wrapMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle WindowBaseOutputHandler::getPadding(void)
|
||||||
|
{
|
||||||
|
return m_padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color WindowBaseOutputHandler::getDefaultBackgroundColor(void)
|
||||||
|
{
|
||||||
|
return m_defaultBackgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color WindowBaseOutputHandler::getDefaultForegroundColor(void)
|
||||||
|
{
|
||||||
|
return m_defaultForegroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t WindowBaseOutputHandler::getTabWidth(void)
|
||||||
|
{
|
||||||
|
return m_tabWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle WindowBaseOutputHandler::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;
|
||||||
|
return { getConsolePosition().x - getPadding().x, getConsolePosition().y - getPadding().y, console_w, console_h };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::bg(const Color& color)
|
||||||
|
{
|
||||||
|
m_backgroundColor = color;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::bg(const ConsoleColors::tConsoleColor& color)
|
||||||
|
{
|
||||||
|
m_backgroundColor = color.fullColor;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::bg(const String& color)
|
||||||
|
{
|
||||||
|
m_backgroundColor = ConsoleColors::getFromName(color).fullColor;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::fg(const Color& color)
|
||||||
|
{
|
||||||
|
m_foregroundColor = color;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::fg(const ConsoleColors::tConsoleColor& color)
|
||||||
|
{
|
||||||
|
m_foregroundColor = color.fullColor;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::fg(const String& color)
|
||||||
|
{
|
||||||
|
m_foregroundColor = ConsoleColors::getFromName(color).fullColor;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::pChar(char c)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").addChar(c));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::pStyled(const String& styled)
|
||||||
|
{
|
||||||
|
return pStyled(TextStyleParser::parse(styled, { m_backgroundColor, "", true }, { m_foregroundColor, "", false }));
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::pStyled(const TextStyleParser::tStyledString& styled)
|
||||||
|
{
|
||||||
|
if (!styled.validate()) return *this;
|
||||||
|
Color oldBgCol = m_backgroundColor;
|
||||||
|
Color oldFgCol = m_foregroundColor;
|
||||||
|
for (int32_t 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;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::pStyled(TextStyleBuilder::IRichStringBase& styled)
|
||||||
|
{
|
||||||
|
auto oldBg = styled.getDefaultBackgroundColor();
|
||||||
|
auto oldFg = styled.getDefaultForegroundColor();
|
||||||
|
styled.setDefaultBackgroundColor(m_backgroundColor);
|
||||||
|
styled.setDefaultForegroundColor(m_foregroundColor);
|
||||||
|
pStyled(styled.getStyledString());
|
||||||
|
styled.setDefaultBackgroundColor(oldBg);
|
||||||
|
styled.setDefaultForegroundColor(oldFg);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::pObject(const BaseObject& bo)
|
||||||
|
{
|
||||||
|
__print_string(bo.toString());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(const String& se)
|
||||||
|
{
|
||||||
|
__print_string(se);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint8_t i)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").add(i));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(int8_t i)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").add(i));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint16_t i)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").add(i));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(int16_t i)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").add(i));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint32_t i)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").add(i));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(int32_t i)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").add(i));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint64_t i)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").add(i));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(int64_t i)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").add(i));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(float f, uint8_t precision)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").add(f, precision));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::p(double f, uint8_t precision)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").add(f, precision));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::nl(void)
|
||||||
|
{
|
||||||
|
if (m_curosrPosition.y >= getConsoleSize().y) return *this;
|
||||||
|
m_curosrPosition.y++;
|
||||||
|
m_curosrPosition.x = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::tab(void)
|
||||||
|
{
|
||||||
|
if (m_curosrPosition.x == 0)
|
||||||
|
{
|
||||||
|
__print_string(ostd::String("").fixedLength(m_tabWidth, ' ', ""));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
int32_t restTab = m_tabWidth - ((int32_t)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, ' ', ""));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::flush(void)
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::clear(void)
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::reset(void)
|
||||||
|
{
|
||||||
|
resetColors();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::xy(IPoint position)
|
||||||
|
{
|
||||||
|
m_curosrPosition = { (float)position.x, (float)position.y };
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::xy(int32_t x, int32_t y)
|
||||||
|
{
|
||||||
|
m_curosrPosition = { (float)x, (float)y };
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::x(int32_t x)
|
||||||
|
{
|
||||||
|
m_curosrPosition.x = (float)x;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& WindowBaseOutputHandler::y(int32_t y)
|
||||||
|
{
|
||||||
|
m_curosrPosition.y = (float)y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPoint WindowBaseOutputHandler::getCursorPosition(void)
|
||||||
|
{
|
||||||
|
return { (int32_t)std::round(m_curosrPosition.x), (int32_t)std::round(m_curosrPosition.y) };
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::getCursorPosition(int32_t& outX, int32_t& outY)
|
||||||
|
{
|
||||||
|
outX = (int32_t)std::round(m_curosrPosition.x);
|
||||||
|
outY = (int32_t)std::round(m_curosrPosition.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t WindowBaseOutputHandler::getCursorX(void)
|
||||||
|
{
|
||||||
|
return (int32_t)std::round(m_curosrPosition.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t WindowBaseOutputHandler::getCursorY(void)
|
||||||
|
{
|
||||||
|
return (int32_t)std::round(m_curosrPosition.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::getConsoleSize(int32_t& outColumns, int32_t& outRows)
|
||||||
|
{
|
||||||
|
int32_t console_rows = std::numeric_limits<int>::max();
|
||||||
|
int32_t console_cols = std::numeric_limits<int>::max();
|
||||||
|
if (m_consoleSize.x > 0) console_cols = m_consoleSize.x;
|
||||||
|
if (m_consoleSize.y > 0) console_rows = m_consoleSize.y;
|
||||||
|
outColumns = console_cols;
|
||||||
|
outRows = console_rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPoint WindowBaseOutputHandler::getConsoleSize(void)
|
||||||
|
{
|
||||||
|
int32_t console_rows = std::numeric_limits<int>::max();
|
||||||
|
int32_t console_cols = std::numeric_limits<int>::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 };
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::__update_char_size(void)
|
||||||
|
{
|
||||||
|
auto size = m_renderer.getStringSize("A", m_fontSize);
|
||||||
|
m_charSize = { (float)size.x, (float)size.y };
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowBaseOutputHandler::__print_string(const String& str)
|
||||||
|
{
|
||||||
|
if (!isReady()) return;
|
||||||
|
auto l_endOfConsole = [&](void) -> bool {
|
||||||
|
return m_curosrPosition.x >= getConsoleSize().x && m_curosrPosition.y >= getConsoleSize().y - 1;
|
||||||
|
};
|
||||||
|
auto l_print = [&](const String& string) {
|
||||||
|
if (l_endOfConsole()) return;
|
||||||
|
if (string.len() == 0) return;
|
||||||
|
float 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);
|
||||||
|
if (m_foregroundColor.a > 0)
|
||||||
|
m_renderer.drawString(string, pos, m_foregroundColor);
|
||||||
|
m_curosrPosition.x += string.len();
|
||||||
|
if (m_curosrPosition.x >= getConsoleSize().x)
|
||||||
|
nl();
|
||||||
|
};
|
||||||
|
int32_t string_length = str.len();
|
||||||
|
int32_t lineLen = m_curosrPosition.x + string_length;
|
||||||
|
if (lineLen <= getConsoleSize().x)
|
||||||
|
{
|
||||||
|
l_print(str);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_wrapMode == eWrapMode::TripleDots)
|
||||||
|
{
|
||||||
|
int32_t 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);
|
||||||
|
l_print(tmp);
|
||||||
|
tmp = str.new_substr(restOfLine);
|
||||||
|
int32_t nlines = tmp.len() / getConsoleSize().x;
|
||||||
|
if (nlines == 0)
|
||||||
|
{
|
||||||
|
l_print(tmp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < nlines; i++)
|
||||||
|
{
|
||||||
|
ostd::String line = tmp.new_substr(0, getConsoleSize().x);
|
||||||
|
l_print(line);
|
||||||
|
tmp.substr(getConsoleSize().x);
|
||||||
|
}
|
||||||
|
if (tmp.len() > 0)
|
||||||
|
l_print(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
106
src/ogfx/WindowBaseOutputHandler.hpp
Normal file
106
src/ogfx/WindowBaseOutputHandler.hpp
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ostd/IOHandlers.hpp>
|
||||||
|
#include <ostd/TextStyleParser.hpp>
|
||||||
|
#include <ogfx/BasicRenderer.hpp>
|
||||||
|
|
||||||
|
namespace ogfx
|
||||||
|
{
|
||||||
|
class WindowBaseOutputHandler : public ostd::OutputHandlerBase
|
||||||
|
{
|
||||||
|
public: enum class eWrapMode { TripleDots, NewLine };
|
||||||
|
public:
|
||||||
|
WindowBaseOutputHandler(void);
|
||||||
|
void attachWindow(WindowBase& window);
|
||||||
|
void setMonospaceFont(const ostd::String& filePath);
|
||||||
|
ostd::Vec2 getStringSize(const ostd::String& str);
|
||||||
|
bool isReady(void);
|
||||||
|
void resetCursorPosition(void);
|
||||||
|
void resetColors(void);
|
||||||
|
void beginFrame(void);
|
||||||
|
|
||||||
|
void setFontSize(int32_t 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);
|
||||||
|
|
||||||
|
int32_t getFontSize(void);
|
||||||
|
ostd::Vec2 getCharacterSize(int32_t 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);
|
||||||
|
ostd::Rectangle getConsoleBounds(void);
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& bg(const ostd::Color& color) override;
|
||||||
|
WindowBaseOutputHandler& bg(const ostd::ConsoleColors::tConsoleColor& color) override;
|
||||||
|
WindowBaseOutputHandler& bg(const ostd::String& color) override;
|
||||||
|
WindowBaseOutputHandler& fg(const ostd::Color& color) override;
|
||||||
|
WindowBaseOutputHandler& fg(const ostd::ConsoleColors::tConsoleColor& color) override;
|
||||||
|
WindowBaseOutputHandler& fg(const ostd::String& color) override;
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& pChar(char c) override;
|
||||||
|
WindowBaseOutputHandler& pStyled(const ostd::String& styled) override;
|
||||||
|
WindowBaseOutputHandler& pStyled(const ostd::TextStyleParser::tStyledString& styled) override;
|
||||||
|
WindowBaseOutputHandler& pStyled(ostd::TextStyleBuilder::IRichStringBase& styled) override;
|
||||||
|
WindowBaseOutputHandler& pObject(const ostd::BaseObject& bo) override;
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& p(const ostd::String& se) override;
|
||||||
|
WindowBaseOutputHandler& p(uint8_t i) override;
|
||||||
|
WindowBaseOutputHandler& p(int8_t i) override;
|
||||||
|
WindowBaseOutputHandler& p(uint16_t i) override;
|
||||||
|
WindowBaseOutputHandler& p(int16_t i) override;
|
||||||
|
WindowBaseOutputHandler& p(uint32_t i) override;
|
||||||
|
WindowBaseOutputHandler& p(int32_t i) override;
|
||||||
|
WindowBaseOutputHandler& p(uint64_t i) override;
|
||||||
|
WindowBaseOutputHandler& p(int64_t i) override;
|
||||||
|
WindowBaseOutputHandler& p(float f, uint8_t precision = 0) override;
|
||||||
|
WindowBaseOutputHandler& p(double f, uint8_t precision = 0) override;
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& nl(void) override;
|
||||||
|
WindowBaseOutputHandler& tab(void) override;
|
||||||
|
WindowBaseOutputHandler& flush(void) override;
|
||||||
|
WindowBaseOutputHandler& clear(void) override;
|
||||||
|
WindowBaseOutputHandler& reset(void) override;
|
||||||
|
|
||||||
|
WindowBaseOutputHandler& xy(ostd::IPoint position) override;
|
||||||
|
WindowBaseOutputHandler& xy(int32_t x, int32_t y) override;
|
||||||
|
WindowBaseOutputHandler& x(int32_t x) override;
|
||||||
|
WindowBaseOutputHandler& y(int32_t 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 getConsoleSize(int32_t& outColumns, int32_t& outRows) override;
|
||||||
|
ostd::IPoint getConsoleSize(void) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void __update_char_size(void);
|
||||||
|
void __print_string(const ostd::String& str);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ostd::Color m_backgroundColor;
|
||||||
|
ostd::Color m_foregroundColor;
|
||||||
|
ostd::Color m_defaultBackgroundColor { 0, 0, 0, 0 };
|
||||||
|
ostd::Color m_defaultForegroundColor { 0, 220, 0, 255 };
|
||||||
|
ostd::Vec2 m_curosrPosition;
|
||||||
|
BasicRenderer2D m_renderer;
|
||||||
|
WindowBase* m_window { nullptr };
|
||||||
|
int32_t 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 };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -182,7 +182,7 @@ OutputHandlerBase& InteractiveConsole::pStyled(const TextStyleParser::tStyledStr
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& InteractiveConsole::pStyled(const TextStyleBuilder::IRichStringBase& styled)
|
OutputHandlerBase& InteractiveConsole::pStyled(TextStyleBuilder::IRichStringBase& styled)
|
||||||
{
|
{
|
||||||
std::cout << styled;
|
std::cout << styled;
|
||||||
return *this;
|
return *this;
|
||||||
|
|
@ -301,7 +301,7 @@ OutputHandlerBase& InteractiveConsole::clear(void)
|
||||||
Utils::clearConsole();
|
Utils::clearConsole();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractiveConsole::getConsoleSize(int32_t& outColumns, int32_t& outRows)
|
void InteractiveConsole::getConsoleSize(int32_t& outColumns, int32_t& outRows)
|
||||||
{
|
{
|
||||||
Utils::getConsoleSize(outColumns, outRows);
|
Utils::getConsoleSize(outColumns, outRows);
|
||||||
|
|
@ -356,4 +356,4 @@ void InteractiveConsole::__validate_and_clear_buffers(void)
|
||||||
m_validBuffer = true;
|
m_validBuffer = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,14 @@
|
||||||
#include <ostd/Geometry.hpp>
|
#include <ostd/Geometry.hpp>
|
||||||
#include <ostd/IOHandlers.hpp>
|
#include <ostd/IOHandlers.hpp>
|
||||||
|
|
||||||
#include "Defines.hpp"
|
|
||||||
#include "String.hpp"
|
#include "String.hpp"
|
||||||
|
|
||||||
#ifndef WINDOWS_OS
|
#ifndef WINDOWS_OS
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#else
|
#else
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
#endif
|
#endif
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace ostd
|
namespace ostd
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +35,7 @@ namespace ostd
|
||||||
OutputHandlerBase& pChar(char c) override;
|
OutputHandlerBase& pChar(char c) override;
|
||||||
OutputHandlerBase& pStyled(const String& styled) override;
|
OutputHandlerBase& pStyled(const String& styled) override;
|
||||||
OutputHandlerBase& pStyled(const TextStyleParser::tStyledString& styled) override;
|
OutputHandlerBase& pStyled(const TextStyleParser::tStyledString& styled) override;
|
||||||
OutputHandlerBase& pStyled(const TextStyleBuilder::IRichStringBase& styled) override;
|
OutputHandlerBase& pStyled(TextStyleBuilder::IRichStringBase& styled) override;
|
||||||
OutputHandlerBase& pObject(const BaseObject& bo) override;
|
OutputHandlerBase& pObject(const BaseObject& bo) override;
|
||||||
|
|
||||||
OutputHandlerBase& p(const String& se) override;
|
OutputHandlerBase& p(const String& se) override;
|
||||||
|
|
@ -61,10 +59,10 @@ namespace ostd
|
||||||
inline OutputHandlerBase& xy(int32_t x, int32_t y) override { m_cursorPosition = { x, y }; __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& 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& y(int32_t y) override { m_cursorPosition.y = y; __set_cursor(); return *this; }
|
||||||
|
|
||||||
void getConsoleSize(int32_t& outColumns, int32_t& outRows) override;
|
void getConsoleSize(int32_t& outColumns, int32_t& outRows) override;
|
||||||
IPoint getConsoleSize(void) override;
|
IPoint getConsoleSize(void) override;
|
||||||
|
|
||||||
inline IPoint getCursorPosition(void) override { return m_cursorPosition; }
|
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 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 getCursorX(void) override { return m_cursorPosition.x; }
|
||||||
|
|
@ -77,7 +75,7 @@ namespace ostd
|
||||||
inline eMode getMode(void) { return m_mode; }
|
inline eMode getMode(void) { return m_mode; }
|
||||||
|
|
||||||
void update(void);
|
void update(void);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void __set_cursor(void);
|
void __set_cursor(void);
|
||||||
|
|
@ -98,9 +96,9 @@ namespace ostd
|
||||||
{ { 0, 0, 0, 255 }, "Black", true },
|
{ { 0, 0, 0, 255 }, "Black", true },
|
||||||
' '
|
' '
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class eKeys
|
enum class eKeys
|
||||||
{
|
{
|
||||||
NoKeyPressed = 0,
|
NoKeyPressed = 0,
|
||||||
|
|
@ -155,29 +153,29 @@ namespace ostd
|
||||||
public:
|
public:
|
||||||
KeyboardController(void);
|
KeyboardController(void);
|
||||||
~KeyboardController(void);
|
~KeyboardController(void);
|
||||||
|
|
||||||
eKeys getPressedKey(void);
|
eKeys getPressedKey(void);
|
||||||
eKeys waitForKeyPress(void);
|
eKeys waitForKeyPress(void);
|
||||||
|
|
||||||
inline String getInputString(void) { return m_cmd; }
|
inline String getInputString(void) { return m_cmd; }
|
||||||
|
|
||||||
inline bool isOutputEnabled(void) { return m_output_enabled; }
|
inline bool isOutputEnabled(void) { return m_output_enabled; }
|
||||||
inline void enableOutput(bool __oe = true) { m_output_enabled = __oe; }
|
inline void enableOutput(bool __oe = true) { m_output_enabled = __oe; }
|
||||||
inline void disableOutput(void) { enableOutput(false); }
|
inline void disableOutput(void) { enableOutput(false); }
|
||||||
|
|
||||||
inline bool isCommandBufferEnabled(void) { return m_cmd_buffer_enabled; }
|
inline bool isCommandBufferEnabled(void) { return m_cmd_buffer_enabled; }
|
||||||
inline void enableCommandBuffer(bool __cbe = true) { m_cmd_buffer_enabled = __cbe; }
|
inline void enableCommandBuffer(bool __cbe = true) { m_cmd_buffer_enabled = __cbe; }
|
||||||
inline void disableCommandBuffer(void) { enableCommandBuffer(false); }
|
inline void disableCommandBuffer(void) { enableCommandBuffer(false); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String getKeyBuffer(void);
|
String getKeyBuffer(void);
|
||||||
String flushKeyBuffer(void);
|
String flushKeyBuffer(void);
|
||||||
|
|
||||||
#ifndef WINDOWS_OS
|
#ifndef WINDOWS_OS
|
||||||
int kbhit(void);
|
int kbhit(void);
|
||||||
int getch(void);
|
int getch(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifndef WINDOWS_OS
|
#ifndef WINDOWS_OS
|
||||||
|
|
@ -189,4 +187,4 @@ namespace ostd
|
||||||
bool m_output_enabled;
|
bool m_output_enabled;
|
||||||
bool m_cmd_buffer_enabled;
|
bool m_cmd_buffer_enabled;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,12 @@
|
||||||
#include <ostd/String.hpp>
|
#include <ostd/String.hpp>
|
||||||
#include <ostd/TextStyleParser.hpp>
|
#include <ostd/TextStyleParser.hpp>
|
||||||
|
|
||||||
|
namespace ogfx
|
||||||
|
{
|
||||||
|
class WindowBase;
|
||||||
|
class BasicRenderer2D;
|
||||||
|
};
|
||||||
|
|
||||||
namespace ostd
|
namespace ostd
|
||||||
{
|
{
|
||||||
class BaseObject;
|
class BaseObject;
|
||||||
|
|
@ -26,6 +32,7 @@ namespace ostd
|
||||||
friend class ConsoleColors;
|
friend class ConsoleColors;
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
|
inline static const tConsoleColor Transparent { "transparent", { 0, 0, 0, 0 }, false};
|
||||||
inline static const tConsoleColor Red { "red", { 255, 0, 0, 255 }, false};
|
inline static const tConsoleColor Red { "red", { 255, 0, 0, 255 }, false};
|
||||||
inline static const tConsoleColor BrightRed { "brightred", { 255, 70, 70, 255 }, false};
|
inline static const tConsoleColor BrightRed { "brightred", { 255, 70, 70, 255 }, false};
|
||||||
inline static const tConsoleColor Green { "green", { 0, 255, 0, 255 }, false};
|
inline static const tConsoleColor Green { "green", { 0, 255, 0, 255 }, false};
|
||||||
|
|
@ -43,6 +50,7 @@ namespace ostd
|
||||||
inline static const tConsoleColor BrightGray { "brightgray", { 150, 150, 150, 255 }, false};
|
inline static const tConsoleColor BrightGray { "brightgray", { 150, 150, 150, 255 }, false};
|
||||||
inline static const tConsoleColor White { "white", { 255, 255, 255, 255 }, false};
|
inline static const tConsoleColor White { "white", { 255, 255, 255, 255 }, false};
|
||||||
|
|
||||||
|
inline static const tConsoleColor OnTransparent { "transparent", { 0, 0, 0, 0 }, true};
|
||||||
inline static const tConsoleColor OnRed { "red", { 255, 0, 0, 255 }, true};
|
inline static const tConsoleColor OnRed { "red", { 255, 0, 0, 255 }, true};
|
||||||
inline static const tConsoleColor OnBrightRed { "brightred", { 255, 70, 70, 255 }, true};
|
inline static const tConsoleColor OnBrightRed { "brightred", { 255, 70, 70, 255 }, true};
|
||||||
inline static const tConsoleColor OnGreen { "green", { 0, 255, 0, 255 }, true};
|
inline static const tConsoleColor OnGreen { "green", { 0, 255, 0, 255 }, true};
|
||||||
|
|
@ -119,7 +127,7 @@ namespace ostd
|
||||||
inline virtual OutputHandlerBase& pChar(char c) { return *this; }
|
inline virtual OutputHandlerBase& pChar(char c) { return *this; }
|
||||||
inline virtual OutputHandlerBase& pStyled(const String& styled) { return *this; }
|
inline virtual OutputHandlerBase& pStyled(const String& styled) { return *this; }
|
||||||
inline virtual OutputHandlerBase& pStyled(const TextStyleParser::tStyledString& styled) { return *this; }
|
inline virtual OutputHandlerBase& pStyled(const TextStyleParser::tStyledString& styled) { return *this; }
|
||||||
inline virtual OutputHandlerBase& pStyled(const TextStyleBuilder::IRichStringBase& styled) { return *this; }
|
inline virtual OutputHandlerBase& pStyled(TextStyleBuilder::IRichStringBase& styled) { return *this; }
|
||||||
inline virtual OutputHandlerBase& pObject(const BaseObject& bo) { return *this; }
|
inline virtual OutputHandlerBase& pObject(const BaseObject& bo) { return *this; }
|
||||||
|
|
||||||
inline virtual OutputHandlerBase& p(const String& se) { return *this; }
|
inline virtual OutputHandlerBase& p(const String& se) { return *this; }
|
||||||
|
|
@ -165,7 +173,7 @@ namespace ostd
|
||||||
OutputHandlerBase& pChar(char c) override;
|
OutputHandlerBase& pChar(char c) override;
|
||||||
OutputHandlerBase& pStyled(const String& styled) override;
|
OutputHandlerBase& pStyled(const String& styled) override;
|
||||||
OutputHandlerBase& pStyled(const TextStyleParser::tStyledString& styled) override;
|
OutputHandlerBase& pStyled(const TextStyleParser::tStyledString& styled) override;
|
||||||
OutputHandlerBase& pStyled(const TextStyleBuilder::IRichStringBase& styled) override;
|
OutputHandlerBase& pStyled(TextStyleBuilder::IRichStringBase& styled) override;
|
||||||
OutputHandlerBase& pObject(const BaseObject& bo) override;
|
OutputHandlerBase& pObject(const BaseObject& bo) override;
|
||||||
|
|
||||||
OutputHandlerBase& p(const String& se) override;
|
OutputHandlerBase& p(const String& se) override;
|
||||||
|
|
|
||||||
|
|
@ -14,155 +14,155 @@
|
||||||
namespace ostd
|
namespace ostd
|
||||||
{
|
{
|
||||||
std::ostream &operator<<(std::ostream &os, ConsoleColors::tConsoleColor const &col)
|
std::ostream &operator<<(std::ostream &os, ConsoleColors::tConsoleColor const &col)
|
||||||
{
|
{
|
||||||
if (col.background)
|
if (col.background)
|
||||||
{
|
{
|
||||||
if (col.name == "red") os << termcolor::on_red;
|
if (col.name == "red") os << termcolor::on_red;
|
||||||
else if (col.name == "brightred") os << termcolor::on_bright_red;
|
else if (col.name == "brightred") os << termcolor::on_bright_red;
|
||||||
else if (col.name == "green") os << termcolor::on_green;
|
else if (col.name == "green") os << termcolor::on_green;
|
||||||
else if (col.name == "brightgreen") os << termcolor::on_bright_green;
|
else if (col.name == "brightgreen") os << termcolor::on_bright_green;
|
||||||
else if (col.name == "blue") os << termcolor::on_blue;
|
else if (col.name == "blue") os << termcolor::on_blue;
|
||||||
else if (col.name == "brightblue") os << termcolor::on_bright_blue;
|
else if (col.name == "brightblue") os << termcolor::on_bright_blue;
|
||||||
else if (col.name == "magenta") os << termcolor::on_magenta;
|
else if (col.name == "magenta") os << termcolor::on_magenta;
|
||||||
else if (col.name == "brightmagenta") os << termcolor::on_bright_magenta;
|
else if (col.name == "brightmagenta") os << termcolor::on_bright_magenta;
|
||||||
else if (col.name == "cyan") os << termcolor::on_cyan;
|
else if (col.name == "cyan") os << termcolor::on_cyan;
|
||||||
else if (col.name == "brightcyan") os << termcolor::on_bright_cyan;
|
else if (col.name == "brightcyan") os << termcolor::on_bright_cyan;
|
||||||
else if (col.name == "yellow") os << termcolor::on_yellow;
|
else if (col.name == "yellow") os << termcolor::on_yellow;
|
||||||
else if (col.name == "brightyellow") os << termcolor::on_bright_yellow;
|
else if (col.name == "brightyellow") os << termcolor::on_bright_yellow;
|
||||||
else if (col.name == "black") os << termcolor::on_grey;
|
else if (col.name == "black") os << termcolor::on_grey;
|
||||||
else if (col.name == "darkgray") os << termcolor::on_bright_grey;
|
else if (col.name == "darkgray") os << termcolor::on_bright_grey;
|
||||||
else if (col.name == "brightgray") os << termcolor::on_white;
|
else if (col.name == "brightgray") os << termcolor::on_white;
|
||||||
else if (col.name == "white") os << termcolor::on_bright_white;
|
else if (col.name == "white") os << termcolor::on_bright_white;
|
||||||
return os;
|
|
||||||
}
|
|
||||||
if (col.name == "red") os << termcolor::red;
|
|
||||||
else if (col.name == "brightred") os << termcolor::bright_red;
|
|
||||||
else if (col.name == "green") os << termcolor::green;
|
|
||||||
else if (col.name == "brightgreen") os << termcolor::bright_green;
|
|
||||||
else if (col.name == "blue") os << termcolor::blue;
|
|
||||||
else if (col.name == "brightblue") os << termcolor::bright_blue;
|
|
||||||
else if (col.name == "magenta") os << termcolor::magenta;
|
|
||||||
else if (col.name == "brightmagenta") os << termcolor::bright_magenta;
|
|
||||||
else if (col.name == "cyan") os << termcolor::cyan;
|
|
||||||
else if (col.name == "brightcyan") os << termcolor::bright_cyan;
|
|
||||||
else if (col.name == "yellow") os << termcolor::yellow;
|
|
||||||
else if (col.name == "brightyellow") os << termcolor::bright_yellow;
|
|
||||||
else if (col.name == "black") os << termcolor::grey;
|
|
||||||
else if (col.name == "darkgray") os << termcolor::bright_grey;
|
|
||||||
else if (col.name == "brightgray") os << termcolor::white;
|
|
||||||
else if (col.name == "white") os << termcolor::bright_white;
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
if (col.name == "red") os << termcolor::red;
|
||||||
|
else if (col.name == "brightred") os << termcolor::bright_red;
|
||||||
|
else if (col.name == "green") os << termcolor::green;
|
||||||
|
else if (col.name == "brightgreen") os << termcolor::bright_green;
|
||||||
|
else if (col.name == "blue") os << termcolor::blue;
|
||||||
|
else if (col.name == "brightblue") os << termcolor::bright_blue;
|
||||||
|
else if (col.name == "magenta") os << termcolor::magenta;
|
||||||
|
else if (col.name == "brightmagenta") os << termcolor::bright_magenta;
|
||||||
|
else if (col.name == "cyan") os << termcolor::cyan;
|
||||||
|
else if (col.name == "brightcyan") os << termcolor::bright_cyan;
|
||||||
|
else if (col.name == "yellow") os << termcolor::yellow;
|
||||||
|
else if (col.name == "brightyellow") os << termcolor::bright_yellow;
|
||||||
|
else if (col.name == "black") os << termcolor::grey;
|
||||||
|
else if (col.name == "darkgray") os << termcolor::bright_grey;
|
||||||
|
else if (col.name == "brightgray") os << termcolor::white;
|
||||||
|
else if (col.name == "white") os << termcolor::bright_white;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::bg(const ConsoleColors::tConsoleColor& color)
|
OutputHandlerBase& ConsoleOutputHandler::bg(const ConsoleColors::tConsoleColor& color)
|
||||||
{
|
{
|
||||||
std::cout << color.asBackground();
|
std::cout << color.asBackground();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::bg(const String& color)
|
OutputHandlerBase& ConsoleOutputHandler::bg(const String& color)
|
||||||
{
|
{
|
||||||
std::cout << ConsoleColors::getFromName(color, true);
|
std::cout << ConsoleColors::getFromName(color, true);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::fg(const ConsoleColors::tConsoleColor& color)
|
OutputHandlerBase& ConsoleOutputHandler::fg(const ConsoleColors::tConsoleColor& color)
|
||||||
{
|
{
|
||||||
std::cout << color.asForeground();
|
std::cout << color.asForeground();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::fg(const String& color)
|
OutputHandlerBase& ConsoleOutputHandler::fg(const String& color)
|
||||||
{
|
{
|
||||||
std::cout << ConsoleColors::getFromName(color, false);
|
std::cout << ConsoleColors::getFromName(color, false);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::pChar(char c)
|
OutputHandlerBase& ConsoleOutputHandler::pChar(char c)
|
||||||
{
|
{
|
||||||
std::cout << (char)c;
|
std::cout << (char)c;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::pStyled(const String& styled)
|
OutputHandlerBase& ConsoleOutputHandler::pStyled(const String& styled)
|
||||||
{
|
{
|
||||||
return pStyled(TextStyleParser::parse(styled));
|
return pStyled(TextStyleParser::parse(styled));
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::pStyled(const TextStyleParser::tStyledString& styled)
|
OutputHandlerBase& ConsoleOutputHandler::pStyled(const TextStyleParser::tStyledString& styled)
|
||||||
{
|
{
|
||||||
std::cout << styled;
|
std::cout << styled;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::pStyled(const TextStyleBuilder::IRichStringBase& styled)
|
OutputHandlerBase& ConsoleOutputHandler::pStyled(TextStyleBuilder::IRichStringBase& styled)
|
||||||
{
|
{
|
||||||
std::cout << styled;
|
std::cout << styled;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::pObject(const BaseObject& bo)
|
OutputHandlerBase& ConsoleOutputHandler::pObject(const BaseObject& bo)
|
||||||
{
|
{
|
||||||
std::cout << bo;
|
std::cout << bo;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(const String& se)
|
OutputHandlerBase& ConsoleOutputHandler::p(const String& se)
|
||||||
{
|
{
|
||||||
std::cout << se;
|
std::cout << se;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(uint8_t i)
|
OutputHandlerBase& ConsoleOutputHandler::p(uint8_t i)
|
||||||
{
|
{
|
||||||
std::cout << (uint8_t)i;
|
std::cout << (uint8_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(int8_t i)
|
OutputHandlerBase& ConsoleOutputHandler::p(int8_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int8_t)i;
|
std::cout << (int8_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(uint16_t i)
|
OutputHandlerBase& ConsoleOutputHandler::p(uint16_t i)
|
||||||
{
|
{
|
||||||
std::cout << (uint16_t)i;
|
std::cout << (uint16_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(int16_t i)
|
OutputHandlerBase& ConsoleOutputHandler::p(int16_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int16_t)i;
|
std::cout << (int16_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(uint32_t i)
|
OutputHandlerBase& ConsoleOutputHandler::p(uint32_t i)
|
||||||
{
|
{
|
||||||
std::cout << (uint32_t)i;
|
std::cout << (uint32_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(int32_t i)
|
OutputHandlerBase& ConsoleOutputHandler::p(int32_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int32_t)i;
|
std::cout << (int32_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(uint64_t i)
|
OutputHandlerBase& ConsoleOutputHandler::p(uint64_t i)
|
||||||
{
|
{
|
||||||
std::cout << (uint64_t)i;
|
std::cout << (uint64_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(int64_t i)
|
OutputHandlerBase& ConsoleOutputHandler::p(int64_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int64_t)i;
|
std::cout << (int64_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(float f, uint8_t precision)
|
OutputHandlerBase& ConsoleOutputHandler::p(float f, uint8_t precision)
|
||||||
{
|
{
|
||||||
if (precision == 0)
|
if (precision == 0)
|
||||||
|
|
@ -177,7 +177,7 @@ namespace ostd
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::p(double f, uint8_t precision)
|
OutputHandlerBase& ConsoleOutputHandler::p(double f, uint8_t precision)
|
||||||
{
|
{
|
||||||
if (precision == 0)
|
if (precision == 0)
|
||||||
|
|
@ -192,25 +192,25 @@ namespace ostd
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::nl(void)
|
OutputHandlerBase& ConsoleOutputHandler::nl(void)
|
||||||
{
|
{
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::flush(void)
|
OutputHandlerBase& ConsoleOutputHandler::flush(void)
|
||||||
{
|
{
|
||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::reset(void)
|
OutputHandlerBase& ConsoleOutputHandler::reset(void)
|
||||||
{
|
{
|
||||||
std::cout << termcolor::reset;
|
std::cout << termcolor::reset;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputHandlerBase& ConsoleOutputHandler::clear(void)
|
OutputHandlerBase& ConsoleOutputHandler::clear(void)
|
||||||
{
|
{
|
||||||
Utils::clearConsole();
|
Utils::clearConsole();
|
||||||
|
|
@ -287,67 +287,67 @@ namespace ostd
|
||||||
cse.addi(color.a).add("]");
|
cse.addi(color.a).add("]");
|
||||||
return col(cse.str());
|
return col(cse.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::p(char c)
|
IOutputHandler& ConsoleOutputHandler::p(char c)
|
||||||
{
|
{
|
||||||
std::cout << (char)c;
|
std::cout << (char)c;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::p(const StringEditor& se)
|
IOutputHandler& ConsoleOutputHandler::p(const StringEditor& se)
|
||||||
{
|
{
|
||||||
std::cout << se;
|
std::cout << se;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::pi(uint8_t i)
|
IOutputHandler& ConsoleOutputHandler::pi(uint8_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int64_t)i;
|
std::cout << (int64_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::pi(int8_t i)
|
IOutputHandler& ConsoleOutputHandler::pi(int8_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int64_t)i;
|
std::cout << (int64_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::pi(uint16_t i)
|
IOutputHandler& ConsoleOutputHandler::pi(uint16_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int64_t)i;
|
std::cout << (int64_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::pi(int16_t i)
|
IOutputHandler& ConsoleOutputHandler::pi(int16_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int64_t)i;
|
std::cout << (int64_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::pi(uint32_t i)
|
IOutputHandler& ConsoleOutputHandler::pi(uint32_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int64_t)i;
|
std::cout << (int64_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::pi(int32_t i)
|
IOutputHandler& ConsoleOutputHandler::pi(int32_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int64_t)i;
|
std::cout << (int64_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::pi(uint64_t i)
|
IOutputHandler& ConsoleOutputHandler::pi(uint64_t i)
|
||||||
{
|
{
|
||||||
std::cout << (uint64_t)i;
|
std::cout << (uint64_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::pi(int64_t i)
|
IOutputHandler& ConsoleOutputHandler::pi(int64_t i)
|
||||||
{
|
{
|
||||||
std::cout << (int64_t)i;
|
std::cout << (int64_t)i;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::pf(float f, uint8_t precision)
|
IOutputHandler& ConsoleOutputHandler::pf(float f, uint8_t precision)
|
||||||
{
|
{
|
||||||
if (precision == 0)
|
if (precision == 0)
|
||||||
|
|
@ -362,7 +362,7 @@ namespace ostd
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::pf(double f, uint8_t precision)
|
IOutputHandler& ConsoleOutputHandler::pf(double f, uint8_t precision)
|
||||||
{
|
{
|
||||||
if (precision == 0)
|
if (precision == 0)
|
||||||
|
|
@ -394,25 +394,25 @@ namespace ostd
|
||||||
std::cout << styled.getStyledString();
|
std::cout << styled.getStyledString();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::nl(void)
|
IOutputHandler& ConsoleOutputHandler::nl(void)
|
||||||
{
|
{
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::flush(void)
|
IOutputHandler& ConsoleOutputHandler::flush(void)
|
||||||
{
|
{
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::reset(void)
|
IOutputHandler& ConsoleOutputHandler::reset(void)
|
||||||
{
|
{
|
||||||
std::cout << termcolor::reset;
|
std::cout << termcolor::reset;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& ConsoleOutputHandler::clear(void)
|
IOutputHandler& ConsoleOutputHandler::clear(void)
|
||||||
{
|
{
|
||||||
Utils::clearConsole();
|
Utils::clearConsole();
|
||||||
|
|
@ -428,79 +428,77 @@ namespace ostd
|
||||||
m_buffer.add(c);
|
m_buffer.add(c);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::p(const StringEditor& se)
|
IOutputHandler& BufferedOutputHandler::p(const StringEditor& se)
|
||||||
{
|
{
|
||||||
m_buffer.add(se.str());
|
m_buffer.add(se.str());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::pi(uint8_t i)
|
IOutputHandler& BufferedOutputHandler::pi(uint8_t i)
|
||||||
{
|
{
|
||||||
m_buffer.addi(i);
|
m_buffer.addi(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::pi(int8_t i)
|
IOutputHandler& BufferedOutputHandler::pi(int8_t i)
|
||||||
{
|
{
|
||||||
m_buffer.addi(i);
|
m_buffer.addi(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::pi(uint16_t i)
|
IOutputHandler& BufferedOutputHandler::pi(uint16_t i)
|
||||||
{
|
{
|
||||||
m_buffer.addi(i);
|
m_buffer.addi(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::pi(int16_t i)
|
IOutputHandler& BufferedOutputHandler::pi(int16_t i)
|
||||||
{
|
{
|
||||||
m_buffer.addi(i);
|
m_buffer.addi(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::pi(uint32_t i)
|
IOutputHandler& BufferedOutputHandler::pi(uint32_t i)
|
||||||
{
|
{
|
||||||
m_buffer.addi(i);
|
m_buffer.addi(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::pi(int32_t i)
|
IOutputHandler& BufferedOutputHandler::pi(int32_t i)
|
||||||
{
|
{
|
||||||
m_buffer.addi(i);
|
m_buffer.addi(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::pi(uint64_t i)
|
IOutputHandler& BufferedOutputHandler::pi(uint64_t i)
|
||||||
{
|
{
|
||||||
m_buffer.addi(i);
|
m_buffer.addi(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::pi(int64_t i)
|
IOutputHandler& BufferedOutputHandler::pi(int64_t i)
|
||||||
{
|
{
|
||||||
m_buffer.addi(i);
|
m_buffer.addi(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::pf(float f, uint8_t precision)
|
IOutputHandler& BufferedOutputHandler::pf(float f, uint8_t precision)
|
||||||
{
|
{
|
||||||
m_buffer.addf(f);
|
m_buffer.addf(f);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::pf(double f, uint8_t precision)
|
IOutputHandler& BufferedOutputHandler::pf(double f, uint8_t precision)
|
||||||
{
|
{
|
||||||
m_buffer.addf(f);
|
m_buffer.addf(f);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOutputHandler& BufferedOutputHandler::nl(void)
|
IOutputHandler& BufferedOutputHandler::nl(void)
|
||||||
{
|
{
|
||||||
m_buffer.add("\n");
|
m_buffer.add("\n");
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,9 @@
|
||||||
|
|
||||||
namespace ostd
|
namespace ostd
|
||||||
{
|
{
|
||||||
void SignalHandler::init(void)
|
void SignalHandler::init(bool allow_reinit)
|
||||||
{
|
{
|
||||||
|
if (m_initialized && !allow_reinit) return;
|
||||||
SignalHandler::m_customRecievers.clear();
|
SignalHandler::m_customRecievers.clear();
|
||||||
SignalHandler::m_customRecievers.reserve(SignalHandler::__SIGNAL_BUFFER_START_SIZE);
|
SignalHandler::m_customRecievers.reserve(SignalHandler::__SIGNAL_BUFFER_START_SIZE);
|
||||||
SignalHandler::m_mousePressedRecievers.clear();
|
SignalHandler::m_mousePressedRecievers.clear();
|
||||||
|
|
@ -30,6 +31,7 @@ namespace ostd
|
||||||
SignalHandler::m_delegatedSignals.reserve(SignalHandler::__DELEGATED_SIGNALS_BUFFER_START_SIZE);
|
SignalHandler::m_delegatedSignals.reserve(SignalHandler::__DELEGATED_SIGNALS_BUFFER_START_SIZE);
|
||||||
SignalHandler::m_onGuiEventRecievers.clear();
|
SignalHandler::m_onGuiEventRecievers.clear();
|
||||||
SignalHandler::m_onGuiEventRecievers.reserve(SignalHandler::__SIGNAL_BUFFER_START_SIZE);
|
SignalHandler::m_onGuiEventRecievers.reserve(SignalHandler::__SIGNAL_BUFFER_START_SIZE);
|
||||||
|
m_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignalHandler::refresh(void)
|
void SignalHandler::refresh(void)
|
||||||
|
|
@ -69,7 +71,6 @@ namespace ostd
|
||||||
sig_list = &m_windowClosedRecievers;
|
sig_list = &m_windowClosedRecievers;
|
||||||
else if (signal_id == tBuiltinSignals::OnGuiEvent)
|
else if (signal_id == tBuiltinSignals::OnGuiEvent)
|
||||||
sig_list = &m_onGuiEventRecievers;
|
sig_list = &m_onGuiEventRecievers;
|
||||||
|
|
||||||
else if (signal_id > tBuiltinSignals::CustomSignalBase)
|
else if (signal_id > tBuiltinSignals::CustomSignalBase)
|
||||||
sig_list = &m_customRecievers;
|
sig_list = &m_customRecievers;
|
||||||
if (sig_list == nullptr)
|
if (sig_list == nullptr)
|
||||||
|
|
@ -111,7 +112,7 @@ namespace ostd
|
||||||
m_onGuiEventRecievers.push_back({ &object, signal_id });
|
m_onGuiEventRecievers.push_back({ &object, signal_id });
|
||||||
else if (signal_id > tBuiltinSignals::CustomSignalBase)
|
else if (signal_id > tBuiltinSignals::CustomSignalBase)
|
||||||
m_customRecievers.push_back({ &object, signal_id });
|
m_customRecievers.push_back({ &object, signal_id });
|
||||||
else
|
else
|
||||||
OX_WARN("ox::SignalHandler::connect(...): Unknown signal ID: <%d>", signal_id);
|
OX_WARN("ox::SignalHandler::connect(...): Unknown signal ID: <%d>", signal_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#include <ostd/Types.hpp>
|
#include <ostd/Types.hpp>
|
||||||
#include <ostd/BaseObject.hpp>
|
#include <ostd/BaseObject.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace ostd
|
namespace ostd
|
||||||
{
|
{
|
||||||
|
|
@ -65,7 +64,7 @@ namespace ostd
|
||||||
inline tDelegateSignal(uint32_t _id, BaseObject& _ud) : id(_id), ud(_ud) { }
|
inline tDelegateSignal(uint32_t _id, BaseObject& _ud) : id(_id), ud(_ud) { }
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
static void init(void);
|
static void init(bool allow_reinit = false);
|
||||||
static void refresh(void);
|
static void refresh(void);
|
||||||
|
|
||||||
static void emitSignal(uint32_t signal_id, uint8_t prio = tSignalPriority::Normal, BaseObject& userData = BaseObject::InvalidRef());
|
static void emitSignal(uint32_t signal_id, uint8_t prio = tSignalPriority::Normal, BaseObject& userData = BaseObject::InvalidRef());
|
||||||
|
|
@ -92,8 +91,10 @@ namespace ostd
|
||||||
|
|
||||||
inline static constexpr uint16_t __SIGNAL_BUFFER_START_SIZE { 128 };
|
inline static constexpr uint16_t __SIGNAL_BUFFER_START_SIZE { 128 };
|
||||||
inline static constexpr uint16_t __DELEGATED_SIGNALS_BUFFER_START_SIZE { 128 };
|
inline static constexpr uint16_t __DELEGATED_SIGNALS_BUFFER_START_SIZE { 128 };
|
||||||
|
|
||||||
|
inline static bool m_initialized { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class WindowSizeObj : public BaseObject
|
class WindowSizeObj : public BaseObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -34,24 +34,24 @@ namespace ostd
|
||||||
}).base(), m_data.end());
|
}).base(), m_data.end());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::trim(void)
|
String& String::trim(void)
|
||||||
{
|
{
|
||||||
return ltrim().rtrim();
|
return ltrim().rtrim();
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::toLower(void)
|
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(), [](unsigned char c){ return std::tolower(c); });
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::toUpper(void)
|
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(), [](unsigned char c){ return std::toupper(c); });
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::addPadding(uint32_t new_string_length, char c, ePaddingBehavior padding_behavior)
|
String& String::addPadding(uint32_t new_string_length, char c, ePaddingBehavior padding_behavior)
|
||||||
{
|
{
|
||||||
if (len() - 1 >= new_string_length) return *this;
|
if (len() - 1 >= new_string_length) return *this;
|
||||||
|
|
@ -94,7 +94,7 @@ namespace ostd
|
||||||
if (leftPadding < 0 || rightPadding < 0) return *this;
|
if (leftPadding < 0 || rightPadding < 0) return *this;
|
||||||
return addLeftPadding(len() + leftPadding, c).addRightPadding(len() + rightPadding, c);
|
return addLeftPadding(len() + leftPadding, c).addRightPadding(len() + rightPadding, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::addLeftPadding(uint32_t new_string_length, char c)
|
String& String::addLeftPadding(uint32_t new_string_length, char c)
|
||||||
{
|
{
|
||||||
reverse();
|
reverse();
|
||||||
|
|
@ -116,14 +116,14 @@ namespace ostd
|
||||||
std::reverse(m_data.begin(), m_data.end());
|
std::reverse(m_data.begin(), m_data.end());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::replaceAll(const String& what, const String& with)
|
String& String::replaceAll(const String& what, const String& with)
|
||||||
{
|
{
|
||||||
while (contains(what))
|
while (contains(what))
|
||||||
replaceFirst(what, with);
|
replaceFirst(what, with);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::replaceFirst(const String& what, const String& with)
|
String& String::replaceFirst(const String& what, const String& with)
|
||||||
{
|
{
|
||||||
int32_t index = indexOf(what);
|
int32_t index = indexOf(what);
|
||||||
|
|
@ -131,7 +131,7 @@ namespace ostd
|
||||||
m_data.replace(index, what.len(), with.cpp_str());
|
m_data.replace(index, what.len(), with.cpp_str());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive)
|
String& String::regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -147,21 +147,21 @@ namespace ostd
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::put(uint32_t index, char c)
|
String& String::put(uint32_t index, char c)
|
||||||
{
|
{
|
||||||
if (index < m_data.length())
|
if (index < m_data.length())
|
||||||
m_data[index] = c;
|
m_data[index] = c;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::substr(uint32_t start, int32_t end)
|
String& String::substr(uint32_t start, int32_t end)
|
||||||
{
|
{
|
||||||
if (end < 0) m_data = m_data.substr(start);
|
if (end < 0) m_data = m_data.substr(start);
|
||||||
else m_data = m_data.substr(start, end - start);
|
else m_data = m_data.substr(start, end - start);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::fixedLength(uint32_t length, char fill_character, const String& truncate_indicator)
|
String& String::fixedLength(uint32_t length, char fill_character, const String& truncate_indicator)
|
||||||
{
|
{
|
||||||
if (length < truncate_indicator.len()) return *this;
|
if (length < truncate_indicator.len()) return *this;
|
||||||
|
|
@ -182,61 +182,61 @@ namespace ostd
|
||||||
m_data += c;
|
m_data += c;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(const String& se)
|
String& String::add(const String& se)
|
||||||
{
|
{
|
||||||
m_data += se.cpp_str();
|
m_data += se.cpp_str();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(uint8_t i)
|
String& String::add(uint8_t i)
|
||||||
{
|
{
|
||||||
m_data += std::to_string(i);
|
m_data += std::to_string(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(int8_t i)
|
String& String::add(int8_t i)
|
||||||
{
|
{
|
||||||
m_data += std::to_string(i);
|
m_data += std::to_string(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(uint16_t i)
|
String& String::add(uint16_t i)
|
||||||
{
|
{
|
||||||
m_data += std::to_string(i);
|
m_data += std::to_string(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(int16_t i)
|
String& String::add(int16_t i)
|
||||||
{
|
{
|
||||||
m_data += std::to_string(i);
|
m_data += std::to_string(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(uint32_t i)
|
String& String::add(uint32_t i)
|
||||||
{
|
{
|
||||||
m_data += std::to_string(i);
|
m_data += std::to_string(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(int32_t i)
|
String& String::add(int32_t i)
|
||||||
{
|
{
|
||||||
m_data += std::to_string(i);
|
m_data += std::to_string(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(uint64_t i)
|
String& String::add(uint64_t i)
|
||||||
{
|
{
|
||||||
m_data += std::to_string(i);
|
m_data += std::to_string(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(int64_t i)
|
String& String::add(int64_t i)
|
||||||
{
|
{
|
||||||
m_data += std::to_string(i);
|
m_data += std::to_string(i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(float f, uint8_t precision)
|
String& String::add(float f, uint8_t precision)
|
||||||
{
|
{
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
|
@ -247,7 +247,7 @@ namespace ostd
|
||||||
cpp_string s = stream.str();
|
cpp_string s = stream.str();
|
||||||
return add(s);
|
return add(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
String& String::add(double f, uint8_t precision)
|
String& String::add(double f, uint8_t precision)
|
||||||
{
|
{
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
|
@ -258,7 +258,7 @@ namespace ostd
|
||||||
cpp_string s = stream.str();
|
cpp_string s = stream.str();
|
||||||
return add(s);
|
return add(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//New String
|
//New String
|
||||||
|
|
@ -267,31 +267,31 @@ namespace ostd
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.ltrim();
|
return __str.ltrim();
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_rtrim(void) const
|
String String::new_rtrim(void) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.rtrim();
|
return __str.rtrim();
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_trim(void) const
|
String String::new_trim(void) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.trim();
|
return __str.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_toLower(void) const
|
String String::new_toLower(void) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.toLower();
|
return __str.toLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_toUpper(void) const
|
String String::new_toUpper(void) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.toUpper();
|
return __str.toUpper();
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_addPadding(uint32_t new_string_length, char c, ePaddingBehavior padding_behavior) const
|
String String::new_addPadding(uint32_t new_string_length, char c, ePaddingBehavior padding_behavior) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
|
|
@ -309,43 +309,43 @@ namespace ostd
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.addRightPadding(new_string_length, c);
|
return __str.addRightPadding(new_string_length, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_reverse(void) const
|
String String::new_reverse(void) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.reverse();
|
return __str.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_replaceAll(const String& what, const String& with) const
|
String String::new_replaceAll(const String& what, const String& with) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.replaceAll(what, with);
|
return __str.replaceAll(what, with);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_replaceFirst(const String& what, const String& with) const
|
String String::new_replaceFirst(const String& what, const String& with) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.replaceFirst(what, with);
|
return __str.replaceFirst(what, with);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive) const
|
String String::new_regexReplace(const String& regex_pattern, const String& replace_with, bool case_insensitive) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.regexReplace(regex_pattern, replace_with, case_insensitive);
|
return __str.regexReplace(regex_pattern, replace_with, case_insensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_put(uint32_t index, char c) const
|
String String::new_put(uint32_t index, char c) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.put(index, c);
|
return __str.put(index, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_substr(uint32_t start, int32_t end) const
|
String String::new_substr(uint32_t start, int32_t end) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.substr(start, end);
|
return __str.substr(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_fixedLength(uint32_t length, char fill_character, const String& truncate_indicator) const
|
String String::new_fixedLength(uint32_t length, char fill_character, const String& truncate_indicator) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
|
|
@ -358,73 +358,73 @@ namespace ostd
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.addChar(c);
|
return __str.addChar(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(const String& se) const
|
String String::new_add(const String& se) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(se);
|
return __str.add(se);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(uint8_t i) const
|
String String::new_add(uint8_t i) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(i);
|
return __str.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(int8_t i) const
|
String String::new_add(int8_t i) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(i);
|
return __str.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(uint16_t i) const
|
String String::new_add(uint16_t i) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(i);
|
return __str.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(int16_t i) const
|
String String::new_add(int16_t i) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(i);
|
return __str.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(uint32_t i) const
|
String String::new_add(uint32_t i) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(i);
|
return __str.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(int32_t i) const
|
String String::new_add(int32_t i) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(i);
|
return __str.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(uint64_t i) const
|
String String::new_add(uint64_t i) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(i);
|
return __str.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(int64_t i) const
|
String String::new_add(int64_t i) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(i);
|
return __str.add(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(float f, uint8_t precision) const
|
String String::new_add(float f, uint8_t precision) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(f, precision);
|
return __str.add(f, precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::new_add(double f, uint8_t precision) const
|
String String::new_add(double f, uint8_t precision) const
|
||||||
{
|
{
|
||||||
String __str = m_data;
|
String __str = m_data;
|
||||||
return __str.add(f, precision);
|
return __str.add(f, precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Utility
|
//Utility
|
||||||
|
|
@ -433,19 +433,19 @@ namespace ostd
|
||||||
if (!isNumeric(false)) return 0;
|
if (!isNumeric(false)) return 0;
|
||||||
return Utils::strToInt(m_data);
|
return Utils::strToInt(m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
float String::toFloat(void) const
|
float String::toFloat(void) const
|
||||||
{
|
{
|
||||||
if (!isNumeric(true)) return 0;
|
if (!isNumeric(true)) return 0;
|
||||||
return std::stof(m_data);
|
return std::stof(m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
double String::toDouble(void) const
|
double String::toDouble(void) const
|
||||||
{
|
{
|
||||||
if (!isNumeric(true)) return 0;
|
if (!isNumeric(true)) return 0;
|
||||||
return std::stod(m_data);
|
return std::stod(m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String::isNumeric(bool decimal) const
|
bool String::isNumeric(bool decimal) const
|
||||||
{
|
{
|
||||||
if (decimal)
|
if (decimal)
|
||||||
|
|
@ -453,38 +453,38 @@ namespace ostd
|
||||||
std::istringstream iss(m_data);
|
std::istringstream iss(m_data);
|
||||||
double f;
|
double f;
|
||||||
iss >> std::noskipws >> f;
|
iss >> std::noskipws >> f;
|
||||||
return iss.eof() && !iss.fail();
|
return iss.eof() && !iss.fail();
|
||||||
}
|
}
|
||||||
return Utils::isInt(m_data);
|
return Utils::isInt(m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String::contains(char c) const
|
bool String::contains(char c) const
|
||||||
{
|
{
|
||||||
return m_data.find(c) != std::string::npos;
|
return m_data.find(c) != std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String::contains(const String& str) const
|
bool String::contains(const String& str) const
|
||||||
{
|
{
|
||||||
return m_data.find(str.cpp_str()) != std::string::npos;
|
return m_data.find(str.cpp_str()) != std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String::startsWith(const String& str) const
|
bool String::startsWith(const String& str) const
|
||||||
{
|
{
|
||||||
return m_data.starts_with(str);
|
return m_data.starts_with(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String::endsWith(const String& str) const
|
bool String::endsWith(const String& str) const
|
||||||
{
|
{
|
||||||
return m_data.ends_with(str);
|
return m_data.ends_with(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t String::count(const String& str) const
|
uint32_t String::count(const String& str) const
|
||||||
{
|
{
|
||||||
Tokens tok = tokenize(str, false, true);
|
Tokens tok = tokenize(str, false, true);
|
||||||
if (tok.count() < 1) return 0;
|
if (tok.count() < 1) return 0;
|
||||||
return tok.count() - 1;
|
return tok.count() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t String::indexOf(char c, uint32_t start) const
|
int32_t String::indexOf(char c, uint32_t start) const
|
||||||
{
|
{
|
||||||
cpp_string cc = "";
|
cpp_string cc = "";
|
||||||
|
|
@ -493,14 +493,14 @@ namespace ostd
|
||||||
if (pos == std::string::npos) return -1;
|
if (pos == std::string::npos) return -1;
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t String::indexOf(const String& str, uint32_t start) const
|
int32_t String::indexOf(const String& str, uint32_t start) const
|
||||||
{
|
{
|
||||||
int32_t pos = m_data.find(str.c_str(), start);
|
int32_t pos = m_data.find(str.c_str(), start);
|
||||||
if (pos == std::string::npos) return -1;
|
if (pos == std::string::npos) return -1;
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t String::lastIndexOf(char c) const
|
int32_t String::lastIndexOf(char c) const
|
||||||
{
|
{
|
||||||
String se(m_data);
|
String se(m_data);
|
||||||
|
|
@ -509,7 +509,7 @@ namespace ostd
|
||||||
if (pos < 0) return -1;
|
if (pos < 0) return -1;
|
||||||
return len() - pos - 1;
|
return len() - pos - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t String::lastIndexOf(const String& str) const
|
int32_t String::lastIndexOf(const String& str) const
|
||||||
{
|
{
|
||||||
String se(m_data);
|
String se(m_data);
|
||||||
|
|
@ -519,7 +519,7 @@ namespace ostd
|
||||||
if (pos < 0) return -1;
|
if (pos < 0) return -1;
|
||||||
return len() - pos - str.len();
|
return len() - pos - str.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
String::Tokens String::tokenize(const String& delimiter, bool trim_tokens, bool allow_white_space_only_tokens) const
|
String::Tokens String::tokenize(const String& delimiter, bool trim_tokens, bool allow_white_space_only_tokens) const
|
||||||
{
|
{
|
||||||
Tokens tokens;
|
Tokens tokens;
|
||||||
|
|
@ -560,7 +560,7 @@ namespace ostd
|
||||||
}
|
}
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String operator+(const cpp_string& str1, const String& str)
|
String operator+(const cpp_string& str1, const String& str)
|
||||||
|
|
@ -573,4 +573,4 @@ namespace ostd
|
||||||
out << val.cpp_str();
|
out << val.cpp_str();
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
#include "TextStyleParser.hpp"
|
#include "TextStyleParser.hpp"
|
||||||
#include "Utils.hpp"
|
|
||||||
#include "IOHandlers.hpp"
|
#include "IOHandlers.hpp"
|
||||||
|
|
||||||
namespace ostd
|
namespace ostd
|
||||||
{
|
{
|
||||||
std::ostream &operator<<(std::ostream &os, TextStyleParser::tStyledString const &str)
|
std::ostream &operator<<(std::ostream &os, TextStyleParser::tStyledString const &str)
|
||||||
{
|
{
|
||||||
if (!str.validate()) return os;
|
if (!str.validate()) return os;
|
||||||
ostd::ConsoleOutputHandler out;
|
ostd::ConsoleOutputHandler out;
|
||||||
for (int32_t i = 0; i < str.text.len(); i++)
|
for (int32_t i = 0; i < str.text.len(); i++)
|
||||||
|
|
@ -15,17 +14,17 @@ namespace ostd
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, TextStyleBuilder::Console const &builder)
|
std::ostream &operator<<(std::ostream &os, TextStyleBuilder::Console const &builder)
|
||||||
{
|
{
|
||||||
return os << builder.getStyledString();
|
return os << builder.getStyledString();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, TextStyleBuilder::Regex const ®ex)
|
std::ostream &operator<<(std::ostream &os, TextStyleBuilder::Regex const ®ex)
|
||||||
{
|
{
|
||||||
return os << regex.getStyledString();
|
return os << regex.getStyledString();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, TextStyleBuilder::IRichStringBase const &rstr)
|
std::ostream &operator<<(std::ostream &os, TextStyleBuilder::IRichStringBase const &rstr)
|
||||||
{
|
{
|
||||||
return os << rstr.getStyledString();
|
return os << rstr.getStyledString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,7 +186,7 @@ namespace ostd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TextStyleBuilder::Console::Console(void)
|
TextStyleBuilder::Console::Console(void)
|
||||||
{
|
{
|
||||||
m_backgroundColor = TextStyleParser::convertColor("black");
|
m_backgroundColor = TextStyleParser::convertColor("black");
|
||||||
|
|
@ -321,7 +320,7 @@ namespace ostd
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TextStyleBuilder::Regex& TextStyleBuilder::Regex::setRawString(const String& rawString)
|
TextStyleBuilder::Regex& TextStyleBuilder::Regex::setRawString(const String& rawString)
|
||||||
{
|
{
|
||||||
m_rawString = rawString;
|
m_rawString = rawString;
|
||||||
|
|
@ -343,7 +342,7 @@ namespace ostd
|
||||||
m_rawString = String(m_rawString).regexReplace(regex, replace_pattern, case_insensitive);
|
m_rawString = String(m_rawString).regexReplace(regex, replace_pattern, case_insensitive);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextStyleBuilder::Regex& TextStyleBuilder::Regex::col(const String& regex, const String& foreground_color, const String& background_color, bool case_insensitive)
|
TextStyleBuilder::Regex& TextStyleBuilder::Regex::col(const String& regex, const String& foreground_color, const String& background_color, bool case_insensitive)
|
||||||
{
|
{
|
||||||
String replace_pattern = "[@@ style background:" + background_color;
|
String replace_pattern = "[@@ style background:" + background_color;
|
||||||
|
|
@ -352,24 +351,24 @@ namespace ostd
|
||||||
m_rawString = String(m_rawString).regexReplace(regex, replace_pattern, case_insensitive);
|
m_rawString = String(m_rawString).regexReplace(regex, replace_pattern, case_insensitive);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextStyleParser::tStyledString TextStyleBuilder::Regex::getStyledString(void) const
|
TextStyleParser::tStyledString TextStyleBuilder::Regex::getStyledString(void) const
|
||||||
{
|
{
|
||||||
return TextStyleParser::parse(m_rawString);
|
return TextStyleParser::parse(m_rawString, m_defaultBackgroundColor, m_defaultForegroundColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextStyleBuilder::Regex& TextStyleBuilder::Regex::print(void)
|
TextStyleBuilder::Regex& TextStyleBuilder::Regex::print(void)
|
||||||
{
|
{
|
||||||
ConsoleOutputHandler out;
|
ConsoleOutputHandler out;
|
||||||
out.pStyled(m_rawString);
|
out.pStyled(m_rawString);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextStyleBuilder::Regex& TextStyleBuilder::Regex::print(OutputHandlerBase& out)
|
TextStyleBuilder::Regex& TextStyleBuilder::Regex::print(OutputHandlerBase& out)
|
||||||
{
|
{
|
||||||
out.pStyled(m_rawString);
|
out.pStyled(m_rawString);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ostd/Color.hpp>
|
#include <ostd/Color.hpp>
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace ostd
|
namespace ostd
|
||||||
{
|
{
|
||||||
|
|
@ -50,6 +49,18 @@ namespace ostd
|
||||||
public:
|
public:
|
||||||
virtual TextStyleParser::tStyledString getStyledString(void) const = 0;
|
virtual TextStyleParser::tStyledString getStyledString(void) const = 0;
|
||||||
friend std::ostream& operator<<(std::ostream&, IRichStringBase const&);
|
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 setDefaultForegroundColor(TextStyleParser::tColor color) { m_defaultForegroundColor = color; }
|
||||||
|
inline void setDefaultForegroundColor(Color color) { m_defaultForegroundColor = { color, "", true }; }
|
||||||
|
|
||||||
|
inline TextStyleParser::tColor getDefaultBackgroundColor(void) { return m_defaultBackgroundColor; }
|
||||||
|
inline TextStyleParser::tColor getDefaultForegroundColor(void) { return m_defaultForegroundColor; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TextStyleParser::tColor m_defaultBackgroundColor { { 0, 0, 0, 255 }, "black", true };
|
||||||
|
TextStyleParser::tColor m_defaultForegroundColor { { 255, 255, 255, 255 }, "white", false };
|
||||||
};
|
};
|
||||||
|
|
||||||
public: class Console : public IRichStringBase {
|
public: class Console : public IRichStringBase {
|
||||||
|
|
@ -93,7 +104,7 @@ namespace ostd
|
||||||
inline Regex(const String& rawString) { setRawString(rawString); }
|
inline Regex(const String& rawString) { setRawString(rawString); }
|
||||||
inline String getRawString(void) const { return m_rawString; }
|
inline String getRawString(void) const { return m_rawString; }
|
||||||
Regex& setRawString(const String& rawString);
|
Regex& setRawString(const String& rawString);
|
||||||
|
|
||||||
Regex& fg(const String& regex, const String& foreground_color, bool case_insensitive = false);
|
Regex& fg(const String& regex, const String& foreground_color, bool case_insensitive = false);
|
||||||
Regex& bg(const String& regex, const String& background_color, bool case_insensitive = false);
|
Regex& bg(const String& regex, const String& background_color, bool case_insensitive = false);
|
||||||
Regex& col(const String& regex, const String& foreground_color, const String& background_color, bool case_insensitive = false);
|
Regex& col(const String& regex, const String& foreground_color, const String& background_color, bool case_insensitive = false);
|
||||||
|
|
@ -117,4 +128,4 @@ namespace ostd
|
||||||
|
|
||||||
typedef TextStyleBuilder::Console ConsoleRichString;
|
typedef TextStyleBuilder::Console ConsoleRichString;
|
||||||
typedef TextStyleBuilder::Regex RegexRichString;
|
typedef TextStyleBuilder::Regex RegexRichString;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue