From 8d1e341555ddf4c4e1aedd8a6ee84ddbcfdbebd6 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 13 Dec 2018 14:53:44 +0100 Subject: [PATCH] web:: 'take screenshot' feature now creates a SVG file and opens it in a new window --- control.cpp | 6 ++--- debug.cpp | 5 ++++ hyper.h | 3 ++- screenshot.cpp | 72 ++++++++++++++++++++++++++++++++------------------ 4 files changed, 56 insertions(+), 30 deletions(-) diff --git a/control.cpp b/control.cpp index 0f62f052..8fcce65d 100644 --- a/control.cpp +++ b/control.cpp @@ -316,12 +316,10 @@ void handleKeyNormal(int sym, int uni) { if(cheater && sym < 256 && sym > 0) { if(applyCheat(uni, mouseover)) - sym = 0; + uni = sym = 0; } - #if ISMOBILE - if(uni == 'A' && !cheater) pushScreen(shot::menu); - #endif + if(uni == 'A') { pushScreen(shot::menu); uni = sym = 0; } if(DEFAULTNOR(sym)) handlePanning(sym, uni); diff --git a/debug.cpp b/debug.cpp index 1a12de40..69de83e0 100644 --- a/debug.cpp +++ b/debug.cpp @@ -169,6 +169,11 @@ bool applyCheat(char u, cell *c = NULL) { pushScreen(mapeditor::showDrawEditor); return true; } +#elif CAP_SHOT + if(u == 'A') { + pushScreen(shot::menu); + return true; + } #endif if(u == 'T') { items[randomTreasure2(10)] += 10; diff --git a/hyper.h b/hyper.h index 0304151e..8c3504dd 100644 --- a/hyper.h +++ b/hyper.h @@ -1864,7 +1864,8 @@ void resetGeometry(); namespace shot { extern int shotx, shoty, shotformat; extern bool make_svg; - extern ld gamma; + extern ld gamma, fade; + extern string caption; void menu(); void default_screenshot_content(); void take(string fname, const function& what = default_screenshot_content); diff --git a/screenshot.cpp b/screenshot.cpp index 61e9a155..2a9630e3 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -12,7 +12,12 @@ namespace svg { #if ISMOBILE==0 // svg renderer namespace svg { - FILE *f; + #if ISWEB + shstream f; + #else + fhstream f; + #endif + bool in = false; ld cta(color_t col) { @@ -72,22 +77,20 @@ namespace svg { void circle(int x, int y, int size, color_t col, color_t fillcol) { if(!invisible(col) || !invisible(fillcol)) { if(vid.stretch == 1) - fprintf(f, "\n", - coord(x), coord(y), coord(size), stylestr(fillcol, col)); + println(f, ""); else - fprintf(f, "\n", - coord(x), coord(y), coord(size), coord(size*vid.stretch), stylestr(fillcol, col)); + println(f, ""); } } string link; void startstring() { - if(link != "") fprintf(f, "", link.c_str()); + if(link != "") print(f, ""); } void stopstring() { - if(link != "") fprintf(f, ""); + if(link != "") print(f, ""); } string font = "Times"; @@ -119,17 +122,17 @@ namespace svg { str2 += "\\#"; else str2 += str[i]; if(uselatex) str2 = string("\\myfont{")+coord(size)+"}{" + str2 + "}"; - fprintf(f, "%s", - stylestr(col, frame ? 0x0000000FF : 0, (1<", str2, ""); stopstring(); - fprintf(f, "\n"); + println(f); } } @@ -141,26 +144,41 @@ namespace svg { startstring(); for(int i=0; i", stylestr(col, outline, (hyperbolic ? current_display->radius : current_display->scrsize) * linewidth/256)); + print(f, "\" ", stylestr(col, outline, (hyperbolic ? current_display->radius : current_display->scrsize) * linewidth/256), "/>"); stopstring(); - fprintf(f, "\n"); + println(f); } void render(const string& fname, const function& what) { dynamicval v2(in, true); dynamicval v3(vid.usingGL, false); - f = fopen(fname.c_str(), "wt"); - fprintf(f, "\n", coord(vid.xres), coord(vid.yres)); + #if ISWEB + f.s = ""; + #else + f.f = fopen(fname.c_str(), "wt"); + #endif + + println(f, ""); what(); - fprintf(f, "\n"); - fclose(f); + println(f, ""); + + #if ISWEB + EM_ASM_({ + var x=window.open(); + x.document.open(); + x.document.write(Pointer_stringify($0)); + x.document.close(); + }, f.s.c_str()); + #else + fclose(f.f); + #endif } #if CAP_COMMANDLINE @@ -312,7 +330,7 @@ void take(string fname, const function& what) { glbuf.enable(); current_display->set_viewport(0); - dynamicval v8(backcolor, transparent ? 0xFF000000 : backcolor); + dynamicval v8(backcolor, transparent ? 0xFF000000 : backcolor); #if CAP_RUG if(rug::rugged && !rug::renderonce) rug::prepareTexture(); #endif @@ -403,6 +421,9 @@ void menu() { dialog::addItem(XLAT("take screenshot"), 'z'); dialog::add_action([] () { + #if ISWEB + shot::take("new window"); + #else static string pngfile = "hqshot.png"; static string svgfile = "svgshot.svg"; string& file = make_svg ? svgfile : pngfile; @@ -410,6 +431,7 @@ void menu() { shot::take(file); return true; }); + #endif }); dialog::addBack(); dialog::display();