mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-25 07:19:28 -05:00
Clean up UI type static_casts.
So disgusting, but not entirely gone yet...
This commit is contained in:
parent
60b8b38652
commit
ce481c0b5a
@ -49,7 +49,7 @@ void Console::write(const std::string message) {
|
||||
crlf();
|
||||
}
|
||||
const Point pos_glyph {
|
||||
static_cast<Coord>(rect.pos.x + pos.x),
|
||||
rect.pos.x + pos.x,
|
||||
display.scroll_area_y(pos.y)
|
||||
};
|
||||
display.draw_glyph(pos_glyph, glyph, s.foreground, s.background);
|
||||
|
@ -172,7 +172,7 @@ void RegistersWidget::draw_legend(const Coord left, Painter& painter) {
|
||||
|
||||
for(size_t i=0; i<config.registers_count; i+=config.registers_per_row) {
|
||||
const Point offset {
|
||||
left, static_cast<Coord>((i / config.registers_per_row) * row_height)
|
||||
left, (i / config.registers_per_row) * row_height
|
||||
};
|
||||
|
||||
const auto text = to_string_hex(i, config.legend_length);
|
||||
@ -192,8 +192,8 @@ void RegistersWidget::draw_values(
|
||||
|
||||
for(size_t i=0; i<config.registers_count; i++) {
|
||||
const Point offset = {
|
||||
static_cast<Coord>(left + config.legend_width() + 8 + (i % config.registers_per_row) * (config.value_width() + 8)),
|
||||
static_cast<Coord>((i / config.registers_per_row) * row_height)
|
||||
left + config.legend_width() + 8 + (i % config.registers_per_row) * (config.value_width() + 8),
|
||||
(i / config.registers_per_row) * row_height
|
||||
};
|
||||
|
||||
const auto value = reader(i);
|
||||
@ -231,8 +231,8 @@ RegistersView::RegistersView(
|
||||
registers_widget.set_parent_rect({ 0, 48, 240, 192 });
|
||||
|
||||
text_title.set_parent_rect({
|
||||
static_cast<Coord>((240 - title.size() * 8) / 2), 16,
|
||||
static_cast<Dim>(title.size() * 8), 16
|
||||
(240 - title.size() * 8) / 2, 16,
|
||||
title.size() * 8, 16
|
||||
});
|
||||
text_title.set(title);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ void MenuItemView::paint(Painter& painter) {
|
||||
);
|
||||
|
||||
painter.draw_string(
|
||||
{ static_cast<Coord>(r.pos.x + 8), static_cast<Coord>(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
|
||||
);
|
||||
|
@ -167,8 +167,8 @@ FrequencyKeypadView::FrequencyKeypadView(
|
||||
};
|
||||
button.on_select = button_fn;
|
||||
button.set_parent_rect({
|
||||
static_cast<Coord>((n % 3) * button_w),
|
||||
static_cast<Coord>((n / 3) * button_h + button_h),
|
||||
(n % 3) * button_w,
|
||||
(n / 3) * button_h + button_h,
|
||||
button_w, button_h
|
||||
});
|
||||
button.set_text(label);
|
||||
|
@ -88,10 +88,7 @@ void FrequencyScale::clear_background(Painter& painter, const Rect r) {
|
||||
void FrequencyScale::draw_frequency_ticks(Painter& painter, const Rect r) {
|
||||
const auto x_center = r.width() / 2;
|
||||
|
||||
const Rect tick {
|
||||
static_cast<Coord>(r.left() + x_center), r.top(),
|
||||
1, r.height()
|
||||
};
|
||||
const Rect tick { r.left() + x_center, r.top(), 1, r.height() };
|
||||
painter.fill_rectangle(tick, Color::white());
|
||||
|
||||
constexpr uint32_t tick_count_max = 4;
|
||||
@ -117,15 +114,15 @@ void FrequencyScale::draw_frequency_ticks(Painter& painter, const Rect r) {
|
||||
(magnitude_n >= 3) ? "k" : "";
|
||||
const std::string label = to_string_dec_uint(tick_offset) + zero_pad + unit;
|
||||
|
||||
const Coord offset_low = static_cast<Coord>(r.left() + x_center - pixel_offset);
|
||||
const Coord offset_low = r.left() + x_center - pixel_offset;
|
||||
const Rect tick_low { offset_low, r.top(), 1, r.height() };
|
||||
painter.fill_rectangle(tick_low, Color::white());
|
||||
painter.draw_string({ static_cast<Coord>(offset_low + 2), r.top() }, style(), label );
|
||||
painter.draw_string({ offset_low + 2, r.top() }, style(), label );
|
||||
|
||||
const Coord offset_high = static_cast<Coord>(r.left() + x_center + pixel_offset);
|
||||
const Coord offset_high = r.left() + x_center + pixel_offset;
|
||||
const Rect tick_high { offset_high, r.top(), 1, r.height() };
|
||||
painter.fill_rectangle(tick_high, Color::white());
|
||||
painter.draw_string({ static_cast<Coord>(offset_high + 2), r.top() }, style(), label );
|
||||
painter.draw_string({ offset_high + 2, r.top() }, style(), label );
|
||||
|
||||
tick_offset += tick_interval;
|
||||
}
|
||||
@ -146,8 +143,8 @@ void FrequencyScale::draw_filter_ranges(Painter& painter, const Rect r) {
|
||||
const auto stop_x_hi = x_center + stop_offset;
|
||||
|
||||
const Rect r_stop_lo {
|
||||
static_cast<Coord>(r.left() + stop_x_lo), static_cast<Coord>(r.bottom() - filter_band_height),
|
||||
static_cast<Dim>(pass_x_lo - stop_x_lo), filter_band_height
|
||||
r.left() + stop_x_lo, r.bottom() - filter_band_height,
|
||||
pass_x_lo - stop_x_lo, filter_band_height
|
||||
};
|
||||
painter.fill_rectangle(
|
||||
r_stop_lo,
|
||||
@ -155,8 +152,8 @@ void FrequencyScale::draw_filter_ranges(Painter& painter, const Rect r) {
|
||||
);
|
||||
|
||||
const Rect r_stop_hi {
|
||||
static_cast<Coord>(r.left() + pass_x_hi), static_cast<Coord>(r.bottom() - filter_band_height),
|
||||
static_cast<Dim>(stop_x_hi - pass_x_hi), filter_band_height
|
||||
r.left() + pass_x_hi, r.bottom() - filter_band_height,
|
||||
stop_x_hi - pass_x_hi, filter_band_height
|
||||
};
|
||||
painter.fill_rectangle(
|
||||
r_stop_hi,
|
||||
@ -165,8 +162,8 @@ void FrequencyScale::draw_filter_ranges(Painter& painter, const Rect r) {
|
||||
}
|
||||
|
||||
const Rect r_pass {
|
||||
static_cast<Coord>(r.left() + pass_x_lo), static_cast<Coord>(r.bottom() - filter_band_height),
|
||||
static_cast<Dim>(pass_x_hi - pass_x_lo), filter_band_height
|
||||
r.left() + pass_x_lo, r.bottom() - filter_band_height,
|
||||
pass_x_hi - pass_x_lo, filter_band_height
|
||||
};
|
||||
painter.fill_rectangle(
|
||||
r_pass,
|
||||
@ -280,7 +277,7 @@ void WaterfallWidget::set_parent_rect(const Rect new_parent_rect) {
|
||||
waterfall_view.set_parent_rect({
|
||||
0, scale_height,
|
||||
new_parent_rect.width(),
|
||||
static_cast<Dim>(new_parent_rect.height() - scale_height)
|
||||
new_parent_rect.height() - scale_height
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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_
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user