summaryrefslogtreecommitdiff
path: root/gui/pop.c
diff options
context:
space:
mode:
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;
+ }
+
+}