mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 10:37:41 +00:00
LibGfx: Unify Rect, Point, and Size
This commit unifies methods and method/param names between the above classes, as well as adds [[nodiscard]] and ALWAYS_INLINE where appropriate. It also renamed the various move_by methods to translate_by, as that more closely matches the transformation terminology.
This commit is contained in:
parent
ac238b3bd6
commit
88cfaf7bf0
48 changed files with 282 additions and 187 deletions
|
@ -242,7 +242,7 @@ int KeysWidget::note_for_event_position(const Gfx::IntPoint& a_point) const
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
auto point = a_point;
|
auto point = a_point;
|
||||||
point.move_by(-frame_thickness(), -frame_thickness());
|
point.translate_by(-frame_thickness(), -frame_thickness());
|
||||||
|
|
||||||
int white_keys = point.x() / white_key_width;
|
int white_keys = point.x() / white_key_width;
|
||||||
int note = note_from_white_keys(white_keys);
|
int note = note_from_white_keys(white_keys);
|
||||||
|
|
|
@ -112,7 +112,7 @@ void RollWidget::paint_event(GUI::PaintEvent& event)
|
||||||
const char* note_name = note_names[note % notes_per_octave];
|
const char* note_name = note_names[note % notes_per_octave];
|
||||||
|
|
||||||
background_painter.draw_text(note_name_rect, note_name, Gfx::TextAlignment::CenterLeft);
|
background_painter.draw_text(note_name_rect, note_name, Gfx::TextAlignment::CenterLeft);
|
||||||
note_name_rect.move_by(Gfx::FontDatabase::default_font().width(note_name) + 2, 0);
|
note_name_rect.translate_by(Gfx::FontDatabase::default_font().width(note_name) + 2, 0);
|
||||||
if (note % notes_per_octave == 0)
|
if (note % notes_per_octave == 0)
|
||||||
background_painter.draw_text(note_name_rect, String::formatted("{}", note / notes_per_octave + 1), Gfx::TextAlignment::CenterLeft);
|
background_painter.draw_text(note_name_rect, String::formatted("{}", note / notes_per_octave + 1), Gfx::TextAlignment::CenterLeft);
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ GUI::MouseEvent ImageEditor::event_with_pan_and_scale_applied(const GUI::MouseEv
|
||||||
GUI::MouseEvent ImageEditor::event_adjusted_for_layer(const GUI::MouseEvent& event, const Layer& layer) const
|
GUI::MouseEvent ImageEditor::event_adjusted_for_layer(const GUI::MouseEvent& event, const Layer& layer) const
|
||||||
{
|
{
|
||||||
auto image_position = editor_position_to_image_position(event.position());
|
auto image_position = editor_position_to_image_position(event.position());
|
||||||
image_position.move_by(-layer.location().x(), -layer.location().y());
|
image_position.translate_by(-layer.location().x(), -layer.location().y());
|
||||||
return {
|
return {
|
||||||
static_cast<GUI::Event::Type>(event.type()),
|
static_cast<GUI::Event::Type>(event.type()),
|
||||||
Gfx::IntPoint(image_position.x(), image_position.y()),
|
Gfx::IntPoint(image_position.x(), image_position.y()),
|
||||||
|
|
|
@ -71,7 +71,7 @@ void LayerListWidget::paint_event(GUI::PaintEvent& event)
|
||||||
auto adjusted_rect = gadget.rect;
|
auto adjusted_rect = gadget.rect;
|
||||||
|
|
||||||
if (gadget.is_moving) {
|
if (gadget.is_moving) {
|
||||||
adjusted_rect.move_by(0, gadget.movement_delta.y());
|
adjusted_rect.translate_by(0, gadget.movement_delta.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gadget.is_moving) {
|
if (gadget.is_moving) {
|
||||||
|
|
|
@ -66,16 +66,16 @@ void MoveTool::on_keydown(GUI::KeyEvent& event)
|
||||||
|
|
||||||
switch (event.key()) {
|
switch (event.key()) {
|
||||||
case Key_Up:
|
case Key_Up:
|
||||||
new_location.move_by(0, -1);
|
new_location.translate_by(0, -1);
|
||||||
break;
|
break;
|
||||||
case Key_Down:
|
case Key_Down:
|
||||||
new_location.move_by(0, 1);
|
new_location.translate_by(0, 1);
|
||||||
break;
|
break;
|
||||||
case Key_Left:
|
case Key_Left:
|
||||||
new_location.move_by(-1, 0);
|
new_location.translate_by(-1, 0);
|
||||||
break;
|
break;
|
||||||
case Key_Right:
|
case Key_Right:
|
||||||
new_location.move_by(1, 0);
|
new_location.translate_by(1, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -96,10 +96,10 @@ void TreeMapWidget::paint_cell_frame(GUI::Painter& painter, const TreeMapNode& n
|
||||||
painter.clear_clip_rect();
|
painter.clear_clip_rect();
|
||||||
painter.add_clip_rect(cell_rect);
|
painter.add_clip_rect(cell_rect);
|
||||||
Gfx::IntRect text_rect = remainder;
|
Gfx::IntRect text_rect = remainder;
|
||||||
text_rect.move_by(2, 2);
|
text_rect.translate_by(2, 2);
|
||||||
painter.draw_text(text_rect, node.name(), font(), Gfx::TextAlignment::TopLeft, Color::Black);
|
painter.draw_text(text_rect, node.name(), font(), Gfx::TextAlignment::TopLeft, Color::Black);
|
||||||
if (node_is_leaf(node)) {
|
if (node_is_leaf(node)) {
|
||||||
text_rect.move_by(0, font().presentation_size() + 1);
|
text_rect.translate_by(0, font().presentation_size() + 1);
|
||||||
painter.draw_text(text_rect, human_readable_size(node.area()), font(), Gfx::TextAlignment::TopLeft, Color::Black);
|
painter.draw_text(text_rect, human_readable_size(node.area()), font(), Gfx::TextAlignment::TopLeft, Color::Black);
|
||||||
}
|
}
|
||||||
painter.clear_clip_rect();
|
painter.clear_clip_rect();
|
||||||
|
|
|
@ -164,9 +164,9 @@ void CardStack::push(NonnullRefPtr<Card> card)
|
||||||
|
|
||||||
if (size && size % m_rules.step == 0) {
|
if (size && size % m_rules.step == 0) {
|
||||||
if (peek().is_upside_down())
|
if (peek().is_upside_down())
|
||||||
top_most_position.move_by(m_rules.shift_x, m_rules.shift_y_upside_down);
|
top_most_position.translate_by(m_rules.shift_x, m_rules.shift_y_upside_down);
|
||||||
else
|
else
|
||||||
top_most_position.move_by(m_rules.shift_x, m_rules.shift_y);
|
top_most_position.translate_by(m_rules.shift_x, m_rules.shift_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_type == Stock)
|
if (m_type == Stock)
|
||||||
|
|
|
@ -256,7 +256,7 @@ void SolitaireWidget::mousemove_event(GUI::MouseEvent& event)
|
||||||
|
|
||||||
for (auto& to_intersect : m_focused_cards) {
|
for (auto& to_intersect : m_focused_cards) {
|
||||||
mark_intersecting_stacks_dirty(to_intersect);
|
mark_intersecting_stacks_dirty(to_intersect);
|
||||||
to_intersect.rect().move_by(dx, dy);
|
to_intersect.rect().translate_by(dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_mouse_down_location = click_location;
|
m_mouse_down_location = click_location;
|
||||||
|
|
|
@ -46,9 +46,9 @@ private:
|
||||||
if (m_animation_card->position().y() + Card::height + m_y_velocity > SolitaireWidget::height + 1 && m_y_velocity > 0) {
|
if (m_animation_card->position().y() + Card::height + m_y_velocity > SolitaireWidget::height + 1 && m_y_velocity > 0) {
|
||||||
m_y_velocity = min((m_y_velocity * -m_bouncyness), -8.f);
|
m_y_velocity = min((m_y_velocity * -m_bouncyness), -8.f);
|
||||||
m_animation_card->rect().set_y(SolitaireWidget::height - Card::height);
|
m_animation_card->rect().set_y(SolitaireWidget::height - Card::height);
|
||||||
m_animation_card->rect().move_by(m_x_velocity, 0);
|
m_animation_card->rect().translate_by(m_x_velocity, 0);
|
||||||
} else {
|
} else {
|
||||||
m_animation_card->rect().move_by(m_x_velocity, m_y_velocity);
|
m_animation_card->rect().translate_by(m_x_velocity, m_y_velocity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ void Application::tooltip_show_timer_did_fire()
|
||||||
const int margin = 30;
|
const int margin = 30;
|
||||||
Gfx::IntPoint adjusted_pos = WindowServerConnection::the().send_sync<Messages::WindowServer::GetGlobalCursorPosition>()->position();
|
Gfx::IntPoint adjusted_pos = WindowServerConnection::the().send_sync<Messages::WindowServer::GetGlobalCursorPosition>()->position();
|
||||||
|
|
||||||
adjusted_pos.move_by(0, 18);
|
adjusted_pos.translate_by(0, 18);
|
||||||
|
|
||||||
if (adjusted_pos.x() + m_tooltip_window->width() >= desktop_rect.width() - margin) {
|
if (adjusted_pos.x() + m_tooltip_window->width() >= desktop_rect.width() - margin) {
|
||||||
adjusted_pos = adjusted_pos.translated(-m_tooltip_window->width(), 0);
|
adjusted_pos = adjusted_pos.translated(-m_tooltip_window->width(), 0);
|
||||||
|
|
|
@ -62,7 +62,7 @@ void Button::paint_event(PaintEvent& event)
|
||||||
painter.blit_filtered(icon_location.translated(1, 1), *m_icon, m_icon->rect(), [&shadow_color](auto) {
|
painter.blit_filtered(icon_location.translated(1, 1), *m_icon, m_icon->rect(), [&shadow_color](auto) {
|
||||||
return shadow_color;
|
return shadow_color;
|
||||||
});
|
});
|
||||||
icon_location.move_by(-1, -1);
|
icon_location.translate_by(-1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_icon) {
|
if (m_icon) {
|
||||||
|
@ -77,7 +77,7 @@ void Button::paint_event(PaintEvent& event)
|
||||||
}
|
}
|
||||||
auto& font = is_checked() ? Gfx::FontDatabase::default_bold_font() : this->font();
|
auto& font = is_checked() ? Gfx::FontDatabase::default_bold_font() : this->font();
|
||||||
if (m_icon && !text().is_empty()) {
|
if (m_icon && !text().is_empty()) {
|
||||||
content_rect.move_by(m_icon->width() + icon_spacing(), 0);
|
content_rect.translate_by(m_icon->width() + icon_spacing(), 0);
|
||||||
content_rect.set_width(content_rect.width() - m_icon->width() - icon_spacing());
|
content_rect.set_width(content_rect.width() - m_icon->width() - icon_spacing());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,7 @@ void HeaderView::paint_horizontal(Painter& painter)
|
||||||
}
|
}
|
||||||
auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0);
|
auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0);
|
||||||
if (pressed)
|
if (pressed)
|
||||||
text_rect.move_by(1, 1);
|
text_rect.translate_by(1, 1);
|
||||||
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());
|
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());
|
||||||
x_offset += section_width + m_table_view.horizontal_padding() * 2;
|
x_offset += section_width + m_table_view.horizontal_padding() * 2;
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ void HeaderView::paint_vertical(Painter& painter)
|
||||||
String text = String::number(section);
|
String text = String::number(section);
|
||||||
auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0);
|
auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0);
|
||||||
if (pressed)
|
if (pressed)
|
||||||
text_rect.move_by(1, 1);
|
text_rect.translate_by(1, 1);
|
||||||
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());
|
painter.draw_text(text_rect, text, font(), section_alignment(section), palette().button_text());
|
||||||
y_offset += section_size;
|
y_offset += section_size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -381,7 +381,7 @@ void IconView::update_item_rects(int item_index, ItemData& item_data) const
|
||||||
{
|
{
|
||||||
auto item_rect = this->item_rect(item_index);
|
auto item_rect = this->item_rect(item_index);
|
||||||
item_data.icon_rect.center_within(item_rect);
|
item_data.icon_rect.center_within(item_rect);
|
||||||
item_data.icon_rect.move_by(0, item_data.icon_offset_y);
|
item_data.icon_rect.translate_by(0, item_data.icon_offset_y);
|
||||||
item_data.text_rect.center_horizontally_within(item_rect);
|
item_data.text_rect.center_horizontally_within(item_rect);
|
||||||
item_data.text_rect.set_top(item_rect.y() + item_data.text_offset_y);
|
item_data.text_rect.set_top(item_rect.y() + item_data.text_offset_y);
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ void IconView::get_item_rects(int item_index, ItemData& item_data, const Gfx::Fo
|
||||||
item_data.icon_rect = { 0, 0, 32, 32 };
|
item_data.icon_rect = { 0, 0, 32, 32 };
|
||||||
item_data.icon_rect.center_within(item_rect);
|
item_data.icon_rect.center_within(item_rect);
|
||||||
item_data.icon_offset_y = -font.glyph_height() - 6;
|
item_data.icon_offset_y = -font.glyph_height() - 6;
|
||||||
item_data.icon_rect.move_by(0, item_data.icon_offset_y);
|
item_data.icon_rect.translate_by(0, item_data.icon_offset_y);
|
||||||
|
|
||||||
int unwrapped_text_width = font.width(item_data.text);
|
int unwrapped_text_width = font.width(item_data.text);
|
||||||
int available_width = item_rect.width() - 6;
|
int available_width = item_rect.width() - 6;
|
||||||
|
|
|
@ -79,7 +79,7 @@ Gfx::IntRect Label::text_rect(size_t line) const
|
||||||
if (frame_thickness() > 0)
|
if (frame_thickness() > 0)
|
||||||
indent = font().glyph_width('x') / 2;
|
indent = font().glyph_width('x') / 2;
|
||||||
auto rect = frame_inner_rect();
|
auto rect = frame_inner_rect();
|
||||||
rect.move_by(indent, line * (font().glyph_height() + 1));
|
rect.translate_by(indent, line * (font().glyph_height() + 1));
|
||||||
rect.set_width(rect.width() - indent * 2);
|
rect.set_width(rect.width() - indent * 2);
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ void ListView::paint_list_item(Painter& painter, int row_index, int painted_item
|
||||||
else
|
else
|
||||||
text_color = index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role()));
|
text_color = index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role()));
|
||||||
auto text_rect = row_rect;
|
auto text_rect = row_rect;
|
||||||
text_rect.move_by(horizontal_padding(), 0);
|
text_rect.translate_by(horizontal_padding(), 0);
|
||||||
text_rect.set_width(text_rect.width() - horizontal_padding() * 2);
|
text_rect.set_width(text_rect.width() - horizontal_padding() * 2);
|
||||||
auto text_alignment = index.data(ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft);
|
auto text_alignment = index.data(ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||||
painter.draw_text(text_rect, data.to_string(), font, text_alignment, text_color);
|
painter.draw_text(text_rect, data.to_string(), font, text_alignment, text_color);
|
||||||
|
|
|
@ -225,16 +225,16 @@ Gfx::IntRect ScrollableWidget::widget_inner_rect() const
|
||||||
Gfx::IntPoint ScrollableWidget::to_content_position(const Gfx::IntPoint& widget_position) const
|
Gfx::IntPoint ScrollableWidget::to_content_position(const Gfx::IntPoint& widget_position) const
|
||||||
{
|
{
|
||||||
auto content_position = widget_position;
|
auto content_position = widget_position;
|
||||||
content_position.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
|
content_position.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
|
||||||
content_position.move_by(-frame_thickness(), -frame_thickness());
|
content_position.translate_by(-frame_thickness(), -frame_thickness());
|
||||||
return content_position;
|
return content_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::IntPoint ScrollableWidget::to_widget_position(const Gfx::IntPoint& content_position) const
|
Gfx::IntPoint ScrollableWidget::to_widget_position(const Gfx::IntPoint& content_position) const
|
||||||
{
|
{
|
||||||
auto widget_position = content_position;
|
auto widget_position = content_position;
|
||||||
widget_position.move_by(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
|
widget_position.translate_by(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
|
||||||
widget_position.move_by(frame_thickness(), frame_thickness());
|
widget_position.translate_by(frame_thickness(), frame_thickness());
|
||||||
return widget_position;
|
return widget_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,14 +201,14 @@ void Scrollbar::paint_event(PaintEvent& event)
|
||||||
if (length(orientation()) > default_button_size()) {
|
if (length(orientation()) > default_button_size()) {
|
||||||
auto decrement_location = decrement_button_rect().location().translated(3, 3);
|
auto decrement_location = decrement_button_rect().location().translated(3, 3);
|
||||||
if (decrement_pressed)
|
if (decrement_pressed)
|
||||||
decrement_location.move_by(1, 1);
|
decrement_location.translate_by(1, 1);
|
||||||
if (!has_scrubber() || !is_enabled())
|
if (!has_scrubber() || !is_enabled())
|
||||||
painter.draw_bitmap(decrement_location.translated(1, 1), orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, palette().threed_highlight());
|
painter.draw_bitmap(decrement_location.translated(1, 1), orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, palette().threed_highlight());
|
||||||
painter.draw_bitmap(decrement_location, orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1());
|
painter.draw_bitmap(decrement_location, orientation() == Orientation::Vertical ? *s_up_arrow_bitmap : *s_left_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1());
|
||||||
|
|
||||||
auto increment_location = increment_button_rect().location().translated(3, 3);
|
auto increment_location = increment_button_rect().location().translated(3, 3);
|
||||||
if (increment_pressed)
|
if (increment_pressed)
|
||||||
increment_location.move_by(1, 1);
|
increment_location.translate_by(1, 1);
|
||||||
if (!has_scrubber() || !is_enabled())
|
if (!has_scrubber() || !is_enabled())
|
||||||
painter.draw_bitmap(increment_location.translated(1, 1), orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, palette().threed_highlight());
|
painter.draw_bitmap(increment_location.translated(1, 1), orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, palette().threed_highlight());
|
||||||
painter.draw_bitmap(increment_location, orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1());
|
painter.draw_bitmap(increment_location, orientation() == Orientation::Vertical ? *s_down_arrow_bitmap : *s_right_arrow_bitmap, (has_scrubber() && is_enabled()) ? palette().button_text() : palette().threed_shadow1());
|
||||||
|
|
|
@ -197,7 +197,7 @@ void TabWidget::paint_event(PaintEvent& event)
|
||||||
if (!icon)
|
if (!icon)
|
||||||
return;
|
return;
|
||||||
Gfx::IntRect icon_rect { button_rect.x(), button_rect.y(), 16, 16 };
|
Gfx::IntRect icon_rect { button_rect.x(), button_rect.y(), 16, 16 };
|
||||||
icon_rect.move_by(4, 3);
|
icon_rect.translate_by(4, 3);
|
||||||
painter.draw_scaled_bitmap(icon_rect, *icon, icon->rect());
|
painter.draw_scaled_bitmap(icon_rect, *icon, icon->rect());
|
||||||
text_rect.set_x(icon_rect.right() + 1 + 4);
|
text_rect.set_x(icon_rect.right() + 1 + 4);
|
||||||
text_rect.intersect(button_rect);
|
text_rect.intersect(button_rect);
|
||||||
|
@ -281,13 +281,13 @@ Gfx::IntRect TabWidget::button_rect(int index) const
|
||||||
}
|
}
|
||||||
Gfx::IntRect rect { x_offset, 0, m_uniform_tabs ? uniform_tab_width() : m_tabs[index].width(font()), bar_height() };
|
Gfx::IntRect rect { x_offset, 0, m_uniform_tabs ? uniform_tab_width() : m_tabs[index].width(font()), bar_height() };
|
||||||
if (m_tabs[index].widget != m_active_widget) {
|
if (m_tabs[index].widget != m_active_widget) {
|
||||||
rect.move_by(0, m_tab_position == TabPosition::Top ? 2 : 0);
|
rect.translate_by(0, m_tab_position == TabPosition::Top ? 2 : 0);
|
||||||
rect.set_height(rect.height() - 2);
|
rect.set_height(rect.height() - 2);
|
||||||
} else {
|
} else {
|
||||||
rect.move_by(-2, 0);
|
rect.translate_by(-2, 0);
|
||||||
rect.set_width(rect.width() + 4);
|
rect.set_width(rect.width() + 4);
|
||||||
}
|
}
|
||||||
rect.move_by(bar_rect().location());
|
rect.translate_by(bar_rect().location());
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ TextPosition TextEditor::text_position_at_content_position(const Gfx::IntPoint&
|
||||||
{
|
{
|
||||||
auto position = content_position;
|
auto position = content_position;
|
||||||
if (is_single_line() && icon())
|
if (is_single_line() && icon())
|
||||||
position.move_by(-(icon_size() + icon_padding()), 0);
|
position.translate_by(-(icon_size() + icon_padding()), 0);
|
||||||
|
|
||||||
size_t line_index = 0;
|
size_t line_index = 0;
|
||||||
|
|
||||||
|
@ -194,9 +194,9 @@ TextPosition TextEditor::text_position_at_content_position(const Gfx::IntPoint&
|
||||||
TextPosition TextEditor::text_position_at(const Gfx::IntPoint& widget_position) const
|
TextPosition TextEditor::text_position_at(const Gfx::IntPoint& widget_position) const
|
||||||
{
|
{
|
||||||
auto content_position = widget_position;
|
auto content_position = widget_position;
|
||||||
content_position.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
|
content_position.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
|
||||||
content_position.move_by(-(m_horizontal_content_padding + ruler_width()), 0);
|
content_position.translate_by(-(m_horizontal_content_padding + ruler_width()), 0);
|
||||||
content_position.move_by(-frame_thickness(), -frame_thickness());
|
content_position.translate_by(-frame_thickness(), -frame_thickness());
|
||||||
return text_position_at_content_position(content_position);
|
return text_position_at_content_position(content_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,8 +435,8 @@ void TextEditor::paint_event(PaintEvent& event)
|
||||||
height() - height_occupied_by_horizontal_scrollbar()
|
height() - height_occupied_by_horizontal_scrollbar()
|
||||||
};
|
};
|
||||||
if (m_ruler_visible)
|
if (m_ruler_visible)
|
||||||
text_clip_rect.move_by(-ruler_width(), 0);
|
text_clip_rect.translate_by(-ruler_width(), 0);
|
||||||
text_clip_rect.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
|
text_clip_rect.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
|
||||||
painter.add_clip_rect(text_clip_rect);
|
painter.add_clip_rect(text_clip_rect);
|
||||||
|
|
||||||
size_t span_index = 0;
|
size_t span_index = 0;
|
||||||
|
@ -507,7 +507,7 @@ void TextEditor::paint_event(PaintEvent& event)
|
||||||
if (underline) {
|
if (underline) {
|
||||||
painter.draw_line(span_rect.bottom_left().translated(0, 1), span_rect.bottom_right().translated(0, 1), color);
|
painter.draw_line(span_rect.bottom_left().translated(0, 1), span_rect.bottom_right().translated(0, 1), color);
|
||||||
}
|
}
|
||||||
span_rect.move_by(span_rect.width(), 0);
|
span_rect.translate_by(span_rect.width(), 0);
|
||||||
};
|
};
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (span_index >= document().spans().size()) {
|
if (span_index >= document().spans().size()) {
|
||||||
|
@ -1015,8 +1015,8 @@ Gfx::IntRect TextEditor::line_widget_rect(size_t line_index) const
|
||||||
auto rect = line_content_rect(line_index);
|
auto rect = line_content_rect(line_index);
|
||||||
rect.set_x(frame_thickness());
|
rect.set_x(frame_thickness());
|
||||||
rect.set_width(frame_inner_rect().width());
|
rect.set_width(frame_inner_rect().width());
|
||||||
rect.move_by(0, -(vertical_scrollbar().value()));
|
rect.translate_by(0, -(vertical_scrollbar().value()));
|
||||||
rect.move_by(0, frame_thickness());
|
rect.translate_by(0, frame_thickness());
|
||||||
rect.intersect(frame_inner_rect());
|
rect.intersect(frame_inner_rect());
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
@ -1567,7 +1567,7 @@ void TextEditor::for_each_visual_line(size_t line_index, Callback callback) cons
|
||||||
if (is_single_line()) {
|
if (is_single_line()) {
|
||||||
visual_line_rect.center_vertically_within(editor_visible_text_rect);
|
visual_line_rect.center_vertically_within(editor_visible_text_rect);
|
||||||
if (m_icon)
|
if (m_icon)
|
||||||
visual_line_rect.move_by(icon_size() + icon_padding(), 0);
|
visual_line_rect.translate_by(icon_size() + icon_padding(), 0);
|
||||||
}
|
}
|
||||||
if (callback(visual_line_rect, visual_line_view, start_of_line, visual_line_index == visual_data.visual_line_breaks.size() - 1) == IterationDecision::Break)
|
if (callback(visual_line_rect, visual_line_view, start_of_line, visual_line_index == visual_data.visual_line_breaks.size() - 1) == IterationDecision::Break)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -575,7 +575,7 @@ Gfx::IntRect Widget::window_relative_rect() const
|
||||||
{
|
{
|
||||||
auto rect = relative_rect();
|
auto rect = relative_rect();
|
||||||
for (auto* parent = parent_widget(); parent; parent = parent->parent_widget()) {
|
for (auto* parent = parent_widget(); parent; parent = parent->parent_widget()) {
|
||||||
rect.move_by(parent->relative_position());
|
rect.translate_by(parent->relative_position());
|
||||||
}
|
}
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
@ -957,7 +957,7 @@ void Widget::set_content_margins(const Margins& margins)
|
||||||
Gfx::IntRect Widget::content_rect() const
|
Gfx::IntRect Widget::content_rect() const
|
||||||
{
|
{
|
||||||
auto rect = relative_rect();
|
auto rect = relative_rect();
|
||||||
rect.move_by(m_content_margins.left(), m_content_margins.top());
|
rect.translate_by(m_content_margins.left(), m_content_margins.top());
|
||||||
rect.set_width(rect.width() - (m_content_margins.left() + m_content_margins.right()));
|
rect.set_width(rect.width() - (m_content_margins.left() + m_content_margins.right()));
|
||||||
rect.set_height(rect.height() - (m_content_margins.top() + m_content_margins.bottom()));
|
rect.set_height(rect.height() - (m_content_margins.top() + m_content_margins.bottom()));
|
||||||
return rect;
|
return rect;
|
||||||
|
|
|
@ -319,7 +319,7 @@ void ClassicStylePainter::paint_progressbar(Painter& painter, const IntRect& rec
|
||||||
float progress_height = progress * rect.height();
|
float progress_height = progress * rect.height();
|
||||||
hole_rect = { 0, 0, rect.width(), (int)(rect.height() - progress_height) };
|
hole_rect = { 0, 0, rect.width(), (int)(rect.height() - progress_height) };
|
||||||
}
|
}
|
||||||
hole_rect.move_by(rect.location());
|
hole_rect.translate_by(rect.location());
|
||||||
hole_rect.set_right_without_resize(rect.right());
|
hole_rect.set_right_without_resize(rect.right());
|
||||||
PainterStateSaver saver(painter);
|
PainterStateSaver saver(painter);
|
||||||
painter.fill_rect(hole_rect, palette.base());
|
painter.fill_rect(hole_rect, palette.base());
|
||||||
|
|
|
@ -36,7 +36,7 @@ Gfx::IntRect ClassicWindowTheme::titlebar_icon_rect(WindowType window_type, cons
|
||||||
16,
|
16,
|
||||||
};
|
};
|
||||||
icon_rect.center_vertically_within(titlebar_rect);
|
icon_rect.center_vertically_within(titlebar_rect);
|
||||||
icon_rect.move_by(0, 1);
|
icon_rect.translate_by(0, 1);
|
||||||
return icon_rect;
|
return icon_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ void DisjointRectSet::shatter()
|
||||||
void DisjointRectSet::move_by(int dx, int dy)
|
void DisjointRectSet::move_by(int dx, int dy)
|
||||||
{
|
{
|
||||||
for (auto& r : m_rects)
|
for (auto& r : m_rects)
|
||||||
r.move_by(dx, dy);
|
r.translate_by(dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DisjointRectSet::contains(const IntRect& rect) const
|
bool DisjointRectSet::contains(const IntRect& rect) const
|
||||||
|
|
|
@ -95,7 +95,7 @@ public:
|
||||||
// TODO: We probably don't need the entire source_rect, we could inflate
|
// TODO: We probably don't need the entire source_rect, we could inflate
|
||||||
// the target_rect appropriately
|
// the target_rect appropriately
|
||||||
apply_cache.m_target = Gfx::Bitmap::create(source.format(), source_rect.size());
|
apply_cache.m_target = Gfx::Bitmap::create(source.format(), source_rect.size());
|
||||||
target_rect.move_by(-target_rect.location());
|
target_rect.translate_by(-target_rect.location());
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap* render_target_bitmap = (&target != &source) ? &target : apply_cache.m_target.ptr();
|
Bitmap* render_target_bitmap = (&target != &source) ? &target : apply_cache.m_target.ptr();
|
||||||
|
|
|
@ -1070,28 +1070,28 @@ void draw_text_line(const IntRect& a_rect, const TextType& text, const Font& fon
|
||||||
|
|
||||||
if (is_vertically_centered_text_alignment(alignment)) {
|
if (is_vertically_centered_text_alignment(alignment)) {
|
||||||
int distance_from_baseline_to_bottom = (font.glyph_height() - 1) - font.baseline();
|
int distance_from_baseline_to_bottom = (font.glyph_height() - 1) - font.baseline();
|
||||||
rect.move_by(0, distance_from_baseline_to_bottom / 2);
|
rect.translate_by(0, distance_from_baseline_to_bottom / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto point = rect.location();
|
auto point = rect.location();
|
||||||
int space_width = font.glyph_width(' ') + font.glyph_spacing();
|
int space_width = font.glyph_width(' ') + font.glyph_spacing();
|
||||||
|
|
||||||
if (direction == TextDirection::RTL) {
|
if (direction == TextDirection::RTL) {
|
||||||
point.move_by(rect.width(), 0); // Start drawing from the end
|
point.translate_by(rect.width(), 0); // Start drawing from the end
|
||||||
space_width = -space_width; // Draw spaces backwards
|
space_width = -space_width; // Draw spaces backwards
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u32 code_point : final_text) {
|
for (u32 code_point : final_text) {
|
||||||
if (code_point == ' ') {
|
if (code_point == ' ') {
|
||||||
point.move_by(space_width, 0);
|
point.translate_by(space_width, 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
IntSize glyph_size(font.glyph_or_emoji_width(code_point) + font.glyph_spacing(), font.glyph_height());
|
IntSize glyph_size(font.glyph_or_emoji_width(code_point) + font.glyph_spacing(), font.glyph_height());
|
||||||
if (direction == TextDirection::RTL)
|
if (direction == TextDirection::RTL)
|
||||||
point.move_by(-glyph_size.width(), 0); // If we are drawing right to left, we have to move backwards before drawing the glyph
|
point.translate_by(-glyph_size.width(), 0); // If we are drawing right to left, we have to move backwards before drawing the glyph
|
||||||
draw_glyph({ point, glyph_size }, code_point);
|
draw_glyph({ point, glyph_size }, code_point);
|
||||||
if (direction == TextDirection::LTR)
|
if (direction == TextDirection::LTR)
|
||||||
point.move_by(glyph_size.width(), 0);
|
point.translate_by(glyph_size.width(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1414,7 +1414,7 @@ void Painter::set_pixel(const IntPoint& p, Color color)
|
||||||
VERIFY(scale() == 1); // FIXME: Add scaling support.
|
VERIFY(scale() == 1); // FIXME: Add scaling support.
|
||||||
|
|
||||||
auto point = p;
|
auto point = p;
|
||||||
point.move_by(state().translation);
|
point.translate_by(state().translation);
|
||||||
if (!clip_rect().contains(point))
|
if (!clip_rect().contains(point))
|
||||||
return;
|
return;
|
||||||
m_target->scanline(point.y())[point.x()] = color.value();
|
m_target->scanline(point.y())[point.x()] = color.value();
|
||||||
|
|
|
@ -100,7 +100,7 @@ public:
|
||||||
void clear_clip_rect();
|
void clear_clip_rect();
|
||||||
|
|
||||||
void translate(int dx, int dy) { translate({ dx, dy }); }
|
void translate(int dx, int dy) { translate({ dx, dy }); }
|
||||||
void translate(const IntPoint& delta) { state().translation.move_by(delta); }
|
void translate(const IntPoint& delta) { state().translation.translate_by(delta); }
|
||||||
|
|
||||||
Gfx::Bitmap* target() { return m_target.ptr(); }
|
Gfx::Bitmap* target() { return m_target.ptr(); }
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ void Path::elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, d
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the endpoint by a small amount to avoid division by zero.
|
// Move the endpoint by a small amount to avoid division by zero.
|
||||||
next_point.move_by(0.01f, 0.01f);
|
next_point.translate_by(0.01f, 0.01f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find (cx, cy), theta_1, theta_delta
|
// Find (cx, cy), theta_1, theta_delta
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
|
#include <LibGfx/AffineTransform.h>
|
||||||
#include <LibGfx/Forward.h>
|
#include <LibGfx/Forward.h>
|
||||||
#include <LibGfx/Orientation.h>
|
#include <LibGfx/Orientation.h>
|
||||||
#include <LibIPC/Forward.h>
|
#include <LibIPC/Forward.h>
|
||||||
|
@ -19,7 +20,7 @@ namespace Gfx {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class Point {
|
class Point {
|
||||||
public:
|
public:
|
||||||
Point() { }
|
Point() = default;
|
||||||
|
|
||||||
Point(T x, T y)
|
Point(T x, T y)
|
||||||
: m_x(x)
|
: m_x(x)
|
||||||
|
@ -41,41 +42,74 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
T x() const { return m_x; }
|
[[nodiscard]] ALWAYS_INLINE T x() const { return m_x; }
|
||||||
T y() const { return m_y; }
|
[[nodiscard]] ALWAYS_INLINE T y() const { return m_y; }
|
||||||
|
|
||||||
void set_x(T x) { m_x = x; }
|
ALWAYS_INLINE void set_x(T x) { m_x = x; }
|
||||||
void set_y(T y) { m_y = y; }
|
ALWAYS_INLINE void set_y(T y) { m_y = y; }
|
||||||
|
|
||||||
void move_by(T dx, T dy)
|
[[nodiscard]] ALWAYS_INLINE bool is_null() const { return !m_x && !m_y; }
|
||||||
|
[[nodiscard]] ALWAYS_INLINE bool is_empty() const { return m_x <= 0 && m_y <= 0; }
|
||||||
|
|
||||||
|
void translate_by(T dx, T dy)
|
||||||
{
|
{
|
||||||
m_x += dx;
|
m_x += dx;
|
||||||
m_y += dy;
|
m_y += dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_by(const Point<T>& delta)
|
ALWAYS_INLINE void translate_by(T dboth) { translate_by(dboth, dboth); }
|
||||||
|
ALWAYS_INLINE void translate_by(const Point<T>& delta) { translate_by(delta.x(), delta.y()); }
|
||||||
|
|
||||||
|
void scale_by(T dx, T dy)
|
||||||
{
|
{
|
||||||
move_by(delta.x(), delta.y());
|
m_x *= dx;
|
||||||
|
m_y *= dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE void scale_by(T dboth) { scale_by(dboth, dboth); }
|
||||||
|
ALWAYS_INLINE void scale_by(const Point<T>& delta) { scale_by(delta.x(), delta.y()); }
|
||||||
|
|
||||||
|
void transform_by(const AffineTransform& transform) { *this = transform.map(*this); }
|
||||||
|
|
||||||
Point<T> translated(const Point<T>& delta) const
|
Point<T> translated(const Point<T>& delta) const
|
||||||
{
|
{
|
||||||
Point<T> point = *this;
|
Point<T> point = *this;
|
||||||
point.move_by(delta);
|
point.translate_by(delta);
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point<T> translated(T dx, T dy) const
|
Point<T> translated(T dx, T dy) const
|
||||||
{
|
{
|
||||||
Point<T> point = *this;
|
Point<T> point = *this;
|
||||||
point.move_by(dx, dy);
|
point.translate_by(dx, dy);
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point<T> translated(T dboth) const
|
Point<T> translated(T dboth) const
|
||||||
{
|
{
|
||||||
Point<T> point = *this;
|
Point<T> point = *this;
|
||||||
point.move_by(dboth, dboth);
|
point.translate_by(dboth, dboth);
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point<T> scaled(const Point<T>& delta) const
|
||||||
|
{
|
||||||
|
Point<T> point = *this;
|
||||||
|
point.scale_by(delta);
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point<T> scaled(T sx, T sy) const
|
||||||
|
{
|
||||||
|
Point<T> point = *this;
|
||||||
|
point.scale_by(sx, sy);
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point<T> transformed(const AffineTransform& transform) const
|
||||||
|
{
|
||||||
|
Point<T> point = *this;
|
||||||
|
point.transform_by(transform);
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +121,11 @@ public:
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Point<T> moved_left(T amount) const { return { x() - amount, y() }; }
|
||||||
|
Point<T> moved_right(T amount) const { return { x() + amount, y() }; }
|
||||||
|
Point<T> moved_up(T amount) const { return { x(), y() - amount }; }
|
||||||
|
Point<T> moved_down(T amount) const { return { x(), y() + amount }; }
|
||||||
|
|
||||||
template<class U>
|
template<class U>
|
||||||
bool operator==(const Point<U>& other) const
|
bool operator==(const Point<U>& other) const
|
||||||
{
|
{
|
||||||
|
@ -137,8 +176,6 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_null() const { return !m_x && !m_y; }
|
|
||||||
|
|
||||||
T primary_offset_for_orientation(Orientation orientation) const
|
T primary_offset_for_orientation(Orientation orientation) const
|
||||||
{
|
{
|
||||||
return orientation == Orientation::Vertical ? y() : x();
|
return orientation == Orientation::Vertical ? y() : x();
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
|
#include <LibGfx/AffineTransform.h>
|
||||||
#include <LibGfx/Orientation.h>
|
#include <LibGfx/Orientation.h>
|
||||||
#include <LibGfx/Point.h>
|
#include <LibGfx/Point.h>
|
||||||
#include <LibGfx/Size.h>
|
#include <LibGfx/Size.h>
|
||||||
|
@ -24,7 +25,7 @@ T abst(T value)
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class Rect {
|
class Rect {
|
||||||
public:
|
public:
|
||||||
Rect() { }
|
Rect() = default;
|
||||||
|
|
||||||
Rect(T x, T y, T width, T height)
|
Rect(T x, T y, T width, T height)
|
||||||
: m_location(x, y)
|
: m_location(x, y)
|
||||||
|
@ -59,37 +60,47 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_null() const
|
[[nodiscard]] ALWAYS_INLINE T x() const { return location().x(); }
|
||||||
{
|
[[nodiscard]] ALWAYS_INLINE T y() const { return location().y(); }
|
||||||
return width() == 0 && height() == 0;
|
[[nodiscard]] ALWAYS_INLINE T width() const { return m_size.width(); }
|
||||||
}
|
[[nodiscard]] ALWAYS_INLINE T height() const { return m_size.height(); }
|
||||||
|
|
||||||
bool is_empty() const
|
ALWAYS_INLINE void set_x(T x) { m_location.set_x(x); }
|
||||||
{
|
ALWAYS_INLINE void set_y(T y) { m_location.set_y(y); }
|
||||||
return width() <= 0 || height() <= 0;
|
ALWAYS_INLINE void set_width(T width) { m_size.set_width(width); }
|
||||||
}
|
ALWAYS_INLINE void set_height(T height) { m_size.set_height(height); }
|
||||||
|
|
||||||
void move_by(T dx, T dy)
|
[[nodiscard]] ALWAYS_INLINE const Point<T>& location() const { return m_location; }
|
||||||
{
|
[[nodiscard]] ALWAYS_INLINE const Size<T>& size() const { return m_size; }
|
||||||
m_location.move_by(dx, dy);
|
|
||||||
}
|
|
||||||
|
|
||||||
void move_by(const Point<T>& delta)
|
[[nodiscard]] ALWAYS_INLINE bool is_null() const { return width() == 0 && height() == 0; }
|
||||||
|
[[nodiscard]] ALWAYS_INLINE bool is_empty() const { return width() <= 0 || height() <= 0; }
|
||||||
|
|
||||||
|
ALWAYS_INLINE void translate_by(T dx, T dy) { m_location.translate_by(dx, dy); }
|
||||||
|
ALWAYS_INLINE void translate_by(T dboth) { m_location.translate_by(dboth); }
|
||||||
|
ALWAYS_INLINE void translate_by(const Point<T>& delta) { m_location.translate_by(delta); }
|
||||||
|
|
||||||
|
ALWAYS_INLINE void scale_by(T dx, T dy)
|
||||||
{
|
{
|
||||||
m_location.move_by(delta);
|
m_location.scale_by(dx, dy);
|
||||||
|
m_size.scale_by(dx, dy);
|
||||||
}
|
}
|
||||||
|
ALWAYS_INLINE void scale_by(T dboth) { scale_by(dboth, dboth); }
|
||||||
|
ALWAYS_INLINE void scale_by(const Point<T>& delta) { scale_by(delta.x(), delta.y()); }
|
||||||
|
|
||||||
|
void transform_by(const AffineTransform& transform) { *this = transform.map(*this); }
|
||||||
|
|
||||||
Point<T> center() const
|
Point<T> center() const
|
||||||
{
|
{
|
||||||
return { x() + width() / 2, y() + height() / 2 };
|
return { x() + width() / 2, y() + height() / 2 };
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_location(const Point<T>& location)
|
ALWAYS_INLINE void set_location(const Point<T>& location)
|
||||||
{
|
{
|
||||||
m_location = location;
|
m_location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_size(const Size<T>& size)
|
ALWAYS_INLINE void set_size(const Size<T>& size)
|
||||||
{
|
{
|
||||||
m_size = size;
|
m_size = size;
|
||||||
}
|
}
|
||||||
|
@ -134,6 +145,41 @@ public:
|
||||||
set_height(height() - size.height());
|
set_height(height() - size.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect<T> translated(T dx, T dy) const
|
||||||
|
{
|
||||||
|
Rect<T> rect = *this;
|
||||||
|
rect.translate_by(dx, dy);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect<T> translated(const Point<T>& delta) const
|
||||||
|
{
|
||||||
|
Rect<T> rect = *this;
|
||||||
|
rect.translate_by(delta);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect<T> scaled(T sx, T sy) const
|
||||||
|
{
|
||||||
|
Rect<T> rect = *this;
|
||||||
|
rect.scale_by(sx, sy);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect<T> scaled(const Point<T>& s) const
|
||||||
|
{
|
||||||
|
Rect<T> rect = *this;
|
||||||
|
rect.scale_by(s);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect<T> transformed(const AffineTransform& transform) const
|
||||||
|
{
|
||||||
|
Rect<T> rect = *this;
|
||||||
|
rect.transform_by(transform);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
Rect<T> shrunken(T w, T h) const
|
Rect<T> shrunken(T w, T h) const
|
||||||
{
|
{
|
||||||
Rect<T> rect = *this;
|
Rect<T> rect = *this;
|
||||||
|
@ -162,20 +208,6 @@ public:
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect<T> translated(T dx, T dy) const
|
|
||||||
{
|
|
||||||
Rect<T> rect = *this;
|
|
||||||
rect.move_by(dx, dy);
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rect<T> translated(const Point<T>& delta) const
|
|
||||||
{
|
|
||||||
Rect<T> rect = *this;
|
|
||||||
rect.move_by(delta);
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rect<T> take_from_right(T w)
|
Rect<T> take_from_right(T w)
|
||||||
{
|
{
|
||||||
if (w > width())
|
if (w > width())
|
||||||
|
@ -235,7 +267,7 @@ public:
|
||||||
return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom();
|
return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool contains(const Point<T>& point) const
|
ALWAYS_INLINE bool contains(const Point<T>& point) const
|
||||||
{
|
{
|
||||||
return contains(point.x(), point.y());
|
return contains(point.x(), point.y());
|
||||||
}
|
}
|
||||||
|
@ -260,15 +292,15 @@ public:
|
||||||
return have_any;
|
return have_any;
|
||||||
}
|
}
|
||||||
|
|
||||||
int primary_offset_for_orientation(Orientation orientation) const { return m_location.primary_offset_for_orientation(orientation); }
|
ALWAYS_INLINE int primary_offset_for_orientation(Orientation orientation) const { return m_location.primary_offset_for_orientation(orientation); }
|
||||||
void set_primary_offset_for_orientation(Orientation orientation, int value) { m_location.set_primary_offset_for_orientation(orientation, value); }
|
ALWAYS_INLINE void set_primary_offset_for_orientation(Orientation orientation, int value) { m_location.set_primary_offset_for_orientation(orientation, value); }
|
||||||
int secondary_offset_for_orientation(Orientation orientation) const { return m_location.secondary_offset_for_orientation(orientation); }
|
ALWAYS_INLINE int secondary_offset_for_orientation(Orientation orientation) const { return m_location.secondary_offset_for_orientation(orientation); }
|
||||||
void set_secondary_offset_for_orientation(Orientation orientation, int value) { m_location.set_secondary_offset_for_orientation(orientation, value); }
|
ALWAYS_INLINE void set_secondary_offset_for_orientation(Orientation orientation, int value) { m_location.set_secondary_offset_for_orientation(orientation, value); }
|
||||||
|
|
||||||
int primary_size_for_orientation(Orientation orientation) const { return m_size.primary_size_for_orientation(orientation); }
|
ALWAYS_INLINE int primary_size_for_orientation(Orientation orientation) const { return m_size.primary_size_for_orientation(orientation); }
|
||||||
int secondary_size_for_orientation(Orientation orientation) const { return m_size.secondary_size_for_orientation(orientation); }
|
ALWAYS_INLINE int secondary_size_for_orientation(Orientation orientation) const { return m_size.secondary_size_for_orientation(orientation); }
|
||||||
void set_primary_size_for_orientation(Orientation orientation, int value) { m_size.set_primary_size_for_orientation(orientation, value); }
|
ALWAYS_INLINE void set_primary_size_for_orientation(Orientation orientation, int value) { m_size.set_primary_size_for_orientation(orientation, value); }
|
||||||
void set_secondary_size_for_orientation(Orientation orientation, int value) { m_size.set_secondary_size_for_orientation(orientation, value); }
|
ALWAYS_INLINE void set_secondary_size_for_orientation(Orientation orientation, int value) { m_size.set_secondary_size_for_orientation(orientation, value); }
|
||||||
|
|
||||||
T first_edge_for_orientation(Orientation orientation) const
|
T first_edge_for_orientation(Orientation orientation) const
|
||||||
{
|
{
|
||||||
|
@ -284,27 +316,27 @@ public:
|
||||||
return right();
|
return right();
|
||||||
}
|
}
|
||||||
|
|
||||||
T left() const { return x(); }
|
[[nodiscard]] ALWAYS_INLINE T left() const { return x(); }
|
||||||
T right() const { return x() + width() - 1; }
|
[[nodiscard]] ALWAYS_INLINE T right() const { return x() + width() - 1; }
|
||||||
T top() const { return y(); }
|
[[nodiscard]] ALWAYS_INLINE T top() const { return y(); }
|
||||||
T bottom() const { return y() + height() - 1; }
|
[[nodiscard]] ALWAYS_INLINE T bottom() const { return y() + height() - 1; }
|
||||||
|
|
||||||
void set_left(T left)
|
ALWAYS_INLINE void set_left(T left)
|
||||||
{
|
{
|
||||||
set_x(left);
|
set_x(left);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_top(T top)
|
ALWAYS_INLINE void set_top(T top)
|
||||||
{
|
{
|
||||||
set_y(top);
|
set_y(top);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_right(T right)
|
ALWAYS_INLINE void set_right(T right)
|
||||||
{
|
{
|
||||||
set_width(right - x() + 1);
|
set_width(right - x() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_bottom(T bottom)
|
ALWAYS_INLINE void set_bottom(T bottom)
|
||||||
{
|
{
|
||||||
set_height(bottom - y() + 1);
|
set_height(bottom - y() + 1);
|
||||||
}
|
}
|
||||||
|
@ -312,13 +344,13 @@ public:
|
||||||
void set_right_without_resize(T new_right)
|
void set_right_without_resize(T new_right)
|
||||||
{
|
{
|
||||||
int delta = new_right - right();
|
int delta = new_right - right();
|
||||||
move_by(delta, 0);
|
translate_by(delta, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_bottom_without_resize(T new_bottom)
|
void set_bottom_without_resize(T new_bottom)
|
||||||
{
|
{
|
||||||
int delta = new_bottom - bottom();
|
int delta = new_bottom - bottom();
|
||||||
move_by(0, delta);
|
translate_by(0, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool intersects_vertically(const Rect<T>& other) const
|
bool intersects_vertically(const Rect<T>& other) const
|
||||||
|
@ -365,19 +397,6 @@ public:
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
T x() const { return location().x(); }
|
|
||||||
T y() const { return location().y(); }
|
|
||||||
T width() const { return m_size.width(); }
|
|
||||||
T height() const { return m_size.height(); }
|
|
||||||
|
|
||||||
void set_x(T x) { m_location.set_x(x); }
|
|
||||||
void set_y(T y) { m_location.set_y(y); }
|
|
||||||
void set_width(T width) { m_size.set_width(width); }
|
|
||||||
void set_height(T height) { m_size.set_height(height); }
|
|
||||||
|
|
||||||
const Point<T>& location() const { return m_location; }
|
|
||||||
const Size<T>& size() const { return m_size; }
|
|
||||||
|
|
||||||
Vector<Rect<T>, 4> shatter(const Rect<T>& hammer) const;
|
Vector<Rect<T>, 4> shatter(const Rect<T>& hammer) const;
|
||||||
|
|
||||||
template<class U>
|
template<class U>
|
||||||
|
@ -415,7 +434,7 @@ public:
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect<T> intersected(const Rect<T>& other) const
|
ALWAYS_INLINE Rect<T> intersected(const Rect<T>& other) const
|
||||||
{
|
{
|
||||||
return intersection(*this, other);
|
return intersection(*this, other);
|
||||||
}
|
}
|
||||||
|
@ -446,7 +465,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
Rect<U> to() const
|
ALWAYS_INLINE Rect<U> to_type() const
|
||||||
{
|
{
|
||||||
return Rect<U>(*this);
|
return Rect<U>(*this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <LibGfx/Orientation.h>
|
#include <LibGfx/Orientation.h>
|
||||||
|
#include <LibGfx/Point.h>
|
||||||
#include <LibIPC/Forward.h>
|
#include <LibIPC/Forward.h>
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
@ -15,7 +16,7 @@ namespace Gfx {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class Size {
|
class Size {
|
||||||
public:
|
public:
|
||||||
Size() { }
|
Size() = default;
|
||||||
|
|
||||||
Size(T w, T h)
|
Size(T w, T h)
|
||||||
: m_width(w)
|
: m_width(w)
|
||||||
|
@ -37,16 +38,54 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_null() const { return !m_width && !m_height; }
|
[[nodiscard]] ALWAYS_INLINE T width() const { return m_width; }
|
||||||
bool is_empty() const { return m_width <= 0 || m_height <= 0; }
|
[[nodiscard]] ALWAYS_INLINE T height() const { return m_height; }
|
||||||
|
[[nodiscard]] ALWAYS_INLINE T area() const { return width() * height(); }
|
||||||
|
|
||||||
T width() const { return m_width; }
|
ALWAYS_INLINE void set_width(T w) { m_width = w; }
|
||||||
T height() const { return m_height; }
|
ALWAYS_INLINE void set_height(T h) { m_height = h; }
|
||||||
|
|
||||||
T area() const { return width() * height(); }
|
[[nodiscard]] ALWAYS_INLINE bool is_null() const { return !m_width && !m_height; }
|
||||||
|
[[nodiscard]] ALWAYS_INLINE bool is_empty() const { return m_width <= 0 || m_height <= 0; }
|
||||||
|
|
||||||
void set_width(T w) { m_width = w; }
|
void scale_by(T dx, T dy)
|
||||||
void set_height(T h) { m_height = h; }
|
{
|
||||||
|
m_width *= dx;
|
||||||
|
m_height *= dy;
|
||||||
|
}
|
||||||
|
|
||||||
|
void transform_by(const AffineTransform& transform) { *this = transform.map(*this); }
|
||||||
|
|
||||||
|
ALWAYS_INLINE void scale_by(T dboth) { scale_by(dboth, dboth); }
|
||||||
|
ALWAYS_INLINE void scale_by(const Point<T>& s) { scale_by(s.x(), s.y()); }
|
||||||
|
|
||||||
|
Size scaled_by(T dx, T dy) const
|
||||||
|
{
|
||||||
|
Size<T> size = *this;
|
||||||
|
size.scale_by(dx, dy);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size scaled_by(T dboth) const
|
||||||
|
{
|
||||||
|
Size<T> size = *this;
|
||||||
|
size.scale_by(dboth);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size scaled_by(const Point<T>& s) const
|
||||||
|
{
|
||||||
|
Size<T> size = *this;
|
||||||
|
size.scale_by(s);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size transformed_by(const AffineTransform& transform) const
|
||||||
|
{
|
||||||
|
Size<T> size = *this;
|
||||||
|
size.transform_by(transform);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
bool contains(const Size<U>& other) const
|
bool contains(const Size<U>& other) const
|
||||||
|
@ -118,7 +157,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U>
|
template<typename U>
|
||||||
Size<U> to_type() const
|
ALWAYS_INLINE Size<U> to_type() const
|
||||||
{
|
{
|
||||||
return Size<U>(*this);
|
return Size<U>(*this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ void CanvasRenderingContext2D::fill_text(const String& text, float x, float y, O
|
||||||
auto text_rect = Gfx::IntRect(x, y, max_width.has_value() ? max_width.value() : painter->font().width(text), painter->font().glyph_height());
|
auto text_rect = Gfx::IntRect(x, y, max_width.has_value() ? max_width.value() : painter->font().width(text), painter->font().glyph_height());
|
||||||
auto transformed_rect = m_transform.map(text_rect);
|
auto transformed_rect = m_transform.map(text_rect);
|
||||||
painter->draw_text(transformed_rect, text, Gfx::TextAlignment::TopLeft, m_fill_style);
|
painter->draw_text(transformed_rect, text, Gfx::TextAlignment::TopLeft, m_fill_style);
|
||||||
did_draw(transformed_rect.to<float>());
|
did_draw(transformed_rect.to_type<float>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanvasRenderingContext2D::begin_path()
|
void CanvasRenderingContext2D::begin_path()
|
||||||
|
|
|
@ -142,7 +142,7 @@ bool BlockBox::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsi
|
||||||
if (!is_scrollable())
|
if (!is_scrollable())
|
||||||
return false;
|
return false;
|
||||||
auto new_offset = m_scroll_offset;
|
auto new_offset = m_scroll_offset;
|
||||||
new_offset.move_by(0, wheel_delta);
|
new_offset.translate_by(0, wheel_delta);
|
||||||
set_scroll_offset(new_offset);
|
set_scroll_offset(new_offset);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -550,7 +550,7 @@ static Gfx::FloatRect rect_in_coordinate_space(const Box& box, const Box& contex
|
||||||
for (auto* ancestor = box.parent(); ancestor; ancestor = ancestor->parent()) {
|
for (auto* ancestor = box.parent(); ancestor; ancestor = ancestor->parent()) {
|
||||||
if (is<Box>(*ancestor)) {
|
if (is<Box>(*ancestor)) {
|
||||||
auto offset = downcast<Box>(*ancestor).effective_offset();
|
auto offset = downcast<Box>(*ancestor).effective_offset();
|
||||||
rect.move_by(offset);
|
rect.translate_by(offset);
|
||||||
}
|
}
|
||||||
if (ancestor == &context_box)
|
if (ancestor == &context_box)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -154,7 +154,7 @@ const Gfx::FloatRect Box::absolute_rect() const
|
||||||
{
|
{
|
||||||
Gfx::FloatRect rect { effective_offset(), size() };
|
Gfx::FloatRect rect { effective_offset(), size() };
|
||||||
for (auto* block = containing_block(); block; block = block->containing_block()) {
|
for (auto* block = containing_block(); block; block = block->containing_block()) {
|
||||||
rect.move_by(block->effective_offset());
|
rect.translate_by(block->effective_offset());
|
||||||
}
|
}
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ void ButtonBox::paint(PaintContext& context, PaintPhase phase)
|
||||||
|
|
||||||
auto text_rect = enclosing_int_rect(absolute_rect());
|
auto text_rect = enclosing_int_rect(absolute_rect());
|
||||||
if (m_being_pressed)
|
if (m_being_pressed)
|
||||||
text_rect.move_by(1, 1);
|
text_rect.translate_by(1, 1);
|
||||||
context.painter().draw_text(text_rect, dom_node().value(), font(), Gfx::TextAlignment::Center, context.palette().button_text());
|
context.painter().draw_text(text_rect, dom_node().value(), font(), Gfx::TextAlignment::Center, context.palette().button_text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ void FrameBox::paint(PaintContext& context, PaintPhase phase)
|
||||||
|
|
||||||
if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) {
|
if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) {
|
||||||
if (dom_node().content_frame()->is_focused_frame()) {
|
if (dom_node().content_frame()->is_focused_frame()) {
|
||||||
context.painter().draw_rect(absolute_rect().to<int>(), Color::Cyan);
|
context.painter().draw_rect(absolute_rect().to_type<int>(), Color::Cyan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ bool ImageBox::renders_as_alt_text() const
|
||||||
|
|
||||||
void ImageBox::frame_did_set_viewport_rect(const Gfx::IntRect& viewport_rect)
|
void ImageBox::frame_did_set_viewport_rect(const Gfx::IntRect& viewport_rect)
|
||||||
{
|
{
|
||||||
m_image_loader.set_visible_in_viewport(viewport_rect.to<float>().intersects(absolute_rect()));
|
m_image_loader.set_visible_in_viewport(viewport_rect.to_type<float>().intersects(absolute_rect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ void InlineFormattingContext::run(Box&, LayoutMode layout_mode)
|
||||||
// Shift subsequent sibling fragments to the right to adjust for change in width.
|
// Shift subsequent sibling fragments to the right to adjust for change in width.
|
||||||
for (size_t j = i + 1; j < line_box.fragments().size(); ++j) {
|
for (size_t j = i + 1; j < line_box.fragments().size(); ++j) {
|
||||||
auto offset = line_box.fragments()[j].offset();
|
auto offset = line_box.fragments()[j].offset();
|
||||||
offset.move_by(diff, 0);
|
offset.translate_by(diff, 0);
|
||||||
line_box.fragments()[j].set_offset(offset);
|
line_box.fragments()[j].set_offset(offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ const Gfx::FloatRect LineBoxFragment::absolute_rect() const
|
||||||
{
|
{
|
||||||
Gfx::FloatRect rect { {}, size() };
|
Gfx::FloatRect rect { {}, size() };
|
||||||
rect.set_location(m_layout_node.containing_block()->absolute_position());
|
rect.set_location(m_layout_node.containing_block()->absolute_position());
|
||||||
rect.move_by(offset());
|
rect.translate_by(offset());
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -319,7 +319,7 @@ bool Node::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned
|
||||||
if (!containing_block->is_scrollable())
|
if (!containing_block->is_scrollable())
|
||||||
return false;
|
return false;
|
||||||
auto new_offset = containing_block->scroll_offset();
|
auto new_offset = containing_block->scroll_offset();
|
||||||
new_offset.move_by(0, wheel_delta);
|
new_offset.translate_by(0, wheel_delta);
|
||||||
containing_block->set_scroll_offset(new_offset);
|
containing_block->set_scroll_offset(new_offset);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ void Frame::scroll_to_anchor(const String& fragment)
|
||||||
if (is<Layout::Box>(layout_node)) {
|
if (is<Layout::Box>(layout_node)) {
|
||||||
auto& layout_box = downcast<Layout::Box>(layout_node);
|
auto& layout_box = downcast<Layout::Box>(layout_node);
|
||||||
auto padding_box = layout_box.box_model().padding_box();
|
auto padding_box = layout_box.box_model().padding_box();
|
||||||
float_rect.move_by(-padding_box.left, -padding_box.top);
|
float_rect.translate_by(-padding_box.left, -padding_box.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_page)
|
if (m_page)
|
||||||
|
@ -206,7 +206,7 @@ Gfx::IntPoint Frame::to_main_frame_position(const Gfx::IntPoint& a_position)
|
||||||
return {};
|
return {};
|
||||||
if (!ancestor->host_element()->layout_node())
|
if (!ancestor->host_element()->layout_node())
|
||||||
return {};
|
return {};
|
||||||
position.move_by(ancestor->host_element()->layout_node()->box_type_agnostic_position().to_type<int>());
|
position.translate_by(ancestor->host_element()->layout_node()->box_type_agnostic_position().to_type<int>());
|
||||||
}
|
}
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,20 +72,20 @@ void paint_border(PaintContext& context, BorderEdge edge, const Gfx::FloatRect&
|
||||||
if (gfx_line_style != Gfx::Painter::LineStyle::Solid) {
|
if (gfx_line_style != Gfx::Painter::LineStyle::Solid) {
|
||||||
switch (edge) {
|
switch (edge) {
|
||||||
case BorderEdge::Top:
|
case BorderEdge::Top:
|
||||||
p1.move_by(int_width / 2, int_width / 2);
|
p1.translate_by(int_width / 2, int_width / 2);
|
||||||
p2.move_by(-int_width / 2, int_width / 2);
|
p2.translate_by(-int_width / 2, int_width / 2);
|
||||||
break;
|
break;
|
||||||
case BorderEdge::Right:
|
case BorderEdge::Right:
|
||||||
p1.move_by(-int_width / 2, int_width / 2);
|
p1.translate_by(-int_width / 2, int_width / 2);
|
||||||
p2.move_by(-int_width / 2, -int_width / 2);
|
p2.translate_by(-int_width / 2, -int_width / 2);
|
||||||
break;
|
break;
|
||||||
case BorderEdge::Bottom:
|
case BorderEdge::Bottom:
|
||||||
p1.move_by(int_width / 2, -int_width / 2);
|
p1.translate_by(int_width / 2, -int_width / 2);
|
||||||
p2.move_by(-int_width / 2, -int_width / 2);
|
p2.translate_by(-int_width / 2, -int_width / 2);
|
||||||
break;
|
break;
|
||||||
case BorderEdge::Left:
|
case BorderEdge::Left:
|
||||||
p1.move_by(int_width / 2, int_width / 2);
|
p1.translate_by(int_width / 2, int_width / 2);
|
||||||
p2.move_by(int_width / 2, -int_width / 2);
|
p2.translate_by(int_width / 2, -int_width / 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
context.painter().draw_line({ (int)p1.x(), (int)p1.y() }, { (int)p2.x(), (int)p2.y() }, color, int_width, gfx_line_style);
|
context.painter().draw_line({ (int)p1.x(), (int)p1.y() }, { (int)p2.x(), (int)p2.y() }, color, int_width, gfx_line_style);
|
||||||
|
@ -105,8 +105,8 @@ void paint_border(PaintContext& context, BorderEdge edge, const Gfx::FloatRect&
|
||||||
p2_step = style.border_right().width / (float)int_width;
|
p2_step = style.border_right().width / (float)int_width;
|
||||||
for (int i = 0; i < int_width; ++i) {
|
for (int i = 0; i < int_width; ++i) {
|
||||||
draw_line(p1, p2);
|
draw_line(p1, p2);
|
||||||
p1.move_by(p1_step, 1);
|
p1.translate_by(p1_step, 1);
|
||||||
p2.move_by(-p2_step, 1);
|
p2.translate_by(-p2_step, 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BorderEdge::Right:
|
case BorderEdge::Right:
|
||||||
|
@ -114,8 +114,8 @@ void paint_border(PaintContext& context, BorderEdge edge, const Gfx::FloatRect&
|
||||||
p2_step = style.border_bottom().width / (float)int_width;
|
p2_step = style.border_bottom().width / (float)int_width;
|
||||||
for (int i = int_width - 1; i >= 0; --i) {
|
for (int i = int_width - 1; i >= 0; --i) {
|
||||||
draw_line(p1, p2);
|
draw_line(p1, p2);
|
||||||
p1.move_by(-1, p1_step);
|
p1.translate_by(-1, p1_step);
|
||||||
p2.move_by(-1, -p2_step);
|
p2.translate_by(-1, -p2_step);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BorderEdge::Bottom:
|
case BorderEdge::Bottom:
|
||||||
|
@ -123,8 +123,8 @@ void paint_border(PaintContext& context, BorderEdge edge, const Gfx::FloatRect&
|
||||||
p2_step = style.border_right().width / (float)int_width;
|
p2_step = style.border_right().width / (float)int_width;
|
||||||
for (int i = int_width - 1; i >= 0; --i) {
|
for (int i = int_width - 1; i >= 0; --i) {
|
||||||
draw_line(p1, p2);
|
draw_line(p1, p2);
|
||||||
p1.move_by(p1_step, -1);
|
p1.translate_by(p1_step, -1);
|
||||||
p2.move_by(-p2_step, -1);
|
p2.translate_by(-p2_step, -1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BorderEdge::Left:
|
case BorderEdge::Left:
|
||||||
|
@ -132,8 +132,8 @@ void paint_border(PaintContext& context, BorderEdge edge, const Gfx::FloatRect&
|
||||||
p2_step = style.border_bottom().width / (float)int_width;
|
p2_step = style.border_bottom().width / (float)int_width;
|
||||||
for (int i = 0; i < int_width; ++i) {
|
for (int i = 0; i < int_width; ++i) {
|
||||||
draw_line(p1, p2);
|
draw_line(p1, p2);
|
||||||
p1.move_by(1, p1_step);
|
p1.translate_by(1, p1_step);
|
||||||
p2.move_by(1, -p2_step);
|
p2.translate_by(1, -p2_step);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ static void paint_custom_progressbar(GUI::Painter& painter, const Gfx::IntRect&
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::IntRect hole_rect { (int)progress_width, 0, (int)(rect.width() - progress_width), rect.height() };
|
Gfx::IntRect hole_rect { (int)progress_width, 0, (int)(rect.width() - progress_width), rect.height() };
|
||||||
hole_rect.move_by(rect.location());
|
hole_rect.translate_by(rect.location());
|
||||||
hole_rect.set_right_without_resize(rect.right());
|
hole_rect.set_right_without_resize(rect.right());
|
||||||
Gfx::PainterStateSaver saver(painter);
|
Gfx::PainterStateSaver saver(painter);
|
||||||
painter.add_clip_rect(hole_rect);
|
painter.add_clip_rect(hole_rect);
|
||||||
|
@ -109,7 +109,7 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
|
||||||
icon_location.set_x(content_rect.x());
|
icon_location.set_x(content_rect.x());
|
||||||
|
|
||||||
if (!text().is_empty()) {
|
if (!text().is_empty()) {
|
||||||
content_rect.move_by(icon.width() + 4, 0);
|
content_rect.translate_by(icon.width() + 4, 0);
|
||||||
content_rect.set_width(content_rect.width() - icon.width() - 4);
|
content_rect.set_width(content_rect.width() - icon.width() - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,8 +119,8 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
|
||||||
text_rect.align_within(content_rect, text_alignment());
|
text_rect.align_within(content_rect, text_alignment());
|
||||||
|
|
||||||
if (is_being_pressed() || is_checked()) {
|
if (is_being_pressed() || is_checked()) {
|
||||||
text_rect.move_by(1, 1);
|
text_rect.translate_by(1, 1);
|
||||||
icon_location.move_by(1, 1);
|
icon_location.translate_by(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.progress().has_value()) {
|
if (window.progress().has_value()) {
|
||||||
|
|
|
@ -138,7 +138,7 @@ void Compositor::compose()
|
||||||
auto invalidate_rect = dirty_rect.intersected(frame_rect);
|
auto invalidate_rect = dirty_rect.intersected(frame_rect);
|
||||||
if (!invalidate_rect.is_empty()) {
|
if (!invalidate_rect.is_empty()) {
|
||||||
auto inner_rect_offset = window.rect().location() - frame_rect.location();
|
auto inner_rect_offset = window.rect().location() - frame_rect.location();
|
||||||
invalidate_rect.move_by(-(frame_rect.location() + inner_rect_offset));
|
invalidate_rect.translate_by(-(frame_rect.location() + inner_rect_offset));
|
||||||
window.invalidate_no_notify(invalidate_rect);
|
window.invalidate_no_notify(invalidate_rect);
|
||||||
m_invalidated_window = true;
|
m_invalidated_window = true;
|
||||||
}
|
}
|
||||||
|
@ -449,7 +449,7 @@ void Compositor::compose()
|
||||||
if (!wm.dnd_text().is_empty()) {
|
if (!wm.dnd_text().is_empty()) {
|
||||||
auto text_rect = dnd_rect;
|
auto text_rect = dnd_rect;
|
||||||
if (wm.dnd_bitmap())
|
if (wm.dnd_bitmap())
|
||||||
text_rect.move_by(wm.dnd_bitmap()->width() + 8, 0);
|
text_rect.translate_by(wm.dnd_bitmap()->width() + 8, 0);
|
||||||
back_painter.draw_text(text_rect, wm.dnd_text(), Gfx::TextAlignment::CenterLeft, wm.palette().selection_text());
|
back_painter.draw_text(text_rect, wm.dnd_text(), Gfx::TextAlignment::CenterLeft, wm.palette().selection_text());
|
||||||
}
|
}
|
||||||
if (wm.dnd_bitmap()) {
|
if (wm.dnd_bitmap()) {
|
||||||
|
|
|
@ -133,7 +133,7 @@ Window& Menu::ensure_menu_window()
|
||||||
else if (item.type() == MenuItem::Separator)
|
else if (item.type() == MenuItem::Separator)
|
||||||
height = 8;
|
height = 8;
|
||||||
item.set_rect({ next_item_location, { width - frame_thickness() * 2, height } });
|
item.set_rect({ next_item_location, { width - frame_thickness() * 2, height } });
|
||||||
next_item_location.move_by(0, height);
|
next_item_location.translate_by(0, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
int window_height_available = Screen::the().height() - frame_thickness() * 2;
|
int window_height_available = Screen::the().height() - frame_thickness() * 2;
|
||||||
|
@ -236,7 +236,7 @@ void Menu::draw()
|
||||||
painter.blit_filtered(icon_rect.location().translated(1, 1), *item.icon(), item.icon()->rect(), [&shadow_color](auto) {
|
painter.blit_filtered(icon_rect.location().translated(1, 1), *item.icon(), item.icon()->rect(), [&shadow_color](auto) {
|
||||||
return shadow_color;
|
return shadow_color;
|
||||||
});
|
});
|
||||||
icon_rect.move_by(-1, -1);
|
icon_rect.translate_by(-1, -1);
|
||||||
}
|
}
|
||||||
if (item.is_enabled())
|
if (item.is_enabled())
|
||||||
painter.blit(icon_rect.location(), *item.icon(), item.icon()->rect());
|
painter.blit(icon_rect.location(), *item.icon(), item.icon()->rect());
|
||||||
|
|
|
@ -123,7 +123,7 @@ void Screen::on_receive_mouse_data(const MousePacket& packet)
|
||||||
{
|
{
|
||||||
auto prev_location = m_physical_cursor_location / m_scale_factor;
|
auto prev_location = m_physical_cursor_location / m_scale_factor;
|
||||||
if (packet.is_relative) {
|
if (packet.is_relative) {
|
||||||
m_physical_cursor_location.move_by(packet.x * m_acceleration_factor, packet.y * m_acceleration_factor);
|
m_physical_cursor_location.translate_by(packet.x * m_acceleration_factor, packet.y * m_acceleration_factor);
|
||||||
dbgln_if(WSSCREEN_DEBUG, "Screen: New Relative mouse point @ {}", m_physical_cursor_location);
|
dbgln_if(WSSCREEN_DEBUG, "Screen: New Relative mouse point @ {}", m_physical_cursor_location);
|
||||||
} else {
|
} else {
|
||||||
m_physical_cursor_location = { packet.x * physical_width() / 0xffff, packet.y * physical_height() / 0xffff };
|
m_physical_cursor_location = { packet.x * physical_width() / 0xffff, packet.y * physical_height() / 0xffff };
|
||||||
|
|
|
@ -541,7 +541,7 @@ bool Window::invalidate_no_notify(const Gfx::IntRect& rect, bool with_frame)
|
||||||
|
|
||||||
auto outer_rect = frame().render_rect();
|
auto outer_rect = frame().render_rect();
|
||||||
auto inner_rect = rect;
|
auto inner_rect = rect;
|
||||||
inner_rect.move_by(position());
|
inner_rect.translate_by(position());
|
||||||
// FIXME: This seems slightly wrong; the inner rect shouldn't intersect the border part of the outer rect.
|
// FIXME: This seems slightly wrong; the inner rect shouldn't intersect the border part of the outer rect.
|
||||||
inner_rect.intersect(outer_rect);
|
inner_rect.intersect(outer_rect);
|
||||||
if (inner_rect.is_empty())
|
if (inner_rect.is_empty())
|
||||||
|
@ -976,7 +976,7 @@ void Window::set_menubar(Menubar* menubar)
|
||||||
m_menubar->for_each_menu([&](Menu& menu) {
|
m_menubar->for_each_menu([&](Menu& menu) {
|
||||||
int text_width = wm.font().width(Gfx::parse_ampersand_string(menu.name()));
|
int text_width = wm.font().width(Gfx::parse_ampersand_string(menu.name()));
|
||||||
menu.set_rect_in_window_menubar({ next_menu_location.x(), 0, text_width + menubar_menu_margin, menubar_rect.height() });
|
menu.set_rect_in_window_menubar({ next_menu_location.x(), 0, text_width + menubar_menu_margin, menubar_rect.height() });
|
||||||
next_menu_location.move_by(menu.rect_in_window_menubar().width(), 0);
|
next_menu_location.translate_by(menu.rect_in_window_menubar().width(), 0);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,7 +301,7 @@ void WindowFrame::paint_menubar(Gfx::Painter& painter)
|
||||||
auto text_rect = menu.rect_in_window_menubar();
|
auto text_rect = menu.rect_in_window_menubar();
|
||||||
Color text_color = palette.window_text();
|
Color text_color = palette.window_text();
|
||||||
if (MenuManager::the().is_open(menu))
|
if (MenuManager::the().is_open(menu))
|
||||||
text_rect.move_by(1, 1);
|
text_rect.translate_by(1, 1);
|
||||||
bool paint_as_pressed = MenuManager::the().is_open(menu);
|
bool paint_as_pressed = MenuManager::the().is_open(menu);
|
||||||
bool paint_as_hovered = !paint_as_pressed && &menu == MenuManager::the().hovered_menu();
|
bool paint_as_hovered = !paint_as_pressed && &menu == MenuManager::the().hovered_menu();
|
||||||
if (paint_as_pressed || paint_as_hovered) {
|
if (paint_as_pressed || paint_as_hovered) {
|
||||||
|
@ -546,7 +546,7 @@ void WindowFrame::invalidate(Gfx::IntRect relative_rect)
|
||||||
{
|
{
|
||||||
auto frame_rect = rect();
|
auto frame_rect = rect();
|
||||||
auto window_rect = m_window.rect();
|
auto window_rect = m_window.rect();
|
||||||
relative_rect.move_by(frame_rect.x() - window_rect.x(), frame_rect.y() - window_rect.y());
|
relative_rect.translate_by(frame_rect.x() - window_rect.x(), frame_rect.y() - window_rect.y());
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
m_window.invalidate(relative_rect, true);
|
m_window.invalidate(relative_rect, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue