1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-17 22:37:11 +02:00

eeshow/gui/gui.c: move global label pop-up to glabel.c

This commit is contained in:
Werner Almesberger 2016-08-18 03:07:43 -03:00
parent 6975c2b6d5
commit 4191931c06
4 changed files with 157 additions and 133 deletions

View File

@ -15,7 +15,7 @@ OBJS = main.o \
kicad/sch-parse.o kicad/sch-render.o kicad/lib-parse.o \ kicad/sch-parse.o kicad/sch-render.o kicad/lib-parse.o \
kicad/lib-render.o kicad/dwg.o kicad/delta.o \ kicad/lib-render.o kicad/dwg.o kicad/delta.o \
gui/gui.o gui/over.o gui/style.o gui/aoi.o gui/fmt-pango.o gui/input.o \ gui/gui.o gui/over.o gui/style.o gui/aoi.o gui/fmt-pango.o gui/input.o \
gui/progress.o \ gui/progress.o gui/glabel.o \
file/file.o file/git-util.o file/git-file.o file/git-hist.o \ file/file.o file/git-util.o file/git-file.o file/git-hist.o \
gfx/style.o gfx/fig.o gfx/record.o gfx/cro.o gfx/diff.o gfx/gfx.o \ gfx/style.o gfx/fig.o gfx/record.o gfx/cro.o gfx/diff.o gfx/gfx.o \
gfx/text.o gfx/misc.o \ gfx/text.o gfx/misc.o \

View File

@ -101,9 +101,20 @@ struct gui_ctx {
void redraw(const struct gui_ctx *ctx); /* progress.c */
void setup_progress_bar(struct gui_ctx *ctx, GtkWidget *window); void setup_progress_bar(struct gui_ctx *ctx, GtkWidget *window);
void progress_update(struct gui_ctx *ctx); void progress_update(struct gui_ctx *ctx);
/* glabel.c */
void dehover_glabel(struct gui_ctx *ctx);
void add_glabel_aoi(struct gui_sheet *sheet, const struct sch_obj *obj);
/* gui.c */
void redraw(const struct gui_ctx *ctx);
void eeschema_coord(const struct gui_ctx *ctx, int x, int y, int *rx, int *ry);
void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet);
#endif /* !GUI_COMMON_H */ #endif /* !GUI_COMMON_H */

142
eeshow/gui/glabel.c Normal file
View File

@ -0,0 +1,142 @@
/*
* gui/glabel.c - Global label pop-up
*
* 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 <stdbool.h>
#include <string.h>
#include <gtk/gtk.h>
#include "misc/util.h"
#include "kicad/dwg.h"
#include "gui/style.h"
#include "gui/aoi.h"
#include "gui/over.h"
#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;
struct dwg_bbox bbox;
struct overlay *over;
};
static void glabel_dest_click(void *user)
{
struct gui_sheet *sheet = user;
go_to_sheet(sheet->ctx, sheet);
}
void dehover_glabel(struct gui_ctx *ctx)
{
overlay_remove_all(&ctx->pop_overlays);
redraw(ctx);
}
static bool hover_glabel(void *user, bool on)
{
struct glabel_aoi_ctx *aoi_ctx = user;
struct gui_ctx *ctx = aoi_ctx->sheet->ctx;
const struct gui_sheet *curr_sheet = ctx->curr_sheet;
const struct dwg_bbox *bbox = &aoi_ctx->bbox;
if (!on) {
dehover_glabel(ctx);
return 1;
}
GtkAllocation alloc;
struct overlay_style style = {
.font = BOLD_FONT,
.wmin = 100,
.wmax = 100,
.radius = 0,
.pad = 4,
.skip = -4,
.fg = { 0.0, 0.0, 0.0, 1.0 },
.bg = { 1.0, 0.8, 0.4, 0.8 },
.frame = { 1.0, 1.0, 1.0, 1.0 }, /* debugging */
.width = 0,
};
int sx, sy, ex, ey, mx, my;
unsigned n = 0;
struct gui_sheet *sheet;
const struct sch_obj *obj;
struct overlay *over;
aoi_dehover();
overlay_remove_all(&ctx->pop_overlays);
for (sheet = ctx->new_hist->sheets; sheet; sheet = sheet->next) {
n++;
if (sheet == curr_sheet)
continue;
for (obj = sheet->sch->objs; obj; obj = obj->next) {
if (obj->type != sch_obj_glabel)
continue;
if (strcmp(obj->u.text.s, aoi_ctx->obj->u.text.s))
continue;
over = overlay_add(&ctx->pop_overlays,
&ctx->aois, NULL, glabel_dest_click, sheet);
overlay_text(over, "%d %s", n, sheet->sch->title);
overlay_style(over, &style);
break;
}
}
eeschema_coord(ctx,
bbox->x - curr_sheet->xmin, bbox->y - curr_sheet->ymin,
&sx, &sy);
eeschema_coord(ctx, bbox->x + bbox->w - curr_sheet->xmin,
bbox->y + bbox->h - curr_sheet->ymin, &ex, &ey);
gtk_widget_get_allocation(ctx->da, &alloc);
mx = (sx + ex) / 2;
my = (sy + ey) / 2;
ctx->pop_x = mx < alloc.width / 2 ?
sx - CHEAT : -(alloc.width - ex) + CHEAT;
ctx->pop_y = my < alloc.height / 2 ?
sy - CHEAT : -(alloc.height - ey) + CHEAT;
redraw(ctx);
return 0;
}
void add_glabel_aoi(struct gui_sheet *sheet, const struct sch_obj *obj)
{
const struct dwg_bbox *bbox = &obj->u.text.bbox;
struct glabel_aoi_ctx *aoi_ctx = alloc_type(struct glabel_aoi_ctx);
struct aoi cfg = {
.x = bbox->x,
.y = bbox->y,
.w = bbox->w,
.h = bbox->h,
.hover = hover_glabel,
.user = aoi_ctx,
};
aoi_ctx->sheet = sheet;
aoi_ctx->obj = obj;
aoi_ctx->bbox = *bbox;
aoi_add(&sheet->aois, &cfg);
}

View File

@ -217,8 +217,7 @@ static void canvas_coord(const struct gui_ctx *ctx,
} }
static void eeschema_coord(const struct gui_ctx *ctx, void eeschema_coord(const struct gui_ctx *ctx, int x, int y, int *rx, int *ry)
int x, int y, int *rx, int *ry)
{ {
GtkAllocation alloc; GtkAllocation alloc;
@ -301,13 +300,6 @@ static void zoom_to_extents(struct gui_ctx *ctx)
} }
/* ----- Need this for jumping around -------------------------------------- */
static void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet);
static bool go_up_sheet(struct gui_ctx *ctx);
/* ----- Revision history -------------------------------------------------- */ /* ----- Revision history -------------------------------------------------- */
@ -643,7 +635,7 @@ static void do_sheet_overlays(struct gui_ctx *ctx)
} }
static void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet) void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet)
{ {
aoi_dehover(); aoi_dehover();
overlay_remove_all(&ctx->pop_overlays); overlay_remove_all(&ctx->pop_overlays);
@ -740,9 +732,6 @@ static void sheet_hover_end(void *user)
} }
static void dehover_glabel(struct gui_ctx *ctx);
static bool sheet_drag_begin(void *user, int x, int y) static bool sheet_drag_begin(void *user, int x, int y)
{ {
dehover_glabel(user); dehover_glabel(user);
@ -902,102 +891,6 @@ static void select_subsheet(void *user)
} }
struct glabel_aoi_ctx {
const struct gui_sheet *sheet;
const struct sch_obj *obj;
struct dwg_bbox bbox;
struct overlay *over;
};
/* small offset to hide rounding errors */
#define CHEAT 1
static void glabel_dest_click(void *user)
{
struct gui_sheet *sheet = user;
go_to_sheet(sheet->ctx, sheet);
}
static void dehover_glabel(struct gui_ctx *ctx)
{
overlay_remove_all(&ctx->pop_overlays);
redraw(ctx);
}
static bool hover_glabel(void *user, bool on)
{
struct glabel_aoi_ctx *aoi_ctx = user;
struct gui_ctx *ctx = aoi_ctx->sheet->ctx;
const struct gui_sheet *curr_sheet = ctx->curr_sheet;
const struct dwg_bbox *bbox = &aoi_ctx->bbox;
if (!on) {
dehover_glabel(ctx);
return 1;
}
GtkAllocation alloc;
struct overlay_style style = {
.font = BOLD_FONT,
.wmin = 100,
.wmax = 100,
.radius = 0,
.pad = 4,
.skip = -4,
.fg = { 0.0, 0.0, 0.0, 1.0 },
.bg = { 1.0, 0.8, 0.4, 0.8 },
.frame = { 1.0, 1.0, 1.0, 1.0 }, /* debugging */
.width = 0,
};
int sx, sy, ex, ey, mx, my;
unsigned n = 0;
struct gui_sheet *sheet;
const struct sch_obj *obj;
struct overlay *over;
aoi_dehover();
overlay_remove_all(&ctx->pop_overlays);
for (sheet = ctx->new_hist->sheets; sheet; sheet = sheet->next) {
n++;
if (sheet == curr_sheet)
continue;
for (obj = sheet->sch->objs; obj; obj = obj->next) {
if (obj->type != sch_obj_glabel)
continue;
if (strcmp(obj->u.text.s, aoi_ctx->obj->u.text.s))
continue;
over = overlay_add(&ctx->pop_overlays,
&ctx->aois, NULL, glabel_dest_click, sheet);
overlay_text(over, "%d %s", n, sheet->sch->title);
overlay_style(over, &style);
break;
}
}
eeschema_coord(ctx,
bbox->x - curr_sheet->xmin, bbox->y - curr_sheet->ymin,
&sx, &sy);
eeschema_coord(ctx, bbox->x + bbox->w - curr_sheet->xmin,
bbox->y + bbox->h - curr_sheet->ymin, &ex, &ey);
gtk_widget_get_allocation(ctx->da, &alloc);
mx = (sx + ex) / 2;
my = (sy + ey) / 2;
ctx->pop_x = mx < alloc.width / 2 ?
sx - CHEAT : -(alloc.width - ex) + CHEAT;
ctx->pop_y = my < alloc.height / 2 ?
sy - CHEAT : -(alloc.height - ey) + CHEAT;
redraw(ctx);
return 0;
}
/* ----- Initialization ---------------------------------------------------- */ /* ----- Initialization ---------------------------------------------------- */
@ -1022,28 +915,6 @@ static void add_sheet_aoi(struct gui_ctx *ctx, struct gui_sheet *parent,
} }
static void add_glabel_aoi(struct gui_sheet *sheet, const struct sch_obj *obj)
{
const struct dwg_bbox *bbox = &obj->u.text.bbox;
struct glabel_aoi_ctx *aoi_ctx = alloc_type(struct glabel_aoi_ctx);
struct aoi cfg = {
.x = bbox->x,
.y = bbox->y,
.w = bbox->w,
.h = bbox->h,
.hover = hover_glabel,
.user = aoi_ctx,
};
aoi_ctx->sheet = sheet;
aoi_ctx->obj = obj;
aoi_ctx->bbox = *bbox;
aoi_add(&sheet->aois, &cfg);
}
static void mark_aois(struct gui_ctx *ctx, struct gui_sheet *sheet) static void mark_aois(struct gui_ctx *ctx, struct gui_sheet *sheet)
{ {
const struct sch_obj *obj; const struct sch_obj *obj;