1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-07-01 03:22:01 +03:00

eeshow/gui/gui.c: move rendering to render.c

This commit is contained in:
Werner Almesberger 2016-08-18 12:41:12 -03:00
parent bbdf819c85
commit cfa730459c
4 changed files with 164 additions and 130 deletions

View File

@ -15,7 +15,7 @@ OBJS = main.o \
kicad/sch-parse.o kicad/sch-render.o kicad/lib-parse.o \
kicad/lib-render.o kicad/dwg.o kicad/delta.o \
gui/gui.o gui/over.o gui/style.o gui/aoi.o gui/fmt-pango.o gui/input.o \
gui/progress.o gui/glabel.o gui/sheet.o gui/history.o \
gui/progress.o gui/glabel.o gui/sheet.o gui/history.o gui/render.o \
file/file.o file/git-util.o file/git-file.o file/git-hist.o \
gfx/style.o gfx/fig.o gfx/record.o gfx/cro.o gfx/diff.o gfx/gfx.o \
gfx/text.o gfx/misc.o \

View File

@ -106,6 +106,13 @@ struct gui_ctx {
void setup_progress_bar(struct gui_ctx *ctx, GtkWidget *window);
void progress_update(struct gui_ctx *ctx);
/* render.c */
void redraw(const struct gui_ctx *ctx);
void render_sheet(struct gui_sheet *sheet);
void render_delta(struct gui_ctx *ctx);
void render_setup(struct gui_ctx *ctx);
/* glabel.c */
void dehover_glabel(struct gui_ctx *ctx);
@ -117,17 +124,14 @@ void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet);
void do_revision_overlays(struct gui_ctx *ctx);
void sheet_setup(struct gui_ctx *ctx);
/* history */
/* history.c */
void show_history(struct gui_ctx *ctx, enum selecting sel);
/* gui.c */
void redraw(const struct gui_ctx *ctx);
struct gui_sheet *find_corresponding_sheet(struct gui_sheet *pick_from,
struct gui_sheet *ref_in, const struct gui_sheet *ref);
void render_sheet(struct gui_sheet *sheet);
void render_delta(struct gui_ctx *ctx);
void mark_aois(struct gui_ctx *ctx, struct gui_sheet *sheet);
#endif /* !GUI_COMMON_H */

View File

@ -22,20 +22,15 @@
#include <stdlib.h>
#include <string.h>
#include <cairo/cairo.h>
#include <gtk/gtk.h>
#include "misc/util.h"
#include "misc/diag.h"
#include "gfx/cro.h"
#include "gfx/gfx.h"
#include "file/git-hist.h"
#include "kicad/lib.h"
#include "kicad/sch.h"
#include "kicad/delta.h"
#include "gfx/diff.h"
#include "gui/aoi.h"
#include "gui/over.h"
#include "gui/input.h"
#include "gui/common.h"
#include "gui/gui.h"
@ -44,12 +39,6 @@
/* ----- Helper functions -------------------------------------------------- */
void redraw(const struct gui_ctx *ctx)
{
gtk_widget_queue_draw(ctx->da);
}
struct gui_sheet *find_corresponding_sheet(struct gui_sheet *pick_from,
struct gui_sheet *ref_in, const struct gui_sheet *ref)
{
@ -78,117 +67,6 @@ struct gui_sheet *find_corresponding_sheet(struct gui_sheet *pick_from,
}
/* ----- Rendering --------------------------------------------------------- */
#define VCS_OVERLAYS_X 5
#define VCS_OVERLAYS_Y 5
#define SHEET_OVERLAYS_X -10
#define SHEET_OVERLAYS_Y 10
static void hack(const struct gui_ctx *ctx, cairo_t *cr)
{
const struct gui_sheet *new = ctx->curr_sheet;
const struct gui_sheet *old = find_corresponding_sheet(
ctx->old_hist->sheets, ctx->new_hist->sheets, ctx->curr_sheet);
diff_to_canvas(cr, ctx->x, ctx->y, 1.0 / (1 << ctx->zoom),
old->gfx_ctx, new->gfx_ctx);
}
static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
gpointer user_data)
{
const struct gui_ctx *ctx = user_data;
const struct gui_sheet *sheet = ctx->curr_sheet;
GtkAllocation alloc;
float f = 1.0 / (1 << ctx->zoom);
int x, y;
gtk_widget_get_allocation(ctx->da, &alloc);
x = -(sheet->xmin + ctx->x) * f + alloc.width / 2;
y = -(sheet->ymin + ctx->y) * f + alloc.height / 2;
cro_canvas_prepare(cr);
if (!ctx->old_hist) {
cro_canvas_draw(sheet->gfx_ctx, cr, x, y, f);
} else {
#if 0
/* @@@ 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);
#endif
hack(ctx, cr);
}
overlay_draw_all(ctx->sheet_overlays, cr,
SHEET_OVERLAYS_X, SHEET_OVERLAYS_Y);
overlay_draw_all_d(ctx->hist_overlays, cr,
VCS_OVERLAYS_X,
VCS_OVERLAYS_Y + (ctx->showing_history ? ctx->hist_y_offset : 0),
0, 1);
overlay_draw_all(ctx->pop_overlays, cr, ctx->pop_x, ctx->pop_y);
return FALSE;
}
void render_sheet(struct gui_sheet *sheet)
{
char *argv[] = { "gui", NULL };
gfx_init(&cro_canvas_ops, 1, argv);
sch_render(sheet->sch);
cro_canvas_end(gfx_ctx,
&sheet->w, &sheet->h, &sheet->xmin, &sheet->ymin);
sheet->gfx_ctx = gfx_ctx;
sheet->rendered = 1;
// gfx_end();
}
void render_delta(struct gui_ctx *ctx)
{
#if 0
/* @@@ needs updating for curr/last vs. new/old */
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
#endif
struct gui_sheet *b = find_corresponding_sheet(
ctx->old_hist->sheets, ctx->new_hist->sheets, ctx->curr_sheet);
if (!b->rendered) {
render_sheet(b);
mark_aois(ctx, b);
}
}
/* ----- AoIs -------------------------------------------------------------- */
@ -526,13 +404,11 @@ int gui(unsigned n_args, char **args, bool recurse, int limit)
if (!ctx.new_hist)
fatal("no valid sheets\n");
g_signal_connect(G_OBJECT(ctx.da), "draw",
G_CALLBACK(on_draw_event), &ctx);
g_signal_connect(window, "destroy",
G_CALLBACK(gtk_main_quit), NULL);
sheet_setup(&ctx);
render_setup(&ctx);
// gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

154
eeshow/gui/render.c Normal file
View File

@ -0,0 +1,154 @@
/*
* gui/render.c - Render schematics and GUI elements
*
* 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.
*/
#include <stddef.h>
#include <stdbool.h>
#include <cairo/cairo.h>
#include <gtk/gtk.h>
#include "misc/util.h"
#include "gfx/cro.h"
#include "gfx/gfx.h"
#include "kicad/sch.h"
#include "kicad/delta.h"
#include "gfx/diff.h"
#include "gui/aoi.h"
#include "gui/over.h"
#include "gui/common.h"
#define VCS_OVERLAYS_X 5
#define VCS_OVERLAYS_Y 5
#define SHEET_OVERLAYS_X -10
#define SHEET_OVERLAYS_Y 10
/* ----- Helper functions -------------------------------------------------- */
void redraw(const struct gui_ctx *ctx)
{
gtk_widget_queue_draw(ctx->da);
}
/* ----- Rendering --------------------------------------------------------- */
static void hack(const struct gui_ctx *ctx, cairo_t *cr)
{
const struct gui_sheet *new = ctx->curr_sheet;
const struct gui_sheet *old = find_corresponding_sheet(
ctx->old_hist->sheets, ctx->new_hist->sheets, ctx->curr_sheet);
diff_to_canvas(cr, ctx->x, ctx->y, 1.0 / (1 << ctx->zoom),
old->gfx_ctx, new->gfx_ctx);
}
static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
gpointer user_data)
{
const struct gui_ctx *ctx = user_data;
const struct gui_sheet *sheet = ctx->curr_sheet;
GtkAllocation alloc;
float f = 1.0 / (1 << ctx->zoom);
int x, y;
gtk_widget_get_allocation(ctx->da, &alloc);
x = -(sheet->xmin + ctx->x) * f + alloc.width / 2;
y = -(sheet->ymin + ctx->y) * f + alloc.height / 2;
cro_canvas_prepare(cr);
if (!ctx->old_hist) {
cro_canvas_draw(sheet->gfx_ctx, cr, x, y, f);
} else {
#if 0
/* @@@ 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);
#endif
hack(ctx, cr);
}
overlay_draw_all(ctx->sheet_overlays, cr,
SHEET_OVERLAYS_X, SHEET_OVERLAYS_Y);
overlay_draw_all_d(ctx->hist_overlays, cr,
VCS_OVERLAYS_X,
VCS_OVERLAYS_Y + (ctx->showing_history ? ctx->hist_y_offset : 0),
0, 1);
overlay_draw_all(ctx->pop_overlays, cr, ctx->pop_x, ctx->pop_y);
return FALSE;
}
void render_sheet(struct gui_sheet *sheet)
{
char *argv[] = { "gui", NULL };
gfx_init(&cro_canvas_ops, 1, argv);
sch_render(sheet->sch);
cro_canvas_end(gfx_ctx,
&sheet->w, &sheet->h, &sheet->xmin, &sheet->ymin);
sheet->gfx_ctx = gfx_ctx;
sheet->rendered = 1;
// gfx_end();
}
void render_delta(struct gui_ctx *ctx)
{
#if 0
/* @@@ needs updating for curr/last vs. new/old */
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
#endif
struct gui_sheet *b = find_corresponding_sheet(
ctx->old_hist->sheets, ctx->new_hist->sheets, ctx->curr_sheet);
if (!b->rendered) {
render_sheet(b);
mark_aois(ctx, b);
}
}
void render_setup(struct gui_ctx *ctx)
{
g_signal_connect(G_OBJECT(ctx->da), "draw",
G_CALLBACK(on_draw_event), ctx);
}