libui+wind: Move some static variables inside functions

This commit is contained in:
apio 2023-08-07 19:10:27 +02:00
parent 3fefb74710
commit fbb66a9fc3
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 12 additions and 18 deletions

View File

@ -11,7 +11,7 @@ set(SOURCES
)
add_library(ui ${SOURCES})
target_compile_options(ui PRIVATE ${COMMON_FLAGS})
target_compile_options(ui PRIVATE ${COMMON_FLAGS} -fno-threadsafe-statics)
target_include_directories(ui PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include/)
target_include_directories(ui PUBLIC ${LUNA_BASE}/usr/include)
target_link_libraries(ui PUBLIC os)

View File

@ -2,9 +2,6 @@
#include <os/File.h>
#include <ui/Font.h>
SharedPtr<ui::Font> s_default_font = {};
SharedPtr<ui::Font> s_default_bold_font = {};
constexpr static int BYTES_PER_PIXEL = (int)sizeof(ui::Color);
namespace ui
@ -51,15 +48,15 @@ namespace ui
SharedPtr<Font> Font::default_font()
{
if (s_default_font) return s_default_font;
s_default_font = load("/usr/share/fonts/Tamsyn-Regular.psf").release_value();
static SharedPtr<ui::Font> s_default_font = {};
if (!s_default_font) s_default_font = load("/usr/share/fonts/Tamsyn-Regular.psf").release_value();
return s_default_font;
}
SharedPtr<Font> Font::default_bold_font()
{
if (s_default_bold_font) return s_default_bold_font;
s_default_bold_font = load("/usr/share/fonts/Tamsyn-Bold.psf").release_value();
static SharedPtr<ui::Font> s_default_bold_font = {};
if (!s_default_bold_font) s_default_bold_font = load("/usr/share/fonts/Tamsyn-Bold.psf").release_value();
return s_default_bold_font;
}

View File

@ -9,7 +9,7 @@ set(SOURCES
)
add_executable(wind ${SOURCES})
target_compile_options(wind PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings)
target_compile_options(wind PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings -fno-threadsafe-statics)
add_dependencies(wind libc)
target_include_directories(wind PRIVATE ${LUNA_BASE}/usr/include ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(wind PRIVATE os ui)

View File

@ -6,8 +6,6 @@
LinkedList<Window> g_windows;
static SharedPtr<ui::Image> g_close_icon;
void Window::draw(ui::Canvas& screen)
{
auto window = screen.subcanvas(surface);
@ -25,11 +23,12 @@ void Window::draw(ui::Canvas& screen)
auto textarea = titlebar_canvas.subcanvas(ui::Rect { 10, 10, titlebar_canvas.width - 10, titlebar_canvas.height });
font->render(buffer, ui::BLACK, textarea);
if (g_close_icon)
{
static SharedPtr<ui::Image> g_close_icon;
if (!g_close_icon) g_close_icon = ui::Image::load("/usr/share/icons/16x16/app-close.tga").release_value();
auto close_area = window.subcanvas(close_button);
close_area.fill(g_close_icon->pixels(), g_close_icon->width());
}
}
void Window::focus()
@ -48,6 +47,4 @@ Window::Window(ui::Rect r, ui::Color c, StringView n) : surface(r), color(c), na
close_button = ui::Rect { surface.width - 26, 10, 16, 16 };
contents = ui::Rect { 0, font->height() + 20, surface.width, surface.height - (font->height() + 20) };
g_windows.append(this);
if (!g_close_icon) g_close_icon = ui::Image::load("/usr/share/icons/16x16/app-close.tga").value_or({});
}