Skip to content

Commit

Permalink
[lib] update
Browse files Browse the repository at this point in the history
  • Loading branch information
momentarylapse committed Jan 23, 2025
1 parent a1f00a5 commit 2a0187b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/lib/base/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/lib/image/ImagePainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion src/lib/kaba/lib/lib_hui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -726,3 +727,14 @@ void SIAddPackageHui(Context *c) {
}

};

#else
namespace kaba {

void SIAddPackageHui(Context *c) {
add_package(c, "hui");
}

};

#endif
15 changes: 11 additions & 4 deletions src/lib/kaba/parser/import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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<Path>({kaba_dir, kaba_dir_static})) {
auto path = (dir | "lib" | name).canonical();
if (os::fs::exists(path))
Expand Down
13 changes: 13 additions & 0 deletions src/lib/math/rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()};
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/math/rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion src/lib/vulkan/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<xx.num; i++)
r += format("%03d %s\n", i+1, xx[i]);
return r;
}

namespace vulkan {

Expand Down Expand Up @@ -169,8 +176,9 @@ static shaderc_compiler_t shaderc = nullptr;
for (auto &m: shader_modules)
if (m.meta.name == imp) {
//msg_error("FOUND " + imp);
r = r.head(p) + "\n// <<\n" + m.source + "\n// >>\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));
Expand All @@ -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;
}

Expand Down

0 comments on commit 2a0187b

Please sign in to comment.