1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-11-07 17:23:00 +00:00

SVG links no longer use an additional field in polytodraw -- they are a new type of polyunion now

This commit is contained in:
Zeno Rogue
2018-07-09 20:40:05 +02:00
parent f721c243d2
commit 6e4e9e0a46
3 changed files with 32 additions and 19 deletions

16
hyper.h
View File

@@ -1566,7 +1566,7 @@ namespace svg {
void polygon(int *polyx, int *polyy, int polyi, int col, int outline, double minwidth); void polygon(int *polyx, int *polyy, int polyi, int col, int outline, double minwidth);
void text(int x, int y, int size, const string& str, bool frame, int col, int align); void text(int x, int y, int size, const string& str, bool frame, int col, int align);
extern bool in; extern bool in;
extern string *info; extern const string *link;
void render(const char *fname = NULL); void render(const char *fname = NULL);
} }
@@ -2347,7 +2347,12 @@ struct qcir {
bool boundary; bool boundary;
}; };
enum eKind { pkPoly, pkLine, pkString, pkCircle, pkShape, pkResetModel, pkSpecial }; // set a link for SVG
struct qlink {
const string *link;
};
enum eKind { pkPoly, pkLine, pkString, pkCircle, pkShape, pkResetModel, pkSpecial, pkLink };
union polyunion { union polyunion {
qpoly poly; qpoly poly;
@@ -2355,6 +2360,7 @@ union polyunion {
qchr chr; qchr chr;
qcir cir; qcir cir;
double dvalue; double dvalue;
qlink link;
polyunion() {} polyunion() {}
}; };
@@ -2362,12 +2368,7 @@ struct polytodraw {
eKind kind; eKind kind;
int prio, col; int prio, col;
polyunion u; polyunion u;
#if CAP_ROGUEVIZ
string* info;
polytodraw() { info = NULL; }
#else
polytodraw() {} polytodraw() {}
#endif
}; };
extern int emeraldtable[100][7]; extern int emeraldtable[100][7];
@@ -2845,6 +2846,7 @@ namespace texture {
#endif #endif
void queueline(const hyperpoint& H1, const hyperpoint& H2, int col, int prf = 0, int prio = PPR_LINE); void queueline(const hyperpoint& H1, const hyperpoint& H2, int col, int prf = 0, int prio = PPR_LINE);
void queuelink(const string *link, int prio);
hyperpoint ddi0(ld dir, ld dist); hyperpoint ddi0(ld dir, ld dist);
extern ld tessf, crossf, hexf, hcrossf, hexhexdist, hexvdist, hepvdist, rhexf; extern ld tessf, crossf, hexf, hcrossf, hexhexdist, hexvdist, hepvdist, rhexf;

View File

@@ -845,13 +845,13 @@ bool keep_curvedata = false;
hookset<void(polytodraw&)> *hooks_specialdraw; hookset<void(polytodraw&)> *hooks_specialdraw;
void drawqueueitem(polytodraw& ptd) { void drawqueueitem(polytodraw& ptd) {
#if CAP_ROGUEVIZ
svg::info = ptd.info;
#endif
// if(ptd.prio == 46) printf("eye size %d\n", polyi); // if(ptd.prio == 46) printf("eye size %d\n", polyi);
switch(ptd.kind) { switch(ptd.kind) {
case pkLink:
svg::link = ptd.u.link.link;
break;
case pkSpecial: case pkSpecial:
callhooks(hooks_specialdraw, ptd); callhooks(hooks_specialdraw, ptd);
break; break;
@@ -2338,6 +2338,13 @@ void queuecurve(int linecol, int fillcol, int prio) {
curvestart = isize(curvedata); curvestart = isize(curvedata);
} }
void queuelink(const string *link, int prio) {
polytodraw& ptd = nextptd();
ptd.kind = pkLink;
ptd.prio = prio << PSHIFT;
ptd.u.link.link = link;
}
void queueline(const hyperpoint& H1, const hyperpoint& H2, int col, int prf, int prio) { void queueline(const hyperpoint& H1, const hyperpoint& H2, int col, int prf, int prio) {
polytodraw& ptd = nextptd(); polytodraw& ptd = nextptd();
ptd.kind = pkLine; ptd.kind = pkLine;
@@ -2465,14 +2472,14 @@ namespace svg {
coord(x), coord(y), coord(size), stylestr(ba, col)); coord(x), coord(y), coord(size), stylestr(ba, col));
} }
string *info; const string *link;
void startstring() { void startstring() {
if(info) fprintf(f, "<a xlink:href=\"%s\" xlink:show=\"replace\">", info->c_str()); if(link) fprintf(f, "<a xlink:href=\"%s\" xlink:show=\"replace\">", link->c_str());
} }
void stopstring() { void stopstring() {
if(info) fprintf(f, "</a>"); if(link) fprintf(f, "</a>");
} }
string font = "Times"; string font = "Times";

View File

@@ -1032,7 +1032,7 @@ void storeline(vector<glvertex>& tab, const hyperpoint& h1, const hyperpoint& h2
hpcshape *vshapes[4] = { &shDisk, &shDisk, &shHeptaMarker, &shSnowball }; hpcshape *vshapes[4] = { &shDisk, &shDisk, &shHeptaMarker, &shSnowball };
void queuedisk(const transmatrix& V, const colorpair& cp, bool legend) { void queuedisk(const transmatrix& V, const colorpair& cp, bool legend, const string* info) {
if(legend && (int) cp.color1 == (int) 0x000000FF && backcolor == 0) if(legend && (int) cp.color1 == (int) 0x000000FF && backcolor == 0)
poly_outline = 0x606060FF; poly_outline = 0x606060FF;
else else
@@ -1047,10 +1047,14 @@ void queuedisk(const transmatrix& V, const colorpair& cp, bool legend) {
int p = poly_outline; poly_outline = OUTLINE_TRANS; int p = poly_outline; poly_outline = OUTLINE_TRANS;
queuepolyat(V, sh, 0x80, PPR_MONSTER_SHADOW); queuepolyat(V, sh, 0x80, PPR_MONSTER_SHADOW);
poly_outline = p; poly_outline = p;
if(info) queuelink(info, PPR_MONSTER_HEAD);
queuepolyat(V1 = mscale(V, geom3::BODY), sh, cp.color1, PPR_MONSTER_HEAD); queuepolyat(V1 = mscale(V, geom3::BODY), sh, cp.color1, PPR_MONSTER_HEAD);
if(info) queuelink(NULL, PPR_MONSTER_HEAD);
} }
else { else {
if(info) queuelink(info, sh.prio);
queuepoly(V1 = V, sh, cp.color1); queuepoly(V1 = V, sh, cp.color1);
if(info) queuelink(NULL, sh.prio);
} }
if(cp.shade == 't') queuepoly(V1, shDiskT, cp.color2); if(cp.shade == 't') queuepoly(V1, shDiskT, cp.color2);
if(cp.shade == 's') queuepoly(V1, shDiskS, cp.color2); if(cp.shade == 's') queuepoly(V1, shDiskS, cp.color2);
@@ -1205,8 +1209,7 @@ bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) {
} }
if(!vd.virt) { if(!vd.virt) {
queuedisk(V * m->at, ghilite ? colorpair(0xFF0000FF) : vd.cp, false); queuedisk(V * m->at, ghilite ? colorpair(0xFF0000FF) : vd.cp, false, vd.info);
if(vertex_shape) lastptd().info = vd.info;
} }
@@ -1221,8 +1224,9 @@ bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) {
hyperpoint h = tC0(V * m->at); hyperpoint h = tC0(V * m->at);
transmatrix V2 = rgpushxto0(h) * ypush(nonbitrunc ? .3 : .2); transmatrix V2 = rgpushxto0(h) * ypush(nonbitrunc ? .3 : .2);
if(doshow && !behindsphere(V2)) { if(doshow && !behindsphere(V2)) {
if(vd.info) queuelink(vd.info, PPR_TEXT);
queuestr(V2, (svg::in ? .28 : .2) * crossf / hcrossf, vd.name, backcolor ? 0x000000 : 0xFFFF00, svg::in ? 0 : 1); queuestr(V2, (svg::in ? .28 : .2) * crossf / hcrossf, vd.name, backcolor ? 0x000000 : 0xFFFF00, svg::in ? 0 : 1);
lastptd().info = vd.info; if(vd.info) queuelink(NULL, PPR_TEXT);
} }
} }
@@ -1317,7 +1321,7 @@ bool rogueviz_hud() {
transmatrix V = atscreenpos(x, y, vid.radius/4); transmatrix V = atscreenpos(x, y, vid.radius/4);
poly_outline = OUTLINE_NONE; poly_outline = OUTLINE_NONE;
queuedisk(V, vd.cp, true); queuedisk(V, vd.cp, true, NULL);
poly_outline = OUTLINE_DEFAULT; poly_outline = OUTLINE_DEFAULT;
queuestr(int(x-rad), int(y), 0, rad*(svg::in?5:3)/4, vd.name, forecolor, 0, 16); queuestr(int(x-rad), int(y), 0, rad*(svg::in?5:3)/4, vd.name, forecolor, 0, 16);
} }