htop/ColorsPanel.c

100 lines
2.5 KiB
C
Raw Normal View History

2006-03-04 18:16:49 +00:00
#include "CRT.h"
2006-05-30 13:47:28 +00:00
#include "ColorsPanel.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 "CheckItem.h"
#include "Settings.h"
#include "ScreenManager.h"
#include "debug.h"
#include <assert.h>
// TO ADD A NEW SCHEME:
2006-05-30 13:47:28 +00:00
// * Increment the size of bool check in ColorsPanel.h
2006-03-04 18:16:49 +00:00
// * Add the entry in the ColorSchemes array below in the file
// * Add a define in CRT.h that matches the order of the array
// * Add the colors in CRT_setColors
/*{
2006-05-30 13:47:28 +00:00
typedef struct ColorsPanel_ {
Panel super;
2006-03-04 18:16:49 +00:00
Settings* settings;
ScreenManager* scr;
bool check[5];
2006-05-30 13:47:28 +00:00
} ColorsPanel;
2006-03-04 18:16:49 +00:00
}*/
2006-03-23 18:55:29 +00:00
/* private */
2006-03-04 18:16:49 +00:00
static char* ColorSchemes[] = {
"Default",
"Monochromatic",
"Black on White",
"Light Terminal",
"MC",
"Black Night",
NULL
};
2006-05-30 13:47:28 +00:00
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
ColorsPanel* this = (ColorsPanel*) malloc(sizeof(ColorsPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
((Object*)this)->delete = ColorsPanel_delete;
2006-03-04 18:16:49 +00:00
this->settings = settings;
this->scr = scr;
2006-05-30 13:47:28 +00:00
super->eventHandler = ColorsPanel_EventHandler;
2006-03-04 18:16:49 +00:00
2006-05-30 13:47:28 +00:00
Panel_setHeader(super, "Colors");
2006-03-04 18:16:49 +00:00
for (int i = 0; ColorSchemes[i] != NULL; i++) {
2006-05-30 13:47:28 +00:00
Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), &(this->check[i])));
2006-03-04 18:16:49 +00:00
this->check[i] = false;
}
this->check[settings->colorScheme] = true;
return this;
}
2006-05-30 13:47:28 +00:00
void ColorsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
ColorsPanel* this = (ColorsPanel*) object;
Panel_done(super);
2006-03-04 18:16:49 +00:00
free(this);
}
2006-05-30 13:47:28 +00:00
HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
ColorsPanel* this = (ColorsPanel*) super;
2006-03-04 18:16:49 +00:00
HandlerResult result = IGNORED;
2006-05-30 13:47:28 +00:00
int mark = Panel_getSelectedIndex(super);
2006-03-04 18:16:49 +00:00
switch(ch) {
case 0x0a:
case 0x0d:
case KEY_ENTER:
case ' ':
for (int i = 0; ColorSchemes[i] != NULL; i++) {
this->check[i] = false;
}
this->check[mark] = true;
this->settings->colorScheme = mark;
result = HANDLED;
}
if (result == HANDLED) {
this->settings->changed = true;
2006-03-04 18:16:49 +00:00
Header* header = this->settings->header;
CRT_setColors(mark);
2006-05-30 13:47:28 +00:00
Panel* lbMenu = (Panel*) Vector_get(this->scr->items, 0);
2006-03-04 18:16:49 +00:00
Header_draw(header);
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
RichString_setAttr(&(lbMenu->header), CRT_colors[PANEL_HEADER_UNFOCUS]);
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
}
return result;
}