[SCM] calf/master: Make meter and linegraph a DrawingArea (also contains horrible hacking expose)
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:39:06 UTC 2013
The following commit has been merged in the master branch:
commit e40b32f613df868133e5676c9f506e5dd0130d77
Author: Torben Hohn <torbenh at gmx.de>
Date: Sat Jan 24 20:11:23 2009 +0100
Make meter and linegraph a DrawingArea (also contains horrible hacking expose)
diff --git a/src/calf/custom_ctl.h b/src/calf/custom_ctl.h
index 1d4b786..91ab03f 100644
--- a/src/calf/custom_ctl.h
+++ b/src/calf/custom_ctl.h
@@ -26,23 +26,26 @@
G_BEGIN_DECLS
-#define CALF_TYPE_LINE_GRAPH (calf_line_graph_get_type())
-#define CALF_LINE_GRAPH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CALF_TYPE_LINE_GRAPH, CalfLineGraph))
-#define CALF_IS_LINE_GRAPH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CALF_TYPE_LINE_GRAPH))
-#define CALF_LINE_GRAPH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CALF_TYPE_LINE_GRAPH, CalfLineGraphClass))
-#define CALF_IS_LINE_GRAPH_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((klass), CALF_TYPE_LINE_GRAPH))
+#define CALF_TYPE_LINE_GRAPH (calf_line_graph_get_type())
+#define CALF_LINE_GRAPH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CALF_TYPE_LINE_GRAPH, CalfLineGraph))
+#define CALF_IS_LINE_GRAPH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CALF_TYPE_LINE_GRAPH))
+#define CALF_LINE_GRAPH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CALF_TYPE_LINE_GRAPH, CalfLineGraphClass))
+#define CALF_IS_LINE_GRAPH_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((klass), CALF_TYPE_LINE_GRAPH))
+#define CALF_LINE_GRAPH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CALF_TYPE_LINE_GRAPH, CalfLineGraphClass))
struct CalfLineGraph
{
- GtkWidget parent;
+ GtkDrawingArea parent;
calf_plugins::line_graph_iface *source;
int source_id;
bool is_square;
+ //cairo_surface_t *cache_surface;
+ GdkPixmap *cache_pixmap;
};
struct CalfLineGraphClass
{
- GtkWidgetClass parent_class;
+ GtkDrawingAreaClass parent_class;
};
extern GtkWidget *calf_line_graph_new();
@@ -66,14 +69,14 @@ enum CalfVUMeterMode
struct CalfVUMeter
{
- GtkWidget parent;
+ GtkDrawingArea parent;
CalfVUMeterMode mode;
float value;
};
struct CalfVUMeterClass
{
- GtkWidgetClass parent_class;
+ GtkDrawingAreaClass parent_class;
};
extern GtkWidget *calf_vumeter_new();
diff --git a/src/custom_ctl.cpp b/src/custom_ctl.cpp
index c7e3e75..4eeeb42 100644
--- a/src/custom_ctl.cpp
+++ b/src/custom_ctl.cpp
@@ -22,6 +22,7 @@
#include <gdk/gdkkeysyms.h>
#include <cairo/cairo.h>
#include <math.h>
+#include <gdk/gdk.h>
/*
I don't really know how to do it, or if it can be done this way.
@@ -50,27 +51,39 @@ calf_line_graph_expose (GtkWidget *widget, GdkEventExpose *event)
g_assert(CALF_IS_LINE_GRAPH(widget));
CalfLineGraph *lg = CALF_LINE_GRAPH(widget);
- int ox = widget->allocation.x + 1, oy = widget->allocation.y + 1;
+ //int ox = widget->allocation.x + 1, oy = widget->allocation.y + 1;
+ int ox = 1, oy = 1;
int sx = widget->allocation.width - 2, sy = widget->allocation.height - 2;
- cairo_t *c = gdk_cairo_create(GDK_DRAWABLE(widget->window));
+ cairo_t *c;
GdkColor sc = { 0, 0, 0, 0 };
+ cairo_impl cimpl;
+
+ if (lg->source) {
+ float pos = 0;
+ bool vertical = false;
+ std::string legend;
+ if( lg->cache_pixmap == NULL ) {
+ c = gdk_cairo_create(GDK_DRAWABLE(widget->window));
+ //cairo_surface_t *window_surface = cairo_get_target( c );
+// lg->cache_surface = cairo_surface_create_similar( window_surface,
+// CAIRO_CONTENT_COLOR,
+// widget->allocation.width,
+// widget->allocation.height );
+// cairo_t *cache_cr = cairo_create( lg->cache_surface );
+ lg->cache_pixmap = gdk_pixmap_new( GDK_DRAWABLE(widget->window), widget->allocation.width, widget->allocation.height, -1 );
+ //cairo_t *cache_cr = gdk_cairo_create(GDK_DRAWABLE(lg->cache_pixmap));
+ cairo_set_line_width(c, 1);
gdk_cairo_set_source_color(c, &sc);
cairo_rectangle(c, ox, oy, sx, sy);
cairo_clip_preserve(c);
cairo_fill(c);
- cairo_impl cimpl;
cimpl.context = c;
cairo_select_font_face(c, "Bitstream Vera Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(c, 9);
- if (lg->source) {
- float pos = 0;
- bool vertical = false;
- cairo_set_line_width(c, 1);
- std::string legend;
for(int phase = 1; phase <= 2; phase++)
{
for(int gn = 0; legend = std::string(), cairo_set_source_rgba(c, 1, 1, 1, 0.5), lg->source->get_gridline(lg->source_id, gn, pos, vertical, legend, &cimpl); gn++)
@@ -111,13 +124,33 @@ calf_line_graph_expose (GtkWidget *widget, GdkEventExpose *event)
}
}
}
+ //cairo_set_source_surface( cache_cr, window_surface, 0,0 );
+ //cairo_paint( cache_cr );
+
+ //GdkGC *gc = gdk_gc_new( GDK_DRAWABLE( lg->cache_pixmap ) );
+ //gdk_draw_drawable( GDK_DRAWABLE( lg->cache_pixmap ), gc, GDK_DRAWABLE( widget->window ), 0,0,0,0,-1,-1 );
+ //gdk_gc_destroy(gc);
+
+ } else {
+ //printf( "cached.... \n" );
+ //cairo_save( c );
+ //cairo_set_source_surface( c, lg->cache_surface, 0,0 );
+ //cairo_paint( c );
+ //cairo_restore( c );
+ GdkGC *gc = gdk_gc_new( GDK_DRAWABLE( widget->window ) );
+ gdk_draw_drawable( GDK_DRAWABLE( widget->window ), gc, GDK_DRAWABLE( lg->cache_pixmap ), 0,0,0,0,-1,-1 );
+ gdk_gc_destroy(gc);
+ c = gdk_cairo_create(GDK_DRAWABLE(widget->window));
+ }
+ if(0) {
float *data = new float[2 * sx];
GdkColor sc2 = { 0, 0, 65535, 0 };
gdk_cairo_set_source_color(c, &sc2);
- cairo_set_line_join(c, CAIRO_LINE_JOIN_MITER);
+ //cairo_set_line_join(c, CAIRO_LINE_JOIN_ROUND);
cairo_set_line_width(c, 1);
for(int gn = 0; lg->source->get_graph(lg->source_id, gn, data, 2 * sx, &cimpl); gn++)
{
+ printf( "bla: %d\n", gn );
for (int i = 0; i < 2 * sx; i++)
{
int y = (int)(oy + sy / 2 - (sy / 2 - 1) * data[i]);
@@ -131,6 +164,7 @@ calf_line_graph_expose (GtkWidget *widget, GdkEventExpose *event)
cairo_stroke(c);
}
delete []data;
+ }
float x, y;
int size = 0;
GdkColor sc3 = { 0, 32767, 65535, 0 };
@@ -141,9 +175,9 @@ calf_line_graph_expose (GtkWidget *widget, GdkEventExpose *event)
cairo_arc(c, ox + x * sx, yv, size, 0, 2 * M_PI);
cairo_fill(c);
}
+ cairo_destroy(c);
}
- cairo_destroy(c);
gtk_paint_shadow(widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, widget, NULL, ox - 1, oy - 1, sx + 2, sy + 2);
// printf("exposed %p %d+%d\n", widget->window, widget->allocation.x, widget->allocation.y);
@@ -164,6 +198,8 @@ calf_line_graph_size_request (GtkWidget *widget,
g_assert(CALF_IS_LINE_GRAPH(widget));
// CalfLineGraph *lg = CALF_LINE_GRAPH(widget);
+ requisition->width = 40;
+ requisition->height = 40;
}
static void
@@ -173,6 +209,15 @@ calf_line_graph_size_allocate (GtkWidget *widget,
g_assert(CALF_IS_LINE_GRAPH(widget));
CalfLineGraph *lg = CALF_LINE_GRAPH(widget);
+ GtkWidgetClass *parent_class = (GtkWidgetClass *) g_type_class_peek_parent( CALF_LINE_GRAPH_GET_CLASS( lg ) );
+
+// if( lg->cache_surface )
+// cairo_surface_destroy( lg->cache_surface );
+// lg->cache_surface = NULL;
+ if( lg->cache_pixmap )
+ g_object_unref( G_OBJECT( lg->cache_pixmap ) );
+ lg->cache_pixmap = NULL;
+
widget->allocation = *allocation;
GtkAllocation &a = widget->allocation;
if (lg->is_square)
@@ -188,6 +233,7 @@ calf_line_graph_size_allocate (GtkWidget *widget,
a.height = a.width;
}
}
+ parent_class->size_allocate( widget, allocation );
}
static void
@@ -204,9 +250,11 @@ static void
calf_line_graph_init (CalfLineGraph *self)
{
GtkWidget *widget = GTK_WIDGET(self);
- GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
- widget->requisition.width = 40;
- widget->requisition.height = 40;
+ //GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
+ //widget->requisition.width = 40;
+ //widget->requisition.height = 40;
+ gtk_widget_set_size_request( widget, 40, 40 );
+ self->cache_pixmap = NULL;
}
GtkWidget *
@@ -240,7 +288,7 @@ calf_line_graph_get_type (void)
free(name);
continue;
}
- type = g_type_register_static( GTK_TYPE_WIDGET,
+ type = g_type_register_static( GTK_TYPE_DRAWING_AREA,
name,
type_info_copy,
(GTypeFlags)0);
@@ -257,9 +305,11 @@ static gboolean
calf_vumeter_expose (GtkWidget *widget, GdkEventExpose *event)
{
g_assert(CALF_IS_VUMETER(widget));
+
CalfVUMeter *vu = CALF_VUMETER(widget);
- int ox = widget->allocation.x + 1, oy = widget->allocation.y + 1;
+ //int ox = widget->allocation.x + 1, oy = widget->allocation.y + 1;
+ int ox = 1, oy = 1;
int sx = widget->allocation.width - 2, sy = widget->allocation.height - 2;
cairo_t *c = gdk_cairo_create(GDK_DRAWABLE(widget->window));
@@ -310,7 +360,7 @@ calf_vumeter_expose (GtkWidget *widget, GdkEventExpose *event)
cairo_destroy(c);
gtk_paint_shadow(widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, widget, NULL, ox - 1, oy - 1, sx + 2, sy + 2);
- // printf("exposed %p %d+%d\n", widget->window, widget->allocation.x, widget->allocation.y);
+ printf("exposed %p %d+%d\n", widget->window, widget->allocation.x, widget->allocation.y);
return TRUE;
}
@@ -340,16 +390,16 @@ calf_vumeter_class_init (CalfVUMeterClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
widget_class->expose_event = calf_vumeter_expose;
widget_class->size_request = calf_vumeter_size_request;
- widget_class->size_allocate = calf_vumeter_size_allocate;
+ //widget_class->size_allocate = calf_vumeter_size_allocate;
}
static void
calf_vumeter_init (CalfVUMeter *self)
{
GtkWidget *widget = GTK_WIDGET(self);
- GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
- widget->requisition.width = 40;
- widget->requisition.height = 40;
+ //GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
+ widget->requisition.width = 50;
+ widget->requisition.height = 15;
self->value = 0.5;
}
@@ -384,7 +434,7 @@ calf_vumeter_get_type (void)
free(name);
continue;
}
- type = g_type_register_static( GTK_TYPE_WIDGET,
+ type = g_type_register_static( GTK_TYPE_DRAWING_AREA,
name,
type_info_copy,
(GTypeFlags)0);
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list