mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-02-27 10:11:26 -05:00
Remove a lot of static_cast<>s involving UI structs.
Also starting to get religion on using unsigned integers only when I want their wrapping/modulus behavior.
This commit is contained in:
parent
4c8550bb7d
commit
3f94591083
@ -161,7 +161,7 @@ void AnalogAudioView::on_hide() {
|
|||||||
void AnalogAudioView::set_parent_rect(const Rect new_parent_rect) {
|
void AnalogAudioView::set_parent_rect(const Rect new_parent_rect) {
|
||||||
View::set_parent_rect(new_parent_rect);
|
View::set_parent_rect(new_parent_rect);
|
||||||
|
|
||||||
const ui::Rect waterfall_rect { 0, header_height, new_parent_rect.width(), static_cast<ui::Dim>(new_parent_rect.height() - header_height) };
|
const ui::Rect waterfall_rect { 0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height };
|
||||||
waterfall.set_parent_rect(waterfall_rect);
|
waterfall.set_parent_rect(waterfall_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ void CaptureAppView::on_hide() {
|
|||||||
void CaptureAppView::set_parent_rect(const Rect new_parent_rect) {
|
void CaptureAppView::set_parent_rect(const Rect new_parent_rect) {
|
||||||
View::set_parent_rect(new_parent_rect);
|
View::set_parent_rect(new_parent_rect);
|
||||||
|
|
||||||
const ui::Rect waterfall_rect { 0, header_height, new_parent_rect.width(), static_cast<ui::Dim>(new_parent_rect.height() - header_height) };
|
const ui::Rect waterfall_rect { 0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height };
|
||||||
waterfall.set_parent_rect(waterfall_rect);
|
waterfall.set_parent_rect(waterfall_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,10 +73,7 @@ ui::Point Calibration::translate(const DigitizerPoint& p) const {
|
|||||||
const int32_t y = (d * p.x + e * p.y + f) / k;
|
const int32_t y = (d * p.x + e * p.y + f) / k;
|
||||||
const auto x_clipped = x_range.clip(x);
|
const auto x_clipped = x_range.clip(x);
|
||||||
const auto y_clipped = y_range.clip(y);
|
const auto y_clipped = y_range.clip(y);
|
||||||
return {
|
return { x_clipped, y_clipped };
|
||||||
static_cast<ui::Coord>(x_clipped),
|
|
||||||
static_cast<ui::Coord>(y_clipped)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Calibration default_calibration() {
|
const Calibration default_calibration() {
|
||||||
|
@ -38,37 +38,25 @@ void Audio::paint(Painter& painter) {
|
|||||||
const range_t<int> x_max_range { x_rms + 1, r.width() };
|
const range_t<int> x_max_range { x_rms + 1, r.width() };
|
||||||
const auto x_max = x_max_range.clip((max_db_ - db_min) * r.width() / db_delta);
|
const auto x_max = x_max_range.clip((max_db_ - db_min) * r.width() / db_delta);
|
||||||
|
|
||||||
const Rect r0 {
|
const Rect r0 { r.left(), r.top(), x_rms, r.height() };
|
||||||
static_cast<ui::Coord>(r.left()), r.top(),
|
|
||||||
static_cast<ui::Dim>(x_rms), r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r0,
|
r0,
|
||||||
Color::green()
|
Color::green()
|
||||||
);
|
);
|
||||||
|
|
||||||
const Rect r1 {
|
const Rect r1 { r.left() + x_rms, r.top(), 1, r.height() };
|
||||||
static_cast<ui::Coord>(r.left() + x_rms), r.top(),
|
|
||||||
1, r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r1,
|
r1,
|
||||||
Color::black()
|
Color::black()
|
||||||
);
|
);
|
||||||
|
|
||||||
const Rect r2 {
|
const Rect r2 { r.left() + x_rms + 1, r.top(), x_max - (x_rms + 1), r.height() };
|
||||||
static_cast<ui::Coord>(r.left() + x_rms + 1), r.top(),
|
|
||||||
static_cast<ui::Dim>(x_max - (x_rms + 1)), r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r2,
|
r2,
|
||||||
Color::red()
|
Color::red()
|
||||||
);
|
);
|
||||||
|
|
||||||
const Rect r3 {
|
const Rect r3 { r.left() + x_max, r.top(), r.width() - x_max, r.height() };
|
||||||
static_cast<ui::Coord>(r.left() + x_max), r.top(),
|
|
||||||
static_cast<ui::Dim>(r.width() - x_max), r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r3,
|
r3,
|
||||||
Color::black()
|
Color::black()
|
||||||
|
@ -36,28 +36,19 @@ void Channel::paint(Painter& painter) {
|
|||||||
const range_t<int> x_max_range { 0, r.width() - 1 };
|
const range_t<int> x_max_range { 0, r.width() - 1 };
|
||||||
const auto x_max = x_max_range.clip((max_db_ - db_min) * r.width() / db_delta);
|
const auto x_max = x_max_range.clip((max_db_ - db_min) * r.width() / db_delta);
|
||||||
|
|
||||||
const Rect r0 {
|
const Rect r0 { r.left(), r.top(), x_max, r.height() };
|
||||||
static_cast<ui::Coord>(r.left()), r.top(),
|
|
||||||
static_cast<ui::Dim>(x_max), r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r0,
|
r0,
|
||||||
Color::blue()
|
Color::blue()
|
||||||
);
|
);
|
||||||
|
|
||||||
const Rect r1 {
|
const Rect r1 { r.left() + x_max, r.top(), 1, r.height() };
|
||||||
static_cast<ui::Coord>(r.left() + x_max), r.top(),
|
|
||||||
1, r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r1,
|
r1,
|
||||||
Color::white()
|
Color::white()
|
||||||
);
|
);
|
||||||
|
|
||||||
const Rect r2 {
|
const Rect r2 { r.left() + x_max + 1, r.top(), r.width() - (x_max + 1), r.height() };
|
||||||
static_cast<ui::Coord>(r.left() + x_max + 1), r.top(),
|
|
||||||
static_cast<ui::Dim>(r.width() - (x_max + 1)), r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r2,
|
r2,
|
||||||
Color::black()
|
Color::black()
|
||||||
|
@ -82,13 +82,10 @@ void MenuView::add_items(std::initializer_list<MenuItem> items) {
|
|||||||
void MenuView::set_parent_rect(const Rect new_parent_rect) {
|
void MenuView::set_parent_rect(const Rect new_parent_rect) {
|
||||||
View::set_parent_rect(new_parent_rect);
|
View::set_parent_rect(new_parent_rect);
|
||||||
|
|
||||||
constexpr size_t item_height = 24;
|
constexpr int item_height = 24;
|
||||||
size_t i = 0;
|
int i = 0;
|
||||||
for(auto child : children_) {
|
for(auto child : children_) {
|
||||||
child->set_parent_rect({
|
child->set_parent_rect({ 0, i * item_height, size().width(), item_height });
|
||||||
{ 0, static_cast<ui::Coord>(i * item_height) },
|
|
||||||
{ size().width(), item_height }
|
|
||||||
});
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,10 +230,7 @@ SystemView::SystemView(
|
|||||||
};
|
};
|
||||||
|
|
||||||
add_child(&navigation_view);
|
add_child(&navigation_view);
|
||||||
navigation_view.set_parent_rect({
|
navigation_view.set_parent_rect({ 0, status_view_height, parent_rect.width(), parent_rect.height() - status_view_height });
|
||||||
{ 0, status_view_height },
|
|
||||||
{ parent_rect.width(), static_cast<ui::Dim>(parent_rect.height() - status_view_height) }
|
|
||||||
});
|
|
||||||
navigation_view.on_view_changed = [this](const View& new_view) {
|
navigation_view.on_view_changed = [this](const View& new_view) {
|
||||||
this->status_view.set_back_enabled(!this->navigation_view.is_top());
|
this->status_view.set_back_enabled(!this->navigation_view.is_top());
|
||||||
this->status_view.set_title(new_view.title());
|
this->status_view.set_title(new_view.title());
|
||||||
|
@ -44,46 +44,31 @@ void RSSI::paint(Painter& painter) {
|
|||||||
const range_t<int> x_max_range { x_avg + 1, r.width() };
|
const range_t<int> x_max_range { x_avg + 1, r.width() };
|
||||||
const auto x_max = x_max_range.clip((max_ - raw_min) * r.width() / raw_delta);
|
const auto x_max = x_max_range.clip((max_ - raw_min) * r.width() / raw_delta);
|
||||||
|
|
||||||
const Rect r0 {
|
const Rect r0 { r.left(), r.top(), x_min, r.height() };
|
||||||
static_cast<ui::Coord>(r.left()), r.top(),
|
|
||||||
static_cast<ui::Dim>(x_min), r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r0,
|
r0,
|
||||||
Color::blue()
|
Color::blue()
|
||||||
);
|
);
|
||||||
|
|
||||||
const Rect r1 {
|
const Rect r1 { r.left() + x_min, r.top(), x_avg - x_min, r.height() };
|
||||||
static_cast<ui::Coord>(r.left() + x_min), r.top(),
|
|
||||||
static_cast<ui::Dim>(x_avg - x_min), r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r1,
|
r1,
|
||||||
Color::red()
|
Color::red()
|
||||||
);
|
);
|
||||||
|
|
||||||
const Rect r2 {
|
const Rect r2 { r.left() + x_avg, r.top(), 1, r.height() };
|
||||||
static_cast<ui::Coord>(r.left() + x_avg), r.top(),
|
|
||||||
1, r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r2,
|
r2,
|
||||||
Color::white()
|
Color::white()
|
||||||
);
|
);
|
||||||
|
|
||||||
const Rect r3 {
|
const Rect r3 { r.left() + x_avg + 1, r.top(), x_max - (x_avg + 1), r.height() };
|
||||||
static_cast<ui::Coord>(r.left() + x_avg + 1), r.top(),
|
|
||||||
static_cast<ui::Dim>(x_max - (x_avg + 1)), r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r3,
|
r3,
|
||||||
Color::red()
|
Color::red()
|
||||||
);
|
);
|
||||||
|
|
||||||
const Rect r4 {
|
const Rect r4 { r.left() + x_max, r.top(), r.width() - x_max, r.height() };
|
||||||
static_cast<ui::Coord>(r.left() + x_max), r.top(),
|
|
||||||
static_cast<ui::Dim>(r.width() - x_max), r.height()
|
|
||||||
};
|
|
||||||
painter.fill_rectangle(
|
painter.fill_rectangle(
|
||||||
r4,
|
r4,
|
||||||
Color::black()
|
Color::black()
|
||||||
|
@ -291,10 +291,7 @@ void ILI9341::fill_circle(
|
|||||||
const uint32_t d2 = x2 + y2;
|
const uint32_t d2 = x2 + y2;
|
||||||
const bool inside = d2 < radius2;
|
const bool inside = d2 < radius2;
|
||||||
const auto color = inside ? foreground : background;
|
const auto color = inside ? foreground : background;
|
||||||
draw_pixel({
|
draw_pixel({ x + center.x(), y + center.y() }, color);
|
||||||
static_cast<ui::Coord>(x + center.x()),
|
|
||||||
static_cast<ui::Coord>(y + center.y())
|
|
||||||
}, color);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -523,9 +523,9 @@ bool ImageButton::on_touch(const TouchEvent event) {
|
|||||||
|
|
||||||
OptionsField::OptionsField(
|
OptionsField::OptionsField(
|
||||||
Point parent_pos,
|
Point parent_pos,
|
||||||
size_t length,
|
int length,
|
||||||
options_t options
|
options_t options
|
||||||
) : Widget { { parent_pos, { static_cast<ui::Dim>(8 * length), 16 } } },
|
) : Widget { { parent_pos, { 8 * length, 16 } } },
|
||||||
length_ { length },
|
length_ { length },
|
||||||
options { options }
|
options { options }
|
||||||
{
|
{
|
||||||
@ -594,11 +594,11 @@ bool OptionsField::on_touch(const TouchEvent event) {
|
|||||||
|
|
||||||
NumberField::NumberField(
|
NumberField::NumberField(
|
||||||
Point parent_pos,
|
Point parent_pos,
|
||||||
size_t length,
|
int length,
|
||||||
range_t range,
|
range_t range,
|
||||||
int32_t step,
|
int32_t step,
|
||||||
char fill_char
|
char fill_char
|
||||||
) : Widget { { parent_pos, { static_cast<ui::Dim>(8 * length), 16 } } },
|
) : Widget { { parent_pos, { 8 * length, 16 } } },
|
||||||
range { range },
|
range { range },
|
||||||
step { step },
|
step { step },
|
||||||
length_ { length },
|
length_ { length },
|
||||||
|
@ -273,7 +273,7 @@ public:
|
|||||||
std::function<void(size_t, value_t)> on_change { };
|
std::function<void(size_t, value_t)> on_change { };
|
||||||
std::function<void(void)> on_show_options { };
|
std::function<void(void)> on_show_options { };
|
||||||
|
|
||||||
OptionsField(Point parent_pos, size_t length, options_t options);
|
OptionsField(Point parent_pos, int length, options_t options);
|
||||||
|
|
||||||
size_t selected_index() const;
|
size_t selected_index() const;
|
||||||
void set_selected_index(const size_t new_index);
|
void set_selected_index(const size_t new_index);
|
||||||
@ -287,7 +287,7 @@ public:
|
|||||||
bool on_touch(const TouchEvent event) override;
|
bool on_touch(const TouchEvent event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const size_t length_;
|
const int length_;
|
||||||
options_t options;
|
options_t options;
|
||||||
size_t selected_index_ { 0 };
|
size_t selected_index_ { 0 };
|
||||||
};
|
};
|
||||||
@ -298,7 +298,7 @@ public:
|
|||||||
|
|
||||||
using range_t = std::pair<int32_t, int32_t>;
|
using range_t = std::pair<int32_t, int32_t>;
|
||||||
|
|
||||||
NumberField(Point parent_pos, size_t length, range_t range, int32_t step, char fill_char);
|
NumberField(Point parent_pos, int length, range_t range, int32_t step, char fill_char);
|
||||||
|
|
||||||
NumberField(const NumberField&) = delete;
|
NumberField(const NumberField&) = delete;
|
||||||
NumberField(NumberField&&) = delete;
|
NumberField(NumberField&&) = delete;
|
||||||
@ -314,7 +314,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
const range_t range;
|
const range_t range;
|
||||||
const int32_t step;
|
const int32_t step;
|
||||||
const size_t length_;
|
const int length_;
|
||||||
const char fill_char;
|
const char fill_char;
|
||||||
int32_t value_ { 0 };
|
int32_t value_ { 0 };
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user