diff --git a/pandatool/src/win-stats/winStatsLabel.cxx b/pandatool/src/win-stats/winStatsLabel.cxx index 31ba550823..00ecfa7686 100755 --- a/pandatool/src/win-stats/winStatsLabel.cxx +++ b/pandatool/src/win-stats/winStatsLabel.cxx @@ -61,8 +61,10 @@ WinStatsLabel(WinStatsMonitor *monitor, int thread_index, if (bright >= 0.5) { _fg_color = RGB(0, 0, 0); + _highlight_brush = (HBRUSH)GetStockObject(BLACK_BRUSH); } else { _fg_color = RGB(255, 255, 255); + _highlight_brush = (HBRUSH)GetStockObject(WHITE_BRUSH); } _x = 0; @@ -70,6 +72,8 @@ WinStatsLabel(WinStatsMonitor *monitor, int thread_index, _width = 0; _height = 0; _ideal_width = 0; + _highlight = false; + _mouse_within = false; } //////////////////////////////////////////////////////////////////// @@ -178,6 +182,55 @@ get_ideal_width() const { return _ideal_width; } +//////////////////////////////////////////////////////////////////// +// Function: WinStatsLabel::get_collector_index +// Access: Public +// Description: Returns the collector this label represents. +//////////////////////////////////////////////////////////////////// +int WinStatsLabel:: +get_collector_index() const { + return _collector_index; +} + +//////////////////////////////////////////////////////////////////// +// Function: WinStatsLabel::set_highlight +// Access: Public +// Description: Enables or disables the visual highlight for this +// label. +//////////////////////////////////////////////////////////////////// +void WinStatsLabel:: +set_highlight(bool highlight) { + if (_highlight != highlight) { + _highlight = highlight; + InvalidateRect(_window, NULL, TRUE); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: WinStatsLabel::get_highlight +// Access: Public +// Description: Returns true if the visual highlight for this +// label is enabled. +//////////////////////////////////////////////////////////////////// +bool WinStatsLabel:: +get_highlight() const { + return _highlight; +} + +//////////////////////////////////////////////////////////////////// +// Function: WinStatsLabel::set_mouse_within +// Access: Private +// Description: Used internally to indicate whether the mouse is +// within the label's window. +//////////////////////////////////////////////////////////////////// +void WinStatsLabel:: +set_mouse_within(bool mouse_within) { + if (_mouse_within != mouse_within) { + _mouse_within = mouse_within; + InvalidateRect(_window, NULL, TRUE); + } +} + //////////////////////////////////////////////////////////////////// // Function: WinStatsLabel::create_window // Access: Private @@ -265,6 +318,27 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { _monitor->open_strip_chart(_thread_index, _collector_index); return 0; + case WM_MOUSEMOVE: + { + // When the mouse enters the label area, highlight the label. + set_mouse_within(true); + + // Now we want to get a WM_MOUSELEAVE when the mouse leaves the + // graph window. + TRACKMOUSEEVENT tme = { + sizeof(TRACKMOUSEEVENT), + TME_LEAVE, + _window, + 0 + }; + TrackMouseEvent(&tme); + } + break; + + case WM_MOUSELEAVE: + set_mouse_within(false); + break; + case WM_PAINT: { PAINTSTRUCT ps; @@ -273,6 +347,10 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { RECT rect = { 0, 0, _width, _height }; FillRect(hdc, &rect, _bg_brush); + if (_highlight || _mouse_within) { + FrameRect(hdc, &rect, _highlight_brush); + } + HFONT hfnt = (HFONT)GetStockObject(ANSI_VAR_FONT); SelectObject(hdc, hfnt); SetTextAlign(hdc, TA_RIGHT | TA_TOP); diff --git a/pandatool/src/win-stats/winStatsLabel.h b/pandatool/src/win-stats/winStatsLabel.h index fd0172133f..5ba79cf8f7 100755 --- a/pandatool/src/win-stats/winStatsLabel.h +++ b/pandatool/src/win-stats/winStatsLabel.h @@ -47,7 +47,14 @@ public: int get_height() const; int get_ideal_width() const; + int get_collector_index() const; + + void set_highlight(bool highlight); + bool get_highlight() const; + private: + void set_mouse_within(bool mouse_within); + void create_window(HWND parent_window); static void register_window_class(HINSTANCE application); @@ -62,12 +69,15 @@ private: COLORREF _bg_color; COLORREF _fg_color; HBRUSH _bg_brush; + HBRUSH _highlight_brush; int _x; int _y; int _width; int _height; int _ideal_width; + bool _highlight; + bool _mouse_within; static int _left_margin, _right_margin; static int _top_margin, _bottom_margin; diff --git a/pandatool/src/win-stats/winStatsLabelStack.cxx b/pandatool/src/win-stats/winStatsLabelStack.cxx index 8035bf39c7..bf5569e8e5 100755 --- a/pandatool/src/win-stats/winStatsLabelStack.cxx +++ b/pandatool/src/win-stats/winStatsLabelStack.cxx @@ -37,6 +37,8 @@ WinStatsLabelStack() { _width = 0; _height = 0; _ideal_width = 0; + + _highlight_label = -1; } //////////////////////////////////////////////////////////////////// @@ -236,6 +238,26 @@ get_num_labels() const { return _labels.size(); } +//////////////////////////////////////////////////////////////////// +// Function: WinStatsLabelStack::highlight_label +// Access: Public +// Description: Draws a highlight around the label representing the +// indicated collector, and removes the highlight from +// any other label. Specify -1 to remove the highlight +// from all labels. +//////////////////////////////////////////////////////////////////// +void WinStatsLabelStack:: +highlight_label(int collector_index) { + if (_highlight_label != collector_index) { + _highlight_label = collector_index; + Labels::iterator li; + for (li = _labels.begin(); li != _labels.end(); ++li) { + WinStatsLabel *label = (*li); + label->set_highlight(label->get_collector_index() == _highlight_label); + } + } +} + //////////////////////////////////////////////////////////////////// // Function: WinStatsLabelStack::create_window diff --git a/pandatool/src/win-stats/winStatsLabelStack.h b/pandatool/src/win-stats/winStatsLabelStack.h index 90b6026be5..08af74924c 100755 --- a/pandatool/src/win-stats/winStatsLabelStack.h +++ b/pandatool/src/win-stats/winStatsLabelStack.h @@ -55,6 +55,8 @@ public: int collector_index, bool use_fullname); int get_num_labels() const; + void highlight_label(int collector_index); + private: void create_window(HWND parent_window); static void register_window_class(HINSTANCE application); @@ -68,6 +70,7 @@ private: int _width; int _height; int _ideal_width; + int _highlight_label; typedef pvector Labels; Labels _labels; diff --git a/pandatool/src/win-stats/winStatsStripChart.cxx b/pandatool/src/win-stats/winStatsStripChart.cxx index 049b6312bb..dbe8992946 100644 --- a/pandatool/src/win-stats/winStatsStripChart.cxx +++ b/pandatool/src/win-stats/winStatsStripChart.cxx @@ -357,6 +357,27 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { break; case WM_MOUSEMOVE: + if (_drag_mode == DM_none && _potential_drag_mode == DM_none) { + // When the mouse is over a color bar, highlight it. + PN_int16 x = LOWORD(lparam); + PN_int16 y = HIWORD(lparam); + _label_stack.highlight_label(get_collector_under_pixel(x, y)); + + // Now we want to get a WM_MOUSELEAVE when the mouse leaves the + // graph window. + TRACKMOUSEEVENT tme = { + sizeof(TRACKMOUSEEVENT), + TME_LEAVE, + _graph_window, + 0 + }; + TrackMouseEvent(&tme); + + } else { + // If the mouse is in some drag mode, stop highlighting. + _label_stack.highlight_label(-1); + } + if (_drag_mode == DM_scale) { PN_int16 y = HIWORD(lparam); float ratio = 1.0f - ((float)y / (float)get_ysize()); @@ -382,6 +403,11 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { } break; + case WM_MOUSELEAVE: + // When the mouse leaves the graph, stop highlighting. + _label_stack.highlight_label(-1); + break; + case WM_LBUTTONUP: if (_drag_mode == DM_scale) { _drag_mode = DM_none;