~ubuntu-branches/ubuntu/intrepid/htop/intrepid

« back to all changes in this revision

Viewing changes to FunctionBar.c

  • Committer: Bazaar Package Importer
  • Author(s): Bartosz Fenski
  • Date: 2004-11-27 10:10:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041127101017-vwknw2ipfvxchno4
Tags: 0.5-1
* New upstream version.
  - fixes problem with wrongly displayed CPU bar (Closes: #283212)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
htop
 
3
(C) 2004 Hisham H. Muhammad
 
4
Released under the GNU GPL, see the COPYING file
 
5
in the source distribution for its full text.
 
6
*/
 
7
 
 
8
#include "FunctionBar.h"
 
9
#include "CRT.h"
 
10
 
 
11
#include "debug.h"
 
12
#include <assert.h>
 
13
 
 
14
#include <string.h>
 
15
#include <stdlib.h>
 
16
#include <stdbool.h>
 
17
#include <curses.h>
 
18
 
 
19
/*{
 
20
 
 
21
typedef struct FunctionBar_ {
 
22
   int size;
 
23
   char** functions;
 
24
   char** keys;
 
25
   int* events;
 
26
} FunctionBar;
 
27
 
 
28
}*/
 
29
 
 
30
/* private property */
 
31
char* FunctionBar_FKeys[10] = {" 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9", "10"};
 
32
 
 
33
/* private property */
 
34
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)};
 
35
 
 
36
FunctionBar* FunctionBar_new(int size, char** functions, char** keys, int* events) {
 
37
   FunctionBar* this = malloc(sizeof(FunctionBar));
 
38
   this->functions = functions;
 
39
   this->size = size;
 
40
   if (keys && events) {
 
41
      this->keys = keys;
 
42
      this->events = events;
 
43
   } else {
 
44
      this->keys = FunctionBar_FKeys;
 
45
      this->events = FunctionBar_FEvents;
 
46
      assert(this->size == 10);
 
47
   }
 
48
   return this;
 
49
}
 
50
 
 
51
void FunctionBar_delete(FunctionBar* this) {
 
52
   // These are always static data, RIGHT? >;)
 
53
   // free(this->functions);
 
54
   // free(this->keys);
 
55
   free(this);
 
56
}
 
57
 
 
58
void FunctionBar_draw(FunctionBar* this, char* buffer) {
 
59
   FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]);
 
60
}
 
61
 
 
62
void FunctionBar_drawAttr(FunctionBar* this, char* buffer, int attr) {
 
63
   attrset(CRT_colors[FUNCTION_BAR]);
 
64
   mvhline(LINES-1, 0, ' ', COLS);
 
65
   int x = 0;
 
66
   for (int i = 0; i < this->size; i++) {
 
67
      attrset(CRT_colors[FUNCTION_KEY]);
 
68
      mvaddstr(LINES-1, x, this->keys[i]);
 
69
      x += strlen(this->keys[i]);
 
70
      attrset(CRT_colors[FUNCTION_BAR]);
 
71
      mvaddstr(LINES-1, x, this->functions[i]);
 
72
      x += strlen(this->functions[i]);
 
73
   }
 
74
   if (buffer != NULL) {
 
75
      attrset(attr);
 
76
      mvaddstr(LINES-1, x, buffer);
 
77
   }
 
78
   attrset(CRT_colors[RESET_COLOR]);
 
79
}
 
80
 
 
81
int FunctionBar_synthesizeEvent(FunctionBar* this, int pos) {
 
82
   int x = 0;
 
83
   for (int i = 0; i < this->size; i++) {
 
84
      x += strlen(this->keys[i]);
 
85
      x += strlen(this->functions[i]);
 
86
      if (pos < x) {
 
87
         return this->events[i];
 
88
      }
 
89
   }
 
90
   return ERR;
 
91
}