CategoriesPanel.c 4.95 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1

2
3
4
5
6
7
8
#include "CategoriesPanel.h"
#include "AvailableMetersPanel.h"
#include "MetersPanel.h"
#include "DisplayOptionsPanel.h"
#include "ColumnsPanel.h"
#include "ColorsPanel.h"
#include "AvailableColumnsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
9

10
#include "Panel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
11
12
13
14
15
16

#include "debug.h"
#include <assert.h>

/*{

17
18
typedef struct CategoriesPanel_ {
   Panel super;
Hisham Muhammad's avatar
Hisham Muhammad committed
19
20
21

   Settings* settings;
   ScreenManager* scr;
22
} CategoriesPanel;
Hisham Muhammad's avatar
Hisham Muhammad committed
23
24
25

}*/

Hisham Muhammad's avatar
Hisham Muhammad committed
26
static char* MetersFunctions[] = {"      ", "      ", "      ", "Type  ", "      ", "      ", "MoveUp", "MoveDn", "Remove", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
27

Hisham Muhammad's avatar
Hisham Muhammad committed
28
static char* AvailableMetersFunctions[] = {"      ", "      ", "      ", "      ", "Add L ", "Add R ", "      ", "      ", "      ", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
29

Hisham Muhammad's avatar
Hisham Muhammad committed
30
static char* DisplayOptionsFunctions[] = {"      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
31

Hisham Muhammad's avatar
Hisham Muhammad committed
32
static char* ColumnsFunctions[] = {"      ", "      ", "      ", "      ", "      ", "      ", "MoveUp", "MoveDn", "Remove", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
33

Hisham Muhammad's avatar
Hisham Muhammad committed
34
static char* ColorsFunctions[] = {"      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
35

Hisham Muhammad's avatar
Hisham Muhammad committed
36
static char* AvailableColumnsFunctions[] = {"      ", "      ", "      ", "      ", "Add   ", "      ", "      ", "      ", "      ", "Done  ", NULL};
Hisham Muhammad's avatar
Hisham Muhammad committed
37

38
static void CategoriesPanel_delete(Object* object) {
39
40
41
   Panel* super = (Panel*) object;
   CategoriesPanel* this = (CategoriesPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
42
43
44
   free(this);
}

45
46
47
48
void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
   Panel* leftMeters = (Panel*) MetersPanel_new(this->settings, "Left column", this->settings->header->leftMeters, this->scr);
   Panel* rightMeters = (Panel*) MetersPanel_new(this->settings, "Right column", this->settings->header->rightMeters, this->scr);
   Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, leftMeters, rightMeters, this->scr);
Hisham Muhammad's avatar
Hisham Muhammad committed
49
50
51
   ScreenManager_add(this->scr, leftMeters, FunctionBar_new(MetersFunctions, NULL, NULL), 20);
   ScreenManager_add(this->scr, rightMeters, FunctionBar_new(MetersFunctions, NULL, NULL), 20);
   ScreenManager_add(this->scr, availableMeters, FunctionBar_new(AvailableMetersFunctions, NULL, NULL), -1);
52
53
54
55
}

static void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
   Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
Hisham Muhammad's avatar
Hisham Muhammad committed
56
   ScreenManager_add(this->scr, displayOptions, FunctionBar_new(DisplayOptionsFunctions, NULL, NULL), -1);
57
58
59
60
}

static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
   Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr);
Hisham Muhammad's avatar
Hisham Muhammad committed
61
   ScreenManager_add(this->scr, colors, FunctionBar_new(ColorsFunctions, NULL, NULL), -1);
62
63
64
65
66
}

static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
   Panel* columns = (Panel*) ColumnsPanel_new(this->settings, this->scr);
   Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(this->settings, columns, this->scr);
Hisham Muhammad's avatar
Hisham Muhammad committed
67
68
   ScreenManager_add(this->scr, columns, FunctionBar_new(ColumnsFunctions, NULL, NULL), 20);
   ScreenManager_add(this->scr, availableColumns, FunctionBar_new(AvailableColumnsFunctions, NULL, NULL), -1);
69
70
71
}

static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
72
   CategoriesPanel* this = (CategoriesPanel*) super;
Hisham Muhammad's avatar
Hisham Muhammad committed
73
74
75

   HandlerResult result = IGNORED;

76
   int selected = Panel_getSelectedIndex(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
77
   switch (ch) {
78
79
80
      case EVENT_SETSELECTED:
         result = HANDLED;
         break;
Hisham Muhammad's avatar
Hisham Muhammad committed
81
82
83
84
85
86
      case KEY_UP:
      case KEY_DOWN:
      case KEY_NPAGE:
      case KEY_PPAGE:
      case KEY_HOME:
      case KEY_END: {
87
         int previous = selected;
88
         Panel_onKey(super, ch);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
         selected = Panel_getSelectedIndex(super);
         if (previous != selected)
            result = HANDLED;
         break;
      }
   }

   if (result == HANDLED) {
      int size = ScreenManager_size(this->scr);
      for (int i = 1; i < size; i++)
         ScreenManager_remove(this->scr, 1);
      switch (selected) {
         case 0:
            CategoriesPanel_makeMetersPage(this);
            break;
         case 1:
            CategoriesPanel_makeDisplayOptionsPage(this);
            break;
         case 2:
            CategoriesPanel_makeColorsPage(this);
            break;
         case 3:
            CategoriesPanel_makeColumnsPage(this);
            break;
Hisham Muhammad's avatar
Hisham Muhammad committed
113
114
115
116
117
118
      }
   }

   return result;
}

119
120
121
122
123
CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr) {
   CategoriesPanel* this = (CategoriesPanel*) malloc(sizeof(CategoriesPanel));
   Panel* super = (Panel*) this;
   Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
   ((Object*)this)->delete = CategoriesPanel_delete;
Hisham Muhammad's avatar
Hisham Muhammad committed
124

125
126
127
128
129
130
131
132
133
   this->settings = settings;
   this->scr = scr;
   super->eventHandler = CategoriesPanel_eventHandler;
   Panel_setHeader(super, "Setup");
   Panel_add(super, (Object*) ListItem_new("Meters", 0));
   Panel_add(super, (Object*) ListItem_new("Display options", 0));
   Panel_add(super, (Object*) ListItem_new("Colors", 0));
   Panel_add(super, (Object*) ListItem_new("Columns", 0));
   return this;
Hisham Muhammad's avatar
Hisham Muhammad committed
134
}