summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorM Joonas Pihlaja <jpihlaja@cc.helsinki.fi>2011-02-19 15:44:04 +0200
committerM Joonas Pihlaja <jpihlaja@cc.helsinki.fi>2011-02-19 16:19:09 +0200
commit3a381a67b283226e1850731c698942b58814312f (patch)
tree459c9d5a14da4aa17e0573d8be9077f4e79b9c15
parentb6b430f2d6f9c1be4955a03853d0b7c7b2de262d (diff)
draw: Remove the backing pixmap from score rendering.patches
Denemo renders the score to a backing pixmap and then copies it to the widget. This duplicates work done by Gtk since it also does back buffering, so there's no reason to keep it around anymore. This patch removes it and adds some rudimentary clipping to the expose event's damage region.
-rw-r--r--include/denemo/denemo_types.h1
-rw-r--r--src/draw.c79
2 files changed, 31 insertions, 49 deletions
diff --git a/include/denemo/denemo_types.h b/include/denemo/denemo_types.h
index e8e4082b..36f22fa9 100644
--- a/include/denemo/denemo_types.h
+++ b/include/denemo/denemo_types.h
@@ -945,7 +945,6 @@ struct DenemoRoot
/* Fields used fairly directly for drawing */
GtkWidget *page;
GtkWidget *scorearea;
- GdkPixmap *pixmap;
GtkObject *vadjustment;
GtkWidget *vscrollbar;
GtkObject *hadjustment;
diff --git a/src/draw.c b/src/draw.c
index b84ded0c..b17990ad 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -54,8 +54,7 @@ create_tool_pixbuf(void) {
/**
* scorearea_configure_event
*
- * This function just creates a backing pixmap of the appropriate
- * size, recaculates the number of measures that can be fit into
+ * This function recaculates the number of measures that can be fit into
* the display, and returns
*/
gint
@@ -71,13 +70,6 @@ scorearea_configure_event (GtkWidget * widget, GdkEventConfigure * event)
create_tool_pixbuf();
init = TRUE;
}
- /* Create a new backing pixmap of the appropriate size */
- if (Denemo.pixmap)
- gdk_pixmap_unref (Denemo.pixmap);
-
- Denemo.pixmap = gdk_pixmap_new (widget->window,
- widget->allocation.width,
- widget->allocation.height, -1);
set_width_to_work_with (gui);
nudgerightward (gui);
@@ -927,12 +919,12 @@ static gboolean schedule_draw(gint *flip_count) {
}
/**
* This actually draws the score, staff-by-staff
- * @param widget pointer to the parent widget
+ * @param cr cairo context to draw with.
* @param gui pointer to the DenemoGUI structure
* returns whether the height of the drawing area was sufficient to draw everything
*/
static gboolean
-draw_score (GtkWidget * widget, DenemoGUI * gui)
+draw_score (cairo_t *cr, DenemoGUI * gui)
{
staffnode *curstaff;
gint y=0;
@@ -967,9 +959,9 @@ draw_score (GtkWidget * widget, DenemoGUI * gui)
get_obj_for_start_time(gui->si->smf, gui->si->end_time - 0.001);
//g_print("Start time %p %f end time %p %f\n", itp.startobj, si->start_time, itp.endobj, si->end_time);
}
- static cairo_t *cr;
- if(cr) cairo_destroy(cr);
- cr = widget?gdk_cairo_create( Denemo.pixmap ): NULL;
+
+ /* The colour for staff lines and such is black. */
+ if (cr) cairo_set_source_rgb( cr, 0, 0, 0 );
if(cr) cairo_scale( cr, gui->si->zoom, gui->si->zoom );
if(cr) cairo_translate( cr, 0.5, 0.5 );
@@ -1195,6 +1187,8 @@ gint
scorearea_expose_event (GtkWidget * widget, GdkEventExpose * event)
{
DenemoGUI *gui = Denemo.gui;
+ cairo_t *cr;
+
if((!Denemo.gui->si)||(!Denemo.gui->si->currentmeasure)){
g_warning("Cannot draw!\n");
return TRUE;
@@ -1203,44 +1197,33 @@ DenemoGUI *gui = Denemo.gui;
draw_score (NULL, gui);
return TRUE;
}
-
- do{
- /* Clear the backing pixmap */
- if(Denemo.gui->input_source!=INPUTKEYBOARD && Denemo.gui->input_source!=INPUTMIDI &&
- (Denemo.prefs.overlays || (Denemo.gui->input_source==INPUTAUDIO))
- && pitch_entry_active(gui)) {
- gdk_draw_rectangle (Denemo.pixmap,
- gcs_lightbluegc(),
- TRUE,
- 0, 0,
- widget->allocation.width, widget->allocation.height);
+ /* Layout the score. */
+ while(draw_score (NULL, gui) && !Denemo.gui->si->playingnow)
+ {/*nothing*/}
+
+ /* Setup a cairo context for rendering and clip to the exposed region. */
+ cr = gdk_cairo_create (event->window);
+ gdk_cairo_region (cr, event->region);
+ cairo_clip (cr);
+
+ /* Clear with an appropriate background color. */
+ if(Denemo.gui->input_source!=INPUTKEYBOARD && Denemo.gui->input_source!=INPUTMIDI &&
+ (Denemo.prefs.overlays || (Denemo.gui->input_source==INPUTAUDIO))
+ && pitch_entry_active(gui)) {
+ GdkColor col;
+ gdk_color_parse ("lightblue", &col);
+ gdk_cairo_set_source_color (cr, &col);
+ } else if (GTK_WIDGET_IS_SENSITIVE (Denemo.scorearea)) {
+ cairo_set_source_rgb (cr, 1,1,1);
} else {
- if (GTK_WIDGET_IS_SENSITIVE (Denemo.scorearea) )
- gdk_draw_rectangle (Denemo.pixmap,
- widget->style->white_gc,
- TRUE,
- 0, 0,
- widget->allocation.width, widget->allocation.height);
- else
- gdk_draw_rectangle (Denemo.pixmap,
- widget->style->bg_gc[0],
- TRUE,
- 0, 0,
- widget->allocation.width, widget->allocation.height);
+ gdk_cairo_set_source_color (cr, widget->style->bg);
}
+ cairo_paint (cr);
- /* Draw the score */
- } while(draw_score (widget, gui) && !Denemo.gui->si->playingnow);
-
- /* Now actually draw the backing pixmap onto the drawing area */
-
- gdk_draw_pixmap (Denemo.scorearea->window,
- Denemo.scorearea->style->black_gc,
- Denemo.pixmap,
- 0, 0, 0, 0,
- Denemo.scorearea->allocation.width,
- Denemo.scorearea->allocation.height);
+ /* Draw the score. */
+ draw_score (cr, gui);
+ cairo_destroy (cr);
return TRUE;
}