2019-12-12 17:32:41 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
// This device code is based on the original SDL device implementation
|
|
|
|
// contributed by Shane Parker (sirshane).
|
|
|
|
|
2021-08-27 17:55:04 +02:00
|
|
|
#ifndef IRR_C_IRR_DEVICE_SDL_H_INCLUDED
|
|
|
|
#define IRR_C_IRR_DEVICE_SDL_H_INCLUDED
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
#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:
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CIrrDeviceSDL(const SIrrlichtCreationParameters& param);
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~CIrrDeviceSDL();
|
|
|
|
|
|
|
|
//! runs the device. Returns false if device wants to be deleted
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool run() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! pause execution temporarily
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void yield() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! pause execution for a specified time
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void sleep(u32 timeMs, bool pauseTimer) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! sets the caption of the window
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setWindowCaption(const wchar_t* text) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! returns if window is active. if not, nothing need to be drawn
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isWindowActive() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! returns if window has focus.
|
2021-08-27 14:55:10 +02:00
|
|
|
bool isWindowFocused() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! returns if window is minimized.
|
2021-08-27 14:55:10 +02:00
|
|
|
bool isWindowMinimized() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! returns color format of the window.
|
2021-08-27 14:55:10 +02:00
|
|
|
video::ECOLOR_FORMAT getColorFormat() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! presents a surface in the client area
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! notifies the device that it should close itself
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void closeDevice() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! \return Returns a pointer to a list with all video modes supported
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual video::IVideoModeList* getVideoModeList() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets if the window should be resizable in windowed mode.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setResizable(bool resize=false) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Minimizes the window.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void minimizeWindow() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Maximizes the window.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void maximizeWindow() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Restores the window size.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void restoreWindow() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Get the position of this window on screen
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual core::position2di getWindowPosition() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Activate any joysticks, and generate events for them.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Set the current Gamma Value for the Display
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast ) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Get the current Gamma Value for the Display
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast ) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Get the device type
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual E_DEVICE_TYPE getType() const IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
2021-08-26 23:09:08 +02:00
|
|
|
return EIDT_SDL;
|
2019-12-12 17:32:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Implementation of the linux cursor control
|
|
|
|
class CCursorControl : public gui::ICursorControl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
CCursorControl(CIrrDeviceSDL* dev)
|
|
|
|
: Device(dev), IsVisible(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Changes the visible state of the mouse cursor.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setVisible(bool visible) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
IsVisible = visible;
|
|
|
|
if ( visible )
|
|
|
|
SDL_ShowCursor( SDL_ENABLE );
|
|
|
|
else
|
|
|
|
SDL_ShowCursor( SDL_DISABLE );
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns if the cursor is currently visible.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isVisible() const IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
return IsVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the new position of the cursor.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setPosition(const core::position2d<f32> &pos) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
setPosition(pos.X, pos.Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the new position of the cursor.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setPosition(f32 x, f32 y) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
setPosition((s32)(x*Device->Width), (s32)(y*Device->Height));
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the new position of the cursor.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setPosition(const core::position2d<s32> &pos) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
setPosition(pos.X, pos.Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the new position of the cursor.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setPosition(s32 x, s32 y) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
SDL_WarpMouse( x, y );
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns the current position of the mouse cursor.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual const core::position2d<s32>& getPosition(bool updateCursor) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
if ( updateCursor )
|
|
|
|
updateCursorPos();
|
|
|
|
return CursorPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns the current position of the mouse cursor.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual core::position2d<f32> getRelativePosition(bool updateCursor) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
if ( updateCursor )
|
|
|
|
updateCursorPos();
|
|
|
|
return core::position2d<f32>(CursorPos.X / (f32)Device->Width,
|
|
|
|
CursorPos.Y / (f32)Device->Height);
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setReferenceRect(core::rect<s32>* rect=0) IRR_OVERRIDE
|
2019-12-12 17:32:41 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
//! create the driver
|
|
|
|
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 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif // _IRR_COMPILE_WITH_SDL_DEVICE_
|
2021-08-27 17:55:04 +02:00
|
|
|
#endif // IRR_C_IRR_DEVICE_SDL_H_INCLUDED
|