summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2014-07-26 21:23:46 (GMT)
committer Michael Drake <tlsa@netsurf-browser.org>2014-07-26 21:23:46 (GMT)
commit88b4af2eef0f89b46980cc1bbba77955f445d6b9 (patch)
tree8a7ab553f472d47b00adf53b6daf50c1b7a37241
parent7ebff5169afecd39fcc9161761d88e792b703d82 (diff)
downloadlibnsfb-88b4af2eef0f89b46980cc1bbba77955f445d6b9.tar.gz
libnsfb-88b4af2eef0f89b46980cc1bbba77955f445d6b9.tar.bz2
Add support for resizable surfaces and implement it for SDL surface.
-rw-r--r--include/libnsfb_event.h5
-rw-r--r--src/surface/sdl.c27
2 files changed, 28 insertions, 4 deletions
diff --git a/include/libnsfb_event.h b/include/libnsfb_event.h
index 6944654..f98b5ba 100644
--- a/include/libnsfb_event.h
+++ b/include/libnsfb_event.h
@@ -18,6 +18,7 @@ enum nsfb_event_type_e {
NSFB_EVENT_KEY_UP,
NSFB_EVENT_MOVE_RELATIVE,
NSFB_EVENT_MOVE_ABSOLUTE,
+ NSFB_EVENT_RESIZE
};
@@ -194,6 +195,10 @@ struct nsfb_event_s {
int y;
int z;
} vector;
+ struct {
+ int w; /**< Width in pixels */
+ int h; /**< Height in pixels */
+ } resize; /**< Window resize event: NSFB_EVENT_RESIZE */
} value;
};
diff --git a/src/surface/sdl.c b/src/surface/sdl.c
index 82e36f8..8a73581 100644
--- a/src/surface/sdl.c
+++ b/src/surface/sdl.c
@@ -415,8 +415,7 @@ sdlcopy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox)
static int sdl_set_geometry(nsfb_t *nsfb, int width, int height,
enum nsfb_format_e format)
{
- if (nsfb->surface_priv != NULL)
- return -1; /* fail if surface already initialised */
+ SDL_Surface *sdl_screen;
nsfb->width = width;
nsfb->height = height;
@@ -427,6 +426,21 @@ static int sdl_set_geometry(nsfb_t *nsfb, int width, int height,
nsfb->plotter_fns->copy = sdlcopy;
+ if (nsfb->surface_priv != NULL) {
+ sdl_screen = SDL_SetVideoMode(nsfb->width,
+ nsfb->height,
+ nsfb->bpp,
+ SDL_SWSURFACE | SDL_RESIZABLE);
+ if (sdl_screen == NULL ) {
+ fprintf(stderr, "Unable to resize video: %s\n", SDL_GetError());
+ return -1;
+ }
+
+ nsfb->surface_priv = sdl_screen;
+ nsfb->ptr = sdl_screen->pixels;
+ nsfb->linelen = sdl_screen->pitch;
+ }
+
return 0;
}
@@ -452,7 +466,7 @@ static int sdl_initialise(nsfb_t *nsfb)
sdl_screen = SDL_SetVideoMode(nsfb->width,
nsfb->height,
nsfb->bpp,
- SDL_SWSURFACE);
+ SDL_SWSURFACE | SDL_RESIZABLE);
if (sdl_screen == NULL ) {
fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
@@ -533,7 +547,7 @@ static bool sdl_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
if (timeout == 0) {
got_event = SDL_PollEvent(&sdlevent);
- } else {
+ } else {
if (timeout > 0) {
/* setup wake timer to ensure the wait event below exits no later
* than when the timeout has occoured.
@@ -638,6 +652,11 @@ static bool sdl_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
event->value.controlcode = NSFB_CONTROL_TIMEOUT;
break;
+ case SDL_VIDEORESIZE:
+ event->type = NSFB_EVENT_RESIZE;
+ event->value.resize.w = sdlevent.resize.w;
+ event->value.resize.h = sdlevent.resize.h;
+ break;
}
return true;