aboutsummaryrefslogtreecommitdiffstats
path: root/ColorsPanel.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2016-04-11 13:00:20 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:20 +0200
commit85bb4ad9cb820ac3b8e935a930084a06cbfd2847 (patch)
tree681fd9b2d9fa80931b2a8bec4bb6667865b7c569 /ColorsPanel.c
parentea859f50d9438bc61ae96721a4d255b49de78653 (diff)
downloaddebian_htop-85bb4ad9cb820ac3b8e935a930084a06cbfd2847.tar.gz
debian_htop-85bb4ad9cb820ac3b8e935a930084a06cbfd2847.tar.bz2
debian_htop-85bb4ad9cb820ac3b8e935a930084a06cbfd2847.zip
Imported Upstream version 0.6.3upstream/0.6.3
Diffstat (limited to 'ColorsPanel.c')
-rw-r--r--ColorsPanel.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/ColorsPanel.c b/ColorsPanel.c
new file mode 100644
index 0000000..e62583c
--- /dev/null
+++ b/ColorsPanel.c
@@ -0,0 +1,98 @@
+
+#include "CRT.h"
+#include "ColorsPanel.h"
+
+#include "Panel.h"
+#include "CheckItem.h"
+#include "Settings.h"
+#include "ScreenManager.h"
+
+#include "debug.h"
+#include <assert.h>
+
+// TO ADD A NEW SCHEME:
+// * Increment the size of bool check in ColorsPanel.h
+// * 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
+
+/*{
+
+typedef struct ColorsPanel_ {
+ Panel super;
+
+ Settings* settings;
+ ScreenManager* scr;
+ bool check[5];
+} ColorsPanel;
+
+}*/
+
+static char* ColorSchemes[] = {
+ "Default",
+ "Monochromatic",
+ "Black on White",
+ "Light Terminal",
+ "MC",
+ "Black Night",
+ NULL
+};
+
+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;
+
+ this->settings = settings;
+ this->scr = scr;
+ super->eventHandler = ColorsPanel_EventHandler;
+
+ Panel_setHeader(super, "Colors");
+ for (int i = 0; ColorSchemes[i] != NULL; i++) {
+ Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), &(this->check[i])));
+ this->check[i] = false;
+ }
+ this->check[settings->colorScheme] = true;
+ return this;
+}
+
+void ColorsPanel_delete(Object* object) {
+ Panel* super = (Panel*) object;
+ ColorsPanel* this = (ColorsPanel*) object;
+ Panel_done(super);
+ free(this);
+}
+
+HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
+ ColorsPanel* this = (ColorsPanel*) super;
+
+ HandlerResult result = IGNORED;
+ int mark = Panel_getSelectedIndex(super);
+
+ 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;
+ Header* header = this->settings->header;
+ CRT_setColors(mark);
+ Panel* menu = (Panel*) Vector_get(this->scr->items, 0);
+ Header_draw(header);
+ RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
+ RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]);
+ ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
+ }
+ return result;
+}
+

© 2014-2024 Faster IT GmbH | imprint | privacy policy