1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 11:31:54 +02:00

eeshow/gui.c: replace {curr,last}_hist with {new,old}_hist

Since we already change the UI paradigm, this greatly simplifies the code.
This commit is contained in:
Werner Almesberger 2016-08-09 19:01:05 -03:00
parent 2bd452d3b3
commit 672228148d

View File

@ -97,9 +97,9 @@ struct gui_ctx {
struct gui_sheet delta_ab; struct gui_sheet delta_ab;
struct gui_sheet *curr_sheet; struct gui_sheet *curr_sheet;
/* current sheet */ /* current sheet, always on new_hist */
struct gui_hist *curr_hist; struct gui_hist *new_hist;
struct gui_hist *last_hist; struct gui_hist *old_hist; /* NULL if not comparing */
}; };
@ -154,10 +154,8 @@ static void hack(const struct gui_ctx *ctx, cairo_t *cr)
{ {
const struct gui_sheet *new = ctx->curr_sheet; const struct gui_sheet *new = ctx->curr_sheet;
const struct gui_sheet *old = find_corresponding_sheet( const struct gui_sheet *old = find_corresponding_sheet(
ctx->last_hist->sheets, ctx->curr_hist->sheets, ctx->curr_sheet); ctx->old_hist->sheets, ctx->new_hist->sheets, ctx->curr_sheet);
if (ctx->curr_hist->age > ctx->last_hist->age)
swap(new, old);
diff_to_canvas(cr, ctx->x, ctx->y, 1.0 / (1 << ctx->zoom), diff_to_canvas(cr, ctx->x, ctx->y, 1.0 / (1 << ctx->zoom),
old->gfx_ctx, new->gfx_ctx); old->gfx_ctx, new->gfx_ctx);
} }
@ -177,7 +175,7 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
y = -(sheet->ymin + ctx->y) * f + alloc.height / 2; y = -(sheet->ymin + ctx->y) * f + alloc.height / 2;
cro_canvas_prepare(cr); cro_canvas_prepare(cr);
if (!ctx->last_hist) { if (!ctx->old_hist) {
cro_canvas_draw(sheet->gfx_ctx, cr, x, y, f); cro_canvas_draw(sheet->gfx_ctx, cr, x, y, f);
} else { } else {
#if 0 #if 0
@ -219,6 +217,7 @@ static void mark_aois(struct gui_ctx *ctx, struct gui_sheet *sheet);
static void render_delta(struct gui_ctx *ctx) static void render_delta(struct gui_ctx *ctx)
{ {
#if 0 #if 0
/* @@@ needs updating for curr/last vs. new/old */
struct sheet *sch_a, *sch_b, *sch_ab; struct sheet *sch_a, *sch_b, *sch_ab;
const struct gui_sheet *a = ctx->curr_sheet; const struct gui_sheet *a = ctx->curr_sheet;
const struct gui_sheet *b = find_corresponding_sheet( const struct gui_sheet *b = find_corresponding_sheet(
@ -244,7 +243,7 @@ static void render_delta(struct gui_ctx *ctx)
// @@@ clean up when leaving sheet // @@@ clean up when leaving sheet
#endif #endif
struct gui_sheet *b = find_corresponding_sheet( struct gui_sheet *b = find_corresponding_sheet(
ctx->last_hist->sheets, ctx->curr_hist->sheets, ctx->curr_sheet); ctx->old_hist->sheets, ctx->new_hist->sheets, ctx->curr_sheet);
if (!b->rendered) { if (!b->rendered) {
render_sheet(b); render_sheet(b);
@ -335,13 +334,13 @@ static void curr_sheet_size(struct gui_ctx *ctx, int *w, int *h)
const struct gui_sheet *sheet = ctx->curr_sheet; const struct gui_sheet *sheet = ctx->curr_sheet;
int ax1, ay1, bx1, by1; int ax1, ay1, bx1, by1;
if (!ctx->last_hist) { if (!ctx->old_hist) {
*w = sheet->w; *w = sheet->w;
*h = sheet->h; *h = sheet->h;
} else { } else {
const struct gui_sheet *last = const struct gui_sheet *old =
find_corresponding_sheet(ctx->last_hist->sheets, find_corresponding_sheet(ctx->old_hist->sheets,
ctx->curr_hist->sheets, sheet); ctx->new_hist->sheets, sheet);
/* /*
* We're only interested in differences here, so no need for * We're only interested in differences here, so no need for
@ -349,12 +348,12 @@ static void curr_sheet_size(struct gui_ctx *ctx, int *w, int *h)
*/ */
ax1 = sheet->xmin + sheet->w; ax1 = sheet->xmin + sheet->w;
ay1 = sheet->ymin + sheet->h; ay1 = sheet->ymin + sheet->h;
bx1 = last->xmin + last->w; bx1 = old->xmin + old->w;
by1 = last->ymin + last->h; by1 = old->ymin + old->h;
*w = (ax1 > bx1 ? ax1 : bx1) - *w = (ax1 > bx1 ? ax1 : bx1) -
(sheet->xmin < last->xmin ? sheet->xmin : last->xmin); (sheet->xmin < old->xmin ? sheet->xmin : old->xmin);
*h = (ay1 > by1 ? ay1 : by1) - *h = (ay1 > by1 ? ay1 : by1) -
(sheet->ymin < last->ymin ? sheet->ymin : last->ymin); (sheet->ymin < old->ymin ? sheet->ymin : old->ymin);
} }
} }
@ -432,8 +431,8 @@ static void set_history_style(struct gui_hist *h, bool current)
{ {
struct gui_ctx *ctx = h->ctx; struct gui_ctx *ctx = h->ctx;
struct overlay_style style = overlay_style_dense; struct overlay_style style = overlay_style_dense;
const struct gui_hist *new = ctx->curr_hist; const struct gui_hist *new = ctx->new_hist;
const struct gui_hist *old = ctx->last_hist; const struct gui_hist *old = ctx->old_hist;
/* this is in addition to showing detailed content */ /* this is in addition to showing detailed content */
if (current) if (current)
@ -453,13 +452,11 @@ static void set_history_style(struct gui_hist *h, bool current)
abort(); abort();
} }
if (ctx->curr_hist == h || ctx->last_hist == h) { if (ctx->new_hist == h || ctx->old_hist == h) {
style.width++; style.width++;
style.font = BOLD_FONT; style.font = BOLD_FONT;
} }
if (ctx->last_hist) { if (ctx->old_hist) {
if (new->age > old->age)
swap(new, old);
if (h == new) if (h == new)
style.bg = RGBA(0.6, 1.0, 0.6, 0.8); style.bg = RGBA(0.6, 1.0, 0.6, 0.8);
if (h == old) if (h == old)
@ -489,76 +486,53 @@ static bool hover_history(void *user, bool on)
} }
static void go_to_history(struct gui_hist *h)
{
struct gui_ctx *ctx = h->ctx;
if (h == ctx->curr_hist) {
ctx->last_hist = NULL;
do_revision_overlays(ctx);
redraw(ctx);
} else {
ctx->last_hist = ctx->curr_hist;
ctx->curr_hist = h;
go_to_sheet(ctx, find_corresponding_sheet(h->sheets,
ctx->last_hist->sheets, ctx->curr_sheet));
}
}
static void click_history(void *user) static void click_history(void *user)
{ {
struct gui_hist *h = user; struct gui_hist *h = user;
struct gui_ctx *ctx = h->ctx; struct gui_ctx *ctx = h->ctx;
struct gui_hist **new = &ctx->curr_hist;
struct gui_hist **old = &ctx->last_hist;
struct gui_sheet *sheet; struct gui_sheet *sheet;
bool set_curr = ctx->selecting == sel_new;
hide_history(ctx); hide_history(ctx);
if (!h->sheets) if (!h->sheets)
return; return;
if (!ctx->last_hist) {
go_to_history(h);
return;
}
if ((*new)->age > (*old)->age) {
swap(new, old);
set_curr = !set_curr;
}
sheet = find_corresponding_sheet(h->sheets, sheet = find_corresponding_sheet(h->sheets,
ctx->curr_hist->sheets, ctx->curr_sheet); ctx->new_hist->sheets, ctx->curr_sheet);
switch (ctx->selecting) { switch (ctx->selecting) {
case sel_only:
ctx->old_hist = ctx->new_hist;
ctx->new_hist = h;
break;
case sel_new: case sel_new:
*new = h; ctx->new_hist = h;
break; break;
case sel_old: case sel_old:
*old = h; ctx->old_hist = h;
break; break;
case sel_only:
default: default:
abort(); abort();
} }
if (ctx->new_hist->age > ctx->old_hist->age) {
if (ctx->curr_hist == ctx->last_hist) { swap(ctx->new_hist, ctx->old_hist);
if (ctx->selecting == sel_old)
go_to_sheet(ctx, sheet); go_to_sheet(ctx, sheet);
go_to_history(ctx->curr_hist); else
return; render_delta(ctx);
} else {
if (ctx->selecting != sel_old)
go_to_sheet(ctx, sheet);
else
render_delta(ctx);
} }
if (set_curr) { if (ctx->old_hist == ctx->new_hist)
go_to_sheet(ctx, sheet); ctx->old_hist = NULL;
} else {
render_delta(ctx);
do_revision_overlays(ctx); do_revision_overlays(ctx);
redraw(ctx); redraw(ctx);
}
} }
@ -584,14 +558,9 @@ static void show_history_cb(void *user)
struct gui_hist *h = user; struct gui_hist *h = user;
struct gui_ctx *ctx = h->ctx; struct gui_ctx *ctx = h->ctx;
enum selecting sel = sel_only; enum selecting sel = sel_only;
const struct gui_hist *new = ctx->curr_hist;
const struct gui_hist *old = ctx->last_hist;
if (ctx->last_hist) { if (ctx->old_hist)
if (new->age > old->age) sel = h == ctx->new_hist ? sel_new : sel_old;
swap(new, old);
sel = h == new ? sel_new : sel_old;
}
show_history(ctx, sel); show_history(ctx, sel);
} }
@ -631,11 +600,8 @@ static bool show_history_details(void *user, bool on)
static void revision_overlays_diff(struct gui_ctx *ctx) static void revision_overlays_diff(struct gui_ctx *ctx)
{ {
struct gui_hist *new = ctx->curr_hist; struct gui_hist *new = ctx->new_hist;
struct gui_hist *old = ctx->last_hist; struct gui_hist *old = ctx->old_hist;
if (new->age > old->age)
swap(old, new);
new->over = overlay_add(&ctx->hist_overlays, &ctx->aois, new->over = overlay_add(&ctx->hist_overlays, &ctx->aois,
show_history_details, show_history_cb, new); show_history_details, show_history_cb, new);
@ -653,14 +619,14 @@ static void do_revision_overlays(struct gui_ctx *ctx)
{ {
overlay_remove_all(&ctx->hist_overlays); overlay_remove_all(&ctx->hist_overlays);
if (ctx->last_hist) { if (ctx->old_hist) {
revision_overlays_diff(ctx); revision_overlays_diff(ctx);
} else { } else {
ctx->curr_hist->over = overlay_add(&ctx->hist_overlays, ctx->new_hist->over = overlay_add(&ctx->hist_overlays,
&ctx->aois, show_history_details, show_history_cb, &ctx->aois, show_history_details, show_history_cb,
ctx->curr_hist); ctx->new_hist);
overlay_style(ctx->curr_hist->over, &overlay_style_default); overlay_style(ctx->new_hist->over, &overlay_style_default);
show_history_details(ctx->curr_hist, 0); show_history_details(ctx->new_hist, 0);
} }
} }
@ -687,7 +653,7 @@ static void sheet_selector_recurse(struct gui_ctx *ctx,
const char *title; const char *title;
struct overlay *over; struct overlay *over;
parent = find_parent_sheet(ctx->curr_hist->sheets, sheet); parent = find_parent_sheet(ctx->new_hist->sheets, sheet);
if (parent) if (parent)
sheet_selector_recurse(ctx, parent); sheet_selector_recurse(ctx, parent);
title = sheet->sch->title; title = sheet->sch->title;
@ -719,7 +685,7 @@ static void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet)
mark_aois(ctx, sheet); mark_aois(ctx, sheet);
} }
ctx->curr_sheet = sheet; ctx->curr_sheet = sheet;
if (ctx->last_hist) if (ctx->old_hist)
render_delta(ctx); render_delta(ctx);
if (ctx->vcs_hist) if (ctx->vcs_hist)
do_revision_overlays(ctx); do_revision_overlays(ctx);
@ -732,7 +698,7 @@ static bool go_up_sheet(struct gui_ctx *ctx)
{ {
struct gui_sheet *parent; struct gui_sheet *parent;
parent = find_parent_sheet(ctx->curr_hist->sheets, ctx->curr_sheet); parent = find_parent_sheet(ctx->new_hist->sheets, ctx->curr_sheet);
if (!parent) if (!parent)
return 0; return 0;
go_to_sheet(ctx, parent); go_to_sheet(ctx, parent);
@ -744,7 +710,7 @@ static bool go_prev_sheet(struct gui_ctx *ctx)
{ {
struct gui_sheet *sheet; struct gui_sheet *sheet;
for (sheet = ctx->curr_hist->sheets; sheet; sheet = sheet->next) for (sheet = ctx->new_hist->sheets; sheet; sheet = sheet->next)
if (sheet->next && sheet->next == ctx->curr_sheet) { if (sheet->next && sheet->next == ctx->curr_sheet) {
go_to_sheet(ctx, sheet); go_to_sheet(ctx, sheet);
return 1; return 1;
@ -857,8 +823,8 @@ static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
zoom_to_extents(ctx); zoom_to_extents(ctx);
break; break;
case GDK_KEY_Home: case GDK_KEY_Home:
if (sheet != ctx->curr_hist->sheets) if (sheet != ctx->new_hist->sheets)
go_to_sheet(ctx, ctx->curr_hist->sheets); go_to_sheet(ctx, ctx->new_hist->sheets);
break; break;
case GDK_KEY_BackSpace: case GDK_KEY_BackSpace:
case GDK_KEY_Delete: case GDK_KEY_Delete:
@ -933,7 +899,7 @@ static void select_subsheet(void *user)
const struct sch_obj *obj = aoi_ctx->obj; const struct sch_obj *obj = aoi_ctx->obj;
struct gui_sheet *sheet; struct gui_sheet *sheet;
for (sheet = ctx->curr_hist->sheets; sheet; sheet = sheet->next) for (sheet = ctx->new_hist->sheets; sheet; sheet = sheet->next)
if (sheet->sch == obj->u.sheet.sheet) { if (sheet->sch == obj->u.sheet.sheet) {
go_to_sheet(ctx, sheet); go_to_sheet(ctx, sheet);
return; return;
@ -1117,13 +1083,13 @@ int gui(unsigned n_args, char **args, bool recurse)
.sheet_overlays = NULL, .sheet_overlays = NULL,
.hist_overlays = NULL, .hist_overlays = NULL,
.aois = NULL, .aois = NULL,
.last_hist = NULL, .old_hist = NULL,
}; };
get_revisions(&ctx, n_args, args, recurse); get_revisions(&ctx, n_args, args, recurse);
for (ctx.curr_hist = ctx.hist; ctx.curr_hist && !ctx.curr_hist->sheets; for (ctx.new_hist = ctx.hist; ctx.new_hist && !ctx.new_hist->sheets;
ctx.curr_hist = ctx.curr_hist->next); ctx.new_hist = ctx.new_hist->next);
if (!ctx.curr_hist) { if (!ctx.new_hist) {
fprintf(stderr, "no valid sheets\n"); fprintf(stderr, "no valid sheets\n");
return 1; return 1;
} }
@ -1166,7 +1132,7 @@ int gui(unsigned n_args, char **args, bool recurse)
gtk_window_set_default_size(GTK_WINDOW(window), 640, 480); gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
gtk_window_set_title(GTK_WINDOW(window), "eeshow"); gtk_window_set_title(GTK_WINDOW(window), "eeshow");
go_to_sheet(&ctx, ctx.curr_hist->sheets); go_to_sheet(&ctx, ctx.new_hist->sheets);
gtk_widget_show_all(window); gtk_widget_show_all(window);
gtk_main(); gtk_main();