1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-07-01 03:46:23 +03:00

eeshow/: make glabels hoverable (WIP)

This commit is contained in:
Werner Almesberger 2016-08-10 21:50:07 -03:00
parent 08de2f7b4b
commit 0fdce017fb
7 changed files with 107 additions and 13 deletions

View File

@ -25,6 +25,32 @@
#include "dwg.h"
/* ----- Helper functions -------------------------------------------------- */
static void bbox_from_poly(struct dwg_bbox *bbox, unsigned n,
const int *vx, const int *vy)
{
unsigned i;
int xmax, ymax;
bbox->x = xmax = *vx;
bbox->y = ymax = *vy;
for (i = 1; i != n; i++) {
if (vx[i] < bbox->x)
bbox->x = vx[i];
if (vy[i] < bbox->y)
bbox->y = vy[i];
if (vx[i] > xmax)
xmax = vx[i];
if (vy[i] > ymax)
ymax = vy[i];
}
bbox->w = xmax - bbox->x + 1;
bbox->h = ymax - bbox->y + 1;
}
/* ----- Labels ------------------------------------------------------------ */
@ -54,7 +80,7 @@ static enum box_type flip_box(enum box_type box)
void dwg_label(int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape)
enum dwg_shape shape, struct dwg_bbox *bbox)
{
struct text txt = {
.s = s,
@ -99,7 +125,7 @@ void dwg_label(int x, int y, const char *s, int dir, int dim,
void dwg_glabel(int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape)
enum dwg_shape shape, struct dwg_bbox *bbox)
{
struct text txt = {
.s = s,
@ -235,6 +261,9 @@ void dwg_glabel(int x, int y, const char *s, int dir, int dim,
vy[0] = vy[n - 1];
gfx_poly(n, vx, vy, COLOR_GLABEL, COLOR_NONE, LAYER_GLABEL);
if (bbox)
bbox_from_poly(bbox, n, vx, vy);
if (asprintf(&tag, "G:%s", s)) {}
gfx_tag(tag, n, vx, vy);
}
@ -296,7 +325,7 @@ static int make_box(enum box_type box, int h, int *vx, int *vy)
void dwg_hlabel(int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape)
enum dwg_shape shape, struct dwg_bbox *bbox)
{
struct text txt = {
.s = s,
@ -374,7 +403,7 @@ void dwg_hlabel(int x, int y, const char *s, int dir, int dim,
void dwg_text(int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape)
enum dwg_shape shape, struct dwg_bbox *bbox)
{
struct text txt = {
.s = s,

View File

@ -25,15 +25,20 @@ enum dwg_shape {
dwg_bidir, // Bidirectional
};
struct dwg_bbox {
int x, y;
int w, h;
};
void dwg_label(int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape);
enum dwg_shape shape, struct dwg_bbox *bbox);
void dwg_hlabel(int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape);
enum dwg_shape shape, struct dwg_bbox *bbox);
void dwg_glabel(int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape);
enum dwg_shape shape, struct dwg_bbox *bbox);
void dwg_text(int x, int y, const char *s, int dir, int dim,
enum dwg_shape shape);
enum dwg_shape shape, struct dwg_bbox *bbox);
void dwg_junction(int x, int y);
void dwg_noconn(int x, int y);

View File

@ -103,3 +103,12 @@ void aoi_remove(struct aoi **aois, const struct aoi *aoi)
*aois = aoi->next;
free((void *) aoi);
}
void aoi_dehover(void)
{
if (hovering)
hovering->hover(hovering->user, 0);
hovering = NULL;
}

View File

@ -33,5 +33,6 @@ void aoi_update(struct aoi *aoi, const struct aoi *cfg);
bool aoi_hover(const struct aoi *aois, int x, int y);
bool aoi_click(const struct aoi *aois, int x, int y);
void aoi_remove(struct aoi **aois, const struct aoi *aoi);
void aoi_dehover(void);
#endif /* !GUI_AOI_H */

View File

@ -35,6 +35,7 @@
#include "sch.h"
#include "delta.h"
#include "diff.h"
#include "dwg.h"
#include "gui-aoi.h"
#include "gui-style.h"
#include "gui-over.h"
@ -678,6 +679,7 @@ static void do_sheet_overlays(struct gui_ctx *ctx)
static void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet)
{
aoi_dehover();
if (!sheet->rendered) {
render_sheet(sheet);
mark_aois(ctx, sheet);
@ -906,6 +908,30 @@ static void select_subsheet(void *user)
}
struct glabel_aoi_ctx {
const struct gui_sheet *sheet;
const struct sch_obj *obj;
struct overlay *over;
};
static bool hover_glabel(void *user, bool on)
{
struct glabel_aoi_ctx *aoi_ctx = user;
struct gui_ctx *ctx = aoi_ctx->sheet->ctx;
if (on) {
aoi_ctx->over = overlay_add(&ctx->sheet_overlays, NULL,// aois
NULL, NULL, NULL);
overlay_text_raw(aoi_ctx->over, aoi_ctx->obj->u.text.s);
} else {
overlay_remove(&ctx->sheet_overlays, aoi_ctx->over);
}
redraw(ctx);
return 1;
}
/* ----- Initialization ---------------------------------------------------- */
@ -930,6 +956,26 @@ 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_add(&sheet->aois, &cfg);
}
static void mark_aois(struct gui_ctx *ctx, struct gui_sheet *sheet)
{
const struct sch_obj *obj;
@ -940,6 +986,8 @@ static void mark_aois(struct gui_ctx *ctx, struct gui_sheet *sheet)
case sch_obj_sheet:
add_sheet_aoi(ctx, sheet, obj);
break;
case sch_obj_glabel:
add_glabel_aoi(sheet, obj);
default:
break;
}

View File

@ -124,14 +124,14 @@ static void render_sheet(const struct sch_obj *obj,
for (field = sheet->fields; field; field = field->next)
dwg_hlabel(obj->x, obj->y, field->s,
field->side, field->dim,
field->shape);
field->shape, NULL);
// free(field->s)
}
void sch_render(const struct sheet *sheet)
{
const struct sch_obj *obj;
struct sch_obj *obj;
for (obj = sheet->objs; obj; obj = obj->next)
switch (obj->type) {
@ -151,10 +151,10 @@ void sch_render(const struct sheet *sheet)
case sch_obj_glabel:
case sch_obj_text:
{
const struct sch_text *text = &obj->u.text;
struct sch_text *text = &obj->u.text;
text->fn(obj->x, obj->y, text->s, text->dir,
text->dim, text->shape);
text->dim, text->shape, &text->bbox);
}
break;
case sch_obj_comp:

View File

@ -54,11 +54,13 @@ struct sch_obj {
} wire;
struct sch_text {
void (*fn)(int x, int y, const char *s,
int dir, int dim, enum dwg_shape shape);
int dir, int dim, enum dwg_shape shape,
struct dwg_bbox *bbox);
const char *s;
int dir; /* orientation */
int dim; /* dimension */
enum dwg_shape shape;
struct dwg_bbox bbox; /* set when rendering; glabel */
} text;
struct sch_comp {
const struct comp *comp; /* current component */