[xiph-commits] r12253 - trunk/sushivision
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Thu Dec 28 12:13:12 PST 2006
Author: xiphmont
Date: 2006-12-28 12:13:10 -0800 (Thu, 28 Dec 2006)
New Revision: 12253
Modified:
trunk/sushivision/example_fractal.c
trunk/sushivision/internal.h
trunk/sushivision/main.c
trunk/sushivision/panel-1d.c
trunk/sushivision/panel-2d.c
trunk/sushivision/undo.c
Log:
Sanitize/bring undo infrastructure up to date with respect to multiple panels:
Correct multiple bugs where undo is applied to wrong panel (use the
one in the logged event, not the passed in trigger!)
Implement instance-global undo as opposed to seperate undo stack per
panel, as an event in one panel can affect the others.
Modified: trunk/sushivision/example_fractal.c
===================================================================
--- trunk/sushivision/example_fractal.c 2006-12-28 19:06:59 UTC (rev 12252)
+++ trunk/sushivision/example_fractal.c 2006-12-28 20:13:10 UTC (rev 12253)
@@ -73,6 +73,10 @@
sushiv_new_panel_1d_linked(s,1,"X Slice",s->objective_list[0]->scale,
(int []){0,-1},
0,0);
+
+ sushiv_new_panel_1d_linked(s,2,"Y Slice",s->objective_list[0]->scale,
+ (int []){0,-1},
+ 0,SUSHIV_LINK_Y | SUSHIV_FLIP);
return 0;
}
Modified: trunk/sushivision/internal.h
===================================================================
--- trunk/sushivision/internal.h 2006-12-28 19:06:59 UTC (rev 12252)
+++ trunk/sushivision/internal.h 2006-12-28 20:13:10 UTC (rev 12253)
@@ -64,10 +64,6 @@
int maps_dirty;
int legend_dirty;
- int undo_level;
- int undo_suspend;
- sushiv_panel_undo_t **undo_stack;
-
// function bundles
void (*realize)(sushiv_panel_t *p);
void (*map_redraw)(sushiv_panel_t *p);
@@ -81,6 +77,12 @@
void (*update_menus)(sushiv_panel_t *p);
};
+struct sushiv_instance_internal {
+ int undo_level;
+ int undo_suspend;
+ sushiv_panel_undo_t **undo_stack;
+};
+
extern void _sushiv_realize_panel(sushiv_panel_t *p);
extern void _sushiv_clean_exit(int sig);
extern int _sushiv_new_panel(sushiv_instance_t *s,
Modified: trunk/sushivision/main.c
===================================================================
--- trunk/sushivision/main.c 2006-12-28 19:06:59 UTC (rev 12252)
+++ trunk/sushivision/main.c 2006-12-28 20:13:10 UTC (rev 12253)
@@ -171,6 +171,7 @@
sushiv_instance_t *sushiv_new_instance(void) {
sushiv_instance_t *ret=calloc(1,sizeof(*ret));
+ ret->private = calloc(1,sizeof(*ret->private));
if(instances){
instance_list = realloc(instance_list,(instances+1)*sizeof(*instance_list));
Modified: trunk/sushivision/panel-1d.c
===================================================================
--- trunk/sushivision/panel-1d.c 2006-12-28 19:06:59 UTC (rev 12252)
+++ trunk/sushivision/panel-1d.c 2006-12-28 20:13:10 UTC (rev 12253)
@@ -64,7 +64,6 @@
int xi,i;
int dw = p1->data_size;
double r = (p1->flip?p1->panel_w:p1->panel_h);
- double neg = p1->y.neg;
scalespace sx = (p1->flip?p1->y:p1->x);
scalespace sy = (p1->flip?p1->x:p1->y);
@@ -84,43 +83,48 @@
}
/* by objective */
- for(i=0;i<p->objectives;i++){
- double *data_vec = p1->data_vec[i];
- double yprev=NAN,xprev=NAN;
-
- u_int32_t color = mapping_calc(p1->mappings+i,0,0);
- cairo_set_source_rgb(c,
- ((color>>16)&0xff)/255.,
- ((color>>8)&0xff)/255.,
- ((color)&0xff)/255.);
-
- /* by x */
- for(xi=0;xi<dw;xi++){
- double val = data_vec[xi];
- double xpixel = xi;
- double ypixel = NAN;
-
- /* in linked panels, the data vector doesn't match the graph width; map */
- if(p1->link_x || p1->link_y)
- xpixel = scalespace_pixel(&p1->x,scalespace_value(&p1->vs,xpixel))+.5;
-
- /* map/render result */
- if(!isnan(val))
- ypixel = scalespace_pixel(&p1->y,val)+.5;
-
- if(!isnan(ypixel) && !isnan(yprev)){
- if(p1->flip){
- cairo_move_to(c,yprev,r-xprev);
- cairo_line_to(c,ypixel,r-xpixel);
- }else{
- cairo_move_to(c,xprev,r-yprev);
- cairo_line_to(c,xpixel,r-ypixel);
+ if(p1->data_vec){
+ for(i=0;i<p->objectives;i++){
+ double *data_vec = p1->data_vec[i];
+ if(data_vec){
+ double yprev=NAN,xprev=NAN;
+
+ u_int32_t color = mapping_calc(p1->mappings+i,0,0);
+
+ cairo_set_source_rgb(c,
+ ((color>>16)&0xff)/255.,
+ ((color>>8)&0xff)/255.,
+ ((color)&0xff)/255.);
+
+ /* by x */
+ for(xi=0;xi<dw;xi++){
+ double val = data_vec[xi];
+ double xpixel = xi;
+ double ypixel = NAN;
+
+ /* in linked panels, the data vector doesn't match the graph width; map */
+ if(p1->link_x || p1->link_y)
+ xpixel = scalespace_pixel(&p1->x,scalespace_value(&p1->vs,xpixel))+.5;
+
+ /* map/render result */
+ if(!isnan(val))
+ ypixel = scalespace_pixel(&p1->y,val)+.5;
+
+ if(!isnan(ypixel) && !isnan(yprev)){
+ if(p1->flip){
+ cairo_move_to(c,yprev,r-xprev);
+ cairo_line_to(c,ypixel,r-xpixel);
+ }else{
+ cairo_move_to(c,xprev,r-yprev);
+ cairo_line_to(c,xpixel,r-ypixel);
+ }
+ cairo_stroke(c);
+ }
+
+ yprev=ypixel;
+ xprev=xpixel;
}
- cairo_stroke(c);
}
-
- yprev=ypixel;
- xprev=xpixel;
}
}
}
@@ -610,8 +614,7 @@
if(s.m == 0){
fprintf(stderr,"X scale underflow; cannot zoom further.\n");
}else{
- p1->x=s;
-
+
d->bracket[0] = lo;
d->bracket[1] = hi;
update_crosshair(p);
@@ -762,8 +765,13 @@
x_max = scalespace_value(&sv,dw);
x_d = p1->x_d->number;
- plot->x = sx;
- plot->y = sy;
+ if(p1->flip){
+ plot->x = sy;
+ plot->y = sx;
+ }else{
+ plot->x = sx;
+ plot->y = sy;
+ }
// Bulletproofing; shouldn't ever come up
if(x_d==-1){
@@ -1001,8 +1009,8 @@
sushiv_panel1d_t *p1 = p->subtype->p1;
// is undo active?
- if(!p->private->undo_stack ||
- !p->private->undo_level){
+ if(!p->sushi->private->undo_stack ||
+ !p->sushi->private->undo_level){
gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p1->popmenu),0),FALSE);
gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p1->graphmenu),0),FALSE);
}else{
@@ -1011,9 +1019,9 @@
}
// is redo active?
- if(!p->private->undo_stack ||
- !p->private->undo_stack[p->private->undo_level] ||
- !p->private->undo_stack[p->private->undo_level+1]){
+ if(!p->sushi->private->undo_stack ||
+ !p->sushi->private->undo_stack[p->sushi->private->undo_level] ||
+ !p->sushi->private->undo_stack[p->sushi->private->undo_level+1]){
gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p1->popmenu),1),FALSE);
gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p1->graphmenu),1),FALSE);
}else{
Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c 2006-12-28 19:06:59 UTC (rev 12252)
+++ trunk/sushivision/panel-2d.c 2006-12-28 20:13:10 UTC (rev 12253)
@@ -1121,19 +1121,19 @@
sushiv_panel2d_t *p2 = p->subtype->p2;
// is undo active?
- if(!p->private->undo_stack ||
- !p->private->undo_level){
+ if(!p->sushi->private->undo_stack ||
+ !p->sushi->private->undo_level){
gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),0),FALSE);
- gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),0),FALSE);
+ gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->graphmenu),0),FALSE);
}else{
gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),0),TRUE);
gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->graphmenu),0),TRUE);
}
// is redo active?
- if(!p->private->undo_stack ||
- !p->private->undo_stack[p->private->undo_level] ||
- !p->private->undo_stack[p->private->undo_level+1]){
+ if(!p->sushi->private->undo_stack ||
+ !p->sushi->private->undo_stack[p->sushi->private->undo_level] ||
+ !p->sushi->private->undo_stack[p->sushi->private->undo_level+1]){
gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),1),FALSE);
gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->graphmenu),1),FALSE);
}else{
Modified: trunk/sushivision/undo.c
===================================================================
--- trunk/sushivision/undo.c 2006-12-28 19:06:59 UTC (rev 12252)
+++ trunk/sushivision/undo.c 2006-12-28 20:13:10 UTC (rev 12253)
@@ -28,114 +28,120 @@
/* encapsulates some amount of common undo/redo infrastructure */
+static void update_all_menus(sushiv_instance_t *s){
+ int i;
+ if(s->panel_list){
+ for(i=0;i<s->panels;i++)
+ if(s->panel_list[i])
+ s->panel_list[i]->private->update_menus(s->panel_list[i]);
+ }
+}
+
void _sushiv_panel_undo_suspend(sushiv_panel_t *p){
- p->private->undo_suspend++;
+ p->sushi->private->undo_suspend++;
}
void _sushiv_panel_undo_resume(sushiv_panel_t *p){
- p->private->undo_suspend--;
- if(p->private->undo_suspend<0){
+ p->sushi->private->undo_suspend--;
+ if(p->sushi->private->undo_suspend<0){
fprintf(stderr,"Internal error: undo suspend refcount count < 0\n");
- p->private->undo_suspend=0;
+ p->sushi->private->undo_suspend=0;
}
- if(p->private->undo_suspend==0)
- _sushiv_panel_undo_log(p);
+ //if(p->sushi->private->undo_suspend==0)
+ //_sushiv_panel_undo_log(p);
}
void _sushiv_panel_undo_log(sushiv_panel_t *p){
sushiv_panel_undo_t *u;
+ int i;
- if(!p->private->undo_stack)
- p->private->undo_stack = calloc(2,sizeof(*p->private->undo_stack));
+ if(!p->sushi->private->undo_stack)
+ p->sushi->private->undo_stack = calloc(2,sizeof(*p->sushi->private->undo_stack));
+ // log into a fresh entry; pop this level and all above it
+ if(p->sushi->private->undo_stack[p->sushi->private->undo_level]){
+ i=p->sushi->private->undo_level;
+ while(p->sushi->private->undo_stack[i]){
+ u = p->sushi->private->undo_stack[i];
+ if(u->mappings) free(u->mappings);
+ if(u->scale_vals[0]) free(u->scale_vals[0]);
+ if(u->scale_vals[1]) free(u->scale_vals[1]);
+ if(u->scale_vals[2]) free(u->scale_vals[2]);
+ if(u->obj_vals[0]) free(u->obj_vals[0]);
+ if(u->obj_vals[1]) free(u->obj_vals[1]);
+ if(u->obj_vals[2]) free(u->obj_vals[2]);
+ if(u->dim_vals[0]) free(u->dim_vals[0]);
+ if(u->dim_vals[1]) free(u->dim_vals[1]);
+ if(u->dim_vals[2]) free(u->dim_vals[2]);
+ free(u);
+ p->sushi->private->undo_stack[i]= NULL;
+ i++;
+ }
+ }
+
// alloc new undo
- u = p->private->undo_stack[p->private->undo_level];
- if(!u)
- u = p->private->undo_stack[p->private->undo_level]= calloc(1,sizeof(*u));
-
- // pass off actual populaiton to panel subtype
+ u = p->sushi->private->undo_stack[p->sushi->private->undo_level]= calloc(1,sizeof(*u));
+
+ // pass off actual population to panel subtype
u->p = p;
p->private->undo_log(u);
}
void _sushiv_panel_undo_restore(sushiv_panel_t *p){
- sushiv_panel_undo_t *u = p->private->undo_stack[p->private->undo_level];
+ sushiv_panel_undo_t *u = p->sushi->private->undo_stack[p->sushi->private->undo_level];
int remap_flag=0;
int recomp_flag=0;
- p->private->undo_restore(u, &remap_flag, &recomp_flag);
+ u->p->private->undo_restore(u, &remap_flag, &recomp_flag);
if(recomp_flag)
- p->private->request_compute(p);
+ u->p->private->request_compute(u->p);
else if(remap_flag){
- p->private->map_redraw(p);
- p->private->legend_redraw(p);
+ u->p->private->map_redraw(u->p);
+ u->p->private->legend_redraw(u->p);
}else
- plot_expose_request(PLOT(p->private->graph));
+ plot_expose_request(PLOT(u->p->private->graph));
}
void _sushiv_panel_undo_push(sushiv_panel_t *p){
- sushiv_panel_undo_t *u;
- int i;
- if(p->private->undo_suspend)return;
+ if(p->sushi->private->undo_suspend)return;
_sushiv_panel_undo_log(p);
- if(p->private->undo_stack[p->private->undo_level+1]){
- /* pop levels above this one */
- i=p->private->undo_level+1;
- while(p->private->undo_stack[i]){
- u = p->private->undo_stack[i];
- if(u->mappings) free(u->mappings);
- if(u->scale_vals[0]) free(u->scale_vals[0]);
- if(u->scale_vals[1]) free(u->scale_vals[1]);
- if(u->scale_vals[2]) free(u->scale_vals[2]);
- if(u->obj_vals[0]) free(u->obj_vals[0]);
- if(u->obj_vals[1]) free(u->obj_vals[1]);
- if(u->obj_vals[2]) free(u->obj_vals[2]);
- if(u->dim_vals[0]) free(u->dim_vals[0]);
- if(u->dim_vals[1]) free(u->dim_vals[1]);
- if(u->dim_vals[2]) free(u->dim_vals[2]);
- free(u);
- p->private->undo_stack[i]= NULL;
- i++;
- }
- }
-
// realloc stack
- p->private->undo_stack = realloc(p->private->undo_stack,(p->private->undo_level+3)*sizeof(*p->private->undo_stack));
- p->private->undo_level++;
- p->private->undo_stack[p->private->undo_level]=0;
- p->private->undo_stack[p->private->undo_level+1]=0;
- p->private->update_menus(p);
+ p->sushi->private->undo_stack = realloc(p->sushi->private->undo_stack,(p->sushi->private->undo_level+3)*sizeof(*p->sushi->private->undo_stack));
+ p->sushi->private->undo_level++;
+ p->sushi->private->undo_stack[p->sushi->private->undo_level]=NULL;
+ p->sushi->private->undo_stack[p->sushi->private->undo_level+1]=NULL;
+ update_all_menus(p->sushi);
}
void _sushiv_panel_undo_up(sushiv_panel_t *p){
- if(!p->private->undo_stack)return;
- if(!p->private->undo_stack[p->private->undo_level])return;
- if(!p->private->undo_stack[p->private->undo_level+1])return;
+ if(!p->sushi->private->undo_stack)return;
+ if(!p->sushi->private->undo_stack[p->sushi->private->undo_level])return;
+ if(!p->sushi->private->undo_stack[p->sushi->private->undo_level+1])return;
- p->private->undo_level++;
+ p->sushi->private->undo_level++;
_sushiv_panel_undo_suspend(p);
_sushiv_panel_undo_restore(p);
_sushiv_panel_undo_resume(p);
- p->private->update_menus(p);
+ update_all_menus(p->sushi);
}
void _sushiv_panel_undo_down(sushiv_panel_t *p){
- if(!p->private->undo_stack)return;
- if(!p->private->undo_level)return;
+ if(!p->sushi->private->undo_stack)return;
+ if(!p->sushi->private->undo_level)return;
_sushiv_panel_undo_log(p);
- p->private->undo_level--;
+ p->sushi->private->undo_level--;
_sushiv_panel_undo_suspend(p);
_sushiv_panel_undo_restore(p);
_sushiv_panel_undo_resume(p);
- p->private->update_menus(p);
+ update_all_menus(p->sushi);
}
More information about the commits
mailing list