diff options
author | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:15 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2016-04-11 13:00:15 +0200 |
commit | d3c9975943df58e293359b87905d19ff1fd52061 (patch) | |
tree | e416378879f60e8d538b1b25963904f767d30ff4 /FunctionBar.c | |
download | debian_htop-d3c9975943df58e293359b87905d19ff1fd52061.tar.gz debian_htop-d3c9975943df58e293359b87905d19ff1fd52061.tar.bz2 debian_htop-d3c9975943df58e293359b87905d19ff1fd52061.zip |
Imported Upstream version 0.5upstream/0.5
Diffstat (limited to 'FunctionBar.c')
-rw-r--r-- | FunctionBar.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/FunctionBar.c b/FunctionBar.c new file mode 100644 index 0000000..49597bd --- /dev/null +++ b/FunctionBar.c @@ -0,0 +1,91 @@ +/* +htop +(C) 2004 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "FunctionBar.h" +#include "CRT.h" + +#include "debug.h" +#include <assert.h> + +#include <string.h> +#include <stdlib.h> +#include <stdbool.h> +#include <curses.h> + +/*{ + +typedef struct FunctionBar_ { + int size; + char** functions; + char** keys; + int* events; +} FunctionBar; + +}*/ + +/* private property */ +char* FunctionBar_FKeys[10] = {" 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9", "10"}; + +/* private property */ +int FunctionBar_FEvents[10] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10)}; + +FunctionBar* FunctionBar_new(int size, char** functions, char** keys, int* events) { + FunctionBar* this = malloc(sizeof(FunctionBar)); + this->functions = functions; + this->size = size; + if (keys && events) { + this->keys = keys; + this->events = events; + } else { + this->keys = FunctionBar_FKeys; + this->events = FunctionBar_FEvents; + assert(this->size == 10); + } + return this; +} + +void FunctionBar_delete(FunctionBar* this) { + // These are always static data, RIGHT? >;) + // free(this->functions); + // free(this->keys); + free(this); +} + +void FunctionBar_draw(FunctionBar* this, char* buffer) { + FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]); +} + +void FunctionBar_drawAttr(FunctionBar* this, char* buffer, int attr) { + attrset(CRT_colors[FUNCTION_BAR]); + mvhline(LINES-1, 0, ' ', COLS); + int x = 0; + for (int i = 0; i < this->size; i++) { + attrset(CRT_colors[FUNCTION_KEY]); + mvaddstr(LINES-1, x, this->keys[i]); + x += strlen(this->keys[i]); + attrset(CRT_colors[FUNCTION_BAR]); + mvaddstr(LINES-1, x, this->functions[i]); + x += strlen(this->functions[i]); + } + if (buffer != NULL) { + attrset(attr); + mvaddstr(LINES-1, x, buffer); + } + attrset(CRT_colors[RESET_COLOR]); +} + +int FunctionBar_synthesizeEvent(FunctionBar* this, int pos) { + int x = 0; + for (int i = 0; i < this->size; i++) { + x += strlen(this->keys[i]); + x += strlen(this->functions[i]); + if (pos < x) { + return this->events[i]; + } + } + return ERR; +} |