Просмотр исходного кода

Very basic subview system introduced.

antirez 3 лет назад
Родитель
Сommit
2de5c2af0f
4 измененных файлов с 66 добавлено и 3 удалено
  1. 6 0
      app.c
  2. 4 1
      app.h
  3. 32 0
      ui.c
  4. 24 2
      view_info.c

+ 6 - 0
app.c

@@ -95,6 +95,11 @@ static void app_switch_view(ProtoViewApp *app, SwitchViewDirection dir) {
     if ((old == ViewFrequencySettings && new != ViewModulationSettings) ||
         (old == ViewModulationSettings && new != ViewFrequencySettings))
         view_exit_settings(app);
+
+    /* Set the current subview of the view we just left to zero, that is
+     * the main subview of the view. When re re-enter it we want to see
+     * the main thing. */
+    app->current_subview[old] = 0;
 }
 
 /* Allocate the application state and initialize a number of stuff.
@@ -118,6 +123,7 @@ ProtoViewApp* protoview_app_alloc() {
     gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
     app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
     app->current_view = ViewRawPulses;
+    for (int j = 0; j < ViewLast; j++) app->current_subview[j] = 0;
     app->direct_sampling_enabled = false;
 
     // Signal found and visualization defaults

+ 4 - 1
app.h

@@ -105,7 +105,8 @@ struct ProtoViewApp {
     Gui *gui;
     ViewPort *view_port;     /* We just use a raw viewport and we render
                                 everything into the low level canvas. */
-    ProtoViewCurrentView current_view;  /* Active view ID. */
+    ProtoViewCurrentView current_view;      /* Active left-right view ID. */
+    int current_subview[ViewLast];  /* Active up-down subview ID. */
     FuriMessageQueue *event_queue;  /* Keypress events go here. */
 
     /* Radio related. */
@@ -182,6 +183,8 @@ void view_exit_direct_sampling(ProtoViewApp *app);
 void view_exit_settings(ProtoViewApp *app);
 
 /* ui.c */
+void show_available_subviews(Canvas *canvas, ProtoViewApp *app, int last_subview);
+bool process_subview_updown(ProtoViewApp *app, InputEvent input, int last_subview);
 void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str, Color text_color, Color border_color);
 
 /* crc.c */

+ 32 - 0
ui.c

@@ -3,6 +3,38 @@
 
 #include "app.h"
 
+/* Called by view rendering callback that has subviews, to show small triangles
+ * facing down/up if there are other subviews the user can access with up
+ * and down. */
+void show_available_subviews(Canvas *canvas, ProtoViewApp *app,
+                             int last_subview)
+{
+    int subview = app->current_subview[app->current_view];
+    if (subview != 0)
+        canvas_draw_triangle(canvas,120,5,8,5,CanvasDirectionBottomToTop);
+    if (subview != last_subview-1)
+        canvas_draw_triangle(canvas,120,59,8,5,CanvasDirectionTopToBottom);
+}
+
+/* Handle up/down keys when we are in a subview. If the function catched
+ * such keypress, it returns true, so that the actual view input callback
+ * knows it can just return ASAP without doing anything. */
+bool process_subview_updown(ProtoViewApp *app, InputEvent input, int last_subview) {
+    int subview = app->current_subview[app->current_view];
+    if (input.type == InputTypePress) {
+        if (input.key == InputKeyUp) {
+            if (subview != 0)
+                app->current_subview[app->current_view]--;
+            return true;
+        } else if (input.key == InputKeyDown) {
+            if (subview != last_subview-1)
+                app->current_subview[app->current_view]++;
+            return true;
+        }
+    }
+    return false;
+}
+
 void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str, Color text_color, Color border_color)
 {
     struct {

+ 24 - 2
view_info.c

@@ -3,8 +3,14 @@
 
 #include "app.h"
 
-/* Renders the view with the detected message information. */
-void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
+enum {
+    SubViewInfoMain,
+    SubViewInfoSave,
+    SubViewInfoLast, /* Just a sentinel. */
+};
+
+/* Render the view with the detected message information. */
+static void render_subview_main(Canvas *const canvas, ProtoViewApp *app) {
     if (app->signal_decoded == false) {
         canvas_set_font(canvas, FontSecondary);
         canvas_draw_str(canvas, 30,36,"No signal decoded");
@@ -31,8 +37,24 @@ void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
     canvas_draw_str(canvas, 0, y, app->signal_info.info4); y += lineheight;
 }
 
+/* Render view with save option. */
+static void render_subview_save(Canvas *const canvas, ProtoViewApp *app) {
+    UNUSED(canvas);
+    UNUSED(app);
+}
+
+/* Render the selected subview of this view. */
+void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
+    show_available_subviews(canvas,app,SubViewInfoLast);
+    switch(app->current_subview[app->current_view]) {
+    case SubViewInfoMain: render_subview_main(canvas,app); break;
+    case SubViewInfoSave: render_subview_save(canvas,app); break;
+    }
+}
+
 /* Handle input for the info view. */
 void process_input_info(ProtoViewApp *app, InputEvent input) {
+    if (process_subview_updown(app,input,SubViewInfoLast)) return;
     if (input.type == InputTypeShort) {
         if (input.key == InputKeyOk) {
             /* Reset the current sample to capture the next. */