summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-10-15 16:06:26 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-10-15 17:32:02 (GMT)
commitbe0bd33447caa04c8079ab8d6f048264cc081105 (patch)
tree399246c2891d2e21047999244811fd84e72b1d46 /gui
parent41ee777fb5d88b523636ec52ba04ffb0a843d06d (diff)
downloadeeshow-be0bd33447caa04c8079ab8d6f048264cc081105.zip
eeshow-be0bd33447caa04c8079ab8d6f048264cc081105.tar.gz
eeshow-be0bd33447caa04c8079ab8d6f048264cc081105.tar.bz2
gui/pop.c: separate general pop-up functions from glabel.c
... for upcoming sharing.
Diffstat (limited to 'gui')
-rw-r--r--gui/common.h3
-rw-r--r--gui/glabel.c128
-rw-r--r--gui/pop.c151
-rw-r--r--gui/pop.h27
-rw-r--r--gui/render.c4
-rw-r--r--gui/sheet.c7
6 files changed, 192 insertions, 128 deletions
diff --git a/gui/common.h b/gui/common.h
index 8727707..bd3fffd 100644
--- a/gui/common.h
+++ b/gui/common.h
@@ -138,7 +138,7 @@ struct gui {
#define VCS_OVERLAYS_X 5
#define VCS_OVERLAYS_Y 5
-#define GLABEL_STACK_PADDING 5
+#define POP_STACK_PADDING 5
/* progress.c */
@@ -159,7 +159,6 @@ void render_setup(struct gui *gui);
/* glabel.c */
-void dehover_glabel(struct gui *gui);
void add_glabel_aoi(struct gui_sheet *sheet, const struct sch_obj *obj);
/* sheet.c */
diff --git a/gui/glabel.c b/gui/glabel.c
index 6c748b8..6e69fdb 100644
--- a/gui/glabel.c
+++ b/gui/glabel.c
@@ -22,6 +22,7 @@
#include "gui/input.h"
#include "gui/aoi.h"
#include "gui/over.h"
+#include "gui/pop.h"
#include "gui/common.h"
@@ -40,20 +41,6 @@ struct glabel_aoi_ctx {
#define GLABEL_W 100
-/* ----- Tools ------------------------------------------------------------- */
-
-
-static void eeschema_coord(const struct gui *gui,
- int x, int y, int *rx, int *ry)
-{
- GtkAllocation alloc;
-
- gtk_widget_get_allocation(gui->da, &alloc);
- *rx = ((x - gui->x) * gui->scale) + alloc.width / 2;
- *ry = ((y - gui->y) * gui->scale) + alloc.height / 2;
-}
-
-
/* ----- AoIs -------------------------------------------------------------- */
@@ -65,125 +52,24 @@ static void glabel_dest_click(void *user)
}
-void dehover_glabel(struct gui *gui)
-{
- overlay_remove_all(&gui->pop_overlays);
- overlay_remove_all(&gui->pop_underlays);
- gui->pop_origin = NULL;
- redraw(gui);
-}
-
-
-static void add_dest_header(struct gui *gui, const char *label)
-{
- struct overlay_style style = {
- .font = BOLD_FONT,
- .wmin = GLABEL_W,
- .wmax = GLABEL_W,
- .radius = 0,
- .pad = 0,
- .skip = 6,
- .fg = { 0.5, 0.0, 0.0, 1.0 },
- .bg = { 0.0, 0.0, 0.0, 0.0 },
- .frame = { 1.0, 1.0, 1.0, 1.0 }, /* debugging */
- .width = 0,
- };
- struct overlay *over;
-
- over = overlay_add(&gui->pop_overlays, NULL, NULL, NULL, NULL);
- overlay_text(over, "%s", label);
- overlay_style(over, &style);
-}
-
-
static void add_dest_overlay(struct gui *gui, const char *label,
struct gui_sheet *sheet, unsigned n)
{
- struct overlay_style style = {
- .font = BOLD_FONT,
- .wmin = GLABEL_W,
- .wmax = GLABEL_W,
- .radius = 0,
- .pad = 0,
- .skip = 4,
- .fg = { 0.0, 0.0, 0.0, 1.0 },
- .bg = { 0.0, 0.0, 0.0, 0.0 },
- .frame = { 1.0, 1.0, 1.0, 1.0 }, /* debugging */
- .width = 0,
- };
const struct sch_obj *obj;
- struct overlay *over;
-
- if (sheet == gui->curr_sheet)
- style.fg = RGBA(0.5, 0.5, 0.5, 1.0);
for (obj = sheet->sch->objs; obj; obj = obj->next) {
if (obj->type != sch_obj_glabel)
continue;
if (strcmp(obj->u.text.s, label))
continue;
- over = overlay_add(&gui->pop_overlays,
- &gui->aois, NULL, glabel_dest_click, sheet);
- overlay_text(over, "%d %s", n,
+ add_pop_item(gui, glabel_dest_click, sheet, GLABEL_W,
+ sheet == gui->curr_sheet, "%d %s", n,
sheet->sch->title ? sheet->sch->title : "(unnamed)");
- overlay_style(over, &style);
break;
}
}
-static bool pop_hover(void *user, bool on, int dx, int dy)
-{
- struct gui *gui = user;
-
- if (!on)
- dehover_glabel(gui);
- return 1;
-}
-
-
-static void add_dest_frame(struct gui *gui)
-{
- int w, h;
-
- overlay_size_all(gui->pop_overlays,
- gtk_widget_get_pango_context(gui->da), 0, 1, &w, &h);
-
- struct overlay_style style = {
- .font = BOLD_FONT,
- .wmin = w,
- .hmin = h,
- .radius = 0,
- .pad = GLABEL_STACK_PADDING,
- .skip = 0,
- .fg = { 0.0, 0.0, 0.0, 1.0 },
- .bg = { 0.9, 0.9, 0.3, 0.8 },
- .frame = { 0.0, 0.0, 0.0, 1.0 }, /* debugging */
- .width = 1,
- };
- struct overlay *over;
-
- over = overlay_add(&gui->pop_underlays, &gui->aois,
- pop_hover, NULL, gui);
- overlay_text_raw(over, "");
- overlay_style(over, &style);
-
- /*
- * This makes it all work. When we receive a click while hovering, it
- * goes to the hovering overlay if that overlay accepts clicks.
- * However, if the overlay accepting the click is different, we first
- * de-hover.
- *
- * Now, in the case of the frame overlay, dehovering would destroy the
- * destination overlays right before trying to deliver the click.
- *
- * We solve this by declaring the frame overlay to be "related" to the
- * destination overlays. This suppresses dehovering.
- */
- overlay_set_related_all(gui->pop_overlays, over);
-}
-
-
static bool hover_glabel(void *user, bool on, int dx, int dy)
{
struct glabel_aoi_ctx *aoi_ctx = user;
@@ -192,13 +78,13 @@ static bool hover_glabel(void *user, bool on, int dx, int dy)
const struct dwg_bbox *bbox = &aoi_ctx->bbox;
if (!on) {
- dehover_glabel(gui);
+ dehover_pop(gui);
return 1;
}
if (gui->pop_underlays) {
if (gui->pop_origin == aoi_ctx)
return 0;
- dehover_glabel(gui);
+ dehover_pop(gui);
}
GtkAllocation alloc;
@@ -213,10 +99,10 @@ static bool hover_glabel(void *user, bool on, int dx, int dy)
overlay_remove_all(&gui->pop_overlays);
overlay_remove_all(&gui->pop_underlays);
- add_dest_header(gui, aoi_ctx->obj->u.text.s);
+ add_pop_header(gui, GLABEL_W, aoi_ctx->obj->u.text.s);
for (sheet = gui->new_hist->sheets; sheet; sheet = sheet->next)
add_dest_overlay(gui, aoi_ctx->obj->u.text.s, sheet, ++n);
- add_dest_frame(gui);
+ add_pop_frame(gui);
eeschema_coord(gui,
bbox->x - curr_sheet->xmin, bbox->y - curr_sheet->ymin,
diff --git a/gui/pop.c b/gui/pop.c
new file mode 100644
index 0000000..a1445a2
--- /dev/null
+++ b/gui/pop.c
@@ -0,0 +1,151 @@
+/*
+ * gui/pop.c - Pop-up helper functions
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <stddef.h>
+#include <stdarg.h>
+
+#include <gtk/gtk.h>
+
+#include "gui/style.h"
+#include "gui/over.h"
+#include "gui/common.h"
+#include "gui/pop.h"
+
+
+void eeschema_coord(const struct gui *gui, int x, int y, int *rx, int *ry)
+{
+ GtkAllocation alloc;
+
+ gtk_widget_get_allocation(gui->da, &alloc);
+ *rx = ((x - gui->x) * gui->scale) + alloc.width / 2;
+ *ry = ((y - gui->y) * gui->scale) + alloc.height / 2;
+}
+
+
+/* ----- Hovering ---------------------------------------------------------- */
+
+
+void dehover_pop(struct gui *gui)
+{
+ overlay_remove_all(&gui->pop_overlays);
+ overlay_remove_all(&gui->pop_underlays);
+ gui->pop_origin = NULL;
+ redraw(gui);
+}
+
+
+
+static bool pop_hover(void *user, bool on, int dx, int dy)
+{
+ struct gui *gui = user;
+
+ if (!on)
+ dehover_pop(gui);
+ return 1;
+}
+
+
+/* ----- Pop-up construction ----------------------------------------------- */
+
+
+
+void add_pop_header(struct gui *gui, unsigned width, const char *label)
+{
+ struct overlay_style style = {
+ .font = BOLD_FONT,
+ .wmin = width,
+ .wmax = width,
+ .radius = 0,
+ .pad = 0,
+ .skip = 6,
+ .fg = { 0.5, 0.0, 0.0, 1.0 },
+ .bg = { 0.0, 0.0, 0.0, 0.0 },
+ .frame = { 1.0, 1.0, 1.0, 1.0 }, /* debugging */
+ .width = 0,
+ };
+ struct overlay *over;
+
+ over = overlay_add(&gui->pop_overlays, NULL, NULL, NULL, NULL);
+ overlay_text(over, "%s", label);
+ overlay_style(over, &style);
+}
+
+
+void add_pop_item(struct gui *gui, void (*click)(void *user), void *user,
+ unsigned width, bool dim, const char *fmt, ...)
+{
+ struct overlay_style style = {
+ .font = BOLD_FONT,
+ .wmin = width,
+ .wmax = width,
+ .radius = 0,
+ .pad = 0,
+ .skip = 4,
+ .fg = { 0.0, 0.0, 0.0, 1.0 },
+ .bg = { 0.0, 0.0, 0.0, 0.0 },
+ .frame = { 1.0, 1.0, 1.0, 1.0 }, /* debugging */
+ .width = 0,
+ };
+ struct overlay *over;
+ va_list ap;
+
+ if (dim)
+ style.fg = RGBA(0.5, 0.5, 0.5, 1.0);
+
+ over = overlay_add(&gui->pop_overlays, &gui->aois, NULL, click, user);
+ va_start(ap, fmt);
+ overlay_vtext(over, fmt, ap);
+ va_end(ap);
+ overlay_style(over, &style);
+}
+
+
+void add_pop_frame(struct gui *gui)
+{
+ int w, h;
+
+ overlay_size_all(gui->pop_overlays,
+ gtk_widget_get_pango_context(gui->da), 0, 1, &w, &h);
+
+ struct overlay_style style = {
+ .font = BOLD_FONT,
+ .wmin = w,
+ .hmin = h,
+ .radius = 0,
+ .pad = POP_STACK_PADDING,
+ .skip = 0,
+ .fg = { 0.0, 0.0, 0.0, 1.0 },
+ .bg = { 0.9, 0.9, 0.3, 0.8 },
+ .frame = { 0.0, 0.0, 0.0, 1.0 }, /* debugging */
+ .width = 1,
+ };
+ struct overlay *over;
+
+ over = overlay_add(&gui->pop_underlays, &gui->aois,
+ pop_hover, NULL, gui);
+ overlay_text_raw(over, "");
+ overlay_style(over, &style);
+
+ /*
+ * This makes it all work. When we receive a click while hovering, it
+ * goes to the hovering overlay if that overlay accepts clicks.
+ * However, if the overlay accepting the click is different, we first
+ * de-hover.
+ *
+ * Now, in the case of the frame overlay, dehovering would destroy the
+ * destination overlays right before trying to deliver the click.
+ *
+ * We solve this by declaring the frame overlay to be "related" to the
+ * destination overlays. This suppresses dehovering.
+ */
+ overlay_set_related_all(gui->pop_overlays, over);
+}
diff --git a/gui/pop.h b/gui/pop.h
new file mode 100644
index 0000000..96fa2a6
--- /dev/null
+++ b/gui/pop.h
@@ -0,0 +1,27 @@
+/*
+ * gui/pop.h - Pop-up helper functions
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef GUI_POP_H
+#define GUI_POP_H
+
+#include "gui/common.h"
+
+
+void eeschema_coord(const struct gui *gui, int x, int y, int *rx, int *ry);
+void dehover_pop(struct gui *gui);
+
+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);
+
+#endif /* !GUI_POP_H */
diff --git a/gui/render.c b/gui/render.c
index a70fbf6..2348d07 100644
--- a/gui/render.c
+++ b/gui/render.c
@@ -217,8 +217,8 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
overlay_draw_all_d(gui->pop_underlays, cr, gui->pop_x, gui->pop_y,
gui->pop_dx, gui->pop_dy);
overlay_draw_all_d(gui->pop_overlays, cr,
- gui->pop_x + gui->pop_dx * GLABEL_STACK_PADDING,
- gui->pop_y + gui->pop_dy * GLABEL_STACK_PADDING,
+ gui->pop_x + gui->pop_dx * POP_STACK_PADDING,
+ gui->pop_y + gui->pop_dy * POP_STACK_PADDING,
gui->pop_dx, gui->pop_dy);
switch (gui->mode) {
diff --git a/gui/sheet.c b/gui/sheet.c
index f1a4656..09d41d3 100644
--- a/gui/sheet.c
+++ b/gui/sheet.c
@@ -24,6 +24,7 @@
#include "gui/style.h"
#include "gui/aoi.h"
#include "gui/over.h"
+#include "gui/pop.h"
#include "gui/input.h"
#include "gui/help.h"
#include "gui/icons.h"
@@ -457,7 +458,7 @@ static bool sheet_hover_update(void *user, int x, int y)
static bool sheet_drag_begin(void *user, int x, int y)
{
- dehover_glabel(user);
+ dehover_pop(user);
return 1;
}
@@ -492,7 +493,7 @@ static void sheet_scroll(void *user, int x, int y, int dy)
if (!zoom_out(gui, ex, ey))
return;
}
- dehover_glabel(gui);
+ dehover_pop(gui);
input_update();
}
@@ -553,7 +554,7 @@ static void sheet_key(void *user, int x, int y, int keyval)
break;
case GDK_KEY_Escape:
- dehover_glabel(user);
+ dehover_pop(user);
gui->glabel = NULL;
redraw(gui);
break;