2016-08-03 13:38:57 +03:00
|
|
|
/*
|
|
|
|
* gui.c - GUI for eeshow
|
|
|
|
*
|
|
|
|
* Written 2016 by Werner Almesberger
|
|
|
|
* Copyright 2016 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resources:
|
|
|
|
*
|
|
|
|
* http://zetcode.com/gfx/cairo/cairobackends/
|
|
|
|
* https://developer.gnome.org/gtk3/stable/gtk-migrating-2-to-3.html
|
|
|
|
*/
|
|
|
|
|
2016-08-05 02:35:41 +03:00
|
|
|
#define _GNU_SOURCE /* for asprintf */
|
2016-08-04 01:18:50 +03:00
|
|
|
#include <stddef.h>
|
2016-08-03 18:26:22 +03:00
|
|
|
#include <stdbool.h>
|
2016-08-04 01:18:50 +03:00
|
|
|
#include <stdlib.h>
|
2016-08-03 15:33:16 +03:00
|
|
|
#include <stdio.h>
|
2016-08-11 07:27:59 +03:00
|
|
|
#include <string.h>
|
2016-08-04 01:18:50 +03:00
|
|
|
#include <math.h>
|
2016-08-03 15:33:16 +03:00
|
|
|
|
2016-08-04 01:18:50 +03:00
|
|
|
#include <cairo/cairo.h>
|
2016-08-03 13:38:57 +03:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2016-08-03 16:52:55 +03:00
|
|
|
#include "util.h"
|
2016-08-07 20:06:50 +03:00
|
|
|
#include "style.h"
|
2016-08-03 13:38:57 +03:00
|
|
|
#include "cro.h"
|
|
|
|
#include "gfx.h"
|
2016-08-05 02:35:41 +03:00
|
|
|
#include "git-hist.h"
|
2016-08-03 13:38:57 +03:00
|
|
|
#include "sch.h"
|
2016-08-07 20:06:50 +03:00
|
|
|
#include "delta.h"
|
2016-08-09 16:16:31 +03:00
|
|
|
#include "diff.h"
|
2016-08-11 03:50:07 +03:00
|
|
|
#include "dwg.h"
|
2016-08-04 13:19:18 +03:00
|
|
|
#include "gui-aoi.h"
|
2016-08-09 21:30:30 +03:00
|
|
|
#include "gui-style.h"
|
2016-08-04 02:55:51 +03:00
|
|
|
#include "gui-over.h"
|
2016-08-03 13:38:57 +03:00
|
|
|
#include "gui.h"
|
|
|
|
|
|
|
|
|
2016-08-03 18:26:22 +03:00
|
|
|
struct gui_ctx;
|
|
|
|
|
2016-08-03 16:52:55 +03:00
|
|
|
struct gui_sheet {
|
2016-08-07 20:06:50 +03:00
|
|
|
const struct sheet *sch;
|
2016-08-11 02:41:33 +03:00
|
|
|
struct gui_ctx *ctx; /* back link */
|
2016-08-03 13:38:57 +03:00
|
|
|
struct cro_ctx *gfx_ctx;
|
2016-08-03 16:52:55 +03:00
|
|
|
|
2016-08-09 17:20:54 +03:00
|
|
|
int w, h; /* in eeschema coordinates */
|
2016-08-03 15:33:16 +03:00
|
|
|
int xmin, ymin;
|
|
|
|
|
2016-08-06 16:19:16 +03:00
|
|
|
bool rendered; /* 0 if still have to render it */
|
|
|
|
|
2016-08-11 02:41:33 +03:00
|
|
|
struct overlay *over; /* current overlay */
|
2016-08-04 13:53:25 +03:00
|
|
|
struct aoi *aois; /* areas of interest; in schematics coord */
|
2016-08-03 18:26:22 +03:00
|
|
|
|
2016-08-03 16:52:55 +03:00
|
|
|
struct gui_sheet *next;
|
|
|
|
};
|
|
|
|
|
2016-08-05 02:35:41 +03:00
|
|
|
struct gui_hist {
|
2016-08-11 02:41:33 +03:00
|
|
|
struct gui_ctx *ctx; /* back link */
|
|
|
|
struct hist *vcs_hist; /* NULL if not from repo */
|
|
|
|
struct overlay *over; /* current overlay */
|
|
|
|
struct gui_sheet *sheets; /* NULL if failed */
|
|
|
|
unsigned age; /* 0-based; uncommitted or HEAD = 0 */
|
2016-08-10 22:03:52 +03:00
|
|
|
|
|
|
|
/* caching support */
|
2016-08-11 02:41:33 +03:00
|
|
|
void **oids; /* file object IDs */
|
2016-08-11 00:57:04 +03:00
|
|
|
struct sch_ctx sch_ctx;
|
2016-08-11 02:41:33 +03:00
|
|
|
struct lib lib; /* combined library */
|
2016-08-10 22:03:52 +03:00
|
|
|
|
2016-08-05 02:35:41 +03:00
|
|
|
struct gui_hist *next;
|
|
|
|
};
|
|
|
|
|
2016-08-03 16:52:55 +03:00
|
|
|
struct gui_ctx {
|
|
|
|
GtkWidget *da;
|
|
|
|
|
2016-08-03 16:05:01 +03:00
|
|
|
int curr_x; /* last on-screen mouse position */
|
|
|
|
int curr_y;
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
unsigned zoom; /* scale by 1.0 / (1 << zoom) */
|
|
|
|
int x, y; /* center, in eeschema coordinates */
|
|
|
|
|
|
|
|
bool panning;
|
|
|
|
int pan_x, pan_y;
|
2016-08-03 16:52:55 +03:00
|
|
|
|
2016-08-05 02:35:41 +03:00
|
|
|
struct gui_hist *hist; /* revision history; NULL if none */
|
|
|
|
struct hist *vcs_hist; /* underlying VCS data; NULL if none */
|
|
|
|
|
2016-08-09 19:28:27 +03:00
|
|
|
bool showing_history;
|
2016-08-10 00:28:59 +03:00
|
|
|
enum selecting {
|
|
|
|
sel_only, /* select the only revision we show */
|
|
|
|
sel_new, /* select the new revision */
|
|
|
|
sel_old, /* select the old revision */
|
|
|
|
} selecting;
|
2016-08-09 19:28:27 +03:00
|
|
|
|
2016-08-05 02:35:41 +03:00
|
|
|
struct overlay *sheet_overlays;
|
2016-08-07 12:23:04 +03:00
|
|
|
struct overlay *hist_overlays;
|
2016-08-11 05:47:08 +03:00
|
|
|
struct overlay *pop_overlays; /* pop-up dialogs */
|
|
|
|
int pop_x, pop_y;
|
2016-08-04 13:53:25 +03:00
|
|
|
struct aoi *aois; /* areas of interest; in canvas coord */
|
2016-08-04 01:18:50 +03:00
|
|
|
|
2016-08-07 20:06:50 +03:00
|
|
|
struct gui_sheet delta_a;
|
|
|
|
struct gui_sheet delta_b;
|
|
|
|
struct gui_sheet delta_ab;
|
|
|
|
|
2016-08-03 18:34:33 +03:00
|
|
|
struct gui_sheet *curr_sheet;
|
2016-08-10 01:01:05 +03:00
|
|
|
/* current sheet, always on new_hist */
|
|
|
|
struct gui_hist *new_hist;
|
|
|
|
struct gui_hist *old_hist; /* NULL if not comparing */
|
2016-08-03 18:26:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-08-04 00:49:16 +03:00
|
|
|
/* ----- Helper functions -------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void redraw(const struct gui_ctx *ctx)
|
|
|
|
{
|
|
|
|
gtk_widget_queue_draw(ctx->da);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-07 20:06:50 +03:00
|
|
|
static struct gui_sheet *find_corresponding_sheet(struct gui_sheet *pick_from,
|
|
|
|
struct gui_sheet *ref_in, const struct gui_sheet *ref)
|
|
|
|
{
|
|
|
|
struct gui_sheet *sheet, *plan_b;
|
|
|
|
const char *title = ref->sch->title;
|
|
|
|
|
|
|
|
/* plan A: try to find sheet with same name */
|
|
|
|
|
|
|
|
if (title)
|
|
|
|
for (sheet = pick_from; sheet; sheet = sheet->next)
|
|
|
|
if (sheet->sch->title &&
|
|
|
|
!strcmp(title, sheet->sch->title))
|
|
|
|
return sheet;
|
|
|
|
|
|
|
|
/* plan B: use sheet in same position in sheet sequence */
|
|
|
|
|
|
|
|
plan_b = ref_in;
|
|
|
|
for (sheet = pick_from; sheet; sheet = sheet->next) {
|
|
|
|
if (plan_b == ref)
|
|
|
|
return sheet;
|
|
|
|
plan_b = plan_b->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* plan C: just go to the top */
|
|
|
|
return pick_from;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
/* ----- Rendering --------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2016-08-07 12:08:42 +03:00
|
|
|
#define VCS_OVERLAYS_X 5
|
|
|
|
#define VCS_OVERLAYS_Y 5
|
2016-08-05 02:35:41 +03:00
|
|
|
|
2016-08-07 12:08:42 +03:00
|
|
|
#define SHEET_OVERLAYS_X -10
|
|
|
|
#define SHEET_OVERLAYS_Y 10
|
2016-08-05 02:35:41 +03:00
|
|
|
|
|
|
|
|
2016-08-09 16:16:31 +03:00
|
|
|
static void hack(const struct gui_ctx *ctx, cairo_t *cr)
|
|
|
|
{
|
2016-08-09 20:16:05 +03:00
|
|
|
const struct gui_sheet *new = ctx->curr_sheet;
|
|
|
|
const struct gui_sheet *old = find_corresponding_sheet(
|
2016-08-10 01:01:05 +03:00
|
|
|
ctx->old_hist->sheets, ctx->new_hist->sheets, ctx->curr_sheet);
|
2016-08-09 16:16:31 +03:00
|
|
|
|
|
|
|
diff_to_canvas(cr, ctx->x, ctx->y, 1.0 / (1 << ctx->zoom),
|
2016-08-09 20:16:05 +03:00
|
|
|
old->gfx_ctx, new->gfx_ctx);
|
2016-08-09 16:16:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 13:38:57 +03:00
|
|
|
static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
const struct gui_ctx *ctx = user_data;
|
2016-08-03 16:52:55 +03:00
|
|
|
const struct gui_sheet *sheet = ctx->curr_sheet;
|
2016-08-03 15:33:16 +03:00
|
|
|
GtkAllocation alloc;
|
|
|
|
float f = 1.0 / (1 << ctx->zoom);
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation(ctx->da, &alloc);
|
2016-08-03 16:52:55 +03:00
|
|
|
x = -(sheet->xmin + ctx->x) * f + alloc.width / 2;
|
|
|
|
y = -(sheet->ymin + ctx->y) * f + alloc.height / 2;
|
2016-08-07 20:06:50 +03:00
|
|
|
|
|
|
|
cro_canvas_prepare(cr);
|
2016-08-10 01:01:05 +03:00
|
|
|
if (!ctx->old_hist) {
|
2016-08-07 20:06:50 +03:00
|
|
|
cro_canvas_draw(sheet->gfx_ctx, cr, x, y, f);
|
|
|
|
} else {
|
2016-08-09 16:16:31 +03:00
|
|
|
#if 0
|
2016-08-07 20:06:50 +03:00
|
|
|
/* @@@ fix geometry later */
|
|
|
|
cro_canvas_draw(ctx->delta_ab.gfx_ctx, cr, x, y, f);
|
|
|
|
cro_canvas_draw(ctx->delta_a.gfx_ctx, cr, x, y, f);
|
|
|
|
cro_canvas_draw(ctx->delta_b.gfx_ctx, cr, x, y, f);
|
2016-08-09 16:16:31 +03:00
|
|
|
#endif
|
|
|
|
hack(ctx, cr);
|
2016-08-07 20:06:50 +03:00
|
|
|
}
|
2016-08-03 13:38:57 +03:00
|
|
|
|
2016-08-07 12:08:42 +03:00
|
|
|
overlay_draw_all(ctx->sheet_overlays, cr,
|
|
|
|
SHEET_OVERLAYS_X, SHEET_OVERLAYS_Y);
|
2016-08-07 12:23:04 +03:00
|
|
|
overlay_draw_all(ctx->hist_overlays, cr,
|
2016-08-07 12:08:42 +03:00
|
|
|
VCS_OVERLAYS_X, VCS_OVERLAYS_Y);
|
2016-08-11 05:47:08 +03:00
|
|
|
overlay_draw_all(ctx->pop_overlays, cr, ctx->pop_x, ctx->pop_y);
|
2016-08-04 01:18:50 +03:00
|
|
|
|
2016-08-03 13:38:57 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-06 16:19:16 +03:00
|
|
|
static void render_sheet(struct gui_sheet *sheet)
|
2016-08-03 13:38:57 +03:00
|
|
|
{
|
|
|
|
char *argv[] = { "gui", NULL };
|
|
|
|
|
|
|
|
gfx_init(&cro_canvas_ops, 1, argv);
|
2016-08-03 16:52:55 +03:00
|
|
|
sch_render(sheet->sch);
|
|
|
|
cro_canvas_end(gfx_ctx,
|
|
|
|
&sheet->w, &sheet->h, &sheet->xmin, &sheet->ymin);
|
|
|
|
sheet->gfx_ctx = gfx_ctx;
|
2016-08-06 16:19:16 +03:00
|
|
|
sheet->rendered = 1;
|
2016-08-03 13:38:57 +03:00
|
|
|
// gfx_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-09 16:16:31 +03:00
|
|
|
/* @@@ not nice to have this so far out */
|
|
|
|
static void mark_aois(struct gui_ctx *ctx, struct gui_sheet *sheet);
|
|
|
|
|
|
|
|
|
2016-08-07 20:06:50 +03:00
|
|
|
static void render_delta(struct gui_ctx *ctx)
|
|
|
|
{
|
2016-08-09 16:16:31 +03:00
|
|
|
#if 0
|
2016-08-10 01:01:05 +03:00
|
|
|
/* @@@ needs updating for curr/last vs. new/old */
|
2016-08-07 20:06:50 +03:00
|
|
|
struct sheet *sch_a, *sch_b, *sch_ab;
|
|
|
|
const struct gui_sheet *a = ctx->curr_sheet;
|
|
|
|
const struct gui_sheet *b = find_corresponding_sheet(
|
|
|
|
ctx->last_hist->sheets, ctx->curr_hist->sheets, ctx->curr_sheet);
|
|
|
|
|
|
|
|
sch_a = alloc_type(struct sheet);
|
|
|
|
sch_b = alloc_type(struct sheet);
|
|
|
|
sch_ab = alloc_type(struct sheet);
|
|
|
|
|
|
|
|
delta(a->sch, b->sch, sch_a, sch_b, sch_ab);
|
|
|
|
ctx->delta_a.sch = sch_a,
|
|
|
|
ctx->delta_b.sch = sch_b,
|
|
|
|
ctx->delta_ab.sch = sch_ab,
|
|
|
|
|
|
|
|
render_sheet(&ctx->delta_a);
|
|
|
|
render_sheet(&ctx->delta_b);
|
|
|
|
render_sheet(&ctx->delta_ab);
|
|
|
|
|
|
|
|
cro_color_override(ctx->delta_ab.gfx_ctx, COLOR_LIGHT_GREY);
|
|
|
|
cro_color_override(ctx->delta_a.gfx_ctx, COLOR_RED);
|
|
|
|
cro_color_override(ctx->delta_b.gfx_ctx, COLOR_GREEN2);
|
|
|
|
|
|
|
|
// @@@ clean up when leaving sheet
|
2016-08-09 16:16:31 +03:00
|
|
|
#endif
|
|
|
|
struct gui_sheet *b = find_corresponding_sheet(
|
2016-08-10 01:01:05 +03:00
|
|
|
ctx->old_hist->sheets, ctx->new_hist->sheets, ctx->curr_sheet);
|
2016-08-09 16:16:31 +03:00
|
|
|
|
|
|
|
if (!b->rendered) {
|
|
|
|
render_sheet(b);
|
|
|
|
mark_aois(ctx, b);
|
|
|
|
}
|
2016-08-07 20:06:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
/* ----- Tools ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void canvas_coord(const struct gui_ctx *ctx,
|
|
|
|
int ex, int ey, int *x, int *y)
|
|
|
|
{
|
|
|
|
GtkAllocation alloc;
|
2016-08-03 19:05:30 +03:00
|
|
|
int sx, sy;
|
2016-08-03 15:33:16 +03:00
|
|
|
|
|
|
|
gtk_widget_get_allocation(ctx->da, &alloc);
|
|
|
|
sx = ex - alloc.width / 2;
|
|
|
|
sy = ey - alloc.height / 2;
|
|
|
|
*x = (sx << ctx->zoom) + ctx->x;
|
|
|
|
*y = (sy << ctx->zoom) + ctx->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 05:47:08 +03:00
|
|
|
static void eeschema_coord(const struct gui_ctx *ctx,
|
|
|
|
int x, int y, int *rx, int *ry)
|
|
|
|
{
|
|
|
|
GtkAllocation alloc;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation(ctx->da, &alloc);
|
|
|
|
*rx = ((x - ctx->x) >> ctx->zoom) + alloc.width / 2;
|
|
|
|
*ry = ((y - ctx->y) >> ctx->zoom) + alloc.height / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
/* ----- Panning ----------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void pan_begin(struct gui_ctx *ctx, int x, int y)
|
|
|
|
{
|
2016-08-03 15:57:58 +03:00
|
|
|
if (ctx->panning)
|
|
|
|
return;
|
|
|
|
ctx->panning = 1;
|
|
|
|
ctx->pan_x = x;
|
|
|
|
ctx->pan_y = y;
|
2016-08-03 15:33:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pan_update(struct gui_ctx *ctx, int x, int y)
|
|
|
|
{
|
2016-08-03 15:57:58 +03:00
|
|
|
if (!ctx->panning)
|
|
|
|
return;
|
2016-08-05 01:25:31 +03:00
|
|
|
|
2016-08-03 15:57:58 +03:00
|
|
|
ctx->x -= (x - ctx->pan_x) << ctx->zoom;
|
|
|
|
ctx->y -= (y - ctx->pan_y) << ctx->zoom;
|
|
|
|
ctx->pan_x = x;
|
|
|
|
ctx->pan_y = y;
|
|
|
|
|
2016-08-04 00:49:16 +03:00
|
|
|
redraw(ctx);
|
2016-08-03 15:33:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pan_end(struct gui_ctx *ctx, int x, int y)
|
|
|
|
{
|
2016-08-03 15:57:58 +03:00
|
|
|
pan_update(ctx, x, y);
|
|
|
|
ctx->panning = 0;
|
2016-08-03 15:33:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- Zoom -------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void zoom_in(struct gui_ctx *ctx, int x, int y)
|
|
|
|
{
|
|
|
|
if (ctx->zoom == 0)
|
|
|
|
return;
|
|
|
|
ctx->zoom--;
|
|
|
|
ctx->x = (ctx->x + x) / 2;
|
|
|
|
ctx->y = (ctx->y + y) / 2;
|
2016-08-04 00:49:16 +03:00
|
|
|
redraw(ctx);
|
2016-08-03 15:33:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void zoom_out(struct gui_ctx *ctx, int x, int y)
|
|
|
|
{
|
2016-08-03 16:52:55 +03:00
|
|
|
if (ctx->curr_sheet->w >> ctx->zoom <= 16)
|
2016-08-03 15:33:16 +03:00
|
|
|
return;
|
|
|
|
ctx->zoom++;
|
|
|
|
ctx->x = 2 * ctx->x - x;
|
|
|
|
ctx->y = 2 * ctx->y - y;
|
2016-08-04 00:49:16 +03:00
|
|
|
redraw(ctx);
|
2016-08-03 15:33:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-09 16:58:29 +03:00
|
|
|
static void curr_sheet_size(struct gui_ctx *ctx, int *w, int *h)
|
2016-08-03 19:05:30 +03:00
|
|
|
{
|
|
|
|
const struct gui_sheet *sheet = ctx->curr_sheet;
|
2016-08-09 17:20:54 +03:00
|
|
|
int ax1, ay1, bx1, by1;
|
2016-08-09 16:58:29 +03:00
|
|
|
|
2016-08-10 01:01:05 +03:00
|
|
|
if (!ctx->old_hist) {
|
2016-08-09 17:20:54 +03:00
|
|
|
*w = sheet->w;
|
|
|
|
*h = sheet->h;
|
|
|
|
} else {
|
2016-08-10 01:01:05 +03:00
|
|
|
const struct gui_sheet *old =
|
|
|
|
find_corresponding_sheet(ctx->old_hist->sheets,
|
|
|
|
ctx->new_hist->sheets, sheet);
|
2016-08-09 17:20:54 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We're only interested in differences here, so no need for
|
|
|
|
* the usual "-1" in x1 = x0 + w - 1
|
|
|
|
*/
|
|
|
|
ax1 = sheet->xmin + sheet->w;
|
|
|
|
ay1 = sheet->ymin + sheet->h;
|
2016-08-10 01:01:05 +03:00
|
|
|
bx1 = old->xmin + old->w;
|
|
|
|
by1 = old->ymin + old->h;
|
2016-08-09 17:20:54 +03:00
|
|
|
*w = (ax1 > bx1 ? ax1 : bx1) -
|
2016-08-10 01:01:05 +03:00
|
|
|
(sheet->xmin < old->xmin ? sheet->xmin : old->xmin);
|
2016-08-09 17:20:54 +03:00
|
|
|
*h = (ay1 > by1 ? ay1 : by1) -
|
2016-08-10 01:01:05 +03:00
|
|
|
(sheet->ymin < old->ymin ? sheet->ymin : old->ymin);
|
2016-08-09 17:20:54 +03:00
|
|
|
}
|
2016-08-09 16:58:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void zoom_to_extents(struct gui_ctx *ctx)
|
|
|
|
{
|
2016-08-03 19:05:30 +03:00
|
|
|
GtkAllocation alloc;
|
2016-08-09 16:58:29 +03:00
|
|
|
int w, h;
|
2016-08-03 19:05:30 +03:00
|
|
|
|
2016-08-09 16:58:29 +03:00
|
|
|
curr_sheet_size(ctx, &w, &h);
|
|
|
|
ctx->x = w / 2;
|
|
|
|
ctx->y = h / 2;
|
2016-08-03 19:05:30 +03:00
|
|
|
|
|
|
|
gtk_widget_get_allocation(ctx->da, &alloc);
|
|
|
|
ctx->zoom = 0;
|
2016-08-09 16:58:29 +03:00
|
|
|
while (w >> ctx->zoom > alloc.width || h >> ctx->zoom > alloc.height)
|
2016-08-03 19:05:30 +03:00
|
|
|
ctx->zoom++;
|
|
|
|
|
2016-08-04 00:49:16 +03:00
|
|
|
redraw(ctx);
|
2016-08-03 19:05:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-06 16:00:29 +03:00
|
|
|
/* ----- Need this for jumping around -------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet);
|
|
|
|
static bool go_up_sheet(struct gui_ctx *ctx);
|
|
|
|
|
|
|
|
|
2016-08-05 14:31:50 +03:00
|
|
|
/* ----- Revision history -------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2016-08-09 19:28:27 +03:00
|
|
|
static void do_revision_overlays(struct gui_ctx *ctx);
|
|
|
|
|
|
|
|
|
2016-08-06 16:00:29 +03:00
|
|
|
static void hide_history(struct gui_ctx *ctx)
|
2016-08-05 14:31:50 +03:00
|
|
|
{
|
2016-08-09 19:28:27 +03:00
|
|
|
ctx->showing_history = 0;
|
|
|
|
do_revision_overlays(ctx);
|
2016-08-05 14:31:50 +03:00
|
|
|
redraw(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-10 01:19:33 +03:00
|
|
|
#define RGBA(r, g, b, a) ((struct color) { (r), (g), (b), (a) })
|
|
|
|
#define COLOR(color) RGBA(color)
|
2016-08-10 00:28:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void set_history_style(struct gui_hist *h, bool current)
|
|
|
|
{
|
|
|
|
struct gui_ctx *ctx = h->ctx;
|
|
|
|
struct overlay_style style = overlay_style_dense;
|
2016-08-10 01:01:05 +03:00
|
|
|
const struct gui_hist *new = ctx->new_hist;
|
|
|
|
const struct gui_hist *old = ctx->old_hist;
|
2016-08-10 00:28:59 +03:00
|
|
|
|
|
|
|
/* this is in addition to showing detailed content */
|
|
|
|
if (current)
|
|
|
|
style.width++;
|
|
|
|
|
|
|
|
switch (ctx->selecting) {
|
|
|
|
case sel_only:
|
2016-08-10 01:19:33 +03:00
|
|
|
style.frame = COLOR(FRAME_SEL_ONLY);
|
2016-08-10 00:28:59 +03:00
|
|
|
break;
|
|
|
|
case sel_old:
|
2016-08-10 01:19:33 +03:00
|
|
|
style.frame = COLOR(FRAME_SEL_OLD);
|
2016-08-10 00:28:59 +03:00
|
|
|
break;
|
|
|
|
case sel_new:
|
2016-08-10 01:19:33 +03:00
|
|
|
style.frame = COLOR(FRAME_SEL_NEW);
|
2016-08-10 00:28:59 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2016-08-10 01:01:05 +03:00
|
|
|
if (ctx->new_hist == h || ctx->old_hist == h) {
|
2016-08-10 00:28:59 +03:00
|
|
|
style.width++;
|
|
|
|
style.font = BOLD_FONT;
|
|
|
|
}
|
2016-08-10 01:01:05 +03:00
|
|
|
if (ctx->old_hist) {
|
2016-08-10 00:28:59 +03:00
|
|
|
if (h == new)
|
2016-08-10 01:19:33 +03:00
|
|
|
style.bg = COLOR(BG_NEW);
|
2016-08-10 00:28:59 +03:00
|
|
|
if (h == old)
|
2016-08-10 01:19:33 +03:00
|
|
|
style.bg = COLOR(BG_OLD);
|
2016-08-10 00:28:59 +03:00
|
|
|
}
|
|
|
|
overlay_style(h->over, &style);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-07 11:22:55 +03:00
|
|
|
static bool hover_history(void *user, bool on)
|
|
|
|
{
|
|
|
|
struct gui_hist *h = user;
|
|
|
|
struct gui_ctx *ctx = h->ctx;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (on) {
|
2016-08-10 20:05:11 +03:00
|
|
|
s = vcs_git_long_for_pango(h->vcs_hist);
|
2016-08-08 03:47:50 +03:00
|
|
|
overlay_text_raw(h->over, s);
|
2016-08-07 11:22:55 +03:00
|
|
|
free(s);
|
|
|
|
} else {
|
2016-08-08 03:47:50 +03:00
|
|
|
overlay_text(h->over, "<small>%s</small>",
|
2016-08-10 20:05:11 +03:00
|
|
|
vcs_git_summary(h->vcs_hist));
|
2016-08-07 11:22:55 +03:00
|
|
|
}
|
2016-08-10 00:28:59 +03:00
|
|
|
set_history_style(h, on);
|
2016-08-07 11:22:55 +03:00
|
|
|
redraw(ctx);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-07 13:51:56 +03:00
|
|
|
static void click_history(void *user)
|
|
|
|
{
|
|
|
|
struct gui_hist *h = user;
|
|
|
|
struct gui_ctx *ctx = h->ctx;
|
2016-08-10 00:28:59 +03:00
|
|
|
struct gui_sheet *sheet;
|
2016-08-07 13:51:56 +03:00
|
|
|
|
2016-08-08 03:47:50 +03:00
|
|
|
hide_history(ctx);
|
2016-08-10 00:28:59 +03:00
|
|
|
|
|
|
|
if (!h->sheets)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sheet = find_corresponding_sheet(h->sheets,
|
2016-08-10 01:01:05 +03:00
|
|
|
ctx->new_hist->sheets, ctx->curr_sheet);
|
2016-08-10 00:28:59 +03:00
|
|
|
|
|
|
|
switch (ctx->selecting) {
|
2016-08-10 01:01:05 +03:00
|
|
|
case sel_only:
|
|
|
|
ctx->old_hist = ctx->new_hist;
|
|
|
|
ctx->new_hist = h;
|
|
|
|
break;
|
2016-08-10 00:28:59 +03:00
|
|
|
case sel_new:
|
2016-08-10 01:01:05 +03:00
|
|
|
ctx->new_hist = h;
|
2016-08-10 00:28:59 +03:00
|
|
|
break;
|
|
|
|
case sel_old:
|
2016-08-10 01:01:05 +03:00
|
|
|
ctx->old_hist = h;
|
2016-08-10 00:28:59 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2016-08-10 01:01:05 +03:00
|
|
|
if (ctx->new_hist->age > ctx->old_hist->age) {
|
|
|
|
swap(ctx->new_hist, ctx->old_hist);
|
|
|
|
if (ctx->selecting == sel_old)
|
|
|
|
go_to_sheet(ctx, sheet);
|
|
|
|
else
|
|
|
|
render_delta(ctx);
|
2016-08-10 00:28:59 +03:00
|
|
|
} else {
|
2016-08-10 01:01:05 +03:00
|
|
|
if (ctx->selecting != sel_old)
|
|
|
|
go_to_sheet(ctx, sheet);
|
|
|
|
else
|
|
|
|
render_delta(ctx);
|
2016-08-10 00:28:59 +03:00
|
|
|
}
|
2016-08-10 01:01:05 +03:00
|
|
|
|
|
|
|
if (ctx->old_hist == ctx->new_hist)
|
|
|
|
ctx->old_hist = NULL;
|
|
|
|
|
|
|
|
do_revision_overlays(ctx);
|
|
|
|
redraw(ctx);
|
2016-08-06 16:00:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-10 00:28:59 +03:00
|
|
|
static void show_history(struct gui_ctx *ctx, enum selecting sel)
|
2016-08-05 14:31:50 +03:00
|
|
|
{
|
|
|
|
struct gui_hist *h = ctx->hist;
|
|
|
|
|
2016-08-09 19:28:27 +03:00
|
|
|
ctx->showing_history = 1;
|
2016-08-10 00:28:59 +03:00
|
|
|
ctx->selecting = sel;
|
2016-08-07 12:23:04 +03:00
|
|
|
overlay_remove_all(&ctx->hist_overlays);
|
2016-08-05 14:31:50 +03:00
|
|
|
for (h = ctx->hist; h; h = h->next) {
|
2016-08-08 03:47:50 +03:00
|
|
|
h->over = overlay_add(&ctx->hist_overlays, &ctx->aois,
|
2016-08-07 11:22:55 +03:00
|
|
|
hover_history, click_history, h);
|
|
|
|
hover_history(h, 0);
|
2016-08-10 00:28:59 +03:00
|
|
|
set_history_style(h, 0);
|
2016-08-05 14:31:50 +03:00
|
|
|
}
|
|
|
|
redraw(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void show_history_cb(void *user)
|
|
|
|
{
|
2016-08-07 11:09:34 +03:00
|
|
|
struct gui_hist *h = user;
|
|
|
|
struct gui_ctx *ctx = h->ctx;
|
2016-08-10 00:28:59 +03:00
|
|
|
enum selecting sel = sel_only;
|
2016-08-05 14:31:50 +03:00
|
|
|
|
2016-08-10 01:01:05 +03:00
|
|
|
if (ctx->old_hist)
|
|
|
|
sel = h == ctx->new_hist ? sel_new : sel_old;
|
2016-08-10 00:28:59 +03:00
|
|
|
show_history(ctx, sel);
|
2016-08-05 14:31:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-04 14:49:54 +03:00
|
|
|
/* ----- Navigate sheets --------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2016-08-06 16:19:16 +03:00
|
|
|
/* @@@ find a better place for this forward declaration */
|
|
|
|
static void mark_aois(struct gui_ctx *ctx, struct gui_sheet *sheet);
|
|
|
|
|
|
|
|
|
2016-08-04 15:02:33 +03:00
|
|
|
static void close_subsheet(void *user)
|
|
|
|
{
|
2016-08-11 02:24:03 +03:00
|
|
|
struct gui_sheet *sheet = user;
|
|
|
|
struct gui_ctx *ctx = sheet->ctx;
|
2016-08-04 15:02:33 +03:00
|
|
|
|
2016-08-11 02:24:03 +03:00
|
|
|
go_to_sheet(ctx, sheet);
|
2016-08-04 15:02:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 02:41:33 +03:00
|
|
|
static bool hover_sheet(void *user, bool on)
|
|
|
|
{
|
|
|
|
struct gui_sheet *sheet = user;
|
|
|
|
struct gui_ctx *ctx = sheet->ctx;
|
|
|
|
const char *title = sheet->sch->title;
|
|
|
|
|
|
|
|
if (!title)
|
|
|
|
title = "(unnamed)";
|
|
|
|
if (on) {
|
|
|
|
const struct gui_sheet *s;
|
|
|
|
int n = 0, this = -1;
|
|
|
|
|
|
|
|
for (s = ctx->new_hist->sheets; s; s = s->next) {
|
|
|
|
n++;
|
|
|
|
if (s == sheet)
|
|
|
|
this = n;
|
|
|
|
}
|
|
|
|
overlay_text(sheet->over, "<b>%s</b>\n<big>%d / %d</big>",
|
|
|
|
title, this, n);
|
|
|
|
} else {
|
|
|
|
overlay_text(sheet->over, "<b>%s</b>", title);
|
|
|
|
}
|
|
|
|
redraw(ctx);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-07 11:09:34 +03:00
|
|
|
static bool show_history_details(void *user, bool on)
|
|
|
|
{
|
|
|
|
struct gui_hist *h = user;
|
|
|
|
struct gui_ctx *ctx = h->ctx;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (on) {
|
2016-08-10 20:05:11 +03:00
|
|
|
s = vcs_git_long_for_pango(h->vcs_hist);
|
2016-08-08 03:47:50 +03:00
|
|
|
overlay_text_raw(h->over, s);
|
2016-08-07 11:09:34 +03:00
|
|
|
free(s);
|
|
|
|
} else {
|
2016-08-10 20:05:11 +03:00
|
|
|
overlay_text(h->over, "%.40s", vcs_git_summary(h->vcs_hist));
|
2016-08-07 11:09:34 +03:00
|
|
|
}
|
|
|
|
redraw(ctx);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-09 20:16:05 +03:00
|
|
|
static void revision_overlays_diff(struct gui_ctx *ctx)
|
|
|
|
{
|
2016-08-10 01:01:05 +03:00
|
|
|
struct gui_hist *new = ctx->new_hist;
|
|
|
|
struct gui_hist *old = ctx->old_hist;
|
2016-08-09 20:16:05 +03:00
|
|
|
|
|
|
|
new->over = overlay_add(&ctx->hist_overlays, &ctx->aois,
|
|
|
|
show_history_details, show_history_cb, new);
|
|
|
|
overlay_style(new->over, &overlay_style_diff_new);
|
|
|
|
show_history_details(new, 0);
|
|
|
|
|
|
|
|
old->over = overlay_add(&ctx->hist_overlays, &ctx->aois,
|
2016-08-10 00:28:59 +03:00
|
|
|
show_history_details, show_history_cb, old);
|
2016-08-09 20:16:05 +03:00
|
|
|
overlay_style(old->over, &overlay_style_diff_old);
|
|
|
|
show_history_details(old, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-08 03:47:50 +03:00
|
|
|
static void do_revision_overlays(struct gui_ctx *ctx)
|
2016-08-04 14:49:54 +03:00
|
|
|
{
|
2016-08-08 03:47:50 +03:00
|
|
|
overlay_remove_all(&ctx->hist_overlays);
|
2016-08-09 20:16:05 +03:00
|
|
|
|
2016-08-10 01:01:05 +03:00
|
|
|
if (ctx->old_hist) {
|
2016-08-09 20:16:05 +03:00
|
|
|
revision_overlays_diff(ctx);
|
|
|
|
} else {
|
2016-08-10 01:01:05 +03:00
|
|
|
ctx->new_hist->over = overlay_add(&ctx->hist_overlays,
|
2016-08-07 11:09:34 +03:00
|
|
|
&ctx->aois, show_history_details, show_history_cb,
|
2016-08-10 01:01:05 +03:00
|
|
|
ctx->new_hist);
|
|
|
|
overlay_style(ctx->new_hist->over, &overlay_style_default);
|
|
|
|
show_history_details(ctx->new_hist, 0);
|
2016-08-07 01:14:31 +03:00
|
|
|
}
|
2016-08-08 03:47:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-09 18:55:29 +03:00
|
|
|
static struct gui_sheet *find_parent_sheet(struct gui_sheet *sheets,
|
|
|
|
const struct gui_sheet *ref)
|
2016-08-08 03:47:50 +03:00
|
|
|
{
|
2016-08-09 18:55:29 +03:00
|
|
|
struct gui_sheet *parent;
|
|
|
|
const struct sch_obj *obj;
|
|
|
|
|
|
|
|
for (parent = sheets; parent; parent = parent->next)
|
|
|
|
for (obj = parent->sch->objs; obj; obj = obj->next)
|
|
|
|
if (obj->type == sch_obj_sheet &&
|
|
|
|
obj->u.sheet.sheet == ref->sch)
|
|
|
|
return parent;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 02:24:03 +03:00
|
|
|
static void sheet_selector_recurse(struct gui_ctx *ctx, struct gui_sheet *sheet)
|
2016-08-09 18:55:29 +03:00
|
|
|
{
|
2016-08-11 02:24:03 +03:00
|
|
|
struct gui_sheet *parent;
|
2016-08-08 03:47:50 +03:00
|
|
|
|
2016-08-10 01:01:05 +03:00
|
|
|
parent = find_parent_sheet(ctx->new_hist->sheets, sheet);
|
2016-08-09 18:55:29 +03:00
|
|
|
if (parent)
|
|
|
|
sheet_selector_recurse(ctx, parent);
|
2016-08-11 02:41:33 +03:00
|
|
|
sheet->over = overlay_add(&ctx->sheet_overlays, &ctx->aois,
|
|
|
|
hover_sheet, close_subsheet, sheet);
|
|
|
|
hover_sheet(sheet, 0);
|
2016-08-09 18:55:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void do_sheet_overlays(struct gui_ctx *ctx)
|
|
|
|
{
|
2016-08-08 03:47:50 +03:00
|
|
|
overlay_remove_all(&ctx->sheet_overlays);
|
2016-08-09 18:55:29 +03:00
|
|
|
sheet_selector_recurse(ctx, ctx->curr_sheet);
|
2016-08-07 13:51:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet)
|
|
|
|
{
|
2016-08-11 03:50:07 +03:00
|
|
|
aoi_dehover();
|
2016-08-11 07:27:59 +03:00
|
|
|
overlay_remove_all(&ctx->pop_overlays);
|
2016-08-07 13:51:56 +03:00
|
|
|
if (!sheet->rendered) {
|
|
|
|
render_sheet(sheet);
|
|
|
|
mark_aois(ctx, sheet);
|
2016-08-05 14:31:50 +03:00
|
|
|
}
|
2016-08-07 13:51:56 +03:00
|
|
|
ctx->curr_sheet = sheet;
|
2016-08-10 01:01:05 +03:00
|
|
|
if (ctx->old_hist)
|
2016-08-07 20:06:50 +03:00
|
|
|
render_delta(ctx);
|
2016-08-09 18:03:36 +03:00
|
|
|
if (ctx->vcs_hist)
|
|
|
|
do_revision_overlays(ctx);
|
2016-08-07 13:51:56 +03:00
|
|
|
do_sheet_overlays(ctx);
|
2016-08-04 14:49:54 +03:00
|
|
|
zoom_to_extents(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool go_up_sheet(struct gui_ctx *ctx)
|
|
|
|
{
|
2016-08-09 18:55:29 +03:00
|
|
|
struct gui_sheet *parent;
|
2016-08-04 14:49:54 +03:00
|
|
|
|
2016-08-10 01:01:05 +03:00
|
|
|
parent = find_parent_sheet(ctx->new_hist->sheets, ctx->curr_sheet);
|
2016-08-09 18:55:29 +03:00
|
|
|
if (!parent)
|
|
|
|
return 0;
|
|
|
|
go_to_sheet(ctx, parent);
|
|
|
|
return 1;
|
2016-08-04 14:49:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-04 15:02:33 +03:00
|
|
|
static bool go_prev_sheet(struct gui_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct gui_sheet *sheet;
|
|
|
|
|
2016-08-10 01:01:05 +03:00
|
|
|
for (sheet = ctx->new_hist->sheets; sheet; sheet = sheet->next)
|
2016-08-04 15:02:33 +03:00
|
|
|
if (sheet->next && sheet->next == ctx->curr_sheet) {
|
|
|
|
go_to_sheet(ctx, sheet);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool go_next_sheet(struct gui_ctx *ctx)
|
|
|
|
{
|
|
|
|
if (!ctx->curr_sheet->next)
|
|
|
|
return 0;
|
|
|
|
go_to_sheet(ctx, ctx->curr_sheet->next);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
/* ----- Event handlers ---------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean motion_notify_event(GtkWidget *widget, GdkEventMotion *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
struct gui_ctx *ctx = data;
|
2016-08-04 13:19:18 +03:00
|
|
|
const struct gui_sheet *curr_sheet = ctx->curr_sheet;
|
2016-08-03 15:33:16 +03:00
|
|
|
int x, y;
|
|
|
|
|
2016-08-03 16:05:01 +03:00
|
|
|
ctx->curr_x = event->x;
|
|
|
|
ctx->curr_y = event->y;
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
canvas_coord(ctx, event->x, event->y, &x, &y);
|
2016-08-03 18:26:22 +03:00
|
|
|
|
2016-08-07 11:09:34 +03:00
|
|
|
aoi_hover(ctx->aois, event->x, event->y) ||
|
|
|
|
aoi_hover(curr_sheet->aois,
|
|
|
|
x + curr_sheet->xmin, y + curr_sheet->ymin);
|
2016-08-03 15:57:58 +03:00
|
|
|
pan_update(ctx, event->x, event->y);
|
2016-08-03 18:26:22 +03:00
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean button_press_event(GtkWidget *widget, GdkEventButton *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
struct gui_ctx *ctx = data;
|
2016-08-04 13:19:18 +03:00
|
|
|
const struct gui_sheet *curr_sheet = ctx->curr_sheet;
|
2016-08-03 15:33:16 +03:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
canvas_coord(ctx, event->x, event->y, &x, &y);
|
2016-08-03 18:34:33 +03:00
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
switch (event->button) {
|
|
|
|
case 1:
|
2016-08-04 13:53:25 +03:00
|
|
|
if (aoi_click(ctx->aois, event->x, event->y))
|
|
|
|
break;
|
2016-08-09 19:28:27 +03:00
|
|
|
if (aoi_click(curr_sheet->aois,
|
|
|
|
x + curr_sheet->xmin, y + curr_sheet->ymin))
|
|
|
|
break;
|
|
|
|
if (ctx->showing_history)
|
|
|
|
hide_history(ctx);
|
2016-08-11 07:27:59 +03:00
|
|
|
overlay_remove_all(&ctx->pop_overlays);
|
|
|
|
redraw(ctx);
|
2016-08-03 15:57:58 +03:00
|
|
|
break;
|
2016-08-03 15:33:16 +03:00
|
|
|
case 2:
|
2016-08-03 15:57:58 +03:00
|
|
|
pan_begin(ctx, event->x, event->y);
|
2016-08-03 15:33:16 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
2016-08-03 15:57:58 +03:00
|
|
|
break;
|
2016-08-03 15:33:16 +03:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
struct gui_ctx *ctx = data;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
canvas_coord(ctx, event->x, event->y, &x, &y);
|
2016-08-03 18:34:33 +03:00
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
switch (event->button) {
|
|
|
|
case 1:
|
2016-08-03 15:57:58 +03:00
|
|
|
break;
|
2016-08-03 15:33:16 +03:00
|
|
|
case 2:
|
2016-08-03 15:57:58 +03:00
|
|
|
pan_end(ctx, event->x, event->y);
|
2016-08-03 15:33:16 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
2016-08-03 15:57:58 +03:00
|
|
|
break;
|
2016-08-03 15:33:16 +03:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2016-08-03 16:05:01 +03:00
|
|
|
struct gui_ctx *ctx = data;
|
2016-08-03 18:34:33 +03:00
|
|
|
struct gui_sheet *sheet = ctx->curr_sheet;
|
2016-08-03 16:05:01 +03:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
canvas_coord(ctx, ctx->curr_x, ctx->curr_y, &x, &y);
|
2016-08-03 18:34:33 +03:00
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
switch (event->keyval) {
|
2016-08-03 16:05:01 +03:00
|
|
|
case '+':
|
|
|
|
case '=':
|
|
|
|
zoom_in(ctx, x, y);
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
zoom_out(ctx, x, y);
|
|
|
|
break;
|
2016-08-03 19:05:30 +03:00
|
|
|
case '*':
|
|
|
|
zoom_to_extents(ctx);
|
|
|
|
break;
|
2016-08-03 22:00:51 +03:00
|
|
|
case GDK_KEY_Home:
|
2016-08-10 01:01:05 +03:00
|
|
|
if (sheet != ctx->new_hist->sheets)
|
|
|
|
go_to_sheet(ctx, ctx->new_hist->sheets);
|
2016-08-03 22:00:51 +03:00
|
|
|
break;
|
2016-08-03 18:34:33 +03:00
|
|
|
case GDK_KEY_BackSpace:
|
|
|
|
case GDK_KEY_Delete:
|
2016-08-04 14:49:54 +03:00
|
|
|
go_up_sheet(ctx);
|
2016-08-03 18:34:33 +03:00
|
|
|
break;
|
2016-08-04 15:02:33 +03:00
|
|
|
case GDK_KEY_Page_Up:
|
|
|
|
case GDK_KEY_KP_Page_Up:
|
|
|
|
go_prev_sheet(ctx);
|
|
|
|
break;
|
|
|
|
case GDK_KEY_Page_Down:
|
|
|
|
case GDK_KEY_KP_Page_Down:
|
|
|
|
go_next_sheet(ctx);
|
|
|
|
break;
|
2016-08-05 02:35:41 +03:00
|
|
|
case GDK_KEY_Up:
|
|
|
|
case GDK_KEY_KP_Up:
|
2016-08-10 00:28:59 +03:00
|
|
|
show_history(ctx, sel_new);
|
|
|
|
break;
|
2016-08-05 02:35:41 +03:00
|
|
|
case GDK_KEY_Down:
|
|
|
|
case GDK_KEY_KP_Down:
|
2016-08-10 00:28:59 +03:00
|
|
|
show_history(ctx, sel_old);
|
2016-08-05 02:35:41 +03:00
|
|
|
break;
|
2016-08-03 15:33:16 +03:00
|
|
|
case GDK_KEY_q:
|
|
|
|
gtk_main_quit();
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
struct gui_ctx *ctx = data;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
canvas_coord(ctx, event->x, event->y, &x, &y);
|
|
|
|
switch (event->direction) {
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
zoom_in(ctx, x, y);
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
zoom_out(ctx, x, y);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* ignore */;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 19:15:25 +03:00
|
|
|
static void size_allocate_event(GtkWidget *widget, GdkRectangle *allocation,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
struct gui_ctx *ctx = data;
|
|
|
|
|
|
|
|
zoom_to_extents(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 18:26:22 +03:00
|
|
|
/* ----- AoI callbacks ----------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2016-08-04 13:19:18 +03:00
|
|
|
struct sheet_aoi_ctx {
|
|
|
|
struct gui_ctx *gui_ctx;
|
|
|
|
const struct sch_obj *obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void select_subsheet(void *user)
|
2016-08-03 18:26:22 +03:00
|
|
|
{
|
2016-08-04 13:19:18 +03:00
|
|
|
const struct sheet_aoi_ctx *aoi_ctx = user;
|
|
|
|
struct gui_ctx *ctx = aoi_ctx->gui_ctx;
|
|
|
|
const struct sch_obj *obj = aoi_ctx->obj;
|
2016-08-05 01:25:31 +03:00
|
|
|
struct gui_sheet *sheet;
|
2016-08-03 18:26:22 +03:00
|
|
|
|
2016-08-11 07:49:49 +03:00
|
|
|
if (!obj->u.sheet.sheet)
|
|
|
|
return;
|
2016-08-10 01:01:05 +03:00
|
|
|
for (sheet = ctx->new_hist->sheets; sheet; sheet = sheet->next)
|
2016-08-03 18:26:22 +03:00
|
|
|
if (sheet->sch == obj->u.sheet.sheet) {
|
2016-08-04 14:49:54 +03:00
|
|
|
go_to_sheet(ctx, sheet);
|
2016-08-03 18:26:22 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 03:50:07 +03:00
|
|
|
struct glabel_aoi_ctx {
|
|
|
|
const struct gui_sheet *sheet;
|
|
|
|
const struct sch_obj *obj;
|
2016-08-11 05:47:08 +03:00
|
|
|
struct dwg_bbox bbox;
|
2016-08-11 03:50:07 +03:00
|
|
|
struct overlay *over;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-08-11 05:47:08 +03:00
|
|
|
/* small offset to hide rounding errors */
|
|
|
|
#define CHEAT 1
|
|
|
|
|
|
|
|
|
2016-08-11 07:27:59 +03:00
|
|
|
static void glabel_dest_click(void *user)
|
|
|
|
{
|
|
|
|
struct gui_sheet *sheet = user;
|
|
|
|
|
|
|
|
go_to_sheet(sheet->ctx, sheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 03:50:07 +03:00
|
|
|
static bool hover_glabel(void *user, bool on)
|
|
|
|
{
|
|
|
|
struct glabel_aoi_ctx *aoi_ctx = user;
|
|
|
|
struct gui_ctx *ctx = aoi_ctx->sheet->ctx;
|
2016-08-11 05:47:08 +03:00
|
|
|
const struct gui_sheet *curr_sheet = ctx->curr_sheet;
|
|
|
|
const struct dwg_bbox *bbox = &aoi_ctx->bbox;
|
2016-08-11 03:50:07 +03:00
|
|
|
|
2016-08-11 07:27:59 +03:00
|
|
|
if (!on) {
|
2016-08-11 05:47:08 +03:00
|
|
|
overlay_remove(&ctx->pop_overlays, aoi_ctx->over);
|
2016-08-11 07:27:59 +03:00
|
|
|
redraw(ctx);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkAllocation alloc;
|
|
|
|
struct overlay_style style = {
|
|
|
|
.font = BOLD_FONT,
|
|
|
|
.wmin = 100,
|
|
|
|
.wmax = 100,
|
|
|
|
.radius = 0,
|
|
|
|
.pad = 4,
|
|
|
|
.skip = -4,
|
|
|
|
.fg = { 0.0, 0.0, 0.0, 1.0 },
|
|
|
|
.bg = { 1.0, 0.8, 0.4, 0.8 },
|
|
|
|
.frame = { 1.0, 1.0, 1.0, 1.0 }, /* debugging */
|
|
|
|
.width = 0,
|
|
|
|
};
|
|
|
|
int sx, sy, ex, ey, mx, my;
|
|
|
|
unsigned n = 0;
|
|
|
|
struct gui_sheet *sheet;
|
|
|
|
const struct sch_obj *obj;
|
|
|
|
struct overlay *over;
|
|
|
|
|
|
|
|
aoi_dehover();
|
|
|
|
overlay_remove_all(&ctx->pop_overlays);
|
|
|
|
for (sheet = ctx->new_hist->sheets; sheet; sheet = sheet->next) {
|
|
|
|
n++;
|
|
|
|
for (obj = sheet->sch->objs; obj; obj = obj->next) {
|
|
|
|
if (sheet == curr_sheet)
|
|
|
|
continue;
|
|
|
|
if (obj->type != sch_obj_glabel)
|
|
|
|
continue;
|
|
|
|
if (strcmp(obj->u.text.s, aoi_ctx->obj->u.text.s))
|
|
|
|
continue;
|
|
|
|
over = overlay_add(&ctx->pop_overlays,
|
|
|
|
&ctx->aois, NULL, glabel_dest_click, sheet);
|
|
|
|
overlay_text(over, "%d %s", n, sheet->sch->title);
|
|
|
|
overlay_style(over, &style);
|
|
|
|
break;
|
|
|
|
}
|
2016-08-11 03:50:07 +03:00
|
|
|
}
|
2016-08-11 07:27:59 +03:00
|
|
|
|
|
|
|
eeschema_coord(ctx,
|
|
|
|
bbox->x - curr_sheet->xmin, bbox->y - curr_sheet->ymin,
|
|
|
|
&sx, &sy);
|
|
|
|
eeschema_coord(ctx, bbox->x + bbox->w - curr_sheet->xmin,
|
|
|
|
bbox->y + bbox->h - curr_sheet->ymin, &ex, &ey);
|
|
|
|
|
|
|
|
gtk_widget_get_allocation(ctx->da, &alloc);
|
|
|
|
mx = (sx + ex) / 2;
|
|
|
|
my = (sy + ey) / 2;
|
|
|
|
ctx->pop_x = mx < alloc.width / 2 ?
|
|
|
|
sx - CHEAT : -(alloc.width - ex) + CHEAT;
|
|
|
|
ctx->pop_y = my < alloc.height / 2 ?
|
|
|
|
sy - CHEAT : -(alloc.height - ey) + CHEAT;
|
|
|
|
|
2016-08-11 03:50:07 +03:00
|
|
|
redraw(ctx);
|
2016-08-11 07:27:59 +03:00
|
|
|
return 0;
|
2016-08-11 03:50:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
/* ----- Initialization ---------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2016-08-04 13:19:18 +03:00
|
|
|
static void add_sheet_aoi(struct gui_ctx *ctx, struct gui_sheet *parent,
|
|
|
|
const struct sch_obj *obj)
|
|
|
|
{
|
|
|
|
struct sheet_aoi_ctx *aoi_ctx = alloc_type(struct sheet_aoi_ctx);
|
|
|
|
|
|
|
|
aoi_ctx->gui_ctx = ctx;
|
|
|
|
aoi_ctx->obj = obj;
|
|
|
|
|
|
|
|
struct aoi aoi = {
|
|
|
|
.x = obj->x,
|
|
|
|
.y = obj->y,
|
|
|
|
.w = obj->u.sheet.w,
|
|
|
|
.h = obj->u.sheet.h,
|
|
|
|
.click = select_subsheet,
|
|
|
|
.user = aoi_ctx,
|
|
|
|
};
|
|
|
|
|
|
|
|
aoi_add(&parent->aois, &aoi);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 03:50:07 +03:00
|
|
|
static void add_glabel_aoi(struct gui_sheet *sheet, const struct sch_obj *obj)
|
|
|
|
{
|
|
|
|
const struct dwg_bbox *bbox = &obj->u.text.bbox;
|
|
|
|
struct glabel_aoi_ctx *aoi_ctx = alloc_type(struct glabel_aoi_ctx);
|
2016-08-11 05:47:08 +03:00
|
|
|
|
2016-08-11 03:50:07 +03:00
|
|
|
struct aoi cfg = {
|
|
|
|
.x = bbox->x,
|
|
|
|
.y = bbox->y,
|
|
|
|
.w = bbox->w,
|
|
|
|
.h = bbox->h,
|
|
|
|
.hover = hover_glabel,
|
|
|
|
.user = aoi_ctx,
|
|
|
|
};
|
|
|
|
|
|
|
|
aoi_ctx->sheet = sheet;
|
|
|
|
aoi_ctx->obj = obj;
|
2016-08-11 05:47:08 +03:00
|
|
|
aoi_ctx->bbox = *bbox;
|
2016-08-11 03:50:07 +03:00
|
|
|
|
|
|
|
aoi_add(&sheet->aois, &cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-04 13:19:18 +03:00
|
|
|
static void mark_aois(struct gui_ctx *ctx, struct gui_sheet *sheet)
|
2016-08-03 18:26:22 +03:00
|
|
|
{
|
|
|
|
const struct sch_obj *obj;
|
|
|
|
|
|
|
|
sheet->aois = NULL;
|
|
|
|
for (obj = sheet->sch->objs; obj; obj = obj->next)
|
|
|
|
switch (obj->type) {
|
2016-08-04 13:19:18 +03:00
|
|
|
case sch_obj_sheet:
|
|
|
|
add_sheet_aoi(ctx, sheet, obj);
|
2016-08-03 18:26:22 +03:00
|
|
|
break;
|
2016-08-11 03:50:07 +03:00
|
|
|
case sch_obj_glabel:
|
|
|
|
add_glabel_aoi(sheet, obj);
|
2016-08-03 18:26:22 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-06 15:25:37 +03:00
|
|
|
static struct gui_sheet *get_sheets(struct gui_ctx *ctx,
|
|
|
|
const struct sheet *sheets)
|
2016-08-03 16:52:55 +03:00
|
|
|
{
|
|
|
|
const struct sheet *sheet;
|
2016-08-06 15:25:37 +03:00
|
|
|
struct gui_sheet *gui_sheets = NULL;
|
|
|
|
struct gui_sheet **next = &gui_sheets;
|
|
|
|
struct gui_sheet *new;
|
2016-08-03 16:52:55 +03:00
|
|
|
|
|
|
|
for (sheet = sheets; sheet; sheet = sheet->next) {
|
2016-08-06 15:25:37 +03:00
|
|
|
new = alloc_type(struct gui_sheet);
|
|
|
|
new->sch = sheet;
|
2016-08-11 02:20:51 +03:00
|
|
|
new->ctx = ctx;
|
2016-08-06 16:19:16 +03:00
|
|
|
new->rendered = 0;
|
2016-08-03 18:26:22 +03:00
|
|
|
|
2016-08-06 15:25:37 +03:00
|
|
|
*next = new;
|
|
|
|
next = &new->next;
|
2016-08-03 16:52:55 +03:00
|
|
|
}
|
|
|
|
*next = NULL;
|
2016-08-06 15:25:37 +03:00
|
|
|
return gui_sheets;
|
2016-08-03 16:52:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-10 22:03:52 +03:00
|
|
|
/*
|
|
|
|
* Library caching:
|
|
|
|
*
|
|
|
|
* We reuse previous components if all libraries are identical
|
|
|
|
*
|
|
|
|
* Future optimizations:
|
|
|
|
* - don't parse into single list of components, so that we can share
|
|
|
|
* libraries that are the same, even if there are others that have changed.
|
|
|
|
* - maybe put components into tree, so that they can be replaced individually
|
|
|
|
* (this would also help to identify sheets that don't need parsing)
|
2016-08-11 02:15:07 +03:00
|
|
|
*
|
|
|
|
* Sheet caching:
|
|
|
|
*
|
|
|
|
* We reuse previous sheets if
|
|
|
|
* - all libraries are identical (whether a given sheet uses them or not),
|
|
|
|
* - they have no sub-sheets, and
|
|
|
|
* - the objects IDs (hashes) are identical.
|
|
|
|
*
|
|
|
|
* Note that we only compare with the immediately preceding (newer) revision,
|
|
|
|
* so branches and merges can disrupt caching.
|
|
|
|
*
|
|
|
|
* Possible optimizations:
|
|
|
|
* - if we record which child sheets a sheet has, we could also clone it,
|
|
|
|
* without having to parse it. However, this is somewhat complex and may
|
|
|
|
* not save all that much time.
|
|
|
|
* - we could record what libraries a sheet uses, and parse only if one of
|
|
|
|
* these has changed (benefits scenarios with many library files),
|
|
|
|
* - we could record what components a sheet uses, and parse only if one of
|
|
|
|
* these has changed (benefits scenarios with few big libraries),
|
|
|
|
* - we could postpone library lookups to render time.
|
|
|
|
* - we could record IDs globally, which would help to avoid tripping over
|
|
|
|
* branches and merges.
|
2016-08-10 22:03:52 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static const struct sheet *parse_files(struct gui_hist *hist,
|
|
|
|
int n_args, char **args, bool recurse, const struct gui_hist *prev)
|
2016-08-05 02:35:41 +03:00
|
|
|
{
|
2016-08-06 15:25:37 +03:00
|
|
|
char *rev = NULL;
|
2016-08-05 16:24:39 +03:00
|
|
|
struct file sch_file;
|
2016-08-10 22:03:52 +03:00
|
|
|
struct file lib_files[n_args - 1];
|
|
|
|
int libs_open, i;
|
|
|
|
bool libs_cached = 0;
|
2016-08-06 15:25:37 +03:00
|
|
|
bool ok;
|
|
|
|
|
2016-08-10 22:03:52 +03:00
|
|
|
if (hist->vcs_hist)
|
|
|
|
rev = vcs_git_get_rev(hist->vcs_hist);
|
2016-08-05 16:24:39 +03:00
|
|
|
|
2016-08-11 00:57:04 +03:00
|
|
|
sch_init(&hist->sch_ctx, recurse);
|
2016-08-06 15:25:37 +03:00
|
|
|
ok = file_open_revision(&sch_file, rev, args[n_args - 1], NULL);
|
|
|
|
|
|
|
|
if (rev)
|
|
|
|
free(rev);
|
|
|
|
if (!ok) {
|
2016-08-11 00:57:04 +03:00
|
|
|
sch_free(&hist->sch_ctx);
|
2016-08-06 03:02:57 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-08-05 16:24:39 +03:00
|
|
|
|
2016-08-10 22:03:52 +03:00
|
|
|
lib_init(&hist->lib);
|
|
|
|
for (libs_open = 0; libs_open != n_args - 1; libs_open++)
|
|
|
|
if (!file_open(lib_files + libs_open, args[libs_open],
|
|
|
|
&sch_file))
|
2016-08-06 03:02:57 +03:00
|
|
|
goto fail;
|
2016-08-10 22:03:52 +03:00
|
|
|
|
|
|
|
if (hist->vcs_hist) {
|
2016-08-11 02:28:31 +03:00
|
|
|
hist->oids = alloc_type_n(void *, libs_open);
|
2016-08-10 22:03:52 +03:00
|
|
|
for (i = 0; i != libs_open; i++)
|
|
|
|
hist->oids[i] = file_oid(lib_files + i);
|
|
|
|
if (prev && prev->vcs_hist) {
|
|
|
|
for (i = 0; i != libs_open; i++)
|
|
|
|
if (!file_oid_eq(hist->oids[i], prev->oids[i]))
|
|
|
|
break;
|
|
|
|
if (i == libs_open) {
|
|
|
|
hist->lib.comps = prev->lib.comps;
|
|
|
|
libs_cached = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!libs_cached)
|
|
|
|
for (i = 0; i != libs_open; i++)
|
|
|
|
if (!lib_parse_file(&hist->lib, lib_files +i))
|
|
|
|
goto fail;
|
|
|
|
|
2016-08-11 00:57:04 +03:00
|
|
|
if (!sch_parse(&hist->sch_ctx, &sch_file, &hist->lib,
|
|
|
|
libs_cached ? &prev->sch_ctx : NULL))
|
2016-08-06 03:02:57 +03:00
|
|
|
goto fail;
|
2016-08-10 22:03:52 +03:00
|
|
|
|
|
|
|
for (i = 0; i != libs_open; i++)
|
|
|
|
file_close(lib_files + i);
|
2016-08-05 16:24:39 +03:00
|
|
|
file_close(&sch_file);
|
|
|
|
|
2016-08-06 15:25:37 +03:00
|
|
|
/*
|
|
|
|
* @@@ we have a major memory leak for the component library.
|
|
|
|
* We should record parsed schematics and libraries separately, so
|
|
|
|
* that we can clean them up, without having to rely on the history,
|
2016-08-10 22:03:52 +03:00
|
|
|
* with - when sharing unchanged item - possibly many duplicate
|
|
|
|
* pointers.
|
2016-08-06 15:25:37 +03:00
|
|
|
*/
|
2016-08-11 00:57:04 +03:00
|
|
|
return hist->sch_ctx.sheets;
|
2016-08-06 03:02:57 +03:00
|
|
|
|
|
|
|
fail:
|
2016-08-10 22:03:52 +03:00
|
|
|
while (libs_open--)
|
|
|
|
file_close(lib_files + libs_open);
|
2016-08-11 00:57:04 +03:00
|
|
|
sch_free(&hist->sch_ctx);
|
2016-08-10 22:03:52 +03:00
|
|
|
lib_free(&hist->lib);
|
2016-08-06 03:02:57 +03:00
|
|
|
file_close(&sch_file);
|
|
|
|
return NULL;
|
2016-08-05 16:24:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-06 15:25:37 +03:00
|
|
|
struct add_hist_ctx {
|
|
|
|
struct gui_ctx *ctx;
|
|
|
|
int n_args;
|
|
|
|
char **args;
|
|
|
|
bool recurse;
|
2016-08-10 15:08:22 +03:00
|
|
|
unsigned limit;
|
2016-08-06 15:25:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void add_hist(void *user, struct hist *h)
|
|
|
|
{
|
|
|
|
struct add_hist_ctx *ahc = user;
|
|
|
|
struct gui_ctx *ctx = ahc->ctx;
|
2016-08-10 22:03:52 +03:00
|
|
|
struct gui_hist **anchor, *hist, *prev;
|
2016-08-06 15:25:37 +03:00
|
|
|
const struct sheet *sch;
|
2016-08-09 20:16:05 +03:00
|
|
|
unsigned age = 0;
|
2016-08-06 15:25:37 +03:00
|
|
|
|
2016-08-10 15:08:22 +03:00
|
|
|
if (!ahc->limit)
|
|
|
|
return;
|
|
|
|
ahc->limit--;
|
|
|
|
|
2016-08-10 22:03:52 +03:00
|
|
|
prev = NULL;
|
|
|
|
for (anchor = &ctx->hist; *anchor; anchor = &(*anchor)->next) {
|
|
|
|
prev = *anchor;
|
2016-08-09 20:16:05 +03:00
|
|
|
age++;
|
2016-08-10 22:03:52 +03:00
|
|
|
}
|
2016-08-10 20:07:03 +03:00
|
|
|
|
|
|
|
hist = alloc_type(struct gui_hist);
|
|
|
|
hist->ctx = ctx;
|
|
|
|
hist->vcs_hist = h;
|
2016-08-10 22:03:52 +03:00
|
|
|
sch = parse_files(hist, ahc->n_args, ahc->args, ahc->recurse, prev);
|
2016-08-10 20:07:03 +03:00
|
|
|
hist->sheets = sch ? get_sheets(ctx, sch) : NULL;
|
|
|
|
hist->age = age;
|
|
|
|
|
|
|
|
hist->next = NULL;
|
|
|
|
*anchor = hist;
|
2016-08-06 15:25:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void get_revisions(struct gui_ctx *ctx,
|
2016-08-10 15:08:22 +03:00
|
|
|
int n_args, char **args, bool recurse, int limit)
|
2016-08-06 15:25:37 +03:00
|
|
|
{
|
|
|
|
const char *sch_name = args[n_args - 1];
|
|
|
|
struct add_hist_ctx add_hist_ctx = {
|
|
|
|
.ctx = ctx,
|
|
|
|
.n_args = n_args,
|
|
|
|
.args = args,
|
|
|
|
.recurse = recurse,
|
2016-08-10 15:08:22 +03:00
|
|
|
.limit = limit < 0 ? -limit : limit,
|
2016-08-06 15:25:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!vcs_git_try(sch_name)) {
|
|
|
|
ctx->vcs_hist = NULL;
|
|
|
|
add_hist(&add_hist_ctx, NULL);
|
|
|
|
} else {
|
|
|
|
ctx->vcs_hist = vcs_git_hist(sch_name);
|
|
|
|
hist_iterate(ctx->vcs_hist, add_hist, &add_hist_ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-10 15:08:22 +03:00
|
|
|
int gui(unsigned n_args, char **args, bool recurse, int limit)
|
2016-08-03 13:38:57 +03:00
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
struct gui_ctx ctx = {
|
2016-08-03 15:33:16 +03:00
|
|
|
.zoom = 4, /* scale by 1 / 16 */
|
|
|
|
.panning = 0,
|
2016-08-05 02:35:41 +03:00
|
|
|
.hist = NULL,
|
|
|
|
.vcs_hist = NULL,
|
2016-08-09 19:28:27 +03:00
|
|
|
.showing_history= 0,
|
2016-08-05 02:35:41 +03:00
|
|
|
.sheet_overlays = NULL,
|
2016-08-07 12:23:04 +03:00
|
|
|
.hist_overlays = NULL,
|
2016-08-11 05:47:08 +03:00
|
|
|
.pop_overlays = NULL,
|
2016-08-04 13:53:25 +03:00
|
|
|
.aois = NULL,
|
2016-08-10 01:01:05 +03:00
|
|
|
.old_hist = NULL,
|
2016-08-03 13:38:57 +03:00
|
|
|
};
|
|
|
|
|
2016-08-10 15:08:22 +03:00
|
|
|
get_revisions(&ctx, n_args, args, recurse, limit);
|
2016-08-10 01:01:05 +03:00
|
|
|
for (ctx.new_hist = ctx.hist; ctx.new_hist && !ctx.new_hist->sheets;
|
|
|
|
ctx.new_hist = ctx.new_hist->next);
|
|
|
|
if (!ctx.new_hist) {
|
2016-08-06 15:25:37 +03:00
|
|
|
fprintf(stderr, "no valid sheets\n");
|
|
|
|
return 1;
|
2016-08-06 03:28:45 +03:00
|
|
|
}
|
2016-08-03 13:38:57 +03:00
|
|
|
|
|
|
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
ctx.da = gtk_drawing_area_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(window), ctx.da);
|
2016-08-03 13:38:57 +03:00
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
g_signal_connect(G_OBJECT(ctx.da), "draw",
|
2016-08-03 13:38:57 +03:00
|
|
|
G_CALLBACK(on_draw_event), &ctx);
|
2016-08-03 15:33:16 +03:00
|
|
|
g_signal_connect(G_OBJECT(ctx.da), "motion_notify_event",
|
|
|
|
G_CALLBACK(motion_notify_event), &ctx);
|
|
|
|
g_signal_connect(G_OBJECT(ctx.da), "button_press_event",
|
|
|
|
G_CALLBACK(button_press_event), &ctx);
|
|
|
|
g_signal_connect(G_OBJECT(ctx.da), "button_release_event",
|
|
|
|
G_CALLBACK(button_release_event), &ctx);
|
|
|
|
g_signal_connect(G_OBJECT(ctx.da), "scroll_event",
|
|
|
|
G_CALLBACK(scroll_event), &ctx);
|
|
|
|
g_signal_connect(G_OBJECT(ctx.da), "key_press_event",
|
|
|
|
G_CALLBACK(key_press_event), &ctx);
|
2016-08-03 19:15:25 +03:00
|
|
|
g_signal_connect(G_OBJECT(ctx.da), "size_allocate",
|
|
|
|
G_CALLBACK(size_allocate_event), &ctx);
|
|
|
|
|
2016-08-03 13:38:57 +03:00
|
|
|
g_signal_connect(window, "destroy",
|
|
|
|
G_CALLBACK(gtk_main_quit), NULL);
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
gtk_widget_set_can_focus(ctx.da, TRUE);
|
|
|
|
|
|
|
|
gtk_widget_set_events(ctx.da,
|
|
|
|
GDK_EXPOSE | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
|
|
|
|
GDK_KEY_PRESS_MASK |
|
|
|
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_SCROLL_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK);
|
|
|
|
|
|
|
|
// gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
|
2016-08-08 04:34:01 +03:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
|
2016-08-03 15:33:16 +03:00
|
|
|
gtk_window_set_title(GTK_WINDOW(window), "eeshow");
|
2016-08-03 13:38:57 +03:00
|
|
|
|
2016-08-10 01:01:05 +03:00
|
|
|
go_to_sheet(&ctx, ctx.new_hist->sheets);
|
2016-08-03 13:38:57 +03:00
|
|
|
gtk_widget_show_all(window);
|
|
|
|
|
2016-08-10 15:08:22 +03:00
|
|
|
/* for performance testing, use -N-depth */
|
|
|
|
if (limit >= 0)
|
|
|
|
gtk_main();
|
2016-08-03 13:38:57 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|