[xiph-commits] r12618 - trunk/sushivision
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Sat Mar 3 11:50:46 PST 2007
Author: xiphmont
Date: 2007-03-03 11:50:44 -0800 (Sat, 03 Mar 2007)
New Revision: 12618
Modified:
trunk/sushivision/panel-1d.c
trunk/sushivision/panel-2d.c
trunk/sushivision/slider.c
trunk/sushivision/slider.h
Log:
Add objective scale legend to 2d panel printing
Change image compositing filter to NEAREST to preserve sharp pixel
boundaries on slider legends and discrete data.
Modified: trunk/sushivision/panel-1d.c
===================================================================
--- trunk/sushivision/panel-1d.c 2007-03-03 17:50:02 UTC (rev 12617)
+++ trunk/sushivision/panel-1d.c 2007-03-03 19:50:44 UTC (rev 12618)
@@ -1307,7 +1307,7 @@
GtkWidget *label = gtk_label_new(o->name);
gtk_misc_set_alignment(GTK_MISC(label),1.,.5);
gtk_table_attach(GTK_TABLE(p1->obj_table),label,0,1,i,i+1,
- GTK_FILL,0,10,0);
+ GTK_FILL,0,5,0);
/* mapping pulldown */
{
@@ -1388,7 +1388,7 @@
GtkWidget *label = gtk_label_new(d->name);
gtk_misc_set_alignment(GTK_MISC(label),1.,.5);
gtk_table_attach(GTK_TABLE(p1->dim_table),label,0,1,i,i+1,
- GTK_FILL,0,10,0);
+ GTK_FILL,0,5,0);
/* x radio buttons */
if(!(d->flags & SUSHIV_DIM_NO_X) && !p1->link_x && !p1->link_y){
@@ -1399,7 +1399,7 @@
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p1->dim_xb[i]),TRUE);
}
gtk_table_attach(GTK_TABLE(p1->dim_table),p1->dim_xb[i],1,2,i,i+1,
- 0,0,10,0);
+ 0,0,3,0);
}
p->private->dim_scales[i] =
Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c 2007-03-03 17:50:02 UTC (rev 12617)
+++ trunk/sushivision/panel-2d.c 2007-03-03 19:50:44 UTC (rev 12618)
@@ -732,16 +732,23 @@
if(!plot) return;
- cairo_set_source_surface(c, plot->back,0,0);
+ cairo_pattern_t *pattern = cairo_pattern_create_for_surface(plot->back);
+ cairo_pattern_set_filter(pattern, CAIRO_FILTER_NEAREST);
+ cairo_set_source(c,pattern);
cairo_paint(c);
+ cairo_pattern_destroy(pattern);
}
static void sushiv_panel2d_print(sushiv_panel_t *p, cairo_t *c, int w, int h){
+ sushiv_panel2d_t *p2 = p->subtype->p2;
Plot *plot = PLOT(p->private->graph);
double pw = p->private->graph->allocation.width;
double ph = p->private->graph->allocation.height;
double scale;
+ int i;
+ double maxlabelw=0;
+ double y;
if(w/pw < h/ph)
scale = w/pw;
@@ -749,13 +756,53 @@
scale = h/ph;
cairo_matrix_t m;
+ cairo_save(c);
cairo_get_matrix(c,&m);
cairo_matrix_scale(&m,scale,scale);
cairo_set_matrix(c,&m);
-
+
plot_print(plot, c, ph*scale, (void(*)(void *, cairo_t *))sushiv_panel2d_print_bg, p);
+ cairo_restore(c);
- // XXX print objective scales
+ // find extents widths for objective scale labels
+ cairo_set_font_size(c,10);
+ for(i=0;i<p->objectives;i++){
+ cairo_text_extents_t ex;
+ sushiv_objective_t *o = p->objective_list[i].o;
+ cairo_text_extents(c, o->name, &ex);
+ if(ex.width > maxlabelw) maxlabelw=ex.width;
+ }
+
+
+ y = ph * scale + 10;
+
+ for(i=0;i<p->objectives;i++){
+ sushiv_objective_t *o = p->objective_list[i].o;
+ Slider *s = p2->range_scales[i];
+
+ // get scale height
+ double labelh = slider_print_height(s);
+ cairo_text_extents_t ex;
+ cairo_text_extents (c, o->name, &ex);
+
+ int lx = maxlabelw - ex.width;
+ int ly = labelh/2 + ex.height/2;
+
+ // print objective labels
+ cairo_set_source_rgb(c,0.,0.,0.);
+ cairo_move_to (c, lx,ly+y);
+ cairo_show_text (c, o->name);
+
+ // draw slider
+ // set translation
+ cairo_save(c);
+ cairo_translate (c, maxlabelw + 10, y);
+ slider_print(s, c, w - maxlabelw - 10, labelh);
+ cairo_restore(c);
+
+ y += labelh;
+ }
+
}
// call while locked
@@ -1684,7 +1731,7 @@
GtkWidget *label = gtk_label_new(o->name);
gtk_misc_set_alignment(GTK_MISC(label),1.,.5);
gtk_table_attach(GTK_TABLE(p2->obj_table),label,0,1,i,i+1,
- GTK_FILL,0,10,0);
+ GTK_FILL,0,8,0);
/* mapping pulldown */
{
@@ -1700,7 +1747,7 @@
p2->range_pulldowns[i] = menu;
}
- /* the range mapping slices/slider */
+ /* the range mapping slices/slider */
sl[0] = slice_new(map_callback_2d,p->objective_list+i);
sl[1] = slice_new(map_callback_2d,p->objective_list+i);
sl[2] = slice_new(map_callback_2d,p->objective_list+i);
@@ -1713,6 +1760,7 @@
GTK_EXPAND|GTK_FILL,0,0,0);
p2->range_scales[i] = slider_new((Slice **)sl,3,o->scale->label_list,o->scale->val_list,
o->scale->vals,SLIDER_FLAG_INDEPENDENT_MIDDLE);
+ gtk_table_set_col_spacing(GTK_TABLE(p2->obj_table),3,5);
slice_thumb_set((Slice *)sl[0],lo);
slice_thumb_set((Slice *)sl[1],lo);
Modified: trunk/sushivision/slider.c
===================================================================
--- trunk/sushivision/slider.c 2007-03-03 17:50:02 UTC (rev 12617)
+++ trunk/sushivision/slider.c 2007-03-03 19:50:44 UTC (rev 12618)
@@ -919,3 +919,135 @@
s->quant_num=num;
s->quant_denom=denom;
}
+
+double slider_print_height(Slider *s){
+ return (s->slices[0]->allocation.height - s->ypad*2)*1.2;
+}
+
+void slider_print(Slider *s, cairo_t *c, int w, int h){
+ cairo_save(c);
+ double ypad = h*.1;
+ double neg = (s->neg? -1.: 1.);
+
+ // set clip region
+ cairo_rectangle(c,0,ypad,w,h-ypad*2);
+ cairo_clip(c);
+
+ // determine start/end deltas
+ // eliminate label sections that are completely unused
+ int slices = s->num_slices;
+ double lo = (slices>0?SLICE(s->slices[0])->thumb_val:s->label_vals[0]) * neg;
+ double hi = (slices>0?SLICE(s->slices[slices-1])->thumb_val:s->label_vals[s->labels-1]) * neg;
+
+ // alpha could push up the unused area
+ if(slices==3 && SLICE(s->slices[1])->thumb_val*neg>lo)
+ lo = SLICE(s->slices[1])->thumb_val*neg;
+
+ // if lo>hi (due to alpha), show the whole scale empty
+ if(lo>hi){
+ lo = s->label_vals[0]*neg;
+ hi = s->label_vals[s->labels-1]*neg;
+ }
+
+ int firstlabel=0;
+ int lastlabel=s->labels-1;
+ int i;
+
+ for(i=s->labels-2;i>0;i--)
+ if(lo>s->label_vals[i]*neg){
+ firstlabel=i;
+ break;
+ }
+
+ for(i=1;i<s->labels-1;i++)
+ if(hi<s->label_vals[i]*neg){
+ lastlabel=i;
+ break;
+ }
+
+ double lodel = 1. / (s->labels-1) * firstlabel;
+ double hidel = 1. / (s->labels-1) * lastlabel;
+ double alphadel = (slices==3 ?
+ slider_val_to_del(s,SLICE(s->slices[1])->thumb_val):0.);
+
+ // create background image
+ {
+ cairo_surface_t *image = cairo_image_surface_create(CAIRO_FORMAT_RGB24,w,h);
+ cairo_t *ci = cairo_create(image);
+ int x,y;
+
+ cairo_save(c);
+ cairo_set_source_rgb (ci, .5,.5,.5);
+ cairo_paint(ci);
+ cairo_set_source_rgb (ci, .314,.314,.314);
+ for(y=0;y<=h/2;y+=8){
+ int phase = (y>>3)&1;
+ for(x=0;x<w;x+=8){
+ if(phase)
+ cairo_rectangle(ci,x,y+h/2.,8.,8.);
+ else
+ cairo_rectangle(ci,x,h/2.-y-8,8.,8.);
+ cairo_fill(ci);
+ phase=!phase;
+ }
+ }
+
+ for(y=0;y<h;y++){
+ ucolor *line = (ucolor *)cairo_image_surface_get_data(image) + w*y;
+ for(x=0;x<w;x++){
+ double del = (hidel - lodel) / (w-1) * x + lodel;
+ if(del>=alphadel)
+ line[x].u = mapping_calc(s->gradient, del, line[x].u);
+ }
+ }
+
+ // composite background with correct resample filter
+ cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image);
+ cairo_pattern_set_filter(pattern, CAIRO_FILTER_NEAREST);
+ cairo_set_source(c,pattern);
+ cairo_rectangle(c,0,0,w,h);
+ cairo_fill(c);
+
+ cairo_destroy(ci);
+ cairo_pattern_destroy(pattern);
+ cairo_surface_destroy(image);
+ cairo_restore(c);
+ }
+
+ // add labels
+ cairo_set_font_size(c,h-ypad*2-3);
+ for(i=firstlabel;i<=lastlabel;i++){
+ double x = (double)(i-firstlabel) / (lastlabel - firstlabel) * (w-1);
+ double y;
+ cairo_text_extents_t ex;
+
+ cairo_move_to(c,x+.5,ypad);
+ cairo_line_to(c,x+.5,h-ypad);
+ cairo_set_source_rgba(c,0,0,0,.8);
+ cairo_set_line_width(c,1);
+ cairo_stroke(c);
+
+ cairo_text_extents (c, s->label[i], &ex);
+ if(i>firstlabel){
+
+ x-=2;
+ x-=ex.width;
+
+ }else{
+ x+=2;
+ }
+ y = h/2. - ex.y_bearing/2.;
+
+ cairo_set_source_rgba(c,1.,1.,1.,.5);
+ cairo_set_line_width(c,2.5);
+ cairo_move_to (c, x,y);
+ cairo_text_path (c, s->label[i]);
+ cairo_stroke(c);
+
+ cairo_set_source_rgba(c,0,0,0,1.);
+ cairo_move_to (c, x,y);
+ cairo_show_text (c, s->label[i]);
+ }
+
+ cairo_restore(c);
+}
Modified: trunk/sushivision/slider.h
===================================================================
--- trunk/sushivision/slider.h 2007-03-03 17:50:02 UTC (rev 12617)
+++ trunk/sushivision/slider.h 2007-03-03 19:50:44 UTC (rev 12618)
@@ -74,3 +74,6 @@
extern void slider_set_value(Slider *s, int thumbnum, double v);
extern double slider_del_to_val(Slider *s, double del);
extern void slider_set_quant(Slider *s, double n, double d);
+
+extern void slider_print(Slider *s, cairo_t *c, int w, int h);
+extern double slider_print_height(Slider *s);
More information about the commits
mailing list