gtkStatsGraph.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file gtkStatsGraph.h
  10. * @author drose
  11. * @date 2006-01-16
  12. */
  13. #ifndef GTKSTATSGRAPH_H
  14. #define GTKSTATSGRAPH_H
  15. #include "pandatoolbase.h"
  16. #include "gtkStatsLabelStack.h"
  17. #include "pmap.h"
  18. #include <gtk/gtk.h>
  19. #include <cairo.h>
  20. class GtkStatsMonitor;
  21. /**
  22. * This is just an abstract base class to provide a common pointer type for
  23. * the various kinds of graphs that may be created for a GtkStatsMonitor.
  24. */
  25. class GtkStatsGraph {
  26. public:
  27. // What is the user adjusting by dragging the mouse in a window?
  28. enum DragMode {
  29. DM_none,
  30. DM_scale,
  31. DM_guide_bar,
  32. DM_new_guide_bar,
  33. DM_sizing,
  34. };
  35. public:
  36. GtkStatsGraph(GtkStatsMonitor *monitor);
  37. virtual ~GtkStatsGraph();
  38. virtual void new_collector(int collector_index);
  39. virtual void new_data(int thread_index, int frame_number);
  40. virtual void force_redraw();
  41. virtual void changed_graph_size(int graph_xsize, int graph_ysize);
  42. virtual void set_time_units(int unit_mask);
  43. virtual void set_scroll_speed(double scroll_speed);
  44. void set_pause(bool pause);
  45. void user_guide_bars_changed();
  46. virtual void clicked_label(int collector_index);
  47. protected:
  48. void close();
  49. cairo_pattern_t *get_collector_pattern(int collector_index);
  50. virtual void additional_graph_window_paint(cairo_t *cr);
  51. virtual DragMode consider_drag_start(int graph_x, int graph_y);
  52. virtual void set_drag_mode(DragMode drag_mode);
  53. virtual gboolean handle_button_press(GtkWidget *widget, int graph_x, int graph_y,
  54. bool double_click);
  55. virtual gboolean handle_button_release(GtkWidget *widget, int graph_x, int graph_y);
  56. virtual gboolean handle_motion(GtkWidget *widget, int graph_x, int graph_y);
  57. protected:
  58. // Table of patterns for our various collectors.
  59. typedef pmap<int, cairo_pattern_t *> Brushes;
  60. Brushes _brushes;
  61. GtkStatsMonitor *_monitor;
  62. GtkWidget *_parent_window;
  63. GtkWidget *_window;
  64. GtkWidget *_graph_window;
  65. GtkWidget *_graph_hbox;
  66. GtkWidget *_graph_vbox;
  67. GtkWidget *_hpaned;
  68. GtkWidget *_scale_area;
  69. GtkStatsLabelStack _label_stack;
  70. GdkCursor *_hand_cursor;
  71. cairo_surface_t *_cr_surface;
  72. cairo_t *_cr;
  73. int _surface_xsize, _surface_ysize;
  74. /*
  75. COLORREF _dark_color;
  76. COLORREF _light_color;
  77. COLORREF _user_guide_bar_color;
  78. HPEN _dark_pen;
  79. HPEN _light_pen;
  80. HPEN _user_guide_bar_pen;
  81. */
  82. DragMode _drag_mode;
  83. DragMode _potential_drag_mode;
  84. int _drag_start_x, _drag_start_y;
  85. double _drag_scale_start;
  86. int _drag_guide_bar;
  87. bool _pause;
  88. static const double rgb_white[3];
  89. static const double rgb_light_gray[3];
  90. static const double rgb_dark_gray[3];
  91. static const double rgb_black[3];
  92. static const double rgb_user_guide_bar[3];
  93. private:
  94. void setup_surface(int xsize, int ysize);
  95. void release_surface();
  96. static gboolean window_delete_event(GtkWidget *widget, GdkEvent *event,
  97. gpointer data);
  98. static void window_destroy(GtkWidget *widget, gpointer data);
  99. static gboolean graph_draw_callback(GtkWidget *widget,
  100. cairo_t *cr, gpointer data);
  101. static gboolean configure_graph_callback(GtkWidget *widget,
  102. GdkEventConfigure *event, gpointer data);
  103. protected:
  104. static gboolean button_press_event_callback(GtkWidget *widget,
  105. GdkEventButton *event,
  106. gpointer data);
  107. static gboolean button_release_event_callback(GtkWidget *widget,
  108. GdkEventButton *event,
  109. gpointer data);
  110. static gboolean motion_notify_event_callback(GtkWidget *widget,
  111. GdkEventMotion *event,
  112. gpointer data);
  113. };
  114. #endif