15 #include "winStatsLabelStack.h" 16 #include "winStatsLabel.h" 19 bool WinStatsLabelStack::_window_class_registered =
false;
20 const char *
const WinStatsLabelStack::_window_class_name =
"stack";
28 WinStatsLabelStack() {
35 _highlight_label = -1;
44 ~WinStatsLabelStack() {
47 DestroyWindow(_window);
60 DestroyWindow(_window);
64 create_window(parent_window);
68 for (li = _labels.begin(); li != _labels.end(); ++li) {
70 label->
setup(_window);
83 return (_window != 0);
92 set_pos(
int x,
int y,
int width,
int height) {
97 SetWindowPos(_window, 0, x, y, _width, _height,
98 SWP_NOZORDER | SWP_SHOWWINDOW);
102 for (li = _labels.begin(); li != _labels.end(); ++li) {
167 nassertr(label_index >= 0 && label_index < (
int)_labels.size(), 0);
168 return _labels[label_index]->get_y() +
get_y();
178 nassertr(label_index >= 0 && label_index < (
int)_labels.size(), 0);
179 return _labels[label_index]->get_height();
190 nassertr(label_index >= 0 && label_index < (
int)_labels.size(), -1);
191 return _labels[label_index]->get_collector_index();
202 for (li = _labels.begin(); li != _labels.end(); ++li) {
217 int thread_index,
int collector_index,
bool use_fullname) {
219 if (!_labels.empty()) {
224 new WinStatsLabel(monitor, graph, thread_index, collector_index, use_fullname);
226 label->
setup(_window);
231 int label_index = (int)_labels.size();
232 _labels.push_back(label);
244 return _labels.size();
257 if (_highlight_label != collector_index) {
258 _highlight_label = collector_index;
260 for (li = _labels.begin(); li != _labels.end(); ++li) {
273 void WinStatsLabelStack::
274 create_window(HWND parent_window) {
279 HINSTANCE application = GetModuleHandle(NULL);
280 register_window_class(application);
283 CreateWindow(_window_class_name,
"label stack", WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
285 parent_window, NULL, application, 0);
287 nout <<
"Could not create Label Stack window!\n";
291 SetWindowLongPtr(_window, 0, (LONG_PTR)
this);
300 void WinStatsLabelStack::
301 register_window_class(HINSTANCE application) {
302 if (_window_class_registered) {
308 ZeroMemory(&wc,
sizeof(WNDCLASS));
310 wc.lpfnWndProc = (WNDPROC)static_window_proc;
311 wc.hInstance = application;
312 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
313 wc.lpszMenuName = NULL;
314 wc.lpszClassName = _window_class_name;
319 if (!RegisterClass(&wc)) {
320 nout <<
"Could not register Label Stack window class!\n";
324 _window_class_registered =
true;
332 LONG WINAPI WinStatsLabelStack::
333 static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
336 return self->window_proc(hwnd, msg, wparam, lparam);
338 return DefWindowProc(hwnd, msg, wparam, lparam);
347 LONG WinStatsLabelStack::
348 window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
353 HDC hdc = BeginPaint(hwnd, &ps);
355 RECT rect = { 0, 0, _width, _height };
356 FillRect(hdc, &rect, (HBRUSH)COLOR_BACKGROUND);
365 return DefWindowProc(hwnd, msg, wparam, lparam);
bool is_setup() const
Returns true if the label stack has been set up, false otherwise.
int get_y() const
Returns the y position of the stack on its parent.
int get_height() const
Returns the height of the label as we requested it.
void setup(HWND parent_window)
Creates the actual window object.
A text label that will draw in color appropriate for a particular collector.
int get_label_height(int label_index) const
Returns the height of the indicated label.
void set_highlight(bool highlight)
Enables or disables the visual highlight for this label.
int get_ideal_width() const
Returns the width the stack would really prefer to be.
A window that contains a stack of labels from bottom to top.
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 ...
void clear_labels()
Removes the set of labels and starts a new set.
This class represents a connection to a PStatsClient and manages the data exchange with the client...
int get_height() const
Returns the height of the stack as we requested it.
int add_label(WinStatsMonitor *monitor, WinStatsGraph *graph, int thread_index, int collector_index, bool use_fullname)
Adds a new label to the top of the stack; returns the new label index.
int get_label_y(int label_index) const
Returns the y position of the indicated label's bottom edge, relative to the label stack's parent win...
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.
void set_pos(int x, int y, int width, int height)
Sets the position and size of the label stack on its parent.
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.
int get_x() const
Returns the x position of the stack on its parent.
int get_width() const
Returns the width of the stack as we requested it.
void highlight_label(int collector_index)
Draws a highlight around the label representing the indicated collector, and removes the highlight fr...
int get_num_labels() const
Returns the number of labels in the stack.
int get_label_collector_index(int label_index) const
Returns the collector index associated with the indicated label.