summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-10-15 17:40:16 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-10-15 17:40:16 (GMT)
commitafce03404dae49c4e3cac63f0a6096a95c9d97d0 (patch)
tree0beb7facc2eedd108b5fb82e59bf40fc4568e1b2
parentbe0bd33447caa04c8079ab8d6f048264cc081105 (diff)
downloadeeshow-afce03404dae49c4e3cac63f0a6096a95c9d97d0.zip
eeshow-afce03404dae49c4e3cac63f0a6096a95c9d97d0.tar.gz
eeshow-afce03404dae49c4e3cac63f0a6096a95c9d97d0.tar.bz2
gui/pop.c: also migrate placement in bounding box calculation
-rw-r--r--gui/glabel.c32
-rw-r--r--gui/pop.c37
-rw-r--r--gui/pop.h1
3 files changed, 39 insertions, 31 deletions
diff --git a/gui/glabel.c b/gui/glabel.c
index 6e69fdb..cb6fce8 100644
--- a/gui/glabel.c
+++ b/gui/glabel.c
@@ -26,10 +26,6 @@
#include "gui/common.h"
-/* small offset to hide rounding errors */
-#define CHEAT 1
-
-
struct glabel_aoi_ctx {
const struct gui_sheet *sheet;
const struct sch_obj *obj;
@@ -74,8 +70,6 @@ static bool hover_glabel(void *user, bool on, int dx, int dy)
{
struct glabel_aoi_ctx *aoi_ctx = user;
struct gui *gui = aoi_ctx->sheet->gui;
- const struct gui_sheet *curr_sheet = gui->curr_sheet;
- const struct dwg_bbox *bbox = &aoi_ctx->bbox;
if (!on) {
dehover_pop(gui);
@@ -87,8 +81,6 @@ static bool hover_glabel(void *user, bool on, int dx, int dy)
dehover_pop(gui);
}
- GtkAllocation alloc;
- int sx, sy, ex, ey, mx, my;
unsigned n = 0;
struct gui_sheet *sheet;
@@ -104,29 +96,7 @@ static bool hover_glabel(void *user, bool on, int dx, int dy)
add_dest_overlay(gui, aoi_ctx->obj->u.text.s, sheet, ++n);
add_pop_frame(gui);
- 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;
- }
+ place_pop(gui, &aoi_ctx->bbox);
/*
* @@@ The idea is to get input to trigger hovering over the pop-up.
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;
+ }
+
+}
diff --git a/gui/pop.h b/gui/pop.h
index 96fa2a6..d4a0c0a 100644
--- a/gui/pop.h
+++ b/gui/pop.h
@@ -23,5 +23,6 @@ void add_pop_header(struct gui *gui, unsigned width, const char *label);
void add_pop_item(struct gui *gui, void (*click)(void *user), void *user,
unsigned width, bool dim, const char *fmt, ...);
void add_pop_frame(struct gui *gui);
+void place_pop(struct gui *gui, const struct dwg_bbox *bbox);
#endif /* !GUI_POP_H */