_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

sdl.cpp File Reference
#include "stratagus.h"
#include "online_service.h"
#include <map>
#include <string>
#include <vector>
#include <limits.h>
#include <math.h>
#include "SDL.h"
#include "SDL_syswm.h"
#include <sys/socket.h>
#include <shellapi.h>
#include "editor.h"
#include "font.h"
#include "game.h"
#include "interface.h"
#include "minimap.h"
#include "network.h"
#include "parameters.h"
#include "sound.h"
#include "sound_server.h"
#include "translate.h"
#include "ui.h"
#include "unit.h"
#include "video.h"
#include "widgets.h"

sdl.cpp - SDL video support.

enum  PROCESS_DPI_AWARENESS { PROCESS_DPI_UNAWARE = 0, PROCESS_SYSTEM_DPI_AWARE = 1, PROCESS_PER_MONITOR_DPI_AWARE = 2 }
 
typedef enum PROCESS_DPI_AWARENESS PROCESS_DPI_AWARENESS
 
SDL_Window * TheWindow
 The SDL screen. More...
 
SDL_Renderer * TheRenderer = NULL
 Internal screen. More...
 
SDL_Texture * TheTexture
 Internal screen. More...
 
SDL_Surface * TheScreen
 Internal screen. More...
 
static SDL_Rect Rects [100]
 Internal screen. More...
 
static int NumRects
 
static std::map< int, std::string > Key2Str
 
static std::map< std::string, int > Str2Key
 
double FrameTicks
 
const EventCallbackCallbacks
 Frame length in ms. More...
 
bool IsSDLWindowVisible = true
 Flag telling if the SDL window is visible. More...
 
uint8_t SizeChangeCounter = 0
 Just a counter to cache window data on in other places when the size changes. More...
 
static bool dummyRenderer = false
 
uint32_t SDL_CUSTOM_KEY_UP
 
static Uint32 LastTick = 0
 
static int RefreshRate = 0
 
void SetVideoSync ()
 Initializes video synchronization. More...
 
static void InitKey2Str ()
 
static void setDpiAware ()
 
void InitVideoSdl ()
 
int VideoValidResolution (int w, int h)
 Check if a resolution is valid. More...
 
void InvalidateArea (int x, int y, int w, int h)
 
void Invalidate ()
 Simply invalidates whole window or screen. More...
 
static bool isTextInput (int key)
 
static void SdlDoEvent (const EventCallback &callbacks, SDL_Event &event)
 
void SetCallbacks (const EventCallback *callbacks)
 Set the current callbacks. More...
 
const EventCallbackGetCallbacks ()
 Get the current callbacks. More...
 
void WaitEventsOneFrame ()
 Process all system events. Returns if the time for a frame is over. More...
 
static void RenderBenchmarkOverlay ()
 
void RealizeVideoMemory ()
 Realize video memory. More...
 
void SdlLockScreen ()
 Init SDL video hardware driver. More...
 
void SdlUnlockScreen ()
 Do SDL hardware lock. More...
 
const char * SdlKey2Str (int key)
 Convert a SDLKey to a string. More...
 
int Str2SdlKey (const char *str)
 
bool SdlGetGrabMouse ()
 Check if the mouse is grabbed. More...
 
void ToggleGrabMouse (int mode)
 Toggle mouse grab mode. More...
 
void ToggleFullScreen ()
 Toggle full screen mode. More...
 

Typedef Documentation

◆ PROCESS_DPI_AWARENESS

Enumeration Type Documentation

◆ PROCESS_DPI_AWARENESS

Enumerator
PROCESS_DPI_UNAWARE 
PROCESS_SYSTEM_DPI_AWARE 
PROCESS_PER_MONITOR_DPI_AWARE 

Function Documentation

◆ GetCallbacks()

const EventCallback* GetCallbacks ( )

Get the current callbacks.

Get the current callbacks

◆ InitKey2Str()

static void InitKey2Str ( )
static

Initialize SDLKey to string map

◆ InitVideoSdl()

void InitVideoSdl ( )

Initialize the video part for SDL.

◆ Invalidate()

void Invalidate ( )

Simply invalidates whole window or screen.

Invalidate whole window

◆ InvalidateArea()

void InvalidateArea ( int  x,
int  y,
int  w,
int  h 
)

Invalidate some area

Parameters
xscreen pixel X position.
yscreen pixel Y position.
wwidth of rectangle in pixels.
hheight of rectangle in pixels.

◆ isTextInput()

static bool isTextInput ( int  key)
static

◆ RealizeVideoMemory()

void RealizeVideoMemory ( )

Realize video memory.

◆ RenderBenchmarkOverlay()

static void RenderBenchmarkOverlay ( )
static

◆ SdlDoEvent()

static void SdlDoEvent ( const EventCallback callbacks,
SDL_Event &  event 
)
static

Handle interactive input event.

Parameters
callbacksCallback structure for events.
eventSDL event structure pointer.

◆ SdlGetGrabMouse()

bool SdlGetGrabMouse ( )

Check if the mouse is grabbed.

Check if the mouse is grabbed

◆ SdlKey2Str()

const char* SdlKey2Str ( int  key)

Convert a SDLKey to a string.

Convert a SDLKey to a string

◆ SdlLockScreen()

void SdlLockScreen ( )

Init SDL video hardware driver.

Lock the screen for write access.

◆ SdlUnlockScreen()

void SdlUnlockScreen ( )

Do SDL hardware lock.

Unlock the screen for write access.

◆ SetCallbacks()

void SetCallbacks ( const EventCallback callbacks)

Set the current callbacks.

Set the current callbacks

◆ setDpiAware()

static void setDpiAware ( )
static

◆ SetVideoSync()

void SetVideoSync ( )

Initializes video synchronization.

Initialise video sync. Calculate the length of video frame and any simulation skips.

See also
VideoSyncSpeed
SkipFrames
FrameTicks

◆ Str2SdlKey()

int Str2SdlKey ( const char *  str)

Convert a string to SDLKey

◆ ToggleFullScreen()

void ToggleFullScreen ( )

Toggle full screen mode.

Toggle full screen mode.

◆ ToggleGrabMouse()

void ToggleGrabMouse ( int  mode)

Toggle mouse grab mode.

Toggle grab mouse.

Parameters
modeWanted mode, 1 grab, -1 not grab, 0 toggle.

◆ VideoValidResolution()

int VideoValidResolution ( int  w,
int  h 
)

Check if a resolution is valid.

Check if a resolution is valid

Parameters
wWidth
hHeight

◆ WaitEventsOneFrame()

void WaitEventsOneFrame ( )

Process all system events. Returns if the time for a frame is over.

Wait for interactive input event for one frame.

Handles system events, joystick, keyboard, mouse. Handles the network messages. Handles the sound queue.

All events available are fetched. Sound and network only if available. Returns if the time for one frame is over.

Variable Documentation

◆ Callbacks

const EventCallback* Callbacks

Frame length in ms.

◆ dummyRenderer

bool dummyRenderer = false
static

◆ FrameTicks

double FrameTicks

◆ IsSDLWindowVisible

bool IsSDLWindowVisible = true

Flag telling if the SDL window is visible.

◆ Key2Str

std::map<int, std::string> Key2Str
static

◆ LastTick

Uint32 LastTick = 0
static

Realize video memory.

◆ NumRects

int NumRects
static

◆ Rects

SDL_Rect Rects[100]
static

Internal screen.

◆ RefreshRate

int RefreshRate = 0
static

◆ SDL_CUSTOM_KEY_UP

uint32_t SDL_CUSTOM_KEY_UP

◆ SizeChangeCounter

uint8_t SizeChangeCounter = 0

Just a counter to cache window data on in other places when the size changes.

◆ Str2Key

std::map<std::string, int> Str2Key
static

◆ TheRenderer

SDL_Renderer* TheRenderer = NULL

Internal screen.

◆ TheScreen

SDL_Surface* TheScreen

Internal screen.

◆ TheTexture

SDL_Texture* TheTexture

Internal screen.

◆ TheWindow

SDL_Window* TheWindow

The SDL screen.

(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.