19 static const int default_strip_chart_width = 400;
    20 static const int default_strip_chart_height = 100;
    27                    int collector_index, 
bool show_level) :
    29                   show_level ? monitor->get_level_view(collector_index, thread_index) : monitor->get_view(thread_index),
    32                   default_strip_chart_width,
    33                   default_strip_chart_height),
    40     if (_unit_name.empty()) {
    41       set_guide_bar_units(GBU_named);
    43       set_guide_bar_units(GBU_named | GBU_show_units);
    48     set_guide_bar_units(get_guide_bar_units() | GBU_show_units);
    52   _top_hbox = gtk_hbox_new(FALSE, 0);
    53   gtk_box_pack_start(GTK_BOX(_graph_vbox), _top_hbox,
    56   _smooth_check_box = gtk_check_button_new_with_label(
"Smooth");
    57   g_signal_connect(G_OBJECT(_smooth_check_box), 
"toggled",
    58        G_CALLBACK(toggled_callback), 
this);
    60   _total_label = gtk_label_new(
"");
    61   gtk_box_pack_start(GTK_BOX(_top_hbox), _smooth_check_box,
    63   gtk_box_pack_end(GTK_BOX(_top_hbox), _total_label,
    68   _scale_area = gtk_drawing_area_new();
    69   g_signal_connect(G_OBJECT(_scale_area), 
"expose_event",
    70        G_CALLBACK(expose_event_callback), 
this);
    71   gtk_box_pack_start(GTK_BOX(_graph_hbox), _scale_area,
    73   gtk_widget_set_size_request(_scale_area, 40, 0);
    76   gtk_widget_set_size_request(_graph_window, default_strip_chart_width,
    77             default_strip_chart_height);
    79   gtk_widget_show_all(_window);
    80   gtk_widget_show(_window);
    85   gtk_widget_set_size_request(_window, 0, 0);
    94 ~GtkStatsStripChart() {
   116       gtk_window_set_title(GTK_WINDOW(_window), window_title.c_str());
   124     if (_net_value_text != text) {
   125       _net_value_text = text;
   126       gtk_label_set_text(GTK_LABEL(_total_label), _net_value_text.c_str());
   136   PStatStripChart::force_redraw();
   144   PStatStripChart::changed_size(graph_xsize, graph_ysize);
   155   if ((old_unit_mask & (GBU_hz | GBU_ms)) != 0) {
   156     unit_mask = unit_mask & (GBU_hz | GBU_ms);
   157     unit_mask |= (old_unit_mask & GBU_show_units);
   160     gtk_widget_queue_draw(_scale_area);
   171   if (scroll_speed != 0.0f) {
   181   if (collector_index < 0) {
   194       if (def._parent_index == 0 && 
get_view().get_show_level()) {
   215   gtk_widget_queue_draw(_graph_window);
   216   gtk_widget_queue_draw(_scale_area);
   222 void GtkStatsStripChart::
   224   PStatStripChart::update_labels();
   226   _label_stack.clear_labels();
   228     _label_stack.add_label(GtkStatsGraph::_monitor, 
this, _thread_index,
   231   _labels_changed = 
false;
   237 void GtkStatsStripChart::
   239   gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_white);
   240   gdk_draw_rectangle(_pixmap, _pixmap_gc, TRUE, 0, 0,
   248 void GtkStatsStripChart::
   249 copy_region(
int start_x, 
int end_x, 
int dest_x) {
   250   gdk_draw_drawable(_pixmap, _pixmap_gc, _pixmap,
   251         start_x, 0, dest_x, 0,
   255   _brush_origin += (dest_x - start_x);
   258   GdkRectangle rect = {
   261   gdk_window_invalidate_rect(_graph_window->window, &rect, FALSE);
   268 void GtkStatsStripChart::
   271   gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_white);
   272   gdk_draw_rectangle(_pixmap, _pixmap_gc, TRUE, x, 0,
   275   double overall_time = 0.0;
   278   FrameData::const_iterator fi;
   279   for (fi = fdata.begin(); fi != fdata.end(); ++fi) {
   280     const ColorData &cd = (*fi);
   281     overall_time += cd._net_value;
   282     GdkGC *gc = get_collector_gc(cd._collector_index);
   287       gdk_draw_rectangle(_pixmap, gc, TRUE, x, 0, w, y);
   293     gdk_draw_rectangle(_pixmap, gc, TRUE, x, top_y, w, y - top_y);
   301 void GtkStatsStripChart::
   302 draw_empty(
int x, 
int w) {
   303   gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_white);
   304   gdk_draw_rectangle(_pixmap, _pixmap_gc, TRUE, x, 0,
   311 void GtkStatsStripChart::
   313   gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_black);
   314   gdk_draw_line(_pixmap, _pixmap_gc, x, 0, x, 
get_ysize());
   322 void GtkStatsStripChart::
   323 end_draw(
int from_x, 
int to_x) {
   326   for (
int i = 0; i < num_guide_bars; i++) {
   330   GdkRectangle rect = {
   331     from_x, 0, to_x - from_x + 1, 
get_ysize()
   333   gdk_window_invalidate_rect(_graph_window->window, &rect, FALSE);
   340 void GtkStatsStripChart::
   341 additional_graph_window_paint() {
   343   for (
int i = 0; i < num_user_guide_bars; i++) {
   353 GtkStatsGraph::DragMode GtkStatsStripChart::
   354 consider_drag_start(
int graph_x, 
int graph_y) {
   355   if (graph_x >= 0 && graph_x < 
get_xsize()) {
   356     if (graph_y >= 0 && graph_y < 
get_ysize()) {
   362       if (_drag_guide_bar >= 0) {
   368       return DM_new_guide_bar;
   372   return GtkStatsGraph::consider_drag_start(graph_x, graph_y);
   379 void GtkStatsStripChart::
   380 set_drag_mode(GtkStatsGraph::DragMode drag_mode) {
   381   GtkStatsGraph::set_drag_mode(drag_mode);
   383   switch (_drag_mode) {
   393       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(_smooth_check_box));
   402 gboolean GtkStatsStripChart::
   403 handle_button_press(GtkWidget *widget, 
int graph_x, 
int graph_y,
   412   if (_potential_drag_mode == DM_none) {
   413     set_drag_mode(DM_scale);
   418   } 
else if (_potential_drag_mode == DM_guide_bar && _drag_guide_bar >= 0) {
   419     set_drag_mode(DM_guide_bar);
   420     _drag_start_y = graph_y;
   425   return GtkStatsGraph::handle_button_press(widget, graph_x, graph_y,
   432 gboolean GtkStatsStripChart::
   433 handle_button_release(GtkWidget *widget, 
int graph_x, 
int graph_y) {
   434   if (_drag_mode == DM_scale) {
   435     set_drag_mode(DM_none);
   437     return handle_motion(widget, graph_x, graph_y);
   439   } 
else if (_drag_mode == DM_guide_bar) {
   440     if (graph_y < 0 || graph_y >= 
get_ysize()) {
   445     set_drag_mode(DM_none);
   447     return handle_motion(widget, graph_x, graph_y);
   450   return GtkStatsGraph::handle_button_release(widget, graph_x, graph_y);
   456 gboolean GtkStatsStripChart::
   457 handle_motion(GtkWidget *widget, 
int graph_x, 
int graph_y) {
   458   if (_drag_mode == DM_none && _potential_drag_mode == DM_none) {
   476     _label_stack.highlight_label(-1);
   479   if (_drag_mode == DM_scale) {
   480     double ratio = 1.0f - ((double)graph_y / (
double)
get_ysize());
   486   } 
else if (_drag_mode == DM_new_guide_bar) {
   489     if (graph_y >= 0 && graph_y < 
get_ysize()) {
   490       set_drag_mode(DM_guide_bar);
   495   } 
else if (_drag_mode == DM_guide_bar) {
   500   return GtkStatsGraph::handle_motion(widget, graph_x, graph_y);
   506 void GtkStatsStripChart::
   507 draw_guide_bar(GdkDrawable *surface, 
int from_x, 
int to_x,
   513     switch (bar._style) {
   515       gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_light_gray);
   519       gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_user_guide_bar);
   523       gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_dark_gray);
   526     gdk_draw_line(surface, _pixmap_gc, from_x, y, to_x, y);
   533 void GtkStatsStripChart::
   534 draw_guide_labels() {
   540   for (i = 0; i < num_guide_bars; i++) {
   545   draw_guide_label(top_value, last_y);
   549   for (i = 0; i < num_user_guide_bars; i++) {
   559 int GtkStatsStripChart::
   561   GdkGC *gc = gdk_gc_new(_scale_area->window);
   563   switch (bar._style) {
   565     gdk_gc_set_rgb_fg_color(gc, &rgb_light_gray);
   569     gdk_gc_set_rgb_fg_color(gc, &rgb_user_guide_bar);
   573     gdk_gc_set_rgb_fg_color(gc, &rgb_dark_gray);
   578   const std::string &label = bar._label;
   580   PangoLayout *layout = gtk_widget_create_pango_layout(_window, label.c_str());
   582   pango_layout_get_pixel_size(layout, &width, &height);
   584   if (bar._style != GBS_user) {
   589       g_object_unref(layout);
   600     gtk_widget_translate_coordinates(_graph_window, _scale_area,
   604     int this_y = y - height / 2;
   605     if (last_y < this_y || last_y > this_y + height) {
   606       gdk_draw_layout(_scale_area->window, gc, 0, this_y, layout);
   611   g_object_unref(layout);
   619 void GtkStatsStripChart::
   620 toggled_callback(GtkToggleButton *button, gpointer data) {
   623   bool active = gtk_toggle_button_get_active(button);
   624   self->set_average_mode(active);
   630 gboolean GtkStatsStripChart::
   631 expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
   633   self->draw_guide_labels();
 void set_horizontal_scale(double time_width)
Changes the amount of time the width of the horizontal axis represents.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_xsize() const
Returns the width of the chart in pixels.
A window that draws a strip chart, given a view.
int get_guide_bar_units() const
Returns the units that are displayed for the guide bar labels.
void set_guide_bar_units(int unit_mask)
Sets the units that are displayed for the guide bar labels.
int get_ysize() const
Returns the height of the chart in pixels.
int get_num_labels() const
Returns the number of labels to be drawn for this chart.
void move_user_guide_bar(int n, double height)
Adjusts the height of the nth user-defined guide bar.
The data associated with a particular client, but not with any one particular frame or thread: the li...
void set_vertical_scale(double value_height)
Changes the value the height of the vertical axis represents.
int find_user_guide_bar(double from_height, double to_height) const
Returns the index number of the first user guide bar found whose height is within the indicated range...
const PStatCollectorDef & get_collector_def(int index) const
Returns the nth collector definition.
virtual void new_collector(int collector_index)
Called whenever a new Collector definition is received from the client.
double pixel_to_height(int y) const
Converts a vertical pixel offset to a value (a "height" in the strip chart).
This is an abstract class that presents the interface for drawing a basic strip-chart,...
int get_collector_under_pixel(int xpoint, int ypoint)
Return the collector index associated with the particular band of color at the indicated pixel locati...
This is our own Panda specialization on the default STL vector.
virtual void new_collector(int collector_index)
Called whenever a new Collector definition is received from the client.
int get_collector_index() const
Returns the particular collector whose data this strip chart reflects.
bool has_collector(int index) const
Returns true if the indicated collector has been defined by the client already, false otherwise.
const GuideBar & get_guide_bar(int n) const
Returns the nth horizontal guide bar.
PStatView & get_view() const
Returns the View this chart represents.
void update()
Updates the chart with the latest data.
int height_to_pixel(double value) const
Converts a value (i.e.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 ...
virtual void new_data(int thread_index, int frame_number)
Called as each frame's data is made available.
This is just an abstract base class to provide a common pointer type for the various kinds of graphs ...
int get_label_collector(int n) const
Returns the collector index associated with the nth label.
int get_num_guide_bars() const
Returns the number of horizontal guide bars that should be drawn, based on the indicated target frame...
const std::string & get_guide_bar_unit_name() const
Returns the name of the units to be used for the guide bars if the units type is set to GBU_named | G...
virtual void clicked_label(int collector_index)
Called when the user single-clicks on a label.
This class represents a connection to a PStatsClient and manages the data exchange with the client.
bool is_title_unknown() const
Returns true if get_title_text() has never yet returned an answer, false if it has.
void set_average_mode(bool average_mode)
Changes the average_mode flag.
void set_collector_index(int collector_index)
Changes the collector represented by this strip chart.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void force_redraw()
Called when it is necessary to redraw the entire 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...
double get_vertical_scale() const
Returns total value the height of the vertical axis represents.
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.
const PStatClientData * get_client_data() const
Returns the client data associated with this monitor.
int add_user_guide_bar(double height)
Creates a new user guide bar and returns its index number.
Defines the details about the Collectors: the name, the suggested color, etc.
static std::string format_number(double value)
Returns a string representing the value nicely formatted for its range.
GuideBar get_user_guide_bar(int n) const
Returns the nth user-defined guide bar.
void set_vertical_scale(double value_height)
Changes the value the height of the vertical axis represents.
int get_num_user_guide_bars() const
Returns the current number of user-defined guide bars.
std::string get_title_text()
Returns the text suitable for the title label on the top line.
void remove_user_guide_bar(int n)
Removes the user guide bar with the indicated index number.