Move app-level config to new AISAppView class.

This commit is contained in:
Jared Boone 2016-01-14 09:41:58 -08:00
parent 1f2b28b2b8
commit 6e0aa79d44
2 changed files with 41 additions and 38 deletions

View File

@ -163,36 +163,11 @@ void AISRecentEntries::truncate_entries() {
namespace ui {
AISRecentEntriesView::AISRecentEntriesView() {
AISRecentEntriesView::AISRecentEntriesView(
AISRecentEntries& recent
) : recent { recent }
{
flags.focusable = true;
EventDispatcher::message_map().register_handler(Message::ID::AISPacket,
[this](Message* const p) {
const auto message = static_cast<const AISPacketMessage*>(p);
const ais::Packet packet { message->packet };
if( packet.is_valid() ) {
this->logger.on_packet(packet);
this->on_packet(packet);
}
}
);
receiver_model.set_baseband_configuration({
.mode = 3,
.sampling_rate = 2457600,
.decimation_factor = 1,
});
receiver_model.set_baseband_bandwidth(1750000);
}
AISRecentEntriesView::~AISRecentEntriesView() {
EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket);
}
void AISRecentEntriesView::on_packet(const ais::Packet& packet) {
recent.on_packet(packet);
set_dirty();
}
void AISRecentEntriesView::on_focus() {
@ -296,6 +271,27 @@ AISAppView::AISAppView() {
add_children({ {
&recent_entries_view,
} });
EventDispatcher::message_map().register_handler(Message::ID::AISPacket,
[this](Message* const p) {
const auto message = static_cast<const AISPacketMessage*>(p);
const ais::Packet packet { message->packet };
if( packet.is_valid() ) {
this->on_packet(packet);
}
}
);
receiver_model.set_baseband_configuration({
.mode = 3,
.sampling_rate = 2457600,
.decimation_factor = 1,
});
receiver_model.set_baseband_bandwidth(1750000);
}
AISAppView::~AISAppView() {
EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket);
}
void AISAppView::set_parent_rect(const Rect new_parent_rect) {
@ -303,4 +299,10 @@ void AISAppView::set_parent_rect(const Rect new_parent_rect) {
recent_entries_view.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() });
}
void AISAppView::on_packet(const ais::Packet& packet) {
logger.on_packet(packet);
recent.on_packet(packet);
recent_entries_view.set_dirty();
}
} /* namespace ui */

View File

@ -108,8 +108,7 @@ namespace ui {
class AISRecentEntriesView : public View {
public:
AISRecentEntriesView();
~AISRecentEntriesView();
AISRecentEntriesView(AISRecentEntries& recent);
void paint(Painter& painter) override;
@ -119,29 +118,31 @@ public:
bool on_encoder(const EncoderEvent event) override;
private:
AISLogger logger;
AISRecentEntries& recent;
using EntryKey = ais::MMSI;
EntryKey selected_key;
const EntryKey invalid_key = 0xffffffff;
bool has_focus = false;
AISRecentEntries recent;
void on_packet(const ais::Packet& packet);
void advance(const int32_t amount);
};
class AISAppView : public View {
public:
AISAppView();
~AISAppView();
void set_parent_rect(const Rect new_parent_rect) override;
private:
AISRecentEntriesView recent_entries_view;
AISRecentEntries recent;
AISLogger logger;
AISRecentEntriesView recent_entries_view { recent };
void on_packet(const ais::Packet& packet);
};
} /* namespace ui */