mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Hide ui::Point implementation.
This commit is contained in:
parent
606c1cebac
commit
aac2d31548
@ -155,7 +155,7 @@ public:
|
||||
const auto is_selected_key = (selected_key == entry.key());
|
||||
const auto item_style = (has_focus() && is_selected_key) ? s.invert() : s;
|
||||
draw(entry, target_rect, painter, item_style);
|
||||
target_rect.pos.y += target_rect.height();
|
||||
target_rect += { 0, target_rect.height() };
|
||||
}
|
||||
|
||||
painter.fill_rectangle(
|
||||
|
@ -128,12 +128,12 @@ struct Calibration {
|
||||
const std::array<DigitizerPoint, 3>& s,
|
||||
const std::array<ui::Point, 3>& d
|
||||
) : k { (s[0].x - s[2].x) * (s[1].y - s[2].y) - (s[1].x - s[2].x) * (s[0].y - s[2].y) },
|
||||
a { (d[0].x - d[2].x) * (s[1].y - s[2].y) - (d[1].x - d[2].x) * (s[0].y - s[2].y) },
|
||||
b { (s[0].x - s[2].x) * (d[1].x - d[2].x) - (d[0].x - d[2].x) * (s[1].x - s[2].x) },
|
||||
c { s[0].y * (s[2].x * d[1].x - s[1].x * d[2].x) + s[1].y * (s[0].x * d[2].x - s[2].x * d[0].x) + s[2].y * (s[1].x * d[0].x - s[0].x * d[1].x) },
|
||||
d { (d[0].y - d[2].y) * (s[1].y - s[2].y) - (d[1].y - d[2].y) * (s[0].y - s[2].y) },
|
||||
e { (s[0].x - s[2].x) * (d[1].y - d[2].y) - (d[0].y - d[2].y) * (s[1].x - s[2].x) },
|
||||
f { s[0].y * (s[2].x * d[1].y - s[1].x * d[2].y) + s[1].y * (s[0].x * d[2].y - s[2].x * d[0].y) + s[2].y * (s[1].x * d[0].y - s[0].x * d[1].y) }
|
||||
a { (d[0].x() - d[2].x()) * (s[1].y - s[2].y) - (d[1].x() - d[2].x()) * (s[0].y - s[2].y) },
|
||||
b { (s[0].x - s[2].x) * (d[1].x() - d[2].x()) - (d[0].x() - d[2].x()) * (s[1].x - s[2].x) },
|
||||
c { s[0].y * (s[2].x * d[1].x() - s[1].x * d[2].x()) + s[1].y * (s[0].x * d[2].x() - s[2].x * d[0].x()) + s[2].y * (s[1].x * d[0].x() - s[0].x * d[1].x()) },
|
||||
d { (d[0].y() - d[2].y()) * (s[1].y - s[2].y) - (d[1].y() - d[2].y()) * (s[0].y - s[2].y) },
|
||||
e { (s[0].x - s[2].x) * (d[1].y() - d[2].y()) - (d[0].y() - d[2].y()) * (s[1].x - s[2].x) },
|
||||
f { s[0].y * (s[2].x * d[1].y() - s[1].x * d[2].y()) + s[1].y * (s[0].x * d[2].y() - s[2].x * d[0].y()) + s[2].y * (s[1].x * d[0].y() - s[0].x * d[1].y()) }
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -45,15 +45,15 @@ void Console::write(const std::string& message) {
|
||||
} else {
|
||||
const auto glyph = font.glyph(c);
|
||||
const auto advance = glyph.advance();
|
||||
if( (pos.x + advance.x) > rect.width() ) {
|
||||
if( (pos.x() + advance.x()) > rect.width() ) {
|
||||
crlf();
|
||||
}
|
||||
const Point pos_glyph {
|
||||
rect.pos.x + pos.x,
|
||||
display.scroll_area_y(pos.y)
|
||||
rect.pos.x() + pos.x(),
|
||||
display.scroll_area_y(pos.y())
|
||||
};
|
||||
display.draw_glyph(pos_glyph, glyph, s.foreground, s.background);
|
||||
pos.x += advance.x;
|
||||
pos += { advance.x(), 0 };
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,14 +86,13 @@ void Console::crlf() {
|
||||
const Style& s = style();
|
||||
const auto sr = screen_rect();
|
||||
const auto line_height = s.font.line_height();
|
||||
pos.x = 0;
|
||||
pos.y += line_height;
|
||||
const int32_t y_excess = pos.y + line_height - sr.height();
|
||||
pos = { 0, pos.y() + line_height };
|
||||
const int32_t y_excess = pos.y() + line_height - sr.height();
|
||||
if( y_excess > 0 ) {
|
||||
display.scroll(-y_excess);
|
||||
pos.y -= y_excess;
|
||||
pos = { pos.x(), pos.y() - y_excess };
|
||||
|
||||
const Rect dirty { sr.left(), display.scroll_area_y(pos.y), sr.width(), line_height };
|
||||
const Rect dirty { sr.left(), display.scroll_area_y(pos.y()), sr.width(), line_height };
|
||||
display.fill_rectangle(dirty, s.background);
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ void MenuItemView::paint(Painter& painter) {
|
||||
);
|
||||
|
||||
painter.draw_string(
|
||||
{ r.pos.x + 8, r.pos.y + (r.size.h - font_height) / 2 },
|
||||
{ r.pos.x() + 8, r.pos.y() + (r.size.h - font_height) / 2 },
|
||||
paint_style,
|
||||
item.text
|
||||
);
|
||||
|
@ -92,8 +92,8 @@ void TouchCalibrationView::set_phase(const Phase value) {
|
||||
|
||||
uint32_t TouchCalibrationView::distance_squared(const Point& touch_point, const Image& target) {
|
||||
const auto target_point = target.screen_rect().center();
|
||||
const int32_t dx = target_point.x - touch_point.x;
|
||||
const int32_t dy = target_point.y - touch_point.y;
|
||||
const int32_t dx = target_point.x() - touch_point.x();
|
||||
const int32_t dy = target_point.y() - touch_point.y();
|
||||
const uint32_t dx2 = dx * dx;
|
||||
const uint32_t dy2 = dy * dy;
|
||||
return dx2 + dy2;
|
||||
|
@ -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_
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user