#ifndef __C_IRR_DEVICE_SDL_H_INCLUDED__
#define __C_IRR_DEVICE_SDL_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
#include "IrrlichtDevice.h"
#include "CIrrDeviceStub.h"
#include "IImagePresenter.h"
#include "ICursorControl.h"
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
namespace irr
{
class CIrrDeviceSDL : public CIrrDeviceStub, video::IImagePresenter
{
public:
CIrrDeviceSDL(const SIrrlichtCreationParameters& param);
virtual ~CIrrDeviceSDL();
virtual bool run();
virtual void yield();
virtual void sleep(u32 timeMs, bool pauseTimer);
virtual void setWindowCaption(const wchar_t* text);
virtual bool isWindowActive() const;
bool isWindowFocused() const;
bool isWindowMinimized() const;
video::ECOLOR_FORMAT getColorFormat() const;
virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0);
virtual void closeDevice();
video::IVideoModeList* getVideoModeList();
virtual void setResizable(bool resize=false);
virtual void minimizeWindow();
virtual void maximizeWindow();
virtual void restoreWindow();
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);
virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast );
virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast );
virtual E_DEVICE_TYPE getType() const
{
return EIDT_SDL;
}
class CCursorControl : public gui::ICursorControl
{
public:
CCursorControl(CIrrDeviceSDL* dev)
: Device(dev), IsVisible(true)
{
}
virtual void setVisible(bool visible)
{
IsVisible = visible;
if ( visible )
SDL_ShowCursor( SDL_ENABLE );
else
SDL_ShowCursor( SDL_DISABLE );
}
virtual bool isVisible() const
{
return IsVisible;
}
virtual void setPosition(const core::position2d<f32> &pos)
{
setPosition(pos.X, pos.Y);
}
virtual void setPosition(f32 x, f32 y)
{
setPosition((s32)(x*Device->Width), (s32)(y*Device->Height));
}
virtual void setPosition(const core::position2d<s32> &pos)
{
setPosition(pos.X, pos.Y);
}
virtual void setPosition(s32 x, s32 y)
{
SDL_WarpMouse( x, y );
}
virtual const core::position2d<s32>& getPosition()
{
updateCursorPos();
return CursorPos;
}
virtual core::position2d<f32> getRelativePosition()
{
updateCursorPos();
return core::position2d<f32>(CursorPos.X / (f32)Device->Width,
CursorPos.Y / (f32)Device->Height);
}
virtual void setReferenceRect(core::rect<s32>* rect=0)
{
}
private:
void updateCursorPos()
{
CursorPos.X = Device->MouseX;
CursorPos.Y = Device->MouseY;
if (CursorPos.X < 0)
CursorPos.X = 0;
if (CursorPos.X > (s32)Device->Width)
CursorPos.X = Device->Width;
if (CursorPos.Y < 0)
CursorPos.Y = 0;
if (CursorPos.Y > (s32)Device->Height)
CursorPos.Y = Device->Height;
}
CIrrDeviceSDL* Device;
core::position2d<s32> CursorPos;
bool IsVisible;
};
private:
void createDriver();
bool createWindow();
void createKeyMap();
SDL_Surface* Screen;
int SDL_Flags;
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
core::array<SDL_Joystick*> Joysticks;
#endif
s32 MouseX, MouseY;
u32 MouseButtonStates;
u32 Width, Height;
bool Resizable;
bool WindowHasFocus;
bool WindowMinimized;
struct SKeyMap
{
SKeyMap() {}
SKeyMap(s32 x11, s32 win32)
: SDLKey(x11), Win32Key(win32)
{
}
s32 SDLKey;
s32 Win32Key;
bool operator<(const SKeyMap& o) const
{
return SDLKey<o.SDLKey;
}
};
core::array<SKeyMap> KeyMap;
SDL_SysWMinfo Info;
};
}
#endif
#endif