LibGfx: Unpublish Gfx::Point from global namespace

This commit is contained in:
Andreas Kling 2020-02-06 13:08:32 +01:00
parent 20cfd2a6bf
commit 9b87843af1
34 changed files with 51 additions and 53 deletions

View file

@ -47,7 +47,7 @@ static void flood_fill(Gfx::Bitmap& bitmap, const Gfx::Point& start_position, Co
if (target_color == fill_color)
return;
Queue<Point> queue;
Queue<Gfx::Point> queue;
queue.enqueue(start_position);
while (!queue.is_empty()) {
auto position = queue.dequeue();

View file

@ -31,7 +31,7 @@
#include <LibGUI/GPainter.h>
#include <LibM/math.h>
Point constrain_line_angle(const Gfx::Point& start_pos, const Gfx::Point& end_pos, float angle_increment)
static Gfx::Point constrain_line_angle(const Gfx::Point& start_pos, const Gfx::Point& end_pos, float angle_increment)
{
float current_angle = atan2(end_pos.y() - start_pos.y(), end_pos.x() - start_pos.x()) + M_PI * 2.;

View file

@ -63,7 +63,7 @@ void PenTool::on_mousemove(GUI::MouseEvent& event)
if (event.buttons() & GUI::MouseButton::Left || event.buttons() & GUI::MouseButton::Right) {
GUI::Painter painter(m_widget->bitmap());
if (m_last_drawing_event_position != Point(-1, -1))
if (m_last_drawing_event_position != Gfx::Point(-1, -1))
painter.draw_line(m_last_drawing_event_position, event.position(), m_widget->color_for(event), m_thickness);
else
painter.draw_line(event.position(), event.position(), m_widget->color_for(event), m_thickness);

View file

@ -102,8 +102,8 @@ void WaveWidget::paint_event(GUI::PaintEvent& event)
for (size_t x = 1; x < buffer.size(); ++x) {
int y = sample_to_y(buffer[x].left);
Point point1(prev_x * width_scale, prev_y);
Point point2(x * width_scale, y);
Gfx::Point point1(prev_x * width_scale, prev_y);
Gfx::Point point2(x * width_scale, y);
painter.draw_line(point1, point2, wave_color);
prev_x = x;

View file

@ -113,7 +113,7 @@ void QSWidget::mousewheel_event(GUI::MouseEvent& event)
relayout();
auto new_scale_factor = (float)m_scale / 100.0f;
auto scale_factor_change = new_scale_factor - old_scale_factor;
m_bitmap_rect.move_by(-Point((float)zoom_point.x() * scale_factor_change, (float)zoom_point.y() * scale_factor_change));
m_bitmap_rect.move_by(-Gfx::Point((float)zoom_point.x() * scale_factor_change, (float)zoom_point.y() * scale_factor_change));
if (old_scale != m_scale) {
if (on_scale_change)
on_scale_change(m_scale);

View file

@ -64,8 +64,8 @@ void SampleWidget::paint_event(GUI::PaintEvent& event)
++count;
if (count >= samples_per_pixel) {
Point min_point = { x, y_offset + static_cast<int>(-sample_max * frame_inner_rect().height() / 2) };
Point max_point = { x++, y_offset + static_cast<int>(sample_max * frame_inner_rect().height() / 2) };
Gfx::Point min_point = { x, y_offset + static_cast<int>(-sample_max * frame_inner_rect().height() / 2) };
Gfx::Point max_point = { x++, y_offset + static_cast<int>(sample_max * frame_inner_rect().height() / 2) };
painter.draw_line(min_point, max_point, Color::Green);
count = 0;

View file

@ -56,13 +56,13 @@ void GraphWidget::paint_event(GUI::PaintEvent& event)
auto inner_rect = frame_inner_rect();
float scale = (float)inner_rect.height() / (float)m_max;
Point prev_point;
Gfx::Point prev_point;
for (int i = 0; i < m_values.size(); ++i) {
int x = inner_rect.right() - (i * 2) + 1;
if (x < 0)
break;
float scaled_value = (float)m_values.at(m_values.size() - i - 1) * scale;
Point point = { x, inner_rect.bottom() - (int)scaled_value };
Gfx::Point point = { x, inner_rect.bottom() - (int)scaled_value };
if (i != 0)
painter.draw_line(prev_point, point, m_graph_color);
prev_point = point;

View file

@ -54,7 +54,7 @@ private:
Gfx::Rect rubber_band_rect() const;
Gfx::Point m_drag_origin;
HashMap<GUI::Widget*, Point> m_positions_before_drag;
HashMap<GUI::Widget*, Gfx::Point> m_positions_before_drag;
bool m_dragging { false };
bool m_rubber_banding { false };

View file

@ -90,7 +90,7 @@ void VBForm::insert_widget(VBWidgetType type)
{
auto* insertion_parent = single_selected_widget();
auto widget = VBWidget::create(type, *this, insertion_parent);
Point insertion_position = m_next_insertion_position;
Gfx::Point insertion_position = m_next_insertion_position;
if (insertion_parent)
insertion_position.move_by(insertion_parent->gwidget()->window_relative_rect().location());
widget->set_rect({ insertion_position, { m_grid_size * 10 + 1, m_grid_size * 5 + 1 } });

View file

@ -325,13 +325,13 @@ void Field::paint_event(GUI::PaintEvent& event)
painter.add_clip_rect(inner_rect);
for (int y = inner_rect.top() - 1; y <= inner_rect.bottom(); y += square_size()) {
Point a { inner_rect.left(), y };
Point b { inner_rect.right(), y };
Gfx::Point a { inner_rect.left(), y };
Gfx::Point b { inner_rect.right(), y };
painter.draw_line(a, b, Color::MidGray);
}
for (int x = frame_inner_rect().left() - 1; x <= frame_inner_rect().right(); x += square_size()) {
Point a { x, inner_rect.top() };
Point b { x, inner_rect.bottom() };
Gfx::Point a { x, inner_rect.top() };
Gfx::Point b { x, inner_rect.bottom() };
painter.draw_line(a, b, Color::MidGray);
}
}

View file

@ -545,7 +545,7 @@ Gfx::Rect AbstractTableView::row_rect(int item_index) const
return { 0, header_height() + (item_index * item_height()), max(content_size().width(), width()), item_height() };
}
Point AbstractTableView::adjusted_position(const Gfx::Point& position) const
Gfx::Point AbstractTableView::adjusted_position(const Gfx::Point& position) const
{
return position.translated(horizontal_scrollbar().value() - frame_thickness(), vertical_scrollbar().value() - frame_thickness());
}

View file

@ -62,7 +62,7 @@ public:
int horizontal_padding() const { return m_horizontal_padding; }
Point adjusted_position(const Gfx::Point&) const;
Gfx::Point adjusted_position(const Gfx::Point&) const;
virtual Gfx::Rect content_rect(const ModelIndex&) const override;
Gfx::Rect content_rect(int row, int column) const;

View file

@ -140,7 +140,7 @@ void Application::show_tooltip(const StringView& tooltip, const Gfx::Point& scre
Gfx::Rect desktop_rect = Desktop::the().rect();
const int margin = 30;
Point adjusted_pos = screen_location;
Gfx::Point adjusted_pos = screen_location;
if (adjusted_pos.x() + m_tooltip_window->width() >= desktop_rect.width() - margin) {
adjusted_pos = adjusted_pos.translated(-m_tooltip_window->width(), 0);
}

View file

@ -61,7 +61,7 @@ void Button::paint_event(PaintEvent& event)
return;
auto content_rect = rect().shrunken(8, 2);
auto icon_location = m_icon ? content_rect.center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)) : Point();
auto icon_location = m_icon ? content_rect.center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)) : Gfx::Point();
if (m_icon && !text().is_empty())
icon_location.set_x(content_rect.x());
if (is_being_pressed() || is_checked())

View file

@ -290,7 +290,7 @@ public:
{
}
Point position() const { return m_position; }
Gfx::Point position() const { return m_position; }
int x() const { return m_position.x(); }
int y() const { return m_position.y(); }
MouseButton button() const { return m_button; }

View file

@ -99,7 +99,7 @@ ModelIndex ListView::index_at_event_position(const Gfx::Point& point) const
return {};
}
Point ListView::adjusted_position(const Gfx::Point& position) const
Gfx::Point ListView::adjusted_position(const Gfx::Point& position) const
{
return position.translated(horizontal_scrollbar().value() - frame_thickness(), vertical_scrollbar().value() - frame_thickness());
}

View file

@ -51,7 +51,7 @@ public:
void scroll_into_view(const ModelIndex&, Orientation);
Point adjusted_position(const Gfx::Point&) const;
Gfx::Point adjusted_position(const Gfx::Point&) const;
virtual ModelIndex index_at_event_position(const Gfx::Point&) const override;
virtual Gfx::Rect content_rect(const ModelIndex&) const override;

View file

@ -209,7 +209,7 @@ Gfx::Rect ScrollableWidget::widget_inner_rect() const
return rect;
}
Point ScrollableWidget::to_content_position(const Gfx::Point& widget_position) const
Gfx::Point ScrollableWidget::to_content_position(const Gfx::Point& widget_position) const
{
auto content_position = widget_position;
content_position.move_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
@ -217,7 +217,7 @@ Point ScrollableWidget::to_content_position(const Gfx::Point& widget_position) c
return content_position;
}
Point ScrollableWidget::to_widget_position(const Gfx::Point& content_position) const
Gfx::Point ScrollableWidget::to_widget_position(const Gfx::Point& content_position) const
{
auto widget_position = content_position;
widget_position.move_by(-horizontal_scrollbar().value(), -vertical_scrollbar().value());

View file

@ -69,8 +69,8 @@ public:
void set_should_hide_unnecessary_scrollbars(bool b) { m_should_hide_unnecessary_scrollbars = b; }
bool should_hide_unnecessary_scrollbars() const { return m_should_hide_unnecessary_scrollbars; }
Point to_content_position(const Gfx::Point& widget_position) const;
Point to_widget_position(const Gfx::Point& content_position) const;
Gfx::Point to_content_position(const Gfx::Point& widget_position) const;
Gfx::Point to_widget_position(const Gfx::Point& content_position) const;
protected:
explicit ScrollableWidget(Widget* parent);

View file

@ -281,16 +281,16 @@ void TreeView::paint_event(PaintEvent& event)
for (int i = indent_level; i > 0; --i) {
auto parent_of_index_at_indent = index_at_indent.parent();
bool index_at_indent_is_last_in_parent = index_at_indent.row() == model.row_count(parent_of_index_at_indent) - 1;
Point a { tree_column_x_offset + horizontal_padding() + indent_width_in_pixels() * i - icon_size() / 2, rect.y() - 2 };
Point b { a.x(), a.y() + item_height() - 1 };
Gfx::Point a { tree_column_x_offset + horizontal_padding() + indent_width_in_pixels() * i - icon_size() / 2, rect.y() - 2 };
Gfx::Point b { a.x(), a.y() + item_height() - 1 };
if (index_at_indent_is_last_in_parent)
b.set_y(rect.center().y());
if (!(i != indent_level && index_at_indent_is_last_in_parent))
painter.draw_line(a, b, Color::MidGray);
if (i == indent_level) {
Point c { a.x(), rect.center().y() };
Point d { c.x() + icon_size() / 2, c.y() };
Gfx::Point c { a.x(), rect.center().y() };
Gfx::Point d { c.x() + icon_size() / 2, c.y() };
painter.draw_line(c, d, Color::MidGray);
}
index_at_indent = parent_of_index_at_indent;

View file

@ -184,7 +184,7 @@ public:
return m_value.as_float;
}
Point as_point() const
Gfx::Point as_point() const
{
return { m_value.as_point.x, m_value.as_point.y };
}

View file

@ -144,7 +144,7 @@ public:
virtual void second_paint_event(PaintEvent&);
Gfx::Rect relative_rect() const { return m_relative_rect; }
Point relative_position() const { return m_relative_rect.location(); }
Gfx::Point relative_position() const { return m_relative_rect.location(); }
Gfx::Rect window_relative_rect() const;
Gfx::Rect screen_relative_rect() const;
@ -170,7 +170,7 @@ public:
Yes };
struct HitTestResult {
Widget* widget { nullptr };
Point local_position;
Gfx::Point local_position;
};
HitTestResult hit_test(const Gfx::Point&, ShouldRespectGreediness = ShouldRespectGreediness::Yes);
Widget* child_at(const Gfx::Point&) const;

View file

@ -197,14 +197,14 @@ void Window::event(Core::Event& event)
auto& mouse_event = static_cast<MouseEvent&>(event);
if (m_global_cursor_tracking_widget) {
auto window_relative_rect = m_global_cursor_tracking_widget->window_relative_rect();
Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
Gfx::Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
auto local_event = make<MouseEvent>((Event::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta());
m_global_cursor_tracking_widget->dispatch_event(*local_event, this);
return;
}
if (m_automatic_cursor_tracking_widget) {
auto window_relative_rect = m_automatic_cursor_tracking_widget->window_relative_rect();
Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
Gfx::Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
auto local_event = make<MouseEvent>((Event::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers(), mouse_event.wheel_delta());
m_automatic_cursor_tracking_widget->dispatch_event(*local_event, this);
if (mouse_event.buttons() == 0)

View file

@ -106,7 +106,7 @@ public:
void set_rect(const Gfx::Rect&);
void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); }
Point position() const { return rect().location(); }
Gfx::Point position() const { return rect().location(); }
void move_to(int x, int y) { move_to({ x, y }); }
void move_to(const Gfx::Point& point) { set_rect({ point, size() }); }

View file

@ -162,5 +162,3 @@ inline const LogStream& operator<<(const LogStream& stream, const Point& value)
}
}
using Gfx::Point;

View file

@ -144,7 +144,7 @@ void WSCompositor::compose()
if (m_wallpaper_mode == WallpaperMode::Simple) {
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
} else if (m_wallpaper_mode == WallpaperMode::Center) {
Point offset { ws.size().width() / 2 - m_wallpaper->size().width() / 2,
Gfx::Point offset { ws.size().width() / 2 - m_wallpaper->size().width() / 2,
ws.size().height() / 2 - m_wallpaper->size().height() / 2 };
m_back_painter->blit_offset(dirty_rect.location(), *m_wallpaper,
dirty_rect, offset);

View file

@ -47,7 +47,7 @@ public:
static RefPtr<WSCursor> create(WSStandardCursor);
~WSCursor();
Point hotspot() const { return m_hotspot; }
Gfx::Point hotspot() const { return m_hotspot; }
const Gfx::Bitmap& bitmap() const { return *m_bitmap; }
Gfx::Rect rect() const { return m_bitmap->rect(); }

View file

@ -108,7 +108,7 @@ public:
{
}
Point position() const { return m_position; }
Gfx::Point position() const { return m_position; }
int x() const { return m_position.x(); }
int y() const { return m_position.y(); }
MouseButton button() const { return m_button; }

View file

@ -125,7 +125,7 @@ WSWindow& WSMenu::ensure_menu_window()
{
int width = this->content_width();
if (!m_menu_window) {
Point next_item_location(frame_thickness(), frame_thickness());
Gfx::Point next_item_location(frame_thickness(), frame_thickness());
for (auto& item : m_items) {
int height = 0;
if (item.type() == WSMenuItem::Text)
@ -249,8 +249,8 @@ void WSMenu::draw()
painter.draw_bitmap(submenu_arrow_rect.location(), submenu_arrow_bitmap, text_color);
}
} else if (item.type() == WSMenuItem::Separator) {
Point p1(item.rect().translated(stripe_rect.width() + 4, 0).x(), item.rect().center().y() - 1);
Point p2(width - 7, item.rect().center().y() - 1);
Gfx::Point p1(item.rect().translated(stripe_rect.width() + 4, 0).x(), item.rect().center().y() - 1);
Gfx::Point p2(width - 7, item.rect().center().y() - 1);
painter.draw_line(p1, p2, palette.threed_shadow1());
painter.draw_line(p1.translated(0, 1), p2.translated(0, 1), palette.threed_highlight());
}
@ -305,8 +305,8 @@ void WSMenu::handle_mouse_move_event(const WSMouseEvent& mouse_event)
if (hovered_item() && hovered_item()->is_submenu()) {
auto item = *hovered_item();
auto submenu_top_left = item.rect().location() + Point { item.rect().width(), 0 };
auto submenu_bottom_left = submenu_top_left + Point { 0, item.submenu()->menu_window()->height() };
auto submenu_top_left = item.rect().location() + Gfx::Point { item.rect().width(), 0 };
auto submenu_bottom_left = submenu_top_left + Gfx::Point { 0, item.submenu()->menu_window()->height() };
auto safe_hover_triangle = Gfx::Triangle { m_last_position_in_hover, submenu_top_left, submenu_bottom_left };
m_last_position_in_hover = mouse_event.position();
@ -510,7 +510,7 @@ void WSMenu::popup(const Gfx::Point& position, bool is_submenu)
redraw_if_theme_changed();
const int margin = 30;
Point adjusted_pos = position;
Gfx::Point adjusted_pos = position;
if (adjusted_pos.x() + window.width() >= WSScreen::the().width() - margin) {
adjusted_pos = adjusted_pos.translated(-window.width(), 0);

View file

@ -518,7 +518,7 @@ void WSMenuManager::set_current_menubar(WSMenuBar* menubar)
#ifdef DEBUG_MENUS
dbg() << "[WM] Current menubar is now " << menubar;
#endif
Point next_menu_location { WSMenuManager::menubar_menu_margin() / 2, 0 };
Gfx::Point next_menu_location { WSMenuManager::menubar_menu_margin() / 2, 0 };
int index = 0;
for_each_active_menubar_menu([&](WSMenu& menu) {
int text_width = index == 1 ? Gfx::Font::default_bold_font().width(menu.name()) : Gfx::Font::default_font().width(menu.name());

View file

@ -52,7 +52,7 @@ public:
Size size() const { return { width(), height() }; }
Gfx::Rect rect() const { return { 0, 0, width(), height() }; }
Point cursor_location() const { return m_cursor_location; }
Gfx::Point cursor_location() const { return m_cursor_location; }
unsigned mouse_button_state() const { return m_mouse_button_state; }
void on_receive_mouse_data(const MousePacket&);

View file

@ -155,7 +155,7 @@ public:
void move_to(const Gfx::Point& position) { set_rect({ position, size() }); }
void move_to(int x, int y) { move_to({ x, y }); }
Point position() const { return m_rect.location(); }
Gfx::Point position() const { return m_rect.location(); }
void set_position(const Gfx::Point& position) { set_rect({ position.x(), position.y(), width(), height() }); }
void set_position_without_repaint(const Gfx::Point& position) { set_rect_without_repaint({ position.x(), position.y(), width(), height() }); }

View file

@ -466,7 +466,7 @@ bool WSWindowManager::process_ongoing_window_move(WSMouseEvent& event, WSWindow*
m_move_window->set_tiled(WindowTileType::Right);
} else if (pixels_moved_from_start > 5 || m_move_window->tiled() == WindowTileType::None) {
m_move_window->set_tiled(WindowTileType::None);
Point pos = m_move_window_origin.translated(event.position() - m_move_origin);
Gfx::Point pos = m_move_window_origin.translated(event.position() - m_move_origin);
m_move_window->set_position_without_repaint(pos);
if (m_move_window->rect().contains(event.position()))
hovered_window = m_move_window;

View file

@ -239,7 +239,7 @@ private:
struct DoubleClickInfo {
struct ClickMetadata {
Core::ElapsedTimer clock;
Point last_position;
Gfx::Point last_position;
};
ClickMetadata& metadata_for_button(MouseButton);