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-directcam --no-directcam (enable/disable use of DIRECTCAM)
--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-mfc --no-mfc (enable/disable use of MFC)
--use-wx --no-wx (enable/disable use of WX)

View File

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

View File

@ -93,7 +93,7 @@ PkgListSet(["PYTHON", "DIRECT", # Python support
"VRPN", "OPENSSL", # Transport
"FFTW", # Algorithm helpers
"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
"COCOA", # macOS toolkits
"X11", # Unix platform support
@ -960,7 +960,7 @@ if (COMPILER=="GCC"):
SmartPkgEnable("OPENSSL", "openssl", ("ssl", "crypto"), ("openssl/ssl.h", "openssl/crypto.h"))
SmartPkgEnable("ZLIB", "zlib", ("z"), "zlib.h")
SmartPkgEnable("GTK2", "gtk+-2.0")
SmartPkgEnable("GTK3", "gtk+-3.0")
if not PkgSkip("OPENSSL") and GetTarget() != "darwin":
LibName("OPENSSL", "-Wl,--exclude-libs,libssl.a")
@ -978,11 +978,6 @@ if (COMPILER=="GCC"):
if GetHost() != "darwin":
# Workaround for an issue where pkg-config does not include this path
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 (os.path.isdir("/usr/X11R6/lib64")):
LibDirectory("ALWAYS", "/usr/X11R6/lib64")
@ -5841,19 +5836,19 @@ if not PkgSkip("PANDATOOL"):
# 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':
OPTS=['DIR:pandatool/src/win-stats']
TargetAdd('pstats_composite1.obj', opts=OPTS, input='winstats_composite1.cxx')
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.exe', input='pstats_composite1.obj')
TargetAdd('pstats.exe', input='libp3pstatserver.lib')
TargetAdd('pstats.exe', input='libp3progbase.lib')
TargetAdd('pstats.exe', input='libp3pandatoolbase.lib')
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/

View File

@ -1,4 +1,4 @@
if(NOT HAVE_GTK2 OR NOT HAVE_NET)
if(NOT HAVE_GTK3 OR NOT HAVE_NET)
return()
endif()
@ -28,7 +28,7 @@ set(GTKSTATS_SOURCES
composite_sources(gtk-stats 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
# 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
// chance to see *something* happen onscreen, even if it's just
// increasingly old data.
gdk_window_process_all_updates();
//gdk_window_process_all_updates();
}
return TRUE;

View File

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

View File

@ -73,8 +73,8 @@ GtkStatsGraph(GtkStatsMonitor *monitor) :
gtk_widget_add_events(_graph_window,
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK);
g_signal_connect(G_OBJECT(_graph_window), "expose_event",
G_CALLBACK(graph_expose_callback), this);
g_signal_connect(G_OBJECT(_graph_window), "draw",
G_CALLBACK(graph_draw_callback), this);
g_signal_connect(G_OBJECT(_graph_window), "configure_event",
G_CALLBACK(configure_graph_callback), this);
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?)
// 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,
TRUE, TRUE, 0);
// An HBox to hold the graph's frame, and the scale legend to the right of
// 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,
TRUE, TRUE, 0);
// 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_set_border_width(GTK_CONTAINER(_window), 8);
@ -373,12 +373,9 @@ window_destroy(GtkWidget *widget, gpointer data) {
* Fills in the graph window.
*/
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;
GdkWindow *window = gtk_widget_get_window(self->_graph_window);
cairo_t *cr = gdk_cairo_create(window);
if (self->_cr_surface != nullptr) {
cairo_set_source_surface(cr, self->_cr_surface, 0, 0);
cairo_paint(cr);
@ -386,8 +383,6 @@ graph_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
self->additional_graph_window_paint(cr);
cairo_destroy(cr);
return TRUE;
}

View File

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

View File

@ -15,8 +15,6 @@
#include "gtkStatsMonitor.h"
#include "gtkStatsGraph.h"
#include <cairo.h>
int GtkStatsLabel::_left_margin = 2;
int GtkStatsLabel::_right_margin = 2;
int GtkStatsLabel::_top_margin = 2;
@ -44,8 +42,8 @@ GtkStatsLabel(GtkStatsMonitor *monitor, GtkStatsGraph *graph,
gtk_widget_add_events(_widget,
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
GDK_BUTTON_PRESS_MASK);
g_signal_connect(G_OBJECT(_widget), "expose_event",
G_CALLBACK(expose_event_callback), this);
g_signal_connect(G_OBJECT(_widget), "draw",
G_CALLBACK(draw_callback), this);
g_signal_connect(G_OBJECT(_widget), "enter_notify_event",
G_CALLBACK(enter_notify_event_callback), this);
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.
*/
gboolean GtkStatsLabel::
expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
draw_callback(GtkWidget *widget, cairo_t *cr, gpointer 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]);
GtkAllocation allocation;
@ -181,7 +177,6 @@ expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
cairo_stroke(cr);
}
cairo_destroy(cr);
return TRUE;
}

View File

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

View File

@ -20,7 +20,7 @@
*/
GtkStatsLabelStack::
GtkStatsLabelStack() {
_widget = gtk_vbox_new(FALSE, 0);
_widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
_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
* permanent state change. The monitor should update its display to represent
@ -373,7 +372,7 @@ create_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_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
// units.
_scale_area = gtk_drawing_area_new();
g_signal_connect(G_OBJECT(_scale_area), "expose_event",
G_CALLBACK(expose_event_callback), this);
g_signal_connect(G_OBJECT(_scale_area), "draw",
G_CALLBACK(draw_callback), this);
gtk_box_pack_start(GTK_BOX(_graph_vbox), _scale_area,
FALSE, FALSE, 0);
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.
*/
void GtkStatsPianoRoll::
draw_guide_labels() {
draw_guide_labels(cairo_t *cr) {
int i;
int num_guide_bars = get_num_guide_bars();
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();
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.
*/
void GtkStatsPianoRoll::
draw_guide_label(const PStatGraph::GuideBar &bar) {
GdkWindow *window = gtk_widget_get_window(_scale_area);
cairo_t *cr = gdk_cairo_create(window);
draw_guide_label(cairo_t *cr, const PStatGraph::GuideBar &bar) {
switch (bar._style) {
case GBS_target:
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) {
// Omit the label: there's a user-defined guide bar in the same space.
g_object_unref(layout);
cairo_destroy(cr);
return;
}
}
@ -476,16 +472,15 @@ draw_guide_label(const PStatGraph::GuideBar &bar) {
}
g_object_unref(layout);
cairo_destroy(cr);
}
/**
* Draws in the scale labels.
*/
gboolean GtkStatsPianoRoll::
expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) {
GtkStatsPianoRoll *self = (GtkStatsPianoRoll *)data;
self->draw_guide_labels();
self->draw_guide_labels(cr);
return TRUE;
}

View File

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

View File

@ -47,7 +47,7 @@ GtkStatsStripChart(GtkStatsMonitor *monitor, int thread_index,
}
// 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,
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
// scale units.
_scale_area = gtk_drawing_area_new();
g_signal_connect(G_OBJECT(_scale_area), "expose_event",
G_CALLBACK(expose_event_callback), this);
g_signal_connect(G_OBJECT(_scale_area), "draw",
G_CALLBACK(draw_callback), this);
gtk_box_pack_start(GTK_BOX(_graph_hbox), _scale_area,
FALSE, FALSE, 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.
*/
void GtkStatsStripChart::
draw_guide_labels() {
draw_guide_labels(cairo_t *cr) {
// Draw in the labels for the guide bars.
int last_y = -100;
int i;
int num_guide_bars = get_num_guide_bars();
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());
draw_guide_label(top_value, last_y);
draw_guide_label(cr, top_value, last_y);
last_y = -100;
int num_user_guide_bars = get_num_user_guide_bars();
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.
*/
int GtkStatsStripChart::
draw_guide_label(const PStatGraph::GuideBar &bar, int last_y) {
GdkWindow *window = gtk_widget_get_window(_scale_area);
cairo_t *cr = gdk_cairo_create(window);
draw_guide_label(cairo_t *cr, const PStatGraph::GuideBar &bar, int last_y) {
switch (bar._style) {
case GBS_target:
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) {
// Omit the label: there's a user-defined guide bar in the same space.
g_object_unref(layout);
cairo_destroy(cr);
return last_y;
}
}
@ -629,7 +625,6 @@ draw_guide_label(const PStatGraph::GuideBar &bar, int last_y) {
}
g_object_unref(layout);
cairo_destroy(cr);
return last_y;
}
@ -648,9 +643,9 @@ toggled_callback(GtkToggleButton *button, gpointer data) {
* Draws in the scale labels.
*/
gboolean GtkStatsStripChart::
expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) {
GtkStatsStripChart *self = (GtkStatsStripChart *)data;
self->draw_guide_labels();
self->draw_guide_labels(cr);
return TRUE;
}

View File

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