src/events/SDL_resize.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 11 Jul 2007 07:47:47 +0000
branchSDL-1.2
changeset 4048 3e380b8247aa
parent 1402 d910939febfa
child 4159 a1b03ba2fcd0
permissions -rw-r--r--
Added more release notes.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
/* Resize event handling code for SDL */
slouken@0
    25
slouken@0
    26
#include "SDL_events.h"
slouken@0
    27
#include "SDL_events_c.h"
slouken@1361
    28
#include "../video/SDL_sysvideo.h"
slouken@0
    29
slouken@0
    30
slouken@0
    31
/* Keep the last resize event so we don't post duplicates */
slouken@0
    32
static struct {
slouken@0
    33
	int w;
slouken@0
    34
	int h;
slouken@0
    35
} last_resize;
slouken@0
    36
slouken@0
    37
/* This is global for SDL_eventloop.c */
slouken@0
    38
int SDL_PrivateResize(int w, int h)
slouken@0
    39
{
slouken@0
    40
	int posted;
slouken@0
    41
	SDL_Event events[32];
slouken@0
    42
slouken@0
    43
	/* See if this event would change the video surface */
icculus@1190
    44
	if ( !w || !h
icculus@1190
    45
#ifndef __OS2__
icculus@1190
    46
            || ((last_resize.w == w) && (last_resize.h == h))
icculus@1190
    47
#endif
icculus@1190
    48
    ) {
slouken@0
    49
		return(0);
slouken@0
    50
	}
slouken@0
    51
        last_resize.w = w;
slouken@0
    52
        last_resize.h = h;
slouken@0
    53
	if ( ! SDL_VideoSurface ||
slouken@0
    54
	     ((w == SDL_VideoSurface->w) && (h == SDL_VideoSurface->h)) ) {
slouken@0
    55
		return(0);
slouken@0
    56
	}
slouken@0
    57
slouken@0
    58
	/* Pull out all old resize events */
slouken@0
    59
	SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]),
slouken@0
    60
	                    SDL_GETEVENT, SDL_VIDEORESIZEMASK);
slouken@0
    61
slouken@0
    62
	/* Post the event, if desired */
slouken@0
    63
	posted = 0;
slouken@0
    64
	if ( SDL_ProcessEvents[SDL_VIDEORESIZE] == SDL_ENABLE ) {
slouken@0
    65
		SDL_Event event;
slouken@0
    66
		event.type = SDL_VIDEORESIZE;
slouken@0
    67
		event.resize.w = w;
slouken@0
    68
		event.resize.h = h;
slouken@0
    69
		if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) {
slouken@0
    70
			posted = 1;
slouken@0
    71
			SDL_PushEvent(&event);
slouken@0
    72
		}
slouken@0
    73
	}
slouken@0
    74
	return(posted);
slouken@0
    75
}