summaryrefslogtreecommitdiff
path: root/gui/pop.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-10-15 14:40:16 -0300
committerWerner Almesberger <werner@almesberger.net>2016-10-15 14:40:16 -0300
commitafce03404dae49c4e3cac63f0a6096a95c9d97d0 (patch)
tree0beb7facc2eedd108b5fb82e59bf40fc4568e1b2 /gui/pop.c
parentbe0bd33447caa04c8079ab8d6f048264cc081105 (diff)
downloadeeshow-afce03404dae49c4e3cac63f0a6096a95c9d97d0.tar.gz
eeshow-afce03404dae49c4e3cac63f0a6096a95c9d97d0.tar.bz2
eeshow-afce03404dae49c4e3cac63f0a6096a95c9d97d0.zip
gui/pop.c: also migrate placement in bounding box calculation
Diffstat (limited to 'gui/pop.c')
-rw-r--r--gui/pop.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/gui/pop.c b/gui/pop.c
index a1445a2..10f319f 100644
--- a/gui/pop.c
+++ b/gui/pop.c
@@ -21,6 +21,10 @@
#include "gui/pop.h"
+/* small offset to hide rounding errors */
+#define CHEAT 1
+
+
void eeschema_coord(const struct gui *gui, int x, int y, int *rx, int *ry)
{
GtkAllocation alloc;
@@ -149,3 +153,36 @@ void add_pop_frame(struct gui *gui)
*/
overlay_set_related_all(gui->pop_overlays, over);
}
+
+
+void place_pop(struct gui *gui, const struct dwg_bbox *bbox)
+{
+ const struct gui_sheet *curr_sheet = gui->curr_sheet;
+ GtkAllocation alloc;
+ int sx, sy, ex, ey, mx, my;
+
+ eeschema_coord(gui,
+ bbox->x - curr_sheet->xmin, bbox->y - curr_sheet->ymin,
+ &sx, &sy);
+ eeschema_coord(gui, bbox->x + bbox->w - curr_sheet->xmin,
+ bbox->y + bbox->h - curr_sheet->ymin, &ex, &ey);
+
+ gtk_widget_get_allocation(gui->da, &alloc);
+ mx = (sx + ex) / 2;
+ my = (sy + ey) / 2;
+ if (mx < alloc.width / 2) {
+ gui->pop_x = sx - CHEAT;
+ gui->pop_dx = 1;
+ } else {
+ gui->pop_x = ex + CHEAT;
+ gui->pop_dx = -1;
+ }
+ if (my < alloc.height / 2) {
+ gui->pop_y = sy - CHEAT;
+ gui->pop_dy = 1;
+ } else {
+ gui->pop_y = ey + CHEAT;
+ gui->pop_dy = -1;
+ }
+
+}