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-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-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-03 13:38:57 +03:00
|
|
|
#include "cro.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "sch.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;
|
|
|
|
|
|
|
|
struct aoi {
|
|
|
|
int x, y, w, h; /* activation box, eeschema coordinates */
|
|
|
|
|
|
|
|
bool (*hover)(struct gui_ctx *ctx, void *user, bool on);
|
|
|
|
void (*click)(struct gui_ctx *ctx, void *user);
|
|
|
|
void *user;
|
|
|
|
|
|
|
|
struct aoi *next;
|
|
|
|
};
|
|
|
|
|
2016-08-03 16:52:55 +03:00
|
|
|
struct gui_sheet {
|
|
|
|
const const struct sheet *sch;
|
2016-08-03 13:38:57 +03:00
|
|
|
struct cro_ctx *gfx_ctx;
|
2016-08-03 16:52:55 +03:00
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
int w, h;
|
|
|
|
int xmin, ymin;
|
|
|
|
|
2016-08-03 18:26:22 +03:00
|
|
|
struct aoi *aois; /* areas of interest */
|
|
|
|
|
2016-08-03 18:34:33 +03:00
|
|
|
struct gui_sheet *prev; /* previous in stack */
|
|
|
|
|
2016-08-03 16:52:55 +03:00
|
|
|
struct gui_sheet *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
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-03 18:26:22 +03:00
|
|
|
const struct aoi *aoi_hovering; /* hovering over this aoi */
|
|
|
|
|
2016-08-04 01:18:50 +03:00
|
|
|
struct overlay *overlays;
|
|
|
|
|
2016-08-03 18:34:33 +03:00
|
|
|
struct gui_sheet *curr_sheet;
|
2016-08-03 16:52:55 +03:00
|
|
|
/* current sheet */
|
|
|
|
struct gui_sheet *sheets;
|
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-03 18:26:22 +03:00
|
|
|
/* ----- Area of intereest ------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void aoi_add(struct gui_sheet *sheet, const struct aoi *aoi)
|
|
|
|
{
|
|
|
|
struct aoi *new;
|
|
|
|
|
|
|
|
new = alloc_type(struct aoi);
|
|
|
|
*new = *aoi;
|
|
|
|
new->next = sheet->aois;
|
|
|
|
sheet->aois = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void aoi_hover(struct gui_ctx *ctx, int x, int y)
|
|
|
|
{
|
|
|
|
const struct gui_sheet *sheet = ctx->curr_sheet;
|
|
|
|
const struct aoi *aoi = ctx->aoi_hovering;
|
|
|
|
|
|
|
|
if (aoi) {
|
|
|
|
if (x >= aoi->x && x < aoi->x + aoi->w &&
|
|
|
|
y >= aoi->y && y < aoi->y + aoi->h)
|
|
|
|
return;
|
|
|
|
aoi->hover(ctx, aoi->user, 0);
|
|
|
|
ctx->aoi_hovering = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (aoi = sheet->aois; aoi; aoi = aoi->next)
|
|
|
|
if (x >= aoi->x && x < aoi->x + aoi->w &&
|
|
|
|
y >= aoi->y && y < aoi->y + aoi->h)
|
|
|
|
break;
|
|
|
|
if (aoi && aoi->hover && aoi->hover(ctx, aoi->user, 1))
|
|
|
|
ctx->aoi_hovering = aoi;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void aoi_click(struct gui_ctx *ctx, int x, int y)
|
|
|
|
{
|
|
|
|
const struct gui_sheet *sheet = ctx->curr_sheet;
|
|
|
|
const struct aoi *aoi = ctx->aoi_hovering;
|
|
|
|
|
|
|
|
x += sheet->xmin;
|
|
|
|
y += sheet->ymin;
|
|
|
|
|
|
|
|
if (aoi) {
|
|
|
|
aoi->hover(ctx, aoi->user, 0);
|
|
|
|
ctx->aoi_hovering = NULL;
|
|
|
|
}
|
|
|
|
for (aoi = sheet->aois; aoi; aoi = aoi->next)
|
|
|
|
if (x >= aoi->x && x < aoi->x + aoi->w &&
|
|
|
|
y >= aoi->y && y < aoi->y + aoi->h)
|
|
|
|
break;
|
|
|
|
if (aoi && aoi->click)
|
|
|
|
aoi->click(ctx, aoi->user);
|
|
|
|
}
|
2016-08-03 13:38:57 +03:00
|
|
|
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
/* ----- Rendering --------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
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;
|
2016-08-03 13:38:57 +03:00
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
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;
|
|
|
|
cro_canvas_draw(sheet->gfx_ctx, cr, x, y, f);
|
2016-08-03 13:38:57 +03:00
|
|
|
|
2016-08-04 02:55:51 +03:00
|
|
|
overlay_draw_all(ctx->overlays, cr);
|
2016-08-04 01:18:50 +03:00
|
|
|
|
2016-08-03 13:38:57 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 16:52:55 +03:00
|
|
|
static void render(struct gui_ctx *ctx, 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-03 15:33:16 +03:00
|
|
|
|
2016-08-03 16:52:55 +03:00
|
|
|
ctx->x = sheet->w >> 1;
|
|
|
|
ctx->y = sheet->h >> 1;
|
2016-08-03 13:38:57 +03:00
|
|
|
// gfx_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- 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;
|
|
|
|
|
|
|
|
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-03 19:05:30 +03:00
|
|
|
static void zoom_to_extents(struct gui_ctx *ctx)
|
|
|
|
{
|
|
|
|
const struct gui_sheet *sheet = ctx->curr_sheet;
|
|
|
|
GtkAllocation alloc;
|
|
|
|
|
|
|
|
ctx->x = sheet->w / 2;
|
|
|
|
ctx->y = sheet->h / 2;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation(ctx->da, &alloc);
|
|
|
|
ctx->zoom = 0;
|
|
|
|
while (sheet->w >> ctx->zoom > alloc.width ||
|
|
|
|
sheet->h >> ctx->zoom > alloc.height)
|
|
|
|
ctx->zoom++;
|
|
|
|
|
2016-08-04 00:49:16 +03:00
|
|
|
redraw(ctx);
|
2016-08-03 19:05:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
|
|
|
aoi_hover(ctx, x, y);
|
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;
|
|
|
|
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 18:26:22 +03:00
|
|
|
aoi_click(ctx, x, y);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-04 01:18:50 +03:00
|
|
|
static void set_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet)
|
|
|
|
{
|
|
|
|
if (sheet->prev == sheet)
|
|
|
|
sheet->prev = NULL;
|
|
|
|
ctx->curr_sheet = sheet;
|
2016-08-04 02:55:51 +03:00
|
|
|
overlay_remove_all(&ctx->overlays);
|
2016-08-04 01:18:50 +03:00
|
|
|
zoom_to_extents(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
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-04 01:18:50 +03:00
|
|
|
if (sheet != ctx->sheets)
|
|
|
|
set_sheet(ctx, ctx->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 01:18:50 +03:00
|
|
|
if (sheet->prev)
|
|
|
|
set_sheet(ctx, sheet->prev);
|
2016-08-03 18:34:33 +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 ----------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void select_subsheet(struct gui_ctx *ctx, void *user)
|
|
|
|
{
|
|
|
|
const struct sch_obj *obj = user;
|
2016-08-03 18:34:33 +03:00
|
|
|
struct gui_sheet *sheet;
|
2016-08-03 18:26:22 +03:00
|
|
|
|
|
|
|
for (sheet = ctx->sheets; sheet; sheet = sheet->next)
|
|
|
|
if (sheet->sch == obj->u.sheet.sheet) {
|
2016-08-03 18:34:33 +03:00
|
|
|
sheet->prev = ctx->curr_sheet;
|
2016-08-04 01:18:50 +03:00
|
|
|
set_sheet(ctx, sheet);
|
2016-08-04 02:55:51 +03:00
|
|
|
overlay_add(&ctx->overlays, obj->u.sheet.name);
|
2016-08-03 18:26:22 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 15:33:16 +03:00
|
|
|
/* ----- Initialization ---------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2016-08-03 18:26:22 +03:00
|
|
|
static void mark_aois(struct gui_sheet *sheet)
|
|
|
|
{
|
|
|
|
const struct sch_obj *obj;
|
|
|
|
|
|
|
|
sheet->aois = NULL;
|
|
|
|
for (obj = sheet->sch->objs; obj; obj = obj->next)
|
|
|
|
switch (obj->type) {
|
|
|
|
case sch_obj_sheet: {
|
|
|
|
struct aoi aoi = {
|
|
|
|
.x = obj->x,
|
|
|
|
.y = obj->y,
|
|
|
|
.w = obj->u.sheet.w,
|
|
|
|
.h = obj->u.sheet.h,
|
|
|
|
.click = select_subsheet,
|
|
|
|
.user = (void *) obj,
|
|
|
|
};
|
|
|
|
|
|
|
|
aoi_add(sheet, &aoi);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void get_sheets(struct gui_ctx *ctx, const struct sheet *sheets)
|
2016-08-03 16:52:55 +03:00
|
|
|
{
|
|
|
|
const struct sheet *sheet;
|
|
|
|
struct gui_sheet **next = &ctx->sheets;
|
|
|
|
struct gui_sheet *gui_sheet;
|
|
|
|
|
|
|
|
for (sheet = sheets; sheet; sheet = sheet->next) {
|
|
|
|
gui_sheet = alloc_type(struct gui_sheet);
|
|
|
|
gui_sheet->sch = sheet;
|
2016-08-03 18:34:33 +03:00
|
|
|
gui_sheet->prev = NULL;
|
2016-08-03 18:26:22 +03:00
|
|
|
|
2016-08-03 18:34:33 +03:00
|
|
|
render(ctx, gui_sheet);
|
2016-08-03 18:26:22 +03:00
|
|
|
mark_aois(gui_sheet);
|
|
|
|
|
2016-08-03 16:52:55 +03:00
|
|
|
*next = gui_sheet;
|
|
|
|
next = &gui_sheet->next;
|
|
|
|
}
|
|
|
|
*next = NULL;
|
|
|
|
ctx->curr_sheet = ctx->sheets;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int gui(const struct sheet *sheets)
|
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-04 01:18:50 +03:00
|
|
|
.overlays = NULL,
|
2016-08-03 13:38:57 +03:00
|
|
|
};
|
|
|
|
|
2016-08-03 16:52:55 +03:00
|
|
|
get_sheets(&ctx, sheets);
|
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);
|
|
|
|
// gtk_window_set_default_size(GTK_WINDOW(window), 400, 90);
|
|
|
|
gtk_window_set_title(GTK_WINDOW(window), "eeshow");
|
2016-08-03 13:38:57 +03:00
|
|
|
|
|
|
|
gtk_widget_show_all(window);
|
2016-08-03 19:05:30 +03:00
|
|
|
zoom_to_extents(&ctx);
|
2016-08-03 13:38:57 +03:00
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|