2006-03-04 18:16:49 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
#include "MetersPanel.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
#include "Panel.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
#include "Settings.h"
|
|
|
|
#include "ScreenManager.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/*{
|
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
typedef struct MetersPanel_ {
|
|
|
|
Panel super;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
Settings* settings;
|
2006-05-30 13:45:40 +00:00
|
|
|
Vector* meters;
|
2006-03-04 18:16:49 +00:00
|
|
|
ScreenManager* scr;
|
2006-05-30 13:47:28 +00:00
|
|
|
} MetersPanel;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
}*/
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void MetersPanel_delete(Object* object) {
|
2006-05-30 13:47:28 +00:00
|
|
|
Panel* super = (Panel*) object;
|
|
|
|
MetersPanel* this = (MetersPanel*) object;
|
|
|
|
Panel_done(super);
|
2006-03-04 18:16:49 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static HandlerResult MetersPanel_EventHandler(Panel* super, int ch) {
|
2006-05-30 13:47:28 +00:00
|
|
|
MetersPanel* this = (MetersPanel*) super;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
int selected = Panel_getSelectedIndex(super);
|
2006-03-04 18:16:49 +00:00
|
|
|
HandlerResult result = IGNORED;
|
|
|
|
|
|
|
|
switch(ch) {
|
|
|
|
case 0x0a:
|
|
|
|
case 0x0d:
|
|
|
|
case KEY_ENTER:
|
|
|
|
case KEY_F(4):
|
|
|
|
case 't':
|
|
|
|
{
|
2006-05-30 13:45:40 +00:00
|
|
|
Meter* meter = (Meter*) Vector_get(this->meters, selected);
|
2006-04-10 20:40:38 +00:00
|
|
|
int mode = meter->mode + 1;
|
|
|
|
if (mode == LAST_METERMODE) mode = 1;
|
2006-03-04 18:16:49 +00:00
|
|
|
Meter_setMode(meter, mode);
|
2006-05-30 13:47:28 +00:00
|
|
|
Panel_set(super, selected, (Object*) Meter_toListItem(meter));
|
2006-03-04 18:16:49 +00:00
|
|
|
result = HANDLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_F(7):
|
|
|
|
case '[':
|
|
|
|
case '-':
|
|
|
|
{
|
2006-05-30 13:45:40 +00:00
|
|
|
Vector_moveUp(this->meters, selected);
|
2006-05-30 13:47:28 +00:00
|
|
|
Panel_moveSelectedUp(super);
|
2006-03-04 18:16:49 +00:00
|
|
|
result = HANDLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_F(8):
|
|
|
|
case ']':
|
|
|
|
case '+':
|
|
|
|
{
|
2006-05-30 13:45:40 +00:00
|
|
|
Vector_moveDown(this->meters, selected);
|
2006-05-30 13:47:28 +00:00
|
|
|
Panel_moveSelectedDown(super);
|
2006-03-04 18:16:49 +00:00
|
|
|
result = HANDLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_F(9):
|
|
|
|
case KEY_DC:
|
|
|
|
{
|
2006-05-30 13:45:40 +00:00
|
|
|
if (selected < Vector_size(this->meters)) {
|
|
|
|
Vector_remove(this->meters, selected);
|
2006-05-30 13:47:28 +00:00
|
|
|
Panel_remove(super, selected);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
result = HANDLED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result == HANDLED) {
|
|
|
|
Header* header = this->settings->header;
|
2009-06-02 04:51:23 +00:00
|
|
|
this->settings->changed = true;
|
2006-03-04 18:16:49 +00:00
|
|
|
Header_calculateHeight(header);
|
|
|
|
Header_draw(header);
|
|
|
|
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2008-03-09 08:58:38 +00:00
|
|
|
|
2010-02-25 01:43:18 +00:00
|
|
|
MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr) {
|
2008-03-09 08:58:38 +00:00
|
|
|
MetersPanel* this = (MetersPanel*) malloc(sizeof(MetersPanel));
|
|
|
|
Panel* super = (Panel*) this;
|
|
|
|
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
|
|
|
((Object*)this)->delete = MetersPanel_delete;
|
|
|
|
|
|
|
|
this->settings = settings;
|
|
|
|
this->meters = meters;
|
|
|
|
this->scr = scr;
|
|
|
|
super->eventHandler = MetersPanel_EventHandler;
|
|
|
|
Panel_setHeader(super, header);
|
|
|
|
for (int i = 0; i < Vector_size(meters); i++) {
|
|
|
|
Meter* meter = (Meter*) Vector_get(meters, i);
|
|
|
|
Panel_add(super, (Object*) Meter_toListItem(meter));
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|