gtk-stats: Update to GTK version 3, since version 2 is EOL

This commit is contained in:
rdb 2022-02-01 17:17:56 +01:00
parent 4c3bc5a42e
commit 87f5aea80e
16 changed files with 62 additions and 88 deletions

View File

@ -186,7 +186,7 @@ it will show you the available command-line options:
--use-opencv --no-opencv (enable/disable use of OPENCV) --use-opencv --no-opencv (enable/disable use of OPENCV)
--use-directcam --no-directcam (enable/disable use of DIRECTCAM) --use-directcam --no-directcam (enable/disable use of DIRECTCAM)
--use-vision --no-vision (enable/disable use of VISION) --use-vision --no-vision (enable/disable use of VISION)
--use-gtk2 --no-gtk2 (enable/disable use of GTK2) --use-gtk3 --no-gtk3 (enable/disable use of GTK3)
--use-npapi --no-npapi (enable/disable use of NPAPI) --use-npapi --no-npapi (enable/disable use of NPAPI)
--use-mfc --no-mfc (enable/disable use of MFC) --use-mfc --no-mfc (enable/disable use of MFC)
--use-wx --no-wx (enable/disable use of WX) --use-wx --no-wx (enable/disable use of WX)

View File

@ -556,16 +556,17 @@ package_option(HarfBuzz
package_status(HarfBuzz "HarfBuzz") package_status(HarfBuzz "HarfBuzz")
# GTK2 # GTK3
set(Freetype_FIND_QUIETLY TRUE) # Fix for builtin FindGTK2 if(NOT WIN32)
set(GTK2_GTK_FIND_QUIETLY TRUE) # Fix for builtin FindGTK2 find_package(GTK3 QUIET)
find_package(GTK2 QUIET COMPONENTS gtk) endif()
package_option(GTK2) package_option(GTK3
"This is necessary to build the PStats performance analysis tool on platforms
package_status(GTK2 "gtk+-2") other than Windows.")
package_status(GTK3 "gtk+-3")
# #
# ------------ Physics engines ------------ # ------------ Physics engines ------------

View File

@ -93,7 +93,7 @@ PkgListSet(["PYTHON", "DIRECT", # Python support
"VRPN", "OPENSSL", # Transport "VRPN", "OPENSSL", # Transport
"FFTW", # Algorithm helpers "FFTW", # Algorithm helpers
"ARTOOLKIT", "OPENCV", "DIRECTCAM", "VISION", # Augmented Reality "ARTOOLKIT", "OPENCV", "DIRECTCAM", "VISION", # Augmented Reality
"GTK2", # GTK2 is used for PStats on Unix "GTK3", # GTK3 is used for PStats on Unix
"MFC", "WX", "FLTK", # Used for web plug-in only "MFC", "WX", "FLTK", # Used for web plug-in only
"COCOA", # macOS toolkits "COCOA", # macOS toolkits
"X11", # Unix platform support "X11", # Unix platform support
@ -960,7 +960,7 @@ if (COMPILER=="GCC"):
SmartPkgEnable("OPENSSL", "openssl", ("ssl", "crypto"), ("openssl/ssl.h", "openssl/crypto.h")) SmartPkgEnable("OPENSSL", "openssl", ("ssl", "crypto"), ("openssl/ssl.h", "openssl/crypto.h"))
SmartPkgEnable("ZLIB", "zlib", ("z"), "zlib.h") SmartPkgEnable("ZLIB", "zlib", ("z"), "zlib.h")
SmartPkgEnable("GTK2", "gtk+-2.0") SmartPkgEnable("GTK3", "gtk+-3.0")
if not PkgSkip("OPENSSL") and GetTarget() != "darwin": if not PkgSkip("OPENSSL") and GetTarget() != "darwin":
LibName("OPENSSL", "-Wl,--exclude-libs,libssl.a") LibName("OPENSSL", "-Wl,--exclude-libs,libssl.a")
@ -978,11 +978,6 @@ if (COMPILER=="GCC"):
if GetHost() != "darwin": if GetHost() != "darwin":
# Workaround for an issue where pkg-config does not include this path # Workaround for an issue where pkg-config does not include this path
if GetTargetArch() in ("x86_64", "amd64"): if GetTargetArch() in ("x86_64", "amd64"):
if (os.path.isdir("/usr/lib64/glib-2.0/include")):
IncDirectory("GTK2", "/usr/lib64/glib-2.0/include")
if (os.path.isdir("/usr/lib64/gtk-2.0/include")):
IncDirectory("GTK2", "/usr/lib64/gtk-2.0/include")
if not PkgSkip("X11"): if not PkgSkip("X11"):
if (os.path.isdir("/usr/X11R6/lib64")): if (os.path.isdir("/usr/X11R6/lib64")):
LibDirectory("ALWAYS", "/usr/X11R6/lib64") LibDirectory("ALWAYS", "/usr/X11R6/lib64")
@ -5841,19 +5836,19 @@ if not PkgSkip("PANDATOOL"):
# DIRECTORY: pandatool/src/gtk-stats/ # DIRECTORY: pandatool/src/gtk-stats/
# #
if not PkgSkip("PANDATOOL") and (GetTarget() == 'windows' or not PkgSkip("GTK2")): if not PkgSkip("PANDATOOL") and (GetTarget() == 'windows' or not PkgSkip("GTK3")):
if GetTarget() == 'windows': if GetTarget() == 'windows':
OPTS=['DIR:pandatool/src/win-stats'] OPTS=['DIR:pandatool/src/win-stats']
TargetAdd('pstats_composite1.obj', opts=OPTS, input='winstats_composite1.cxx') TargetAdd('pstats_composite1.obj', opts=OPTS, input='winstats_composite1.cxx')
else: else:
OPTS=['DIR:pandatool/src/gtk-stats', 'GTK2'] OPTS=['DIR:pandatool/src/gtk-stats', 'GTK3']
TargetAdd('pstats_composite1.obj', opts=OPTS, input='gtkstats_composite1.cxx') TargetAdd('pstats_composite1.obj', opts=OPTS, input='gtkstats_composite1.cxx')
TargetAdd('pstats.exe', input='pstats_composite1.obj') TargetAdd('pstats.exe', input='pstats_composite1.obj')
TargetAdd('pstats.exe', input='libp3pstatserver.lib') TargetAdd('pstats.exe', input='libp3pstatserver.lib')
TargetAdd('pstats.exe', input='libp3progbase.lib') TargetAdd('pstats.exe', input='libp3progbase.lib')
TargetAdd('pstats.exe', input='libp3pandatoolbase.lib') TargetAdd('pstats.exe', input='libp3pandatoolbase.lib')
TargetAdd('pstats.exe', input=COMMON_PANDA_LIBS) TargetAdd('pstats.exe', input=COMMON_PANDA_LIBS)
TargetAdd('pstats.exe', opts=['SUBSYSTEM:WINDOWS', 'WINSOCK', 'WINIMM', 'WINGDI', 'WINKERNEL', 'WINOLDNAMES', 'WINUSER', 'WINMM', 'GTK2']) TargetAdd('pstats.exe', opts=['SUBSYSTEM:WINDOWS', 'WINSOCK', 'WINIMM', 'WINGDI', 'WINKERNEL', 'WINOLDNAMES', 'WINUSER', 'WINMM', 'GTK3'])
# #
# DIRECTORY: pandatool/src/xfileprogs/ # DIRECTORY: pandatool/src/xfileprogs/

View File

@ -1,4 +1,4 @@
if(NOT HAVE_GTK2 OR NOT HAVE_NET) if(NOT HAVE_GTK3 OR NOT HAVE_NET)
return() return()
endif() endif()
@ -28,7 +28,7 @@ set(GTKSTATS_SOURCES
composite_sources(gtk-stats GTKSTATS_SOURCES) composite_sources(gtk-stats GTKSTATS_SOURCES)
add_executable(gtk-stats ${GTKSTATS_HEADERS} ${GTKSTATS_SOURCES}) add_executable(gtk-stats ${GTKSTATS_HEADERS} ${GTKSTATS_SOURCES})
target_link_libraries(gtk-stats p3progbase p3pstatserver PKG::GTK2) target_link_libraries(gtk-stats p3progbase p3pstatserver PKG::GTK3)
# This program is NOT actually called gtk-stats. It's pstats-gtk on Win32 and # This program is NOT actually called gtk-stats. It's pstats-gtk on Win32 and
# pstats everywhere else (as the Win32 GUI is not built). # pstats everywhere else (as the Win32 GUI is not built).

View File

@ -44,7 +44,7 @@ timer(gpointer data) {
// are getting starved and falling behind, so that the user still gets a // are getting starved and falling behind, so that the user still gets a
// chance to see *something* happen onscreen, even if it's just // chance to see *something* happen onscreen, even if it's just
// increasingly old data. // increasingly old data.
gdk_window_process_all_updates(); //gdk_window_process_all_updates();
} }
return TRUE; return TRUE;

View File

@ -104,9 +104,9 @@ do_update() {
// We put a separator between the above frame collector and the first // We put a separator between the above frame collector and the first
// level collector. // level collector.
if (needs_separator) { if (needs_separator) {
GtkWidget *sep = gtk_separator_menu_item_new(); GtkWidget *sep = gtk_separator_menu_item_new();
gtk_widget_show(sep); gtk_widget_show(sep);
gtk_menu_shell_append(GTK_MENU_SHELL(_menu), sep); gtk_menu_shell_append(GTK_MENU_SHELL(_menu), sep);
needs_separator = false; needs_separator = false;
} }
@ -138,7 +138,7 @@ do_update() {
*/ */
void GtkStatsChartMenu:: void GtkStatsChartMenu::
add_view(GtkWidget *parent_menu, const PStatViewLevel *view_level, add_view(GtkWidget *parent_menu, const PStatViewLevel *view_level,
bool show_level) { bool show_level) {
int collector = view_level->get_collector(); int collector = view_level->get_collector();
const PStatClientData *client_data = _monitor->get_client_data(); const PStatClientData *client_data = _monitor->get_client_data();

View File

@ -73,8 +73,8 @@ GtkStatsGraph(GtkStatsMonitor *monitor) :
gtk_widget_add_events(_graph_window, gtk_widget_add_events(_graph_window,
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK); GDK_POINTER_MOTION_MASK);
g_signal_connect(G_OBJECT(_graph_window), "expose_event", g_signal_connect(G_OBJECT(_graph_window), "draw",
G_CALLBACK(graph_expose_callback), this); G_CALLBACK(graph_draw_callback), this);
g_signal_connect(G_OBJECT(_graph_window), "configure_event", g_signal_connect(G_OBJECT(_graph_window), "configure_event",
G_CALLBACK(configure_graph_callback), this); G_CALLBACK(configure_graph_callback), this);
g_signal_connect(G_OBJECT(_graph_window), "button_press_event", g_signal_connect(G_OBJECT(_graph_window), "button_press_event",
@ -91,18 +91,18 @@ GtkStatsGraph(GtkStatsMonitor *monitor) :
// A VBox to hold the graph's frame, and any numbers (scale legend? total?) // A VBox to hold the graph's frame, and any numbers (scale legend? total?)
// above it. // above it.
_graph_vbox = gtk_vbox_new(FALSE, 0); _graph_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_end(GTK_BOX(_graph_vbox), graph_frame, gtk_box_pack_end(GTK_BOX(_graph_vbox), graph_frame,
TRUE, TRUE, 0); TRUE, TRUE, 0);
// An HBox to hold the graph's frame, and the scale legend to the right of // An HBox to hold the graph's frame, and the scale legend to the right of
// it. // it.
_graph_hbox = gtk_hbox_new(FALSE, 0); _graph_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start(GTK_BOX(_graph_hbox), _graph_vbox, gtk_box_pack_start(GTK_BOX(_graph_hbox), _graph_vbox,
TRUE, TRUE, 0); TRUE, TRUE, 0);
// An HPaned to hold the label stack and the graph hbox. // An HPaned to hold the label stack and the graph hbox.
_hpaned = gtk_hpaned_new(); _hpaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
gtk_container_add(GTK_CONTAINER(_window), _hpaned); gtk_container_add(GTK_CONTAINER(_window), _hpaned);
gtk_container_set_border_width(GTK_CONTAINER(_window), 8); gtk_container_set_border_width(GTK_CONTAINER(_window), 8);
@ -373,12 +373,9 @@ window_destroy(GtkWidget *widget, gpointer data) {
* Fills in the graph window. * Fills in the graph window.
*/ */
gboolean GtkStatsGraph:: gboolean GtkStatsGraph::
graph_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) { graph_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) {
GtkStatsGraph *self = (GtkStatsGraph *)data; GtkStatsGraph *self = (GtkStatsGraph *)data;
GdkWindow *window = gtk_widget_get_window(self->_graph_window);
cairo_t *cr = gdk_cairo_create(window);
if (self->_cr_surface != nullptr) { if (self->_cr_surface != nullptr) {
cairo_set_source_surface(cr, self->_cr_surface, 0, 0); cairo_set_source_surface(cr, self->_cr_surface, 0, 0);
cairo_paint(cr); cairo_paint(cr);
@ -386,8 +383,6 @@ graph_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
self->additional_graph_window_paint(cr); self->additional_graph_window_paint(cr);
cairo_destroy(cr);
return TRUE; return TRUE;
} }

View File

@ -118,10 +118,10 @@ private:
static gboolean window_delete_event(GtkWidget *widget, GdkEvent *event, static gboolean window_delete_event(GtkWidget *widget, GdkEvent *event,
gpointer data); gpointer data);
static void window_destroy(GtkWidget *widget, gpointer data); static void window_destroy(GtkWidget *widget, gpointer data);
static gboolean graph_expose_callback(GtkWidget *widget, static gboolean graph_draw_callback(GtkWidget *widget,
GdkEventExpose *event, gpointer data); cairo_t *cr, gpointer data);
static gboolean configure_graph_callback(GtkWidget *widget, static gboolean configure_graph_callback(GtkWidget *widget,
GdkEventConfigure *event, gpointer data); GdkEventConfigure *event, gpointer data);
protected: protected:
static gboolean button_press_event_callback(GtkWidget *widget, static gboolean button_press_event_callback(GtkWidget *widget,

View File

@ -15,8 +15,6 @@
#include "gtkStatsMonitor.h" #include "gtkStatsMonitor.h"
#include "gtkStatsGraph.h" #include "gtkStatsGraph.h"
#include <cairo.h>
int GtkStatsLabel::_left_margin = 2; int GtkStatsLabel::_left_margin = 2;
int GtkStatsLabel::_right_margin = 2; int GtkStatsLabel::_right_margin = 2;
int GtkStatsLabel::_top_margin = 2; int GtkStatsLabel::_top_margin = 2;
@ -44,8 +42,8 @@ GtkStatsLabel(GtkStatsMonitor *monitor, GtkStatsGraph *graph,
gtk_widget_add_events(_widget, gtk_widget_add_events(_widget,
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
GDK_BUTTON_PRESS_MASK); GDK_BUTTON_PRESS_MASK);
g_signal_connect(G_OBJECT(_widget), "expose_event", g_signal_connect(G_OBJECT(_widget), "draw",
G_CALLBACK(expose_event_callback), this); G_CALLBACK(draw_callback), this);
g_signal_connect(G_OBJECT(_widget), "enter_notify_event", g_signal_connect(G_OBJECT(_widget), "enter_notify_event",
G_CALLBACK(enter_notify_event_callback), this); G_CALLBACK(enter_notify_event_callback), this);
g_signal_connect(G_OBJECT(_widget), "leave_notify_event", g_signal_connect(G_OBJECT(_widget), "leave_notify_event",
@ -154,11 +152,9 @@ set_mouse_within(bool mouse_within) {
* Draws the background color of the label. * Draws the background color of the label.
*/ */
gboolean GtkStatsLabel:: gboolean GtkStatsLabel::
expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) { draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) {
GtkStatsLabel *self = (GtkStatsLabel *)data; GtkStatsLabel *self = (GtkStatsLabel *)data;
GdkWindow *window = gtk_widget_get_window(widget);
cairo_t *cr = gdk_cairo_create(window);
cairo_set_source_rgb(cr, self->_bg_color[0], self->_bg_color[1], self->_bg_color[2]); cairo_set_source_rgb(cr, self->_bg_color[0], self->_bg_color[1], self->_bg_color[2]);
GtkAllocation allocation; GtkAllocation allocation;
@ -181,7 +177,6 @@ expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
cairo_stroke(cr); cairo_stroke(cr);
} }
cairo_destroy(cr);
return TRUE; return TRUE;
} }

View File

@ -17,6 +17,7 @@
#include "pandatoolbase.h" #include "pandatoolbase.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <cairo.h>
class GtkStatsMonitor; class GtkStatsMonitor;
class GtkStatsGraph; class GtkStatsGraph;
@ -43,8 +44,8 @@ public:
private: private:
void set_mouse_within(bool mouse_within); void set_mouse_within(bool mouse_within);
static gboolean expose_event_callback(GtkWidget *widget, static gboolean draw_callback(GtkWidget *widget,
GdkEventExpose *event, gpointer data); cairo_t *cr, gpointer data);
static gboolean enter_notify_event_callback(GtkWidget *widget, static gboolean enter_notify_event_callback(GtkWidget *widget,
GdkEventCrossing *event, GdkEventCrossing *event,
gpointer data); gpointer data);

View File

@ -20,7 +20,7 @@
*/ */
GtkStatsLabelStack:: GtkStatsLabelStack::
GtkStatsLabelStack() { GtkStatsLabelStack() {
_widget = gtk_vbox_new(FALSE, 0); _widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
_highlight_label = -1; _highlight_label = -1;
} }

View File

@ -160,7 +160,6 @@ new_data(int thread_index, int frame_number) {
} }
} }
/** /**
* Called whenever the connection to the client has been lost. This is a * Called whenever the connection to the client has been lost. This is a
* permanent state change. The monitor should update its display to represent * permanent state change. The monitor should update its display to represent
@ -373,7 +372,7 @@ create_window() {
} }
// Pack the menu into the window. // Pack the menu into the window.
GtkWidget *main_vbox = gtk_vbox_new(FALSE, 1); GtkWidget *main_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
gtk_container_add(GTK_CONTAINER(_window), main_vbox); gtk_container_add(GTK_CONTAINER(_window), main_vbox);
gtk_box_pack_start(GTK_BOX(main_vbox), _menu_bar, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(main_vbox), _menu_bar, FALSE, TRUE, 0);

View File

@ -35,8 +35,8 @@ GtkStatsPianoRoll(GtkStatsMonitor *monitor, int thread_index) :
// Add a DrawingArea widget on top of the graph, to display all of the scale // Add a DrawingArea widget on top of the graph, to display all of the scale
// units. // units.
_scale_area = gtk_drawing_area_new(); _scale_area = gtk_drawing_area_new();
g_signal_connect(G_OBJECT(_scale_area), "expose_event", g_signal_connect(G_OBJECT(_scale_area), "draw",
G_CALLBACK(expose_event_callback), this); G_CALLBACK(draw_callback), this);
gtk_box_pack_start(GTK_BOX(_graph_vbox), _scale_area, gtk_box_pack_start(GTK_BOX(_graph_vbox), _scale_area,
FALSE, FALSE, 0); FALSE, FALSE, 0);
gtk_widget_set_size_request(_scale_area, 0, 20); gtk_widget_set_size_request(_scale_area, 0, 20);
@ -405,16 +405,16 @@ draw_guide_bar(cairo_t *cr, const PStatGraph::GuideBar &bar) {
* This is called during the servicing of expose_event. * This is called during the servicing of expose_event.
*/ */
void GtkStatsPianoRoll:: void GtkStatsPianoRoll::
draw_guide_labels() { draw_guide_labels(cairo_t *cr) {
int i; int i;
int num_guide_bars = get_num_guide_bars(); int num_guide_bars = get_num_guide_bars();
for (i = 0; i < num_guide_bars; i++) { for (i = 0; i < num_guide_bars; i++) {
draw_guide_label(get_guide_bar(i)); draw_guide_label(cr, get_guide_bar(i));
} }
int num_user_guide_bars = get_num_user_guide_bars(); int num_user_guide_bars = get_num_user_guide_bars();
for (i = 0; i < num_user_guide_bars; i++) { for (i = 0; i < num_user_guide_bars; i++) {
draw_guide_label(get_user_guide_bar(i)); draw_guide_label(cr, get_user_guide_bar(i));
} }
} }
@ -422,10 +422,7 @@ draw_guide_labels() {
* Draws the text for the indicated guide bar label at the top of the graph. * Draws the text for the indicated guide bar label at the top of the graph.
*/ */
void GtkStatsPianoRoll:: void GtkStatsPianoRoll::
draw_guide_label(const PStatGraph::GuideBar &bar) { draw_guide_label(cairo_t *cr, const PStatGraph::GuideBar &bar) {
GdkWindow *window = gtk_widget_get_window(_scale_area);
cairo_t *cr = gdk_cairo_create(window);
switch (bar._style) { switch (bar._style) {
case GBS_target: case GBS_target:
cairo_set_source_rgb(cr, rgb_light_gray[0], rgb_light_gray[1], rgb_light_gray[2]); cairo_set_source_rgb(cr, rgb_light_gray[0], rgb_light_gray[1], rgb_light_gray[2]);
@ -453,7 +450,6 @@ draw_guide_label(const PStatGraph::GuideBar &bar) {
if (find_user_guide_bar(from_height, to_height) >= 0) { if (find_user_guide_bar(from_height, to_height) >= 0) {
// Omit the label: there's a user-defined guide bar in the same space. // Omit the label: there's a user-defined guide bar in the same space.
g_object_unref(layout); g_object_unref(layout);
cairo_destroy(cr);
return; return;
} }
} }
@ -476,16 +472,15 @@ draw_guide_label(const PStatGraph::GuideBar &bar) {
} }
g_object_unref(layout); g_object_unref(layout);
cairo_destroy(cr);
} }
/** /**
* Draws in the scale labels. * Draws in the scale labels.
*/ */
gboolean GtkStatsPianoRoll:: gboolean GtkStatsPianoRoll::
expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) { draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) {
GtkStatsPianoRoll *self = (GtkStatsPianoRoll *)data; GtkStatsPianoRoll *self = (GtkStatsPianoRoll *)data;
self->draw_guide_labels(); self->draw_guide_labels(cr);
return TRUE; return TRUE;
} }

View File

@ -60,11 +60,10 @@ private:
int get_collector_under_pixel(int xpoint, int ypoint); int get_collector_under_pixel(int xpoint, int ypoint);
void update_labels(); void update_labels();
void draw_guide_bar(cairo_t *cr, const PStatGraph::GuideBar &bar); void draw_guide_bar(cairo_t *cr, const PStatGraph::GuideBar &bar);
void draw_guide_labels(); void draw_guide_labels(cairo_t *cr);
void draw_guide_label(const PStatGraph::GuideBar &bar); void draw_guide_label(cairo_t *cr, const PStatGraph::GuideBar &bar);
static gboolean expose_event_callback(GtkWidget *widget, static gboolean draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data);
GdkEventExpose *event, gpointer data);
}; };
#endif #endif

View File

@ -47,7 +47,7 @@ GtkStatsStripChart(GtkStatsMonitor *monitor, int thread_index,
} }
// Put some stuff on top of the graph. // Put some stuff on top of the graph.
_top_hbox = gtk_hbox_new(FALSE, 0); _top_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start(GTK_BOX(_graph_vbox), _top_hbox, gtk_box_pack_start(GTK_BOX(_graph_vbox), _top_hbox,
FALSE, FALSE, 0); FALSE, FALSE, 0);
@ -64,8 +64,8 @@ GtkStatsStripChart(GtkStatsMonitor *monitor, int thread_index,
// Add a DrawingArea widget to the right of the graph, to display all of the // Add a DrawingArea widget to the right of the graph, to display all of the
// scale units. // scale units.
_scale_area = gtk_drawing_area_new(); _scale_area = gtk_drawing_area_new();
g_signal_connect(G_OBJECT(_scale_area), "expose_event", g_signal_connect(G_OBJECT(_scale_area), "draw",
G_CALLBACK(expose_event_callback), this); G_CALLBACK(draw_callback), this);
gtk_box_pack_start(GTK_BOX(_graph_hbox), _scale_area, gtk_box_pack_start(GTK_BOX(_graph_hbox), _scale_area,
FALSE, FALSE, 0); FALSE, FALSE, 0);
gtk_widget_set_size_request(_scale_area, 40, 0); gtk_widget_set_size_request(_scale_area, 40, 0);
@ -549,23 +549,23 @@ draw_guide_bar(cairo_t *cr, int from_x, int to_x,
* This is called during the servicing of expose_event. * This is called during the servicing of expose_event.
*/ */
void GtkStatsStripChart:: void GtkStatsStripChart::
draw_guide_labels() { draw_guide_labels(cairo_t *cr) {
// Draw in the labels for the guide bars. // Draw in the labels for the guide bars.
int last_y = -100; int last_y = -100;
int i; int i;
int num_guide_bars = get_num_guide_bars(); int num_guide_bars = get_num_guide_bars();
for (i = 0; i < num_guide_bars; i++) { for (i = 0; i < num_guide_bars; i++) {
last_y = draw_guide_label(get_guide_bar(i), last_y); last_y = draw_guide_label(cr, get_guide_bar(i), last_y);
} }
GuideBar top_value = make_guide_bar(get_vertical_scale()); GuideBar top_value = make_guide_bar(get_vertical_scale());
draw_guide_label(top_value, last_y); draw_guide_label(cr, top_value, last_y);
last_y = -100; last_y = -100;
int num_user_guide_bars = get_num_user_guide_bars(); int num_user_guide_bars = get_num_user_guide_bars();
for (i = 0; i < num_user_guide_bars; i++) { for (i = 0; i < num_user_guide_bars; i++) {
last_y = draw_guide_label(get_user_guide_bar(i), last_y); last_y = draw_guide_label(cr, get_user_guide_bar(i), last_y);
} }
} }
@ -575,10 +575,7 @@ draw_guide_labels() {
* value is given. Returns the top pixel value of the new label. * value is given. Returns the top pixel value of the new label.
*/ */
int GtkStatsStripChart:: int GtkStatsStripChart::
draw_guide_label(const PStatGraph::GuideBar &bar, int last_y) { draw_guide_label(cairo_t *cr, const PStatGraph::GuideBar &bar, int last_y) {
GdkWindow *window = gtk_widget_get_window(_scale_area);
cairo_t *cr = gdk_cairo_create(window);
switch (bar._style) { switch (bar._style) {
case GBS_target: case GBS_target:
cairo_set_source_rgb(cr, rgb_light_gray[0], rgb_light_gray[1], rgb_light_gray[2]); cairo_set_source_rgb(cr, rgb_light_gray[0], rgb_light_gray[1], rgb_light_gray[2]);
@ -606,7 +603,6 @@ draw_guide_label(const PStatGraph::GuideBar &bar, int last_y) {
if (find_user_guide_bar(from_height, to_height) >= 0) { if (find_user_guide_bar(from_height, to_height) >= 0) {
// Omit the label: there's a user-defined guide bar in the same space. // Omit the label: there's a user-defined guide bar in the same space.
g_object_unref(layout); g_object_unref(layout);
cairo_destroy(cr);
return last_y; return last_y;
} }
} }
@ -629,7 +625,6 @@ draw_guide_label(const PStatGraph::GuideBar &bar, int last_y) {
} }
g_object_unref(layout); g_object_unref(layout);
cairo_destroy(cr);
return last_y; return last_y;
} }
@ -648,9 +643,9 @@ toggled_callback(GtkToggleButton *button, gpointer data) {
* Draws in the scale labels. * Draws in the scale labels.
*/ */
gboolean GtkStatsStripChart:: gboolean GtkStatsStripChart::
expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) { draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) {
GtkStatsStripChart *self = (GtkStatsStripChart *)data; GtkStatsStripChart *self = (GtkStatsStripChart *)data;
self->draw_guide_labels(); self->draw_guide_labels(cr);
return TRUE; return TRUE;
} }

View File

@ -66,12 +66,11 @@ protected:
private: private:
void draw_guide_bar(cairo_t *cr, int from_x, int to_x, void draw_guide_bar(cairo_t *cr, int from_x, int to_x,
const PStatGraph::GuideBar &bar); const PStatGraph::GuideBar &bar);
void draw_guide_labels(); void draw_guide_labels(cairo_t *cr);
int draw_guide_label(const PStatGraph::GuideBar &bar, int last_y); int draw_guide_label(cairo_t *cr, const PStatGraph::GuideBar &bar, int last_y);
static void toggled_callback(GtkToggleButton *button, gpointer data); static void toggled_callback(GtkToggleButton *button, gpointer data);
static gboolean expose_event_callback(GtkWidget *widget, static gboolean draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data);
GdkEventExpose *event, gpointer data);
private: private:
std::string _net_value_text; std::string _net_value_text;