From 089ef25df99c57c94fa856ec964cfb8cebd71cbe Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 15 Jan 2016 11:23:28 -0800 Subject: [PATCH] Draw AIS entry details. --- firmware/application/ais_app.cpp | 36 ++++++++++++++++++++++++++++++++ firmware/application/ais_app.hpp | 9 ++++++++ 2 files changed, 45 insertions(+) diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index d56e894a..13abac8e 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -294,6 +294,42 @@ void AISRecentEntryDetailView::focus() { button_done.focus(); } +Rect AISRecentEntryDetailView::draw_field( + Painter& painter, + const Rect& draw_rect, + const Style& style, + const std::string& label, + const std::string& value +) { + const size_t label_length_max = 4; + + painter.draw_string(Point { draw_rect.left(), draw_rect.top() }, style, label); + + const auto length = value.length(); + painter.draw_string(Point { draw_rect.left() + (label_length_max + 1) * 8, draw_rect.top() }, style, value); + + return { draw_rect.left(), draw_rect.top() + draw_rect.height(), draw_rect.width(), draw_rect.height() }; +} + +void AISRecentEntryDetailView::paint(Painter& painter) { + View::paint(painter); + + const auto s = style(); + const auto rect = screen_rect(); + + auto field_rect = Rect { rect.left(), rect.top() + 16, rect.width(), 16 }; + + const size_t mmsi_length = 9; + field_rect = draw_field(painter, field_rect, s, "MMSI", to_string_dec_int(entry.mmsi, mmsi_length)); + field_rect = draw_field(painter, field_rect, s, "Name", entry.name); + field_rect = draw_field(painter, field_rect, s, "Call", entry.call_sign); + field_rect = draw_field(painter, field_rect, s, "Dest", entry.destination); + field_rect = draw_field(painter, field_rect, s, "Lat ", ais::format::latlon_normalized(entry.last_position.latitude) + "N"); + field_rect = draw_field(painter, field_rect, s, "Lon ", ais::format::latlon_normalized(entry.last_position.longitude) + "E"); + field_rect = draw_field(painter, field_rect, s, "Stat", ais::format::navigational_status(entry.navigational_status)); + field_rect = draw_field(painter, field_rect, s, "Rx #", to_string_dec_uint(entry.received_count, 10)); +} + void AISRecentEntryDetailView::set_entry(const AISRecentEntry& new_entry) { entry = new_entry; } diff --git a/firmware/application/ais_app.hpp b/firmware/application/ais_app.hpp index e9d8df92..9c8ebe08 100644 --- a/firmware/application/ais_app.hpp +++ b/firmware/application/ais_app.hpp @@ -146,6 +146,7 @@ public: void set_entry(const AISRecentEntry& new_entry); void focus() override; + void paint(Painter&) override; private: AISRecentEntry entry; @@ -154,6 +155,14 @@ private: { 72, 192, 96, 24 }, "Done" }; + + Rect draw_field( + Painter& painter, + const Rect& draw_rect, + const Style& style, + const std::string& label, + const std::string& value + ); }; class AISAppView : public View {