15 #include "winStatsLabel.h"
16 #include "winStatsMonitor.h"
17 #include "winStatsGraph.h"
19 int WinStatsLabel::_left_margin = 2;
20 int WinStatsLabel::_right_margin = 2;
21 int WinStatsLabel::_top_margin = 2;
22 int WinStatsLabel::_bottom_margin = 2;
24 bool WinStatsLabel::_window_class_registered =
false;
25 const char *
const WinStatsLabel::_window_class_name =
"label";
34 int thread_index,
int collector_index,
bool use_fullname) :
37 _thread_index(thread_index),
38 _collector_index(collector_index)
48 int r = (int)(rgb[0] * 255.0f);
49 int g = (int)(rgb[1] * 255.0f);
50 int b = (int)(rgb[2] * 255.0f);
51 _bg_color = RGB(r, g, b);
52 _bg_brush = CreateSolidBrush(RGB(r, g, b));
61 _fg_color = RGB(0, 0, 0);
62 _highlight_brush = (HBRUSH)GetStockObject(BLACK_BRUSH);
64 _fg_color = RGB(255, 255, 255);
65 _highlight_brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
74 _mouse_within =
false;
85 DestroyWindow(_window);
88 DeleteObject(_bg_brush);
99 DestroyWindow(_window);
103 create_window(parent_window);
105 HDC hdc = GetDC(_window);
106 HFONT hfnt = (HFONT)GetStockObject(ANSI_VAR_FONT);
107 SelectObject(hdc, hfnt);
110 GetTextExtentPoint32(hdc, _text.data(), _text.length(), &size);
111 _height = size.cy + _top_margin + _bottom_margin;
112 _ideal_width = size.cx + _left_margin + _right_margin;
114 ReleaseDC(_window, hdc);
129 SetWindowPos(_window, 0, x, y - _height, _width, _height,
130 SWP_NOZORDER | SWP_SHOWWINDOW);
190 return _collector_index;
201 if (_highlight != highlight) {
202 _highlight = highlight;
203 InvalidateRect(_window, NULL, TRUE);
225 set_mouse_within(
bool mouse_within) {
226 if (_mouse_within != mouse_within) {
227 _mouse_within = mouse_within;
228 InvalidateRect(_window, NULL, TRUE);
238 create_window(HWND parent_window) {
243 HINSTANCE application = GetModuleHandle(NULL);
244 register_window_class(application);
247 CreateWindow(_window_class_name, _text.c_str(), WS_CHILD | WS_CLIPSIBLINGS,
249 parent_window, NULL, application, 0);
251 nout <<
"Could not create Label window!\n";
255 SetWindowLongPtr(_window, 0, (LONG_PTR)
this);
265 register_window_class(HINSTANCE application) {
266 if (_window_class_registered) {
272 ZeroMemory(&wc,
sizeof(WNDCLASS));
273 wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
274 wc.lpfnWndProc = (WNDPROC)static_window_proc;
275 wc.hInstance = application;
276 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
277 wc.hbrBackground = NULL;
278 wc.lpszMenuName = NULL;
279 wc.lpszClassName = _window_class_name;
284 if (!RegisterClass(&wc)) {
285 nout <<
"Could not register Label window class!\n";
289 _window_class_registered =
true;
297 LONG WINAPI WinStatsLabel::
298 static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
300 if (
self != (
WinStatsLabel *)NULL &&
self->_window == hwnd) {
301 return self->window_proc(hwnd, msg, wparam, lparam);
303 return DefWindowProc(hwnd, msg, wparam, lparam);
313 window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
315 case WM_LBUTTONDBLCLK:
322 set_mouse_within(
true);
326 TRACKMOUSEEVENT tme = {
327 sizeof(TRACKMOUSEEVENT),
332 TrackMouseEvent(&tme);
337 set_mouse_within(
false);
343 HDC hdc = BeginPaint(hwnd, &ps);
345 RECT rect = { 0, 0, _width, _height };
346 FillRect(hdc, &rect, _bg_brush);
348 if (_highlight || _mouse_within) {
349 FrameRect(hdc, &rect, _highlight_brush);
352 HFONT hfnt = (HFONT)GetStockObject(ANSI_VAR_FONT);
353 SelectObject(hdc, hfnt);
354 SetTextAlign(hdc, TA_RIGHT | TA_TOP);
356 SetBkColor(hdc, _bg_color);
357 SetBkMode(hdc, OPAQUE);
358 SetTextColor(hdc, _fg_color);
360 TextOut(hdc, _width - _right_margin, _top_margin,
361 _text.data(), _text.length());
370 return DefWindowProc(hwnd, msg, wparam, lparam);
This is the base class for all three-component vectors and points.
int get_ideal_width() const
Returns the width the label would really prefer to be.
string get_collector_name(int index) const
Returns the name of the indicated collector.
const LRGBColor & get_collector_color(int collector_index)
Returns the color associated with the indicated collector.
int get_y() const
Returns the y position of the label on its parent.
string get_collector_fullname(int index) const
Returns the "full name" of the indicated collector.
int get_collector_index() const
Returns the collector this label represents.
A text label that will draw in color appropriate for a particular collector.
int get_height() const
Returns the height of the label as we requested it.
void set_highlight(bool highlight)
Enables or disables the visual highlight for this label.
This is just an abstract base class to provide a common pointer type for the various kinds of graphs ...
int get_x() const
Returns the x position of the label on its parent.
This class represents a connection to a PStatsClient and manages the data exchange with the client...
bool get_highlight() const
Returns true if the visual highlight for this label is enabled.
const PStatClientData * get_client_data() const
Returns the client data associated with this monitor.
int get_width() const
Returns the width of the label as we requested it.
void setup(HWND parent_window)
Creates the actual window.
void set_pos(int x, int y, int width)
Sets the position of the label on its parent.
virtual void clicked_label(int collector_index)
Called when the user single-clicks on a label.