mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Drawing code
This commit is contained in:
parent
b2408f4957
commit
a486d1b3bf
@ -1,14 +1,22 @@
|
||||
#include <FL/Fl.H>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <FL/Fl.H>
|
||||
#include <FL/fl_draw.H>
|
||||
#include <edelib/Color.h>
|
||||
#include <edelib/Missing.h>
|
||||
#include "Applet.h"
|
||||
#include "MemMonitor.h"
|
||||
|
||||
EDELIB_NS_USING(color_rgb_to_fltk)
|
||||
|
||||
#define UPDATE_INTERVAL .5f
|
||||
#define STR_CMP(first, second, n) (strncmp(first, second, n) == 0)
|
||||
|
||||
static int height_from_perc(int perc, int h) {
|
||||
return (perc * h) / 100;
|
||||
}
|
||||
|
||||
static long get_number(const char *ln) {
|
||||
char *s = edelib_strndup(ln, 128);
|
||||
int i = 1;
|
||||
@ -21,7 +29,6 @@ static long get_number(const char *ln) {
|
||||
free(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mem_timeout_cb(void *d) {
|
||||
((MemMonitor*)d)->update_status();
|
||||
Fl::repeat_timeout(UPDATE_INTERVAL, mem_timeout_cb, d);
|
||||
@ -55,6 +62,29 @@ void MemMonitor::update_status(void) {
|
||||
|
||||
mem_usedp = 100 - (int)(((float)mem_free / (float)mem_total) * 100);
|
||||
swap_usedp = 100 - (int)(((float)swap_total / (float)swap_free) * 100);
|
||||
|
||||
static char tip[100];
|
||||
snprintf(tip, sizeof(tip), "Memory used: %i%%\nSwap used: %i%%", mem_usedp, swap_usedp);
|
||||
tooltip(tip);
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
void MemMonitor::draw(void) {
|
||||
draw_box();
|
||||
int W, W2, H, X, Y, mh, sh;
|
||||
|
||||
W = w() - Fl::box_dw(box());
|
||||
H = h() - Fl::box_dh(box());
|
||||
X = x() + Fl::box_dx(box());
|
||||
Y = y() + Fl::box_dy(box());
|
||||
W2 = W / 2;
|
||||
|
||||
mh = height_from_perc(mem_usedp, H);
|
||||
sh = height_from_perc(swap_usedp, H);
|
||||
|
||||
fl_rectf(X, Y + H - mh, W2, mh, color_rgb_to_fltk(166, 48, 48));
|
||||
fl_rectf(X + W2, Y + H - sh, W2, sh, color_rgb_to_fltk(54, 136, 79));
|
||||
}
|
||||
|
||||
EDE_PANEL_APPLET_EXPORT (
|
||||
|
@ -10,6 +10,7 @@ private:
|
||||
public:
|
||||
MemMonitor();
|
||||
void update_status(void);
|
||||
void draw(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user