From a486d1b3bf8b67927b1f77801601c19ec8ebee9f Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Fri, 30 Sep 2011 11:41:22 +0000 Subject: [PATCH] Drawing code --- ede-panel/applets/mem-monitor/MemMonitor.cpp | 34 ++++++++++++++++++-- ede-panel/applets/mem-monitor/MemMonitor.h | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ede-panel/applets/mem-monitor/MemMonitor.cpp b/ede-panel/applets/mem-monitor/MemMonitor.cpp index 511b012..8aae45c 100644 --- a/ede-panel/applets/mem-monitor/MemMonitor.cpp +++ b/ede-panel/applets/mem-monitor/MemMonitor.cpp @@ -1,14 +1,22 @@ -#include #include #include #include +#include +#include +#include #include #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 ( diff --git a/ede-panel/applets/mem-monitor/MemMonitor.h b/ede-panel/applets/mem-monitor/MemMonitor.h index 472617e..24f3346 100644 --- a/ede-panel/applets/mem-monitor/MemMonitor.h +++ b/ede-panel/applets/mem-monitor/MemMonitor.h @@ -10,6 +10,7 @@ private: public: MemMonitor(); void update_status(void); + void draw(void); }; #endif