mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 17:35:34 -04:00
clicking on labels change focus, not create new graph
This commit is contained in:
parent
a25b9372ea
commit
eb951840cc
@ -20,10 +20,10 @@
|
||||
#include "pStatClientData.h"
|
||||
#include "pStatMonitor.h"
|
||||
|
||||
#include <pStatFrameData.h>
|
||||
#include <pStatCollectorDef.h>
|
||||
#include <string_utils.h>
|
||||
#include <config_pstats.h>
|
||||
#include "pStatFrameData.h"
|
||||
#include "pStatCollectorDef.h"
|
||||
#include "string_utils.h"
|
||||
#include "config_pstats.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -140,6 +140,23 @@ first_data() const {
|
||||
return _first_data;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PStatStripChart::set_collector_index
|
||||
// Access: Public
|
||||
// Description: Changes the collector represented by this strip
|
||||
// chart. This may force a redraw.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PStatStripChart::
|
||||
set_collector_index(int collector_index) {
|
||||
if (_collector_index != collector_index) {
|
||||
_collector_index = collector_index;
|
||||
_title_unknown = true;
|
||||
_data.clear();
|
||||
force_redraw();
|
||||
update_labels();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PStatStripChart::set_default_vertical_scale
|
||||
// Access: Public
|
||||
|
@ -55,6 +55,7 @@ public:
|
||||
|
||||
INLINE PStatView &get_view() const;
|
||||
INLINE int get_collector_index() const;
|
||||
void set_collector_index(int collector_index);
|
||||
|
||||
INLINE void set_horizontal_scale(float time_width);
|
||||
INLINE float get_horizontal_scale() const;
|
||||
|
@ -174,6 +174,15 @@ user_guide_bars_changed() {
|
||||
InvalidateRect(_graph_window, NULL, TRUE);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinStatsGraph::clicked_label
|
||||
// Access: Public, Virtual
|
||||
// Description: Called when the user single-clicks on a label.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void WinStatsGraph::
|
||||
clicked_label(int collector_index) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinStatsGraph::close
|
||||
// Access: Protected
|
||||
@ -576,7 +585,7 @@ register_graph_window_class(HINSTANCE application) {
|
||||
WNDCLASS wc;
|
||||
|
||||
ZeroMemory(&wc, sizeof(WNDCLASS));
|
||||
wc.style = 0;
|
||||
wc.style = CS_DBLCLKS;
|
||||
wc.lpfnWndProc = (WNDPROC)static_graph_window_proc;
|
||||
wc.hInstance = application;
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
virtual void set_time_units(int unit_mask);
|
||||
virtual void set_scroll_speed(float scroll_speed);
|
||||
void user_guide_bars_changed();
|
||||
virtual void clicked_label(int collector_index);
|
||||
|
||||
protected:
|
||||
void close();
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "winStatsLabel.h"
|
||||
#include "winStatsMonitor.h"
|
||||
#include "winStatsGraph.h"
|
||||
|
||||
int WinStatsLabel::_left_margin = 2;
|
||||
int WinStatsLabel::_right_margin = 2;
|
||||
@ -33,9 +34,10 @@ const char * const WinStatsLabel::_window_class_name = "label";
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
WinStatsLabel::
|
||||
WinStatsLabel(WinStatsMonitor *monitor, int thread_index,
|
||||
int collector_index, bool use_fullname) :
|
||||
WinStatsLabel(WinStatsMonitor *monitor, WinStatsGraph *graph,
|
||||
int thread_index, int collector_index, bool use_fullname) :
|
||||
_monitor(monitor),
|
||||
_graph(graph),
|
||||
_thread_index(thread_index),
|
||||
_collector_index(collector_index)
|
||||
{
|
||||
@ -315,16 +317,16 @@ LONG WinStatsLabel::
|
||||
window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
switch (msg) {
|
||||
case WM_LBUTTONDBLCLK:
|
||||
_monitor->open_strip_chart(_thread_index, _collector_index);
|
||||
_graph->clicked_label(_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.
|
||||
// label.
|
||||
TRACKMOUSEEVENT tme = {
|
||||
sizeof(TRACKMOUSEEVENT),
|
||||
TME_LEAVE,
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <windows.h>
|
||||
|
||||
class WinStatsMonitor;
|
||||
class WinStatsGraph;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : WinStatsLabel
|
||||
@ -34,8 +35,8 @@ class WinStatsMonitor;
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class WinStatsLabel {
|
||||
public:
|
||||
WinStatsLabel(WinStatsMonitor *monitor, int thread_index,
|
||||
int collector_index, bool use_fullname);
|
||||
WinStatsLabel(WinStatsMonitor *monitor, WinStatsGraph *graph,
|
||||
int thread_index, int collector_index, bool use_fullname);
|
||||
~WinStatsLabel();
|
||||
|
||||
void setup(HWND parent_window);
|
||||
@ -62,6 +63,7 @@ private:
|
||||
LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
|
||||
|
||||
WinStatsMonitor *_monitor;
|
||||
WinStatsGraph *_graph;
|
||||
int _thread_index;
|
||||
int _collector_index;
|
||||
string _text;
|
||||
|
@ -30,8 +30,6 @@ const char * const WinStatsLabelStack::_window_class_name = "stack";
|
||||
////////////////////////////////////////////////////////////////////
|
||||
WinStatsLabelStack::
|
||||
WinStatsLabelStack() {
|
||||
_window = 0;
|
||||
|
||||
_x = 0;
|
||||
_y = 0;
|
||||
_width = 0;
|
||||
@ -185,6 +183,18 @@ get_label_height(int label_index) const {
|
||||
return _labels[label_index]->get_height();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinStatsLabelStack::get_label_collector_index
|
||||
// Access: Public
|
||||
// Description: Returns the collector index associated with the
|
||||
// indicated label.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int WinStatsLabelStack::
|
||||
get_label_collector_index(int label_index) const {
|
||||
nassertr(label_index >= 0 && label_index < (int)_labels.size(), -1);
|
||||
return _labels[label_index]->get_collector_index();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinStatsLabelStack::clear_labels
|
||||
// Access: Public
|
||||
@ -207,15 +217,15 @@ clear_labels() {
|
||||
// new label index.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int WinStatsLabelStack::
|
||||
add_label(WinStatsMonitor *monitor, int thread_index, int collector_index,
|
||||
bool use_fullname) {
|
||||
add_label(WinStatsMonitor *monitor, WinStatsGraph *graph,
|
||||
int thread_index, int collector_index, bool use_fullname) {
|
||||
int yp = _height;
|
||||
if (!_labels.empty()) {
|
||||
WinStatsLabel *top_label = _labels.back();
|
||||
yp = top_label->get_y() - top_label->get_height();
|
||||
}
|
||||
WinStatsLabel *label =
|
||||
new WinStatsLabel(monitor, thread_index, collector_index, use_fullname);
|
||||
new WinStatsLabel(monitor, graph, thread_index, collector_index, use_fullname);
|
||||
if (_window) {
|
||||
label->setup(_window);
|
||||
label->set_pos(0, yp, _width);
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
class WinStatsLabel;
|
||||
class WinStatsMonitor;
|
||||
class WinStatsGraph;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : WinStatsLabelStack
|
||||
@ -49,10 +50,11 @@ public:
|
||||
|
||||
int get_label_y(int label_index) const;
|
||||
int get_label_height(int label_index) const;
|
||||
int get_label_collector_index(int label_index) const;
|
||||
|
||||
void clear_labels();
|
||||
int add_label(WinStatsMonitor *monitor, int thread_index,
|
||||
int collector_index, bool use_fullname);
|
||||
int add_label(WinStatsMonitor *monitor, WinStatsGraph *graph,
|
||||
int thread_index, int collector_index, bool use_fullname);
|
||||
int get_num_labels() const;
|
||||
|
||||
void highlight_label(int collector_index);
|
||||
|
@ -117,6 +117,18 @@ set_time_units(int unit_mask) {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinStatsPianoRoll::clicked_label
|
||||
// Access: Public, Virtual
|
||||
// Description: Called when the user single-clicks on a label.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void WinStatsPianoRoll::
|
||||
clicked_label(int collector_index) {
|
||||
if (collector_index >= 0) {
|
||||
WinStatsGraph::_monitor->open_strip_chart(WinStatsGraph::_thread_index, collector_index);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinStatsPianoRoll::set_horizontal_scale
|
||||
// Access: Public
|
||||
@ -254,6 +266,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 x = LOWORD(lparam);
|
||||
float ratio = (float)x / (float)get_xsize();
|
||||
@ -279,6 +312,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;
|
||||
@ -298,6 +336,17 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_LBUTTONDBLCLK:
|
||||
{
|
||||
// Double-clicking on a color bar in the graph is the same as
|
||||
// double-clicking on the corresponding label.
|
||||
PN_int16 x = LOWORD(lparam);
|
||||
PN_int16 y = HIWORD(lparam);
|
||||
clicked_label(get_collector_under_pixel(x, y));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -382,6 +431,28 @@ consider_drag_start(int mouse_x, int mouse_y, int width, int height) {
|
||||
return WinStatsGraph::consider_drag_start(mouse_x, mouse_y, width, height);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinStatsPianoRoll::get_collector_under_pixel
|
||||
// Access: Private
|
||||
// Description: Returns the collector index associated with the
|
||||
// indicated vertical row, or -1.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int WinStatsPianoRoll::
|
||||
get_collector_under_pixel(int xpoint, int ypoint) {
|
||||
if (_label_stack.get_num_labels() == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Assume all of the labels are the same height.
|
||||
int height = _label_stack.get_label_height(0);
|
||||
int row = (get_ysize() - ypoint) / height;
|
||||
if (row >= 0 && row < _label_stack.get_num_labels()) {
|
||||
return _label_stack.get_label_collector_index(row);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinStatsPianoRoll::update_labels
|
||||
// Access: Private
|
||||
@ -392,7 +463,7 @@ update_labels() {
|
||||
_label_stack.clear_labels();
|
||||
for (int i = 0; i < get_num_labels(); i++) {
|
||||
int label_index =
|
||||
_label_stack.add_label(WinStatsGraph::_monitor,
|
||||
_label_stack.add_label(WinStatsGraph::_monitor, this,
|
||||
WinStatsGraph::_thread_index,
|
||||
get_label_collector(i), true);
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
virtual void changed_graph_size(int graph_xsize, int graph_ysize);
|
||||
|
||||
virtual void set_time_units(int unit_mask);
|
||||
virtual void clicked_label(int collector_index);
|
||||
void set_horizontal_scale(float time_width);
|
||||
|
||||
protected:
|
||||
@ -62,6 +63,7 @@ protected:
|
||||
int width, int height);
|
||||
|
||||
private:
|
||||
int get_collector_under_pixel(int xpoint, int ypoint);
|
||||
void update_labels();
|
||||
void draw_guide_bar(HDC hdc, const GuideBar &bar);
|
||||
void draw_guide_label(HDC hdc, int y, const PStatGraph::GuideBar &bar);
|
||||
|
@ -153,6 +153,35 @@ set_scroll_speed(float scroll_speed) {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinStatsStripChart::clicked_label
|
||||
// Access: Public, Virtual
|
||||
// Description: Called when the user single-clicks on a label.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void WinStatsStripChart::
|
||||
clicked_label(int collector_index) {
|
||||
if (collector_index < 0) {
|
||||
// Clicking on whitespace in the graph is the same as clicking on
|
||||
// the top label.
|
||||
collector_index = get_collector_index();
|
||||
}
|
||||
|
||||
if (collector_index == get_collector_index() && collector_index != 0) {
|
||||
// Clicking on the top label means to go up to the parent level.
|
||||
const PStatClientData *client_data =
|
||||
WinStatsGraph::_monitor->get_client_data();
|
||||
if (client_data->has_collector(collector_index)) {
|
||||
const PStatCollectorDef &def =
|
||||
client_data->get_collector_def(collector_index);
|
||||
set_collector_index(def._parent_index);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Clicking on any other label means to focus on that.
|
||||
set_collector_index(collector_index);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: WinStatsStripChart::set_vertical_scale
|
||||
// Access: Public
|
||||
@ -180,7 +209,7 @@ update_labels() {
|
||||
|
||||
_label_stack.clear_labels();
|
||||
for (int i = 0; i < get_num_labels(); i++) {
|
||||
_label_stack.add_label(WinStatsGraph::_monitor, _thread_index,
|
||||
_label_stack.add_label(WinStatsGraph::_monitor, this, _thread_index,
|
||||
get_label_collector(i), false);
|
||||
}
|
||||
_labels_changed = false;
|
||||
@ -427,6 +456,17 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_LBUTTONDBLCLK:
|
||||
{
|
||||
// Double-clicking on a color bar in the graph is the same as
|
||||
// double-clicking on the corresponding label.
|
||||
PN_int16 x = LOWORD(lparam);
|
||||
PN_int16 y = HIWORD(lparam);
|
||||
clicked_label(get_collector_under_pixel(x, y));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
|
||||
virtual void set_time_units(int unit_mask);
|
||||
virtual void set_scroll_speed(float scroll_speed);
|
||||
virtual void clicked_label(int collector_index);
|
||||
void set_vertical_scale(float value_height);
|
||||
|
||||
protected:
|
||||
|
Loading…
x
Reference in New Issue
Block a user