projects
/
dosdemo
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
bb8b987
)
SDL backend: toggle fullscreen with 'f'
author
John Tsiombikas
<nuclear@mutantstargoat.com>
Wed, 21 Sep 2016 04:47:27 +0000
(07:47 +0300)
committer
John Tsiombikas
<nuclear@mutantstargoat.com>
Wed, 21 Sep 2016 04:47:27 +0000
(07:47 +0300)
src/sdl/main.c
patch
|
blob
|
history
diff --git
a/src/sdl/main.c
b/src/sdl/main.c
index
e5eda65
..
6b65796
100644
(file)
--- a/
src/sdl/main.c
+++ b/
src/sdl/main.c
@@
-5,6
+5,7
@@
#include "demo.h"
static void handle_event(SDL_Event *ev);
#include "demo.h"
static void handle_event(SDL_Event *ev);
+static void toggle_fullscreen(void);
static int quit;
static long start_time;
static int quit;
static long start_time;
@@
-12,13
+13,13
@@
static SDL_Surface *fbsurf;
static int fbscale = 2;
static int xsz, ysz;
static int fbscale = 2;
static int xsz, ysz;
+static unsigned int sdl_flags = SDL_SWSURFACE;
int main(int argc, char **argv)
{
int s, i, j;
char *env;
unsigned short *sptr, *dptr;
int main(int argc, char **argv)
{
int s, i, j;
char *env;
unsigned short *sptr, *dptr;
- unsigned int sdl_flags = SDL_SWSURFACE;
if((env = getenv("FBSCALE")) && (s = atoi(env))) {
fbscale = s;
if((env = getenv("FBSCALE")) && (s = atoi(env))) {
fbscale = s;
@@
-66,7
+67,7
@@
int main(int argc, char **argv)
}
sptr = fb_pixels;
}
sptr = fb_pixels;
- dptr = fbsurf->pixels;
+ dptr = (unsigned short*)fbsurf->pixels + (fbsurf->w - xsz) / 2;
for(i=0; i<fb_height; i++) {
for(j=0; j<fb_width; j++) {
int x, y;
for(i=0; i<fb_height; i++) {
for(j=0; j<fb_width; j++) {
int x, y;
@@
-74,12
+75,12
@@
int main(int argc, char **argv)
for(y=0; y<fbscale; y++) {
for(x=0; x<fbscale; x++) {
for(y=0; y<fbscale; y++) {
for(x=0; x<fbscale; x++) {
- dptr[y * xsz + x] = pixel;
+ dptr[y * fbsurf->w + x] = pixel;
}
}
dptr += fbscale;
}
}
}
dptr += fbscale;
}
- dptr += xsz * (fbscale - 1);
+ dptr += (fbsurf->w - fb_width) * fbscale;
}
if(SDL_MUSTLOCK(fbsurf)) {
}
if(SDL_MUSTLOCK(fbsurf)) {
@@
-113,6
+114,12
@@
static void handle_event(SDL_Event *ev)
case SDL_KEYDOWN:
case SDL_KEYUP:
case SDL_KEYDOWN:
case SDL_KEYUP:
+ if(ev->key.keysym.sym == 'f') {
+ if(ev->key.state == SDL_PRESSED) {
+ toggle_fullscreen();
+ }
+ break;
+ }
demo_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED ? 1 : 0);
break;
demo_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED ? 1 : 0);
break;
@@
-135,3
+142,17
@@
static void handle_event(SDL_Event *ev)
break;
}
}
break;
}
}
+
+static void toggle_fullscreen(void)
+{
+ SDL_Surface *newsurf;
+ unsigned int newflags = sdl_flags ^ SDL_FULLSCREEN;
+
+ if(!(newsurf = SDL_SetVideoMode(xsz, ysz, fb_bpp, newflags))) {
+ fprintf(stderr, "failed to go %s\n", newflags & SDL_FULLSCREEN ? "fullscreen" : "windowed");
+ return;
+ }
+
+ fbsurf = newsurf;
+ sdl_flags = newflags;
+}