Make util/geometry.h C++20 friendly

- Move header to base/include to make it applicable for base types
  like 'Affinity' down the road.
- Represent 'Rect' as typle of point and area, which is the most
  common form of initialization, creates in valid 'Rect' by default.
- Turn Point, Area, and Rect into compound types, making x, y, w, h, at,
  area accessible without a method call
- 'Rect::Compound' function for constructing a 'Rect' from two points,
  replacing a former constructor
- Use result type 'Rect::Cut_remainder' instead of out parameters.

Fixes #5239
This commit is contained in:
Norman Feske
2024-06-05 12:40:13 +02:00
parent bb06d879aa
commit c629c54153
131 changed files with 1200 additions and 1218 deletions

View File

@ -71,8 +71,8 @@ class Framebuffer_window : public Scout::Window
bool config_decoration)
:
Scout::Window(gfx_backend, position,
Scout::Area(content->min_size().w() + 2,
content->min_size().h() + 1 + _TH),
Scout::Area(content->min_size().w + 2,
content->min_size().h + 1 + _TH),
max_size, false),
_content(content), _config_alpha(config_alpha),
_config_resize_handle(config_resize_handle),
@ -167,14 +167,14 @@ class Framebuffer_window : public Scout::Window
{
using namespace Scout;
unsigned w = size.w();
unsigned h = size.h();
unsigned w = size.w;
unsigned h = size.h;
/* limit window size to valid values */
w = max(w, min_size().w());
h = max(h, min_size().h());
w = min(w, max_size().w());
h = min(h, max_size().h());
w = max(w, min_size().w);
h = max(h, min_size().h);
w = min(w, max_size().w);
h = min(h, max_size().h);
_size = Scout::Area(w, h);
@ -183,9 +183,9 @@ class Framebuffer_window : public Scout::Window
if (_config_decoration) {
_titlebar.format_fixed_width(w);
_titlebar.geometry(Rect(Point(1, y),
Area(_titlebar.min_size().w(),
_titlebar.min_size().h())));
y += _titlebar.min_size().h();
Area(_titlebar.min_size().w,
_titlebar.min_size().h)));
y += _titlebar.min_size().h;
}
int const content_h = ((int)h > y + 1) ? (h - y - 1) : 0;
@ -196,12 +196,12 @@ class Framebuffer_window : public Scout::Window
_content->geometry(Rect(Point(content_x, y),
Area(content_w, content_h)));
_sizer.geometry(Rect(Point(_size.w() - 32, _size.h() - 32), Area(32, 32)));
_sizer.geometry(Rect(Point(_size.w - 32, _size.h - 32), Area(32, 32)));
if (_config_decoration)
Window::format(_size);
else
Window::format(Area(_size.w() - 2, _size.h() - 1 - _TH));
Window::format(Area(_size.w - 2, _size.h - 1 - _TH));
refresh();
}
@ -225,12 +225,12 @@ class Framebuffer_window : public Scout::Window
/* border */
Color const color = Color::black();
canvas.draw_box(0, 0, _size.w(), 1, color);
canvas.draw_box(0, 0, _size.w, 1, color);
if (_config_decoration)
canvas.draw_box(0, _TH, _size.w(), 1, color);
canvas.draw_box(0, _size.h() - 1, _size.w(), 1, color);
canvas.draw_box(0, 1, 1, _size.h() - 2, color);
canvas.draw_box(_size.w() - 1, 1, 1, _size.h() - 2, color);
canvas.draw_box(0, _TH, _size.w, 1, color);
canvas.draw_box(0, _size.h - 1, _size.w, 1, color);
canvas.draw_box(0, 1, 1, _size.h - 2, color);
canvas.draw_box(_size.w - 1, 1, 1, _size.h - 2, color);
};
};

View File

@ -186,7 +186,7 @@ class Liquid_fb::Main : public Scout::Event_handler
bool _background_animator_initialized = (_init_background_animator(), true);
User_state _user_state { &_fb_win, &_fb_win,
_initial_position.x(), _initial_position.y() };
_initial_position.x, _initial_position.y };
void _init_fb_win()
{

View File

@ -61,7 +61,7 @@ class Window_content : public Scout::Element
Point mouse_position = ev.mouse_position - _element->abs_position();
auto motion = [&] (Point p) { return Input::Absolute_motion{p.x(), p.y()}; };
auto motion = [&] (Point p) { return Input::Absolute_motion{p.x, p.y}; };
if (ev.type == Event::MOTION)
_input_session.submit(motion(mouse_position));
@ -193,10 +193,10 @@ class Window_content : public Scout::Element
void realloc_framebuffer()
{
/* skip reallocation if size has not changed */
if (_next_size.w() == _fb->w && _next_size.h() == _fb->h)
if (_next_size.w == _fb->w && _next_size.h == _fb->h)
return;
_fb.construct(_ram, _rm, _alloc, _next_size.w(), _next_size.h(), _config_alpha);
_fb.construct(_ram, _rm, _alloc, _next_size.w, _next_size.h, _config_alpha);
}
/**

View File

@ -88,7 +88,7 @@ class Canvas : public Canvas_base
void draw_string(Point p, Font const &font, Color color,
char const *sstr) override
{
Text_painter::paint(_surface, Text_painter::Position(p.x(), p.y()),
Text_painter::paint(_surface, Text_painter::Position(p.x, p.y),
font, color, sstr);
}
@ -157,7 +157,7 @@ class Log_entry
/* calculate label dimensions */
int label_w = font.string_width(_label).decimal();
int label_h = font.bounding_box().h();
int label_h = font.bounding_box().h;
if (new_section) {
canvas.draw_box(Rect(Point(1, y), Area(label_w + 2, label_h - 1)), label_bgcol);
@ -244,7 +244,7 @@ class Log_window
_dirty = false;
}
int line_h = _font.bounding_box().h();
int line_h = _font.bounding_box().h;
int curr_session_id = -1;
for (int i = 0, y = 0; i < LOG_H; i++, y += line_h) {
@ -365,8 +365,8 @@ class Log_view
Log_view(Gui::Session_client &gui, Gui::Rect geometry)
:
_gui(gui),
_pos(geometry.p1()),
_size(geometry.area()),
_pos(geometry.at),
_size(geometry.area),
_handle(gui.create_view())
{
move(_pos);
@ -401,8 +401,8 @@ struct Nitlog::Main
Tff_font _font { _binary_mono_tff_start, _glyph_buffer };
/* calculate size of log view in pixels */
unsigned const _win_w = _font.bounding_box().w() * LOG_W + 2;
unsigned const _win_h = _font.bounding_box().h() * LOG_H + 2;
unsigned const _win_w = _font.bounding_box().w * LOG_W + 2;
unsigned const _win_h = _font.bounding_box().h * LOG_H + 2;
/* init sessions to the required external services */
Gui::Connection _gui { _env };