From 2a0187b67d1e7ebd5b7c9d5fa24e5c590ce9b27b Mon Sep 17 00:00:00 2001 From: Michael Ankele Date: Thu, 23 Jan 2025 18:49:43 +0100 Subject: [PATCH] [lib] update --- src/lib/base/optional.h | 6 ++++++ src/lib/image/ImagePainter.cpp | 2 ++ src/lib/kaba/lib/lib_hui.cpp | 14 +++++++++++++- src/lib/kaba/parser/import.cpp | 15 +++++++++++---- src/lib/math/rect.cpp | 13 +++++++++++++ src/lib/math/rect.h | 3 +++ src/lib/vulkan/Shader.cpp | 15 ++++++++++++++- 7 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/lib/base/optional.h b/src/lib/base/optional.h index 63438e90..fe87637e 100644 --- a/src/lib/base/optional.h +++ b/src/lib/base/optional.h @@ -51,6 +51,12 @@ class optional { T &operator*() { return value(); } + T *operator ->() { + return &value(); + } + const T *operator ->() const { + return &value(); + } void operator=(const T &o) { _init(); diff --git a/src/lib/image/ImagePainter.cpp b/src/lib/image/ImagePainter.cpp index 861f8345..38108cb9 100644 --- a/src/lib/image/ImagePainter.cpp +++ b/src/lib/image/ImagePainter.cpp @@ -185,6 +185,7 @@ void ImagePainter::draw_circle(const vec2 &c, float radius) { void ImagePainter::draw_str(const vec2 &p, const string& str) { #if 1 #if HAS_LIB_GTK3 || HAS_LIB_GTK4 +#ifdef HAS_HUI_PAINTER cairo_surface_t *surface = cairo_image_surface_create_for_data((unsigned char*)image->data.data, CAIRO_FORMAT_ARGB32, width, height, width * 4); cairo_t *cr = cairo_create(surface); @@ -213,6 +214,7 @@ void ImagePainter::draw_str(const vec2 &p, const string& str) { cairo_surface_destroy(surface); #endif #endif +#endif } vec2 ImagePainter::get_str_size(const string& str) { diff --git a/src/lib/kaba/lib/lib_hui.cpp b/src/lib/kaba/lib/lib_hui.cpp index c1c14e85..5bc2ec9a 100644 --- a/src/lib/kaba/lib/lib_hui.cpp +++ b/src/lib/kaba/lib/lib_hui.cpp @@ -14,9 +14,10 @@ #include "../../hui_minimal/config.h" #define KABA_EXPORT_HUI_MINIMAL #else - #error("we are re screwed.... no hui or hui_minimal") + #warning("we are screwed.... no hui or hui_minimal") #endif +#if defined(KABA_EXPORT_HUI_MINIMAL) || defined(KABA_EXPORT_HUI) namespace hui{ #ifdef KABA_EXPORT_HUI_MINIMAL @@ -726,3 +727,14 @@ void SIAddPackageHui(Context *c) { } }; + +#else +namespace kaba { + + void SIAddPackageHui(Context *c) { + add_package(c, "hui"); + } + +}; + +#endif diff --git a/src/lib/kaba/parser/import.cpp b/src/lib/kaba/parser/import.cpp index 041a1fc8..5aa06fcb 100644 --- a/src/lib/kaba/parser/import.cpp +++ b/src/lib/kaba/parser/import.cpp @@ -18,6 +18,8 @@ #include "../../hui/Application.h" #elif defined(_X_USE_HUI_MINIMAL_) #include "../../hui_minimal/Application.h" +#elif __has_include("../../xhui/xhui.h") +#include "../../xhui/xhui.h" #endif @@ -78,10 +80,15 @@ Path import_dir_match(const Path &dir0, const string &name) { } Path find_installed_lib_import(const string &name) { - Path kaba_dir = hui::Application::directory.parent() | "kaba"; - if (hui::Application::directory.basename()[0] == '.') - kaba_dir = hui::Application::directory.parent() | ".kaba"; - Path kaba_dir_static = hui::Application::directory_static.parent() | "kaba"; +#ifdef _X_USE_XHUI_ + using App = xhui::Application; +#else + using App = hui::Application; +#endif + Path kaba_dir = App::directory.parent() | "kaba"; + if (App::directory.basename()[0] == '.') + kaba_dir = App::directory.parent() | ".kaba"; + Path kaba_dir_static = App::directory_static.parent() | "kaba"; for (auto &dir: Array({kaba_dir, kaba_dir_static})) { auto path = (dir | "lib" | name).canonical(); if (os::fs::exists(path)) diff --git a/src/lib/math/rect.cpp b/src/lib/math/rect.cpp index 2f02e58a..eb6b570b 100644 --- a/src/lib/math/rect.cpp +++ b/src/lib/math/rect.cpp @@ -34,10 +34,23 @@ vec2 rect::p00() const { return {x1, y1}; } +vec2 rect::p01() const { + return {x1, y2}; +} + +vec2 rect::p10() const { + return {x2, y1}; +} + vec2 rect::p11() const { return {x2, y2}; } +rect rect::canonical() const { + return {min(x1, x2), max(x1, x2), min(y1, y2), max(y1, y2)}; +} + + vec2 rect::size() const { return {width(), height()}; } diff --git a/src/lib/math/rect.h b/src/lib/math/rect.h index f40141c6..01f19674 100644 --- a/src/lib/math/rect.h +++ b/src/lib/math/rect.h @@ -19,7 +19,10 @@ class rect { vec2 center() const; vec2 size() const; vec2 p00() const; + vec2 p01() const; + vec2 p10() const; vec2 p11() const; + rect canonical() const; bool inside(const vec2 &p) const; bool covers(const rect &r) const; bool overlaps(const rect &r) const; diff --git a/src/lib/vulkan/Shader.cpp b/src/lib/vulkan/Shader.cpp index 125cf72b..1c225712 100644 --- a/src/lib/vulkan/Shader.cpp +++ b/src/lib/vulkan/Shader.cpp @@ -19,6 +19,13 @@ #include "shaderc/shaderc.h" #endif +string with_line_numbers(const string& s) { + auto xx = s.explode("\n"); + string r; + for (int i=0; i>\n" + r.sub(p2); + r = r.head(p) + "\n// << + " + imp + "\n" + m.source + "\n// >> " + imp + "\n" + r.sub(p2); found = true; + break; } if (!found) throw Exception(format("shader import '%s' not found", imp)); @@ -183,6 +191,11 @@ static shaderc_compiler_t shaderc = nullptr; intro += "#extension " + e + " : require\n"; if (r.find("GL_ARB_separate_shader_objects", 0) < 0) intro += "#extension GL_ARB_separate_shader_objects : enable\n"; + if (false) { + msg_write("\n\n======================================"); + msg_write(with_line_numbers(intro + r)); + msg_write("======================================\n\n"); + } return intro + r; }