From 3084c95cf968dcb4d901b77ee73672e25fa07484 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 12 Jun 2012 14:57:38 +0200 Subject: don't render into invisible area of the text layer it is unknown how large that area has to be in order for every contribution to fit in --- lib/experiment-reader/experiment-reader.c | 4 +-- .../gtk-experiment-transcript-private.h | 2 -- .../gtk-experiment-transcript.c | 30 ++++++++++++++-------- 3 files changed, 22 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/experiment-reader/experiment-reader.c b/lib/experiment-reader/experiment-reader.c index 0ba25b2..b5aa398 100644 --- a/lib/experiment-reader/experiment-reader.c +++ b/lib/experiment-reader/experiment-reader.c @@ -354,7 +354,7 @@ experiment_reader_get_contributions_by_speaker(ExperimentReader *reader, * @brief Get a contribution by time * * Gets the closest contribution after the specified time or the last one - * if there is no contribution after or at the specified time. + * if there is no contribution after the specified time. * The contribution is returned as a pointer into the contribution list * so that the list may be traversed by the caller. * @@ -371,7 +371,7 @@ experiment_reader_get_contribution_by_time(GList *contribs, gint64 timept) ExperimentReaderContrib *contrib = (ExperimentReaderContrib *)cur->data; - if (contrib->start_time >= timept || + if (contrib->start_time > timept || cur->next == NULL) return cur; } diff --git a/lib/gtk-experiment-widgets/gtk-experiment-transcript-private.h b/lib/gtk-experiment-widgets/gtk-experiment-transcript-private.h index af9a16f..98c689c 100644 --- a/lib/gtk-experiment-widgets/gtk-experiment-transcript-private.h +++ b/lib/gtk-experiment-widgets/gtk-experiment-transcript-private.h @@ -58,8 +58,6 @@ struct _GtkExperimentTranscriptPrivate { #define DEFAULT_WIDTH 100 #define DEFAULT_HEIGHT 200 -#define LAYER_TEXT_INVISIBLE 100 - /** @todo scale should be configurable */ #define PX_PER_SECOND 15 #define TIME_TO_PX(TIME) ((TIME)/(1000/PX_PER_SECOND)) diff --git a/lib/gtk-experiment-widgets/gtk-experiment-transcript.c b/lib/gtk-experiment-widgets/gtk-experiment-transcript.c index 05a627e..b33d230 100644 --- a/lib/gtk-experiment-widgets/gtk-experiment-transcript.c +++ b/lib/gtk-experiment-widgets/gtk-experiment-transcript.c @@ -392,7 +392,7 @@ gtk_experiment_transcript_reconfigure(GtkExperimentTranscript *trans) GOBJECT_UNREF_SAFE(trans->priv->layer_text); trans->priv->layer_text = gdk_pixmap_new(gtk_widget_get_window(widget), widget->allocation.width, - widget->allocation.height + LAYER_TEXT_INVISIBLE, + widget->allocation.height, -1); pango_layout_set_width(trans->priv->layer_text_layout, widget->allocation.width*PANGO_SCALE); @@ -407,14 +407,14 @@ gtk_experiment_transcript_text_layer_redraw(GtkExperimentTranscript *trans) GtkWidget *widget = GTK_WIDGET(trans); gint64 current_time = 0; - gint last_contrib_y; + gint last_contrib_y = -1; gdk_draw_rectangle(GDK_DRAWABLE(trans->priv->layer_text), widget->style->bg_gc[gtk_widget_get_state(widget)], TRUE, 0, 0, widget->allocation.width, - widget->allocation.height + LAYER_TEXT_INVISIBLE); + widget->allocation.height); gtk_widget_queue_draw_area(widget, 0, 0, widget->allocation.width, @@ -427,13 +427,14 @@ gtk_experiment_transcript_text_layer_redraw(GtkExperimentTranscript *trans) if (trans->priv->time_adjustment != NULL) current_time = (gint64)gtk_adjustment_get_value(GTK_ADJUSTMENT(trans->priv->time_adjustment)); - last_contrib_y = widget->allocation.height + LAYER_TEXT_INVISIBLE; - for (GList *cur = experiment_reader_get_contribution_by_time(trans->priv->contribs, - current_time); + for (GList *cur = experiment_reader_get_contribution_by_time( + trans->priv->contribs, + current_time); cur != NULL; cur = cur->prev) { - ExperimentReaderContrib *contrib = (ExperimentReaderContrib *)cur->data; + ExperimentReaderContrib *contrib = (ExperimentReaderContrib *) + cur->data; gint y = widget->allocation.height - TIME_TO_PX(current_time - contrib->start_time); @@ -441,8 +442,10 @@ gtk_experiment_transcript_text_layer_redraw(GtkExperimentTranscript *trans) PangoAttrList *attrib_list; - if (y > widget->allocation.height + LAYER_TEXT_INVISIBLE) + if (y >= widget->allocation.height) { + last_contrib_y = y; continue; + } attrib_list = pango_attr_list_new(); @@ -462,8 +465,13 @@ gtk_experiment_transcript_text_layer_redraw(GtkExperimentTranscript *trans) pango_layout_set_text(trans->priv->layer_text_layout, contrib->text, -1); - pango_layout_set_height(trans->priv->layer_text_layout, - (last_contrib_y - y)*PANGO_SCALE); + + if (last_contrib_y == 1) + pango_layout_set_height(trans->priv->layer_text_layout, + G_MAXINT); + else + pango_layout_set_height(trans->priv->layer_text_layout, + (last_contrib_y - y)*PANGO_SCALE); pango_layout_get_pixel_size(trans->priv->layer_text_layout, NULL, &logical_height); @@ -473,6 +481,8 @@ gtk_experiment_transcript_text_layer_redraw(GtkExperimentTranscript *trans) gdk_draw_layout(GDK_DRAWABLE(trans->priv->layer_text), widget->style->text_gc[gtk_widget_get_state(widget)], 0, y, trans->priv->layer_text_layout); + if (y <= 0) + break; last_contrib_y = y; } } -- cgit v1.2.3