CategoriesPanel.c 5.01 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

}*/

/* private property */
char* MetersFunctions[10] = {"      ", "      ", "      ", "Type  ", "      ", "      ", "MoveUp", "MoveDn", "Remove", "Done  "};

/* private property */
char* AvailableMetersFunctions[10] = {"      ", "      ", "      ", "      ", "Add L ", "Add R ", "      ", "      ", "      ", "Done  "};

/* private property */
char* DisplayOptionsFunctions[10] = {"      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "Done  "};

/* private property */
char* ColumnsFunctions[10] = {"      ", "      ", "      ", "      ", "      ", "      ", "MoveUp", "MoveDn", "Remove", "Done  "};

/* private property */
char* ColorsFunctions[10] = {"      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "Done  "};

/* private property */
char* AvailableColumnsFunctions[10] = {"      ", "      ", "      ", "      ", "Add   ", "      ", "      ", "      ", "      ", "Done  "};

44
45
46
47
48
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
49
50
51

   this->settings = settings;
   this->scr = scr;
52
53
54
55
56
57
   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));
Hisham Muhammad's avatar
Hisham Muhammad committed
58
59
60
   return this;
}

61
62
63
64
void CategoriesPanel_delete(Object* object) {
   Panel* super = (Panel*) object;
   CategoriesPanel* this = (CategoriesPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
65
66
67
   free(this);
}

68
69
HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
   CategoriesPanel* this = (CategoriesPanel*) super;
Hisham Muhammad's avatar
Hisham Muhammad committed
70
71
72

   HandlerResult result = IGNORED;

73
   int previous = Panel_getSelectedIndex(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
74
75
76
77
78
79
80
81

   switch (ch) {
      case KEY_UP:
      case KEY_DOWN:
      case KEY_NPAGE:
      case KEY_PPAGE:
      case KEY_HOME:
      case KEY_END: {
82
83
         Panel_onKey(super, ch);
         int selected = Panel_getSelectedIndex(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
84
85
86
87
88
89
         if (previous != selected) {
            int size = ScreenManager_size(this->scr);
            for (int i = 1; i < size; i++)
               ScreenManager_remove(this->scr, 1);
            switch (selected) {
               case 0:
90
                  CategoriesPanel_makeMetersPage(this);
Hisham Muhammad's avatar
Hisham Muhammad committed
91
92
                  break;
               case 1:
93
                  CategoriesPanel_makeDisplayOptionsPage(this);
Hisham Muhammad's avatar
Hisham Muhammad committed
94
95
                  break;
               case 2:
96
                  CategoriesPanel_makeColorsPage(this);
Hisham Muhammad's avatar
Hisham Muhammad committed
97
98
                  break;
               case 3:
99
                  CategoriesPanel_makeColumnsPage(this);
Hisham Muhammad's avatar
Hisham Muhammad committed
100
101
102
103
104
105
106
107
108
109
                  break;
            }
         }
         result = HANDLED;
      }
   }

   return result;
}

110
111
112
113
void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
   Panel* lbLeftMeters = (Panel*) MetersPanel_new(this->settings, "Left column", this->settings->header->leftMeters, this->scr);
   Panel* lbRightMeters = (Panel*) MetersPanel_new(this->settings, "Right column", this->settings->header->rightMeters, this->scr);
   Panel* lbAvailableMeters = (Panel*) AvailableMetersPanel_new(this->settings, lbLeftMeters, lbRightMeters, this->scr);
Hisham Muhammad's avatar
Hisham Muhammad committed
114
115
116
117
118
   ScreenManager_add(this->scr, lbLeftMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
   ScreenManager_add(this->scr, lbRightMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
   ScreenManager_add(this->scr, lbAvailableMeters, FunctionBar_new(10, AvailableMetersFunctions, NULL, NULL), -1);
}

119
120
void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
   Panel* lbDisplayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
Hisham Muhammad's avatar
Hisham Muhammad committed
121
122
123
   ScreenManager_add(this->scr, lbDisplayOptions, FunctionBar_new(10, DisplayOptionsFunctions, NULL, NULL), -1);
}

124
125
void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
   Panel* lbColors = (Panel*) ColorsPanel_new(this->settings, this->scr);
Hisham Muhammad's avatar
Hisham Muhammad committed
126
127
128
   ScreenManager_add(this->scr, lbColors, FunctionBar_new(10, ColorsFunctions, NULL, NULL), -1);
}

129
130
131
void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
   Panel* lbColumns = (Panel*) ColumnsPanel_new(this->settings, this->scr);
   Panel* lbAvailableColumns = (Panel*) AvailableColumnsPanel_new(this->settings, lbColumns, this->scr);
Hisham Muhammad's avatar
Hisham Muhammad committed
132
133
134
   ScreenManager_add(this->scr, lbColumns, FunctionBar_new(10, ColumnsFunctions, NULL, NULL), 20);
   ScreenManager_add(this->scr, lbAvailableColumns, FunctionBar_new(10, AvailableColumnsFunctions, NULL, NULL), -1);
}