mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-04-22 17:31:32 +00:00
Touch on waterfall to set cursor pos (#2624)
* init * fix typo that found by Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
f344a1ca40
commit
584af02dba
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||||
|
* Copyleft Mr. Robot 2025
|
||||||
*
|
*
|
||||||
* This file is part of PortaPack.
|
* This file is part of PortaPack.
|
||||||
*
|
*
|
||||||
@ -100,6 +101,15 @@ void FrequencyScale::set_channel_filter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrequencyScale::set_cursor_position(const int32_t position) {
|
||||||
|
cursor_position = position;
|
||||||
|
|
||||||
|
cursor_position = std::min<int32_t>(cursor_position, 119);
|
||||||
|
cursor_position = std::max<int32_t>(cursor_position, -120);
|
||||||
|
|
||||||
|
set_dirty();
|
||||||
|
}
|
||||||
|
|
||||||
void FrequencyScale::paint(Painter& painter) {
|
void FrequencyScale::paint(Painter& painter) {
|
||||||
const auto r = screen_rect();
|
const auto r = screen_rect();
|
||||||
|
|
||||||
@ -240,6 +250,15 @@ bool FrequencyScale::on_key(const KeyEvent key) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FrequencyScale::on_touch(const TouchEvent touch) {
|
||||||
|
if (touch.type == TouchEvent::Type::Start) {
|
||||||
|
if (on_select) {
|
||||||
|
on_select((touch.point.x() * spectrum_sampling_rate) / 240);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void FrequencyScale::on_tick_second() {
|
void FrequencyScale::on_tick_second() {
|
||||||
set_dirty();
|
set_dirty();
|
||||||
_blink = !_blink;
|
_blink = !_blink;
|
||||||
@ -285,6 +304,15 @@ void WaterfallWidget::on_channel_spectrum(
|
|||||||
pixel_row);
|
pixel_row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WaterfallWidget::on_touch(const TouchEvent event) {
|
||||||
|
if (event.type == TouchEvent::Type::Start) {
|
||||||
|
if (on_touch_select) {
|
||||||
|
on_touch_select(event.point.x(), event.point.y());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void WaterfallWidget::clear() {
|
void WaterfallWidget::clear() {
|
||||||
display.fill_rectangle(
|
display.fill_rectangle(
|
||||||
screen_rect(),
|
screen_rect(),
|
||||||
@ -304,6 +332,18 @@ WaterfallView::WaterfallView(const bool cursor) {
|
|||||||
if (on_select) on_select(offset);
|
if (on_select) on_select(offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
waterfall_widget.on_touch_select = [this](int32_t x, int32_t y) {
|
||||||
|
if (y > screen_height - screen_height * 0.1) return; // prevent ghost touch
|
||||||
|
|
||||||
|
frequency_scale.focus(); // focus on frequency scale to show cursor
|
||||||
|
|
||||||
|
if (sampling_rate) {
|
||||||
|
// screen x to frequency scale x, NB we need two widgets align
|
||||||
|
int32_t cursor_position = x - (screen_width / 2);
|
||||||
|
frequency_scale.set_cursor_position(cursor_position);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!waterfall_widget.gradient.load_file(default_gradient_file)) {
|
if (!waterfall_widget.gradient.load_file(default_gradient_file)) {
|
||||||
waterfall_widget.gradient.set_default();
|
waterfall_widget.gradient.set_default();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||||
|
* Copyleft Mr. Robot 2025
|
||||||
*
|
*
|
||||||
* This file is part of PortaPack.
|
* This file is part of PortaPack.
|
||||||
*
|
*
|
||||||
@ -79,9 +80,11 @@ class FrequencyScale : public Widget {
|
|||||||
|
|
||||||
bool on_encoder(const EncoderEvent delta) override;
|
bool on_encoder(const EncoderEvent delta) override;
|
||||||
bool on_key(const KeyEvent key) override;
|
bool on_key(const KeyEvent key) override;
|
||||||
|
bool on_touch(const TouchEvent touch) override;
|
||||||
|
|
||||||
void set_spectrum_sampling_rate(const int new_sampling_rate);
|
void set_spectrum_sampling_rate(const int new_sampling_rate);
|
||||||
void set_channel_filter(const int low_frequency, const int high_frequency, const int transition);
|
void set_channel_filter(const int low_frequency, const int high_frequency, const int transition);
|
||||||
|
void set_cursor_position(const int32_t position);
|
||||||
|
|
||||||
void paint(Painter& painter) override;
|
void paint(Painter& painter) override;
|
||||||
|
|
||||||
@ -112,11 +115,14 @@ class FrequencyScale : public Widget {
|
|||||||
|
|
||||||
class WaterfallWidget : public Widget {
|
class WaterfallWidget : public Widget {
|
||||||
public:
|
public:
|
||||||
|
std::function<void(int32_t offset, int32_t y)> on_touch_select{};
|
||||||
|
|
||||||
Gradient gradient{};
|
Gradient gradient{};
|
||||||
|
|
||||||
void on_show() override;
|
void on_show() override;
|
||||||
void on_hide() override;
|
void on_hide() override;
|
||||||
void paint(Painter&) override {}
|
void paint(Painter&) override {}
|
||||||
|
bool on_touch(const TouchEvent event) override;
|
||||||
|
|
||||||
void on_channel_spectrum(const ChannelSpectrum& spectrum);
|
void on_channel_spectrum(const ChannelSpectrum& spectrum);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user