1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-25 01:20:37 +00:00

export more presentation functions

This commit is contained in:
Zeno Rogue 2021-03-30 23:01:54 +02:00
parent cf1cd09f81
commit 4486e9a017
2 changed files with 78 additions and 61 deletions

View File

@ -9,64 +9,57 @@ namespace rogueviz {
namespace pres { namespace pres {
/* maks graphs in presentations */ /* maks graphs in presentations */
struct grapher { grapher::grapher(ld _minx, ld _miny, ld _maxx, ld _maxy) : minx(_minx), miny(_miny), maxx(_maxx), maxy(_maxy) {
auto& cd = *current_display;
ld minx, miny, maxx, maxy;
shiftmatrix T; ld xpixels = 2 * min(cd.xcenter - cd.xmin, cd.xmax - cd.xcenter);
ld ypixels = 2 * min(cd.ycenter - cd.ymin, cd.ymax - cd.ycenter);
grapher(ld _minx, ld _miny, ld _maxx, ld _maxy) : minx(_minx), miny(_miny), maxx(_maxx), maxy(_maxy) { ld sca = min(abs(xpixels / (maxx-minx)), abs(ypixels / (maxy-miny)));
auto& cd = *current_display;
ld medx = (minx + maxx) / 2;
ld xpixels = 2 * min(cd.xcenter - cd.xmin, cd.xmax - cd.xcenter); ld medy = (miny + maxy) / 2;
ld ypixels = 2 * min(cd.ycenter - cd.ymin, cd.ymax - cd.ycenter);
ld sca = min(abs(xpixels / (maxx-minx)), abs(ypixels / (maxy-miny)));
ld medx = (minx + maxx) / 2;
ld medy = (miny + maxy) / 2;
hyperpoint zero = atscreenpos(cd.xcenter - sca * medx, cd.ycenter + sca * medy, 1) * C0; hyperpoint zero = atscreenpos(cd.xcenter - sca * medx, cd.ycenter + sca * medy, 1) * C0;
hyperpoint zero10 = atscreenpos(cd.xcenter - sca * medx + sca, cd.ycenter + sca * medy, 1) * C0; hyperpoint zero10 = atscreenpos(cd.xcenter - sca * medx + sca, cd.ycenter + sca * medy, 1) * C0;
hyperpoint zero01 = atscreenpos(cd.xcenter - sca * medx, cd.ycenter + sca * medy - sca, 1) * C0; hyperpoint zero01 = atscreenpos(cd.xcenter - sca * medx, cd.ycenter + sca * medy - sca, 1) * C0;
T = shiftless(Id); T = shiftless(Id);
T.T[LDIM] = zero; T.T[LDIM] = zero;
T.T[0] = zero10 - zero; T.T[0] = zero10 - zero;
T.T[1] = zero01 - zero; T.T[1] = zero01 - zero;
T.T = transpose(T.T); T.T = transpose(T.T);
} }
void line(hyperpoint h1, hyperpoint h2, color_t col) { void grapher::line(hyperpoint h1, hyperpoint h2, color_t col) {
curvepoint(h1); curvepoint(h1);
curvepoint(h2); curvepoint(h2);
queuecurve(T, col, 0, PPR::LINE).flags |= POLY_FORCEWIDE; queuecurve(T, col, 0, PPR::LINE).flags |= POLY_FORCEWIDE;
} }
void arrow(hyperpoint h1, hyperpoint h2, ld sca) { void grapher::arrow(hyperpoint h1, hyperpoint h2, ld sca, color_t col) {
line(h1, h2, 0xFF); line(h1, h2, col);
hyperpoint h = h2 - h1; if(!sca) return;
ld siz = hypot_d(2, h); hyperpoint h = h2 - h1;
h *= sca / siz; ld siz = hypot_d(2, h);
curvepoint(h2); h *= sca / siz;
curvepoint(h2 - spin(15*degree) * h); curvepoint(h2);
curvepoint(h2 - spin(-15*degree) * h); curvepoint(h2 - spin(15*degree) * h);
curvepoint(h2); curvepoint(h2 - spin(-15*degree) * h);
queuecurve(T, 0xFF, 0xFF, PPR::LINE); curvepoint(h2);
} queuecurve(T, col, col, PPR::LINE);
}
shiftmatrix pos(ld x, ld y, ld sca) { shiftmatrix grapher::pos(ld x, ld y, ld sca) {
transmatrix P = Id; transmatrix P = Id;
P[0][0] = sca; P[0][0] = sca;
P[1][1] = sca; P[1][1] = sca;
P[0][LDIM] = x; P[0][LDIM] = x;
P[1][LDIM] = y; P[1][LDIM] = y;
return T * P; return T * P;
} }
};
hyperpoint p2(ld x, ld y) { return LDIM == 2 ? point3(x, y, 1) : point31(x, y, 0); } hyperpoint p2(ld x, ld y) { return LDIM == 2 ? point3(x, y, 1) : point31(x, y, 0); }
@ -74,15 +67,6 @@ hyperpoint p2(ld x, ld y) { return LDIM == 2 ? point3(x, y, 1) : point31(x, y, 0
using namespace hr::tour; using namespace hr::tour;
template<class T, class U> void add_temporary_hook(int mode, hookset<T>& m, int prio, U&& hook) {
if(mode == pmStart) {
int p = addHook(m, prio, hook);
on_restore([&m, p] {
delHook(m, p);
});
}
}
void add_stat(presmode mode, const bool_reaction_t& stat) { void add_stat(presmode mode, const bool_reaction_t& stat) {
add_temporary_hook(mode, hooks_prestats, 200, stat); add_temporary_hook(mode, hooks_prestats, 200, stat);
} }
@ -92,7 +76,7 @@ void no_other_hud(presmode mode) {
clearMessages(); clearMessages();
} }
void empty_screen(presmode mode, color_t col = 0xFFFFFFFF) { void empty_screen(presmode mode, color_t col) {
if(mode == pmStart) { if(mode == pmStart) {
tour::slide_backup(nomap, true); tour::slide_backup(nomap, true);
tour::slide_backup(backcolor, col); tour::slide_backup(backcolor, col);
@ -262,9 +246,6 @@ int phooks =
} }
}); });
static ld angle = 0;
static int dir = -1;
void use_angledir(presmode mode, bool reset) { void use_angledir(presmode mode, bool reset) {
if(mode == pmStart && reset) if(mode == pmStart && reset)
angle = 0, dir = -1; angle = 0, dir = -1;

View File

@ -169,7 +169,43 @@ function<void(presmode)> roguevizslide_action(char c, const T& t, const U& act)
}; };
} }
}
void add_end(vector<slide>& s);
template<class T, class U> void add_temporary_hook(int mode, hookset<T>& m, int prio, U&& hook) {
using namespace tour;
if(mode == pmStart) {
int p = addHook(m, prio, hook);
on_restore([&m, p] {
delHook(m, p);
});
}
}
/* maks graphs in presentations */
struct grapher {
ld minx, miny, maxx, maxy;
shiftmatrix T;
grapher(ld _minx, ld _miny, ld _maxx, ld _maxy);
void line(hyperpoint h1, hyperpoint h2, color_t col);
void arrow(hyperpoint h1, hyperpoint h2, ld sca, color_t col = 0xFF);
shiftmatrix pos(ld x, ld y, ld sca);
};
void add_stat(presmode mode, const bool_reaction_t& stat);
void compare_projections(presmode mode, eModel a, eModel b);
void no_other_hud(presmode mode);
void empty_screen(presmode mode, color_t col = 0xFFFFFFFF);
void show_picture(presmode mode, string s);
void use_angledir(presmode mode, bool reset);
inline ld angle = 0;
inline int dir = -1;
hyperpoint p2(ld x, ld y);
}
void createViz(int id, cell *c, transmatrix at); void createViz(int id, cell *c, transmatrix at);