mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
colored labels
This commit is contained in:
parent
d1f039f707
commit
531438ce6f
@ -260,7 +260,7 @@ get_collector_gc(int collector_index) {
|
|||||||
c.green = (int)(rgb[1] * 65535.0f);
|
c.green = (int)(rgb[1] * 65535.0f);
|
||||||
c.blue = (int)(rgb[2] * 65535.0f);
|
c.blue = (int)(rgb[2] * 65535.0f);
|
||||||
GdkGC *gc = gdk_gc_new(_pixmap);
|
GdkGC *gc = gdk_gc_new(_pixmap);
|
||||||
g_object_ref(gc);
|
// g_object_ref(gc); // Should this be ref_sink?
|
||||||
gdk_gc_set_rgb_fg_color(gc, &c);
|
gdk_gc_set_rgb_fg_color(gc, &c);
|
||||||
|
|
||||||
_brushes[collector_index] = gc;
|
_brushes[collector_index] = gc;
|
||||||
@ -311,9 +311,9 @@ setup_pixmap(int xsize, int ysize) {
|
|||||||
_pixmap_ysize = max(ysize, 0);
|
_pixmap_ysize = max(ysize, 0);
|
||||||
|
|
||||||
_pixmap = gdk_pixmap_new(_graph_window->window, _pixmap_xsize, _pixmap_ysize, -1);
|
_pixmap = gdk_pixmap_new(_graph_window->window, _pixmap_xsize, _pixmap_ysize, -1);
|
||||||
g_object_ref(_pixmap);
|
// g_object_ref(_pixmap); // Should this be ref_sink?
|
||||||
_pixmap_gc = gdk_gc_new(_pixmap);
|
_pixmap_gc = gdk_gc_new(_pixmap);
|
||||||
g_object_ref(_pixmap_gc);
|
// g_object_ref(_pixmap_gc); // Should this be ref_sink?
|
||||||
|
|
||||||
gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_white);
|
gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_white);
|
||||||
gdk_draw_rectangle(_pixmap, _pixmap_gc, TRUE, 0, 0,
|
gdk_draw_rectangle(_pixmap, _pixmap_gc, TRUE, 0, 0,
|
||||||
|
@ -45,13 +45,29 @@ GtkStatsLabel(GtkStatsMonitor *monitor, GtkStatsGraph *graph,
|
|||||||
_text = _monitor->get_client_data()->get_collector_name(_collector_index);
|
_text = _monitor->get_client_data()->get_collector_name(_collector_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
_widget = gtk_drawing_area_new();
|
||||||
|
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), "enter_notify_event",
|
||||||
|
G_CALLBACK(enter_notify_event_callback), this);
|
||||||
|
g_signal_connect(G_OBJECT(_widget), "leave_notify_event",
|
||||||
|
G_CALLBACK(leave_notify_event_callback), this);
|
||||||
|
g_signal_connect(G_OBJECT(_widget), "button_press_event",
|
||||||
|
G_CALLBACK(button_press_event_callback), this);
|
||||||
|
|
||||||
|
gtk_widget_show(_widget);
|
||||||
|
|
||||||
|
// Make up a PangoLayout to represent the text.
|
||||||
|
_layout = gtk_widget_create_pango_layout(_widget, _text.c_str());
|
||||||
|
|
||||||
|
// Set the fg and bg colors on the label.
|
||||||
RGBColorf rgb = _monitor->get_collector_color(_collector_index);
|
RGBColorf rgb = _monitor->get_collector_color(_collector_index);
|
||||||
int r = (int)(rgb[0] * 255.0f);
|
_bg_color.red = (int)(rgb[0] * 65535.0f);
|
||||||
int g = (int)(rgb[1] * 255.0f);
|
_bg_color.green = (int)(rgb[1] * 65535.0f);
|
||||||
int b = (int)(rgb[2] * 255.0f);
|
_bg_color.blue = (int)(rgb[2] * 65535.0f);
|
||||||
_bg_color = RGB(r, g, b);
|
|
||||||
_bg_brush = CreateSolidBrush(RGB(r, g, b));
|
|
||||||
|
|
||||||
// Should our foreground be black or white?
|
// Should our foreground be black or white?
|
||||||
float bright =
|
float bright =
|
||||||
@ -60,13 +76,16 @@ GtkStatsLabel(GtkStatsMonitor *monitor, GtkStatsGraph *graph,
|
|||||||
rgb[2] * 0.114;
|
rgb[2] * 0.114;
|
||||||
|
|
||||||
if (bright >= 0.5) {
|
if (bright >= 0.5) {
|
||||||
_fg_color = RGB(0, 0, 0);
|
_fg_color.red = _fg_color.green = _fg_color.blue = 0;
|
||||||
_highlight_brush = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
|
||||||
} else {
|
} else {
|
||||||
_fg_color = RGB(255, 255, 255);
|
_fg_color.red = _fg_color.green = _fg_color.blue = 0xffff;
|
||||||
_highlight_brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
// What are the extents of the text? This determines the minimum
|
||||||
|
// size of our widget.
|
||||||
|
int width, height;
|
||||||
|
pango_layout_get_pixel_size(_layout, &width, &height);
|
||||||
|
gtk_widget_set_size_request(_widget, width + 8, height);
|
||||||
|
|
||||||
_highlight = false;
|
_highlight = false;
|
||||||
_mouse_within = false;
|
_mouse_within = false;
|
||||||
@ -82,22 +101,6 @@ GtkStatsLabel::
|
|||||||
// DeleteObject(_bg_brush);
|
// DeleteObject(_bg_brush);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: GtkStatsLabel::setup
|
|
||||||
// Access: Public
|
|
||||||
// Description: Creates the actual widget.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
GtkWidget *GtkStatsLabel::
|
|
||||||
setup() {
|
|
||||||
_widget = gtk_event_box_new();
|
|
||||||
GtkWidget *label = gtk_label_new(_text.c_str());
|
|
||||||
gtk_container_add(GTK_CONTAINER(_widget), label);
|
|
||||||
gtk_widget_show(label);
|
|
||||||
gtk_widget_show(_widget);
|
|
||||||
|
|
||||||
return _widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GtkStatsLabel::get_widget
|
// Function: GtkStatsLabel::get_widget
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -128,9 +131,7 @@ void GtkStatsLabel::
|
|||||||
set_highlight(bool highlight) {
|
set_highlight(bool highlight) {
|
||||||
if (_highlight != highlight) {
|
if (_highlight != highlight) {
|
||||||
_highlight = highlight;
|
_highlight = highlight;
|
||||||
/*
|
gtk_widget_queue_draw(_widget);
|
||||||
InvalidateRect(_widget, NULL, TRUE);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,8 +156,77 @@ void GtkStatsLabel::
|
|||||||
set_mouse_within(bool mouse_within) {
|
set_mouse_within(bool mouse_within) {
|
||||||
if (_mouse_within != mouse_within) {
|
if (_mouse_within != mouse_within) {
|
||||||
_mouse_within = mouse_within;
|
_mouse_within = mouse_within;
|
||||||
/*
|
gtk_widget_queue_draw(_widget);
|
||||||
InvalidateRect(_widget, NULL, TRUE);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: GtkStatsLabel::expose_event_callback
|
||||||
|
// Access: Private, Static
|
||||||
|
// Description: Draws the background color of the label.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
gboolean GtkStatsLabel::
|
||||||
|
expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
|
||||||
|
GtkStatsLabel *self = (GtkStatsLabel *)data;
|
||||||
|
|
||||||
|
GdkGC *gc = gdk_gc_new(widget->window);
|
||||||
|
gdk_gc_set_rgb_fg_color(gc, &self->_bg_color);
|
||||||
|
|
||||||
|
gdk_draw_rectangle(widget->window, gc, TRUE, 0, 0,
|
||||||
|
widget->allocation.width, widget->allocation.height);
|
||||||
|
|
||||||
|
// Center the text within the rectangle.
|
||||||
|
int width, height;
|
||||||
|
pango_layout_get_pixel_size(self->_layout, &width, &height);
|
||||||
|
|
||||||
|
gdk_gc_set_rgb_fg_color(gc, &self->_fg_color);
|
||||||
|
gdk_draw_layout(widget->window, gc,
|
||||||
|
(widget->allocation.width - width) / 2, 0,
|
||||||
|
self->_layout);
|
||||||
|
|
||||||
|
// Now draw the highlight rectangle, if any.
|
||||||
|
if (self->_highlight || self->_mouse_within) {
|
||||||
|
gdk_draw_rectangle(widget->window, gc, FALSE, 0, 0,
|
||||||
|
widget->allocation.width - 1, widget->allocation.height - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref(gc);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: GtkStatsLabel::enter_notify_event_callback
|
||||||
|
// Access: Private, Static
|
||||||
|
// Description: Called when the mouse enters the label region
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
gboolean GtkStatsLabel::
|
||||||
|
enter_notify_event_callback(GtkWidget *widget, GdkEventCrossing *event,
|
||||||
|
gpointer data) {
|
||||||
|
GtkStatsLabel *self = (GtkStatsLabel *)data;
|
||||||
|
self->set_mouse_within(true);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: GtkStatsLabel::leave_notify_event_callback
|
||||||
|
// Access: Private, Static
|
||||||
|
// Description: Called when the mouse leaves the label region
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
gboolean GtkStatsLabel::
|
||||||
|
leave_notify_event_callback(GtkWidget *widget, GdkEventCrossing *event,
|
||||||
|
gpointer data) {
|
||||||
|
GtkStatsLabel *self = (GtkStatsLabel *)data;
|
||||||
|
self->set_mouse_within(false);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: GtkStatsLabel::button_press_event_callback
|
||||||
|
// Access: Private, Static
|
||||||
|
// Description: Called when the mouse leaves the label region
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
gboolean GtkStatsLabel::
|
||||||
|
button_press_event_callback(GtkWidget *widget, GdkEventButton *event,
|
||||||
|
gpointer data) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
@ -39,7 +39,6 @@ public:
|
|||||||
int thread_index, int collector_index, bool use_fullname);
|
int thread_index, int collector_index, bool use_fullname);
|
||||||
~GtkStatsLabel();
|
~GtkStatsLabel();
|
||||||
|
|
||||||
GtkWidget *setup();
|
|
||||||
GtkWidget *get_widget() const;
|
GtkWidget *get_widget() const;
|
||||||
|
|
||||||
int get_collector_index() const;
|
int get_collector_index() const;
|
||||||
@ -49,6 +48,17 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void set_mouse_within(bool mouse_within);
|
void set_mouse_within(bool mouse_within);
|
||||||
|
static gboolean expose_event_callback(GtkWidget *widget,
|
||||||
|
GdkEventExpose *event, gpointer data);
|
||||||
|
static gboolean enter_notify_event_callback(GtkWidget *widget,
|
||||||
|
GdkEventCrossing *event,
|
||||||
|
gpointer data);
|
||||||
|
static gboolean leave_notify_event_callback(GtkWidget *widget,
|
||||||
|
GdkEventCrossing *event,
|
||||||
|
gpointer data);
|
||||||
|
static gboolean button_press_event_callback(GtkWidget *widget,
|
||||||
|
GdkEventButton *event,
|
||||||
|
gpointer data);
|
||||||
|
|
||||||
GtkStatsMonitor *_monitor;
|
GtkStatsMonitor *_monitor;
|
||||||
GtkStatsGraph *_graph;
|
GtkStatsGraph *_graph;
|
||||||
@ -56,6 +66,9 @@ private:
|
|||||||
int _collector_index;
|
int _collector_index;
|
||||||
string _text;
|
string _text;
|
||||||
GtkWidget *_widget;
|
GtkWidget *_widget;
|
||||||
|
GdkColor _fg_color;
|
||||||
|
GdkColor _bg_color;
|
||||||
|
PangoLayout *_layout;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
COLORREF _bg_color;
|
COLORREF _bg_color;
|
||||||
|
@ -27,8 +27,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
GtkStatsLabelStack::
|
GtkStatsLabelStack::
|
||||||
GtkStatsLabelStack() {
|
GtkStatsLabelStack() {
|
||||||
_widget = NULL;
|
_widget = gtk_vbox_new(FALSE, 0);
|
||||||
|
|
||||||
_highlight_label = -1;
|
_highlight_label = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,30 +42,15 @@ GtkStatsLabelStack::
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GtkStatsLabelStack::setup
|
// Function: GtkStatsLabelStack::get_widget
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description: Creates the actual widget object.
|
// Description: Returns the widget for this stack.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
GtkWidget *GtkStatsLabelStack::
|
GtkWidget *GtkStatsLabelStack::
|
||||||
setup() {
|
get_widget() const {
|
||||||
if (_widget == NULL) {
|
|
||||||
_widget = gtk_vbox_new(FALSE, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _widget;
|
return _widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: GtkStatsLabelStack::is_setup
|
|
||||||
// Access: Public
|
|
||||||
// Description: Returns true if the label stack has been set up,
|
|
||||||
// false otherwise.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
bool GtkStatsLabelStack::
|
|
||||||
is_setup() const {
|
|
||||||
return (_widget != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GtkStatsLabelStack::get_label_collector_index
|
// Function: GtkStatsLabelStack::get_label_collector_index
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -107,8 +91,8 @@ add_label(GtkStatsMonitor *monitor, GtkStatsGraph *graph,
|
|||||||
GtkStatsLabel *label =
|
GtkStatsLabel *label =
|
||||||
new GtkStatsLabel(monitor, graph, thread_index, collector_index, use_fullname);
|
new GtkStatsLabel(monitor, graph, thread_index, collector_index, use_fullname);
|
||||||
|
|
||||||
gtk_box_pack_start(GTK_BOX(_widget), label->setup(),
|
gtk_box_pack_end(GTK_BOX(_widget), label->get_widget(),
|
||||||
FALSE, FALSE, 0);
|
FALSE, FALSE, 0);
|
||||||
|
|
||||||
int label_index = (int)_labels.size();
|
int label_index = (int)_labels.size();
|
||||||
_labels.push_back(label);
|
_labels.push_back(label);
|
||||||
|
@ -38,8 +38,7 @@ public:
|
|||||||
GtkStatsLabelStack();
|
GtkStatsLabelStack();
|
||||||
~GtkStatsLabelStack();
|
~GtkStatsLabelStack();
|
||||||
|
|
||||||
GtkWidget *setup();
|
GtkWidget *get_widget() const;
|
||||||
bool is_setup() const;
|
|
||||||
|
|
||||||
int get_label_collector_index(int label_index) const;
|
int get_label_collector_index(int label_index) const;
|
||||||
|
|
||||||
|
@ -91,8 +91,8 @@ GtkStatsMonitor::
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEVELOP_GTKSTATS
|
#ifdef DEVELOP_GTKSTATS
|
||||||
// For Gtkstats developers, exit when the first monitor closes.
|
// For GtkStats developers, exit when the first monitor closes.
|
||||||
gtk_main_quit(0);
|
gtk_main_quit();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,10 +62,10 @@ GtkStatsStripChart(GtkStatsMonitor *monitor, int thread_index,
|
|||||||
_smooth_check_box = 0;
|
_smooth_check_box = 0;
|
||||||
|
|
||||||
GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
|
GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), _label_stack.setup(),
|
gtk_box_pack_start(GTK_BOX(hbox), _label_stack.get_widget(),
|
||||||
FALSE, FALSE, 0);
|
FALSE, FALSE, 0);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), _graph_window,
|
gtk_box_pack_start(GTK_BOX(hbox), _graph_window,
|
||||||
FALSE, FALSE, 0);
|
TRUE, TRUE, 0);
|
||||||
|
|
||||||
gtk_container_add(GTK_CONTAINER(_window), hbox);
|
gtk_container_add(GTK_CONTAINER(_window), hbox);
|
||||||
|
|
||||||
@ -237,10 +237,7 @@ void GtkStatsStripChart::
|
|||||||
set_vertical_scale(float value_height) {
|
set_vertical_scale(float value_height) {
|
||||||
PStatStripChart::set_vertical_scale(value_height);
|
PStatStripChart::set_vertical_scale(value_height);
|
||||||
|
|
||||||
GdkRectangle rect = {
|
gtk_widget_queue_draw(_graph_window);
|
||||||
0, 0, get_xsize(), get_ysize()
|
|
||||||
};
|
|
||||||
gdk_window_invalidate_rect(_graph_window->window, &rect, FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user