mirror of
git://projects.qi-hardware.com/fped.git
synced 2024-11-22 08:24:06 +02:00
track bounding box also on a per-package basis and use this to scale Postscript
Until now, everything used the bounding box of the root frame which contains all the packages, visible or not. We now also record what ends up in which package, allowing inst_get_bbox to return the bounding box of a specific package. This is mainly useful for scaling Postscript output where only one package is printed per sheet and there is not much point in reserving space for any other packages that may be generated from the same footprint definition.
This commit is contained in:
parent
e2ce0eecf7
commit
86c082f5a9
8
gui.c
8
gui.c
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* gui.c - Editor GUI core
|
* gui.c - Editor GUI core
|
||||||
*
|
*
|
||||||
* Written 2009-2011 by Werner Almesberger
|
* Written 2009-2012 by Werner Almesberger
|
||||||
* Copyright 2009-2011 by Werner Almesberger
|
* Copyright 2009-2012 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -326,7 +326,7 @@ void change_world(void)
|
|||||||
|
|
||||||
inst_deselect();
|
inst_deselect();
|
||||||
status_begin_reporting();
|
status_begin_reporting();
|
||||||
before = inst_get_bbox();
|
before = inst_get_bbox(NULL);
|
||||||
reachable_is_active = reachable_pkg && reachable_pkg == active_pkg;
|
reachable_is_active = reachable_pkg && reachable_pkg == active_pkg;
|
||||||
instantiate();
|
instantiate();
|
||||||
if (reachable_is_active && reachable_pkg &&
|
if (reachable_is_active && reachable_pkg &&
|
||||||
@ -334,7 +334,7 @@ void change_world(void)
|
|||||||
active_pkg = reachable_pkg;
|
active_pkg = reachable_pkg;
|
||||||
instantiate();
|
instantiate();
|
||||||
}
|
}
|
||||||
after = inst_get_bbox();
|
after = inst_get_bbox(NULL);
|
||||||
label_in_box_bg(active_frame->label, COLOR_FRAME_SELECTED);
|
label_in_box_bg(active_frame->label, COLOR_FRAME_SELECTED);
|
||||||
do_build_frames();
|
do_build_frames();
|
||||||
if (after.min.x < before.min.x || after.min.y < before.min.y ||
|
if (after.min.x < before.min.x || after.min.y < before.min.y ||
|
||||||
|
10
gui_canvas.c
10
gui_canvas.c
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* gui_canvas.c - GUI, canvas
|
* gui_canvas.c - GUI, canvas
|
||||||
*
|
*
|
||||||
* Written 2009, 2010 by Werner Almesberger
|
* Written 2009, 2010, 2012 by Werner Almesberger
|
||||||
* Copyright 2009, 2010 by Werner Almesberger
|
* Copyright 2009, 2010, 2012 by Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -94,7 +94,7 @@ static void center(const struct bbox *this_bbox)
|
|||||||
{
|
{
|
||||||
struct bbox bbox;
|
struct bbox bbox;
|
||||||
|
|
||||||
bbox = this_bbox ? *this_bbox : inst_get_bbox();
|
bbox = this_bbox ? *this_bbox : inst_get_bbox(NULL);
|
||||||
draw_ctx.center.x = (bbox.min.x+bbox.max.x)/2;
|
draw_ctx.center.x = (bbox.min.x+bbox.max.x)/2;
|
||||||
draw_ctx.center.y = (bbox.min.y+bbox.max.y)/2;
|
draw_ctx.center.y = (bbox.min.y+bbox.max.y)/2;
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ static void auto_scale(const struct bbox *this_bbox)
|
|||||||
int sx, sy;
|
int sx, sy;
|
||||||
float aw, ah;
|
float aw, ah;
|
||||||
|
|
||||||
bbox = this_bbox ? *this_bbox : inst_get_bbox();
|
bbox = this_bbox ? *this_bbox : inst_get_bbox(NULL);
|
||||||
aw = draw_ctx.widget->allocation.width;
|
aw = draw_ctx.widget->allocation.width;
|
||||||
ah = draw_ctx.widget->allocation.height;
|
ah = draw_ctx.widget->allocation.height;
|
||||||
h = bbox.max.x-bbox.min.x;
|
h = bbox.max.x-bbox.min.x;
|
||||||
@ -332,7 +332,7 @@ static void zoom_out(struct coord pos)
|
|||||||
{
|
{
|
||||||
struct bbox bbox;
|
struct bbox bbox;
|
||||||
|
|
||||||
bbox = inst_get_bbox();
|
bbox = inst_get_bbox(NULL);
|
||||||
bbox.min = translate(bbox.min);
|
bbox.min = translate(bbox.min);
|
||||||
bbox.max = translate(bbox.max);
|
bbox.max = translate(bbox.max);
|
||||||
if (bbox.min.x >= ZOOM_STOP_BORDER &&
|
if (bbox.min.x >= ZOOM_STOP_BORDER &&
|
||||||
|
13
inst.c
13
inst.c
@ -581,6 +581,14 @@ static void propagate_bbox(const struct inst *inst)
|
|||||||
|
|
||||||
update_bbox(&frame->bbox, inst->bbox.min);
|
update_bbox(&frame->bbox, inst->bbox.min);
|
||||||
update_bbox(&frame->bbox, inst->bbox.max);
|
update_bbox(&frame->bbox, inst->bbox.max);
|
||||||
|
|
||||||
|
if (curr_pkg->bbox.min.x || curr_pkg->bbox.min.y ||
|
||||||
|
curr_pkg->bbox.max.x || curr_pkg->bbox.max.y) {
|
||||||
|
update_bbox(&curr_pkg->bbox, inst->bbox.min);
|
||||||
|
update_bbox(&curr_pkg->bbox, inst->bbox.max);
|
||||||
|
} else {
|
||||||
|
curr_pkg->bbox = inst->bbox;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1225,8 +1233,11 @@ void inst_select_pkg(const char *name, int active)
|
|||||||
/* ----- misc. ------------------------------------------------------------- */
|
/* ----- misc. ------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
struct bbox inst_get_bbox(void)
|
struct bbox inst_get_bbox(const struct pkg *pkg)
|
||||||
{
|
{
|
||||||
|
if (pkg)
|
||||||
|
return pkg->bbox;
|
||||||
|
else
|
||||||
return pkgs->insts[ip_frame]->bbox;
|
return pkgs->insts[ip_frame]->bbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
inst.h
3
inst.h
@ -124,6 +124,7 @@ struct pkg {
|
|||||||
const char *name; /* NULL if global package */
|
const char *name; /* NULL if global package */
|
||||||
struct inst *insts[ip_n];
|
struct inst *insts[ip_n];
|
||||||
struct inst **next_inst[ip_n];
|
struct inst **next_inst[ip_n];
|
||||||
|
struct bbox bbox; /* bbox only of items in this package */
|
||||||
struct sample **samples;
|
struct sample **samples;
|
||||||
int n_samples;
|
int n_samples;
|
||||||
struct pkg *next;
|
struct pkg *next;
|
||||||
@ -198,7 +199,7 @@ void inst_end_frame(const struct frame *frame);
|
|||||||
|
|
||||||
void inst_select_pkg(const char *name, int active);
|
void inst_select_pkg(const char *name, int active);
|
||||||
|
|
||||||
struct bbox inst_get_bbox(void);
|
struct bbox inst_get_bbox(const struct pkg *pkg);
|
||||||
|
|
||||||
void inst_start(void);
|
void inst_start(void);
|
||||||
void inst_commit(void);
|
void inst_commit(void);
|
||||||
|
@ -809,7 +809,7 @@ static void ps_package(FILE *file, const struct pkg *pkg, int page)
|
|||||||
x = 2*PAGE_HALF_WIDTH-2*PS_DIVIDER_BORDER;
|
x = 2*PAGE_HALF_WIDTH-2*PS_DIVIDER_BORDER;
|
||||||
y = PAGE_HALF_HEIGHT-PS_HEADER_HEIGHT-3*PS_DIVIDER_BORDER;
|
y = PAGE_HALF_HEIGHT-PS_HEADER_HEIGHT-3*PS_DIVIDER_BORDER;
|
||||||
|
|
||||||
bbox = inst_get_bbox();
|
bbox = inst_get_bbox(pkg);
|
||||||
w = 2*(-bbox.min.x > bbox.max.x ? -bbox.min.x : bbox.max.x);
|
w = 2*(-bbox.min.x > bbox.max.x ? -bbox.min.x : bbox.max.x);
|
||||||
h = 2*(-bbox.min.y > bbox.max.y ? -bbox.min.y : bbox.max.y);
|
h = 2*(-bbox.min.y > bbox.max.y ? -bbox.min.y : bbox.max.y);
|
||||||
|
|
||||||
@ -1132,7 +1132,7 @@ static void ps_package_fullpage(FILE *file, const struct pkg *pkg, int page)
|
|||||||
|
|
||||||
ps_page(file, page, pkg);
|
ps_page(file, page, pkg);
|
||||||
active_params = postscript_params;
|
active_params = postscript_params;
|
||||||
bbox = inst_get_bbox();
|
bbox = inst_get_bbox(pkg);
|
||||||
cx = (bbox.min.x+bbox.max.x)/2;
|
cx = (bbox.min.x+bbox.max.x)/2;
|
||||||
cy = (bbox.min.y+bbox.max.y)/2;
|
cy = (bbox.min.y+bbox.max.y)/2;
|
||||||
if (active_params.zoom) {
|
if (active_params.zoom) {
|
||||||
|
Loading…
Reference in New Issue
Block a user