18 int WinStatsLabel::_left_margin = 2;
19 int WinStatsLabel::_right_margin = 2;
20 int WinStatsLabel::_top_margin = 2;
21 int WinStatsLabel::_bottom_margin = 2;
23 bool WinStatsLabel::_window_class_registered =
false;
24 const char *
const WinStatsLabel::_window_class_name =
"label";
31 int thread_index,
int collector_index,
bool use_fullname) :
34 _thread_index(thread_index),
35 _collector_index(collector_index)
45 int r = (int)(rgb[0] * 255.0f);
46 int g = (int)(rgb[1] * 255.0f);
47 int b = (int)(rgb[2] * 255.0f);
48 _bg_color = RGB(r, g, b);
49 _bg_brush = CreateSolidBrush(RGB(r, g, b));
58 _fg_color = RGB(0, 0, 0);
59 _highlight_brush = (HBRUSH)GetStockObject(BLACK_BRUSH);
61 _fg_color = RGB(255, 255, 255);
62 _highlight_brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
71 _mouse_within =
false;
80 DestroyWindow(_window);
83 DeleteObject(_bg_brush);
92 DestroyWindow(_window);
96 create_window(parent_window);
98 HDC hdc = GetDC(_window);
99 HFONT hfnt = (HFONT)GetStockObject(ANSI_VAR_FONT);
100 SelectObject(hdc, hfnt);
103 GetTextExtentPoint32(hdc, _text.data(), _text.length(), &size);
104 _height = size.cy + _top_margin + _bottom_margin;
105 _ideal_width = size.cx + _left_margin + _right_margin;
107 ReleaseDC(_window, hdc);
119 SetWindowPos(_window, 0, x, y - _height, _width, _height,
120 SWP_NOZORDER | SWP_SHOWWINDOW);
168 return _collector_index;
176 if (_highlight != highlight) {
177 _highlight = highlight;
178 InvalidateRect(_window,
nullptr, TRUE);
194 set_mouse_within(
bool mouse_within) {
195 if (_mouse_within != mouse_within) {
196 _mouse_within = mouse_within;
197 InvalidateRect(_window,
nullptr, TRUE);
205 create_window(HWND parent_window) {
210 HINSTANCE application = GetModuleHandle(
nullptr);
211 register_window_class(application);
214 CreateWindow(_window_class_name, _text.c_str(), WS_CHILD | WS_CLIPSIBLINGS,
216 parent_window,
nullptr, application, 0);
218 nout <<
"Could not create Label window!\n";
222 SetWindowLongPtr(_window, 0, (LONG_PTR)
this);
230 register_window_class(HINSTANCE application) {
231 if (_window_class_registered) {
237 ZeroMemory(&wc,
sizeof(WNDCLASS));
238 wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
239 wc.lpfnWndProc = (WNDPROC)static_window_proc;
240 wc.hInstance = application;
241 wc.hCursor = LoadCursor(
nullptr, IDC_ARROW);
242 wc.hbrBackground =
nullptr;
243 wc.lpszMenuName =
nullptr;
244 wc.lpszClassName = _window_class_name;
249 if (!RegisterClass(&wc)) {
250 nout <<
"Could not register Label window class!\n";
254 _window_class_registered =
true;
260 LONG WINAPI WinStatsLabel::
261 static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
263 if (
self !=
nullptr && self->_window == hwnd) {
264 return self->window_proc(hwnd, msg, wparam, lparam);
266 return DefWindowProc(hwnd, msg, wparam, lparam);
274 window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
276 case WM_LBUTTONDBLCLK:
283 set_mouse_within(
true);
286 TRACKMOUSEEVENT tme = {
287 sizeof(TRACKMOUSEEVENT),
292 TrackMouseEvent(&tme);
297 set_mouse_within(
false);
303 HDC hdc = BeginPaint(hwnd, &ps);
305 RECT rect = { 0, 0, _width, _height };
306 FillRect(hdc, &rect, _bg_brush);
308 if (_highlight || _mouse_within) {
309 FrameRect(hdc, &rect, _highlight_brush);
312 HFONT hfnt = (HFONT)GetStockObject(ANSI_VAR_FONT);
313 SelectObject(hdc, hfnt);
314 SetTextAlign(hdc, TA_RIGHT | TA_TOP);
316 SetBkColor(hdc, _bg_color);
317 SetBkMode(hdc, OPAQUE);
318 SetTextColor(hdc, _fg_color);
320 TextOut(hdc, _width - _right_margin, _top_margin,
321 _text.data(), _text.length());
330 return DefWindowProc(hwnd, msg, wparam, lparam);
int get_x() const
Returns the x position of the label on its parent.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const LRGBColor & get_collector_color(int collector_index)
Returns the color associated with the indicated collector.
int get_height() const
Returns the height of the label as we requested it.
std::string get_collector_fullname(int index) const
Returns the "full name" of the indicated collector.
A text label that will draw in color appropriate for a particular collector.
std::string get_collector_name(int index) const
Returns the name of the indicated collector.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_width() const
Returns the width of the label as we requested it.
void set_highlight(bool highlight)
Enables or disables the visual highlight for this label.
bool get_highlight() const
Returns true if the visual highlight for this label is enabled.
int get_ideal_width() const
Returns the width the label would really prefer to be.
This is just an abstract base class to provide a common pointer type for the various kinds of graphs ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class represents a connection to a PStatsClient and manages the data exchange with the client.
int get_collector_index() const
Returns the collector this label represents.
int get_y() const
Returns the y position of the label on its parent.
const PStatClientData * get_client_data() const
Returns the client data associated with this monitor.
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.