mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-11 15:29:28 -05:00
Reduce use of unsigned integers when signed will do fine.
This commit is contained in:
parent
ce481c0b5a
commit
14f18d5cf7
@ -262,7 +262,7 @@ Rect AISRecentEntryDetailView::draw_field(
|
||||
const std::string& label,
|
||||
const std::string& value
|
||||
) {
|
||||
const size_t label_length_max = 4;
|
||||
const int label_length_max = 4;
|
||||
|
||||
painter.draw_string(Point { draw_rect.left(), draw_rect.top() }, style, label);
|
||||
|
||||
|
@ -67,8 +67,8 @@ void TemperatureWidget::paint(Painter& painter) {
|
||||
const Color color_foreground = Color::green();
|
||||
const Color color_reticle { 128, 128, 128 };
|
||||
|
||||
const Dim graph_width = logger.capacity() * bar_width;
|
||||
const Dim graph_height = rect.height() - 16;
|
||||
const auto graph_width = static_cast<int>(logger.capacity()) * bar_width;
|
||||
const Rect graph_rect {
|
||||
rect.left() + (rect.width() - graph_width) / 2, rect.top() + 8,
|
||||
graph_width, rect.height()
|
||||
@ -124,7 +124,7 @@ Coord TemperatureWidget::screen_y(
|
||||
const temperature_t temperature,
|
||||
const Rect& rect
|
||||
) const {
|
||||
const Coord y_raw = rect.bottom() - ((temperature - display_temp_min) * display_temp_scale);
|
||||
int y_raw = rect.bottom() - ((temperature - display_temp_min) * display_temp_scale);
|
||||
const auto y_limit = std::min(rect.bottom(), std::max(rect.top(), y_raw));
|
||||
return y_limit;
|
||||
}
|
||||
@ -170,7 +170,7 @@ void RegistersWidget::paint(Painter& painter) {
|
||||
void RegistersWidget::draw_legend(const Coord left, Painter& painter) {
|
||||
const auto pos = screen_pos();
|
||||
|
||||
for(size_t i=0; i<config.registers_count; i+=config.registers_per_row) {
|
||||
for(int i=0; i<config.registers_count; i+=config.registers_per_row) {
|
||||
const Point offset {
|
||||
left, (i / config.registers_per_row) * row_height
|
||||
};
|
||||
@ -190,7 +190,7 @@ void RegistersWidget::draw_values(
|
||||
) {
|
||||
const auto pos = screen_pos();
|
||||
|
||||
for(size_t i=0; i<config.registers_count; i++) {
|
||||
for(int i=0; i<config.registers_count; i++) {
|
||||
const Point offset = {
|
||||
left + config.legend_width() + 8 + (i % config.registers_per_row) * (config.value_width() + 8),
|
||||
(i / config.registers_per_row) * row_height
|
||||
@ -231,8 +231,8 @@ RegistersView::RegistersView(
|
||||
registers_widget.set_parent_rect({ 0, 48, 240, 192 });
|
||||
|
||||
text_title.set_parent_rect({
|
||||
(240 - title.size() * 8) / 2, 16,
|
||||
title.size() * 8, 16
|
||||
(240 - static_cast<int>(title.size()) * 8) / 2, 16,
|
||||
static_cast<int>(title.size()) * 8, 16
|
||||
});
|
||||
text_title.set(title);
|
||||
}
|
||||
|
@ -103,8 +103,8 @@ private:
|
||||
|
||||
static constexpr temperature_t display_temp_min = 0;
|
||||
static constexpr temperature_t display_temp_scale = 3;
|
||||
static constexpr Dim bar_width = 1;
|
||||
static constexpr size_t temp_len = 3;
|
||||
static constexpr int bar_width = 1;
|
||||
static constexpr int temp_len = 3;
|
||||
};
|
||||
|
||||
class TemperatureView : public View {
|
||||
@ -130,32 +130,32 @@ private:
|
||||
};
|
||||
|
||||
struct RegistersWidgetConfig {
|
||||
size_t registers_count;
|
||||
size_t legend_length;
|
||||
size_t value_length;
|
||||
size_t registers_per_row;
|
||||
int registers_count;
|
||||
int legend_length;
|
||||
int value_length;
|
||||
int registers_per_row;
|
||||
|
||||
constexpr Dim legend_width() const {
|
||||
constexpr int legend_width() const {
|
||||
return legend_length * 8;
|
||||
}
|
||||
|
||||
constexpr Dim value_width() const {
|
||||
constexpr int value_width() const {
|
||||
return value_length * 8;
|
||||
}
|
||||
|
||||
constexpr size_t registers_row_length() const {
|
||||
constexpr int registers_row_length() const {
|
||||
return (registers_per_row * (value_length + 1)) - 1;
|
||||
}
|
||||
|
||||
constexpr Dim registers_row_width() const {
|
||||
constexpr int registers_row_width() const {
|
||||
return registers_row_length() * 8;
|
||||
}
|
||||
|
||||
constexpr Dim row_width() const {
|
||||
constexpr int row_width() const {
|
||||
return legend_width() + 8 + registers_row_width();
|
||||
}
|
||||
|
||||
constexpr size_t rows() const {
|
||||
constexpr int rows() const {
|
||||
return registers_count / registers_per_row;
|
||||
}
|
||||
};
|
||||
@ -175,7 +175,7 @@ private:
|
||||
const RegistersWidgetConfig config;
|
||||
const std::function<uint32_t(const size_t register_number)> reader;
|
||||
|
||||
static constexpr Dim row_height = 16;
|
||||
static constexpr int row_height = 16;
|
||||
|
||||
void draw_legend(const Coord left, Painter& painter);
|
||||
void draw_values(const Coord left, Painter& painter);
|
||||
|
@ -159,7 +159,7 @@ FrequencyKeypadView::FrequencyKeypadView(
|
||||
|
||||
const char* const key_caps = "123456789<0.";
|
||||
|
||||
size_t n = 0;
|
||||
int n = 0;
|
||||
for(auto& button : buttons) {
|
||||
add_child(&button);
|
||||
const std::string label {
|
||||
|
@ -204,16 +204,16 @@ public:
|
||||
void set_value(const rf::Frequency new_value);
|
||||
|
||||
private:
|
||||
static constexpr size_t button_w = 240 / 3;
|
||||
static constexpr size_t button_h = 48;
|
||||
static constexpr int button_w = 240 / 3;
|
||||
static constexpr int button_h = 48;
|
||||
|
||||
static constexpr size_t mhz_digits = 4;
|
||||
static constexpr size_t submhz_digits = 4;
|
||||
static constexpr int mhz_digits = 4;
|
||||
static constexpr int submhz_digits = 4;
|
||||
|
||||
static constexpr size_t mhz_mod = pow(10, mhz_digits);
|
||||
static constexpr size_t submhz_base = pow(10, 6 - submhz_digits);
|
||||
//static constexpr size_t submhz_mod = pow(10, submhz_digits);
|
||||
static constexpr size_t text_digits = mhz_digits + 1 + submhz_digits;
|
||||
static constexpr int mhz_mod = pow(10, mhz_digits);
|
||||
static constexpr int submhz_base = pow(10, 6 - submhz_digits);
|
||||
//static constexpr int submhz_mod = pow(10, submhz_digits);
|
||||
static constexpr int text_digits = mhz_digits + 1 + submhz_digits;
|
||||
|
||||
Text text_value {
|
||||
{ 0, 0, text_digits * button_w, button_h }
|
||||
|
@ -43,7 +43,7 @@ void FrequencyScale::on_show() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void FrequencyScale::set_spectrum_sampling_rate(const uint32_t new_sampling_rate) {
|
||||
void FrequencyScale::set_spectrum_sampling_rate(const int new_sampling_rate) {
|
||||
if( (spectrum_sampling_rate != new_sampling_rate) ) {
|
||||
spectrum_sampling_rate = new_sampling_rate;
|
||||
set_dirty();
|
||||
@ -51,8 +51,8 @@ void FrequencyScale::set_spectrum_sampling_rate(const uint32_t new_sampling_rate
|
||||
}
|
||||
|
||||
void FrequencyScale::set_channel_filter(
|
||||
const uint32_t pass_frequency,
|
||||
const uint32_t stop_frequency
|
||||
const int pass_frequency,
|
||||
const int stop_frequency
|
||||
) {
|
||||
if( (channel_filter_pass_frequency != pass_frequency) ||
|
||||
(channel_filter_stop_frequency != stop_frequency) ) {
|
||||
@ -91,18 +91,18 @@ void FrequencyScale::draw_frequency_ticks(Painter& painter, const Rect r) {
|
||||
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;
|
||||
constexpr int tick_count_max = 4;
|
||||
float rough_tick_interval = float(spectrum_sampling_rate) / tick_count_max;
|
||||
size_t magnitude = 1;
|
||||
size_t magnitude_n = 0;
|
||||
int magnitude = 1;
|
||||
int magnitude_n = 0;
|
||||
while(rough_tick_interval >= 10.0f) {
|
||||
rough_tick_interval /= 10;
|
||||
magnitude *= 10;
|
||||
magnitude_n += 1;
|
||||
}
|
||||
const size_t tick_interval = std::ceil(rough_tick_interval);
|
||||
const int tick_interval = std::ceil(rough_tick_interval);
|
||||
|
||||
size_t tick_offset = tick_interval;
|
||||
auto tick_offset = tick_interval;
|
||||
while((tick_offset * magnitude) < spectrum_sampling_rate / 2) {
|
||||
const Dim pixel_offset = tick_offset * magnitude * spectrum_bins / spectrum_sampling_rate;
|
||||
|
||||
|
@ -37,18 +37,18 @@ class FrequencyScale : public Widget {
|
||||
public:
|
||||
void on_show() override;
|
||||
|
||||
void set_spectrum_sampling_rate(const uint32_t new_sampling_rate);
|
||||
void set_channel_filter(const uint32_t pass_frequency, const uint32_t stop_frequency);
|
||||
void set_spectrum_sampling_rate(const int new_sampling_rate);
|
||||
void set_channel_filter(const int pass_frequency, const int stop_frequency);
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
private:
|
||||
static constexpr Dim filter_band_height = 4;
|
||||
static constexpr int filter_band_height = 4;
|
||||
|
||||
uint32_t spectrum_sampling_rate { 0 };
|
||||
const size_t spectrum_bins = std::tuple_size<decltype(ChannelSpectrum::db)>::value;
|
||||
uint32_t channel_filter_pass_frequency { 0 };
|
||||
uint32_t channel_filter_stop_frequency { 0 };
|
||||
int spectrum_sampling_rate { 0 };
|
||||
const int spectrum_bins = std::tuple_size<decltype(ChannelSpectrum::db)>::value;
|
||||
int channel_filter_pass_frequency { 0 };
|
||||
int channel_filter_stop_frequency { 0 };
|
||||
|
||||
void clear();
|
||||
void clear_background(Painter& painter, const Rect r);
|
||||
|
@ -209,27 +209,28 @@ struct Rect {
|
||||
{
|
||||
}
|
||||
|
||||
Coord top() const {
|
||||
|
||||
int top() const {
|
||||
return pos.y;
|
||||
}
|
||||
|
||||
Coord bottom() const {
|
||||
int bottom() const {
|
||||
return pos.y + size.h;
|
||||
}
|
||||
|
||||
Coord left() const {
|
||||
int left() const {
|
||||
return pos.x;
|
||||
}
|
||||
|
||||
Coord right() const {
|
||||
int right() const {
|
||||
return pos.x + size.w;
|
||||
}
|
||||
|
||||
Dim width() const {
|
||||
int width() const {
|
||||
return size.w;
|
||||
}
|
||||
|
||||
Dim height() const {
|
||||
int height() const {
|
||||
return size.h;
|
||||
}
|
||||
|
||||
|
@ -36,13 +36,13 @@ Style Style::invert() const {
|
||||
};
|
||||
}
|
||||
|
||||
size_t Painter::draw_char(const Point p, const Style& style, const char c) {
|
||||
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;
|
||||
}
|
||||
|
||||
size_t Painter::draw_string(Point p, const Style& style, const std::string text) {
|
||||
int Painter::draw_string(Point p, const Style& style, const std::string text) {
|
||||
size_t width = 0;
|
||||
for(const auto c : text) {
|
||||
const auto glyph = style.font.glyph(c);
|
||||
@ -54,11 +54,11 @@ size_t Painter::draw_string(Point p, const Style& style, const std::string text)
|
||||
return width;
|
||||
}
|
||||
|
||||
void Painter::draw_hline(Point p, size_t width, const Color c) {
|
||||
void Painter::draw_hline(Point p, int width, const Color c) {
|
||||
display.fill_rectangle({ p, { width, 1 } }, c);
|
||||
}
|
||||
|
||||
void Painter::draw_vline(Point p, size_t height, const Color c) {
|
||||
void Painter::draw_vline(Point p, int height, const Color c) {
|
||||
display.fill_rectangle({ p, { 1, height } }, c);
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,9 @@ public:
|
||||
Painter(const Painter&) = delete;
|
||||
Painter(Painter&&) = delete;
|
||||
|
||||
size_t draw_char(const Point p, const Style& style, const char c);
|
||||
int draw_char(const Point p, const Style& style, const char c);
|
||||
|
||||
size_t draw_string(Point p, const Style& style, const std::string text);
|
||||
int draw_string(Point p, const Style& style, const std::string text);
|
||||
|
||||
void draw_rectangle(const Rect r, const Color c);
|
||||
void fill_rectangle(const Rect r, const Color c);
|
||||
@ -56,8 +56,8 @@ public:
|
||||
void paint_widget_tree(Widget* const w);
|
||||
|
||||
private:
|
||||
void draw_hline(Point p, size_t width, const Color c);
|
||||
void draw_vline(Point p, size_t height, const Color c);
|
||||
void draw_hline(Point p, int width, const Color c);
|
||||
void draw_vline(Point p, int height, const Color c);
|
||||
|
||||
void paint_widget(Widget* const w);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user