mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-16 21:32:27 +02:00
eeshow/gui/: change zoom system to use float; reduce step from 2 to 2^(1/3)
This commit is contained in:
parent
a1106b0985
commit
0550b016ee
@ -65,7 +65,7 @@ struct gui_hist {
|
|||||||
struct gui_ctx {
|
struct gui_ctx {
|
||||||
GtkWidget *da;
|
GtkWidget *da;
|
||||||
|
|
||||||
unsigned zoom; /* scale by 1.0 / (1 << zoom) */
|
float scale; /* pixels = eeschema * scale */
|
||||||
int x, y; /* center, in eeschema coordinates */
|
int x, y; /* center, in eeschema coordinates */
|
||||||
|
|
||||||
struct pl_ctx *pl; // @@@
|
struct pl_ctx *pl; // @@@
|
||||||
|
@ -49,8 +49,8 @@ static void eeschema_coord(const struct gui_ctx *ctx,
|
|||||||
GtkAllocation alloc;
|
GtkAllocation alloc;
|
||||||
|
|
||||||
gtk_widget_get_allocation(ctx->da, &alloc);
|
gtk_widget_get_allocation(ctx->da, &alloc);
|
||||||
*rx = ((x - ctx->x) >> ctx->zoom) + alloc.width / 2;
|
*rx = ((x - ctx->x) * ctx->scale) + alloc.width / 2;
|
||||||
*ry = ((y - ctx->y) >> ctx->zoom) + alloc.height / 2;
|
*ry = ((y - ctx->y) * ctx->scale) + alloc.height / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ int gui(unsigned n_args, char **args, bool recurse, int limit,
|
|||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
char *title;
|
char *title;
|
||||||
struct gui_ctx ctx = {
|
struct gui_ctx ctx = {
|
||||||
.zoom = 4, /* scale by 1 / 16 */
|
.scale = 1 / 16.0,
|
||||||
.pl = pl, // @@@
|
.pl = pl, // @@@
|
||||||
.hist = NULL,
|
.hist = NULL,
|
||||||
.vcs_hist = NULL,
|
.vcs_hist = NULL,
|
||||||
|
@ -158,7 +158,7 @@ static void hack(const struct gui_ctx *ctx, cairo_t *cr,
|
|||||||
struct area *areas = NULL;
|
struct area *areas = NULL;
|
||||||
|
|
||||||
areas = changed_sheets(ctx, xo, yo, f);
|
areas = changed_sheets(ctx, xo, yo, f);
|
||||||
diff_to_canvas(cr, ctx->x, ctx->y, 1.0 / (1 << ctx->zoom),
|
diff_to_canvas(cr, ctx->x, ctx->y, ctx->scale,
|
||||||
old->gfx_ctx, new->gfx_ctx, areas);
|
old->gfx_ctx, new->gfx_ctx, areas);
|
||||||
free_areas(&areas);
|
free_areas(&areas);
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
|
|||||||
const struct gui_ctx *ctx = user_data;
|
const struct gui_ctx *ctx = user_data;
|
||||||
const struct gui_sheet *sheet = ctx->curr_sheet;
|
const struct gui_sheet *sheet = ctx->curr_sheet;
|
||||||
GtkAllocation alloc;
|
GtkAllocation alloc;
|
||||||
float f = 1.0 / (1 << ctx->zoom);
|
float f = ctx->scale;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
gtk_widget_get_allocation(ctx->da, &alloc);
|
gtk_widget_get_allocation(ctx->da, &alloc);
|
||||||
|
@ -29,6 +29,12 @@
|
|||||||
#include "gui/common.h"
|
#include "gui/common.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define ZOOM_FACTOR 1.26 /* 2^(1/3) */
|
||||||
|
#define ZOOM_MAX 1
|
||||||
|
#define ZOOM_MIN_SIZE 16
|
||||||
|
#define ZOOM_MARGIN 0.95
|
||||||
|
|
||||||
|
|
||||||
/* ----- Tools ------------------------------------------------------------- */
|
/* ----- Tools ------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
@ -41,8 +47,8 @@ static void canvas_coord(const struct gui_ctx *ctx,
|
|||||||
gtk_widget_get_allocation(ctx->da, &alloc);
|
gtk_widget_get_allocation(ctx->da, &alloc);
|
||||||
sx = ex - alloc.width / 2;
|
sx = ex - alloc.width / 2;
|
||||||
sy = ey - alloc.height / 2;
|
sy = ey - alloc.height / 2;
|
||||||
*x = (sx << ctx->zoom) + ctx->x;
|
*x = sx / ctx->scale + ctx->x;
|
||||||
*y = (sy << ctx->zoom) + ctx->y;
|
*y = sy / ctx->scale + ctx->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -51,11 +57,15 @@ static void canvas_coord(const struct gui_ctx *ctx,
|
|||||||
|
|
||||||
static bool zoom_in(struct gui_ctx *ctx, int x, int y)
|
static bool zoom_in(struct gui_ctx *ctx, int x, int y)
|
||||||
{
|
{
|
||||||
if (ctx->zoom == 0)
|
float old = ctx->scale;
|
||||||
|
|
||||||
|
if (ctx->scale == ZOOM_MAX)
|
||||||
return 0;
|
return 0;
|
||||||
ctx->zoom--;
|
ctx->scale *= ZOOM_FACTOR;
|
||||||
ctx->x = (ctx->x + x) / 2;
|
if (ctx->scale > ZOOM_MAX)
|
||||||
ctx->y = (ctx->y + y) / 2;
|
ctx->scale = ZOOM_MAX;
|
||||||
|
ctx->x = x + (ctx->x - x) * old / ctx->scale;
|
||||||
|
ctx->y = y + (ctx->y - y) * old / ctx->scale;
|
||||||
redraw(ctx);
|
redraw(ctx);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -63,11 +73,17 @@ static bool zoom_in(struct gui_ctx *ctx, int x, int y)
|
|||||||
|
|
||||||
static bool zoom_out(struct gui_ctx *ctx, int x, int y)
|
static bool zoom_out(struct gui_ctx *ctx, int x, int y)
|
||||||
{
|
{
|
||||||
if (ctx->curr_sheet->w >> ctx->zoom <= 16)
|
float old = ctx->scale;
|
||||||
|
|
||||||
|
if (ctx->curr_sheet->w * ctx->scale <= ZOOM_MIN_SIZE)
|
||||||
return 0;
|
return 0;
|
||||||
ctx->zoom++;
|
ctx->scale /= ZOOM_FACTOR;
|
||||||
ctx->x = 2 * ctx->x - x;
|
if (ctx->curr_sheet->w <= ZOOM_MIN_SIZE)
|
||||||
ctx->y = 2 * ctx->y - y;
|
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);
|
redraw(ctx);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -106,15 +122,17 @@ static void zoom_to_extents(struct gui_ctx *ctx)
|
|||||||
{
|
{
|
||||||
GtkAllocation alloc;
|
GtkAllocation alloc;
|
||||||
int w, h;
|
int w, h;
|
||||||
|
float sw, sh;
|
||||||
|
|
||||||
curr_sheet_size(ctx, &w, &h);
|
curr_sheet_size(ctx, &w, &h);
|
||||||
ctx->x = w / 2;
|
ctx->x = w / 2;
|
||||||
ctx->y = h / 2;
|
ctx->y = h / 2;
|
||||||
|
|
||||||
gtk_widget_get_allocation(ctx->da, &alloc);
|
gtk_widget_get_allocation(ctx->da, &alloc);
|
||||||
ctx->zoom = 0;
|
|
||||||
while (w >> ctx->zoom > alloc.width || h >> ctx->zoom > alloc.height)
|
sw = w ? (float) ZOOM_MARGIN * alloc.width / w : 1;
|
||||||
ctx->zoom++;
|
sh = h ? (float) ZOOM_MARGIN * alloc.height / h : 1;
|
||||||
|
ctx->scale = sw < sh ? sw : sh;
|
||||||
|
|
||||||
redraw(ctx);
|
redraw(ctx);
|
||||||
}
|
}
|
||||||
@ -439,8 +457,8 @@ static void sheet_drag_move(void *user, int dx, int dy)
|
|||||||
{
|
{
|
||||||
struct gui_ctx *ctx = user;
|
struct gui_ctx *ctx = user;
|
||||||
|
|
||||||
ctx->x -= dx << ctx->zoom;
|
ctx->x -= dx / ctx->scale;
|
||||||
ctx->y -= dy << ctx->zoom;
|
ctx->y -= dy / ctx->scale;
|
||||||
redraw(ctx);
|
redraw(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user