00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gtkStatsLabel.h"
00020 #include "gtkStatsMonitor.h"
00021
00022 #include <pStatClientData.h>
00023 #include <pStatMonitor.h>
00024
00025
00026
00027
00028
00029
00030
00031 GtkStatsLabel::
00032 GtkStatsLabel(PStatMonitor *monitor, int collector_index,
00033 Gdk_Font font) :
00034 _collector_index(collector_index),
00035 _font(font)
00036 {
00037 set_events(GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
00038
00039 _text = monitor->get_client_data()->get_collector_name(_collector_index);
00040 RGBColorf rgb = monitor->get_collector_color(_collector_index);
00041 _bg_color.set_rgb_p(rgb[0], rgb[1], rgb[2]);
00042
00043
00044 float bright =
00045 rgb[0] * 0.299 +
00046 rgb[1] * 0.587 +
00047 rgb[2] * 0.114;
00048
00049 if (bright >= 0.5) {
00050 _fg_color.set_rgb_p(0, 0, 0);
00051 } else {
00052 _fg_color.set_rgb_p(1, 1, 1);
00053 }
00054
00055 Gdk_Colormap::get_system().alloc(_fg_color);
00056 Gdk_Colormap::get_system().alloc(_bg_color);
00057
00058 int text_width = _font.string_width(_text);
00059 int text_height = _font.height();
00060
00061 _height = text_height + 4;
00062 _width = text_width + 4;
00063
00064 set_usize(_width, _height);
00065 }
00066
00067
00068
00069
00070
00071
00072 int GtkStatsLabel::
00073 get_width() const {
00074 return _width;
00075 }
00076
00077
00078
00079
00080
00081
00082 int GtkStatsLabel::
00083 get_height() const {
00084 return _height;
00085 }
00086
00087
00088
00089
00090
00091
00092 gint GtkStatsLabel::
00093 configure_event_impl(GdkEventConfigure *) {
00094 Gdk_Window window = get_window();
00095
00096 _gc = Gdk_GC(window);
00097 _gc.set_foreground(_fg_color);
00098 _gc.set_background(_bg_color);
00099 _gc.set_font(_font);
00100
00101 _reverse_gc = Gdk_GC(window);
00102 _reverse_gc.set_foreground(_bg_color);
00103 _reverse_gc.set_background(_fg_color);
00104 _reverse_gc.set_font(_font);
00105
00106 return true;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116 gint GtkStatsLabel::
00117 expose_event_impl(GdkEventExpose *event) {
00118 int text_width = _font.string_width(_text);
00119 int text_height = _font.height();
00120
00121 Gdk_Window window = get_window();
00122
00123 window.draw_rectangle(_reverse_gc, true, 0, 0, width(), height());
00124 window.draw_string(_font, _gc, width() - text_width - 2,
00125 height() - (height() - text_height) / 2 - _font.descent(),
00126 _text);
00127 return false;
00128 }
00129
00130
00131
00132
00133
00134
00135 gint GtkStatsLabel::
00136 button_press_event_impl(GdkEventButton *button) {
00137 if (button->type == GDK_2BUTTON_PRESS && button->button == 1) {
00138 collector_picked(_collector_index);
00139 return true;
00140 }
00141 return false;
00142 }