mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-11 17:19:29 +00:00
Checkboxes, more AFSK options
This commit is contained in:
@@ -72,9 +72,9 @@ struct data_t {
|
||||
|
||||
// AFSK modem
|
||||
int32_t afsk_mark_freq;
|
||||
int32_t afsk_space_freq;
|
||||
int32_t afsk_space_freq; // Todo: optimize size, only 256 bytes of NVRAM !
|
||||
int32_t afsk_bitrate;
|
||||
uint8_t afsk_config;
|
||||
uint32_t afsk_config;
|
||||
|
||||
// Play dead unlock
|
||||
bool playing_dead;
|
||||
@@ -130,11 +130,11 @@ void set_afsk_bitrate(const int32_t new_value) {
|
||||
data->afsk_bitrate = afsk_bitrate_range.clip(new_value);
|
||||
}
|
||||
|
||||
uint8_t afsk_config() {
|
||||
uint32_t afsk_config() {
|
||||
return data->afsk_config;
|
||||
}
|
||||
|
||||
void set_afsk_config(const uint8_t new_value) {
|
||||
void set_afsk_config(const uint32_t new_value) {
|
||||
data->afsk_config = new_value;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ void set_afsk_space(const int32_t new_value);
|
||||
int32_t afsk_bitrate();
|
||||
void set_afsk_bitrate(const int32_t new_value);
|
||||
|
||||
uint8_t afsk_config();
|
||||
void set_afsk_config(const uint8_t new_value);
|
||||
uint32_t afsk_config();
|
||||
void set_afsk_config(const uint32_t new_value);
|
||||
|
||||
bool playing_dead();
|
||||
void set_playing_dead(const bool new_value);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_painter.hpp"
|
||||
#include "portapack.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
@@ -349,6 +350,132 @@ void Text::paint(Painter& painter) {
|
||||
);
|
||||
}
|
||||
|
||||
/* Checkbox **************************************************************/
|
||||
|
||||
void Checkbox::set_text(const std::string value) {
|
||||
text_ = value;
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
std::string Checkbox::text() const {
|
||||
return text_;
|
||||
}
|
||||
|
||||
void Checkbox::set_value(const bool value) {
|
||||
value_ = value;
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
bool Checkbox::value() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
void Checkbox::paint(Painter& painter) {
|
||||
const auto r = screen_rect();
|
||||
|
||||
const auto paint_style = (has_focus() || flags.highlighted) ? style().invert() : style();
|
||||
|
||||
painter.draw_rectangle({ r.pos.x, r.pos.y, 24, 24 }, style().foreground);
|
||||
|
||||
painter.fill_rectangle(
|
||||
{
|
||||
static_cast<Coord>(r.pos.x + 1), static_cast<Coord>(r.pos.y + 1),
|
||||
static_cast<Dim>(24 - 2), static_cast<Dim>(24 - 2)
|
||||
},
|
||||
style().background
|
||||
);
|
||||
|
||||
painter.draw_rectangle({ r.pos.x+2, r.pos.y+2, 24-4, 24-4 }, paint_style.background);
|
||||
|
||||
if (value_ == true) {
|
||||
// Check
|
||||
portapack::display.draw_line( {r.pos.x+2, r.pos.y+14}, {r.pos.x+6, r.pos.y+18}, ui::Color::green());
|
||||
portapack::display.draw_line( {r.pos.x+6, r.pos.y+18}, {r.pos.x+20, r.pos.y+4}, ui::Color::green());
|
||||
} else {
|
||||
// Cross
|
||||
portapack::display.draw_line( {r.pos.x+1, r.pos.y+1}, {r.pos.x+24-2, r.pos.y+24-2}, ui::Color::red());
|
||||
portapack::display.draw_line( {r.pos.x+24-2, r.pos.y+1}, {r.pos.x+1, r.pos.y+24-2}, ui::Color::red());
|
||||
}
|
||||
|
||||
const auto label_r = paint_style.font.size_of(text_);
|
||||
painter.draw_string(
|
||||
{
|
||||
static_cast<Coord>(r.pos.x + 24 + 4),
|
||||
static_cast<Coord>(r.pos.y + (24 - label_r.h) / 2)
|
||||
},
|
||||
paint_style,
|
||||
text_
|
||||
);
|
||||
}
|
||||
|
||||
bool Checkbox::on_key(const KeyEvent key) {
|
||||
if( key == KeyEvent::Select ) {
|
||||
value_ = not value_;
|
||||
set_dirty();
|
||||
|
||||
if( on_select ) {
|
||||
on_select(*this);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Checkbox::on_touch(const TouchEvent event) {
|
||||
switch(event.type) {
|
||||
case TouchEvent::Type::Start:
|
||||
flags.highlighted = true;
|
||||
set_dirty();
|
||||
return true;
|
||||
|
||||
|
||||
case TouchEvent::Type::End:
|
||||
flags.highlighted = false;
|
||||
value_ = not value_;
|
||||
set_dirty();
|
||||
if( on_select ) {
|
||||
on_select(*this);
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
#if 0
|
||||
switch(event.type) {
|
||||
case TouchEvent::Type::Start:
|
||||
flags.highlighted = true;
|
||||
set_dirty();
|
||||
return true;
|
||||
|
||||
case TouchEvent::Type::Move:
|
||||
{
|
||||
const bool new_highlighted = screen_rect().contains(event.point);
|
||||
if( flags.highlighted != new_highlighted ) {
|
||||
flags.highlighted = new_highlighted;
|
||||
set_dirty();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case TouchEvent::Type::End:
|
||||
if( flags.highlighted ) {
|
||||
flags.highlighted = false;
|
||||
set_dirty();
|
||||
if( on_select ) {
|
||||
on_select(*this);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Button ****************************************************************/
|
||||
|
||||
void Button::set_text(const std::string value) {
|
||||
|
||||
@@ -56,6 +56,12 @@ public:
|
||||
) : parent_rect { }
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Widget(
|
||||
Point parent_point
|
||||
) : parent_rect { parent_point, { 24, 24 } }
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Widget(
|
||||
Rect parent_rect
|
||||
@@ -209,6 +215,41 @@ private:
|
||||
std::string text;
|
||||
};
|
||||
|
||||
class Checkbox : public Widget {
|
||||
public:
|
||||
std::function<void(Checkbox&)> on_select;
|
||||
|
||||
Checkbox(
|
||||
Point parent_point,
|
||||
std::string text
|
||||
) : Widget { parent_point },
|
||||
text_ { text }
|
||||
{
|
||||
flags.focusable = true;
|
||||
}
|
||||
|
||||
Checkbox(
|
||||
) : Checkbox { { }, { } }
|
||||
{
|
||||
}
|
||||
|
||||
void set_text(const std::string value);
|
||||
void set_style(const Style* new_style);
|
||||
std::string text() const;
|
||||
void set_value(const bool value);
|
||||
bool value() const;
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
bool on_key(const KeyEvent key) override;
|
||||
bool on_touch(const TouchEvent event) override;
|
||||
|
||||
private:
|
||||
std::string text_;
|
||||
bool value_ = false;
|
||||
const Style* style_ { nullptr };
|
||||
};
|
||||
|
||||
class Button : public Widget {
|
||||
public:
|
||||
std::function<void(Button&)> on_select;
|
||||
|
||||
Reference in New Issue
Block a user