wm pt1
[voxelands-alt.git] / src / graphics / wm.c
blob45fe05e242bd4b6dfb8d7a583e9a403ee3c111a5
1 /************************************************************************
2 * wm.c
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
20 #include "common.h"
21 #define _WM_EXPOSE_ALL
22 #include "wm.h"
24 wm_t wm_data = {
26 600,
27 1024,
32 30,
33 30,
34 NULL,
35 1000.0,
39 /* command width setter */
40 int wm_width_setter(char* value)
42 int v = strtol(value,NULL,10);
43 if (v > 0) {
44 wm_data.size.width = v;
45 wm_resize();
47 return 0;
50 /* command height setter */
51 int wm_height_setter(char* value)
53 int v = strtol(value,NULL,10);
54 if (v > 0) {
55 wm_data.size.height = v;
56 wm_resize();
58 return 0;
61 /* command frame cap setter */
62 int wm_cap_setter(char* value)
64 int v = strtol(value,NULL,10);
65 if (v > 0)
66 wm_data.frame_cap = v;
67 return 0;
70 /* command fullscreen setter */
71 int wm_fullscreen_setter(char* value)
73 int v = !!strtol(value,NULL,10);
74 wm_toggle_fullscreen(v);
75 return 0;
78 /* screen capture - take a screenshot, save to file */
79 void wm_capture(char* file)
82 /* TODO: once the rest of the graphics are in, do it */
83 #ifdef DONT_DO_IT_FOR_FUCKS_SAKE
84 char* fmt;
85 image_t *p;
87 p = image_load_fromscreen(0,0,wm_data.width,wm_data.height,0);
88 if (!p) {
89 rtprintf(CN_ERROR "Could not grab screen data");
90 return;
93 fmt = config_get("wm.capture_format");
94 #ifdef RTG_HAVE_JPG
95 if (!fmt || !strcmp(fmt,"jpg")) {
96 if (!file)
97 file = "screenshot.jpg";
98 image_save_jpg(p,file);
99 }else
100 #endif
101 #ifdef RTG_HAVE_PNG
102 if (!fmt || !strcmp(fmt,"png")) {
103 if (!file)
104 file = "screenshot.png";
105 image_save_png(p,file);
106 }else
107 #endif
108 #ifdef RTG_HAVE_TGA
109 if (!fmt || !strcmp(fmt,"tga")) {
110 if (!file)
111 file = "screenshot.tga";
112 image_save_tga(p,file);
113 }else
114 #endif
115 #ifdef RTG_HAVE_BMP
116 if (!fmt || !strcmp(fmt,"bmp")) {
117 if (!file)
118 file = "screenshot.bmp";
119 image_save_bmp(p,file);
120 }else
121 #endif
122 if (fmt) {
123 rtprintf(CN_ERROR "Unsupported capture format '%s'",fmt);
124 }else{
125 rtprintf(CN_ERROR "Unsupported capture format");
128 free(p->pixels);
129 free(p);
130 #endif