mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Insulate ui::Context a bit from its clients.
Add accessor methods.
This commit is contained in:
parent
85383e488b
commit
47a3ffb15a
@ -125,7 +125,7 @@ private:
|
||||
void handle_application_queue() {
|
||||
std::array<uint8_t, Message::MAX_SIZE> message_buffer;
|
||||
while(Message* const message = shared_memory.application_queue.pop(message_buffer)) {
|
||||
context.message_map.send(message);
|
||||
context.message_map().send(message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ private:
|
||||
if( switches_state[i] ) {
|
||||
const auto event = static_cast<ui::KeyEvent>(i);
|
||||
if( !event_bubble_key(event) ) {
|
||||
context.focus_manager.update(top_widget, event);
|
||||
context.focus_manager().update(top_widget, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -211,7 +211,7 @@ private:
|
||||
}
|
||||
|
||||
bool event_bubble_key(const ui::KeyEvent event) {
|
||||
auto target = context.focus_manager.focus_widget();
|
||||
auto target = context.focus_manager().focus_widget();
|
||||
while( (target != nullptr) && !target->on_key(event) ) {
|
||||
target = target->parent();
|
||||
}
|
||||
@ -221,7 +221,7 @@ private:
|
||||
}
|
||||
|
||||
void event_bubble_encoder(const ui::EncoderEvent event) {
|
||||
auto target = context.focus_manager.focus_widget();
|
||||
auto target = context.focus_manager().focus_widget();
|
||||
while( (target != nullptr) && !target->on_encoder(event) ) {
|
||||
target = target->parent();
|
||||
}
|
||||
@ -251,7 +251,7 @@ int main(void) {
|
||||
ui::Painter painter;
|
||||
EventDispatcher event_dispatcher { &system_view, painter, context };
|
||||
|
||||
auto& message_handlers = context.message_map;
|
||||
auto& message_handlers = context.message_map();
|
||||
message_handlers.register_handler(Message::ID::Shutdown,
|
||||
[&event_dispatcher](const Message* const) {
|
||||
event_dispatcher.request_stop();
|
||||
|
@ -26,7 +26,7 @@
|
||||
namespace ui {
|
||||
|
||||
void Audio::on_show() {
|
||||
context().message_map.register_handler(Message::ID::AudioStatistics,
|
||||
context().message_map().register_handler(Message::ID::AudioStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const AudioStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
@ -34,7 +34,7 @@ void Audio::on_show() {
|
||||
}
|
||||
|
||||
void Audio::on_hide() {
|
||||
context().message_map.unregister_handler(Message::ID::AudioStatistics);
|
||||
context().message_map().unregister_handler(Message::ID::AudioStatistics);
|
||||
}
|
||||
|
||||
void Audio::paint(Painter& painter) {
|
||||
|
@ -38,7 +38,7 @@ BasebandStatsView::BasebandStatsView() {
|
||||
}
|
||||
|
||||
void BasebandStatsView::on_show() {
|
||||
context().message_map.register_handler(Message::ID::BasebandStatistics,
|
||||
context().message_map().register_handler(Message::ID::BasebandStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const BasebandStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
@ -46,7 +46,7 @@ void BasebandStatsView::on_show() {
|
||||
}
|
||||
|
||||
void BasebandStatsView::on_hide() {
|
||||
context().message_map.unregister_handler(Message::ID::BasebandStatistics);
|
||||
context().message_map().unregister_handler(Message::ID::BasebandStatistics);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
namespace ui {
|
||||
|
||||
void Channel::on_show() {
|
||||
context().message_map.register_handler(Message::ID::ChannelStatistics,
|
||||
context().message_map().register_handler(Message::ID::ChannelStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const ChannelStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
@ -34,7 +34,7 @@ void Channel::on_show() {
|
||||
}
|
||||
|
||||
void Channel::on_hide() {
|
||||
context().message_map.unregister_handler(Message::ID::ChannelStatistics);
|
||||
context().message_map().unregister_handler(Message::ID::ChannelStatistics);
|
||||
}
|
||||
|
||||
void Channel::paint(Painter& painter) {
|
||||
|
@ -496,7 +496,8 @@ ReceiverView::~ReceiverView() {
|
||||
}
|
||||
|
||||
void ReceiverView::on_show() {
|
||||
context().message_map.register_handler(Message::ID::FSKPacket,
|
||||
auto& message_map = context().message_map();
|
||||
message_map.register_handler(Message::ID::FSKPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const FSKPacketMessage*>(p);
|
||||
this->on_packet_ais(*message);
|
||||
@ -505,7 +506,8 @@ void ReceiverView::on_show() {
|
||||
}
|
||||
|
||||
void ReceiverView::on_hide() {
|
||||
context().message_map.unregister_handler(Message::ID::FSKPacket);
|
||||
auto& message_map = context().message_map();
|
||||
message_map.unregister_handler(Message::ID::FSKPacket);
|
||||
}
|
||||
|
||||
void ReceiverView::on_packet_ais(const FSKPacketMessage& message) {
|
||||
|
@ -26,7 +26,7 @@
|
||||
namespace ui {
|
||||
|
||||
void RSSI::on_show() {
|
||||
context().message_map.register_handler(Message::ID::RSSIStatistics,
|
||||
context().message_map().register_handler(Message::ID::RSSIStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const RSSIStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
@ -34,7 +34,7 @@ void RSSI::on_show() {
|
||||
}
|
||||
|
||||
void RSSI::on_hide() {
|
||||
context().message_map.unregister_handler(Message::ID::RSSIStatistics);
|
||||
context().message_map().unregister_handler(Message::ID::RSSIStatistics);
|
||||
}
|
||||
|
||||
void RSSI::paint(Painter& painter) {
|
||||
|
@ -252,7 +252,7 @@ public:
|
||||
}
|
||||
|
||||
void on_show() override {
|
||||
context().message_map.register_handler(Message::ID::ChannelSpectrum,
|
||||
context().message_map().register_handler(Message::ID::ChannelSpectrum,
|
||||
[this](const Message* const p) {
|
||||
this->on_channel_spectrum(reinterpret_cast<const ChannelSpectrumMessage*>(p)->spectrum);
|
||||
}
|
||||
@ -260,7 +260,7 @@ public:
|
||||
}
|
||||
|
||||
void on_hide() override {
|
||||
context().message_map.unregister_handler(Message::ID::ChannelSpectrum);
|
||||
context().message_map().unregister_handler(Message::ID::ChannelSpectrum);
|
||||
}
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override {
|
||||
|
@ -200,7 +200,7 @@ void Widget::hidden(bool hide) {
|
||||
}
|
||||
|
||||
void Widget::focus() {
|
||||
context().focus_manager.set_focus_widget(this);
|
||||
context().focus_manager().set_focus_widget(this);
|
||||
}
|
||||
|
||||
void Widget::on_focus() {
|
||||
@ -208,7 +208,7 @@ void Widget::on_focus() {
|
||||
}
|
||||
|
||||
void Widget::blur() {
|
||||
context().focus_manager.set_focus_widget(nullptr);
|
||||
context().focus_manager().set_focus_widget(nullptr);
|
||||
}
|
||||
|
||||
void Widget::on_blur() {
|
||||
@ -220,7 +220,7 @@ bool Widget::focusable() const {
|
||||
}
|
||||
|
||||
bool Widget::has_focus() {
|
||||
return (context().focus_manager.focus_widget() == this);
|
||||
return (context().focus_manager().focus_widget() == this);
|
||||
}
|
||||
|
||||
Widget* Widget::last_child_focus() const {
|
||||
|
@ -47,9 +47,19 @@ std::string to_string_dec_uint(const uint32_t n, const int32_t l = 0, const char
|
||||
std::string to_string_dec_int(const int32_t n, const int32_t l = 0, const char fill = 0);
|
||||
std::string to_string_hex(const uint32_t n, const int32_t l = 0);
|
||||
|
||||
struct Context {
|
||||
FocusManager focus_manager;
|
||||
MessageHandlerMap message_map;
|
||||
class Context {
|
||||
public:
|
||||
FocusManager& focus_manager() {
|
||||
return focus_manager_;
|
||||
}
|
||||
|
||||
MessageHandlerMap& message_map() {
|
||||
return message_map_;
|
||||
}
|
||||
|
||||
private:
|
||||
FocusManager focus_manager_;
|
||||
MessageHandlerMap message_map_;
|
||||
};
|
||||
|
||||
class Widget {
|
||||
|
Loading…
Reference in New Issue
Block a user