libui+wind: Move some static variables inside functions
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
parent
4cbdea954a
commit
2ddec76061
@ -11,7 +11,7 @@ set(SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_library(ui ${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 ${CMAKE_CURRENT_LIST_DIR}/include/)
|
||||||
target_include_directories(ui PUBLIC ${LUNA_BASE}/usr/include)
|
target_include_directories(ui PUBLIC ${LUNA_BASE}/usr/include)
|
||||||
target_link_libraries(ui PUBLIC os)
|
target_link_libraries(ui PUBLIC os)
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
#include <os/File.h>
|
#include <os/File.h>
|
||||||
#include <ui/Font.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);
|
constexpr static int BYTES_PER_PIXEL = (int)sizeof(ui::Color);
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
@ -51,15 +48,15 @@ namespace ui
|
|||||||
|
|
||||||
SharedPtr<Font> Font::default_font()
|
SharedPtr<Font> Font::default_font()
|
||||||
{
|
{
|
||||||
if (s_default_font) return s_default_font;
|
static SharedPtr<ui::Font> s_default_font = {};
|
||||||
s_default_font = load("/usr/share/fonts/Tamsyn-Regular.psf").release_value();
|
if (!s_default_font) s_default_font = load("/usr/share/fonts/Tamsyn-Regular.psf").release_value();
|
||||||
return s_default_font;
|
return s_default_font;
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr<Font> Font::default_bold_font()
|
SharedPtr<Font> Font::default_bold_font()
|
||||||
{
|
{
|
||||||
if (s_default_bold_font) return s_default_bold_font;
|
static SharedPtr<ui::Font> s_default_bold_font = {};
|
||||||
s_default_bold_font = load("/usr/share/fonts/Tamsyn-Bold.psf").release_value();
|
if (!s_default_bold_font) s_default_bold_font = load("/usr/share/fonts/Tamsyn-Bold.psf").release_value();
|
||||||
return s_default_bold_font;
|
return s_default_bold_font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ set(SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_executable(wind ${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)
|
add_dependencies(wind libc)
|
||||||
target_include_directories(wind PRIVATE ${LUNA_BASE}/usr/include ${CMAKE_CURRENT_LIST_DIR})
|
target_include_directories(wind PRIVATE ${LUNA_BASE}/usr/include ${CMAKE_CURRENT_LIST_DIR})
|
||||||
target_link_libraries(wind PRIVATE os ui)
|
target_link_libraries(wind PRIVATE os ui)
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
LinkedList<Window> g_windows;
|
LinkedList<Window> g_windows;
|
||||||
|
|
||||||
static SharedPtr<ui::Image> g_close_icon;
|
|
||||||
|
|
||||||
void Window::draw(ui::Canvas& screen)
|
void Window::draw(ui::Canvas& screen)
|
||||||
{
|
{
|
||||||
auto window = screen.subcanvas(surface);
|
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 });
|
auto textarea = titlebar_canvas.subcanvas(ui::Rect { 10, 10, titlebar_canvas.width - 10, titlebar_canvas.height });
|
||||||
font->render(buffer, ui::BLACK, textarea);
|
font->render(buffer, ui::BLACK, textarea);
|
||||||
|
|
||||||
if (g_close_icon)
|
static SharedPtr<ui::Image> g_close_icon;
|
||||||
{
|
|
||||||
auto close_area = window.subcanvas(close_button);
|
if (!g_close_icon) g_close_icon = ui::Image::load("/usr/share/icons/16x16/app-close.tga").release_value();
|
||||||
close_area.fill(g_close_icon->pixels(), g_close_icon->width());
|
|
||||||
}
|
auto close_area = window.subcanvas(close_button);
|
||||||
|
close_area.fill(g_close_icon->pixels(), g_close_icon->width());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::focus()
|
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 };
|
close_button = ui::Rect { surface.width - 26, 10, 16, 16 };
|
||||||
contents = ui::Rect { 0, font->height() + 20, surface.width, surface.height - (font->height() + 20) };
|
contents = ui::Rect { 0, font->height() + 20, surface.width, surface.height - (font->height() + 20) };
|
||||||
g_windows.append(this);
|
g_windows.append(this);
|
||||||
|
|
||||||
if (!g_close_icon) g_close_icon = ui::Image::load("/usr/share/icons/16x16/app-close.tga").value_or({});
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user