…aaand add PREFIX to the freebsd makefile too
[voxelands-alt.git] / src / graphics / wm.c
blobda89144f772ecac2566d2a2ca667ad39688d5e0b
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"
23 #include "graphics.h"
25 #include <string.h>
27 wm_t wm_data = {
29 600,
30 1024,
35 30,
36 30,
37 NULL,
38 1000.0,
42 /* command width setter */
43 int wm_width_setter(char* value)
45 int v = strtol(value,NULL,10);
46 if (v > 0) {
47 wm_data.size.width = v;
48 wm_resize();
50 return 0;
53 /* command height setter */
54 int wm_height_setter(char* value)
56 int v = strtol(value,NULL,10);
57 if (v > 0) {
58 wm_data.size.height = v;
59 wm_resize();
61 return 0;
64 /* command frame cap setter */
65 int wm_cap_setter(char* value)
67 int v = strtol(value,NULL,10);
68 if (v > 0)
69 wm_data.frame_cap = v;
70 return 0;
73 /* command fullscreen setter */
74 int wm_fullscreen_setter(char* value)
76 int v = !!strtol(value,NULL,10);
77 wm_toggle_fullscreen(v);
78 return 0;
81 /* screen capture - take a screenshot, save to file */
82 void wm_capture(char* file)
84 char* fmt;
85 image_t *p;
87 p = image_load_fromscreen(0,0,wm_data.size.width,wm_data.size.height,0);
88 if (!p) {
89 vlprintf(CN_ERROR "Could not grab screen data");
90 return;
93 fmt = config_get("wm.capture_format");
94 if (!fmt || !strcmp(fmt,"png")) {
95 if (!file)
96 file = "screenshot.png";
97 image_save_png(p,file);
98 }else if (!strcmp(fmt,"tga")) {
99 if (!file)
100 file = "screenshot.tga";
101 image_save_tga(p,file);
102 }else if (!strcmp(fmt,"bmp")) {
103 if (!file)
104 file = "screenshot.bmp";
105 image_save_bmp(p,file);
106 }else{
107 vlprintf(CN_ERROR "Unsupported capture format '%s'",fmt);
110 free(p->pixels);
111 free(p);