Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/backends/sdl2_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ namespace tinyui {
namespace {

void loadFont(Context &ctx) {
ctx.mSDLContext.mDefaultFont = new Font;
ctx.mSDLContext.mDefaultFont->mFont = new FontImpl;
ctx.mSDLContext.mDefaultFont->mSize = ctx.mStyle.mFont.mSize;
ctx.mSDLContext.mDefaultFont->mFont->mFontImpl = TTF_OpenFont(ctx.mStyle.mFont.mName, ctx.mStyle.mFont.mSize);
ctx.mDefaultFont = new Font;
ctx.mDefaultFont->mFont = new FontImpl;
ctx.mDefaultFont->mSize = ctx.mStyle.mFont.mSize;
ctx.mDefaultFont->mFont->mFontImpl = TTF_OpenFont(ctx.mStyle.mFont.mName, ctx.mStyle.mFont.mSize);
}

Font *loadDefaultFont(Context &ctx) {
Font *font = nullptr;
if (ctx.mSDLContext.mDefaultFont == nullptr) {
if (ctx.mDefaultFont == nullptr) {
if (ctx.mStyle.mFont.mName != nullptr) {
loadFont(ctx);
font = ctx.mSDLContext.mDefaultFont;
font = ctx.mDefaultFont;
}
}
return font;
Expand Down Expand Up @@ -174,9 +174,9 @@ ret_code Renderer::releaseRenderer(Context &ctx) {
return ErrorCode;
}

if (ctx.mSDLContext.mDefaultFont != nullptr) {
delete ctx.mSDLContext.mDefaultFont;
ctx.mSDLContext.mDefaultFont = nullptr;
if (ctx.mDefaultFont != nullptr) {
delete ctx.mDefaultFont;
ctx.mDefaultFont = nullptr;
}

IMG_Quit();
Expand All @@ -192,15 +192,15 @@ ret_code Renderer::drawText(Context &ctx, const char *string, Font *font, const
return InvalidHandle;
}

if (ctx.mSDLContext.mDefaultFont == nullptr) {
if (ctx.mDefaultFont == nullptr) {
if (ctx.mStyle.mFont.mName != nullptr) {
loadFont(ctx);
if (font == nullptr) {
font = ctx.mSDLContext.mDefaultFont;
font = ctx.mDefaultFont;
}
}
}
font = ctx.mSDLContext.mDefaultFont;
font = ctx.mDefaultFont;

if (font == nullptr) {
return InvalidHandle;
Expand Down
4 changes: 2 additions & 2 deletions src/tinyui.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,6 @@ struct SDLContext {
SDL_Window *mWindow{nullptr}; ///< The window.
SDL_Surface *mSurface{ nullptr }; ///< The surface.
SDL_Renderer *mRenderer{ nullptr }; ///< The renderer.
Font *mDefaultFont{ nullptr }; ///< The default font.
Font *mSelectedFont{ nullptr }; ///< The selected font.
bool mOwner{ false }; ///< The owner state.
};

Expand All @@ -403,6 +401,8 @@ struct Context {
Style mStyle{}; ///< The active style.
Widget *mRoot{nullptr}; ///< The root widget.
Widget *mFocus{nullptr}; ///< The widget which is in focus.
Font *mDefaultFont{ nullptr }; ///< The default font.
Font *mSelectedFont{ nullptr }; ///< The selected font.
Widget *mCurrentParent{ nullptr }; ///< The current parent widget for new widgets.
tui_log_func mLogger{}; ///< The logger function.
EventDispatchMap mEventDispatchMap; ///< The event dispatch map.
Expand Down
6 changes: 3 additions & 3 deletions src/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ static void render(Context &ctx, Widget *currentWidget) {
}
if (!currentWidget->mText.empty()) {
Color4 fg = ctx.mStyle.mTextColor, bg = ctx.mStyle.mBg;
Renderer::drawText(ctx, currentWidget->mText.c_str(), ctx.mSDLContext.mDefaultFont,
Renderer::drawText(ctx, currentWidget->mText.c_str(), ctx.mDefaultFont,
currentWidget->mRect, fg, bg, currentWidget->mAlignment);
}
}
Expand All @@ -513,7 +513,7 @@ static void render(Context &ctx, Widget *currentWidget) {
Renderer::drawRect(ctx, r.top.x, r.top.y, r.width, r.height, false, ctx.mStyle.mFg);
if (!currentWidget->mText.empty()) {
Color4 fg = ctx.mStyle.mTextColor, bg = ctx.mStyle.mBg;
Renderer::drawText(ctx, currentWidget->mText.c_str(), ctx.mSDLContext.mDefaultFont,
Renderer::drawText(ctx, currentWidget->mText.c_str(), ctx.mDefaultFont,
currentWidget->mRect, fg, bg, currentWidget->mAlignment);
}
}
Expand All @@ -523,7 +523,7 @@ static void render(Context &ctx, Widget *currentWidget) {
{
if (!currentWidget->mText.empty()) {
Color4 fg = ctx.mStyle.mTextColor, bg = ctx.mStyle.mBg;
Renderer::drawText(ctx, currentWidget->mText.c_str(), ctx.mSDLContext.mDefaultFont,
Renderer::drawText(ctx, currentWidget->mText.c_str(), ctx.mDefaultFont,
currentWidget->mRect, fg, bg, currentWidget->mAlignment);
}
}
Expand Down
Loading