Added ogfx::WindowBaseOutputHandler class
This commit is contained in:
parent
3990a50b00
commit
025d089bcb
15 changed files with 794 additions and 203 deletions
|
|
@ -76,6 +76,7 @@ list(APPEND OGFX_SOURCE_FILES
|
||||||
${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;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#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
|
||||||
|
|
@ -13,7 +12,6 @@
|
||||||
#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;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ namespace ostd
|
||||||
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;
|
||||||
|
|
@ -500,7 +500,5 @@ namespace ostd
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -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,6 +91,8 @@ 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
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#include "TextStyleParser.hpp"
|
#include "TextStyleParser.hpp"
|
||||||
#include "Utils.hpp"
|
|
||||||
#include "IOHandlers.hpp"
|
#include "IOHandlers.hpp"
|
||||||
|
|
||||||
namespace ostd
|
namespace ostd
|
||||||
|
|
@ -355,7 +354,7 @@ namespace ostd
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue