diff --git a/source/src/main.cpp b/source/src/main.cpp index 4c687cdd..3fcd887d 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -146,15 +146,14 @@ const char *screenshotpath(const char *imagepath, const char *suffix) s_sprintf(buf)("screenshots/%s.%s", timestring(), suffix); } path(buf); - return imagepath; + return buf; } -void jpeg_screenshot(char *imagepath) +void jpeg_screenshot(const char *imagepath) { const char *found = findfile(screenshotpath(imagepath, "jpg"), "wb"); - conoutf("writing to file: %s", found); FILE *jpegfile = fopen(found, "wb"); - if(!jpegfile) return; + if(!jpegfile) { conoutf("failed to create: %s", found); return; } struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; @@ -190,10 +189,11 @@ void jpeg_screenshot(char *imagepath) jpeg_destroy_compress(&cinfo); delete[] pixels; + conoutf("writing to file: %s", found); fclose(jpegfile); } -void bmp_screenshot(char *imagepath) +void bmp_screenshot(const char *imagepath) { SDL_Surface *image = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, 24, 0x0000FF, 0x00FF00, 0xFF0000, 0); if(!image) return; @@ -209,12 +209,12 @@ void bmp_screenshot(char *imagepath) } delete[] tmp; const char *found = findfile(screenshotpath(imagepath, "bmp"), "wb"); - conoutf("writing to file: %s", found); SDL_SaveBMP(image, found); + conoutf("writing to file: %s", found); SDL_FreeSurface(image); } -void screenshot(char *imagepath) +void screenshot(const char *imagepath) { switch(screenshottype) { diff --git a/source/src/menus.cpp b/source/src/menus.cpp index e0580465..dfe2eb43 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -695,16 +695,23 @@ void chmenumdl(char *menu, char *mdl, char *anim, char *rotspeed, char *scale) m.scale = max(0, min(atoi(scale), 100)); } +bool parsecolor(color *col, const char *r, const char *g, const char *b, const char *a) +{ + if(!r[0] || !col) return false; // four possible parameter schemes: + if(!g[0]) g = b = r; // grey + if(!b[0]) { a = g; g = b = r; } // grey alpha + col->r = ((float) atoi(r)) / 100; // red green blue + col->g = ((float) atoi(g)) / 100; // red green blue alpha + col->b = ((float) atoi(b)) / 100; + col->alpha = a[0] ? ((float) atoi(a)) / 100 : 1.0; + return true; +} + void menuselectionbgcolor(char *r, char *g, char *b, char *a) { if(!menuselbgcolor) menuselbgcolor = new color; if(!r[0]) { DELETEA(menuselbgcolor); return; } - if(!g[0]) g = b = r; - if(!b[0]) { a = g; g = b = r; } - menuselbgcolor->r = ((float) atoi(r)) / 100; - menuselbgcolor->g = ((float) atoi(g)) / 100; - menuselbgcolor->b = ((float) atoi(b)) / 100; - menuselbgcolor->alpha = a[0] ? ((float) atoi(a)) / 100 : 1.0; + parsecolor(menuselbgcolor, r, g, b, a); } COMMAND(newmenu, ARG_3STR); @@ -784,6 +791,13 @@ bool menukey(int code, bool isdown, int unicode, SDLMod mod) } return true; } + case SDLK_F12: + { + extern void screenshot(const char *imagepath); + if(!curmenu->allowinput) return false; + screenshot(NULL); + break; + } default: { if(!curmenu->allowinput) return false;