mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-23 14:57:29 +00:00
Clean up UI type static_casts.
So disgusting, but not entirely gone yet...
This commit is contained in:
@@ -36,9 +36,7 @@ Rect Rect::intersect(const Rect& o) const {
|
||||
const auto y1 = std::max(top(), o.top());
|
||||
const auto y2 = std::min(bottom(), o.bottom());
|
||||
if( (x2 >= x1) && (y2 > y1) ) {
|
||||
return {
|
||||
x1, y1,
|
||||
static_cast<Dim>(x2 - x1), static_cast<Dim>(y2 - y1) };
|
||||
return { x1, y1, x2 - x1, y2 - y1 };
|
||||
} else {
|
||||
return { };
|
||||
}
|
||||
@@ -54,7 +52,7 @@ Rect& Rect::operator+=(const Rect& p) {
|
||||
pos = { x1, y1 };
|
||||
const auto x2 = std::max(right(), p.right());
|
||||
const auto y2 = std::max(bottom(), p.bottom());
|
||||
size = { static_cast<Dim>(x2 - x1), static_cast<Dim>(y2 - y1) };
|
||||
size = { x2 - x1, y2 - y1 };
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@@ -99,23 +99,23 @@ struct Point {
|
||||
}
|
||||
|
||||
constexpr Point(
|
||||
Coord x,
|
||||
Coord y
|
||||
) : x { x },
|
||||
y { y }
|
||||
int x,
|
||||
int y
|
||||
) : x { static_cast<Coord>(x) },
|
||||
y { static_cast<Coord>(y) }
|
||||
{
|
||||
}
|
||||
|
||||
Point operator-() const {
|
||||
return { static_cast<Coord>(-x), static_cast<Coord>(-y) };
|
||||
return { -x, -y };
|
||||
}
|
||||
|
||||
Point operator+(const Point& p) const {
|
||||
return { static_cast<Coord>(x + p.x), static_cast<Coord>(y + p.y) };
|
||||
return { x + p.x, y + p.y };
|
||||
}
|
||||
|
||||
Point operator-(const Point& p) const {
|
||||
return { static_cast<Coord>(x - p.x), static_cast<Coord>(y - p.y) };
|
||||
return { x - p.x, y - p.y };
|
||||
}
|
||||
|
||||
Point& operator+=(const Point& p) {
|
||||
@@ -155,10 +155,7 @@ private:
|
||||
/* Clockwise rotate (in screen coordinates), with a gain in
|
||||
* magnitude of sqrt(2).
|
||||
*/
|
||||
return {
|
||||
static_cast<Coord>(x - y),
|
||||
static_cast<Coord>(x + y)
|
||||
};
|
||||
return { x - y, x + y };
|
||||
}
|
||||
#endif
|
||||
};
|
||||
@@ -174,10 +171,10 @@ struct Size {
|
||||
}
|
||||
|
||||
constexpr Size(
|
||||
Dim w,
|
||||
Dim h
|
||||
) : w { w },
|
||||
h { h }
|
||||
int w,
|
||||
int h
|
||||
) : w { static_cast<Dim>(w) },
|
||||
h { static_cast<Dim>(h) }
|
||||
{
|
||||
}
|
||||
|
||||
@@ -197,8 +194,8 @@ struct Rect {
|
||||
}
|
||||
|
||||
constexpr Rect(
|
||||
Coord x, Coord y,
|
||||
Dim w, Dim h
|
||||
int x, int y,
|
||||
int w, int h
|
||||
) : pos { x, y },
|
||||
size { w, h }
|
||||
{
|
||||
@@ -237,10 +234,7 @@ struct Rect {
|
||||
}
|
||||
|
||||
Point center() const {
|
||||
return {
|
||||
static_cast<Coord>(pos.x + size.w / 2),
|
||||
static_cast<Coord>(pos.y + size.h / 2)
|
||||
};
|
||||
return { pos.x + size.w / 2, pos.y + size.h / 2 };
|
||||
}
|
||||
|
||||
bool is_empty() const {
|
||||
|
@@ -55,18 +55,18 @@ size_t Painter::draw_string(Point p, const Style& style, const std::string text)
|
||||
}
|
||||
|
||||
void Painter::draw_hline(Point p, size_t width, const Color c) {
|
||||
display.fill_rectangle({ p, { static_cast<Dim>(width), 1 } }, c);
|
||||
display.fill_rectangle({ p, { width, 1 } }, c);
|
||||
}
|
||||
|
||||
void Painter::draw_vline(Point p, size_t height, const Color c) {
|
||||
display.fill_rectangle({ p, { 1, static_cast<Dim>(height) } }, c);
|
||||
display.fill_rectangle({ p, { 1, height } }, c);
|
||||
}
|
||||
|
||||
void Painter::draw_rectangle(const Rect r, const Color c) {
|
||||
draw_hline(r.pos, r.size.w, c);
|
||||
draw_vline({ r.pos.x, static_cast<Coord>(r.pos.y + 1) }, r.size.h - 2, c);
|
||||
draw_vline({ static_cast<Coord>(r.pos.x + r.size.w - 1), static_cast<Coord>(r.pos.y + 1) }, r.size.h - 2, c);
|
||||
draw_hline({ r.pos.x, static_cast<Coord>(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) {
|
||||
|
@@ -326,19 +326,13 @@ void Button::paint(Painter& painter) {
|
||||
painter.draw_rectangle(r, style().foreground);
|
||||
|
||||
painter.fill_rectangle(
|
||||
{
|
||||
static_cast<Coord>(r.pos.x + 1), static_cast<Coord>(r.pos.y + 1),
|
||||
static_cast<Dim>(r.size.w - 2), static_cast<Dim>(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(
|
||||
{
|
||||
static_cast<Coord>(r.pos.x + (r.size.w - label_r.w) / 2),
|
||||
static_cast<Coord>(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