Skip to content

Commit 226baf9

Browse files
committed
Merge branch 'main' of github.com:cppfw/ruis
2 parents 32ad080 + 8bbf39f commit 226baf9

4 files changed

Lines changed: 46 additions & 34 deletions

File tree

build/vcpkg/test/vcpkg-configuration.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{
99
"kind": "git",
1010
"repository": "https://github.com/cppfw/vcpkg-repo/",
11-
"baseline": "eaf033e17af571842ea244375b7463b1cf126efb",
11+
"baseline": "ce5410475b56e531aac195d77719646c600e6bfa",
1212
"reference": "main",
1313
"packages": [
1414
"myci",

src/ruis/font/texture_font.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ freetype_face::metrics freetype_face::get_metrics(unsigned font_size) const
8585
this->set_size(font_size);
8686
using std::ceil;
8787
return {
88-
ceil(real(this->face.f->size->metrics.height) / real(freetype_granularity)), // height
89-
-ceil(real(this->face.f->size->metrics.descender) / real(freetype_granularity)), // descender
90-
ceil(real(this->face.f->size->metrics.ascender) / real(freetype_granularity)) // ascender
88+
.height = ceil(real(this->face.f->size->metrics.height) / real(freetype_granularity)), //
89+
.descender = -ceil(real(this->face.f->size->metrics.descender) / real(freetype_granularity)),
90+
.ascender = ceil(real(this->face.f->size->metrics.ascender) / real(freetype_granularity))
9191
};
9292
}
9393

@@ -102,13 +102,13 @@ freetype_face::glyph freetype_face::load_glyph(char32_t c, unsigned font_size) c
102102
"texture_font::load_glyph(): could not load 'unknown character' glyph (UTF-32: 0xfffd)"
103103
);
104104
}
105-
LOG([&](auto& o) {
105+
utki::log_debug([&](auto& o) {
106106
o << "texture_font::load_glyph(" << std::hex << uint32_t(c) << "): failed to load glyph" << std::endl;
107-
})
107+
});
108108
return {
109-
{}, // vertices
110-
{}, // image
111-
-1 // advance
109+
.vertices = {}, //
110+
.image = {},
111+
.advance = -1 // negative means invalid
112112
};
113113
}
114114

@@ -123,32 +123,31 @@ freetype_face::glyph freetype_face::load_glyph(char32_t c, unsigned font_size) c
123123
if (!slot->bitmap.buffer) {
124124
// empty glyph (space)
125125
return glyph{
126-
{}, // vertices
127-
{}, // image
128-
advance
126+
.vertices = {}, //
127+
.image = {},
128+
.advance = advance
129129
};
130130
}
131131

132-
ASSERT(slot->format == FT_GLYPH_FORMAT_BITMAP)
133-
ASSERT(slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY)
134-
ASSERT(slot->bitmap.pitch >= 0)
132+
utki::assert(slot->format == FT_GLYPH_FORMAT_BITMAP);
133+
utki::assert(slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY);
134+
utki::assert(slot->bitmap.pitch >= 0);
135135

136136
return glyph{
137-
// vertices
138-
{
139-
(ruis::vec2(real(m->horiBearingX), -real(m->horiBearingY)) / real(freetype_granularity)),
140-
(ruis::vec2(real(m->horiBearingX), real(m->height - m->horiBearingY)) / real(freetype_granularity)),
141-
(ruis::vec2(real(m->horiBearingX + m->width), real(m->height - m->horiBearingY)) /
142-
real(freetype_granularity)),
143-
(ruis::vec2(real(m->horiBearingX + m->width), -real(m->horiBearingY)) / real(freetype_granularity)) //
144-
},
145-
// image
146-
rasterimage::image<uint8_t, 1>::make(
137+
.vertices =
138+
{
139+
(ruis::vec2(real(m->horiBearingX), -real(m->horiBearingY)) / real(freetype_granularity)), //
140+
(ruis::vec2(real(m->horiBearingX), real(m->height - m->horiBearingY)) / real(freetype_granularity)),
141+
(ruis::vec2(real(m->horiBearingX + m->width), real(m->height - m->horiBearingY)) /
142+
real(freetype_granularity)),
143+
(ruis::vec2(real(m->horiBearingX + m->width), -real(m->horiBearingY)) / real(freetype_granularity)) //
144+
}, //
145+
.image = rasterimage::image<uint8_t, 1>::make(
147146
{slot->bitmap.width, slot->bitmap.rows},
148147
slot->bitmap.buffer,
149148
slot->bitmap.pitch
150149
),
151-
advance
150+
.advance = advance
152151
};
153152
}
154153

@@ -188,7 +187,7 @@ texture_font::glyph texture_font::load_glyph(char32_t c) const
188187
g.tex = rc.make_texture_2d(
189188
std::move(ftg.image),
190189
{
191-
.min_filter = render::texture_2d::filter::nearest,
190+
.min_filter = render::texture_2d::filter::nearest, //
192191
.mag_filter = render::texture_2d::filter::nearest,
193192
.mipmap = render::texture_2d::mipmap::none
194193
}
@@ -233,7 +232,7 @@ const texture_font::glyph& texture_font::get_glyph(char32_t c) const
233232
auto i = this->glyphs.find(c);
234233
if (i == this->glyphs.end()) {
235234
auto r = this->glyphs.insert(std::make_pair(c, this->load_glyph(c)));
236-
ASSERT(r.second)
235+
utki::assert(r.second);
237236
i = r.first;
238237
this->last_used_order.push_front(c);
239238
i->second.last_used_iter = this->last_used_order.begin();
@@ -248,7 +247,7 @@ const texture_font::glyph& texture_font::get_glyph(char32_t c) const
248247
this->last_used_order.splice(this->last_used_order.begin(), this->last_used_order, g.last_used_iter);
249248
}
250249

251-
ASSERT(this->last_used_order.size() <= this->max_cached)
250+
utki::assert(this->last_used_order.size() <= this->max_cached);
252251

253252
return i->second;
254253
}
@@ -347,7 +346,10 @@ font::render_result texture_font::render_internal(
347346
size_t offset
348347
) const
349348
{
350-
render_result ret = {0, 0};
349+
render_result ret = {
350+
.advance = 0, //
351+
.length = 0
352+
};
351353

352354
if (str.size() == 0) {
353355
return ret;

src/ruis/gui.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ void gui::send_mouse_move(
147147
auto& rw = this->get_root();
148148
if (rw.is_interactive()) {
149149
rw.set_hovered(rw.rect().overlaps(pos), id);
150-
rw.on_mouse_move(mouse_move_event{pos, id, false});
150+
rw.on_mouse_move(mouse_move_event{
151+
.pos = pos, //
152+
.pointer_id = id,
153+
.ignore_mouse_capture = false
154+
});
151155
}
152156
}
153157

@@ -161,7 +165,12 @@ void gui::send_mouse_button(
161165
auto& rw = this->get_root();
162166
if (rw.is_interactive()) {
163167
rw.set_hovered(rw.rect().overlaps(pos), id);
164-
rw.on_mouse_button(mouse_button_event{action, pos, button, id});
168+
rw.on_mouse_button(mouse_button_event{
169+
.action = action, //
170+
.pos = pos,
171+
.button = button,
172+
.pointer_id = id
173+
});
165174
}
166175
}
167176

src/ruis/paint/rectangle_vao.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121

2222
#include "rectangle_vao.hpp"
2323

24+
#include <numbers>
25+
2426
#include <veg/canvas.hpp>
2527

2628
#include "../util/util.hpp"
@@ -263,8 +265,7 @@ void rectangle_vao::render_rounder_corners(
263265
namespace {
264266
// approximate 90 degree arc with bezier curve which matches the arc at 45 degree point
265267
// and has the same tangent as an arc at 45 degree point
266-
using std::sqrt;
267-
const auto arc_bezier_param = ruis::real(4 * (sqrt(2) - 1) / 3);
268+
const auto arc_bezier_param = ruis::real(4 * (std::numbers::sqrt2 - 1) / 3);
268269

269270
auto make_rounded_corners_texture_image(const ruis::sides<ruis::real>& radii)
270271
{

0 commit comments

Comments
 (0)