15 #include "winStatsGraph.h" 16 #include "winStatsMonitor.h" 17 #include "winStatsLabelStack.h" 19 bool WinStatsGraph::_graph_window_class_registered =
false;
20 const char *
const WinStatsGraph::_graph_window_class_name =
"graph";
22 DWORD WinStatsGraph::graph_window_style =
23 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW | WS_VISIBLE;
36 _sizewe_cursor = LoadCursor(NULL, IDC_SIZEWE);
37 _hand_cursor = LoadCursor(NULL, IDC_HAND);
46 _dark_color = RGB(51, 51, 51);
47 _light_color = RGB(154, 154, 154);
48 _user_guide_bar_color = RGB(130, 150, 255);
49 _dark_pen = CreatePen(PS_SOLID, 1, _dark_color);
50 _light_pen = CreatePen(PS_SOLID, 1, _light_color);
51 _user_guide_bar_pen = CreatePen(PS_DASH, 1, _user_guide_bar_color);
54 _potential_drag_mode = DM_none;
55 _drag_scale_start = 0.0f;
70 DeleteObject(_dark_pen);
71 DeleteObject(_light_pen);
72 DeleteObject(_user_guide_bar_pen);
75 for (bi = _brushes.begin(); bi != _brushes.end(); ++bi) {
76 HBRUSH brush = (*bi).second;
81 DestroyWindow(_graph_window);
86 DestroyWindow(_window);
171 InvalidateRect(_window, NULL, TRUE);
172 InvalidateRect(_graph_window, NULL, TRUE);
195 monitor->remove_graph(
this);
206 setup_label_stack() {
207 _label_stack.
setup(_window);
221 GetClientRect(_window, &rect);
224 rect.right = _left_margin - 8;
225 rect.bottom -= _bottom_margin;
227 _label_stack.
set_pos(rect.left, rect.top,
228 rect.right - rect.left, rect.bottom - rect.top);
238 HBRUSH WinStatsGraph::
239 get_collector_brush(
int collector_index) {
240 Brushes::iterator bi;
241 bi = _brushes.find(collector_index);
242 if (bi != _brushes.end()) {
248 int r = (int)(rgb[0] * 255.0f);
249 int g = (int)(rgb[1] * 255.0f);
250 int b = (int)(rgb[2] * 255.0f);
251 HBRUSH brush = CreateSolidBrush(RGB(r, g, b));
253 _brushes[collector_index] = brush;
265 window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
273 InvalidateRect(hwnd, NULL, TRUE);
277 set_drag_mode(DM_sizing);
280 case WM_EXITSIZEMOVE:
281 set_drag_mode(DM_none);
289 GetCursorPos(&point);
291 GetWindowInfo(hwnd, &winfo);
292 const RECT &rect = winfo.rcClient;
293 int x = point.x - rect.left;
294 int y = point.y - rect.top;
295 int width = rect.right - rect.left;
296 int height = rect.bottom - rect.top;
298 _potential_drag_mode = consider_drag_start(x, y, width, height);
300 switch (_potential_drag_mode) {
302 case DM_right_margin:
303 SetCursor(_sizewe_cursor);
307 SetCursor(_hand_cursor);
318 if (_potential_drag_mode != DM_none) {
319 set_drag_mode(_potential_drag_mode);
320 _drag_start_x = (PN_int16)LOWORD(lparam);
321 _drag_start_y = (PN_int16)HIWORD(lparam);
327 if (_drag_mode == DM_left_margin) {
328 PN_int16 x = LOWORD(lparam);
329 _left_margin += (x - _drag_start_x);
331 InvalidateRect(hwnd, NULL, TRUE);
335 }
else if (_drag_mode == DM_right_margin) {
336 PN_int16 x = LOWORD(lparam);
337 _right_margin += (_drag_start_x - x);
339 InvalidateRect(hwnd, NULL, TRUE);
345 set_drag_mode(DM_none);
352 HDC hdc = BeginPaint(hwnd, &ps);
356 GetClientRect(hwnd, &rect);
358 rect.left += _left_margin;
359 rect.top += _top_margin;
360 rect.right -= _right_margin;
361 rect.bottom -= _bottom_margin;
363 if (rect.right > rect.left && rect.bottom > rect.top) {
364 DrawEdge(hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
366 int graph_xsize = rect.right - rect.left;
367 int graph_ysize = rect.bottom - rect.top;
368 if (_bitmap_dc == 0 ||
369 graph_xsize != _bitmap_xsize ||
370 graph_ysize != _bitmap_ysize) {
373 move_graph_window(rect.left, rect.top, graph_xsize, graph_ysize);
378 additional_window_paint(hdc);
388 return DefWindowProc(hwnd, msg, wparam, lparam);
397 graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
399 case WM_DISPLAYCHANGE:
400 setup_bitmap(_bitmap_xsize, _bitmap_ysize);
407 if (_potential_drag_mode != DM_none) {
408 PN_int16 x = LOWORD(lparam) + _graph_left;
409 PN_int16 y = HIWORD(lparam) + _graph_top;
410 return window_proc(_window, msg, wparam, MAKELPARAM(x, y));
415 set_drag_mode(DM_none);
423 HDC hdc = BeginPaint(hwnd, &ps);
426 _bitmap_xsize, _bitmap_ysize,
430 additional_graph_window_paint(hdc);
440 return DefWindowProc(hwnd, msg, wparam, lparam);
452 additional_window_paint(HDC hdc) {
463 additional_graph_window_paint(HDC hdc) {
474 WinStatsGraph::DragMode WinStatsGraph::
475 consider_drag_start(
int mouse_x,
int mouse_y,
int width,
int height) {
476 if (mouse_x >= _left_margin - 2 && mouse_x <= _left_margin + 2) {
477 return DM_left_margin;
478 }
else if (mouse_x >= width - _right_margin - 2 && mouse_x <= width - _right_margin + 2) {
479 return DM_right_margin;
493 set_drag_mode(WinStatsGraph::DragMode drag_mode) {
494 _drag_mode = drag_mode;
504 move_graph_window(
int graph_left,
int graph_top,
int graph_xsize,
int graph_ysize) {
505 if (_graph_window == 0) {
506 create_graph_window();
509 _graph_left = graph_left;
510 _graph_top = graph_top;
512 SetWindowPos(_graph_window, 0,
513 _graph_left, _graph_top,
514 graph_xsize, graph_ysize,
515 SWP_NOZORDER | SWP_SHOWWINDOW);
517 if (graph_xsize != _bitmap_xsize || graph_ysize != _bitmap_ysize) {
518 setup_bitmap(graph_xsize, graph_ysize);
528 setup_bitmap(
int xsize,
int ysize) {
530 _bitmap_xsize = max(xsize, 0);
531 _bitmap_ysize = max(ysize, 0);
533 HDC hdc = GetDC(_graph_window);
534 _bitmap_dc = CreateCompatibleDC(hdc);
535 _bitmap = CreateCompatibleBitmap(hdc, _bitmap_xsize, _bitmap_ysize);
536 SelectObject(_bitmap_dc, _bitmap);
538 RECT rect = { 0, 0, _bitmap_xsize, _bitmap_ysize };
539 FillRect(_bitmap_dc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
541 ReleaseDC(_window, hdc);
553 DeleteObject(_bitmap);
557 DeleteDC(_bitmap_dc);
568 create_graph_window() {
573 HINSTANCE application = GetModuleHandle(NULL);
574 register_graph_window_class(application);
576 string window_title =
"graph";
577 DWORD window_style = WS_CHILD | WS_CLIPSIBLINGS;
580 CreateWindow(_graph_window_class_name, window_title.c_str(), window_style,
582 _window, NULL, application, 0);
583 if (!_graph_window) {
584 nout <<
"Could not create graph window!\n";
588 SetWindowLongPtr(_graph_window, 0, (LONG_PTR)
this);
598 register_graph_window_class(HINSTANCE application) {
599 if (_graph_window_class_registered) {
605 ZeroMemory(&wc,
sizeof(WNDCLASS));
606 wc.style = CS_DBLCLKS;
607 wc.lpfnWndProc = (WNDPROC)static_graph_window_proc;
608 wc.hInstance = application;
609 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
610 wc.hbrBackground = NULL;
611 wc.lpszMenuName = NULL;
612 wc.lpszClassName = _graph_window_class_name;
617 if (!RegisterClass(&wc)) {
618 nout <<
"Could not register graph window class!\n";
622 _graph_window_class_registered =
true;
630 LONG WINAPI WinStatsGraph::
631 static_graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
633 if (
self != (
WinStatsGraph *)NULL &&
self->_graph_window == hwnd) {
634 return self->graph_window_proc(hwnd, msg, wparam, lparam);
636 return DefWindowProc(hwnd, msg, wparam, lparam);
virtual void new_collector(int collector_index)
Called whenever a new Collector definition is received from the client.
bool is_setup() const
Returns true if the label stack has been set up, false otherwise.
This is the base class for all three-component vectors and points.
const LRGBColor & get_collector_color(int collector_index)
Returns the color associated with the indicated collector.
virtual void set_time_units(int unit_mask)
Called when the user selects a new time units from the monitor pulldown menu, this should adjust the ...
void user_guide_bars_changed()
Called when the user guide bars have been changed.
void setup(HWND parent_window)
Creates the actual window object.
virtual void changed_graph_size(int graph_xsize, int graph_ysize)
Called when the user has resized the window, forcing a resize of the graph.
virtual void set_scroll_speed(double scroll_speed)
Called when the user selects a new scroll speed from the monitor pulldown menu, this should adjust th...
This is just an abstract base class to provide a common pointer type for the various kinds of graphs ...
This class represents a connection to a PStatsClient and manages the data exchange with the client...
void set_pause(bool pause)
Changes the pause flag for the graph.
virtual void new_data(int thread_index, int frame_number)
Called whenever new data arrives.
virtual void force_redraw()
Called when it is necessary to redraw the entire graph.
void set_pos(int x, int y, int width, int height)
Sets the position and size of the label stack on its parent.
virtual void clicked_label(int collector_index)
Called when the user single-clicks on a label.