mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 14:02:59 +00:00 
			
		
		
		
	web:: 'take screenshot' feature now creates a SVG file and opens it in a new window
This commit is contained in:
		| @@ -316,12 +316,10 @@ void handleKeyNormal(int sym, int uni) { | |||||||
|  |  | ||||||
|   if(cheater && sym < 256 && sym > 0) { |   if(cheater && sym < 256 && sym > 0) { | ||||||
|     if(applyCheat(uni, mouseover)) |     if(applyCheat(uni, mouseover)) | ||||||
|       sym = 0; |       uni = sym = 0; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   #if ISMOBILE   |   if(uni == 'A') { pushScreen(shot::menu); uni = sym = 0; } | ||||||
|   if(uni == 'A' && !cheater) pushScreen(shot::menu); |  | ||||||
|   #endif |  | ||||||
|  |  | ||||||
|   if(DEFAULTNOR(sym)) handlePanning(sym, uni); |   if(DEFAULTNOR(sym)) handlePanning(sym, uni); | ||||||
|    |    | ||||||
|   | |||||||
| @@ -169,6 +169,11 @@ bool applyCheat(char u, cell *c = NULL) { | |||||||
|     pushScreen(mapeditor::showDrawEditor); |     pushScreen(mapeditor::showDrawEditor); | ||||||
|     return true; |     return true; | ||||||
|     } |     } | ||||||
|  | #elif CAP_SHOT | ||||||
|  |   if(u == 'A') { | ||||||
|  |     pushScreen(shot::menu); | ||||||
|  |     return true; | ||||||
|  |     } | ||||||
| #endif | #endif | ||||||
|   if(u == 'T') { |   if(u == 'T') { | ||||||
|     items[randomTreasure2(10)] += 10; |     items[randomTreasure2(10)] += 10; | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								hyper.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								hyper.h
									
									
									
									
									
								
							| @@ -1864,7 +1864,8 @@ void resetGeometry(); | |||||||
| namespace shot { | namespace shot { | ||||||
|   extern int shotx, shoty, shotformat; |   extern int shotx, shoty, shotformat; | ||||||
|   extern bool make_svg; |   extern bool make_svg; | ||||||
|   extern ld gamma; |   extern ld gamma, fade; | ||||||
|  |   extern string caption; | ||||||
|   void menu(); |   void menu(); | ||||||
|   void default_screenshot_content(); |   void default_screenshot_content(); | ||||||
|   void take(string fname, const function<void()>& what = default_screenshot_content); |   void take(string fname, const function<void()>& what = default_screenshot_content); | ||||||
|   | |||||||
| @@ -12,7 +12,12 @@ namespace svg { | |||||||
| #if ISMOBILE==0 | #if ISMOBILE==0 | ||||||
| // svg renderer | // svg renderer | ||||||
| namespace svg { | namespace svg { | ||||||
|   FILE *f; |   #if ISWEB | ||||||
|  |   shstream f; | ||||||
|  |   #else | ||||||
|  |   fhstream f; | ||||||
|  |   #endif | ||||||
|  |    | ||||||
|   bool in = false; |   bool in = false; | ||||||
|    |    | ||||||
|   ld cta(color_t col) { |   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) { |   void circle(int x, int y, int size, color_t col, color_t fillcol) { | ||||||
|     if(!invisible(col) || !invisible(fillcol)) { |     if(!invisible(col) || !invisible(fillcol)) { | ||||||
|       if(vid.stretch == 1) |       if(vid.stretch == 1) | ||||||
|         fprintf(f, "<circle cx='%s' cy='%s' r='%s' %s/>\n", |         println(f, "<circle cx='", coord(x), "' cy='", coord(y), "' r='", coord(size), "' ", stylestr(fillcol, col), "/>"); | ||||||
|           coord(x), coord(y), coord(size), stylestr(fillcol, col)); |  | ||||||
|       else |       else | ||||||
|         fprintf(f, "<ellipse cx='%s' cy='%s' rx='%s' ry='%s' %s/>\n", |         println(f, "<ellipse cx='", coord(x), "' cy='", coord(y), "' rx='", coord(size), "' ry='", coord(size*vid.stretch), "' ", stylestr(fillcol, col), "/>"); | ||||||
|           coord(x), coord(y), coord(size), coord(size*vid.stretch), stylestr(fillcol, col)); |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|    |    | ||||||
|   string link; |   string link; | ||||||
|    |    | ||||||
|   void startstring() { |   void startstring() { | ||||||
|     if(link != "") fprintf(f, "<a xlink:href=\"%s\" xlink:show=\"replace\">", link.c_str()); |     if(link != "") print(f, "<a xlink:href=\"", link, "\" xlink:show=\"replace\">"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   void stopstring() { |   void stopstring() { | ||||||
|     if(link != "") fprintf(f, "</a>"); |     if(link != "") print(f, "</a>"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   string font = "Times"; |   string font = "Times"; | ||||||
| @@ -119,17 +122,17 @@ namespace svg { | |||||||
|           str2 += "\\#"; |           str2 += "\\#"; | ||||||
|         else str2 += str[i]; |         else str2 += str[i]; | ||||||
|       if(uselatex) str2 = string("\\myfont{")+coord(size)+"}{" + str2 + "}";   |       if(uselatex) str2 = string("\\myfont{")+coord(size)+"}{" + str2 + "}";   | ||||||
|       fprintf(f, "<text x='%s' y='%s' text-anchor='%s' ", |        | ||||||
|         coord(x), coord(y+size*.4),  |       print(f, "<text x='", coord(x), "' y='", coord(y+size*.4), "' text-anchor='", align == 8 ? "middle" : | ||||||
|         align == 8 ? "middle" : |  | ||||||
|         align < 8 ? "start" : |         align < 8 ? "start" : | ||||||
|         "end"); |         "end", "' "); | ||||||
|       if(!uselatex) |       if(!uselatex) | ||||||
|         fprintf(f, "font-family='%s' font-size='%s' ", font.c_str(), coord(size));       |         print(f, "font-family='", font, "' font-size='", coord(size), "' "); | ||||||
|       fprintf(f, "%s>%s</text>", |       print(f,  | ||||||
|         stylestr(col, frame ? 0x0000000FF : 0, (1<<get_sightrange())*dfc/40), str2.c_str()); |         stylestr(col, frame ? 0x0000000FF : 0, (1<<get_sightrange())*dfc/40),  | ||||||
|  |         ">", str2, "</text>"); | ||||||
|       stopstring(); |       stopstring(); | ||||||
|       fprintf(f, "\n"); |       println(f); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|    |    | ||||||
| @@ -141,26 +144,41 @@ namespace svg { | |||||||
|     startstring(); |     startstring(); | ||||||
|     for(int i=0; i<polyi; i++) { |     for(int i=0; i<polyi; i++) { | ||||||
|       if(i == 0) |       if(i == 0) | ||||||
|         fprintf(f, "<path d=\"M "); |         print(f, "<path d=\"M "); | ||||||
|       else |       else | ||||||
|         fprintf(f, " L "); |         print(f, " L "); | ||||||
|       fprintf(f, "%s %s", coord(polyx[i]), coord(polyy[i])); |       print(f, coord(polyx[i]), " ", coord(polyy[i])); | ||||||
|       } |       } | ||||||
|      |      | ||||||
|     fprintf(f, "\" %s/>", 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(); |     stopstring(); | ||||||
|     fprintf(f, "\n"); |     println(f); | ||||||
|     } |     } | ||||||
|    |    | ||||||
|   void render(const string& fname, const function<void()>& what) { |   void render(const string& fname, const function<void()>& what) { | ||||||
|     dynamicval<bool> v2(in, true); |     dynamicval<bool> v2(in, true); | ||||||
|     dynamicval<bool> v3(vid.usingGL, false); |     dynamicval<bool> v3(vid.usingGL, false); | ||||||
|      |      | ||||||
|     f = fopen(fname.c_str(), "wt"); |     #if ISWEB | ||||||
|     fprintf(f, "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"%s\" height=\"%s\">\n", coord(vid.xres), coord(vid.yres)); |     f.s = ""; | ||||||
|  |     #else | ||||||
|  |     f.f = fopen(fname.c_str(), "wt"); | ||||||
|  |     #endif | ||||||
|  |  | ||||||
|  |     println(f, "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"", coord(vid.xres), "\" height=\"", coord(vid.yres), "\">"); | ||||||
|     what(); |     what(); | ||||||
|     fprintf(f, "</svg>\n"); |     println(f, "</svg>"); | ||||||
|     fclose(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 | #if CAP_COMMANDLINE | ||||||
| @@ -312,7 +330,7 @@ void take(string fname, const function<void()>& what) { | |||||||
|     glbuf.enable(); |     glbuf.enable(); | ||||||
|     current_display->set_viewport(0); |     current_display->set_viewport(0); | ||||||
|  |  | ||||||
|     dynamicval v8(backcolor, transparent ? 0xFF000000 : backcolor); |     dynamicval<color_t> v8(backcolor, transparent ? 0xFF000000 : backcolor); | ||||||
|     #if CAP_RUG |     #if CAP_RUG | ||||||
|     if(rug::rugged && !rug::renderonce) rug::prepareTexture(); |     if(rug::rugged && !rug::renderonce) rug::prepareTexture(); | ||||||
|     #endif |     #endif | ||||||
| @@ -403,6 +421,9 @@ void menu() { | |||||||
|    |    | ||||||
|   dialog::addItem(XLAT("take screenshot"), 'z'); |   dialog::addItem(XLAT("take screenshot"), 'z'); | ||||||
|   dialog::add_action([] () {  |   dialog::add_action([] () {  | ||||||
|  |     #if ISWEB | ||||||
|  |     shot::take("new window"); | ||||||
|  |     #else | ||||||
|     static string pngfile = "hqshot.png"; |     static string pngfile = "hqshot.png"; | ||||||
|     static string svgfile = "svgshot.svg"; |     static string svgfile = "svgshot.svg"; | ||||||
|     string& file = make_svg ? svgfile : pngfile; |     string& file = make_svg ? svgfile : pngfile; | ||||||
| @@ -410,6 +431,7 @@ void menu() { | |||||||
|       shot::take(file); |       shot::take(file); | ||||||
|       return true; |       return true; | ||||||
|       }); |       }); | ||||||
|  |     #endif | ||||||
|     }); |     }); | ||||||
|   dialog::addBack(); |   dialog::addBack(); | ||||||
|   dialog::display(); |   dialog::display(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue