diff --git a/firmware/application/ui_console.cpp b/firmware/application/ui_console.cpp index 48c0daeb..65482236 100644 --- a/firmware/application/ui_console.cpp +++ b/firmware/application/ui_console.cpp @@ -49,7 +49,7 @@ void Console::write(const std::string message) { crlf(); } const Point pos_glyph { - static_cast(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); diff --git a/firmware/application/ui_debug.cpp b/firmware/application/ui_debug.cpp index fff640c9..7b91f8df 100644 --- a/firmware/application/ui_debug.cpp +++ b/firmware/application/ui_debug.cpp @@ -172,7 +172,7 @@ void RegistersWidget::draw_legend(const Coord left, Painter& painter) { for(size_t i=0; i((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(left + config.legend_width() + 8 + (i % config.registers_per_row) * (config.value_width() + 8)), - static_cast((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((240 - title.size() * 8) / 2), 16, - static_cast(title.size() * 8), 16 + (240 - title.size() * 8) / 2, 16, + title.size() * 8, 16 }); text_title.set(title); } diff --git a/firmware/application/ui_menu.cpp b/firmware/application/ui_menu.cpp index 45468c2d..7aa098d3 100644 --- a/firmware/application/ui_menu.cpp +++ b/firmware/application/ui_menu.cpp @@ -52,7 +52,7 @@ void MenuItemView::paint(Painter& painter) { ); painter.draw_string( - { static_cast(r.pos.x + 8), static_cast(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 ); diff --git a/firmware/application/ui_receiver.cpp b/firmware/application/ui_receiver.cpp index e281a88b..f9b9f9b4 100644 --- a/firmware/application/ui_receiver.cpp +++ b/firmware/application/ui_receiver.cpp @@ -167,8 +167,8 @@ FrequencyKeypadView::FrequencyKeypadView( }; button.on_select = button_fn; button.set_parent_rect({ - static_cast((n % 3) * button_w), - static_cast((n / 3) * button_h + button_h), + (n % 3) * button_w, + (n / 3) * button_h + button_h, button_w, button_h }); button.set_text(label); diff --git a/firmware/application/ui_spectrum.cpp b/firmware/application/ui_spectrum.cpp index addd2079..4204e37a 100644 --- a/firmware/application/ui_spectrum.cpp +++ b/firmware/application/ui_spectrum.cpp @@ -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(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(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(offset_low + 2), r.top() }, style(), label ); + painter.draw_string({ offset_low + 2, r.top() }, style(), label ); - const Coord offset_high = static_cast(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(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(r.left() + stop_x_lo), static_cast(r.bottom() - filter_band_height), - static_cast(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(r.left() + pass_x_hi), static_cast(r.bottom() - filter_band_height), - static_cast(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(r.left() + pass_x_lo), static_cast(r.bottom() - filter_band_height), - static_cast(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(new_parent_rect.height() - scale_height) + new_parent_rect.height() - scale_height }); } diff --git a/firmware/common/ui.cpp b/firmware/common/ui.cpp index e85c07c9..4fd40088 100644 --- a/firmware/common/ui.cpp +++ b/firmware/common/ui.cpp @@ -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(x2 - x1), static_cast(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(x2 - x1), static_cast(y2 - y1) }; + size = { x2 - x1, y2 - y1 }; } return *this; } diff --git a/firmware/common/ui.hpp b/firmware/common/ui.hpp index 554b1f36..cf62d137 100644 --- a/firmware/common/ui.hpp +++ b/firmware/common/ui.hpp @@ -99,23 +99,23 @@ struct Point { } constexpr Point( - Coord x, - Coord y - ) : x { x }, - y { y } + int x, + int y + ) : x { static_cast(x) }, + y { static_cast(y) } { } Point operator-() const { - return { static_cast(-x), static_cast(-y) }; + return { -x, -y }; } Point operator+(const Point& p) const { - return { static_cast(x + p.x), static_cast(y + p.y) }; + return { x + p.x, y + p.y }; } Point operator-(const Point& p) const { - return { static_cast(x - p.x), static_cast(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(x - y), - static_cast(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(w) }, + h { static_cast(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(pos.x + size.w / 2), - static_cast(pos.y + size.h / 2) - }; + return { pos.x + size.w / 2, pos.y + size.h / 2 }; } bool is_empty() const { diff --git a/firmware/common/ui_painter.cpp b/firmware/common/ui_painter.cpp index 1f772fa1..3dbcf89b 100644 --- a/firmware/common/ui_painter.cpp +++ b/firmware/common/ui_painter.cpp @@ -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(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(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(r.pos.y + 1) }, r.size.h - 2, c); - draw_vline({ static_cast(r.pos.x + r.size.w - 1), static_cast(r.pos.y + 1) }, r.size.h - 2, c); - draw_hline({ r.pos.x, static_cast(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) { diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index 7732a502..8564514e 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -326,19 +326,13 @@ void Button::paint(Painter& painter) { painter.draw_rectangle(r, style().foreground); painter.fill_rectangle( - { - static_cast(r.pos.x + 1), static_cast(r.pos.y + 1), - static_cast(r.size.w - 2), static_cast(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(r.pos.x + (r.size.w - label_r.w) / 2), - static_cast(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_ );