mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-25 08:23:42 +00:00
Hide ui::Point implementation.
This commit is contained in:
@@ -196,8 +196,8 @@ void lcd_start_ram_write(
|
||||
const ui::Point p,
|
||||
const ui::Size s
|
||||
) {
|
||||
lcd_caset(p.x, p.x + s.w - 1);
|
||||
lcd_paset(p.y, p.y + s.h - 1);
|
||||
lcd_caset(p.x(), p.x() + s.w - 1);
|
||||
lcd_paset(p.y(), p.y() + s.h - 1);
|
||||
lcd_ramwr_start();
|
||||
}
|
||||
|
||||
@@ -205,8 +205,8 @@ void lcd_start_ram_read(
|
||||
const ui::Point p,
|
||||
const ui::Size s
|
||||
) {
|
||||
lcd_caset(p.x, p.x + s.w - 1);
|
||||
lcd_paset(p.y, p.y + s.h - 1);
|
||||
lcd_caset(p.x(), p.x() + s.w - 1);
|
||||
lcd_paset(p.y(), p.y() + s.h - 1);
|
||||
lcd_ramrd_start();
|
||||
}
|
||||
|
||||
@@ -292,8 +292,8 @@ void ILI9341::fill_circle(
|
||||
const bool inside = d2 < radius2;
|
||||
const auto color = inside ? foreground : background;
|
||||
draw_pixel({
|
||||
static_cast<ui::Coord>(x + center.x),
|
||||
static_cast<ui::Coord>(y + center.y)
|
||||
static_cast<ui::Coord>(x + center.x()),
|
||||
static_cast<ui::Coord>(y + center.y())
|
||||
}, color);
|
||||
}
|
||||
}
|
||||
|
@@ -26,8 +26,8 @@
|
||||
namespace ui {
|
||||
|
||||
bool Rect::contains(const Point p) const {
|
||||
return (p.x >= left()) && (p.y >= top()) &&
|
||||
(p.x < right()) && (p.y < bottom());
|
||||
return (p.x() >= left()) && (p.y() >= top()) &&
|
||||
(p.x() < right()) && (p.y() < bottom());
|
||||
}
|
||||
|
||||
Rect Rect::intersect(const Rect& o) const {
|
||||
@@ -64,4 +64,9 @@ Rect& Rect::operator+=(const Point& p) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Rect& Rect::operator-=(const Point& p) {
|
||||
pos -= p;
|
||||
return *this;
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
|
@@ -82,38 +82,54 @@ struct ColorRGB888 {
|
||||
};
|
||||
|
||||
struct Point {
|
||||
Coord x;
|
||||
Coord y;
|
||||
private:
|
||||
Coord _x;
|
||||
Coord _y;
|
||||
|
||||
public:
|
||||
constexpr Point(
|
||||
) : x { 0 },
|
||||
y { 0 }
|
||||
) : _x { 0 },
|
||||
_y { 0 }
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Point(
|
||||
int x,
|
||||
int y
|
||||
) : x { static_cast<Coord>(x) },
|
||||
y { static_cast<Coord>(y) }
|
||||
) : _x { static_cast<Coord>(x) },
|
||||
_y { static_cast<Coord>(y) }
|
||||
{
|
||||
}
|
||||
|
||||
Point operator-() const {
|
||||
return { -x, -y };
|
||||
constexpr int x() const {
|
||||
return _x;
|
||||
}
|
||||
|
||||
Point operator+(const Point& p) const {
|
||||
return { x + p.x, y + p.y };
|
||||
constexpr int y() const {
|
||||
return _y;
|
||||
}
|
||||
|
||||
Point operator-(const Point& p) const {
|
||||
return { x - p.x, y - p.y };
|
||||
constexpr Point operator-() const {
|
||||
return { -_x, -_y };
|
||||
}
|
||||
|
||||
constexpr Point operator+(const Point& p) const {
|
||||
return { _x + p._x, _y + p._y };
|
||||
}
|
||||
|
||||
constexpr Point operator-(const Point& p) const {
|
||||
return { _x - p._x, _y - p._y };
|
||||
}
|
||||
|
||||
Point& operator+=(const Point& p) {
|
||||
x += p.x;
|
||||
y += p.y;
|
||||
_x += p._x;
|
||||
_y += p._y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point& operator-=(const Point& p) {
|
||||
_x -= p._x;
|
||||
_y -= p._y;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
@@ -168,19 +184,19 @@ struct Rect {
|
||||
}
|
||||
|
||||
int top() const {
|
||||
return pos.y;
|
||||
return pos.y();
|
||||
}
|
||||
|
||||
int bottom() const {
|
||||
return pos.y + size.h;
|
||||
return pos.y() + size.h;
|
||||
}
|
||||
|
||||
int left() const {
|
||||
return pos.x;
|
||||
return pos.x();
|
||||
}
|
||||
|
||||
int right() const {
|
||||
return pos.x + size.w;
|
||||
return pos.x() + size.w;
|
||||
}
|
||||
|
||||
int width() const {
|
||||
@@ -192,7 +208,7 @@ struct Rect {
|
||||
}
|
||||
|
||||
Point center() const {
|
||||
return { pos.x + size.w / 2, pos.y + size.h / 2 };
|
||||
return { pos.x() + size.w / 2, pos.y() + size.h / 2 };
|
||||
}
|
||||
|
||||
bool is_empty() const {
|
||||
@@ -209,6 +225,7 @@ struct Rect {
|
||||
|
||||
Rect& operator+=(const Rect& p);
|
||||
Rect& operator+=(const Point& p);
|
||||
Rect& operator-=(const Point& p);
|
||||
|
||||
operator bool() const {
|
||||
return !size.is_empty();
|
||||
|
@@ -127,14 +127,14 @@ static int32_t rect_distances(
|
||||
switch(direction) {
|
||||
case KeyEvent::Right:
|
||||
case KeyEvent::Left:
|
||||
perpendicular_axis_start = rect_start.center().y;
|
||||
perpendicular_axis_end = rect_end.center().y;
|
||||
perpendicular_axis_start = rect_start.center().y();
|
||||
perpendicular_axis_end = rect_end.center().y();
|
||||
break;
|
||||
|
||||
case KeyEvent::Up:
|
||||
case KeyEvent::Down:
|
||||
perpendicular_axis_start = rect_start.center().x;
|
||||
perpendicular_axis_end = rect_end.center().x;
|
||||
perpendicular_axis_start = rect_start.center().x();
|
||||
perpendicular_axis_end = rect_end.center().x();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@@ -39,7 +39,7 @@ Style Style::invert() const {
|
||||
int Painter::draw_char(const Point p, const Style& style, const char c) {
|
||||
const auto glyph = style.font.glyph(c);
|
||||
display.draw_glyph(p, glyph, style.foreground, style.background);
|
||||
return glyph.advance().x;
|
||||
return glyph.advance().x();
|
||||
}
|
||||
|
||||
int Painter::draw_string(Point p, const Style& style, const std::string text) {
|
||||
@@ -49,7 +49,7 @@ int Painter::draw_string(Point p, const Style& style, const std::string text) {
|
||||
display.draw_glyph(p, glyph, style.foreground, style.background);
|
||||
const auto advance = glyph.advance();
|
||||
p += advance;
|
||||
width += advance.x;
|
||||
width += advance.x();
|
||||
}
|
||||
return width;
|
||||
}
|
||||
@@ -68,9 +68,9 @@ void Painter::draw_vline(Point p, int height, const Color c) {
|
||||
|
||||
void Painter::draw_rectangle(const Rect r, const Color c) {
|
||||
draw_hline(r.pos, r.size.w, c);
|
||||
draw_vline({ r.pos.x, r.pos.y + 1 }, r.size.h - 2, c);
|
||||
draw_vline({ r.pos.x + r.size.w - 1, r.pos.y + 1 }, r.size.h - 2, c);
|
||||
draw_hline({ r.pos.x, r.pos.y + r.size.h - 1 }, r.size.w, c);
|
||||
draw_vline({ r.pos.x(), r.pos.y() + 1 }, r.size.h - 2, c);
|
||||
draw_vline({ r.pos.x() + r.size.w - 1, r.pos.y() + 1 }, r.size.h - 2, c);
|
||||
draw_hline({ r.pos.x(), r.pos.y() + r.size.h - 1 }, r.size.w, c);
|
||||
}
|
||||
|
||||
void Painter::fill_rectangle(const Rect r, const Color c) {
|
||||
|
@@ -351,13 +351,13 @@ void Button::paint(Painter& painter) {
|
||||
painter.draw_rectangle(r, style().foreground);
|
||||
|
||||
painter.fill_rectangle(
|
||||
{ r.pos.x + 1, r.pos.y + 1, r.size.w - 2, r.size.h - 2 },
|
||||
{ r.pos.x() + 1, r.pos.y() + 1, r.size.w - 2, r.size.h - 2 },
|
||||
paint_style.background
|
||||
);
|
||||
|
||||
const auto label_r = paint_style.font.size_of(text_);
|
||||
painter.draw_string(
|
||||
{ r.pos.x + (r.size.w - label_r.w) / 2, r.pos.y + (r.size.h - label_r.h) / 2 },
|
||||
{ r.pos.x() + (r.size.w - label_r.w) / 2, r.pos.y() + (r.size.h - label_r.h) / 2 },
|
||||
paint_style,
|
||||
text_
|
||||
);
|
||||
|
Reference in New Issue
Block a user