htop/ColorsPanel.c

106 lines
2.6 KiB
C
Raw Normal View History

2011-12-26 21:35:57 +00:00
/*
htop - ColorsPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
2011-12-26 21:35:57 +00:00
in the source distribution for its full text.
*/
2006-03-04 18:16:49 +00:00
2006-05-30 13:47:28 +00:00
#include "ColorsPanel.h"
2006-03-04 18:16:49 +00:00
2021-04-29 15:12:43 +00:00
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include "CRT.h"
#include "FunctionBar.h"
2021-08-24 15:27:43 +00:00
#include "Macros.h"
#include "Object.h"
#include "OptionItem.h"
#include "ProvideCurses.h"
2011-12-26 21:35:57 +00:00
2006-03-04 18:16:49 +00:00
// TO ADD A NEW SCHEME:
2006-05-30 13:47:28 +00:00
// * Increment the size of bool check in ColorsPanel.h
// * Add the entry in the ColorSchemeNames array below in the file
2006-03-04 18:16:49 +00:00
// * Add a define in CRT.h that matches the order of the array
// * Add the colors in CRT_setColors
static const char* const ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
2015-03-23 18:26:56 +00:00
static const char* const ColorSchemeNames[] = {
2006-03-04 18:16:49 +00:00
"Default",
"Monochromatic",
"Black on White",
"Light Terminal",
"MC",
"Black Night",
"Broken Gray",
2006-03-04 18:16:49 +00:00
NULL
};
static void ColorsPanel_delete(Object* object) {
2006-05-30 13:47:28 +00:00
Panel* super = (Panel*) object;
ColorsPanel* this = (ColorsPanel*) object;
Panel_done(super);
2006-03-04 18:16:49 +00:00
free(this);
}
static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
2006-05-30 13:47:28 +00:00
ColorsPanel* this = (ColorsPanel*) super;
2019-10-31 16:39:12 +00:00
2006-03-04 18:16:49 +00:00
HandlerResult result = IGNORED;
int mark;
2006-03-04 18:16:49 +00:00
switch(ch) {
case 0x0a:
case 0x0d:
case KEY_ENTER:
2008-05-07 23:01:45 +00:00
case KEY_MOUSE:
case KEY_RECLICK:
2006-03-04 18:16:49 +00:00
case ' ':
mark = Panel_getSelectedIndex(super);
assert(mark >= 0);
assert(mark < LAST_COLORSCHEME);
for (int i = 0; ColorSchemeNames[i] != NULL; i++)
CheckItem_set((CheckItem*)Panel_get(super, i), false);
CheckItem_set((CheckItem*)Panel_get(super, mark), true);
2020-11-01 00:09:51 +00:00
2006-03-04 18:16:49 +00:00
this->settings->colorScheme = mark;
this->settings->changed = true;
2006-03-04 18:16:49 +00:00
CRT_setColors(mark);
clear();
result = HANDLED | REDRAW;
2006-03-04 18:16:49 +00:00
}
2006-03-04 18:16:49 +00:00
return result;
}
2020-10-05 11:19:50 +00:00
const PanelClass ColorsPanel_class = {
.super = {
.extends = Class(Panel),
.delete = ColorsPanel_delete
},
.eventHandler = ColorsPanel_eventHandler
};
2021-08-21 15:58:23 +00:00
ColorsPanel* ColorsPanel_new(Settings* settings) {
ColorsPanel* this = AllocThis(ColorsPanel);
Panel* super = (Panel*) this;
2015-03-23 18:26:56 +00:00
FunctionBar* fuBar = FunctionBar_new(ColorsFunctions, NULL, NULL);
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
this->settings = settings;
assert(ARRAYSIZE(ColorSchemeNames) == LAST_COLORSCHEME + 1);
Panel_setHeader(super, "Colors");
for (int i = 0; ColorSchemeNames[i] != NULL; i++) {
Panel_add(super, (Object*) CheckItem_newByVal(ColorSchemeNames[i], false));
}
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
return this;
}