From 4486e9a01780637578cc3920ce55c74282c59bc0 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 30 Mar 2021 23:01:54 +0200 Subject: [PATCH] export more presentation functions --- rogueviz/presentation.cpp | 101 ++++++++++++++++---------------------- rogueviz/rogueviz.h | 38 +++++++++++++- 2 files changed, 78 insertions(+), 61 deletions(-) diff --git a/rogueviz/presentation.cpp b/rogueviz/presentation.cpp index d85f7eac..b8175639 100644 --- a/rogueviz/presentation.cpp +++ b/rogueviz/presentation.cpp @@ -9,64 +9,57 @@ namespace rogueviz { namespace pres { /* maks graphs in presentations */ -struct grapher { - - ld minx, miny, maxx, maxy; +grapher::grapher(ld _minx, ld _miny, ld _maxx, ld _maxy) : minx(_minx), miny(_miny), maxx(_maxx), maxy(_maxy) { + auto& cd = *current_display; - 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) { - auto& cd = *current_display; - - ld xpixels = 2 * min(cd.xcenter - cd.xmin, cd.xmax - cd.xcenter); - 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; + 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 zero01 = atscreenpos(cd.xcenter - sca * medx, cd.ycenter + sca * medy - sca, 1) * C0; - - T = shiftless(Id); - T.T[LDIM] = zero; - T.T[0] = zero10 - zero; - T.T[1] = zero01 - zero; - - T.T = transpose(T.T); - } + 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; + + T = shiftless(Id); + T.T[LDIM] = zero; + T.T[0] = zero10 - zero; + T.T[1] = zero01 - zero; + + 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(h2); queuecurve(T, col, 0, PPR::LINE).flags |= POLY_FORCEWIDE; } - void arrow(hyperpoint h1, hyperpoint h2, ld sca) { - line(h1, h2, 0xFF); - hyperpoint h = h2 - h1; - ld siz = hypot_d(2, h); - h *= sca / siz; - curvepoint(h2); - curvepoint(h2 - spin(15*degree) * h); - curvepoint(h2 - spin(-15*degree) * h); - curvepoint(h2); - queuecurve(T, 0xFF, 0xFF, PPR::LINE); - } +void grapher::arrow(hyperpoint h1, hyperpoint h2, ld sca, color_t col) { + line(h1, h2, col); + if(!sca) return; + hyperpoint h = h2 - h1; + ld siz = hypot_d(2, h); + h *= sca / siz; + curvepoint(h2); + curvepoint(h2 - spin(15*degree) * h); + curvepoint(h2 - spin(-15*degree) * h); + curvepoint(h2); + queuecurve(T, col, col, PPR::LINE); + } - shiftmatrix pos(ld x, ld y, ld sca) { - transmatrix P = Id; - P[0][0] = sca; - P[1][1] = sca; - P[0][LDIM] = x; - P[1][LDIM] = y; - return T * P; - } - - }; +shiftmatrix grapher::pos(ld x, ld y, ld sca) { + transmatrix P = Id; + P[0][0] = sca; + P[1][1] = sca; + P[0][LDIM] = x; + P[1][LDIM] = y; + return T * P; + } 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; -template void add_temporary_hook(int mode, hookset& 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) { add_temporary_hook(mode, hooks_prestats, 200, stat); } @@ -92,7 +76,7 @@ void no_other_hud(presmode mode) { clearMessages(); } -void empty_screen(presmode mode, color_t col = 0xFFFFFFFF) { +void empty_screen(presmode mode, color_t col) { if(mode == pmStart) { tour::slide_backup(nomap, true); 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) { if(mode == pmStart && reset) angle = 0, dir = -1; diff --git a/rogueviz/rogueviz.h b/rogueviz/rogueviz.h index 9040471a..95eadea8 100644 --- a/rogueviz/rogueviz.h +++ b/rogueviz/rogueviz.h @@ -169,7 +169,43 @@ function roguevizslide_action(char c, const T& t, const U& act) }; } - } + + void add_end(vector& s); + + template void add_temporary_hook(int mode, hookset& 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);