summaryrefslogtreecommitdiff
path: root/gui/sheet.c
diff options
context:
space:
mode:
Diffstat (limited to 'gui/sheet.c')
-rw-r--r--gui/sheet.c336
1 files changed, 168 insertions, 168 deletions
diff --git a/gui/sheet.c b/gui/sheet.c
index dc9676b..9499908 100644
--- a/gui/sheet.c
+++ b/gui/sheet.c
@@ -39,69 +39,69 @@
/* ----- Tools ------------------------------------------------------------- */
-static void canvas_coord(const struct gui_ctx *ctx,
+static void canvas_coord(const struct gui_ctx *gui,
int ex, int ey, int *x, int *y)
{
GtkAllocation alloc;
int sx, sy;
- gtk_widget_get_allocation(ctx->da, &alloc);
+ gtk_widget_get_allocation(gui->da, &alloc);
sx = ex - alloc.width / 2;
sy = ey - alloc.height / 2;
- *x = sx / ctx->scale + ctx->x;
- *y = sy / ctx->scale + ctx->y;
+ *x = sx / gui->scale + gui->x;
+ *y = sy / gui->scale + gui->y;
}
/* ----- Zoom -------------------------------------------------------------- */
-static bool zoom_in(struct gui_ctx *ctx, int x, int y)
+static bool zoom_in(struct gui_ctx *gui, int x, int y)
{
- float old = ctx->scale;
+ float old = gui->scale;
- if (ctx->scale == ZOOM_MAX)
+ if (gui->scale == ZOOM_MAX)
return 0;
- ctx->scale *= ZOOM_FACTOR;
- if (ctx->scale > ZOOM_MAX)
- ctx->scale = ZOOM_MAX;
- ctx->x = x + (ctx->x - x) * old / ctx->scale;
- ctx->y = y + (ctx->y - y) * old / ctx->scale;
- redraw(ctx);
+ gui->scale *= ZOOM_FACTOR;
+ if (gui->scale > ZOOM_MAX)
+ gui->scale = ZOOM_MAX;
+ gui->x = x + (gui->x - x) * old / gui->scale;
+ gui->y = y + (gui->y - y) * old / gui->scale;
+ redraw(gui);
return 1;
}
-static bool zoom_out(struct gui_ctx *ctx, int x, int y)
+static bool zoom_out(struct gui_ctx *gui, int x, int y)
{
- float old = ctx->scale;
+ float old = gui->scale;
- if (ctx->curr_sheet->w * ctx->scale <= ZOOM_MIN_SIZE)
+ if (gui->curr_sheet->w * gui->scale <= ZOOM_MIN_SIZE)
return 0;
- ctx->scale /= ZOOM_FACTOR;
- if (ctx->curr_sheet->w <= ZOOM_MIN_SIZE)
- ctx->scale = 1;
- else if (ctx->curr_sheet->w * ctx->scale <= ZOOM_MIN_SIZE )
- ctx->scale = (float) ZOOM_MIN_SIZE / ctx->curr_sheet->w;
- ctx->x = x + (ctx->x - x) * old / ctx->scale;
- ctx->y = y + (ctx->y - y) * old / ctx->scale;
- redraw(ctx);
+ gui->scale /= ZOOM_FACTOR;
+ if (gui->curr_sheet->w <= ZOOM_MIN_SIZE)
+ gui->scale = 1;
+ else if (gui->curr_sheet->w * gui->scale <= ZOOM_MIN_SIZE )
+ gui->scale = (float) ZOOM_MIN_SIZE / gui->curr_sheet->w;
+ gui->x = x + (gui->x - x) * old / gui->scale;
+ gui->y = y + (gui->y - y) * old / gui->scale;
+ redraw(gui);
return 1;
}
-static void curr_sheet_size(struct gui_ctx *ctx, int *w, int *h)
+static void curr_sheet_size(struct gui_ctx *gui, int *w, int *h)
{
- const struct gui_sheet *sheet = ctx->curr_sheet;
+ const struct gui_sheet *sheet = gui->curr_sheet;
int ax1, ay1, bx1, by1;
- if (!ctx->old_hist) {
+ if (!gui->old_hist) {
*w = sheet->w;
*h = sheet->h;
} else {
const struct gui_sheet *old =
- find_corresponding_sheet(ctx->old_hist->sheets,
- ctx->new_hist->sheets, sheet);
+ find_corresponding_sheet(gui->old_hist->sheets,
+ gui->new_hist->sheets, sheet);
/*
* We're only interested in differences here, so no need for
@@ -119,23 +119,23 @@ static void curr_sheet_size(struct gui_ctx *ctx, int *w, int *h)
}
-void zoom_to_extents(struct gui_ctx *ctx)
+void zoom_to_extents(struct gui_ctx *gui)
{
GtkAllocation alloc;
int w, h;
float sw, sh;
- curr_sheet_size(ctx, &w, &h);
- ctx->x = w / 2;
- ctx->y = h / 2;
+ curr_sheet_size(gui, &w, &h);
+ gui->x = w / 2;
+ gui->y = h / 2;
- gtk_widget_get_allocation(ctx->da, &alloc);
+ gtk_widget_get_allocation(gui->da, &alloc);
sw = w ? (float) ZOOM_MARGIN * alloc.width / w : 1;
sh = h ? (float) ZOOM_MARGIN * alloc.height / h : 1;
- ctx->scale = sw < sh ? sw : sh;
+ gui->scale = sw < sh ? sw : sh;
- redraw(ctx);
+ redraw(gui);
}
@@ -145,7 +145,7 @@ void zoom_to_extents(struct gui_ctx *ctx)
static bool show_history_details(void *user, bool on, int dx, int dy)
{
struct gui_hist *h = user;
- struct gui_ctx *ctx = h->ctx;
+ struct gui_ctx *gui = h->gui;
char *s;
if (on) {
@@ -155,67 +155,67 @@ static bool show_history_details(void *user, bool on, int dx, int dy)
} else {
overlay_text(h->over, "%.40s", vcs_git_summary(h->vcs_hist));
}
- redraw(ctx);
+ redraw(gui);
return 1;
}
-static void set_diff_mode(struct gui_ctx *ctx, enum diff_mode mode)
+static void set_diff_mode(struct gui_ctx *gui, enum diff_mode mode)
{
- ctx->diff_mode = mode;
- do_revision_overlays(ctx);
- redraw(ctx);
+ gui->diff_mode = mode;
+ do_revision_overlays(gui);
+ redraw(gui);
}
static void show_history_cb(void *user)
{
struct gui_hist *h = user;
- struct gui_ctx *ctx = h->ctx;
+ struct gui_ctx *gui = h->gui;
enum selecting sel = sel_only;
- if (ctx->old_hist) {
- if (h == ctx->new_hist && ctx->diff_mode != diff_new) {
- set_diff_mode(ctx, diff_new);
+ if (gui->old_hist) {
+ if (h == gui->new_hist && gui->diff_mode != diff_new) {
+ set_diff_mode(gui, diff_new);
return;
}
- if (h == ctx->old_hist && ctx->diff_mode != diff_old) {
- set_diff_mode(ctx, diff_old);
+ if (h == gui->old_hist && gui->diff_mode != diff_old) {
+ set_diff_mode(gui, diff_old);
return;
}
- sel = h == ctx->new_hist ? sel_new : sel_old;
+ sel = h == gui->new_hist ? sel_new : sel_old;
}
- show_history(ctx, sel);
+ show_history(gui, sel);
}
static void show_diff_cb(void *user)
{
- struct gui_ctx *ctx = user;
+ struct gui_ctx *gui = user;
- if (ctx->old_hist)
- set_diff_mode(ctx,
- ctx->diff_mode == diff_delta ? diff_new : diff_delta);
+ if (gui->old_hist)
+ set_diff_mode(gui,
+ gui->diff_mode == diff_delta ? diff_new : diff_delta);
else
- show_history(ctx, sel_split);
+ show_history(gui, sel_split);
}
-static void toggle_old_new(struct gui_ctx *ctx)
+static void toggle_old_new(struct gui_ctx *gui)
{
- set_diff_mode(ctx, ctx->diff_mode == diff_new ? diff_old : diff_new);
+ set_diff_mode(gui, gui->diff_mode == diff_new ? diff_old : diff_new);
}
-static void add_delta(struct gui_ctx *ctx)
+static void add_delta(struct gui_ctx *gui)
{
struct overlay *over;
struct overlay_style style;
- over = overlay_add(&ctx->hist_overlays, &ctx->aois,
- NULL, show_diff_cb, ctx);
+ over = overlay_add(&gui->hist_overlays, &gui->aois,
+ NULL, show_diff_cb, gui);
style = overlay_style_default;
- if (ctx->old_hist && ctx->diff_mode == diff_delta)
+ if (gui->old_hist && gui->diff_mode == diff_delta)
style.frame = RGBA(0, 0, 0, 1);
style.pad = 4;
overlay_style(over, &style);
@@ -226,46 +226,46 @@ static void add_delta(struct gui_ctx *ctx)
}
-static void revision_overlays_diff(struct gui_ctx *ctx)
+static void revision_overlays_diff(struct gui_ctx *gui)
{
- struct gui_hist *new = ctx->new_hist;
- struct gui_hist *old = ctx->old_hist;
+ struct gui_hist *new = gui->new_hist;
+ struct gui_hist *old = gui->old_hist;
struct overlay_style style;
- new->over = overlay_add(&ctx->hist_overlays, &ctx->aois,
+ new->over = overlay_add(&gui->hist_overlays, &gui->aois,
show_history_details, show_history_cb, new);
style = overlay_style_diff_new;
- if (ctx->diff_mode == diff_new)
+ if (gui->diff_mode == diff_new)
style.frame = RGBA(0, 0, 0, 1);
overlay_style(new->over, &style);
show_history_details(new, 0, 0, 0);
- add_delta(ctx);
+ add_delta(gui);
- old->over = overlay_add(&ctx->hist_overlays, &ctx->aois,
+ old->over = overlay_add(&gui->hist_overlays, &gui->aois,
show_history_details, show_history_cb, old);
style = overlay_style_diff_old;
- if (ctx->diff_mode == diff_old)
+ if (gui->diff_mode == diff_old)
style.frame = RGBA(0, 0, 0, 1);
overlay_style(old->over, &style);
show_history_details(old, 0, 0, 0);
}
-void do_revision_overlays(struct gui_ctx *ctx)
+void do_revision_overlays(struct gui_ctx *gui)
{
- overlay_remove_all(&ctx->hist_overlays);
+ overlay_remove_all(&gui->hist_overlays);
- if (ctx->old_hist) {
- revision_overlays_diff(ctx);
+ if (gui->old_hist) {
+ revision_overlays_diff(gui);
} else {
- ctx->new_hist->over = overlay_add(&ctx->hist_overlays,
- &ctx->aois, show_history_details, show_history_cb,
- ctx->new_hist);
- overlay_style(ctx->new_hist->over, &overlay_style_default);
- show_history_details(ctx->new_hist, 0, 0, 0);
+ gui->new_hist->over = overlay_add(&gui->hist_overlays,
+ &gui->aois, show_history_details, show_history_cb,
+ gui->new_hist);
+ overlay_style(gui->new_hist->over, &overlay_style_default);
+ show_history_details(gui->new_hist, 0, 0, 0);
- add_delta(ctx);
+ add_delta(gui);
}
}
@@ -291,21 +291,21 @@ static struct gui_sheet *find_parent_sheet(struct gui_sheet *sheets,
static void close_subsheet(void *user)
{
struct gui_sheet *sheet = user;
- struct gui_ctx *ctx = sheet->ctx;
+ struct gui_ctx *gui = sheet->gui;
struct gui_sheet *parent;
- parent = find_parent_sheet(ctx->new_hist->sheets, sheet);
+ parent = find_parent_sheet(gui->new_hist->sheets, sheet);
if (parent)
- go_to_sheet(ctx, parent);
+ go_to_sheet(gui, parent);
else
- show_index(ctx);
+ show_index(gui);
}
static bool hover_sheet(void *user, bool on, int dx, int dy)
{
struct gui_sheet *sheet = user;
- struct gui_ctx *ctx = sheet->ctx;
+ struct gui_ctx *gui = sheet->gui;
const char *title = sheet->sch->title;
if (!title)
@@ -314,7 +314,7 @@ static bool hover_sheet(void *user, bool on, int dx, int dy)
const struct gui_sheet *s;
int n = 0, this = -1;
- for (s = ctx->new_hist->sheets; s; s = s->next) {
+ for (s = gui->new_hist->sheets; s; s = s->next) {
n++;
if (s == sheet)
this = n;
@@ -324,83 +324,83 @@ static bool hover_sheet(void *user, bool on, int dx, int dy)
} else {
overlay_text(sheet->over, "<b>%s</b>", title);
}
- redraw(ctx);
+ redraw(gui);
return 1;
}
-static void sheet_selector_recurse(struct gui_ctx *ctx, struct gui_sheet *sheet)
+static void sheet_selector_recurse(struct gui_ctx *gui, struct gui_sheet *sheet)
{
struct gui_sheet *parent;
- parent = find_parent_sheet(ctx->new_hist->sheets, sheet);
+ parent = find_parent_sheet(gui->new_hist->sheets, sheet);
if (parent)
- sheet_selector_recurse(ctx, parent);
- sheet->over = overlay_add(&ctx->sheet_overlays, &ctx->aois,
+ sheet_selector_recurse(gui, parent);
+ sheet->over = overlay_add(&gui->sheet_overlays, &gui->aois,
hover_sheet, close_subsheet, sheet);
hover_sheet(sheet, 0, 0, 0);
}
-static void do_sheet_overlays(struct gui_ctx *ctx)
+static void do_sheet_overlays(struct gui_ctx *gui)
{
- overlay_remove_all(&ctx->sheet_overlays);
- sheet_selector_recurse(ctx, ctx->curr_sheet);
+ overlay_remove_all(&gui->sheet_overlays);
+ sheet_selector_recurse(gui, gui->curr_sheet);
}
/* ----- Navigate sheets --------------------------------------------------- */
-void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet)
+void go_to_sheet(struct gui_ctx *gui, struct gui_sheet *sheet)
{
aoi_dehover();
- overlay_remove_all(&ctx->pop_overlays);
- overlay_remove_all(&ctx->pop_underlays);
+ overlay_remove_all(&gui->pop_overlays);
+ overlay_remove_all(&gui->pop_underlays);
if (!sheet->rendered) {
render_sheet(sheet);
- mark_aois(ctx, sheet);
+ mark_aois(gui, sheet);
}
- ctx->curr_sheet = sheet;
- if (ctx->old_hist)
- render_delta(ctx);
- if (ctx->vcs_hist)
- do_revision_overlays(ctx);
- do_sheet_overlays(ctx);
- zoom_to_extents(ctx);
+ gui->curr_sheet = sheet;
+ if (gui->old_hist)
+ render_delta(gui);
+ if (gui->vcs_hist)
+ do_revision_overlays(gui);
+ do_sheet_overlays(gui);
+ zoom_to_extents(gui);
}
-static bool go_up_sheet(struct gui_ctx *ctx)
+static bool go_up_sheet(struct gui_ctx *gui)
{
struct gui_sheet *parent;
- parent = find_parent_sheet(ctx->new_hist->sheets, ctx->curr_sheet);
+ parent = find_parent_sheet(gui->new_hist->sheets, gui->curr_sheet);
if (!parent)
return 0;
- go_to_sheet(ctx, parent);
+ go_to_sheet(gui, parent);
return 1;
}
-static bool go_prev_sheet(struct gui_ctx *ctx)
+static bool go_prev_sheet(struct gui_ctx *gui)
{
struct gui_sheet *sheet;
- for (sheet = ctx->new_hist->sheets; sheet; sheet = sheet->next)
- if (sheet->next && sheet->next == ctx->curr_sheet) {
- go_to_sheet(ctx, sheet);
+ for (sheet = gui->new_hist->sheets; sheet; sheet = sheet->next)
+ if (sheet->next && sheet->next == gui->curr_sheet) {
+ go_to_sheet(gui, sheet);
return 1;
}
return 0;
}
-static bool go_next_sheet(struct gui_ctx *ctx)
+static bool go_next_sheet(struct gui_ctx *gui)
{
- if (!ctx->curr_sheet->next)
+ if (!gui->curr_sheet->next)
return 0;
- go_to_sheet(ctx, ctx->curr_sheet->next);
+ go_to_sheet(gui, gui->curr_sheet->next);
return 1;
}
@@ -410,42 +410,42 @@ static bool go_next_sheet(struct gui_ctx *ctx)
static bool sheet_click(void *user, int x, int y)
{
- struct gui_ctx *ctx = user;
- const struct gui_sheet *curr_sheet = ctx->curr_sheet;
+ struct gui_ctx *gui = user;
+ const struct gui_sheet *curr_sheet = gui->curr_sheet;
int ex, ey;
- canvas_coord(ctx, x, y, &ex, &ey);
+ canvas_coord(gui, x, y, &ex, &ey);
- if (ctx->old_hist && ctx->diff_mode == diff_old)
- curr_sheet = find_corresponding_sheet(ctx->old_hist->sheets,
- ctx->new_hist->sheets, ctx->curr_sheet);
+ if (gui->old_hist && gui->diff_mode == diff_old)
+ curr_sheet = find_corresponding_sheet(gui->old_hist->sheets,
+ gui->new_hist->sheets, gui->curr_sheet);
- if (aoi_click(&ctx->aois, x, y))
+ if (aoi_click(&gui->aois, x, y))
return 1;
if (aoi_click(&curr_sheet->aois,
ex + curr_sheet->xmin, ey + curr_sheet->ymin))
return 1;
- overlay_remove_all(&ctx->pop_overlays);
- overlay_remove_all(&ctx->pop_underlays);
- redraw(ctx);
+ overlay_remove_all(&gui->pop_overlays);
+ overlay_remove_all(&gui->pop_underlays);
+ redraw(gui);
return 1;
}
static bool sheet_hover_update(void *user, int x, int y)
{
- struct gui_ctx *ctx = user;
- const struct gui_sheet *curr_sheet = ctx->curr_sheet;
+ struct gui_ctx *gui = user;
+ const struct gui_sheet *curr_sheet = gui->curr_sheet;
int ex, ey;
- canvas_coord(ctx, x, y, &ex, &ey);
+ canvas_coord(gui, x, y, &ex, &ey);
- if (ctx->old_hist && ctx->diff_mode == diff_old)
- curr_sheet = find_corresponding_sheet(ctx->old_hist->sheets,
- ctx->new_hist->sheets, ctx->curr_sheet);
+ if (gui->old_hist && gui->diff_mode == diff_old)
+ curr_sheet = find_corresponding_sheet(gui->old_hist->sheets,
+ gui->new_hist->sheets, gui->curr_sheet);
- if (aoi_hover(&ctx->aois, x, y))
+ if (aoi_hover(&gui->aois, x, y))
return 1;
return aoi_hover(&curr_sheet->aois,
ex + curr_sheet->xmin, ey + curr_sheet->ymin);
@@ -461,11 +461,11 @@ static bool sheet_drag_begin(void *user, int x, int y)
static void sheet_drag_move(void *user, int dx, int dy)
{
- struct gui_ctx *ctx = user;
+ struct gui_ctx *gui = user;
- ctx->x -= dx / ctx->scale;
- ctx->y -= dy / ctx->scale;
- redraw(ctx);
+ gui->x -= dx / gui->scale;
+ gui->y -= dy / gui->scale;
+ redraw(gui);
}
@@ -477,105 +477,105 @@ static void sheet_drag_end(void *user)
static void sheet_scroll(void *user, int x, int y, int dy)
{
- struct gui_ctx *ctx = user;
+ struct gui_ctx *gui = user;
int ex, ey;
- canvas_coord(ctx, x, y, &ex, &ey);
+ canvas_coord(gui, x, y, &ex, &ey);
if (dy < 0) {
- if (!zoom_in(ctx, ex, ey))
+ if (!zoom_in(gui, ex, ey))
return;
} else {
- if (!zoom_out(ctx, ex, ey))
+ if (!zoom_out(gui, ex, ey))
return;
}
- dehover_glabel(ctx);
+ dehover_glabel(gui);
input_update();
}
static void sheet_key(void *user, int x, int y, int keyval)
{
- struct gui_ctx *ctx = user;
- struct gui_sheet *sheet = ctx->curr_sheet;
+ struct gui_ctx *gui = user;
+ struct gui_sheet *sheet = gui->curr_sheet;
int ex, ey;
- canvas_coord(ctx, x, y, &ex, &ey);
+ canvas_coord(gui, x, y, &ex, &ey);
switch (keyval) {
case '+':
case '=':
case GDK_KEY_KP_Add:
case GDK_KEY_KP_Equal:
- zoom_in(ctx, x, y);
+ zoom_in(gui, x, y);
break;
case '-':
case GDK_KEY_KP_Subtract:
- zoom_out(ctx, x, y);
+ zoom_out(gui, x, y);
break;
case '*':
case GDK_KEY_KP_Multiply:
- zoom_to_extents(ctx);
+ zoom_to_extents(gui);
break;
case GDK_KEY_Home:
case GDK_KEY_KP_Home:
- if (sheet != ctx->new_hist->sheets)
- go_to_sheet(ctx, ctx->new_hist->sheets);
+ if (sheet != gui->new_hist->sheets)
+ go_to_sheet(gui, gui->new_hist->sheets);
break;
case GDK_KEY_BackSpace:
case GDK_KEY_Delete:
case GDK_KEY_KP_Delete:
- go_up_sheet(ctx);
+ go_up_sheet(gui);
break;
case GDK_KEY_Page_Up:
case GDK_KEY_KP_Page_Up:
- go_prev_sheet(ctx);
+ go_prev_sheet(gui);
break;
case GDK_KEY_Page_Down:
case GDK_KEY_KP_Page_Down:
- go_next_sheet(ctx);
+ go_next_sheet(gui);
break;
case GDK_KEY_Up:
case GDK_KEY_KP_Up:
- show_history(ctx, sel_new);
+ show_history(gui, sel_new);
break;
case GDK_KEY_Down:
case GDK_KEY_KP_Down:
- show_history(ctx, sel_old);
+ show_history(gui, sel_old);
break;
case GDK_KEY_Tab:
case GDK_KEY_KP_Tab:
- toggle_old_new(ctx);
+ toggle_old_new(gui);
break;
case GDK_KEY_Escape:
dehover_glabel(user);
- ctx->glabel = NULL;
- redraw(ctx);
+ gui->glabel = NULL;
+ redraw(gui);
break;
case GDK_KEY_a:
use_delta = !use_delta;
- do_revision_overlays(ctx);
- redraw(ctx);
+ do_revision_overlays(gui);
+ redraw(gui);
break;
case GDK_KEY_e:
show_extra = !show_extra;
- redraw(ctx);
+ redraw(gui);
break;
case GDK_KEY_n:
- ctx->diff_mode = diff_new;
- redraw(ctx);
+ gui->diff_mode = diff_new;
+ redraw(gui);
break;
case GDK_KEY_o:
- ctx->diff_mode = diff_old;
- redraw(ctx);
+ gui->diff_mode = diff_old;
+ redraw(gui);
break;
case GDK_KEY_d:
- ctx->diff_mode = diff_delta;
- redraw(ctx);
+ gui->diff_mode = diff_delta;
+ redraw(gui);
break;
case GDK_KEY_h:
@@ -585,7 +585,7 @@ static void sheet_key(void *user, int x, int y, int keyval)
case GDK_KEY_t:
timer_toggle();
- redraw(ctx);
+ redraw(gui);
break;
case GDK_KEY_q:
@@ -610,7 +610,7 @@ static const struct input_ops sheet_input_ops = {
/* ----- Initialization ---------------------------------------------------- */
-void sheet_setup(struct gui_ctx *ctx)
+void sheet_setup(struct gui_ctx *gui)
{
- input_push(&sheet_input_ops, ctx);
+ input_push(&sheet_input_ops, gui);
}