diff --git a/Makefile b/Makefile
index 1319eb55b..37eb7ea95 100644
--- a/Makefile
+++ b/Makefile
@@ -93,7 +93,7 @@ SRCMATH = $(wildcard ./src/math/*.cpp)
SRCSYSTEM = $(wildcard ./src/system/*.cpp)
SRCUI = $(wildcard ./src/ui/*.cpp)
SRCUTILS = $(wildcard ./src/utils/*.cpp)
-SRCWINDOW = $(wildcard ./src/window/*.cpp)
+SRCWINDOW = $(wildcard ./src/window/*.cpp) $(wildcard ./src/window/backend/SDL/*.cpp) $(wildcard ./src/window/backend/null/*.cpp)
SRCPHYSICS = $(wildcard ./src/physics/*.cpp) $(wildcard ./src/physics/constraints/*.cpp)
SRCTEST = $(wildcard ./src/test/*.cpp)
@@ -169,6 +169,8 @@ dirs:
@mkdir -p $(OBJDIR)/src/ui
@mkdir -p $(OBJDIR)/src/utils
@mkdir -p $(OBJDIR)/src/window
+ @mkdir -p $(OBJDIR)/src/window/backend/SDL
+ @mkdir -p $(OBJDIR)/src/window/backend/null
@mkdir -p $(OBJDIR)/src/physics
@mkdir -p $(OBJDIR)/src/physics/constraints
@mkdir -p $(OBJDIR)/src/test
diff --git a/ee.creator b/ee.creator
new file mode 100644
index 000000000..e94cbbd30
--- /dev/null
+++ b/ee.creator
@@ -0,0 +1 @@
+[General]
diff --git a/ee.creator.user b/ee.creator.user
new file mode 100644
index 000000000..b71c00d79
--- /dev/null
+++ b/ee.creator.user
@@ -0,0 +1,660 @@
+
+
+
+ GenericProjectManager.GenericProject.Toolchain
+ 0
+
+
+ ProjectExplorer.Project.ActiveTarget
+ 0
+
+
+ ProjectExplorer.Project.EditorSettings
+
+ System
+
+
+
+ ProjectExplorer.Project.Target.0
+
+
+
+ GenericProjectManager.GenericTarget
+ 0
+ 0
+ 0
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ test
+ -e
+ DEBUGBUILD=yes
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=yes
+ clean
+
+ /usr/bin/make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ debug-test
+ debug-test
+ GenericProjectManager.GenericBuildConfiguration
+
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ test
+ -e
+ DEBUGBUILD=no
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=no
+ clean
+
+ /usr/bin/make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ release-test
+ release-test
+ GenericProjectManager.GenericBuildConfiguration
+
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ test
+ -e
+ DEBUGBUILD=yes
+ -e
+ GLES2=yes
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=yes
+ clean
+
+ /usr/bin/make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ debug-test-gles2
+ debug-test-gles2
+ GenericProjectManager.GenericBuildConfiguration
+
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ eeiv
+ -e
+ DEBUGBUILD=yes
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=yes
+ clean
+
+ /usr/bin/make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ debug-eeiv
+ debug-eeiv
+ GenericProjectManager.GenericBuildConfiguration
+
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ eeiv
+ -e
+ DEBUGBUILD=no
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=no
+ clean
+
+ /usr/bin/make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ release-eeiv
+ release-eeiv
+ GenericProjectManager.GenericBuildConfiguration
+
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ -e
+ DYNAMIC=no
+ -e
+ DEBUGBUILD=yes
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=yes
+ clean
+
+ /usr/bin/make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ debug-static-lib
+ debug-static-lib
+ GenericProjectManager.GenericBuildConfiguration
+
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ -e
+ DYNAMIC=no
+ -e
+ DEBUGBUILD=no
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=no
+ clean
+
+ make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ release-static-lib
+ release-static-lib
+ GenericProjectManager.GenericBuildConfiguration
+
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ -e
+ DYNAMIC=yes
+ -e
+ DEBUGBUILD=yes
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=yes
+ clean
+
+ /usr/bin/make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ debug-dynamic-lib
+ debug-dynamic-lib
+ GenericProjectManager.GenericBuildConfiguration
+
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ -e
+ DYNAMIC=yes
+ -e
+ DEBUGBUILD=no
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=no
+ clean
+
+ make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ release-dynamic-lib
+ release-dynamic-lib
+ GenericProjectManager.GenericBuildConfiguration
+
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ fluid
+ -e
+ DEBUGBUILD=yes
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=yes
+ clean
+
+ /usr/bin/make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ debug-fluid
+ debug-fluid
+ GenericProjectManager.GenericBuildConfiguration
+
+
+ /home/programming/projects/EE
+
+
+
+
+ -j4
+ fluid
+
+
+
+
+ GenericProjectManager.GenericMakeStep
+
+ 1
+ Build
+ Build
+ ProjectExplorer.BuildSteps.Build
+
+
+
+
+ -e
+ DEBUGBUILD=yes
+ clean
+
+ /usr/bin/make
+ true
+ $BUILDDIR
+ clean
+ clean
+ ProjectExplorer.ProcessStep
+
+ 1
+ Clean
+ Clean
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ release-fluid
+ release-fluid
+ GenericProjectManager.GenericBuildConfiguration
+
+ 11
+
+
+ 0
+ Deploy
+ Deploy
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+ No deployment
+ No deployment
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+
+ 2
+ /home/programming/projects/EE/eetest-debug
+ false
+
+ /home/programming/projects/EE
+ eetest-debug
+ eetest-debug
+ ProjectExplorer.CustomExecutableRunConfiguration
+ 3768
+ true
+ false
+
+
+
+ 2
+ /home/programming/projects/EE/eetest-release
+ false
+
+ $BUILDDIR
+ eetest-release
+ eetest-release
+ ProjectExplorer.CustomExecutableRunConfiguration
+ 3768
+ true
+ false
+
+
+
+ 2
+ /home/programming/projects/EE/eeiv-debug
+ false
+
+ $BUILDDIR
+ eeiv-debug
+ eeiv-debug
+ ProjectExplorer.CustomExecutableRunConfiguration
+ 3768
+ true
+ false
+
+
+
+ 2
+ /home/programming/projects/EE/eeiv-release
+ false
+
+ $BUILDDIR
+ eeiv-release
+ eeiv-release
+ ProjectExplorer.CustomExecutableRunConfiguration
+ 3768
+ true
+ false
+
+
+
+ 2
+ /home/programming/projects/EE/eefluid-debug
+ false
+
+ $BUILDDIR
+ eefluid-debug
+ eefluid-debug
+ ProjectExplorer.CustomExecutableRunConfiguration
+ 3768
+ true
+ false
+
+
+
+ 2
+ /home/programming/projects/EE/eefluid-release
+ false
+
+ $BUILDDIR
+ eefluid-release
+ eefluid-release
+ ProjectExplorer.CustomExecutableRunConfiguration
+ 3768
+ true
+ false
+
+ 6
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 1
+
+
+ ProjectExplorer.Project.Updater.EnvironmentId
+ {bbaeda53-a008-4abc-a769-1c41d79116d2}
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 8
+
+
diff --git a/ee.linux.cbp b/ee.linux.cbp
index 28a1ee7a7..5043f7464 100644
--- a/ee.linux.cbp
+++ b/ee.linux.cbp
@@ -165,6 +165,13 @@
+
+
+
+
+
+
+
@@ -190,6 +197,116 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -208,9 +325,11 @@
+
+
@@ -421,6 +540,7 @@
+
@@ -474,6 +594,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -499,9 +666,9 @@
-
+
@@ -512,6 +679,8 @@
+
+
@@ -526,20 +695,26 @@
+
+
+
+
-
-
+
+
+
+
@@ -568,14 +743,23 @@
+
+
+
+
+
+
+
+
+
@@ -601,7 +785,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -614,6 +823,13 @@
+
+
+
+
+
+
+
diff --git a/ee.win.cbp b/ee.win.cbp
index eba75e435..de72339c0 100644
--- a/ee.win.cbp
+++ b/ee.win.cbp
@@ -25,7 +25,6 @@
-
@@ -34,6 +33,8 @@
+
+
@@ -167,6 +168,13 @@
+
+
+
+
+
+
+
@@ -192,12 +200,125 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -425,6 +546,7 @@
+
@@ -478,6 +600,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -503,9 +672,9 @@
-
+
@@ -516,6 +685,8 @@
+
+
@@ -530,12 +701,14 @@
+
+
+
+
-
-
@@ -580,12 +753,19 @@
+
+
+
+
+
+
+
@@ -611,7 +791,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -624,6 +818,13 @@
+
+
+
+
+
+
+
diff --git a/src/audio/caudiodevice.cpp b/src/audio/caudiodevice.cpp
index 241017958..352ee6ef1 100755
--- a/src/audio/caudiodevice.cpp
+++ b/src/audio/caudiodevice.cpp
@@ -26,8 +26,9 @@ cAudioDevice::cAudioDevice() :
cAudioListener::instance()->SetPosition(0.f, 0.f, 0.f);
cAudioListener::instance()->SetTarget(0.f, 0.f, -1.f);
- cLog::instance()->Write( "OpenAL current device: " );
- cLog::instance()->Write( "\t" + std::string( (const char *)alcGetString(mDevice, ALC_DEVICE_SPECIFIER) ) );
+ std::string log( "OpenAL current device:\n" );
+ log += "\t" + std::string( (const char *)alcGetString(mDevice, ALC_DEVICE_SPECIFIER) );
+ cLog::instance()->Write( log );
} else {
cLog::instance()->Write("Failed to create the audio context");
}
@@ -37,21 +38,23 @@ cAudioDevice::cAudioDevice() :
}
void cAudioDevice::PrintInfo() {
- cLog::instance()->Write( "OpenAL devices detected:" );
+ std::string log( "OpenAL devices detected:\n" );
if ( alcIsExtensionPresent( NULL, (const ALCchar *) "ALC_ENUMERATION_EXT" ) == AL_TRUE ) {
const char *s = (const char *) alcGetString(NULL, ALC_DEVICE_SPECIFIER);
while (*s != '\0') {
- cLog::instance()->Write( "\t" + std::string( s ) );
+ log += "\t" + std::string( s ) + "\n";
while (*s++ != '\0');
}
} else {
- cLog::instance()->Write( "OpenAL device enumeration isn't available." );
+ log += "OpenAL device enumeration isn't available.";
}
- cLog::instance()->Write( "OpenAL default device: " );
- cLog::instance()->Write( "\t" + std::string( (const char *)alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER) ) );
+ log += "OpenAL default device:\n";
+ log += "\t" + std::string( (const char *)alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER) );
+
+ cLog::instance()->Write( log );
}
cAudioDevice::~cAudioDevice() {
diff --git a/src/base.hpp b/src/base.hpp
index 88ad2e9f0..2f352abcd 100644
--- a/src/base.hpp
+++ b/src/base.hpp
@@ -26,13 +26,16 @@
#include
#include "helper/PlusCallback/callback.hpp"
+#include "helper/sophist/sophist.h"
-#include
-
-#define Int8 Sint8
-#define Int16 Sint16
-#define Int32 Sint32
-#define Int64 Sint64
+namespace EE {
+typedef SOPHIST_int8 Int8;
+typedef SOPHIST_uint8 Uint8;
+typedef SOPHIST_int16 Int16;
+typedef SOPHIST_uint16 Uint16;
+typedef SOPHIST_int32 Int32;
+typedef SOPHIST_uint32 Uint32;
+}
#define EE_PLATFORM_WIN 1
#define EE_PLATFORM_LINUX 2
@@ -186,6 +189,26 @@ namespace EE {
return ( n < 0 ) ? -n : n;
}
+ template
+ T eeclamp( T val, T min, T max ) {
+ if ( val < min ) {
+ return min;
+ } else if ( val > max ) {
+ return max;
+ }
+
+ return val;
+ }
+
+ template
+ void eeclamp( T* val, T min, T max ) {
+ if ( *val < min ) {
+ *val = min;
+ } else if ( *val > max ) {
+ *val = max;
+ }
+ }
+
typedef double eeDouble; //! The internal double floating point. It's only used when the engine needs some very high precision floating point ( for example the timer )
typedef unsigned int eeUint;
typedef signed int eeInt;
diff --git a/src/ee.h b/src/ee.h
index dc9a6353a..0d8f320dd 100755
--- a/src/ee.h
+++ b/src/ee.h
@@ -24,8 +24,8 @@
/**
@TODO Add some Surface Grid class, to create special effects ( waved texture, and stuff like that ).
@TODO Add Scripting support ( lua or squirrel ).
- @TODO Encapsulate SDL and OpenGL ( and remove unnecessary dependencies ).
@TODO Support color cursors ( not only black and white cursors, that really sucks ) - Imposible with SDL 1.2
+ @TODO Support for Android and iPhone
*/
// General includes and declarations
@@ -93,6 +93,8 @@
#include "window/cinput.hpp"
#include "window/cinputtextbuffer.hpp"
#include "window/cview.hpp"
+ #include "window/cwindow.hpp"
+ #include "window/cclipboard.hpp"
#include "window/cjoystick.hpp"
#include "window/cjoystickmanager.hpp"
#include "window/cengine.hpp"
diff --git a/src/gaming/cisomap.cpp b/src/gaming/cisomap.cpp
index a538d0fa6..c0dcbcc3c 100755
--- a/src/gaming/cisomap.cpp
+++ b/src/gaming/cisomap.cpp
@@ -2,18 +2,25 @@
namespace EE { namespace Gaming {
-cIsoMap::cIsoMap() :
+cIsoMap::cIsoMap( cWindow * window ) :
+ mWindow( window ),
mOffsetX(0),
mOffsetY(0),
mFont(NULL)
{
- mEE = cEngine::instance();
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
}
cIsoMap::~cIsoMap() {
}
void cIsoMap::Create( const eeUint& MapTilesX, const eeUint& MapTilesY, const eeUint& NumLayers, const eeUint TilesWidth, const eeUint TilesHeight, const eeColor& AmbientCol ) {
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
+
mMapWidth = MapTilesX;
mMapHeight = MapTilesY;
mMapLayers = NumLayers;
@@ -75,9 +82,9 @@ void cIsoMap::Draw() {
eeAABB TileAABB;
cIsoTile * T;
- mScreenAABB = eeAABB( -mOffsetX, -mOffsetY, mEE->GetWidth() - mOffsetX, mEE->GetHeight() - mOffsetY ); // Screen AABB to MAP AABB
+ mScreenAABB = eeAABB( -mOffsetX, -mOffsetY, mWindow->GetWidth() - mOffsetX, mWindow->GetHeight() - mOffsetY ); // Screen AABB to MAP AABB
- mMouseMapPos = eeVector2f( cInput::instance()->MouseX() - mOffsetX, cInput::instance()->MouseY() - mOffsetY );
+ mMouseMapPos = eeVector2f( mWindow->GetInput()->MouseX() - mOffsetX, mWindow->GetInput()->MouseY() - mOffsetY );
mLight.UpdatePos( mMouseMapPos );
@@ -87,11 +94,11 @@ void cIsoMap::Draw() {
if (mOffsetY > 0)
mOffsetY = 0;
- if ( -mOffsetX > Tile( mMapWidth-1, mMapHeight-1 ).Q.V[1].x - mEE->GetWidth() )
- mOffsetX = -(Tile( mMapWidth-1, mMapHeight-1 ).Q.V[1].x - mEE->GetWidth());
+ if ( -mOffsetX > Tile( mMapWidth-1, mMapHeight-1 ).Q.V[1].x - mWindow->GetWidth() )
+ mOffsetX = -(Tile( mMapWidth-1, mMapHeight-1 ).Q.V[1].x - mWindow->GetWidth());
- if ( -mOffsetY > Tile( mMapWidth-1, mMapHeight-1 ).Q.V[1].y - mEE->GetHeight() )
- mOffsetY = -(Tile( mMapWidth-1, mMapHeight-1 ).Q.V[1].y - mEE->GetHeight());
+ if ( -mOffsetY > Tile( mMapWidth-1, mMapHeight-1 ).Q.V[1].y - mWindow->GetHeight() )
+ mOffsetY = -(Tile( mMapWidth-1, mMapHeight-1 ).Q.V[1].y - mWindow->GetHeight());
Tx = (Int32)( -mOffsetX / (eeFloat)mTileHeight ) - mTilesRange;
Ty = (Int32)( -mOffsetY / (eeFloat)mTileHeight ) - mTilesRange;
@@ -102,8 +109,8 @@ void cIsoMap::Draw() {
if (Ty < 0) Ty = 0;
if (Ty >= (eeInt)mMapHeight) Ty = mMapHeight-1;
- Tx2 = ( Tx + mTilesRange + (eeInt)( mEE->GetWidth() / (eeFloat)mTileHeight ) + mTilesRange );
- Ty2 = ( Ty + mTilesRange + (eeInt)( mEE->GetHeight() / (eeFloat)mTileHeight) + mTilesRange );
+ Tx2 = ( Tx + mTilesRange + (eeInt)( mWindow->GetWidth() / (eeFloat)mTileHeight ) + mTilesRange );
+ Ty2 = ( Ty + mTilesRange + (eeInt)( mWindow->GetHeight() / (eeFloat)mTileHeight) + mTilesRange );
eeColorA SC(50,50,50,100);
diff --git a/src/gaming/cisomap.hpp b/src/gaming/cisomap.hpp
index 2e033c00c..fbea6bae7 100755
--- a/src/gaming/cisomap.hpp
+++ b/src/gaming/cisomap.hpp
@@ -4,6 +4,7 @@
#include "base.hpp"
#include "../window/cinput.hpp"
+#include "../window/cwindow.hpp"
#include "../window/cengine.hpp"
using namespace EE::Window;
@@ -30,7 +31,7 @@ class EE_API cIsoTile {
class EE_API cIsoMap {
public:
- cIsoMap();
+ cIsoMap( cWindow * window = NULL );
~cIsoMap();
@@ -80,6 +81,7 @@ class EE_API cIsoMap {
protected:
std::vector Map;
+ cWindow * mWindow;
eeColor mMapAmbientColor;
eeUint mMapWidth;
eeUint mMapHeight;
@@ -101,7 +103,6 @@ class EE_API cIsoMap {
eeFloat mOffsetY;
// Fast access to classes
- cEngine * mEE;
cPrimitives mPR;
cFont * mFont;
diff --git a/src/graphics/cconsole.cpp b/src/graphics/cconsole.cpp
index 8ebfad941..9812b535c 100755
--- a/src/graphics/cconsole.cpp
+++ b/src/graphics/cconsole.cpp
@@ -8,11 +8,16 @@ using namespace EE::Window;
namespace EE { namespace Graphics {
-cConsole::cConsole() : mLastLogPos(0), mEnabled(false), mVisible(false), mFadeIn(false), mFadeOut(false), mExpand(false), mFading(false), mShowFps(false),
- mConColor(35, 47, 73, 230), mConLineColor(55, 67, 93, 230), mFontColor(153, 153, 179, 230), mFontLineColor(255, 255, 255, 230),
- mWidth(0), mHeight(0), mHeightMin(0), mY(0.0f), mA(0.0f), mFadeSpeed(250.f),
- mMaxLogLines(1024), mFont(NULL), mTexId(0), mCurAlpha(0), mCurSide(false)
+cConsole::cConsole( cWindow * window ) :
+ mWindow( window ),
+ mLastLogPos(0), mEnabled(false), mVisible(false), mFadeIn(false), mFadeOut(false), mExpand(false), mFading(false), mShowFps(false),
+ mConColor(35, 47, 73, 230), mConLineColor(55, 67, 93, 230), mFontColor(153, 153, 179, 230), mFontLineColor(255, 255, 255, 230),
+ mWidth(0), mHeight(0), mHeightMin(0), mY(0.0f), mA(0.0f), mFadeSpeed(250.f),
+ mMaxLogLines(1024), mFont(NULL), mTexId(0), mCurAlpha(0), mCurSide(false)
{
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
}
cConsole::~cConsole() {
@@ -20,11 +25,20 @@ cConsole::~cConsole() {
mCmdLog.clear();
mLastCommands.clear();
- if ( mMyCallback && NULL != cInput::ExistsSingleton() )
- cInput::instance()->PopCallback( mMyCallback );
+ if ( mMyCallback &&
+ NULL != cEngine::ExistsSingleton() &&
+ cEngine::instance()->ExistsWindow( mWindow )
+ )
+ {
+ mWindow->GetInput()->PopCallback( mMyCallback );
+ }
}
void cConsole::Create( cFont* Font, const bool& MakeDefaultCommands, const eeUint& MaxLogLines, const Uint32& TextureId ) {
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
+
mFont = Font;
mFontSize = (eeFloat)mFont->GetFontSize();
@@ -41,11 +55,15 @@ void cConsole::Create( cFont* Font, const bool& MakeDefaultCommands, const eeUin
if ( MakeDefaultCommands )
CreateDefaultCommands();
- mWidth = (eeFloat) cEngine::instance()->GetWidth();
- mHeight = (eeFloat) cEngine::instance()->GetHeight();
- mHeightMin = (eeFloat) cEngine::instance()->GetHeight() * 0.4f;
+ mWidth = (eeFloat) mWindow->GetWidth();
+ mHeight = (eeFloat) mWindow->GetHeight();
+ mHeightMin = (eeFloat) mWindow->GetHeight() * 0.4f;
- mMyCallback = cInput::instance()->PushCallback( cb::Make1( this, &cConsole::PrivInputCallback ) );
+ if ( NULL != cEngine::ExistsSingleton() &&
+ cEngine::instance()->ExistsWindow( mWindow ) )
+ {
+ mMyCallback = mWindow->GetInput()->PushCallback( cb::Make1( this, &cConsole::PrivInputCallback ) );
+ }
mTBuf.SetReturnCallback( cb::Make0( this, &cConsole::ProcessLine ) );
mTBuf.Start();
@@ -130,8 +148,8 @@ void cConsole::Draw() {
if ( mShowFps ) {
mFont->Color( eeColorA () );
- mFont->SetText( L"FPS: " + toWStr( cEngine::instance()->FPS() ) );
- mFont->Draw( cEngine::instance()->GetWidth() - mFont->GetTextWidth() - 15, 6 );
+ mFont->SetText( L"FPS: " + toWStr( mWindow->FPS() ) );
+ mFont->Draw( mWindow->GetWidth() - mFont->GetTextWidth() - 15, 6 );
}
}
@@ -234,13 +252,13 @@ void cConsole::Toggle() {
void cConsole::Fade() {
if (mCurSide) {
- mCurAlpha -= 255.f * cEngine::instance()->Elapsed() / mFadeSpeed;
+ mCurAlpha -= 255.f * mWindow->Elapsed() / mFadeSpeed;
if ( mCurAlpha <= 0.0f ) {
mCurAlpha = 0.0f;
mCurSide = !mCurSide;
}
} else {
- mCurAlpha += 255.f * cEngine::instance()->Elapsed() / mFadeSpeed;
+ mCurAlpha += 255.f * mWindow->Elapsed() / mFadeSpeed;
if ( mCurAlpha >= 255.f ) {
mCurAlpha = 255.f;
mCurSide = !mCurSide;
@@ -254,7 +272,7 @@ void cConsole::Fade() {
if ( mFadeIn ) {
mFadeOut = false;
- mY += mCurHeight * cEngine::instance()->Elapsed() / mFadeSpeed;
+ mY += mCurHeight * mWindow->Elapsed() / mFadeSpeed;
mA = ( mY * mMaxAlpha / mCurHeight ) ;
if ( mY > mCurHeight ) {
@@ -266,7 +284,7 @@ void cConsole::Fade() {
if ( mFadeOut ) {
mFadeIn = false;
- mY -= mCurHeight * cEngine::instance()->Elapsed() / mFadeSpeed;
+ mY -= mCurHeight * mWindow->Elapsed() / mFadeSpeed;
mA = ( mY * mMaxAlpha / mCurHeight ) ;
if ( mY <= 0.0f ) {
@@ -304,14 +322,27 @@ void cConsole::PrintCommandsStartingWith( const std::wstring& start ) {
}
}
-void cConsole::PrivInputCallback( EE_Event * Event ) {
- Uint8 etype = Event->type;
+void cConsole::PrivInputCallback( InputEvent * Event ) {
+ Uint8 etype = Event->Type;
- if ( mVisible ) {
+ if ( InputEvent::VideoExpose == etype || InputEvent::VideoResize == etype ) {
+ mWidth = (eeFloat) mWindow->GetWidth();
+ mHeight = (eeFloat) mWindow->GetHeight();
+ mHeightMin = (eeFloat) mWindow->GetHeight() * 0.4f;
+
+ if ( mVisible ) {
+ if ( mExpand )
+ mCurHeight = mHeight;
+ else
+ mCurHeight = mHeightMin;
+
+ mY = mCurHeight;
+ }
+ } else if ( mVisible ) {
Uint32 KeyCode = (Uint32)Event->key.keysym.sym;
Uint32 Button = Event->button.button;
- if ( SDL_KEYDOWN == etype ) {
+ if ( InputEvent::KeyDown == etype ) {
if ( ( KeyCode == KEY_TAB ) && (eeUint)mTBuf.CurPos() == mTBuf.Buffer().size() ) {
PrintCommandsStartingWith( mTBuf.Buffer() );
}
@@ -353,7 +384,7 @@ void cConsole::PrivInputCallback( EE_Event * Event ) {
if ( KeyCode == KEY_END ) {
mCon.ConModif = 0;
}
- } else if ( SDL_MOUSEBUTTONDOWN == etype ) {
+ } else if ( InputEvent::MouseButtonDown == etype ) {
if ( Button == EE_BUTTON_WHEELUP ) {
if ( mCon.ConMin - mCon.ConModif > 0 )
mCon.ConModif++;
@@ -364,19 +395,6 @@ void cConsole::PrivInputCallback( EE_Event * Event ) {
mCon.ConModif--;
}
}
- } else if ( SDL_VIDEOEXPOSE == etype || SDL_VIDEORESIZE == etype ) {
- mWidth = (eeFloat) cEngine::instance()->GetWidth();
- mHeight = (eeFloat) cEngine::instance()->GetHeight();
- mHeightMin = (eeFloat) cEngine::instance()->GetHeight() * 0.4f;
-
- if ( mVisible ) {
- if ( mExpand )
- mCurHeight = mHeight;
- else
- mCurHeight = mHeightMin;
-
- mY = mCurHeight;
- }
}
}
@@ -428,7 +446,7 @@ void cConsole::CmdMinimize ( const std::vector < std::wstring >& params ) {
}
void cConsole::CmdQuit ( const std::vector < std::wstring >& params ) {
- cEngine::instance()->Running(false);
+ cEngine::instance()->Close();
}
void cConsole::CmdGetTextureMemory ( const std::vector < std::wstring >& params ) {
@@ -450,7 +468,7 @@ void cConsole::CmdShowCursor ( const std::vector < std::wstring >& params ) {
bool Res = fromWString( tInt, params[1] );
if ( Res && ( tInt == 0 || tInt == 1 ) ) {
- cEngine::instance()->ShowCursor( 0 != tInt );
+ mWindow->ShowCursor( 0 != tInt );
PushText( L"showcursor " + toWStr(tInt) );
} else
PushText( L"Valid parameters are 0 or 1." );
@@ -468,7 +486,7 @@ void cConsole::CmdFrameLimit ( const std::vector < std::wstring >& params ) {
bool Res = fromWString( tInt, params[1] );
if ( Res && ( tInt >= 0 && tInt <= 10000 ) ) {
- cEngine::instance()->SetFrameRateLimit( tInt );
+ mWindow->FrameRateLimit( tInt );
PushText( L"setframelimit " + toWStr(tInt) );
} else
PushText( L"Valid parameters are between 0 and 10000 (0 = no limit)." );
@@ -511,7 +529,7 @@ void cConsole::CmdSetGamma( const std::vector < std::wstring >& params ) {
bool Res = fromWString( tFloat, params[1] );
if ( Res && ( tFloat > 0.1f && tFloat <= 10.0f ) ) {
- cEngine::instance()->SetGamma( tFloat, tFloat, tFloat );
+ mWindow->SetGamma( tFloat, tFloat, tFloat );
PushText( L"setgamma " + toWStr(tFloat) );
} else
PushText( L"Valid parameters are between 0.1 and 10." );
diff --git a/src/graphics/cconsole.hpp b/src/graphics/cconsole.hpp
index 95cecb726..9af250d29 100755
--- a/src/graphics/cconsole.hpp
+++ b/src/graphics/cconsole.hpp
@@ -2,6 +2,7 @@
#define EE_GRAPHICSCCONSOLE_H
#include "base.hpp"
+#include "../window/cwindow.hpp"
#include "../window/cinputtextbuffer.hpp"
#include "cprimitives.hpp"
#include "cfont.hpp"
@@ -15,7 +16,7 @@ class EE_API cConsole{
//! The Console Callback return a vector of parameters ( wstring )
typedef cb::Callback1& > ConsoleCallback;
- cConsole();
+ cConsole( cWindow * window = NULL );
~cConsole();
@@ -131,6 +132,7 @@ class EE_API cConsole{
std::deque < std::wstring > mCmdLog;
std::deque < std::wstring > mLastCommands;
+ cWindow * mWindow;
eeInt mLastLogPos;
bool mEnabled, mVisible, mFadeIn, mFadeOut, mExpand, mFading, mShowFps;
@@ -202,7 +204,7 @@ class EE_API cConsole{
void CmdGetTextureMemory ( const std::vector < std::wstring >& params );
/** The Default Commands Callbacks for the Console ( don't call it ) */
- void PrivInputCallback( EE_Event* Event );
+ void PrivInputCallback( InputEvent * Event );
/** Clear the Console */
void CmdClear();
diff --git a/src/graphics/cfont.cpp b/src/graphics/cfont.cpp
index 5abe6034b..eab26a5a2 100644
--- a/src/graphics/cfont.cpp
+++ b/src/graphics/cfont.cpp
@@ -139,7 +139,7 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con
eeColorA Col = mColor;
- //! FIXME: Cache shadows?
+ /** FIXME: Cache shadows? */
SetText( TextCache.Text() );
Color( mShadowColor );
Draw( TextCache, X + 1, Y + 1, f, Scale, Angle, Effect );
diff --git a/src/graphics/cframebuffer.cpp b/src/graphics/cframebuffer.cpp
index 7d2fbe5cf..7bddfa207 100644
--- a/src/graphics/cframebuffer.cpp
+++ b/src/graphics/cframebuffer.cpp
@@ -9,23 +9,28 @@ using namespace EE::Graphics::Private;
namespace EE { namespace Graphics {
-cFrameBuffer * cFrameBuffer::CreateNew( const Uint32& Width, const Uint32& Height, bool DepthBuffer ) {
+cFrameBuffer * cFrameBuffer::CreateNew( const Uint32& Width, const Uint32& Height, bool DepthBuffer, cWindow * window ) {
if ( cFrameBufferFBO::IsSupported() )
- return eeNew( cFrameBufferFBO, ( Width, Height, DepthBuffer ) );
+ return eeNew( cFrameBufferFBO, ( Width, Height, DepthBuffer, window ) );
if ( cFrameBufferPBuffer::IsSupported() )
- return eeNew( cFrameBufferPBuffer, ( Width, Height, DepthBuffer ) );
+ return eeNew( cFrameBufferPBuffer, ( Width, Height, DepthBuffer, window ) );
return NULL;
}
-cFrameBuffer::cFrameBuffer() :
+cFrameBuffer::cFrameBuffer( cWindow * window ) :
+ mWindow( window ),
mWidth(0),
mHeight(0),
mHasDepthBuffer(false),
mTexture(NULL),
mClearColor(0,0,0,0)
{
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
+
cFrameBufferManager::instance()->Add( this );
}
@@ -51,13 +56,13 @@ eeColorAf cFrameBuffer::ClearColor() const {
void cFrameBuffer::Clear() {
GLi->ClearColor( mClearColor.R(), mClearColor.G(), mClearColor.B(), mClearColor.A() );
GLi->Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- cEngine::instance()->SetBackColor( cEngine::instance()->GetBackColor() );
+ mWindow->BackColor( mWindow->BackColor() );
}
void cFrameBuffer::SetBufferView() {
cGlobalBatchRenderer::instance()->Draw();
- mPrevView = Window::cEngine::instance()->GetView();
+ mPrevView = mWindow->GetView();
GLi->MatrixMode( GL_PROJECTION );
GLi->LoadIdentity();
@@ -70,7 +75,7 @@ void cFrameBuffer::SetBufferView() {
void cFrameBuffer::RecoverView() {
cGlobalBatchRenderer::instance()->Draw();
- cEngine::instance()->SetView( mPrevView );
+ mWindow->SetView( mPrevView );
}
const Int32& cFrameBuffer::GetWidth() const {
diff --git a/src/graphics/cframebuffer.hpp b/src/graphics/cframebuffer.hpp
index 8f8c11879..115a80f74 100644
--- a/src/graphics/cframebuffer.hpp
+++ b/src/graphics/cframebuffer.hpp
@@ -4,6 +4,7 @@
#include "base.hpp"
#include "ctexture.hpp"
#include "../window/cview.hpp"
+#include "../window/cwindow.hpp"
using namespace EE::Window;
@@ -11,9 +12,9 @@ namespace EE { namespace Graphics {
class EE_API cFrameBuffer {
public:
- static cFrameBuffer * CreateNew( const Uint32& Width, const Uint32& Height, bool DepthBuffer = false );
+ static cFrameBuffer * CreateNew( const Uint32& Width, const Uint32& Height, bool DepthBuffer = false, cWindow * window = NULL );
- cFrameBuffer();
+ cFrameBuffer( cWindow * window );
virtual ~cFrameBuffer();
@@ -39,6 +40,7 @@ class EE_API cFrameBuffer {
const bool& HasDepthBuffer() const;
protected:
+ cWindow * mWindow;
Int32 mWidth;
Int32 mHeight;
bool mHasDepthBuffer;
diff --git a/src/graphics/cframebufferfbo.cpp b/src/graphics/cframebufferfbo.cpp
index aa33b2a01..957df7d1a 100644
--- a/src/graphics/cframebufferfbo.cpp
+++ b/src/graphics/cframebufferfbo.cpp
@@ -9,14 +9,14 @@ bool cFrameBufferFBO::IsSupported() {
return 0 != GLi->IsExtension( EEGL_EXT_framebuffer_object );
}
-cFrameBufferFBO::cFrameBufferFBO() :
- cFrameBuffer(),
+cFrameBufferFBO::cFrameBufferFBO( cWindow * window ) :
+ cFrameBuffer( window ),
mFrameBuffer(0),
mDepthBuffer(0)
{}
-cFrameBufferFBO::cFrameBufferFBO( const Uint32& Width, const Uint32& Height, bool DepthBuffer ) :
- cFrameBuffer(),
+cFrameBufferFBO::cFrameBufferFBO( const Uint32& Width, const Uint32& Height, bool DepthBuffer, cWindow * window ) :
+ cFrameBuffer( window ),
mFrameBuffer(0),
mDepthBuffer(0)
{
@@ -52,6 +52,10 @@ bool cFrameBufferFBO::Create( const Uint32& Width, const Uint32& Height, bool De
if ( !IsSupported() )
return false;
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
+
mWidth = Width;
mHeight = Height;
mHasDepthBuffer = DepthBuffer;
diff --git a/src/graphics/cframebufferfbo.hpp b/src/graphics/cframebufferfbo.hpp
index 83b6d7d6f..f4f28c681 100644
--- a/src/graphics/cframebufferfbo.hpp
+++ b/src/graphics/cframebufferfbo.hpp
@@ -9,11 +9,11 @@ namespace EE { namespace Graphics {
class EE_API cFrameBufferFBO : public cFrameBuffer {
public:
- cFrameBufferFBO();
+ cFrameBufferFBO( cWindow * window = NULL );
~cFrameBufferFBO();
- cFrameBufferFBO( const Uint32& Width, const Uint32& Height, bool DepthBuffer = false );
+ cFrameBufferFBO( const Uint32& Width, const Uint32& Height, bool DepthBuffer = false, cWindow * window = NULL );
bool Create( const Uint32& Width, const Uint32& Height );
diff --git a/src/graphics/cframebufferpbuffer.cpp b/src/graphics/cframebufferpbuffer.cpp
index f75a35d7d..f7a8a83f4 100644
--- a/src/graphics/cframebufferpbuffer.cpp
+++ b/src/graphics/cframebufferpbuffer.cpp
@@ -4,19 +4,21 @@
namespace EE { namespace Graphics {
-cFrameBufferPBuffer::cFrameBufferPBuffer()
+cFrameBufferPBuffer::cFrameBufferPBuffer( cWindow * window )
#ifdef EE_GLEW_AVAILABLE
#if EE_PLATFORM == EE_PLATFORM_WIN
- : cFrameBuffer(),
+ : cFrameBuffer( window ),
mDeviceContext( NULL ),
mPBuffer( NULL ),
mContext( NULL )
#elif EE_PLATFORM == EE_PLATFORM_LINUX
- : cFrameBuffer(),
+ : cFrameBuffer( window ),
mDisplay( NULL ),
mPBuffer( 0 ),
mContext( NULL )
+#else
+ : cFrameBuffer( window )
#endif
#endif
@@ -26,19 +28,21 @@ cFrameBufferPBuffer::cFrameBufferPBuffer()
#endif
}
-cFrameBufferPBuffer::cFrameBufferPBuffer( const Uint32& Width, const Uint32& Height, bool DepthBuffer )
+cFrameBufferPBuffer::cFrameBufferPBuffer( const Uint32& Width, const Uint32& Height, bool DepthBuffer, cWindow * window )
#ifdef EE_GLEW_AVAILABLE
#if EE_PLATFORM == EE_PLATFORM_WIN
- : cFrameBuffer(),
+ : cFrameBuffer( window ),
mDeviceContext( NULL ),
mPBuffer( NULL ),
mContext( NULL )
#elif EE_PLATFORM == EE_PLATFORM_LINUX
- : cFrameBuffer(),
+ : cFrameBuffer( window ),
mDisplay( NULL ),
mPBuffer( 0 ),
mContext( NULL )
+#else
+ : cFrameBuffer( window )
#endif
#endif
@@ -72,8 +76,9 @@ cFrameBufferPBuffer::~cFrameBufferPBuffer() {
#endif
#endif
- if ( Window::cEngine::ExistsSingleton() )
- Window::cEngine::instance()->SetDefaultContext();
+ if ( Window::cEngine::instance()->ExistsWindow( mWindow ) ) {
+ mWindow->SetDefaultContext();
+ }
}
bool cFrameBufferPBuffer::IsSupported() {
@@ -100,6 +105,10 @@ bool cFrameBufferPBuffer::Create( const Uint32& Width, const Uint32& Height, boo
if ( !IsSupported() )
return false;
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
+
mWidth = Width;
mHeight = Height;
mHasDepthBuffer = DepthBuffer;
@@ -252,7 +261,7 @@ void cFrameBufferPBuffer::Bind() {
#endif
if ( ChangeContext ) {
- Window::cEngine::instance()->Setup2D( true );
+ mWindow->Setup2D( true );
SetBufferView();
}
}
@@ -268,7 +277,7 @@ void cFrameBufferPBuffer::Unbind() {
glBindTexture( GL_TEXTURE_2D, previousTexture );
- Window::cEngine::instance()->SetDefaultContext();
+ mWindow->SetDefaultContext();
}
diff --git a/src/graphics/cframebufferpbuffer.hpp b/src/graphics/cframebufferpbuffer.hpp
index e36a5ee95..990462194 100644
--- a/src/graphics/cframebufferpbuffer.hpp
+++ b/src/graphics/cframebufferpbuffer.hpp
@@ -49,11 +49,11 @@ namespace EE { namespace Graphics {
class EE_API cFrameBufferPBuffer : public cFrameBuffer {
public:
- cFrameBufferPBuffer();
+ cFrameBufferPBuffer( cWindow * window = NULL );
~cFrameBufferPBuffer();
- cFrameBufferPBuffer( const Uint32& Width, const Uint32& Height, bool DepthBuffer = false );
+ cFrameBufferPBuffer( const Uint32& Width, const Uint32& Height, bool DepthBuffer = false, cWindow * window = NULL );
bool Create( const Uint32& Width, const Uint32& Height );
diff --git a/src/graphics/cparticlesystem.cpp b/src/graphics/cparticlesystem.cpp
index 2ac242d57..da93a328f 100755
--- a/src/graphics/cparticlesystem.cpp
+++ b/src/graphics/cparticlesystem.cpp
@@ -1,5 +1,9 @@
#include "cparticlesystem.hpp"
#include "glhelper.hpp"
+#include "ctexturefactory.hpp"
+#include "../window/cengine.hpp"
+
+using namespace EE::Window;
namespace EE { namespace Graphics {
@@ -30,8 +34,6 @@ cParticleSystem::cParticleSystem() :
mY2( 0.f )
{
- EE = cEngine::instance();
- TF = cTextureFactory::instance();
}
cParticleSystem::~cParticleSystem() {
@@ -259,6 +261,8 @@ void cParticleSystem::Reset(cParticle* P) {
}
void cParticleSystem::Draw() {
+ cTextureFactory * TF = cTextureFactory::instance();
+
TF->Bind( mTexId );
TF->SetPreBlendFunc( ALPHA_BLENDONE );
@@ -306,7 +310,7 @@ void cParticleSystem::Draw() {
}
void cParticleSystem::Update( const eeFloat& Time ) {
- eeFloat Elapsed = ( Time == -99999.f ) ? EE->Elapsed() : Time;
+ eeFloat Elapsed = ( Time == -99999.f ) ? cEngine::instance()->Elapsed() : Time;
Uint32 i;
for ( i = 0; i < mPCount; i++ ) {
diff --git a/src/graphics/cparticlesystem.hpp b/src/graphics/cparticlesystem.hpp
index 87380e3e9..53d68d124 100755
--- a/src/graphics/cparticlesystem.hpp
+++ b/src/graphics/cparticlesystem.hpp
@@ -3,10 +3,6 @@
#include "base.hpp"
#include "cparticle.hpp"
-#include "ctexturefactory.hpp"
-#include "../window/cengine.hpp"
-
-using namespace EE::Window;
namespace EE { namespace Graphics {
@@ -124,9 +120,6 @@ class EE_API cParticleSystem {
/** Set a callback function for the reset effect of the particles. \n The reset it's where do you create the effect for every single particle. */
void SetCallbackReset( const ParticleCallback& pc );
private:
- cEngine * EE;
- cTextureFactory * TF;
-
cParticle * mParticle;
Uint32 mPCount;
Uint32 mTexId;
diff --git a/src/graphics/renderer/cgl.cpp b/src/graphics/renderer/cgl.cpp
index c61bdf4af..4a3dd966a 100644
--- a/src/graphics/renderer/cgl.cpp
+++ b/src/graphics/renderer/cgl.cpp
@@ -76,7 +76,8 @@ void cGL::DestroySingleton() {
}
cGL::cGL() :
- mExtensions(0)
+ mExtensions(0),
+ mStateFlags( 1 << GLSF_LINE_SMOOTH )
{
GLi = this;
}
@@ -119,36 +120,37 @@ void cGL::Init() {
else
#endif
{
- WriteExtension( EEGL_ARB_texture_non_power_of_two , GetExtension( "GL_ARB_texture_non_power_of_two" ) );
- WriteExtension( EEGL_ARB_point_parameters , GetExtension( "GL_ARB_point_parameters" ) );
- WriteExtension( EEGL_ARB_point_sprite , GetExtension( "GL_ARB_point_sprite" ) );
- WriteExtension( EEGL_ARB_shading_language_100 , GetExtension( "GL_ARB_shading_language_100" ) );
- WriteExtension( EEGL_ARB_shader_objects , GetExtension( "GL_ARB_shader_objects" ) );
- WriteExtension( EEGL_ARB_vertex_shader , GetExtension( "GL_ARB_vertex_shader" ) );
- WriteExtension( EEGL_ARB_fragment_shader , GetExtension( "GL_ARB_fragment_shader" ) );
- WriteExtension( EEGL_EXT_framebuffer_object , GetExtension( "GL_EXT_framebuffer_object" ) );
- WriteExtension( EEGL_ARB_multitexture , GetExtension( "GL_ARB_multitexture" ) );
- WriteExtension( EEGL_EXT_texture_compression_s3tc , GetExtension( "GL_EXT_texture_compression_s3tc" ) );
- WriteExtension( EEGL_ARB_vertex_buffer_object , GetExtension( "GL_ARB_vertex_buffer_object" ) );
+ WriteExtension( EEGL_ARB_texture_non_power_of_two , IsExtension( "GL_ARB_texture_non_power_of_two" ) );
+ WriteExtension( EEGL_ARB_point_parameters , IsExtension( "GL_ARB_point_parameters" ) );
+ WriteExtension( EEGL_ARB_point_sprite , IsExtension( "GL_ARB_point_sprite" ) );
+ WriteExtension( EEGL_ARB_shading_language_100 , IsExtension( "GL_ARB_shading_language_100" ) );
+ WriteExtension( EEGL_ARB_shader_objects , IsExtension( "GL_ARB_shader_objects" ) );
+ WriteExtension( EEGL_ARB_vertex_shader , IsExtension( "GL_ARB_vertex_shader" ) );
+ WriteExtension( EEGL_ARB_fragment_shader , IsExtension( "GL_ARB_fragment_shader" ) );
+ WriteExtension( EEGL_EXT_framebuffer_object , IsExtension( "GL_EXT_framebuffer_object" ) );
+ WriteExtension( EEGL_ARB_multitexture , IsExtension( "GL_ARB_multitexture" ) );
+ WriteExtension( EEGL_EXT_texture_compression_s3tc , IsExtension( "GL_EXT_texture_compression_s3tc" ) );
+ WriteExtension( EEGL_ARB_vertex_buffer_object , IsExtension( "GL_ARB_vertex_buffer_object" ) );
glewOn = false; /// avoid compiler warning
}
}
-Uint32 cGL::GetExtension( const char * name ) {
+bool cGL::IsExtension( const std::string& name ) {
#ifdef EE_GLEW_AVAILABLE
- return glewIsSupported( name );
+ return 0 != glewIsSupported( name.c_str() );
#else
- char *Exts = (char *)glGetString(GL_EXTENSIONS);
+ char *Exts = (char *)glGetString( GL_EXTENSIONS );
- if ( strstr( Exts, name ) )
- return 1;
+ if ( strstr( Exts, name.c_str() ) ) {
+ return true;
+ }
- return 0;
+ return false;
#endif
}
-bool cGL::IsExtension( Uint32 name ) {
+bool cGL::IsExtension( EEGL_extensions name ) {
return 0 != ( mExtensions & ( 1 << name ) );
}
@@ -293,4 +295,52 @@ void cGL::SetShader( cShaderProgram * Shader ) {
}
}
+bool cGL::IsLineSmooth() {
+ return Read32BitKey( &mStateFlags, GLSF_LINE_SMOOTH );
+}
+
+void cGL::LineSmooth() {
+ LineSmooth( IsLineSmooth() );
+}
+
+void cGL::LineSmooth( const bool& Enable ) {
+ if ( Enable ) {
+ GLi->Enable( GL_LINE_SMOOTH );
+ } else {
+ GLi->Disable( GL_LINE_SMOOTH );
+ }
+
+ Write32BitKey( &mStateFlags, GLSF_LINE_SMOOTH, Enable ? 1 : 0 );
+}
+
+void cGL::PolygonMode() {
+ EE_FILL_MODE Mode = EE_DRAW_FILL;
+
+ if ( Read32BitKey( &mStateFlags, GLSF_POLYGON_MODE ) )
+ Mode = EE_DRAW_LINE;
+
+ PolygonMode( Mode );
+}
+
+void cGL::PolygonMode( const EE_FILL_MODE& Mode ) {
+ if ( Mode == EE_DRAW_FILL )
+ GLi->PolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+ else
+ GLi->PolygonMode( GL_FRONT_AND_BACK, GL_LINE );
+
+ Write32BitKey( &mStateFlags, GLSF_POLYGON_MODE, Mode == EE_DRAW_LINE ? 1 : 0 );
+}
+
+std::string cGL::GetVendor() {
+ return std::string( reinterpret_cast ( cGL::instance()->GetString( GL_VENDOR ) ) );
+}
+
+std::string cGL::GetRenderer() {
+ return std::string( reinterpret_cast ( cGL::instance()->GetString( GL_RENDERER ) ) );
+}
+
+std::string cGL::GetVersion() {
+ return std::string( reinterpret_cast ( cGL::instance()->GetString( GL_VERSION ) ) );
+}
+
}}
diff --git a/src/graphics/renderer/cgl.hpp b/src/graphics/renderer/cgl.hpp
index 054ae6871..036d4507e 100644
--- a/src/graphics/renderer/cgl.hpp
+++ b/src/graphics/renderer/cgl.hpp
@@ -66,9 +66,20 @@ class cGL {
virtual void Init();
- Uint32 GetExtension( const char * name );
+ /** @return The company responsible for this GL implementation. */
+ std::string GetVendor();
- bool IsExtension( Uint32 name );
+ /** @return The name of the renderer.\n This name is typically specific to a particular configuration of a hardware platform. */
+ std::string GetRenderer();
+
+ /** @return A GL version or release number. */
+ std::string GetVersion();
+
+ /** @return If the extension passed is supported by the GPU */
+ bool IsExtension( const std::string& name );
+
+ /** @return If the extension from the EEGL_extensions is present on the GPU. */
+ bool IsExtension( EEGL_extensions name );
bool PointSpriteSupported();
@@ -106,6 +117,19 @@ class cGL {
void Viewport ( GLint x, GLint y, GLsizei width, GLsizei height );
+ void LineSmooth( const bool& Enable );
+
+ /** Reapply the line smooth state */
+ void LineSmooth();
+
+ bool IsLineSmooth();
+
+ /** Set the polygon fill mode ( wireframe or filled ) */
+ void PolygonMode( const EE_FILL_MODE& Mode );
+
+ /** Reapply the polygon mode */
+ void PolygonMode();
+
cRendererGL * GetRendererGL();
cRendererGL3 * GetRendererGL3();
@@ -172,7 +196,13 @@ class cGL {
virtual GLenum GetCurrentMatrixMode() = 0;
protected:
+ enum GLStateFlags {
+ GLSF_LINE_SMOOTH = 0,
+ GLSF_POLYGON_MODE
+ };
+
Uint32 mExtensions;
+ Uint32 mStateFlags;
private:
void WriteExtension( Uint8 Pos, Uint32 BitWrite );
};
diff --git a/src/helper/sophist/sophist.h b/src/helper/sophist/sophist.h
new file mode 100644
index 000000000..3818b6b8e
--- /dev/null
+++ b/src/helper/sophist/sophist.h
@@ -0,0 +1,187 @@
+/* sophist.h - 0.3 - public domain - Sean Barrett 2010
+** Knowledge drawn from Brian Hook's posh.h and http://predef.sourceforge.net
+** Sophist provides portable types; you typedef/#define them to your own names
+**
+** defines:
+** - SOPHIST_endian - either SOPHIST_little_endian or SOPHIST_big_endian
+** - SOPHIST_has_64 - either 0 or 1; if 0, int64 types aren't defined
+** - SOPHIST_pointer64 - either 0 or 1; if 1, pointer is 64-bit
+**
+** - SOPHIST_intptr, SOPHIST_uintptr - integer same size as pointer
+** - SOPHIST_int8, SOPHIST_uint8, SOPHIST_int16, SOPHIST_uint16
+** - SOPHIST_int32, SOPHIST_uint32, SOPHIST_int64, SOPHIST_uint64
+** - SOPHIST_int64_constant(number) - macros for creating 64-bit
+** - SOPHIST_uint64_constant(number) integer constants
+** - SOPHIST_printf_format64 - string for printf format for int64
+*/
+
+#ifndef __INCLUDE_SOPHIST_H__
+#define __INCLUDE_SOPHIST_H__
+
+#define SOPHIST_compiletime_assert(name,val) \
+ typedef int SOPHIST__assert##name[(val) ? 1 : -1]
+
+/* define a couple synthetic rules to make code more readable */
+#if (defined(__sparc__) || defined(__sparc)) && \
+ (defined(__arch64__) || defined(__sparcv9) || defined(__sparc_v9__))
+ #define SOPHIST_sparc64
+#endif
+
+#if (defined(linux) || defined(__linux__)) && \
+ (defined(__alpha)||defined(__alpha__)||defined(__x86_64__)||defined(_M_X64))
+ #define SOPHIST_linux64
+#endif
+
+/* basic types */
+typedef signed char SOPHIST_int8;
+typedef unsigned char SOPHIST_uint8;
+
+typedef signed short SOPHIST_int16;
+typedef unsigned short SOPHIST_uint16;
+
+#ifdef __palmos__
+ typedef signed long SOPHIST_int32;
+ typedef unsigned long SOPHIST_uint32;
+#else
+ typedef signed int SOPHIST_int32;
+ typedef unsigned int SOPHIST_uint32;
+#endif
+
+#ifndef SOPHIST_NO_64
+ #if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) \
+ || (defined(__alpha) && defined(__DECC))
+
+ typedef signed __int64 SOPHIST_int64;
+ typedef unsigned __int64 SOPHIST_uint64;
+ #define SOPHIST_has_64 1
+ #define SOPHIST_int64_constant(x) (x##i64)
+ #define SOPHIST_uint64_constant(x) (x##ui64)
+ #define SOPHIST_printf_format64 "I64"
+
+ #elif defined(__LP64__) || defined(__powerpc64__) || defined(SOPHIST_sparc64)
+
+ typedef signed long SOPHIST_int64;
+ typedef unsigned long SOPHIST_uint64;
+
+ #define SOPHIST_has_64 1
+ #define SOPHIST_int64_constant(x) ((SOPHIST_int64) x)
+ #define SOPHIST_uint64_constant(x) ((SOPHIST_uint64) x)
+ #define SOPHIST_printf_format64 "l"
+
+ #elif defined(_LONG_LONG) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) \
+ || defined(__GNUC__) || defined(__MWERKS__) || defined(__APPLE_CC__) \
+ || defined(sgi) || defined (__sgi) || defined(__sgi__) \
+ || defined(_CRAYC)
+
+ typedef signed long long SOPHIST_int64;
+ typedef unsigned long long SOPHIST_uint64;
+
+ #define SOPHIST_has_64 1
+ #define SOPHIST_int64_constant(x) (x##LL)
+ #define SOPHIST_uint64_constant(x) (x##ULL)
+ #define SOPHIST_printf_format64 "ll"
+ #endif
+#endif
+
+#ifndef SOPHIST_has_64
+#define SOPHIST_has_64 0
+#endif
+
+SOPHIST_compiletime_assert( int8 , sizeof(SOPHIST_int8 ) == 1);
+SOPHIST_compiletime_assert(uint16, sizeof(SOPHIST_int16) == 2);
+SOPHIST_compiletime_assert( int32, sizeof(SOPHIST_int32 ) == 4);
+SOPHIST_compiletime_assert(uint32, sizeof(SOPHIST_uint32) == 4);
+
+#if SOPHIST_has_64
+ SOPHIST_compiletime_assert( int64, sizeof(SOPHIST_int64 ) == 8);
+ SOPHIST_compiletime_assert(uint64, sizeof(SOPHIST_uint64) == 8);
+#endif
+
+/* determine whether pointers are 64-bit */
+
+#if defined(SOPHIST_linux64) || defined(SOPHIST_sparc64) \
+ || defined(__osf__) || (defined(_WIN64) && !defined(_XBOX)) \
+ || defined(__64BIT__) \
+ || defined(__LP64) || defined(__LP64__) || defined(_LP64) \
+ || defined(_ADDR64) || defined(_CRAYC) \
+
+ #define SOPHIST_pointer64 1
+
+ SOPHIST_compiletime_assert(pointer64, sizeof(void*) == 8);
+
+ typedef SOPHIST_int64 SOPHIST_intptr;
+ typedef SOPHIST_uint64 SOPHIST_uintptr;
+#else
+
+ #define SOPHIST_pointer64 0
+
+ SOPHIST_compiletime_assert(pointer64, sizeof(void*) <= 4);
+
+ /* do we care about pointers that are only 16-bit? */
+ typedef SOPHIST_int32 SOPHIST_intptr;
+ typedef SOPHIST_uint32 SOPHIST_uintptr;
+
+#endif
+
+SOPHIST_compiletime_assert(intptr, sizeof(SOPHIST_intptr) == sizeof(char *));
+
+/* enumerate known little endian cases; fallback to big-endian */
+
+#define SOPHIST_little_endian 1
+#define SOPHIST_big_endian 2
+
+#if defined(__386__) || defined(i386) || defined(__i386__) \
+ || defined(__X86) || defined(_M_IX86) \
+ || defined(_M_X64) || defined(__x86_64__) \
+ || defined(alpha) || defined(__alpha) || defined(__alpha__) \
+ || defined(_M_ALPHA) \
+ || defined(ARM) || defined(_ARM) || defined(__arm__) \
+ || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
+ || defined(_WIN32_WCE) || defined(__NT__) \
+ || defined(__MIPSEL__)
+ #define SOPHIST_endian SOPHIST_little_endian
+#else
+ #define SOPHIST_endian SOPHIST_big_endian
+#endif
+
+#endif /* __INCLUDE_SOPHIST_H__ */
+
+#ifdef SOPHIST_selftest
+#include
+#include
+int main(int argc, char **argv)
+{
+ int fail=0;
+ union {
+ SOPHIST_uint8 bytes[4];
+ SOPHIST_uint32 num;
+ } x;
+
+ #if SOPHIST_has_64
+ char buffer[32];
+ sprintf(buffer, "%016" SOPHIST_printf_format64 "x",
+ SOPHIST_uint64_constant(0x0123456789abcdef));
+ if (strcmp(buffer, "0123456789abcdef")) {
+ fail = 1; fputs("ERROR: 64-bit check failed.\n", stderr);
+ }
+ #endif
+
+ #if SOPHIST_endian == SOPHIST_little_endian
+ x.bytes[0] = 7; x.bytes[1] = 5; x.bytes[2] = 3; x.bytes[3] = 1;
+ #elif SOPHIST_endian == SOPHIST_big_endian
+ x.bytes[0] = 1; x.bytes[1] = 3; x.bytes[2] = 5; x.bytes[3] = 7;
+ #else
+ #error "Failure: endianness unknown!"
+ #endif
+ if (x.num != 0x01030507) {
+ fail = 1; fputs("ERROR: endian check failed.\n", stderr);
+ }
+
+ fputs(fail ? "Failed.\n" : "Passed.\n", stdout);
+
+ argc = argc; /* attempt to suppress unused variable warnings */
+ argv = argv;
+
+ return 0;
+}
+#endif
diff --git a/src/test/ee.cpp b/src/test/ee.cpp
index ba0338370..9d7ce2981 100644
--- a/src/test/ee.cpp
+++ b/src/test/ee.cpp
@@ -31,9 +31,9 @@ class cUITest : public cUIControlAnim {
virtual Uint32 OnMouseUp( const eeVector2i& Pos, const Uint32 Flags ) {
cUIDragable::OnMouseUp( Pos, Flags );
- if ( cInput::instance()->MouseWheelUp() )
+ if ( cEngine::instance()->GetCurrentWindow()->GetInput()->MouseWheelUp() )
Scale( Scale() + 0.1f );
- else if ( cInput::instance()->MouseWheelDown() )
+ else if ( cEngine::instance()->GetCurrentWindow()->GetInput()->MouseWheelDown() )
Scale( Scale() - 0.1f );
return 1;
@@ -83,7 +83,8 @@ class cEETest : private cThread {
cTimeElapsed cElapsed;
eeFloat PSElapsed;
private:
- cEngine* EE;
+ cEngine * EE;
+ cWindow * mWindow;
cTextureFactory* TF;
cLog* Log;
cInput* KM;
@@ -219,7 +220,7 @@ class cEETest : private cThread {
cUIProgressBar * mProgressBar;
cUIListBox * mListBox;
cUIPopUpMenu * Menu;
- cUIWindow * mWindow;
+ cUIWindow * mUIWindow;
cTextCache mEEText;
cTextCache mFBOText;
@@ -283,7 +284,6 @@ void cEETest::CreateAquaTextureAtlas() {
void cEETest::Init() {
EE = cEngine::instance();
- SetScreen( 0 );
run = false;
DrawBack = false;
MultiViewportMode = false;
@@ -325,20 +325,30 @@ void cEETest::Init() {
else
GLVer = GLv_2;
- run = EE->Init(mWidth, mHeight, BitColor, Windowed, Resizeable, VSync, true, false, false, GLVer );
+ Uint32 Style = Window::WindowStyle::Titlebar;
+
+ if ( !Windowed )
+ Style |= Window::WindowStyle::Fullscreen;
+
+ if ( Resizeable )
+ Style |= Window::WindowStyle::Resize;
+
+ mWindow = EE->CreateWindow( WindowSettings( mWidth, mHeight, BitColor, Style ), ContextSettings( VSync, GLVer ) );
PAK.Open( MyPath + "data/ee.zip" );
- run = ( run && PAK.IsOpen() );
+ run = ( mWindow->Created() && PAK.IsOpen() );
if ( run ) {
- EE->SetWindowCaption( "EE++ Test Application" );
+ SetScreen( 0 );
+
+ mWindow->Caption( "EE++ Test Application" );
TF = cTextureFactory::instance();
TF->Allocate(40);
Log = cLog::instance();
- KM = cInput::instance();
- JM = cJoystickManager::instance();
+ KM = mWindow->GetInput();
+ JM = KM->GetJoystickManager();
PS.resize(5);
@@ -446,13 +456,13 @@ void cEETest::OnFontLoaded( cResourceLoader * ObjLoaded ) {
mFBOText.Create( TTFB, L"This is a VBO\nInside of a FBO" );
mInfoText.Create( FF, L"", eeColorA(255,255,255,150) );
- EE->Display();
+ mWindow->Display();
mFontsLoaded = true;
}
void cEETest::CreateShaders() {
- mUseShaders = mUseShaders && EE->ShadersSupported();
+ mUseShaders = mUseShaders && GLi->ShadersSupported();
mShaderProgram = NULL;
@@ -788,7 +798,7 @@ void cEETest::CreateUI() {
C->Scale( 0 );
CreateDecoratedWindow();
- //mWindow->Show();
+ //mUIWindow->Show();
}
void cEETest::CreateDecoratedWindow() {
@@ -803,14 +813,14 @@ void cEETest::CreateDecoratedWindow() {
//WinParams.BorderAutoSize = false;
//WinParams.BorderSize = eeSize( 8, 8 );
- mWindow = eeNew( cUIWindow, ( WinParams ) );
- mWindow->AddEventListener( cUIEvent::EventOnWindowCloseClick, cb::Make1( this, &cEETest::CloseClick ) );
- mWindow->Title( L"Test Window" );
- mWindow->ToBack();
+ mUIWindow = eeNew( cUIWindow, ( WinParams ) );
+ mUIWindow->AddEventListener( cUIEvent::EventOnWindowCloseClick, cb::Make1( this, &cEETest::CloseClick ) );
+ mUIWindow->Title( L"Test Window" );
+ mUIWindow->ToBack();
}
void cEETest::CloseClick( const cUIEvent * Event ) {
- mWindow = NULL;
+ mUIWindow = NULL;
}
void cEETest::ItemClick( const cUIEvent * Event ) {
@@ -847,11 +857,11 @@ void cEETest::ItemClick( const cUIEvent * Event ) {
C->StartRotation( 0, 360, 500.f, SINEIN );
}
} else if ( L"Show Window 2" == txt ) {
- if ( NULL == mWindow ) {
+ if ( NULL == mUIWindow ) {
CreateDecoratedWindow();
}
- mWindow->Show();
+ mUIWindow->Show();
} else if ( L"Multi Viewport" == txt ) {
MultiViewportMode = !MultiViewportMode;
}
@@ -867,7 +877,7 @@ void cEETest::QuitClick( const cUIEvent * Event ) {
const cUIEventMouse * MouseEvent = reinterpret_cast ( Event );
if ( MouseEvent->Flags() & EE_BUTTON_LMASK ) {
- EE->Running(false);
+ mWindow->Close();
}
}
@@ -895,7 +905,7 @@ void cEETest::ButtonClick( const cUIEvent * Event ) {
Gfx->Enabled( false );
Gfx->StartRotation( 0, 2500, 2500 );
- Gfx->StartMovement( eeVector2i( eeRandi( 0, EE->GetWidth() ), -64 ), eeVector2i( eeRandi( 0, EE->GetWidth() ), EE->GetHeight() + 64 ), 2500 );
+ Gfx->StartMovement( eeVector2i( eeRandi( 0, mWindow->GetWidth() ), -64 ), eeVector2i( eeRandi( 0, mWindow->GetWidth() ), mWindow->GetHeight() + 64 ), 2500 );
Gfx->CloseFadeOut( 3500 );
mListBox->AddListBoxItem( L"Test ListBox " + toWStr( mListBox->Count() + 1 ) + L" testing it right now!" );
@@ -904,9 +914,9 @@ void cEETest::ButtonClick( const cUIEvent * Event ) {
void cEETest::SetScreen( Uint32 num ) {
if ( 0 == num )
- EE->SetBackColor( eeColor( 240, 240, 240 ) );
+ mWindow->BackColor( eeColor( 240, 240, 240 ) );
else
- EE->SetBackColor( eeColor( 0, 0, 0 ) );
+ mWindow->BackColor( eeColor( 0, 0, 0 ) );
if ( num < 6 )
Screen = num;
@@ -920,7 +930,7 @@ void cEETest::CmdSetPartsNum ( const std::vector < std::wstring >& params ) {
bool Res = fromWString( tInt, params[1] );
if ( Res && ( tInt >= 0 && tInt <= 100000 ) ) {
- PS[2].Create(WormHole, tInt, TN[5], EE->GetWidth() * 0.5f, EE->GetHeight() * 0.5f, 32, true);
+ PS[2].Create(WormHole, tInt, TN[5], mWindow->GetWidth() * 0.5f, mWindow->GetHeight() * 0.5f, 32, true);
Con.PushText( L"Wormhole Particles Number Changed to: " + toWStr(tInt) );
} else
Con.PushText( L"Valid parameters are between 0 and 100000 (0 = no limit)." );
@@ -985,9 +995,9 @@ void cEETest::LoadTextures() {
PS[0].SetCallbackReset( cb::Make2( this, &cEETest::ParticlesCallback ) );
PS[0].Create(Callback, 500, TN[5], 0, 0, 16, true);
- PS[1].Create(Heal, 250, TN[5], EE->GetWidth() * 0.5f, EE->GetHeight() * 0.5f, 16, true);
+ PS[1].Create(Heal, 250, TN[5], mWindow->GetWidth() * 0.5f, mWindow->GetHeight() * 0.5f, 16, true);
- PS[2].Create(WormHole, PartsNum, TN[5], EE->GetWidth() * 0.5f, EE->GetHeight() * 0.5f, 32, true);
+ PS[2].Create(WormHole, PartsNum, TN[5], mWindow->GetWidth() * 0.5f, mWindow->GetHeight() * 0.5f, 32, true);
Con.AddCommand( L"setparticlesnum", cb::Make1( this, &cEETest::CmdSetPartsNum ) );
PS[3].Create(Fire, 350, TN[5], -50.f, -50.f, 32, true);
@@ -1016,7 +1026,7 @@ void cEETest::LoadTextures() {
Cursor[1] = TF->LoadFromPack( &PAK, "cursor.tga" );
CursorP[1] = TF->GetTexture( Cursor[1] );
- EE->ShowCursor(false);
+ mWindow->ShowCursor(false);
CL1.AddFrame(TN[2]);
CL1.Position( 500, 400 );
@@ -1094,7 +1104,7 @@ void cEETest::Run() {
}
void cEETest::ParticlesThread() {
- while ( cEngine::instance()->Running() ) {
+ while ( mWindow->Running() ) {
if ( MultiViewportMode || Screen == 2 ) {
PSElapsed = (eeFloat)cElapsed.Elapsed();
@@ -1118,7 +1128,7 @@ void cEETest::Screen2() {
}
if ( KM->MouseLeftPressed() )
- TNP[3]->DrawEx( 0.f, 0.f, (eeFloat)EE->GetWidth(), (eeFloat)EE->GetHeight() );
+ TNP[3]->DrawEx( 0.f, 0.f, (eeFloat)mWindow->GetWidth(), (eeFloat)mWindow->GetHeight() );
Batch.SetTexture( TNP[2] );
Batch.QuadsBegin();
@@ -1195,7 +1205,7 @@ void cEETest::Screen2() {
}
eeColorA Col(255,255,255,(int)alpha);
- TNP[1]->DrawEx( (eeFloat)EE->GetWidth() - 128.f, (eeFloat)EE->GetHeight() - 128.f, 128.f, 128.f, ang, 1, Col, Col, Col, Col, ALPHA_BLENDONE, RN_FLIPMIRROR);
+ TNP[1]->DrawEx( (eeFloat)mWindow->GetWidth() - 128.f, (eeFloat)mWindow->GetHeight() - 128.f, 128.f, 128.f, ang, 1, Col, Col, Col, Col, ALPHA_BLENDONE, RN_FLIPMIRROR);
SP.Position( alpha, alpha );
SP.Draw();
@@ -1226,7 +1236,7 @@ void cEETest::Screen2() {
PR.DrawQuad( CL1.GetQuad(), EE_DRAW_LINE );
- Ang = Ang + EE->Elapsed() * 0.1f;
+ Ang = Ang + mWindow->Elapsed() * 0.1f;
if (Ang > 360.f) Ang = 1.f;
if ( ShowParticles )
@@ -1234,10 +1244,10 @@ void cEETest::Screen2() {
PR.SetColor( eeColorA(0, 255, 0, 50) );
- if (IntersectLines( eeVector2f(0.f, 0.f), eeVector2f( (eeFloat)EE->GetWidth(), (eeFloat)EE->GetHeight() ), eeVector2f(Mousef.x - 80.f, Mousef.y - 80.f), eeVector2f(Mousef.x + 80.f, Mousef.y + 80.f) ) )
+ if (IntersectLines( eeVector2f(0.f, 0.f), eeVector2f( (eeFloat)mWindow->GetWidth(), (eeFloat)mWindow->GetHeight() ), eeVector2f(Mousef.x - 80.f, Mousef.y - 80.f), eeVector2f(Mousef.x + 80.f, Mousef.y + 80.f) ) )
iL1 = true; else iL1 = false;
- if (IntersectLines( eeVector2f((eeFloat)EE->GetWidth(), 0.f), eeVector2f( 0.f, (eeFloat)EE->GetHeight() ), eeVector2f(Mousef.x - 80.f, Mousef.y + 80.f), eeVector2f(Mousef.x + 80.f, Mousef.y - 80.f) ) )
+ if (IntersectLines( eeVector2f((eeFloat)mWindow->GetWidth(), 0.f), eeVector2f( 0.f, (eeFloat)mWindow->GetHeight() ), eeVector2f(Mousef.x - 80.f, Mousef.y + 80.f), eeVector2f(Mousef.x + 80.f, Mousef.y - 80.f) ) )
iL2 = true; else iL2 = false;
if (iL1 && iL2)
@@ -1252,10 +1262,10 @@ void cEETest::Screen2() {
PR.DrawTriangle( eeVector2f( Mousef.x, Mousef.y - 10.f ), eeVector2f( Mousef.x - 10.f, Mousef.y + 10.f ), eeVector2f( Mousef.x + 10.f, Mousef.y + 10.f ), EE_DRAW_LINE );
PR.DrawLine( eeVector2f(Mousef.x - 80.f, Mousef.y - 80.f), eeVector2f(Mousef.x + 80.f, Mousef.y + 80.f) );
PR.DrawLine( eeVector2f(Mousef.x - 80.f, Mousef.y + 80.f), eeVector2f(Mousef.x + 80.f, Mousef.y - 80.f) );
- PR.DrawLine( eeVector2f((eeFloat)EE->GetWidth(), 0.f), eeVector2f( 0.f, (eeFloat)EE->GetHeight() ) );
+ PR.DrawLine( eeVector2f((eeFloat)mWindow->GetWidth(), 0.f), eeVector2f( 0.f, (eeFloat)mWindow->GetHeight() ) );
PR.DrawQuad( eeVector2f(0.f, 0.f), eeVector2f(0.f, 100.f), eeVector2f(150.f, 150.f), eeVector2f(200.f, 150.f), eeColorA(220, 240, 0, 125), eeColorA(100, 0, 240, 125), eeColorA(250, 50, 25, 125), eeColorA(50, 150, 150, 125) );
PR.DrawRectangle(Mousef.x - 80.f, Mousef.y - 80.f, 160.f, 160.f, 45.f, 1.f, EE_DRAW_LINE);
- PR.DrawLine( eeVector2f(0.f, 0.f), eeVector2f( (eeFloat)EE->GetWidth(), (eeFloat)EE->GetHeight() ) );
+ PR.DrawLine( eeVector2f(0.f, 0.f), eeVector2f( (eeFloat)mWindow->GetWidth(), (eeFloat)mWindow->GetHeight() ) );
TNP[3]->DrawQuadEx( eeQuad2f( eeVector2f(0.f, 0.f), eeVector2f(0.f, 100.f), eeVector2f(150.f, 150.f), eeVector2f(200.f, 150.f) ), 0.0f, 0.0f, ang, scale, eeColorA(220, 240, 0, 125), eeColorA(100, 0, 240, 125), eeColorA(250, 50, 25, 125), eeColorA(50, 150, 150, 125) );
@@ -1299,7 +1309,7 @@ void cEETest::Screen4() {
mFBO->Unbind();
if ( NULL != mFBO->GetTexture() ) {
- mFBO->GetTexture()->Draw( (eeFloat)EE->GetWidth() * 0.5f - (eeFloat)mFBO->GetWidth() * 0.5f, (eeFloat)EE->GetHeight() * 0.5f - (eeFloat)mFBO->GetHeight() * 0.5f, Ang );
+ mFBO->GetTexture()->Draw( (eeFloat)mWindow->GetWidth() * 0.5f - (eeFloat)mFBO->GetWidth() * 0.5f, (eeFloat)mWindow->GetHeight() * 0.5f - (eeFloat)mFBO->GetHeight() * 0.5f, Ang );
cGlobalBatchRenderer::instance()->Draw();
}
}
@@ -1313,14 +1323,14 @@ void cEETest::Render() {
if ( !mTextureLoaded )
mResLoad.Update();
- HWidth = EE->GetWidth() * 0.5f;
- HHeight = EE->GetHeight() * 0.5f;
+ HWidth = mWindow->GetWidth() * 0.5f;
+ HHeight = mWindow->GetHeight() * 0.5f;
if ( eeGetTicks() - lasttick >= 50 ) {
lasttick = eeGetTicks();
#ifdef EE_DEBUG
mInfo = StrFormated( "EE - FPS: %d Elapsed Time: %4.8f\nMouse X: %d Mouse Y: %d\nTexture Memory Usage: %s\nApp Memory Usage: %s\nApp Peak Memory Usage: %s",
- EE->FPS(),
+ mWindow->FPS(),
et,
(Int32)Mouse.x,
(Int32)Mouse.y,
@@ -1330,7 +1340,7 @@ void cEETest::Render() {
);
#else
mInfo = StrFormated( "EE - FPS: %d Elapsed Time: %4.8f\nMouse X: %d Mouse Y: %d\nTexture Memory Usage: %s",
- EE->FPS(),
+ mWindow->FPS(),
et,
(Int32)Mouse.x,
(Int32)Mouse.y,
@@ -1344,23 +1354,23 @@ void cEETest::Render() {
if ( !MultiViewportMode ) {
Scenes[ Screen ]();
} else {
- Views[0].SetView( 0, 0, EE->GetWidth(), static_cast( HHeight ) );
- Views[1].SetView( 0, static_cast ( HHeight ), EE->GetWidth(), static_cast( HHeight ) );
+ Views[0].SetView( 0, 0, mWindow->GetWidth(), static_cast( HHeight ) );
+ Views[1].SetView( 0, static_cast ( HHeight ), mWindow->GetWidth(), static_cast( HHeight ) );
- EE->SetView( Views[1] );
+ mWindow->SetView( Views[1] );
Mouse = KM->GetMousePosFromView( Views[1] );
Mousef = eeVector2f( (eeFloat)Mouse.x, (eeFloat)Mouse.y );
Screen2();
- EE->SetView( Views[0] );
+ mWindow->SetView( Views[0] );
Mouse = KM->GetMousePosFromView( Views[0] );
Mousef = eeVector2f( (eeFloat)Mouse.x, (eeFloat)Mouse.y );
Screen1();
- EE->SetView( EE->GetDefaultView() );
- EE->ClipEnable( (Int32)HWidth - 320, (Int32)HHeight - 240, 640, 480 );
+ mWindow->SetView( mWindow->GetDefaultView() );
+ mWindow->ClipEnable( (Int32)HWidth - 320, (Int32)HHeight - 240, 640, 480 );
Screen3();
- EE->ClipDisable();
+ mWindow->ClipDisable();
}
eeColorA ColRR1( 150, 150, 150, 220 );
@@ -1372,13 +1382,13 @@ void cEETest::Render() {
PR.DrawRectangle(
0.f,
- (eeFloat)EE->GetHeight() - (eeFloat)mEEText.GetNumLines() * (eeFloat)mEEText.Font()->GetFontSize(),
+ (eeFloat)mWindow->GetHeight() - (eeFloat)mEEText.GetNumLines() * (eeFloat)mEEText.Font()->GetFontSize(),
mEEText.GetTextWidth(),
mEEText.GetTextHeight(),
ColRR1, ColRR2, ColRR3, ColRR4
);
- mEEText.Draw( 0.f, (eeFloat)EE->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER, 1.f, Ang );
+ mEEText.Draw( 0.f, (eeFloat)mWindow->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER, 1.f, Ang );
mInfoText.Draw( 6.f, 6.f );
@@ -1391,8 +1401,8 @@ void cEETest::Render() {
FF2->Draw( L"_", 6.f + FF2->GetTextWidth(), 180.f + (eeFloat)LineNum * (eeFloat)FF2->GetFontSize() );
}
- FF2->SetText( L"FPS: " + toWStr( EE->FPS() ) );
- FF2->Draw( EE->GetWidth() - FF2->GetTextWidth() - 15, 0 );
+ FF2->SetText( L"FPS: " + toWStr( mWindow->FPS() ) );
+ FF2->Draw( mWindow->GetWidth() - FF2->GetTextWidth() - 15, 0 );
FF2->SetText( InBuf.Buffer() );
FF2->Draw( 6, 180, FONT_DRAW_SHADOW );
@@ -1415,56 +1425,56 @@ void cEETest::Input() {
Mouse = KM->GetMousePos();
Mousef = eeVector2f( (eeFloat)Mouse.x, (eeFloat)Mouse.y );
- if ( !EE->WindowVisible() ) {
+ if ( !mWindow->Visible() ) {
mWasMinimized = true;
- EE->SetFrameRateLimit( 10 );
+ mWindow->FrameRateLimit( 10 );
if ( Mus->State() == SOUND_PLAYING )
Mus->Pause();
} else {
- if ( mLastFPSLimit != EE->GetFrameRateLimit() && !mWasMinimized )
- mLastFPSLimit = EE->GetFrameRateLimit();
+ if ( mLastFPSLimit != mWindow->FrameRateLimit() && !mWasMinimized )
+ mLastFPSLimit = mWindow->FrameRateLimit();
if ( mWasMinimized ) {
mWasMinimized = false;
- if ( !EE->Windowed() )
+ if ( !mWindow->Windowed() )
KM->GrabInput( true );
}
- EE->SetFrameRateLimit( mLastFPSLimit );
+ mWindow->FrameRateLimit( mLastFPSLimit );
if ( Mus->State() == SOUND_PAUSED )
Mus->Play();
}
if ( KM->IsKeyDown(KEY_ESCAPE) )
- EE->Running(false);
+ mWindow->Close();
if ( KM->IsKeyUp(KEY_F1) )
MultiViewportMode = !MultiViewportMode;
if ( KM->AltPressed() && KM->IsKeyUp(KEY_M) && !Con.Active() )
- EE->MaximizeWindow();
+ mWindow->Maximize();
if ( KM->IsKeyUp(KEY_F4) )
TF->ReloadAllTextures();
if ( KM->AltPressed() && KM->IsKeyUp(KEY_RETURN) ) {
- if ( EE->Windowed() ) {
- EE->ChangeRes( EE->GetDeskWidth(), EE->GetDeskHeight(), false );
+ if ( mWindow->Windowed() ) {
+ mWindow->Size( mWindow->GetDesktopResolution().Width(), mWindow->GetDesktopResolution().Height(), false );
KM->GrabInput(true);
} else {
- EE->ToggleFullscreen();
+ mWindow->ToggleFullscreen();
KM->GrabInput(false);
}
}
if ( KM->GrabInput() ) {
if ( KM->AltPressed() && KM->IsKeyDown( KEY_TAB ) ) {
- EE->MinimizeWindow();
+ mWindow->Minimize();
if ( KM->GrabInput() )
KM->GrabInput( false );
@@ -1519,7 +1529,7 @@ void cEETest::Input() {
Int16 aY = Joy->GetAxis( AXIS_Y );
if ( 0 != aX || 0 != aY ) {
- eeFloat rE = EE->Elapsed();
+ eeFloat rE = mWindow->Elapsed();
if ( aX < 0 ) mAxisX -= ( (eeFloat)aX / (eeFloat)AXIS_MIN ) * rE;
else mAxisX += ( (eeFloat)aX / (eeFloat)AXIS_MAX ) * rE;
@@ -1556,35 +1566,35 @@ void cEETest::Input() {
Uint8 hat = Joy->GetHat();
if ( HAT_LEFT == hat || HAT_LEFTDOWN == hat || HAT_LEFTUP == hat )
- Map.Move( (EE->Elapsed() * 0.2f), 0 );
+ Map.Move( (mWindow->Elapsed() * 0.2f), 0 );
if ( HAT_RIGHT == hat || HAT_RIGHTDOWN == hat || HAT_RIGHTUP == hat )
- Map.Move( -EE->Elapsed() * 0.2f, 0 );
+ Map.Move( -mWindow->Elapsed() * 0.2f, 0 );
if ( HAT_UP == hat || HAT_LEFTUP == hat || HAT_RIGHTUP == hat )
- Map.Move( 0, (EE->Elapsed() * 0.2f) );
+ Map.Move( 0, (mWindow->Elapsed() * 0.2f) );
if ( HAT_DOWN == hat || HAT_LEFTDOWN == hat || HAT_RIGHTDOWN == hat )
- Map.Move( 0, -EE->Elapsed() * 0.2f );
+ Map.Move( 0, -mWindow->Elapsed() * 0.2f );
}
if ( KM->IsKeyDown(KEY_LEFT) )
- Map.Move( (EE->Elapsed() * 0.2f), 0 );
+ Map.Move( (mWindow->Elapsed() * 0.2f), 0 );
if ( KM->IsKeyDown(KEY_RIGHT) )
- Map.Move( -EE->Elapsed() * 0.2f, 0 );
+ Map.Move( -mWindow->Elapsed() * 0.2f, 0 );
if ( KM->IsKeyDown(KEY_UP) )
- Map.Move( 0, (EE->Elapsed() * 0.2f) );
+ Map.Move( 0, (mWindow->Elapsed() * 0.2f) );
if ( KM->IsKeyDown(KEY_DOWN) )
- Map.Move( 0, -EE->Elapsed() * 0.2f );
+ Map.Move( 0, -mWindow->Elapsed() * 0.2f );
if ( KM->IsKeyDown(KEY_KP_MINUS) )
- Map.BaseLight().Radius( Map.BaseLight().Radius() - EE->Elapsed() * 0.2f );
+ Map.BaseLight().Radius( Map.BaseLight().Radius() - mWindow->Elapsed() * 0.2f );
if ( KM->IsKeyDown(KEY_KP_PLUS) )
- Map.BaseLight().Radius( Map.BaseLight().Radius() + EE->Elapsed() * 0.2f );
+ Map.BaseLight().Radius( Map.BaseLight().Radius() + mWindow->Elapsed() * 0.2f );
if ( KM->IsKeyUp(KEY_F6) ) {
Wireframe = !Wireframe;
@@ -1641,7 +1651,7 @@ void cEETest::Process() {
Init();
if ( run ) {
do {
- et = EE->Elapsed();
+ et = mWindow->Elapsed();
Input();
@@ -1650,10 +1660,10 @@ void cEETest::Process() {
else
mFontLoader.Update();
- if ( KM->IsKeyUp(KEY_F12) ) EE->TakeScreenshot( MyPath + "data/screenshots/" ); //After render and before Display
+ if ( KM->IsKeyUp(KEY_F12) ) mWindow->TakeScreenshot( MyPath + "data/screenshots/" ); //After render and before Display
- EE->Display();
- } while( EE->Running() );
+ mWindow->Display();
+ } while( mWindow->Running() );
}
End();
@@ -1720,27 +1730,27 @@ void cEETest::Demo1Create() {
cBody *body, *staticBody = mSpace->StaticBody();
Physics::cShape * shape;
- shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, EE->GetHeight() ), cVectNew( EE->GetWidth(), EE->GetHeight() ), 0.0f ) );
+ shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, mWindow->GetHeight() ), cVectNew( mWindow->GetWidth(), mWindow->GetHeight() ), 0.0f ) );
shape->e( 1.0f );
shape->u( 1.0f );
shape->Layers( NOT_GRABABLE_MASK );
- shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( EE->GetWidth(), 0 ), cVectNew( EE->GetWidth(), EE->GetHeight() ), 0.0f ) );
+ shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( mWindow->GetWidth(), 0 ), cVectNew( mWindow->GetWidth(), mWindow->GetHeight() ), 0.0f ) );
shape->e( 1.0f );
shape->u( 1.0f );
shape->Layers( NOT_GRABABLE_MASK );
- shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, 0 ), cVectNew( 0, EE->GetHeight() ), 0.0f ) );
+ shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, 0 ), cVectNew( 0, mWindow->GetHeight() ), 0.0f ) );
shape->e( 1.0f );
shape->u( 1.0f );
shape->Layers( NOT_GRABABLE_MASK );
- shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, 0 ), cVectNew( EE->GetWidth(), 0 ), 0.0f ) );
+ shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, 0 ), cVectNew( mWindow->GetWidth(), 0 ), 0.0f ) );
shape->e( 1.0f );
shape->u( 1.0f );
shape->Layers( NOT_GRABABLE_MASK );
- eeFloat hw = EE->GetWidth() / 2;
+ eeFloat hw = mWindow->GetWidth() / 2;
for(int i=0; i<14; i++){
for(int j=0; j<=i; j++){
@@ -1757,7 +1767,7 @@ void cEETest::Demo1Create() {
cpFloat radius = 15.0f;
body = mSpace->AddBody( cBody::New( 10.0f, Moment::ForCircle( 10.0f, 0.0f, radius, cVectZero ) ) );
- body->Pos( cVectNew( hw, EE->GetHeight() - radius - 5 ) );
+ body->Pos( cVectNew( hw, mWindow->GetHeight() - radius - 5 ) );
//shape = mSpace->AddShape( cShapeCircleSprite::New( body, radius, cVectZero, mCircleSprite ) );
shape = mSpace->AddShape( cShapeCircle::New( body, radius, cVectZero ) );
@@ -1837,7 +1847,7 @@ void cEETest::Demo2Create() {
emitterInstance.queue = 5;
emitterInstance.blocked = 0;
- emitterInstance.position = cVectNew( EE->GetWidth() / 2 , 150);
+ emitterInstance.position = cVectNew( mWindow->GetWidth() / 2 , 150);
shape = mSpace->AddShape( cShapeCircle::New( staticBody, 15.0f, emitterInstance.position ) );
shape->Sensor( 1 );
@@ -1927,7 +1937,7 @@ void cEETest::PhysicsUpdate() {
mMousePoint = cVectNew( KM->GetMousePosf().x, KM->GetMousePosf().y );
cVect newPoint = tovect( cpvlerp( tocpv( mMousePoint_last ), tocpv( mMousePoint ), 0.25 ) );
mMouseBody->Pos( newPoint );
- mMouseBody->Vel( ( newPoint - mMousePoint_last ) * (cpFloat)EE->FPS() );
+ mMouseBody->Vel( ( newPoint - mMousePoint_last ) * (cpFloat)mWindow->FPS() );
mMousePoint_last = newPoint;
if ( KM->MouseLeftPressed() ) {
@@ -1956,118 +1966,15 @@ void cEETest::PhysicsUpdate() {
void cEETest::PhysicsDestroy() {
mDemo[ mCurDemo ].destroy();
- cPhysicsManager::DestroySingleton();
}
-/*
-static void defineVertexArrayObject(GLuint vaoId, size_t NbytesV, size_t NbytesC, GLint size, GLenum type, GLfloat *vertices, GLfloat *colors, GLfloat * texCoords, GLuint shader_id ) {
- //enable vertex array object to be defined
- glBindVertexArray(vaoId);
- //generate VBO foreach 'in'; dgl_Vertex dgl_Color dgl_TexCoord
- GLuint m_vboId[3];
- glGenBuffers(3, &m_vboId[0]);
-
- //"in vec2 dgl_Vertex;",
- glBindBuffer(GL_ARRAY_BUFFER, m_vboId[0] ); // enable the 1st VBO
- glBufferData(GL_ARRAY_BUFFER, NbytesV, vertices, GL_STATIC_DRAW); // fill the VBO with vertices data
- const GLuint index_mPosition = glGetAttribLocation( shader_id, "dgl_Vertex" ); // get ID for "dgl_Vertex"
- glEnableVertexAttribArray( index_mPosition ); // enable VBO vertex attribute ("dgl_Vertex")
- glVertexAttribPointer( index_mPosition, 2, type, GL_FALSE, 0, 0 ); // VBO point to the "dgl_Vertex" attribute
-
- //"in vec4 dgl_Color;",
- glBindBuffer( GL_ARRAY_BUFFER, m_vboId[1] ); // enable the 2nd VBO
- glBufferData( GL_ARRAY_BUFFER, NbytesC, colors, GL_STATIC_DRAW ); // fill the 2nd VBO with colors data
- const GLuint index_mcolor = glGetAttribLocation( shader_id,"dgl_Color" ); // get ID for "dgl_Color"
- glEnableVertexAttribArray( index_mcolor ); // enable VBO vertex attribute ("dgl_Color")
- glVertexAttribPointer( index_mcolor, 4, type, GL_FALSE, 0, 0 ); // VBO point to the "dgl_Color" attribute
-
- //"in vec2 dgl_TexCoord;",
- glBindBuffer( GL_ARRAY_BUFFER, m_vboId[2] ); // enable the 3rd VBO
- glBufferData( GL_ARRAY_BUFFER, NbytesV, texCoords, GL_STATIC_DRAW ); // fill the 3nd VBO with tex coords data
- const GLuint index_mcoords = glGetAttribLocation( shader_id,"dgl_TexCoord" ); // get ID for "dgl_TexCoords"
- glEnableVertexAttribArray( index_mcoords ); // enable VBO vertex attribute ("dgl_TexCoords")
- glVertexAttribPointer( index_mcoords, 2, type, GL_FALSE, 0, 0 ); // VBO point to the "dgl_TexCoords" attribute
-}
-*/
int main (int argc, char * argv []) {
cEETest * Test = eeNew( cEETest, () );
Test->Process();
eeDelete( Test );
-/*
- cEngine * EE = cEngine::instance();
- EE->Init( 800, 600, 32, true, true, true, true, false, false, GLv_3 );
- EE->SetBackColor( eeColor( 255, 255, 255 ) );
- cInput * KM = cInput::instance();
- cTextureFactory * TF = cTextureFactory::instance();
- cTexture * Tex = TF->GetTexture( TF->Load( AppPath() + "data/bnb/bnb.png" ) );
-
- cRendererGL3 * Ren = reinterpret_cast( GLi );
-
- GLfloat vertices0[] = { // dgl_Vertex
- 0.0 , 0.0, // xy
- 0.0 , 600,
- 800.0 , 600.0,
- 800.0 , 0.0
- };
-
- size_t Nbytes_vertices0=sizeof(vertices0);
-
- GLfloat colors0[] = { // dgl_Color
- 1.0, 1.0, 1.0, 0.5, //rgba
- 1.0, 1.0, 1.0, 0.5,
- 1.0, 1.0, 1.0, 0.5,
- 1.0, 1.0, 1.0, 0.5
- };
- size_t Nbytes_colors0=sizeof(colors0);
-
- GLfloat texCoords0[] = { // dgl_TexCoord
- 0.0 , 0.0, // xy
- 0.0 , 1.0,
- 1.0 , 1.0,
- 1.0 , 0.0
- };
-
- GLuint vao_id;
-
- glGenVertexArrays( 1, &vao_id );
- glBindVertexArray( vao_id );
-
- GLuint vao_elementcount = Nbytes_vertices0 / 2 / sizeof(GLfloat);
-
- defineVertexArrayObject( vao_id, Nbytes_vertices0, Nbytes_colors0, 4, GL_FLOAT, vertices0, colors0, texCoords0, Ren->BaseShaderId() );
-
- eeFloat ang = 0;
-
- while( EE->Running() ) {
- KM->Update();
-
- ang += EE->Elapsed() * 0.1;
-
- TF->Bind( Tex );
- //glBindVertexArray( vao_id );
-
- GLi->DrawArrays( GL_TRIANGLE_FAN, 0, vao_elementcount );
-
- GLi->PushMatrix();
-
- GLi->Translatef( 400, 300, 0 );
- GLi->Rotatef( ang, 0, 0, 1 );
- GLi->Translatef( -400, -300, 0 );
-
- GLi->DrawArrays( GL_TRIANGLE_FAN, 0, vao_elementcount );
-
- GLi->PopMatrix();
-
- EE->Display();
-
- if ( KM->IsKeyDown( KEY_ESCAPE ) ) EE->Running( false );
- };
-
- cEngine::DestroySingleton();
-*/
EE::MemoryManager::LogResults();
return 0;
diff --git a/src/ui/cuimanager.cpp b/src/ui/cuimanager.cpp
index c18f19e58..99969eac3 100644
--- a/src/ui/cuimanager.cpp
+++ b/src/ui/cuimanager.cpp
@@ -3,7 +3,8 @@
namespace EE { namespace UI {
-cUIManager::cUIManager() :
+cUIManager::cUIManager( cWindow * window ) :
+ mWindow( window ),
mKM( NULL ),
mInit( false ),
mControl( NULL ),
@@ -11,9 +12,14 @@ cUIManager::cUIManager() :
mOverControl( NULL ),
mDownControl( NULL ),
mFirstPress( false ),
- mCbId(-1)
+ mCbId(-1),
+ mResizeCb(0)
{
- mKM = cInput::instance();
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
+
+ mKM = mWindow->GetInput();
}
cUIManager::~cUIManager() {
@@ -32,13 +38,20 @@ void cUIManager::Init() {
mFocusControl = mControl;
mOverControl = mControl;
- mCbId = cInput::instance()->PushCallback( cb::Make1( this, &cUIManager::InputCallback ) );
+ mCbId = mKM->PushCallback( cb::Make1( this, &cUIManager::InputCallback ) );
+ mResizeCb = mWindow->PushResizeCallback( cb::Make0( this, &cUIManager::ResizeControl ) );
}
void cUIManager::Shutdown() {
if ( mInit ) {
- if ( -1 != mCbId )
- cInput::instance()->PopCallback( mCbId );
+ if ( -1 != mCbId &&
+ NULL != cEngine::ExistsSingleton() &&
+ cEngine::instance()->ExistsWindow( mWindow )
+ )
+ {
+ mKM->PopCallback( mCbId );
+ mWindow->PopResizeCallback( mResizeCb );
+ }
mOverControl = NULL;
mFocusControl = NULL;
@@ -51,19 +64,19 @@ void cUIManager::Shutdown() {
cUIThemeManager::DestroySingleton();
}
-void cUIManager::InputCallback( EE_Event * Event ) {
- switch( Event->type ) {
- case SDL_KEYUP:
+void cUIManager::InputCallback( InputEvent * Event ) {
+ switch( Event->Type ) {
+ case InputEvent::KeyUp:
SendKeyUp( Event->key.keysym.sym, Event->key.keysym.unicode, Event->key.keysym.mod );
break;
- case SDL_KEYDOWN:
+ case InputEvent::KeyDown:
SendKeyDown( Event->key.keysym.sym, Event->key.keysym.unicode, Event->key.keysym.mod );
break;
}
}
void cUIManager::ResizeControl() {
- mControl->Size( cEngine::instance()->GetWidth(), cEngine::instance()->GetHeight() );
+ mControl->Size( mWindow->GetWidth(), mWindow->GetHeight() );
SendMsg( mControl, cUIMessage::MsgWindowResize );
}
@@ -124,7 +137,7 @@ void cUIManager::SendMsg( cUIControl * Ctrl, const Uint32& Msg, const Uint32& Fl
}
void cUIManager::Update() {
- mElapsed = cEngine::instance()->Elapsed();
+ mElapsed = mWindow->Elapsed();
mControl->Update();
@@ -215,11 +228,11 @@ const Uint32& cUIManager::LastPressTrigger() const {
}
void cUIManager::ClipEnable( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height ) {
- cEngine::instance()->ClipPlaneEnable( x, y, Width, Height );
+ mWindow->ClipPlaneEnable( x, y, Width, Height );
}
void cUIManager::ClipDisable() {
- cEngine::instance()->ClipPlaneDisable();
+ mWindow->ClipPlaneDisable();
}
}}
diff --git a/src/ui/cuimanager.hpp b/src/ui/cuimanager.hpp
index cd44d6f62..6c95da8a7 100644
--- a/src/ui/cuimanager.hpp
+++ b/src/ui/cuimanager.hpp
@@ -4,6 +4,7 @@
#include "cuicontrol.hpp"
#include "cuicontrolanim.hpp"
#include "../window/cinput.hpp"
+#include "../window/cwindow.hpp"
namespace EE { namespace UI {
@@ -12,7 +13,7 @@ class cUIControl;
class EE_API cUIManager : public tSingleton {
friend class tSingleton;
public:
- cUIManager();
+ cUIManager( cWindow * window = NULL );
~cUIManager();
@@ -56,6 +57,7 @@ class EE_API cUIManager : public tSingleton {
void SendKeyDown( const Uint32& KeyCode, const Uint16& Char, const Uint32& Mod );
protected:
+ cWindow * mWindow;
cInput * mKM;
bool mInit;
@@ -66,8 +68,9 @@ class EE_API cUIManager : public tSingleton {
bool mFirstPress;
eeFloat mElapsed;
Int32 mCbId;
+ Uint32 mResizeCb;
- void InputCallback( EE_Event * Event );
+ void InputCallback( InputEvent * Event );
};
}}
diff --git a/src/ui/cuiscrollbar.cpp b/src/ui/cuiscrollbar.cpp
index 8fa9a8a66..3870738fd 100644
--- a/src/ui/cuiscrollbar.cpp
+++ b/src/ui/cuiscrollbar.cpp
@@ -127,7 +127,7 @@ void cUIScrollBar::Update() {
void cUIScrollBar::ManageClick( const Uint32& Flags ) {
if ( Flags & EE_BUTTONS_WUWD ) {
- if ( Flags & EE_BUTTON( EE_BUTTON_WHEELUP ) )
+ if ( Flags & EE_BUTTON_WUMASK )
mSlider->Value( Value() + ClickStep() );
else
mSlider->Value( Value() - ClickStep() );
diff --git a/src/ui/cuislider.cpp b/src/ui/cuislider.cpp
index b3c3c0b15..bb283de9c 100644
--- a/src/ui/cuislider.cpp
+++ b/src/ui/cuislider.cpp
@@ -301,7 +301,7 @@ void cUISlider::ManageClick( const Uint32& Flags ) {
Value( mValue + mClickStep );
}
} else if ( Flags & EE_BUTTONS_WUWD ) {
- if ( Flags & EE_BUTTON( EE_BUTTON_WHEELUP ) )
+ if ( Flags & EE_BUTTON_WUMASK )
Value( mValue - mClickStep );
else
Value( mValue + mClickStep );
diff --git a/src/ui/cuispinbox.cpp b/src/ui/cuispinbox.cpp
index 9c58f5e28..77b4baeda 100644
--- a/src/ui/cuispinbox.cpp
+++ b/src/ui/cuispinbox.cpp
@@ -114,7 +114,7 @@ Uint32 cUISpinBox::OnMessage( const cUIMessage * Msg ) {
AddValue( -mClickStep );
}
} else if ( Msg->Flags() & EE_BUTTONS_WUWD ) {
- if ( Msg->Flags() & EE_BUTTON( EE_BUTTON_WHEELUP ) )
+ if ( Msg->Flags() & EE_BUTTON_WUMASK )
AddValue( mClickStep );
else
AddValue( -mClickStep );
diff --git a/src/ui/cuitextinput.cpp b/src/ui/cuitextinput.cpp
index fa5638dfe..43673b9ea 100644
--- a/src/ui/cuitextinput.cpp
+++ b/src/ui/cuitextinput.cpp
@@ -62,10 +62,10 @@ void cUITextInput::Draw() {
mWaitCursorTime += cUIManager::instance()->Elapsed();
if ( mShowingWait ) {
- bool disableSmooth = mShowingWait && cEngine::instance()->GetVideoInfo()->LineSmooth;
+ bool disableSmooth = mShowingWait && GLi->IsLineSmooth();
if ( disableSmooth )
- cEngine::instance()->SetLineSmooth( false );
+ GLi->LineSmooth( false );
cPrimitives P;
P.SetColor( mFontColor );
@@ -79,7 +79,7 @@ void cUITextInput::Draw() {
P.DrawLine( CurPosX, CurPosY, CurPosX, CurPosY + mTextCache->Font()->GetFontHeight(), 1.f );
if ( disableSmooth )
- cEngine::instance()->SetLineSmooth( true );
+ GLi->LineSmooth( true );
}
if ( mWaitCursorTime >= 500.f ) {
diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp
index 653be8231..2b988dc48 100755
--- a/src/utils/utils.cpp
+++ b/src/utils/utils.cpp
@@ -28,8 +28,8 @@
static bool TickStarted = false;
-#if EE_PLATFORM == EE_PLATFORM_WIN
-
+#if EE_PLATFORM == EE_PLATFORM_WIN
+
#define TIME_WRAP_VALUE (~(DWORD)0)
/* The first high-resolution ticks value of the application */
static LARGE_INTEGER hires_start_ticks;
@@ -57,7 +57,7 @@ bool FileExists( const std::string& Filepath ) {
}
static void eeStartTicks() {
-#if EE_PLATFORM == EE_PLATFORM_WIN
+#if EE_PLATFORM == EE_PLATFORM_WIN
QueryPerformanceFrequency(&hires_ticks_per_second);
QueryPerformanceCounter(&hires_start_ticks);
#elif EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_MACOSX
@@ -78,7 +78,7 @@ Uint32 eeGetTicks() {
eeStartTicks();
#if EE_PLATFORM == EE_PLATFORM_WIN
- LARGE_INTEGER hires_now;
+ LARGE_INTEGER hires_now;
QueryPerformanceCounter(&hires_now);
@@ -661,4 +661,13 @@ bool Read32BitKey( Uint32 * Key, Uint32 Pos ) {
return 0 != ( ( * Key ) & ( 1 << Pos ) );
}
+void SetFlagValue( Uint32 * Key, Uint32 Val, Uint32 BitWrite ) {
+ if ( BitWrite )
+ ( * Key ) |= Val;
+ else {
+ if ( ( * Key ) & Val )
+ ( * Key ) &= ~Val;
+ }
+}
+
}}
diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp
index 411e09951..32f6618aa 100755
--- a/src/utils/utils.hpp
+++ b/src/utils/utils.hpp
@@ -114,14 +114,17 @@ namespace EE { namespace Utils {
* @param Pos The Position of the bit
* @param BitWrite 0 for write 0, any other to write 1.
*/
- void Write32BitKey( Uint32 * Key, Uint32 Pos, Uint32 BitWrite );
+ void EE_API Write32BitKey( Uint32 * Key, Uint32 Pos, Uint32 BitWrite );
/** Read a bit from a 32 bit key, in the position defined
* @param Key The Key to read
* @param Pos The Position in the key to read
* @return True if the bit is 1
*/
- bool Read32BitKey( Uint32 * Key, Uint32 Pos );
+ bool EE_API Read32BitKey( Uint32 * Key, Uint32 Pos );
+
+ /** Write a 32 bit flag value */
+ void EE_API SetFlagValue( Uint32 * Key, Uint32 Val, Uint32 BitWrite );
}
}
diff --git a/src/window/backend/SDL/cbackendsdl.hpp b/src/window/backend/SDL/cbackendsdl.hpp
new file mode 100644
index 000000000..204f6aad2
--- /dev/null
+++ b/src/window/backend/SDL/cbackendsdl.hpp
@@ -0,0 +1,23 @@
+#ifndef EE_WINDOWCBACKENDSDL_HPP
+#define EE_WINDOWCBACKENDSDL_HPP
+
+#include "../../cbackend.hpp"
+#include
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+class EE_API cBackendSDL : public cBackend {
+ public:
+ inline cBackendSDL() : cBackend()
+ {
+ }
+
+ inline ~cBackendSDL()
+ {
+ SDL_Quit();
+ }
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/SDL/cclipboardsdl.cpp b/src/window/backend/SDL/cclipboardsdl.cpp
new file mode 100644
index 000000000..05d3197f1
--- /dev/null
+++ b/src/window/backend/SDL/cclipboardsdl.cpp
@@ -0,0 +1,315 @@
+#include "cclipboardsdl.hpp"
+#include "cwindowsdl.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+static void * CurrentHandler = NULL;
+
+#define T(A, B, C, D) (int)((A<<24)|(B<<16)|(C<<8)|(D<<0))
+#define FORMAT_PREFIX "EE_scrap_0x"
+
+#if EE_PLATFORM == EE_PLATFORM_LINUX
+static int clipboard_filter( const SDL_Event *event ) {
+ /* Post all non-window manager specific events */
+ if ( event->type != SDL_SYSWMEVENT ) {
+ return 1;
+ }
+
+ /** FIXME: Support multiple windows */
+ //Display * curDisplay = cEngine::instance()->GetWindowHandler();
+ Display * curDisplay = (Display *)CurrentHandler;
+
+ /* Handle window-manager specific clipboard events */
+ switch ( event->syswm.msg->event.xevent.type ) {
+ /* Copy the selection from XA_CUT_BUFFER0 to the requested property */
+ case SelectionRequest:
+ {
+ XSelectionRequestEvent *req;
+ XEvent sevent;
+ int seln_format;
+ unsigned long nbytes;
+ unsigned long overflow;
+ unsigned char *seln_data;
+
+ req = &event->syswm.msg->event.xevent.xselectionrequest;
+ sevent.xselection.type = SelectionNotify;
+ sevent.xselection.display = req->display;
+ sevent.xselection.selection = req->selection;
+ sevent.xselection.target = None;
+ sevent.xselection.property = None;
+ sevent.xselection.requestor = req->requestor;
+ sevent.xselection.time = req->time;
+
+ if ( XGetWindowProperty(curDisplay, DefaultRootWindow(curDisplay), XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target, &sevent.xselection.target, &seln_format, &nbytes, &overflow, &seln_data) == Success ) {
+ if ( sevent.xselection.target == req->target ) {
+ if ( sevent.xselection.target == XA_STRING ) {
+ if ( seln_data[nbytes-1] == '\0' )
+ --nbytes;
+ }
+
+ XChangeProperty(curDisplay, req->requestor, req->property, sevent.xselection.target, seln_format, PropModeReplace, seln_data, nbytes);
+ sevent.xselection.property = req->property;
+ }
+
+ XFree(seln_data);
+ }
+
+ XSendEvent(curDisplay,req->requestor, False, 0, &sevent);
+ XSync(curDisplay, False);
+ }
+
+ break;
+ }
+
+ /* Post the event for X11 clipboard reading above */
+ return 1;
+}
+#endif
+
+cClipboardSDL::cClipboardSDL( cWindow * window ) :
+ cClipboard( window ),
+ mInfo( NULL )
+{
+}
+
+cClipboardSDL::~cClipboardSDL() {
+}
+
+void cClipboardSDL::Init() {
+ #if EE_PLATFORM == EE_PLATFORM_LINUX
+ /// Enable the special window hook events
+ SDL_EventState( SDL_SYSWMEVENT, SDL_ENABLE );
+ SDL_SetEventFilter( clipboard_filter );
+
+ /** FIXME: Support multiple windows */
+ CurrentHandler = (void*)mWindow->GetWindowHandler();
+ #endif
+
+ mInfo = &( reinterpret_cast ( mWindow )->mWMinfo );
+}
+
+void cClipboardSDL::SetText( const std::string& Text ) {
+}
+
+void cClipboardSDL::SetText( const std::wstring& Text ) {
+}
+
+int cClipboardSDL::clipboard_convert_scrap( int type, char *dst, char *src, int srclen ) {
+ int dstlen;
+
+ dstlen = 0;
+ switch (type) {
+ case T('T', 'E', 'X', 'T'):
+ if ( srclen == 0 )
+ srclen = (int)strlen(src);
+
+ if ( dst ) {
+ while ( --srclen >= 0 ) {
+ #if EE_PLATFORM == EE_PLATFORM_WIN
+ if ( *src == '\r' )
+ /* drop extraneous '\r' */;
+ else
+ #endif
+ if ( *src == '\n' ) {
+ *dst++ = '\r';
+ ++dstlen;
+ } else {
+ *dst++ = *src;
+ ++dstlen;
+ }
+ ++src;
+ }
+ *dst = '\0';
+ ++dstlen;
+ } else {
+ while ( --srclen >= 0 ) {
+ #if EE_PLATFORM == EE_PLATFORM_WIN
+ if ( *src == '\r' )
+ /* drop unspected '\r' */;
+ else
+ #endif
+ ++dstlen;
+ ++src;
+ }
+ ++dstlen;
+ }
+ break;
+ default:
+ dstlen = *(int *)src;
+ if ( dst ) {
+ if ( srclen == 0 )
+ memcpy(dst, src+sizeof(int), dstlen);
+ else
+ memcpy(dst, src+sizeof(int), srclen-sizeof(int));
+ }
+ break;
+ }
+ return dstlen;
+}
+
+eeScrapType cClipboardSDL::clipboard_convert_format( int type ) {
+ switch (type) {
+ case T('T', 'E', 'X', 'T'):
+ #if EE_PLATFORM == EE_PLATFORM_LINUX
+ return XA_STRING;
+ #elif EE_PLATFORM == EE_PLATFORM_WIN
+ return CF_TEXT;
+ #endif
+ default: {
+ char format[ sizeof(FORMAT_PREFIX)+8+1 ];
+ StrFormat(format, sizeof(FORMAT_PREFIX)+8+1, "%s%08lx", FORMAT_PREFIX, (unsigned long)type);
+
+ #if EE_PLATFORM == EE_PLATFORM_LINUX
+ return XInternAtom( mInfo->info.x11.display, format, False );
+ #elif EE_PLATFORM == EE_PLATFORM_WIN
+ #ifdef UNICODE
+ return RegisterClipboardFormat( reinterpret_cast( format ) );
+ #else
+ return RegisterClipboardFormat( reinterpret_cast( format ) );
+ #endif
+ #endif
+ }
+ }
+
+ return 0;
+}
+
+void cClipboardSDL::clipboard_get_scrap( int type, int *dstlen, char **dst ) {
+ eeScrapType format;
+ *dstlen = 0;
+ format = clipboard_convert_format( type );
+
+#if EE_PLATFORM == EE_PLATFORM_LINUX
+ X11Window owner;
+ Atom selection;
+ Atom seln_type;
+ int seln_format;
+ unsigned long nbytes;
+ unsigned long overflow;
+ char *src;
+
+ mInfo->info.x11.lock_func();
+ owner = XGetSelectionOwner( mInfo->info.x11.display , XA_PRIMARY);
+ mInfo->info.x11.unlock_func();
+
+ if ( ( owner == None ) || ( owner == mInfo->info.x11.wmwindow ) ) {
+ owner = DefaultRootWindow( mInfo->info.x11.display );
+ selection = XA_CUT_BUFFER0;
+ } else {
+ int selection_response = 0;
+ SDL_Event event;
+
+ owner = mInfo->info.x11.wmwindow;
+ mInfo->info.x11.lock_func();
+
+ selection = XInternAtom( mInfo->info.x11.display, "SELECTION", False);
+ XConvertSelection( mInfo->info.x11.display, XA_PRIMARY, format, selection, owner, CurrentTime);
+
+ mInfo->info.x11.unlock_func();
+
+ while ( ! selection_response ) {
+ SDL_WaitEvent(&event);
+ if ( event.type == SDL_SYSWMEVENT ) {
+ XEvent xevent = event.syswm.msg->event.xevent;
+ if ( (xevent.type == SelectionNotify) && (xevent.xselection.requestor == owner) )
+ selection_response = 1;
+ }
+ }
+ }
+
+ mInfo->info.x11.lock_func();
+ if ( XGetWindowProperty( mInfo->info.x11.display, owner, selection, 0, INT_MAX/4, False, format, &seln_type, &seln_format, &nbytes, &overflow, (unsigned char **)&src ) == Success ) {
+ if ( seln_type == format ) {
+ *dstlen = clipboard_convert_scrap(type, NULL, src, nbytes);
+ *dst = (char *)eeMalloc( *dstlen );
+
+ if ( *dst == NULL )
+ *dstlen = 0;
+ else
+ clipboard_convert_scrap(type, *dst, src, nbytes);
+ }
+ XFree(src);
+ }
+ mInfo->info.x11.unlock_func();
+#elif EE_PLATFORM == EE_PLATFORM_WIN
+ if ( IsClipboardFormatAvailable(format) && OpenClipboard( mInfo->window ) ) {
+ HANDLE hMem;
+ char *src;
+ hMem = GetClipboardData(format);
+ if ( hMem != NULL ) {
+ src = (char *)GlobalLock(hMem);
+ *dstlen = clipboard_convert_scrap(type, NULL, src, 0);
+ *dst = (char *)eeMalloc( *dstlen );
+ if ( *dst == NULL )
+ *dstlen = 0;
+ else
+ clipboard_convert_scrap(type, *dst, src, 0);
+ GlobalUnlock(hMem);
+ }
+ CloseClipboard();
+ }
+#endif
+}
+
+std::string cClipboardSDL::GetText() {
+ std::string tStr;
+
+ #if EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_WIN
+ char *scrap = NULL;
+ int scraplen;
+
+ clipboard_get_scrap( T('T','E','X','T'), &scraplen, &scrap );
+
+ if ( scraplen != 0 && strcmp( scrap, "SDL-\r-scrap") ) {
+ char *cp;
+ int i;
+
+ for ( cp = scrap, i = 0; i < scraplen; ++cp, ++i ) {
+ if ( *cp == '\r' )
+ *cp = '\n';
+ }
+
+ tStr.assign( scrap, scraplen-1 );
+ }
+
+ eeSAFE_DELETE_ARRAY( scrap );
+ #else
+ #warning cClipboardSDL::GetClipboardText() not implemented on this platform.
+ #endif
+
+ return tStr;
+}
+
+std::wstring cClipboardSDL::GetTextWStr() {
+ std::wstring tStr;
+
+ #if EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_WIN
+ char * scrap = NULL;
+ int scraplen;
+
+ clipboard_get_scrap( T('T','E','X','T'), &scraplen, &scrap );
+
+ if ( scraplen != 0 && strcmp( scrap, "SDL-\r-scrap" ) ) {
+ tStr.resize( scraplen-1, L' ' );
+
+ char *cp;
+ int i;
+
+ for ( cp = scrap, i = 0; i < scraplen; ++cp, ++i ) {
+ if ( *cp == '\r' )
+ *cp = '\n';
+
+ unsigned char y = *cp; // convert the nevative values to positives
+ tStr[i] = y;
+ }
+ }
+
+ eeSAFE_DELETE_ARRAY( scrap );
+ #else
+ #warning cClipboardSDL::GetClipboardTextWStr() not implemented on this platform.
+ #endif
+
+ return tStr;
+}
+
+}}}}
diff --git a/src/window/backend/SDL/cclipboardsdl.hpp b/src/window/backend/SDL/cclipboardsdl.hpp
new file mode 100644
index 000000000..53ec8a4aa
--- /dev/null
+++ b/src/window/backend/SDL/cclipboardsdl.hpp
@@ -0,0 +1,40 @@
+#ifndef EE_WINDOWCCLIPBOARDSDL_HPP
+#define EE_WINDOWCCLIPBOARDSDL_HPP
+
+#include "../../base.hpp"
+#include "../../cclipboard.hpp"
+#include
+#include
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+class EE_API cClipboardSDL : public cClipboard {
+ public:
+ virtual ~cClipboardSDL();
+
+ std::string GetText();
+
+ std::wstring GetTextWStr();
+
+ void SetText( const std::string& Text );
+
+ void SetText( const std::wstring& Text );
+ protected:
+ friend class cWindowSDL;
+
+ cClipboardSDL( cWindow * window );
+
+ void Init();
+
+ SDL_SysWMinfo * mInfo;
+
+ eeScrapType clipboard_convert_format(int type);
+
+ int clipboard_convert_scrap(int type, char *dst, char *src, int srclen);
+
+ void clipboard_get_scrap(int type, int *dstlen, char **dst);
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/SDL/cinputsdl.cpp b/src/window/backend/SDL/cinputsdl.cpp
new file mode 100644
index 000000000..eaa7fc519
--- /dev/null
+++ b/src/window/backend/SDL/cinputsdl.cpp
@@ -0,0 +1,192 @@
+#include "cinputsdl.hpp"
+#include "cjoystickmanagersdl.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+cInputSDL::cInputSDL( cWindow * window ) :
+ cInput( window, eeNew( cJoystickManagerSDL, () ) )
+{
+}
+
+cInputSDL::~cInputSDL() {
+}
+
+void cInputSDL::Update() {
+ SDL_Event SDLEvent;
+ InputEvent EEEvent;
+
+ CleanStates();
+
+ while ( SDL_PollEvent( &SDLEvent ) ) {
+ switch( SDLEvent.type ) {
+ case SDL_ACTIVEEVENT:
+ {
+ EEEvent.Type = InputEvent::Active;
+ EEEvent.active.gain = SDLEvent.active.gain;
+ EEEvent.active.state = SDLEvent.active.state;
+ break;
+ }
+ case SDL_KEYDOWN:
+ {
+ EEEvent.Type = InputEvent::KeyDown;
+ EEEvent.key.state = SDLEvent.key.state;
+ EEEvent.key.which = SDLEvent.key.which;
+ EEEvent.key.keysym.sym = SDLEvent.key.keysym.sym;
+ EEEvent.key.keysym.mod = SDLEvent.key.keysym.mod;
+ EEEvent.key.keysym.unicode = SDLEvent.key.keysym.unicode;
+ break;
+ }
+ case SDL_KEYUP:
+ {
+ EEEvent.Type = InputEvent::KeyUp;
+ EEEvent.key.state = SDLEvent.key.state;
+ EEEvent.key.which = SDLEvent.key.which;
+ EEEvent.key.keysym.sym = SDLEvent.key.keysym.sym;
+ EEEvent.key.keysym.mod = SDLEvent.key.keysym.mod;
+ EEEvent.key.keysym.unicode = SDLEvent.key.keysym.unicode;
+ break;
+ }
+ case SDL_MOUSEMOTION:
+ {
+ EEEvent.Type = InputEvent::MouseMotion;
+ EEEvent.motion.which = SDLEvent.motion.which;
+ EEEvent.motion.state = SDLEvent.motion.state;
+ EEEvent.motion.x = SDLEvent.motion.x;
+ EEEvent.motion.y = SDLEvent.motion.y;
+ EEEvent.motion.xrel = SDLEvent.motion.xrel;
+ EEEvent.motion.yrel = SDLEvent.motion.yrel;
+ break;
+ }
+ case SDL_MOUSEBUTTONDOWN:
+ {
+ EEEvent.Type = InputEvent::MouseButtonDown;
+ EEEvent.button.button = SDLEvent.button.button;
+ EEEvent.button.which = SDLEvent.button.which;
+ EEEvent.button.state = SDLEvent.button.state;
+ EEEvent.button.x = SDLEvent.button.x;
+ EEEvent.button.y = SDLEvent.button.y;
+ break;
+ }
+ case SDL_MOUSEBUTTONUP:
+ {
+ EEEvent.Type = InputEvent::MouseButtonUp;
+ EEEvent.button.button = SDLEvent.button.button;
+ EEEvent.button.which = SDLEvent.button.which;
+ EEEvent.button.state = SDLEvent.button.state;
+ EEEvent.button.x = SDLEvent.button.x;
+ EEEvent.button.y = SDLEvent.button.y;
+ break;
+ }
+ case SDL_JOYAXISMOTION:
+ {
+ EEEvent.Type = InputEvent::JoyAxisMotion;
+ EEEvent.jaxis.which = SDLEvent.jaxis.which;
+ EEEvent.jaxis.axis = SDLEvent.jaxis.axis;
+ EEEvent.jaxis.value = SDLEvent.jaxis.value;
+ break;
+ }
+ case SDL_JOYBALLMOTION:
+ {
+ EEEvent.Type = InputEvent::JoyBallMotion;
+ EEEvent.jball.which = SDLEvent.jball.which;
+ EEEvent.jball.ball = SDLEvent.jball.ball;
+ EEEvent.jball.xrel = SDLEvent.jball.xrel;
+ EEEvent.jball.yrel = SDLEvent.jball.yrel;
+ break;
+ }
+ case SDL_JOYHATMOTION:
+ {
+ EEEvent.Type = InputEvent::JoyHatMotion;
+ EEEvent.jhat.which = SDLEvent.jhat.which;
+ EEEvent.jhat.value = SDLEvent.jhat.value;
+ EEEvent.jhat.hat = SDLEvent.jhat.hat;
+ break;
+ }
+ case SDL_JOYBUTTONDOWN:
+ {
+ EEEvent.Type = InputEvent::JoyButtonDown;
+ EEEvent.jbutton.which = SDLEvent.jbutton.which;
+ EEEvent.jbutton.state = SDLEvent.jbutton.state;
+ EEEvent.jbutton.button = SDLEvent.jbutton.button;
+ break;
+ }
+ case SDL_JOYBUTTONUP:
+ {
+ EEEvent.Type = InputEvent::JoyButtonUp;
+ EEEvent.jbutton.which = SDLEvent.jbutton.which;
+ EEEvent.jbutton.state = SDLEvent.jbutton.state;
+ EEEvent.jbutton.button = SDLEvent.jbutton.button;
+ break;
+ }
+ case SDL_QUIT:
+ {
+ EEEvent.Type = InputEvent::Quit;
+ EEEvent.quit.type = EEEvent.Type;
+ break;
+ }
+ case SDL_SYSWMEVENT:
+ {
+ EEEvent.Type = InputEvent::SysWM;
+ EEEvent.syswm.msg = (InputEvent::SysWMmsg*)SDLEvent.syswm.msg;
+ break;
+ }
+ case SDL_VIDEORESIZE:
+ {
+ EEEvent.Type = InputEvent::VideoResize;
+ EEEvent.resize.w = SDLEvent.resize.w;
+ EEEvent.resize.h = SDLEvent.resize.h;
+ break;
+ }
+ case SDL_VIDEOEXPOSE:
+ {
+ EEEvent.Type = InputEvent::VideoExpose;
+ EEEvent.expose.type = EEEvent.Type;
+ break;
+ }
+ default:
+ {
+ if ( SDLEvent.type >= SDL_USEREVENT && SDLEvent.type < SDL_NUMEVENTS ) {
+ EEEvent.Type = InputEvent::EventUser + SDLEvent.type - SDL_USEREVENT;
+ EEEvent.user.type = EEEvent.Type;
+ EEEvent.user.code = SDLEvent.user.code;
+ EEEvent.user.data1 = SDLEvent.user.data1;
+ EEEvent.user.data2 = SDLEvent.user.data2;
+ } else {
+ EEEvent.Type = InputEvent::NoEvent;
+ }
+ }
+ }
+
+ if ( InputEvent::NoEvent != EEEvent.Type ) {
+ ProcessEvent( &EEEvent );
+ }
+ }
+}
+
+bool cInputSDL::GrabInput() {
+ return ( SDL_WM_GrabInput( SDL_GRAB_QUERY ) == SDL_GRAB_ON ) ? true : false;
+}
+
+void cInputSDL::GrabInput( const bool& Grab ) {
+ if ( Grab )
+ SDL_WM_GrabInput(SDL_GRAB_ON);
+ else
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+}
+
+void cInputSDL::InjectMousePos( const Uint16& x, const Uint16& y ) {
+ SDL_WarpMouse( x, y );
+}
+
+void cInputSDL::Init() {
+ eeVector2if mTempMouse;
+ SDL_GetMouseState( &mTempMouse.x, &mTempMouse.y );
+ mMousePos.x = (eeInt)mTempMouse.x;
+ mMousePos.y = (eeInt)mTempMouse.y;
+
+ SDL_EnableUNICODE(1);
+
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+}
+
+}}}}
diff --git a/src/window/backend/SDL/cinputsdl.hpp b/src/window/backend/SDL/cinputsdl.hpp
new file mode 100644
index 000000000..8c9a8e6e7
--- /dev/null
+++ b/src/window/backend/SDL/cinputsdl.hpp
@@ -0,0 +1,31 @@
+#ifndef EE_WINDOWCINPUTSDL_HPP
+#define EE_WINDOWCINPUTSDL_HPP
+
+#include "../../cinput.hpp"
+#include
+#include
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+class EE_API cInputSDL : public cInput {
+ public:
+ virtual ~cInputSDL();
+
+ void Update();
+
+ bool GrabInput();
+
+ void GrabInput( const bool& Grab );
+
+ void InjectMousePos( const Uint16& x, const Uint16& y );
+ protected:
+ friend class cWindowSDL;
+
+ cInputSDL( cWindow * window );
+
+ virtual void Init();
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/SDL/cjoystickmanagersdl.cpp b/src/window/backend/SDL/cjoystickmanagersdl.cpp
new file mode 100644
index 000000000..e7620219d
--- /dev/null
+++ b/src/window/backend/SDL/cjoystickmanagersdl.cpp
@@ -0,0 +1,52 @@
+#include "cjoystickmanagersdl.hpp"
+#include "cjoysticksdl.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+cJoystickManagerSDL::cJoystickManagerSDL() :
+ cJoystickManager()
+{
+}
+
+cJoystickManagerSDL::~cJoystickManagerSDL() {
+}
+
+void cJoystickManagerSDL::Update() {
+ if ( mInit ) {
+ SDL_JoystickUpdate();
+
+ for ( eeUint i = 0; i < mCount; i++ )
+ if ( NULL != mJoysticks[i] )
+ mJoysticks[i]->Update();
+ }
+}
+
+void cJoystickManagerSDL::Open() {
+ eeInt error = SDL_InitSubSystem( SDL_INIT_JOYSTICK );
+
+ if ( !error ) {
+ mCount = SDL_NumJoysticks();
+
+ for ( eeUint i = 0; i < mCount; i++ )
+ Create(i);
+
+ mInit = true;
+ }
+}
+
+void cJoystickManagerSDL::Close() {
+ if ( SDL_WasInit( SDL_INIT_JOYSTICK ) ) {
+ SDL_QuitSubSystem( SDL_INIT_JOYSTICK );
+
+ mInit = false;
+ }
+}
+
+void cJoystickManagerSDL::Create( const Uint32& index ) {
+ if ( NULL != mJoysticks[ index ] )
+ mJoysticks[ index ]->ReOpen();
+ else
+ mJoysticks[ index ] = eeNew( cJoystickSDL, ( index ) );
+}
+
+}}}}
diff --git a/src/window/backend/SDL/cjoystickmanagersdl.hpp b/src/window/backend/SDL/cjoystickmanagersdl.hpp
new file mode 100644
index 000000000..ce3adae7d
--- /dev/null
+++ b/src/window/backend/SDL/cjoystickmanagersdl.hpp
@@ -0,0 +1,26 @@
+#ifndef EE_WINDOWCJOYSTICKMANAGERSDL_HPP
+#define EE_WINDOWCJOYSTICKMANAGERSDL_HPP
+
+#include "../../cjoystickmanager.hpp"
+#include
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+class EE_API cJoystickManagerSDL : public cJoystickManager {
+ public:
+ cJoystickManagerSDL();
+
+ ~cJoystickManagerSDL();
+
+ void Update();
+ protected:
+ void Close();
+
+ void Open();
+
+ void Create( const Uint32& index );
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/SDL/cjoysticksdl.cpp b/src/window/backend/SDL/cjoysticksdl.cpp
new file mode 100644
index 000000000..0925299d1
--- /dev/null
+++ b/src/window/backend/SDL/cjoysticksdl.cpp
@@ -0,0 +1,80 @@
+#include "cjoysticksdl.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+cJoystickSDL::cJoystickSDL( const Uint32& index ) :
+ cJoystick( index ),
+ mJoystick( NULL )
+{
+}
+
+cJoystickSDL::~cJoystickSDL() {
+}
+
+void cJoystickSDL::Open() {
+ mJoystick = SDL_JoystickOpen( mIndex );
+
+ if ( NULL != mJoystick ) {
+ mName = SDL_JoystickName( mIndex );
+ mHats = SDL_JoystickNumHats( mJoystick );
+ mButtons = SDL_JoystickNumButtons( mJoystick );
+ mAxes = SDL_JoystickNumAxes( mJoystick );
+ mBalls = SDL_JoystickNumBalls( mJoystick );
+
+ mButtonDown = mButtonDownLast = mButtonUp = 0;
+
+ if ( mButtons > 32 )
+ mButtons = 32;
+ }
+}
+
+void cJoystickSDL::Close() {
+ if( SDL_JoystickOpened( mIndex ) )
+ SDL_JoystickClose( mJoystick );
+
+ mJoystick = NULL;
+ mName = "";
+ mHats = mButtons = mAxes = mBalls = 0;
+}
+
+void cJoystickSDL::Update() {
+ if ( NULL != mJoystick ) {
+ ClearStates();
+
+ for ( Int32 i = 0; i < mButtons; i++ ) {
+ UpdateButton( i, 0 != SDL_JoystickGetButton( mJoystick, i ) );
+ }
+
+ }
+}
+
+Uint8 cJoystickSDL::GetHat( const Int32& index ) {
+ if ( index >= 0 && index < mHats )
+ return SDL_JoystickGetHat( mJoystick, index );
+
+ return HAT_CENTERED;
+}
+
+Int16 cJoystickSDL::GetAxis( const Int32& axis ) {
+ if ( axis >= 0 && axis < mAxes )
+ return SDL_JoystickGetAxis( mJoystick, axis );
+
+ return 0;
+}
+
+eeVector2i cJoystickSDL::GetBallMotion( const Int32& ball ) {
+ eeVector2i v;
+
+ if ( ball >= 0 && ball < mBalls )
+ SDL_JoystickGetBall( mJoystick, ball, &v.x, &v.y );
+
+ return v;
+}
+
+
+bool cJoystickSDL::Plugged() const {
+ return NULL != mJoystick;
+}
+
+
+}}}}
diff --git a/src/window/backend/SDL/cjoysticksdl.hpp b/src/window/backend/SDL/cjoysticksdl.hpp
new file mode 100644
index 000000000..c0095f25b
--- /dev/null
+++ b/src/window/backend/SDL/cjoysticksdl.hpp
@@ -0,0 +1,34 @@
+#ifndef EE_WINDOWCJOYSTICKSDL_HPP
+#define EE_WINDOWCJOYSTICKSDL_HPP
+
+#include "../../cjoystick.hpp"
+#include
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+class EE_API cJoystickSDL : public cJoystick {
+ public:
+ cJoystickSDL( const Uint32& index );
+
+ ~cJoystickSDL();
+
+ void Close();
+
+ void Open();
+
+ void Update();
+
+ Uint8 GetHat( const Int32& index );
+
+ Int16 GetAxis( const Int32& axis );
+
+ eeVector2i GetBallMotion( const Int32& ball );
+
+ bool Plugged() const;
+ protected:
+ SDL_Joystick * mJoystick;
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/SDL/cwindowsdl.cpp b/src/window/backend/SDL/cwindowsdl.cpp
new file mode 100644
index 000000000..79ebb0d11
--- /dev/null
+++ b/src/window/backend/SDL/cwindowsdl.cpp
@@ -0,0 +1,496 @@
+#include "cwindowsdl.hpp"
+#include "cclipboardsdl.hpp"
+#include "cinputsdl.hpp"
+#include "../../../graphics/cglobalbatchrenderer.hpp"
+#include "../../../graphics/cshaderprogrammanager.hpp"
+#include "../../../graphics/cvertexbuffermanager.hpp"
+#include "../../../graphics/cframebuffermanager.hpp"
+#include "../../../graphics/ctexturefactory.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+cWindowSDL::cWindowSDL( WindowSettings Settings, ContextSettings Context ) :
+ cWindow( Settings, Context, eeNew( cClipboardSDL, ( this ) ), eeNew( cInputSDL, ( this ) ) )
+{
+ Create( Settings, Context );
+}
+
+cWindowSDL::~cWindowSDL() {
+}
+
+bool cWindowSDL::Create( WindowSettings Settings, ContextSettings Context ) {
+ try {
+ if ( mWindow.Created )
+ return false;
+
+ mWindow.WindowConfig = Settings;
+ mWindow.ContextConfig = Context;
+
+ if ( SDL_Init( SDL_INIT_VIDEO ) != 0 ) {
+ cLog::instance()->Write( "Unable to initialize SDL: " + std::string( SDL_GetError() ) );
+ return false;
+ }
+
+ if ( "" != mWindow.WindowConfig.Icon ) {
+ mWindow.Created = true;
+ Icon( mWindow.WindowConfig.Icon );
+ mWindow.Created = false;
+ }
+
+ const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo();
+
+ mWindow.DesktopResolution = eeSize( videoInfo->current_w, videoInfo->current_h );
+
+ if ( mWindow.WindowConfig.Style & WindowStyle::UseDesktopResolution ) {
+ mWindow.WindowConfig.Width = mWindow.DesktopResolution.Width();
+ mWindow.WindowConfig.Height = mWindow.DesktopResolution.Height();
+ }
+
+ mWindow.Flags = SDL_OPENGL | SDL_HWPALETTE;
+
+ if ( mWindow.WindowConfig.Style & WindowStyle::Resize ) {
+ mWindow.Flags |= SDL_RESIZABLE;
+ }
+
+ if ( mWindow.WindowConfig.Style & WindowStyle::NoBorder ) {
+ mWindow.Flags |= SDL_NOFRAME;
+ }
+
+ SetGLConfig();
+
+ Uint32 mTmpFlags = mWindow.Flags;
+
+ if ( mWindow.WindowConfig.Style & WindowStyle::Fullscreen ) {
+ mTmpFlags |= SDL_FULLSCREEN;
+ }
+
+ if ( SDL_VideoModeOK( mWindow.WindowConfig.Width, mWindow.WindowConfig.Height, mWindow.WindowConfig.BitsPerPixel, mTmpFlags ) ) {
+ mSurface = SDL_SetVideoMode( mWindow.WindowConfig.Width, mWindow.WindowConfig.Height, mWindow.WindowConfig.BitsPerPixel, mTmpFlags );
+ } else {
+ cLog::instance()->Write( "Video Mode Unsopported for this videocard: " );
+ return false;
+ }
+
+ mWindow.WindowSize = eeSize( mWindow.WindowConfig.Width, mWindow.WindowConfig.Height );
+
+ if ( NULL == mSurface ) {
+ cLog::instance()->Write( "Unable to set video mode: " + std::string( SDL_GetError() ) );
+ return false;
+ }
+
+ SDL_VERSION( &mWMinfo.version );
+ SDL_GetWMInfo ( &mWMinfo );
+
+ if ( mWindow.WindowConfig.BitsPerPixel == 16 ) {
+ SDL_GL_SetAttribute( SDL_GL_RED_SIZE , 4 );
+ SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE , 4 );
+ SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE , 4 );
+ SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE , 4 );
+ } else {
+ SDL_GL_SetAttribute( SDL_GL_RED_SIZE , 8);
+ SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE , 8 );
+ SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE , 8 );
+ SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE , 8 );
+ }
+
+ Caption( mWindow.WindowConfig.Caption );
+
+ if ( NULL == cGL::ExistsSingleton() ) {
+ cGL::CreateSingleton( mWindow.ContextConfig.Version );
+ cGL::instance()->Init();
+ }
+
+ GetMainContext();
+
+ CreateView();
+ Setup2D();
+
+ mWindow.Created = true;
+
+ /// Init the clipboard after the window creation
+ reinterpret_cast ( mClipboard )->Init();
+
+ /// Init the input after the window creation
+ reinterpret_cast ( mInput )->Init();
+
+ LogSuccessfulInit( "SDL" );
+
+ return true;
+ } catch (...) {
+ LogFailureInit( "cWindowSDL", "SDL" );
+ return false;
+ }
+}
+
+void cWindowSDL::SetGLConfig() {
+ SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE , mWindow.ContextConfig.DepthBufferSize ); // Depth
+ SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, ( mWindow.ContextConfig.DoubleBuffering ? 1 : 0 ) ); // Double Buffering
+ SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, mWindow.ContextConfig.StencilBufferSize );
+ SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, ( mWindow.ContextConfig.VSync ? 1 : 0 ) ); // VSync
+}
+
+void cWindowSDL::ToggleFullscreen() {
+ #if EE_PLATFORM == EE_PLATFORM_WIN
+ bool WasMaximized = mWindow.Maximized;
+
+ if ( Windowed() ) {
+ Size( mWindow.WindowConfig.Width, mWindow.WindowConfig.Height, !Windowed() );
+ } else {
+ Size( mWindow.WindowSize.Width(), mWindow.WindowSize.Height(), !Windowed() );
+ }
+
+ if ( WasMaximized ) {
+ Maximize();
+ }
+ #else
+ SetFlagValue( &mWindow.WindowConfig.Style, WindowStyle::Fullscreen, !( mWindow.WindowConfig.Style & WindowStyle::Fullscreen ) );
+
+ SDL_WM_ToggleFullScreen( mSurface );
+ #endif
+
+ ShowCursor( mWindow.CursorVisible );
+}
+
+void cWindowSDL::Caption( const std::string& Caption ) {
+ mWindow.WindowConfig.Caption = Caption;
+
+ SDL_WM_SetCaption( Caption.c_str(), NULL );
+}
+
+std::string cWindowSDL::Caption() {
+ return mWindow.WindowConfig.Caption;
+}
+
+bool cWindowSDL::Icon( const std::string& Path ) {
+ int x, y, c;
+
+ if ( !FileExists( Path ) ) {
+ return false;
+ }
+
+ if ( !mWindow.Created ) {
+ if ( stbi_info( Path.c_str(), &x, &y, &c ) ) {
+ mWindow.WindowConfig.Icon = Path;
+
+ return true;
+ }
+
+ return false;
+ }
+
+ unsigned char * Ptr = SOIL_load_image( Path.c_str(), &x, &y, &c, SOIL_LOAD_AUTO );
+
+ if ( NULL != Ptr ) {
+ Int32 W = x;
+ Int32 H = y;
+
+ if ( ( W % 8 ) == 0 && ( H % 8 ) == 0 ) {
+ Uint32 rmask, gmask, bmask, amask;
+ #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ rmask = 0xff000000;
+ gmask = 0x00ff0000;
+ bmask = 0x0000ff00;
+ amask = 0x000000ff;
+ #else
+ rmask = 0x000000ff;
+ gmask = 0x0000ff00;
+ bmask = 0x00ff0000;
+ amask = 0xff000000;
+ #endif
+ SDL_Surface * TempGlyphSheet = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, c * 8, rmask, gmask, bmask, amask);
+
+ SDL_LockSurface( TempGlyphSheet );
+
+ Uint32 ssize = TempGlyphSheet->w * TempGlyphSheet->h * c;
+
+ for ( Uint32 i=0; i < ssize; i++ ) {
+ ( static_cast( TempGlyphSheet->pixels ) )[i+0] = (Ptr)[i];
+ }
+
+ SDL_UnlockSurface( TempGlyphSheet );
+
+ SDL_WM_SetIcon( TempGlyphSheet, NULL );
+
+ SDL_FreeSurface( TempGlyphSheet );
+
+ free( Ptr );
+
+ return true;
+ }
+
+ free( Ptr );
+ }
+
+ return false;
+}
+
+void cWindowSDL::Minimize() {
+ SDL_WM_IconifyWindow();
+}
+
+void cWindowSDL::Maximize() {
+ #if EE_PLATFORM == EE_PLATFORM_WIN
+ WIN_ShowWindow(mWMinfo.window, SW_MAXIMIZE);
+ #elif EE_PLATFORM == EE_PLATFORM_LINUX
+ // coded by Rafał Maj, idea from Måns Rullgård http://tinyurl.com/68mvk3
+ mWMinfo.info.x11.lock_func();
+
+ XEvent xev;
+ Atom wm_state = XInternAtom( mWMinfo.info.x11.display, "_NET_WM_STATE", False);
+ Atom maximizeV = XInternAtom( mWMinfo.info.x11.display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
+ Atom maximizeH = XInternAtom( mWMinfo.info.x11.display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
+
+ memset( &xev, 0, sizeof(xev) );
+ xev.type = ClientMessage;
+ xev.xclient.window = mWMinfo.info.x11.wmwindow;
+ xev.xclient.message_type = wm_state;
+ xev.xclient.format = 32;
+ xev.xclient.data.l[0] = 1;
+ xev.xclient.data.l[1] = maximizeV;
+ xev.xclient.data.l[2] = maximizeH;
+ xev.xclient.data.l[3] = 0;
+ XSendEvent( mWMinfo.info.x11.display, DefaultRootWindow(mWMinfo.info.x11.display), 0, SubstructureNotifyMask|SubstructureRedirectMask, &xev);
+
+ XFlush(mWMinfo.info.x11.display);
+
+ mWMinfo.info.x11.unlock_func();
+ #else
+ #warning cWindowSDL::MaximizeWindow() not implemented on this platform.
+ #endif
+}
+
+void cWindowSDL::Hide() {
+#if EE_PLATFORM == EE_PLATFORM_LINUX
+ mWMinfo.info.x11.lock_func();
+ XUnmapWindow( mWMinfo.info.x11.display, mWMinfo.info.x11.wmwindow );
+ mWMinfo.info.x11.unlock_func();
+#elif EE_PLATFORM == EE_PLATFORM_WIN
+ WIN_ShowWindow( mWMinfo.window, SW_HIDE );
+#else
+ #warning cWindowSDL::HideWindow() not implemented on this platform.
+#endif
+}
+
+void cWindowSDL::Raise() {
+#if EE_PLATFORM == EE_PLATFORM_LINUX
+ mWMinfo.info.x11.lock_func();
+ XRaiseWindow( mWMinfo.info.x11.display, mWMinfo.info.x11.wmwindow );
+ mWMinfo.info.x11.unlock_func();
+#elif EE_PLATFORM == EE_PLATFORM_WIN
+ HWND top;
+
+ if ( !Windowed() )
+ top = HWND_TOPMOST;
+ else
+ top = HWND_NOTOPMOST;
+
+ SetWindowPos( mWMinfo.window, top, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE) );
+#else
+ #warning cWindowSDL::RaiseWindow() not implemented on this platform.
+#endif
+}
+
+void cWindowSDL::Show() {
+#if EE_PLATFORM == EE_PLATFORM_LINUX
+ mWMinfo.info.x11.lock_func();
+ XMapRaised( mWMinfo.info.x11.display, mWMinfo.info.x11.wmwindow );
+ mWMinfo.info.x11.unlock_func();
+#elif EE_PLATFORM == EE_PLATFORM_WIN
+ WIN_ShowWindow( mWMinfo.window, SW_SHOW );
+#else
+ #warning cWindowSDL::RaiseWindow() not implemented on this platform.
+#endif
+}
+
+void cWindowSDL::Position( Int16 Left, Int16 Top ) {
+#if EE_PLATFORM == EE_PLATFORM_LINUX
+ XMoveWindow( mWMinfo.info.x11.display, mWMinfo.info.x11.wmwindow, Left, Top);
+ XFlush( mWMinfo.info.x11.display );
+#elif EE_PLATFORM == EE_PLATFORM_WIN
+ SetWindowPos( mWMinfo.window, NULL, Left, Top, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
+#else
+ #warning cWindowSDL::SetWindowPosition() not implemented on this platform.
+#endif
+}
+
+bool cWindowSDL::Active() {
+ return 0 != ( SDL_GetAppState() & SDL_APPINPUTFOCUS );
+}
+
+bool cWindowSDL::Visible() {
+ return 0 != ( SDL_GetAppState() & SDL_APPACTIVE );
+}
+
+eeVector2i cWindowSDL::Position() {
+#if EE_PLATFORM == EE_PLATFORM_LINUX
+ XWindowAttributes Attrs;
+ XGetWindowAttributes( mWMinfo.info.x11.display, mWMinfo.info.x11.wmwindow, &Attrs );
+
+ return eeVector2i( Attrs.x, Attrs.y );
+#elif EE_PLATFORM == EE_PLATFORM_WIN
+ RECT r;
+ GetWindowRect( mWMinfo.window, &r );
+ return eeVector2i( r.left, r.top );
+#else
+ #warning cWindowSDL::GetWindowPos() not implemented on this platform.
+ return eeVector2i( 0, 0 );
+#endif
+}
+
+void cWindowSDL::Size( const Uint32& Width, const Uint32& Height ) {
+ if ( Windowed() ) {
+ Size( Width, Height, true );
+ }
+}
+
+void cWindowSDL::Size( const Uint16& Width, const Uint16& Height, const bool& Windowed ) {
+ try {
+ cLog::instance()->Writef( "Switching from %s to %s. Width: %d Height %d.", this->Windowed() ? "windowed" : "fullscreen", Windowed ? "windowed" : "fullscreen", Width, Height );
+
+ #if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX
+ #if EE_PLATFORM == EE_PLATFORM_WIN
+ bool Reload = this->Windowed() != Windowed;
+ #else
+ bool Reload = true;
+ #endif
+
+ if ( Reload )
+ Graphics::cTextureFactory::instance()->GrabTextures();
+ #endif
+
+ SetFlagValue( &mWindow.WindowConfig.Style, WindowStyle::Fullscreen, !Windowed );
+
+ mWindow.WindowConfig.Width = Width;
+ mWindow.WindowConfig.Height = Height;
+
+ if ( Windowed ) {
+ mWindow.WindowSize = eeSize( Width, Height );
+ }
+
+ mDefaultView.SetView( 0, 0, Width, Height );
+
+ SetGLConfig();
+
+ if ( Windowed ) {
+ mSurface = SDL_SetVideoMode( Width, Height, mWindow.WindowConfig.BitsPerPixel, mWindow.Flags );
+ } else {
+ mSurface = SDL_SetVideoMode( Width, Height, mWindow.WindowConfig.BitsPerPixel, mWindow.Flags | SDL_FULLSCREEN );
+ }
+
+ Setup2D();
+
+ #if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX
+ if ( Reload ) {
+ Graphics::cTextureFactory::instance()->UngrabTextures(); // Reload all textures
+ Graphics::cShaderProgramManager::instance()->Reload(); // Reload all shaders
+ Graphics::Private::cFrameBufferManager::instance()->Reload(); // Reload all frame buffers
+ Graphics::Private::cVertexBufferManager::instance()->Reload(); // Reload all vertex buffers
+ GetMainContext(); // Recover the context
+ }
+ #endif
+
+ SendVideoResizeCb();
+
+ if ( NULL == mSurface ) {
+ mWindow.Created = false;
+ }
+ } catch (...) {
+ cLog::instance()->Write( "Unable to change resolution: " + std::string( SDL_GetError() ) );
+ cLog::instance()->Save();
+ mWindow.Created = false;
+ }
+}
+
+void cWindowSDL::ShowCursor( const bool& showcursor ) {
+ mWindow.CursorVisible = showcursor;
+
+ SDL_ShowCursor( mWindow.CursorVisible ? SDL_ENABLE : SDL_DISABLE );
+}
+
+void cWindowSDL::SwapBuffers() {
+ SDL_GL_SwapBuffers();
+}
+
+std::vector< std::pair > cWindowSDL::GetPossibleResolutions() const {
+ SDL_Rect **modes = SDL_ListModes( NULL, SDL_OPENGL | SDL_HWPALETTE | SDL_HWACCEL | SDL_FULLSCREEN );
+
+ if(modes == (SDL_Rect **)0)
+ cLog::instance()->Write("No VideoMode Found");
+
+ std::vector< std::pair > result;
+ if( modes != (SDL_Rect **)-1 )
+ for(unsigned int i = 0; modes[i]; ++i)
+ result.push_back( std::pair(modes[i]->w, modes[i]->h) );
+
+ return result;
+}
+
+void cWindowSDL::SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ) {
+ eeclamp( &Red , 0.1f, 10.0f );
+ eeclamp( &Green , 0.1f, 10.0f );
+ eeclamp( &Blue , 0.1f, 10.0f );
+ SDL_SetGamma( Red, Green, Blue );
+}
+
+
+void cWindowSDL::SetCurrentContext( eeWindowContex Context ) {
+ if ( mWindow.Created ) {
+ #ifdef EE_GLEW_AVAILABLE
+
+ #if EE_PLATFORM == EE_PLATFORM_WIN
+ wglMakeCurrent( GetDC( mWMinfo.window ), Context );
+ #elif EE_PLATFORM == EE_PLATFORM_LINUX
+ mWMinfo.info.x11.lock_func();
+ glXMakeCurrent( mWMinfo.info.x11.display, mWMinfo.info.x11.window, Context );
+ mWMinfo.info.x11.unlock_func();
+ #elif EE_PLATFORM == EE_PLATFORM_MACOSX
+ aglSetCurrentContext( Context );
+ #else
+ #warning No context supported on this platform
+ #endif
+
+ #endif
+ }
+}
+
+eeWindowContex cWindowSDL::GetContext() const {
+#if defined( EE_GLEW_AVAILABLE ) && ( EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_MACOSX )
+ return mWindow.Context;
+#else
+ return 0;
+#endif
+}
+
+void cWindowSDL::GetMainContext() {
+#ifdef EE_GLEW_AVAILABLE
+
+#if EE_PLATFORM == EE_PLATFORM_WIN
+ mWindow.Context = wglGetCurrentContext();
+#elif EE_PLATFORM == EE_PLATFORM_LINUX
+ mWindow.Context = glXGetCurrentContext();
+#elif EE_PLATFORM == EE_PLATFORM_MACOSX
+ mWindow.Context = aglGetCurrentContext();
+#endif
+
+#endif
+}
+
+eeWindowHandler cWindowSDL::GetWindowHandler() {
+#if EE_PLATFORM == EE_PLATFORM_WIN
+ return mWMinfo.window;
+#elif EE_PLATFORM == EE_PLATFORM_LINUX
+ return mWMinfo.info.x11.display;
+#elif EE_PLATFORM == EE_PLATFORM_MACOSX
+ return mWMinfo.cocoa.window;
+#else
+ return 0;
+#endif
+}
+
+void cWindowSDL::SetDefaultContext() {
+#if defined( EE_GLEW_AVAILABLE ) && ( EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_LINUX )
+ SetCurrentContext( mWindow.Context );
+#endif
+}
+
+}}}}
diff --git a/src/window/backend/SDL/cwindowsdl.hpp b/src/window/backend/SDL/cwindowsdl.hpp
new file mode 100644
index 000000000..b05941449
--- /dev/null
+++ b/src/window/backend/SDL/cwindowsdl.hpp
@@ -0,0 +1,76 @@
+#ifndef EE_WINDOWCWINDOWSDL_HPP
+#define EE_WINDOWCWINDOWSDL_HPP
+
+#include "../../cwindow.hpp"
+#include
+#include
+
+namespace EE { namespace Window { namespace Backend { namespace SDL {
+
+class EE_API cWindowSDL : public cWindow {
+ public:
+ cWindowSDL( WindowSettings Settings, ContextSettings Context );
+
+ virtual ~cWindowSDL();
+
+ bool Create( WindowSettings Settings, ContextSettings Context );
+
+ void ToggleFullscreen();
+
+ void Caption( const std::string& Caption );
+
+ std::string Caption();
+
+ bool Icon( const std::string& Path );
+
+ void Minimize();
+
+ void Maximize();
+
+ void Hide();
+
+ void Raise();
+
+ void Show();
+
+ void Position( Int16 Left, Int16 Top );
+
+ bool Active();
+
+ bool Visible();
+
+ eeVector2i Position();
+
+ void Size( const Uint32& Width, const Uint32& Height );
+
+ void Size( const Uint16& Width, const Uint16& Height, const bool& Windowed );
+
+ void ShowCursor( const bool& showcursor );
+
+ std::vector< std::pair > GetPossibleResolutions() const;
+
+ void SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue );
+
+ void SetCurrentContext( eeWindowContex Context );
+
+ eeWindowContex GetContext() const;
+
+ eeWindowHandler GetWindowHandler();
+
+ void SetDefaultContext();
+ protected:
+ friend class cClipboardSDL;
+
+ SDL_Surface * mSurface;
+ SDL_SysWMinfo mWMinfo;
+
+ void SwapBuffers();
+
+ void GetMainContext();
+
+ void SetGLConfig();
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/null/cbackendnull.hpp b/src/window/backend/null/cbackendnull.hpp
new file mode 100644
index 000000000..7f230ead8
--- /dev/null
+++ b/src/window/backend/null/cbackendnull.hpp
@@ -0,0 +1,21 @@
+#ifndef EE_WINDOWCBACKENDNULL_HPP
+#define EE_WINDOWCBACKENDNULL_HPP
+
+#include "../../cbackend.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+class EE_API cBackendNull : public cBackend {
+ public:
+ inline cBackendNull() : cBackend()
+ {
+ }
+
+ inline ~cBackendNull()
+ {
+ }
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/null/cclipboardnull.cpp b/src/window/backend/null/cclipboardnull.cpp
new file mode 100644
index 000000000..5ac56613a
--- /dev/null
+++ b/src/window/backend/null/cclipboardnull.cpp
@@ -0,0 +1,31 @@
+#include "cclipboardnull.hpp"
+#include "cwindownull.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+cClipboardNull::cClipboardNull( cWindow * window ) :
+ cClipboard( window )
+{
+}
+
+cClipboardNull::~cClipboardNull() {
+}
+
+void cClipboardNull::Init() {
+}
+
+void cClipboardNull::SetText( const std::string& Text ) {
+}
+
+void cClipboardNull::SetText( const std::wstring& Text ) {
+}
+
+std::string cClipboardNull::GetText() {
+ return std::string();
+}
+
+std::wstring cClipboardNull::GetTextWStr() {
+ return std::wstring();
+}
+
+}}}}
diff --git a/src/window/backend/null/cclipboardnull.hpp b/src/window/backend/null/cclipboardnull.hpp
new file mode 100644
index 000000000..445c2bf05
--- /dev/null
+++ b/src/window/backend/null/cclipboardnull.hpp
@@ -0,0 +1,30 @@
+#ifndef EE_WINDOWCCLIPBOARDNULL_HPP
+#define EE_WINDOWCCLIPBOARDNULL_HPP
+
+#include "../../base.hpp"
+#include "../../cclipboard.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+class EE_API cClipboardNull : public cClipboard {
+ public:
+ virtual ~cClipboardNull();
+
+ std::string GetText();
+
+ std::wstring GetTextWStr();
+
+ void SetText( const std::string& Text );
+
+ void SetText( const std::wstring& Text );
+ protected:
+ friend class cWindowNull;
+
+ cClipboardNull( cWindow * window );
+
+ void Init();
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/null/cinputnull.cpp b/src/window/backend/null/cinputnull.cpp
new file mode 100644
index 000000000..cee014e12
--- /dev/null
+++ b/src/window/backend/null/cinputnull.cpp
@@ -0,0 +1,30 @@
+#include "cinputnull.hpp"
+#include "cjoystickmanagernull.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+cInputNull::cInputNull( cWindow * window ) :
+ cInput( window, eeNew( cJoystickManagerNull, () ) )
+{
+}
+
+cInputNull::~cInputNull() {
+}
+
+void cInputNull::Update() {
+}
+
+bool cInputNull::GrabInput() {
+ return false;
+}
+
+void cInputNull::GrabInput( const bool& Grab ) {
+}
+
+void cInputNull::InjectMousePos( const Uint16& x, const Uint16& y ) {
+}
+
+void cInputNull::Init() {
+}
+
+}}}}
diff --git a/src/window/backend/null/cinputnull.hpp b/src/window/backend/null/cinputnull.hpp
new file mode 100644
index 000000000..3244d619a
--- /dev/null
+++ b/src/window/backend/null/cinputnull.hpp
@@ -0,0 +1,29 @@
+#ifndef EE_WINDOWCINPUTNULL_HPP
+#define EE_WINDOWCINPUTNULL_HPP
+
+#include "../../cinput.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+class EE_API cInputNull : public cInput {
+ public:
+ virtual ~cInputNull();
+
+ void Update();
+
+ bool GrabInput();
+
+ void GrabInput( const bool& Grab );
+
+ void InjectMousePos( const Uint16& x, const Uint16& y );
+ protected:
+ friend class cWindowNull;
+
+ cInputNull( cWindow * window );
+
+ virtual void Init();
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/null/cjoystickmanagernull.cpp b/src/window/backend/null/cjoystickmanagernull.cpp
new file mode 100644
index 000000000..41cd6e91b
--- /dev/null
+++ b/src/window/backend/null/cjoystickmanagernull.cpp
@@ -0,0 +1,26 @@
+#include "cjoystickmanagernull.hpp"
+#include "cjoysticknull.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+cJoystickManagerNull::cJoystickManagerNull() :
+ cJoystickManager()
+{
+}
+
+cJoystickManagerNull::~cJoystickManagerNull() {
+}
+
+void cJoystickManagerNull::Update() {
+}
+
+void cJoystickManagerNull::Open() {
+}
+
+void cJoystickManagerNull::Close() {
+}
+
+void cJoystickManagerNull::Create( const Uint32& index ) {
+}
+
+}}}}
diff --git a/src/window/backend/null/cjoystickmanagernull.hpp b/src/window/backend/null/cjoystickmanagernull.hpp
new file mode 100644
index 000000000..b39ec4731
--- /dev/null
+++ b/src/window/backend/null/cjoystickmanagernull.hpp
@@ -0,0 +1,25 @@
+#ifndef EE_WINDOWCJOYSTICKMANAGERNULL_HPP
+#define EE_WINDOWCJOYSTICKMANAGERNULL_HPP
+
+#include "../../cjoystickmanager.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+class EE_API cJoystickManagerNull : public cJoystickManager {
+ public:
+ cJoystickManagerNull();
+
+ ~cJoystickManagerNull();
+
+ void Update();
+ protected:
+ void Close();
+
+ void Open();
+
+ void Create( const Uint32& index );
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/null/cjoysticknull.cpp b/src/window/backend/null/cjoysticknull.cpp
new file mode 100644
index 000000000..c7d154e17
--- /dev/null
+++ b/src/window/backend/null/cjoysticknull.cpp
@@ -0,0 +1,39 @@
+#include "cjoysticknull.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+cJoystickNull::cJoystickNull( const Uint32& index ) :
+ cJoystick( index )
+{
+}
+
+cJoystickNull::~cJoystickNull() {
+}
+
+void cJoystickNull::Open() {
+}
+
+void cJoystickNull::Close() {
+}
+
+void cJoystickNull::Update() {
+}
+
+Uint8 cJoystickNull::GetHat( const Int32& index ) {
+ return 0;
+}
+
+Int16 cJoystickNull::GetAxis( const Int32& axis ) {
+ return 0;
+}
+
+eeVector2i cJoystickNull::GetBallMotion( const Int32& ball ) {
+ return eeVector2i();
+}
+
+bool cJoystickNull::Plugged() const {
+ return false;
+}
+
+
+}}}}
diff --git a/src/window/backend/null/cjoysticknull.hpp b/src/window/backend/null/cjoysticknull.hpp
new file mode 100644
index 000000000..37bb11917
--- /dev/null
+++ b/src/window/backend/null/cjoysticknull.hpp
@@ -0,0 +1,32 @@
+#ifndef EE_WINDOWCJOYSTICKNULL_HPP
+#define EE_WINDOWCJOYSTICKNULL_HPP
+
+#include "../../cjoystick.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+class EE_API cJoystickNull : public cJoystick {
+ public:
+ cJoystickNull( const Uint32& index );
+
+ ~cJoystickNull();
+
+ void Close();
+
+ void Open();
+
+ void Update();
+
+ Uint8 GetHat( const Int32& index );
+
+ Int16 GetAxis( const Int32& axis );
+
+ eeVector2i GetBallMotion( const Int32& ball );
+
+ bool Plugged() const;
+ protected:
+};
+
+}}}}
+
+#endif
diff --git a/src/window/backend/null/cwindownull.cpp b/src/window/backend/null/cwindownull.cpp
new file mode 100644
index 000000000..59a38bdfd
--- /dev/null
+++ b/src/window/backend/null/cwindownull.cpp
@@ -0,0 +1,100 @@
+#include "cwindownull.hpp"
+#include "cclipboardnull.hpp"
+#include "cinputnull.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+cWindowNull::cWindowNull( WindowSettings Settings, ContextSettings Context ) :
+ cWindow( Settings, Context, eeNew( cClipboardNull, ( this ) ), eeNew( cInputNull, ( this ) ) )
+{
+ Create( Settings, Context );
+}
+
+cWindowNull::~cWindowNull() {
+}
+
+bool cWindowNull::Create( WindowSettings Settings, ContextSettings Context ) {
+ return false;
+}
+
+void cWindowNull::ToggleFullscreen() {
+}
+
+void cWindowNull::Caption( const std::string& Caption ) {
+}
+
+std::string cWindowNull::Caption() {
+ return std::string();
+}
+
+bool cWindowNull::Icon( const std::string& Path ) {
+ return false;
+}
+
+void cWindowNull::Minimize() {
+}
+
+void cWindowNull::Maximize() {
+}
+
+void cWindowNull::Hide() {
+}
+
+void cWindowNull::Raise() {
+}
+
+void cWindowNull::Show() {
+}
+
+void cWindowNull::Position( Int16 Left, Int16 Top ) {
+}
+
+bool cWindowNull::Active() {
+ return false;
+}
+
+bool cWindowNull::Visible() {
+ return false;
+}
+
+eeVector2i cWindowNull::Position() {
+ return eeVector2i();
+}
+
+void cWindowNull::Size( const Uint32& Width, const Uint32& Height ) {
+}
+
+void cWindowNull::Size( const Uint16& Width, const Uint16& Height, const bool& Windowed ) {
+}
+
+void cWindowNull::ShowCursor( const bool& showcursor ) {
+}
+
+void cWindowNull::SwapBuffers() {
+}
+
+std::vector< std::pair > cWindowNull::GetPossibleResolutions() const {
+ return std::vector< std::pair >();
+}
+
+void cWindowNull::SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ) {
+}
+
+void cWindowNull::SetCurrentContext( eeWindowContex Context ) {
+}
+
+eeWindowContex cWindowNull::GetContext() const {
+ return 0;
+}
+
+void cWindowNull::GetMainContext() {
+}
+
+eeWindowHandler cWindowNull::GetWindowHandler() {
+ return 0;
+}
+
+void cWindowNull::SetDefaultContext() {
+}
+
+}}}}
diff --git a/src/window/backend/null/cwindownull.hpp b/src/window/backend/null/cwindownull.hpp
new file mode 100644
index 000000000..2a519c983
--- /dev/null
+++ b/src/window/backend/null/cwindownull.hpp
@@ -0,0 +1,69 @@
+#ifndef EE_WINDOWCWINDOWNULL_HPP
+#define EE_WINDOWCWINDOWNULL_HPP
+
+#include "../../cwindow.hpp"
+
+namespace EE { namespace Window { namespace Backend { namespace Null {
+
+class EE_API cWindowNull : public cWindow {
+ public:
+ cWindowNull( WindowSettings Settings, ContextSettings Context );
+
+ virtual ~cWindowNull();
+
+ bool Create( WindowSettings Settings, ContextSettings Context );
+
+ void ToggleFullscreen();
+
+ void Caption( const std::string& Caption );
+
+ std::string Caption();
+
+ bool Icon( const std::string& Path );
+
+ void Minimize();
+
+ void Maximize();
+
+ void Hide();
+
+ void Raise();
+
+ void Show();
+
+ void Position( Int16 Left, Int16 Top );
+
+ bool Active();
+
+ bool Visible();
+
+ eeVector2i Position();
+
+ void Size( const Uint32& Width, const Uint32& Height );
+
+ void Size( const Uint16& Width, const Uint16& Height, const bool& Windowed );
+
+ void ShowCursor( const bool& showcursor );
+
+ std::vector< std::pair > GetPossibleResolutions() const;
+
+ void SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue );
+
+ void SetCurrentContext( eeWindowContex Context );
+
+ eeWindowContex GetContext() const;
+
+ eeWindowHandler GetWindowHandler();
+
+ void SetDefaultContext();
+ protected:
+ friend class cClipboardNull;
+
+ void SwapBuffers();
+
+ void GetMainContext();
+};
+
+}}}}
+
+#endif
diff --git a/src/window/base.hpp b/src/window/base.hpp
index 04894b407..ad7cecf1e 100644
--- a/src/window/base.hpp
+++ b/src/window/base.hpp
@@ -2,7 +2,6 @@
#define EE_WINDOW_BASE
#include "../base.hpp"
-#include
#include "../utils/colors.hpp"
#include "../utils/rect.hpp"
@@ -32,28 +31,34 @@ using namespace EE::Graphics;
typedef Atom eeScrapType;
typedef Window X11Window;
typedef Display * eeWindowHandler;
+ #undef Window
#elif EE_PLATFORM == EE_PLATFORM_MACOSX
typedef Uint32 eeScrapType;
+ typedef void * eeWindowHandler; // NSWindow *
+#else
+ typedef Uint32 eeWindowHandler; //! Fallback
+ typedef Uint32 eeScrapType;
#endif
#ifdef EE_GLEW_AVAILABLE
#if EE_PLATFORM == EE_PLATFORM_WIN
#include "../helper/glew/wglew.h"
- typedef HGLRC eeWindowContex;
+ typedef HGLRC eeWindowContex;
#elif EE_PLATFORM == EE_PLATFORM_LINUX
#include "../helper/glew/glxew.h"
- typedef GLXContext eeWindowContex;
+ typedef GLXContext eeWindowContex;
#elif EE_PLATFORM == EE_PLATFORM_MACOSX
- //#include
+ #include
- //typedef AGLContext eeWindowContex;
- //typedef NSWindow * eeWindowHandler;
+ typedef AGLContext eeWindowContex;
#endif
#else
typedef Uint32 eeWindowContex; //! Fallback
#endif
+#include "keycodes.hpp"
+
#endif
diff --git a/src/window/cbackend.hpp b/src/window/cbackend.hpp
new file mode 100644
index 000000000..6869a6d41
--- /dev/null
+++ b/src/window/cbackend.hpp
@@ -0,0 +1,17 @@
+#ifndef EE_WINDOWCBACKEND_HPP
+#define EE_WINDOWCBACKEND_HPP
+
+#include "../base.hpp"
+
+namespace EE { namespace Window { namespace Backend {
+
+class EE_API cBackend {
+ public:
+ inline cBackend() {};
+
+ inline virtual ~cBackend() {};
+};
+
+}}}
+
+#endif
diff --git a/src/window/cclipboard.cpp b/src/window/cclipboard.cpp
new file mode 100644
index 000000000..cba1464b8
--- /dev/null
+++ b/src/window/cclipboard.cpp
@@ -0,0 +1,15 @@
+#include "cclipboard.hpp"
+
+namespace EE { namespace Window {
+
+cClipboard::cClipboard( cWindow * window ) :
+ mWindow( window )
+{}
+
+cClipboard::~cClipboard() {}
+
+cWindow * cClipboard::GetWindow() const {
+ return mWindow;
+}
+
+}}
diff --git a/src/window/cclipboard.hpp b/src/window/cclipboard.hpp
new file mode 100644
index 000000000..c4f2387cb
--- /dev/null
+++ b/src/window/cclipboard.hpp
@@ -0,0 +1,38 @@
+#ifndef EE_WINDOWCCLIPBOARD_HPP
+#define EE_WINDOWCCLIPBOARD_HPP
+
+#include "cwindow.hpp"
+
+namespace EE { namespace Window {
+
+class cClipboard {
+ public:
+ virtual ~cClipboard();
+
+ /** @return The Clipboard Text if available */
+ virtual std::string GetText() = 0;
+
+ /** @return The Clipboard Text if available ( as std::wstring ) */
+ virtual std::wstring GetTextWStr() = 0;
+
+ /** Set the current clipboard text */
+ virtual void SetText( const std::string& Text ) = 0;
+
+ /** Set the current clipboard text */
+ virtual void SetText( const std::wstring& Text ) = 0;
+
+ cWindow * GetWindow() const;
+ protected:
+ friend class cWindow;
+
+ cClipboard( cWindow * window );
+
+ /** Initialize the clipboard manager. This is needed because the backends first create the instance of the clipboard and then initialize the window context. */
+ virtual void Init() = 0;
+
+ cWindow * mWindow;
+};
+
+}}
+
+#endif
diff --git a/src/window/cengine.cpp b/src/window/cengine.cpp
index 7a571312c..e11388452 100755
--- a/src/window/cengine.cpp
+++ b/src/window/cengine.cpp
@@ -1,102 +1,37 @@
#include "cengine.hpp"
-#include "cinput.hpp"
-#include "cjoystickmanager.hpp"
#include "../graphics/ctexturefactory.hpp"
#include "../graphics/cfontmanager.hpp"
#include "../graphics/cglobalbatchrenderer.hpp"
#include "../graphics/cshaderprogrammanager.hpp"
#include "../graphics/cshapegroupmanager.hpp"
-#include "../graphics/cvertexbuffermanager.hpp"
#include "../graphics/cframebuffermanager.hpp"
+#include "../graphics/cvertexbuffermanager.hpp"
#include "../ui/cuimanager.hpp"
#include "../audio/caudiolistener.hpp"
#include "../graphics/glhelper.hpp"
#include "../helper/haikuttf/hkfontmanager.hpp"
-#include "../helper/SOIL/SOIL.h"
-#include "../helper/SOIL/stb_image.h"
+#include "../physics/cphysicsmanager.hpp"
-using namespace EE::Graphics;
-using namespace EE::Graphics::Private;
-
-#define T(A, B, C, D) (int)((A<<24)|(B<<16)|(C<<8)|(D<<0))
-#define FORMAT_PREFIX "EE_scrap_0x"
+#include "backend/SDL/cwindowsdl.hpp"
+#include "backend/SDL/cbackendsdl.hpp"
namespace EE { namespace Window {
-#if EE_PLATFORM == EE_PLATFORM_LINUX
-static int clipboard_filter( const SDL_Event *event ) {
- /* Post all non-window manager specific events */
- if ( event->type != SDL_SYSWMEVENT ) {
- return(1);
- }
-
- Display * curDisplay = cEngine::instance()->GetWindowHandler();
-
- /* Handle window-manager specific clipboard events */
- switch ( event->syswm.msg->event.xevent.type ) {
- /* Copy the selection from XA_CUT_BUFFER0 to the requested property */
- case SelectionRequest: {
- XSelectionRequestEvent *req;
- XEvent sevent;
- int seln_format;
- unsigned long nbytes;
- unsigned long overflow;
- unsigned char *seln_data;
-
- req = &event->syswm.msg->event.xevent.xselectionrequest;
- sevent.xselection.type = SelectionNotify;
- sevent.xselection.display = req->display;
- sevent.xselection.selection = req->selection;
- sevent.xselection.target = None;
- sevent.xselection.property = None;
- sevent.xselection.requestor = req->requestor;
- sevent.xselection.time = req->time;
-
- if ( XGetWindowProperty(curDisplay, DefaultRootWindow(curDisplay), XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target, &sevent.xselection.target, &seln_format, &nbytes, &overflow, &seln_data) == Success ) {
- if ( sevent.xselection.target == req->target ) {
- if ( sevent.xselection.target == XA_STRING ) {
- if ( seln_data[nbytes-1] == '\0' )
- --nbytes;
- }
- XChangeProperty(curDisplay, req->requestor, req->property, sevent.xselection.target, seln_format, PropModeReplace, seln_data, nbytes);
- sevent.xselection.property = req->property;
- }
- XFree(seln_data);
- }
- XSendEvent(curDisplay,req->requestor, False, 0, &sevent);
- XSync(curDisplay, False);
- }
- break;
- }
-
- /* Post the event for X11 clipboard reading above */
- return(1);
-}
-#endif
-
cEngine::cEngine() :
- mInit(false),
- mBackColor(0, 0, 0),
- mCursor(NULL),
- mShowCursor(true)
+ mBackend( NULL ),
+ mWindow( NULL )
{
- mFrames.FPS.LastCheck = 0;
- mFrames.FPS.Current = 0;
- mFrames.FPS.Count = 0;
- mFrames.FPS.Limit = 0;
- mFrames.FPS.Error = 0;
- mFrames.ElapsedTime = 0;
-
- cShapeGroupManager::CreateSingleton();
+ mBackend = eeNew( Backend::SDL::cBackendSDL, () );
}
cEngine::~cEngine() {
- if ( NULL != mCursor )
- SDL_FreeCursor(mCursor);
+ Destroy();
- cFrameBufferManager::DestroySingleton();
+ Physics::cPhysicsManager::DestroySingleton();
- cVertexBufferManager::DestroySingleton();
+ Graphics::Private::cFrameBufferManager::DestroySingleton();
+
+ Graphics::Private::cVertexBufferManager::DestroySingleton();
cGlobalBatchRenderer::DestroySingleton();
@@ -108,10 +43,6 @@ cEngine::~cEngine() {
UI::cUIManager::DestroySingleton();
- cJoystickManager::DestroySingleton();
-
- cInput::DestroySingleton();
-
Audio::cAudioListener::DestroySingleton();
Graphics::cGL::DestroySingleton();
@@ -122,977 +53,96 @@ cEngine::~cEngine() {
HaikuTTF::hkFontManager::DestroySingleton();
- SDL_Quit();
+ eeSAFE_DELETE( mBackend );
}
-bool cEngine::Init(const Uint32& Width, const Uint32& Height, const Uint8& BitColor, const bool& Windowed, const bool& Resizeable, const bool& VSync, const bool& DoubleBuffering, const bool& UseDesktopResolution, const bool& NoFrame, EEGL_version ver ) {
- try {
- mInit = false;
+void cEngine::Destroy() {
+ std::list::iterator it;
- mVideoInfo.Width = Width;
- mVideoInfo.Height = Height;
- mVideoInfo.ColorDepth = BitColor;
- mVideoInfo.Windowed = Windowed;
- mVideoInfo.Resizeable = Resizeable;
- mVideoInfo.DoubleBuffering = DoubleBuffering;
- mVideoInfo.VSync = VSync;
- mVideoInfo.NoFrame = NoFrame;
- mVideoInfo.LineSmooth = true;
-
- if ( SDL_Init( SDL_INIT_VIDEO ) != 0 ) {
- cLog::instance()->Write( "Unable to initialize SDL: " + std::string( SDL_GetError() ) );
- return false;
- }
+ for ( it = mWindows.begin(); it != mWindows.end(); it++ ) {
+ eeSAFE_DELETE( *it );
+ }
- if ( "" != mIcon ) {
- mInit = true;
- SetIcon( mIcon );
- mInit = false;
- }
+ mWindow = NULL;
+}
- mVideoInfo.Flags = SDL_OPENGL | SDL_HWPALETTE;
+cWindow * cEngine::CreateWindow( WindowSettings Settings, ContextSettings Context ) {
+ cWindow * window = eeNew( Backend::SDL::cWindowSDL, ( Settings, Context ) );
+
+ if ( NULL == mWindow ) {
+ mWindow = window;
+ }
- const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
+ mWindows.push_back( mWindow );
+
+ return window;
+}
- mVideoInfo.DeskWidth = videoInfo->current_w;
- mVideoInfo.DeskHeight = videoInfo->current_h;
-
- if ( UseDesktopResolution ) {
- mVideoInfo.Width = mVideoInfo.DeskWidth;
- mVideoInfo.Height = mVideoInfo.DeskHeight;
- }
-
- if ( mVideoInfo.Resizeable )
- mVideoInfo.Flags |= SDL_RESIZABLE;
-
- if ( mVideoInfo.NoFrame )
- mVideoInfo.Flags |= SDL_NOFRAME;
-
- SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 ); // Depth
- SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, ( mVideoInfo.DoubleBuffering ? 1 : 0 ) ); // Double Buffering
- SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 1 );
- SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, ( mVideoInfo.VSync ? 1 : 0 ) ); // VSync
-
- Uint32 mTmpFlags = mVideoInfo.Flags;
-
- if ( !mVideoInfo.Windowed )
- mTmpFlags |= SDL_FULLSCREEN;
-
- if ( SDL_VideoModeOK(mVideoInfo.Width, mVideoInfo.Height, mVideoInfo.ColorDepth, mTmpFlags ) ) {
- mVideoInfo.Screen = SDL_SetVideoMode(mVideoInfo.Width, mVideoInfo.Height, mVideoInfo.ColorDepth, mTmpFlags );
+void cEngine::DestroyWindow( cWindow * window ) {
+ mWindows.remove( window );
+
+ if ( window == mWindow ) {
+ if ( mWindows.size() > 0 ) {
+ mWindow = mWindows.back();
} else {
- cLog::instance()->Write( "Video Mode Unsopported for this videocard: " );
- return false;
- }
-
- mVideoInfo.WWidth = mVideoInfo.Width;
- mVideoInfo.WHeight = mVideoInfo.Height;
-
- mVideoInfo.Maximized = false;
-
- if ( mVideoInfo.Screen == NULL ) {
- cLog::instance()->Write( "Unable to set video mode: " + std::string( SDL_GetError() ) );
- return false;
- }
-
- SDL_VERSION(&mVideoInfo.info.version);
- SDL_GetWMInfo (&mVideoInfo.info);
-
- #if EE_PLATFORM == EE_PLATFORM_LINUX
- /* Enable the special window hook events */
- SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
- SDL_SetEventFilter(clipboard_filter);
- #endif
-
- if ( mVideoInfo.ColorDepth == 16 ) {
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE , 4);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE , 4);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE , 4);
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE , 4);
- } else {
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE , 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE , 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE , 8);
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE , 8);
- }
-
- SetWindowCaption("EEPP");
-
- GetMainContext();
-
- mDefaultView.SetView( 0, 0, mVideoInfo.Width, mVideoInfo.Height );
- mCurrentView = &mDefaultView;
-
- cGL::CreateSingleton( ver );
- cGL::instance()->Init();
-
- Setup2D();
-
- cLog::instance()->Write( "Engine Initialized Succesfully.\nGL Vendor: " + GetVendor() + "\nGL Renderer: " + GetRenderer() + "\nGL Version: " + GetVersion() );
-
- mInit = true;
-
- return true;
- } catch (...) {
- cLog::instance()->Write( "Error on cEngine::Init" );
- return false;
- }
-}
-
-void cEngine::SetViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height ) {
- GLi->MatrixMode( GL_PROJECTION );
- GLi->LoadIdentity();
-
- GLi->Viewport( x, GetHeight() - Height - y, Width, Height );
- GLi->Ortho( 0.0f, Width, Height, 0.0f, -1000.0f, 1000.0f );
-
- GLi->MatrixMode( GL_MODELVIEW );
- GLi->LoadIdentity();
-}
-
-void cEngine::SetView( const cView& View ) {
- mCurrentView = &View;
-
- eeRecti RView = mCurrentView->GetView();
- SetViewport( RView.Left, RView.Top, RView.Right, RView.Bottom );
-}
-
-const cView& cEngine::GetDefaultView() const {
- return mDefaultView;
-}
-
-const cView& cEngine::GetView() const {
- return *mCurrentView;
-}
-
-void cEngine::Setup2D( const bool& KeepView ) {
- SetBackColor( mBackColor );
-
- SetLineSmooth( mVideoInfo.LineSmooth );
-
- GLi->Enable ( GL_TEXTURE_2D ); // Enable Textures
- GLi->Disable( GL_DEPTH_TEST );
- GLi->Disable( GL_LIGHTING );
-
- if ( !KeepView )
- SetView( mDefaultView );
-
- cTextureFactory::instance()->SetPreBlendFunc( ALPHA_BLENDONE ); // This is to fix a little bug on windows when the resolution change. I don't know why it happens, but this line fix it.
- cTextureFactory::instance()->SetPreBlendFunc( ALPHA_NORMAL );
-
- if ( GLv_3 != GLi->Version() ) {
- #ifndef EE_GLES
- GLi->TexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
- GLi->TexEnvi( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE );
- #endif
- }
-
- GLi->EnableClientState( GL_VERTEX_ARRAY );
- GLi->EnableClientState( GL_TEXTURE_COORD_ARRAY );
- GLi->EnableClientState( GL_COLOR_ARRAY );
-}
-
-void cEngine::CalculateFps() {
- if ( eeGetTicks() - mFrames.FPS.LastCheck >= 1000 ) {
- mFrames.FPS.Current = mFrames.FPS.Count;
- mFrames.FPS.Count = 0;
- mFrames.FPS.LastCheck = eeGetTicks();
- }
- mFrames.FPS.Count++;
-}
-
-void cEngine::LimitFps() {
- if ( mFrames.FPS.Limit > 0 ) {
- mFrames.FPS.Error = 0;
- eeFloat RemainT = 1000.f / mFrames.FPS.Limit - ( mFrames.ElapsedTime * 0.1f );
-
- if ( RemainT < 0 ) {
- mFrames.FPS.Error = 0;
- } else {
- mFrames.FPS.Error += 1000 % (Int32)mFrames.FPS.Limit;
-
- if ( mFrames.FPS.Error > (Int32)mFrames.FPS.Limit ) {
- ++RemainT;
- mFrames.FPS.Error -= (Int32)mFrames.FPS.Limit;
- }
-
- if ( RemainT > 0 )
- SDL_Delay( (Int32) RemainT );
+ mWindow = NULL;
}
}
+
+ eeSAFE_DELETE( window );
}
-void cEngine::Display() {
- cGlobalBatchRenderer::instance()->Draw();
-
- if ( mCurrentView->NeedUpdate() )
- SetView( *mCurrentView );
-
- SDL_GL_SwapBuffers();
-
- GLi->Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
-
- GetElapsedTime();
-
- CalculateFps();
-
- LimitFps();
-}
-
-void cEngine::ChangeRes( const Uint16& width, const Uint16& height, const bool& Windowed ) {
- try {
- cLog::instance()->Writef( "Switching from %s to %s. Width: %d Height %d.", mVideoInfo.Windowed == true ? "windowed" : "fullscreen", Windowed == true ? "windowed" : "fullscreen", width, height );
-
- #if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX
- #if EE_PLATFORM == EE_PLATFORM_WIN
- bool Reload = mVideoInfo.Windowed != Windowed;
- #else
- bool Reload = true;
- #endif
-
- if ( Reload )
- cTextureFactory::instance()->GrabTextures();
- #endif
-
- mVideoInfo.Windowed = Windowed;
- mVideoInfo.Width = width;
- mVideoInfo.Height = height;
-
- if ( Windowed ) {
- mVideoInfo.WWidth = width;
- mVideoInfo.WHeight = height;
- }
-
- mDefaultView.SetView( 0, 0, mVideoInfo.Width, mVideoInfo.Height );
-
- SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); // Depth
- SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, ( mVideoInfo.DoubleBuffering ? 1 : 0 ) ); // Double Buffering
- SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, ( mVideoInfo.VSync ? 1 : 0 ) ); // VSync
-
- if (Windowed)
- mVideoInfo.Screen = SDL_SetVideoMode( mVideoInfo.Width, mVideoInfo.Height, mVideoInfo.ColorDepth, mVideoInfo.Flags );
- else
- mVideoInfo.Screen = SDL_SetVideoMode( mVideoInfo.Width, mVideoInfo.Height, mVideoInfo.ColorDepth, mVideoInfo.Flags | SDL_FULLSCREEN );
-
- Setup2D();
-
- #if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX
- if ( Reload ) {
- cTextureFactory::instance()->UngrabTextures(); // Reload all textures
- cShaderProgramManager::instance()->Reload(); // Reload all shaders
- cFrameBufferManager::instance()->Reload(); // Reload all frame buffers
- cVertexBufferManager::instance()->Reload(); // Reload all vertex buffers
- GetMainContext(); // Recover the context
- }
- #endif
-
- if ( UI::cUIManager::ExistsSingleton() != NULL )
- UI::cUIManager::instance()->ResizeControl();
-
- if ( !mVideoInfo.Screen )
- mInit = false;
- } catch (...) {
- cLog::instance()->Write( "Unable to change resolution: " + std::string( SDL_GetError() ) );
- cLog::instance()->Save();
- mInit = false;
- }
-}
-
-Uint32 cEngine::FPS() const {
- return mFrames.FPS.Current;
-}
-
-void cEngine::SetBackColor(const eeColor& Color) {
- mBackColor = Color;
- GLi->ClearColor( static_cast( mBackColor.R() ) / 255.0f, static_cast( mBackColor.G() ) / 255.0f, static_cast( mBackColor.B() ) / 255.0f, 255.0f );
-}
-
-const eeColor& cEngine::GetBackColor() const {
- return mBackColor;
-}
-
-void cEngine::SetWindowCaption(const std::string& Caption) {
- SDL_WM_SetCaption( Caption.c_str(), NULL );
-}
-
-void cEngine::GetElapsedTime() {
- mFrames.ElapsedTime = static_cast ( mFrames.FrameElapsed.Elapsed() );
-}
-
-eeFloat cEngine::Elapsed() const {
- return mFrames.ElapsedTime;
-}
-
-bool cEngine::Windowed() const {
- return mVideoInfo.Windowed;
-}
-
-void cEngine::ToggleFullscreen() {
- #if EE_PLATFORM == EE_PLATFORM_WIN
- bool WasMaximized = mVideoInfo.Maximized;
-
- if ( mVideoInfo.Windowed )
- ChangeRes( mVideoInfo.Width, mVideoInfo.Height, !mVideoInfo.Windowed );
- else
- ChangeRes( mVideoInfo.WWidth, mVideoInfo.WHeight, !mVideoInfo.Windowed );
-
- if ( WasMaximized )
- MaximizeWindow();
- #else
- mVideoInfo.Windowed = !mVideoInfo.Windowed;
- SDL_WM_ToggleFullScreen( mVideoInfo.Screen );
- #endif
-
- ShowCursor(mShowCursor);
-}
-
-void cEngine::ShowCursor(const bool& showcursor) {
- mShowCursor = showcursor;
- if ( mShowCursor )
- SDL_ShowCursor(SDL_ENABLE);
- else
- SDL_ShowCursor(SDL_DISABLE);
-}
-
-void cEngine::SetFrameRateLimit(const Uint32& FrameRateLimit) {
- mFrames.FPS.Limit = (eeFloat)FrameRateLimit;
-}
-
-bool cEngine::TakeScreenshot( std::string filepath, const EE_SAVE_TYPE& Format ) {
- bool CreateNewFile = false;
- std::string File, Ext;
-
- if ( filepath.size() ) {
- File = filepath.substr( filepath.find_last_of("/\\") + 1 );
- Ext = File.substr( File.find_last_of(".") + 1 );
-
- if ( IsDirectory( filepath ) || !Ext.size() )
- CreateNewFile = true;
- } else {
- filepath = AppPath();
- CreateNewFile = true;
- }
-
- if ( CreateNewFile ) { // Search if file path is given, and if have and extension
- bool find = false;
- Int32 FileNum = 1;
- std::string TmpPath = filepath, Ext;
-
- if ( !IsDirectory( filepath ) )
- MakeDir( filepath );
-
- Ext = "." + SaveTypeToExtension( Format );
-
- while ( !find && FileNum < 10000 ) {
- TmpPath = StrFormated( "%s%05d%s", filepath.c_str(), FileNum, Ext.c_str() );
-
- FileNum++;
-
- if ( !FileExists( TmpPath ) )
- find = true;
-
- if ( FileNum == 10000 && find == false )
- return false;
- }
-
- return 0 != SOIL_save_screenshot(TmpPath.c_str(), Format, 0, 0, mVideoInfo.Width, mVideoInfo.Height );
- } else {
- std::string Direc = filepath.substr( 0, filepath.find_last_of("/\\") );
- if ( !IsDirectory( Direc ) )
- MakeDir( Direc );
-
- return 0 != SOIL_save_screenshot(filepath.c_str(), Format, 0, 0, mVideoInfo.Width, mVideoInfo.Height );
- }
-}
-
-std::vector< std::pair > cEngine::GetPossibleResolutions() const {
- SDL_Rect **modes = SDL_ListModes( NULL, SDL_OPENGL | SDL_HWPALETTE | SDL_HWACCEL | SDL_FULLSCREEN );
-
- if(modes == (SDL_Rect **)0)
- cLog::instance()->Write("No VideoMode Found");
-
- std::vector< std::pair > result;
- if( modes != (SDL_Rect **)-1 )
- for(unsigned int i = 0; modes[i]; ++i)
- result.push_back( std::pair(modes[i]->w, modes[i]->h) );
-
- return result;
-}
-
-bool cEngine::ShadersSupported() const {
- return cGL::instance()->ShadersSupported();
-}
-
-void cEngine::SetGamma( const eeFloat& Red, const eeFloat& Green, const eeFloat& Blue ) {
- if ( Red >= 0.1f && Red <= 10.0f && Green >= 0.1f && Green <= 10.0f && Blue >= 0.1f && Blue <= 10.0f )
- SDL_SetGamma( Red, Green, Blue );
-}
-
-void cEngine::SetLineSmooth( const bool& Enable ) {
- mVideoInfo.LineSmooth = Enable;
- if ( Enable )
- GLi->Enable( GL_LINE_SMOOTH );
- else
- GLi->Disable( GL_LINE_SMOOTH );
-}
-
-void cEngine::SetPolygonMode( const EE_FILL_MODE& Mode ) {
- if ( Mode == EE_DRAW_FILL )
- GLi->PolygonMode( GL_FRONT_AND_BACK, GL_FILL );
- else
- GLi->PolygonMode( GL_FRONT_AND_BACK, GL_LINE );
-}
-
-void cEngine::ClipEnable( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height ) {
- cGlobalBatchRenderer::instance()->Draw();
- GLi->Scissor( x, GetHeight() - Height - y, Width, Height );
- GLi->Enable( GL_SCISSOR_TEST );
-}
-
-void cEngine::ClipDisable() {
- cGlobalBatchRenderer::instance()->Draw();
- GLi->Disable( GL_SCISSOR_TEST );
-}
-
-std::string cEngine::GetVendor() {
- return std::string( reinterpret_cast ( cGL::instance()->GetString( GL_VENDOR ) ) );
-}
-
-std::string cEngine::GetRenderer() {
- return std::string( reinterpret_cast ( cGL::instance()->GetString( GL_RENDERER ) ) );
-}
-
-std::string cEngine::GetVersion() {
- return std::string( reinterpret_cast ( cGL::instance()->GetString( GL_VERSION ) ) );
-}
-
-bool cEngine::GetExtension( const std::string& Ext ) {
- return 0 != cGL::instance()->GetExtension( Ext.c_str() );
-}
-
-SDL_Cursor* cEngine::CreateCursor( const Uint32& TexId, const eeVector2i& HotSpot ) {
- cTexture* Tex = cTextureFactory::instance()->GetTexture( TexId );
-
- if ( Tex == NULL )
- return NULL;
-
- //the width must be a multiple of 8 (SDL requirement)
- #if EE_PLATFORM == EE_PLATFORM_MACOSX
- size_t cursor_width = 16;
- #else
- size_t cursor_width = static_cast(Tex->Width());
- if ( (cursor_width % 8) != 0 ) {
- cursor_width += 8 - ( cursor_width % 8 );
- }
- #endif
-
- std::vector data( ( cursor_width * static_cast( Tex->Height() ) ) / 8, 0);
- std::vector mask( data.size(), 0 );
-
- //see http://sdldoc.csn.ul.ie/sdlcreatecursor.php for documentation on
- //the format that data has to be in to pass to SDL_CreateCursor
- Tex->Lock();
- for( eeUint y = 0; y != Tex->Height(); ++y) {
- for( eeUint x = 0; x != Tex->Width(); ++x) {
- Uint8 trans = 0;
- Uint8 black = 0;
-
- const size_t index = y * cursor_width + x;
-
- if ( (size_t)x < cursor_width ) {
- eeColorA Col = Tex->GetPixel( x, y );
-
- const size_t shift = 7 - ( index % 8 );
-
- trans = ( Col.A() < 128 ? 0 : 1) << shift;
- black = (trans == 0 || ( Col.R() + Col.G() + Col.B() ) /3 > 128 ? 0 : 1) << shift;
-
- data[index/8] |= black;
- mask[index/8] |= trans;
- }
- }
- }
- Tex->Unlock( false, false );
-
- return SDL_CreateCursor( &data[0], &mask[0], (int)cursor_width, static_cast( Tex->Height() ), HotSpot.x, HotSpot.y );
-}
-
-void cEngine::SetCursor( const Uint32& TexId, const eeVector2i& HotSpot ) {
- mCursor = CreateCursor( TexId, HotSpot );
- if ( mCursor )
- SDL_SetCursor( mCursor );
-}
-
-bool cEngine::SetIcon( const std::string& Path ) {
- int x, y, c;
-
- if ( !FileExists( Path ) )
- return false;
-
- if ( !mInit ) {
- if ( stbi_info( Path.c_str(), &x, &y, &c ) ) {
- mIcon = Path;
+bool cEngine::ExistsWindow( cWindow * window ) {
+ std::list::iterator it;
+ for ( it = mWindows.begin(); it != mWindows.end(); it++ ) {
+ if ( (*it) == window )
return true;
- }
-
- return false;
- }
-
- unsigned char * Ptr = SOIL_load_image( Path.c_str(), &x, &y, &c, SOIL_LOAD_AUTO );
-
- if ( NULL != Ptr ) {
- Int32 W = x;
- Int32 H = y;
-
- if ( ( W % 8 ) == 0 && ( H % 8 ) == 0 ) {
- Uint32 rmask, gmask, bmask, amask;
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- rmask = 0xff000000;
- gmask = 0x00ff0000;
- bmask = 0x0000ff00;
- amask = 0x000000ff;
- #else
- rmask = 0x000000ff;
- gmask = 0x0000ff00;
- bmask = 0x00ff0000;
- amask = 0xff000000;
- #endif
- SDL_Surface* TempGlyphSheet = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, c * 8, rmask, gmask, bmask, amask);
-
- SDL_LockSurface( TempGlyphSheet );
-
- Uint32 ssize = TempGlyphSheet->w * TempGlyphSheet->h * c;
-
- for ( Uint32 i=0; i < ssize; i++ ) {
- ( static_cast( TempGlyphSheet->pixels ) )[i+0] = (Ptr)[i];
- }
-
- SDL_UnlockSurface( TempGlyphSheet );
-
- SDL_WM_SetIcon( TempGlyphSheet, NULL );
-
- SDL_FreeSurface( TempGlyphSheet );
-
- free( Ptr );
-
- return true;
- }
-
- free( Ptr );
}
return false;
}
-void cEngine::MinimizeWindow() {
- SDL_WM_IconifyWindow();
+cWindow * cEngine::GetCurrentWindow() const {
+ return mWindow;
}
-void cEngine::MaximizeWindow() {
- #if EE_PLATFORM == EE_PLATFORM_WIN
- WIN_ShowWindow(mVideoInfo.info.window, SW_MAXIMIZE);
- #elif EE_PLATFORM == EE_PLATFORM_LINUX
- // coded by Rafał Maj, idea from Måns Rullgård http://tinyurl.com/68mvk3
- mVideoInfo.info.info.x11.lock_func();
-
- XEvent xev;
- Atom wm_state = XInternAtom( mVideoInfo.info.info.x11.display, "_NET_WM_STATE", False);
- Atom maximizeV = XInternAtom( mVideoInfo.info.info.x11.display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
- Atom maximizeH = XInternAtom( mVideoInfo.info.info.x11.display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
-
- memset( &xev, 0, sizeof(xev) );
- xev.type = ClientMessage;
- xev.xclient.window = mVideoInfo.info.info.x11.wmwindow;
- xev.xclient.message_type = wm_state;
- xev.xclient.format = 32;
- xev.xclient.data.l[0] = 1;
- xev.xclient.data.l[1] = maximizeV;
- xev.xclient.data.l[2] = maximizeH;
- xev.xclient.data.l[3] = 0;
- XSendEvent( mVideoInfo.info.info.x11.display, DefaultRootWindow(mVideoInfo.info.info.x11.display), 0, SubstructureNotifyMask|SubstructureRedirectMask, &xev);
-
- XFlush(mVideoInfo.info.info.x11.display);
-
- mVideoInfo.info.info.x11.unlock_func();
- #else
- #warning cEngine::MaximizeWindow() not implemented on this platform.
- #endif
-}
-
-void cEngine::HideWindow() {
-#if EE_PLATFORM == EE_PLATFORM_LINUX
- mVideoInfo.info.info.x11.lock_func();
- XUnmapWindow( mVideoInfo.info.info.x11.display, mVideoInfo.info.info.x11.wmwindow );
- mVideoInfo.info.info.x11.unlock_func();
-#elif EE_PLATFORM == EE_PLATFORM_WIN
- WIN_ShowWindow( mVideoInfo.info.window, SW_HIDE );
-#else
- #warning cEngine::HideWindow() not implemented on this platform.
-#endif
-}
-
-void cEngine::RaiseWindow() {
-#if EE_PLATFORM == EE_PLATFORM_LINUX
- mVideoInfo.info.info.x11.lock_func();
- XRaiseWindow( mVideoInfo.info.info.x11.display, mVideoInfo.info.info.x11.wmwindow );
- mVideoInfo.info.info.x11.unlock_func();
-#elif EE_PLATFORM == EE_PLATFORM_WIN
- HWND top;
-
- if ( !mVideoInfo.Windowed )
- top = HWND_TOPMOST;
- else
- top = HWND_NOTOPMOST;
-
- SetWindowPos( mVideoInfo.info.window, top, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE) );
-#else
- #warning cEngine::RaiseWindow() not implemented on this platform.
-#endif
-}
-
-void cEngine::ShowWindow() {
-#if EE_PLATFORM == EE_PLATFORM_LINUX
- mVideoInfo.info.info.x11.lock_func();
- XMapRaised( mVideoInfo.info.info.x11.display, mVideoInfo.info.info.x11.wmwindow );
- mVideoInfo.info.info.x11.unlock_func();
-#elif EE_PLATFORM == EE_PLATFORM_WIN
- WIN_ShowWindow( mVideoInfo.info.window, SW_SHOW );
-#else
- #warning cEngine::RaiseWindow() not implemented on this platform.
-#endif
-}
-
-void cEngine::SetWindowPosition(Int16 Left, Int16 Top) {
-#if EE_PLATFORM == EE_PLATFORM_LINUX
- XMoveWindow( mVideoInfo.info.info.x11.display, mVideoInfo.info.info.x11.wmwindow, Left, Top);
- XFlush( mVideoInfo.info.info.x11.display );
-#elif EE_PLATFORM == EE_PLATFORM_WIN
- SetWindowPos( mVideoInfo.info.window, NULL, Left, Top, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
-#else
- #warning cEngine::SetWindowPosition() not implemented on this platform.
-#endif
-}
-
-eeVector2i cEngine::GetWindowPosition() {
-#if EE_PLATFORM == EE_PLATFORM_LINUX
- XWindowAttributes Attrs;
- XGetWindowAttributes( mVideoInfo.info.info.x11.display, mVideoInfo.info.info.x11.wmwindow, &Attrs );
-
- return eeVector2i( Attrs.x, Attrs.y );
-#elif EE_PLATFORM == EE_PLATFORM_WIN
- RECT r;
- GetWindowRect( mVideoInfo.info.window, &r );
- return eeVector2i( r.left, r.top );
-#else
- #warning cEngine::GetWindowPos() not implemented on this platform.
- return eeVector2i( 0, 0 );
-#endif
-}
-
-bool cEngine::WindowActive() {
- return 0 != ( SDL_GetAppState() & SDL_APPINPUTFOCUS );
-}
-
-bool cEngine::WindowVisible() {
- return 0 != ( SDL_GetAppState() & SDL_APPACTIVE );
-}
-
-void cEngine::SetWindowSize( const Uint32& Width, const Uint32& Height ) {
- if ( mVideoInfo.Windowed )
- ChangeRes( Width, Height, true );
-}
-
-int cEngine::clipboard_convert_scrap(int type, char *dst, char *src, int srclen) {
- int dstlen;
-
- dstlen = 0;
- switch (type) {
- case T('T', 'E', 'X', 'T'):
- if ( srclen == 0 )
- srclen = (int)strlen(src);
-
- if ( dst ) {
- while ( --srclen >= 0 ) {
- #if EE_PLATFORM == EE_PLATFORM_WIN
- if ( *src == '\r' )
- /* drop extraneous '\r' */;
- else
- #endif
- if ( *src == '\n' ) {
- *dst++ = '\r';
- ++dstlen;
- } else {
- *dst++ = *src;
- ++dstlen;
- }
- ++src;
- }
- *dst = '\0';
- ++dstlen;
- } else {
- while ( --srclen >= 0 ) {
- #if EE_PLATFORM == EE_PLATFORM_WIN
- if ( *src == '\r' )
- /* drop unspected '\r' */;
- else
- #endif
- ++dstlen;
- ++src;
- }
- ++dstlen;
- }
- break;
- default:
- dstlen = *(int *)src;
- if ( dst ) {
- if ( srclen == 0 )
- memcpy(dst, src+sizeof(int), dstlen);
- else
- memcpy(dst, src+sizeof(int), srclen-sizeof(int));
- }
- break;
- }
- return dstlen;
-}
-
-eeScrapType cEngine::clipboard_convert_format(int type) {
- switch (type) {
- case T('T', 'E', 'X', 'T'):
- #if EE_PLATFORM == EE_PLATFORM_LINUX
- return XA_STRING;
- #elif EE_PLATFORM == EE_PLATFORM_WIN
- return CF_TEXT;
- #endif
- default: {
- char format[ sizeof(FORMAT_PREFIX)+8+1 ];
- StrFormat(format, sizeof(FORMAT_PREFIX)+8+1, "%s%08lx", FORMAT_PREFIX, (unsigned long)type);
-
- #if EE_PLATFORM == EE_PLATFORM_LINUX
- return XInternAtom( mVideoInfo.info.info.x11.display, format, False );
- #elif EE_PLATFORM == EE_PLATFORM_WIN
- #ifdef UNICODE
- return RegisterClipboardFormat( reinterpret_cast( format ) );
- #else
- return RegisterClipboardFormat( reinterpret_cast( format ) );
- #endif
- #endif
- }
+void cEngine::SetCurrentWindow( cWindow * window ) {
+ if ( NULL != window ) {
+ mWindow = window;
+
+ mWindow->SetDefaultContext();
}
}
-void cEngine::clipboard_get_scrap(int type, int *dstlen, char **dst) {
- eeScrapType format;
- *dstlen = 0;
- format = clipboard_convert_format(type);
-
-#if EE_PLATFORM == EE_PLATFORM_LINUX
- X11Window owner;
- Atom selection;
- Atom seln_type;
- int seln_format;
- unsigned long nbytes;
- unsigned long overflow;
- char *src;
-
- mVideoInfo.info.info.x11.lock_func();
- owner = XGetSelectionOwner( mVideoInfo.info.info.x11.display , XA_PRIMARY);
- mVideoInfo.info.info.x11.unlock_func();
-
- if ( ( owner == None ) || ( owner == mVideoInfo.info.info.x11.wmwindow ) ) {
- owner = DefaultRootWindow( mVideoInfo.info.info.x11.display );
- selection = XA_CUT_BUFFER0;
- } else {
- int selection_response = 0;
- SDL_Event event;
-
- owner = mVideoInfo.info.info.x11.wmwindow;
- mVideoInfo.info.info.x11.lock_func();
-
- selection = XInternAtom( mVideoInfo.info.info.x11.display, "SELECTION", False);
- XConvertSelection( mVideoInfo.info.info.x11.display, XA_PRIMARY, format, selection, owner, CurrentTime);
-
- mVideoInfo.info.info.x11.unlock_func();
-
- while ( ! selection_response ) {
- SDL_WaitEvent(&event);
- if ( event.type == SDL_SYSWMEVENT ) {
- XEvent xevent = event.syswm.msg->event.xevent;
- if ( (xevent.type == SelectionNotify) && (xevent.xselection.requestor == owner) )
- selection_response = 1;
- }
- }
- }
-
- mVideoInfo.info.info.x11.lock_func();
- if ( XGetWindowProperty( mVideoInfo.info.info.x11.display, owner, selection, 0, INT_MAX/4, False, format, &seln_type, &seln_format, &nbytes, &overflow, (unsigned char **)&src ) == Success ) {
- if ( seln_type == format ) {
- *dstlen = clipboard_convert_scrap(type, NULL, src, nbytes);
- *dst = (char *)eeMalloc( *dstlen );
-
- if ( *dst == NULL )
- *dstlen = 0;
- else
- clipboard_convert_scrap(type, *dst, src, nbytes);
- }
- XFree(src);
- }
- mVideoInfo.info.info.x11.unlock_func();
-#elif EE_PLATFORM == EE_PLATFORM_WIN
- if ( IsClipboardFormatAvailable(format) && OpenClipboard( mVideoInfo.info.window ) ) {
- HANDLE hMem;
- char *src;
- hMem = GetClipboardData(format);
- if ( hMem != NULL ) {
- src = (char *)GlobalLock(hMem);
- *dstlen = clipboard_convert_scrap(type, NULL, src, 0);
- *dst = (char *)eeMalloc( *dstlen );
- if ( *dst == NULL )
- *dstlen = 0;
- else
- clipboard_convert_scrap(type, *dst, src, 0);
- GlobalUnlock(hMem);
- }
- CloseClipboard();
- }
-#endif
+Uint32 cEngine::GetWindowCount() const {
+ return mWindows.size();
}
-std::string cEngine::GetClipboardText() {
- std::string tStr;
-
- #if EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_WIN
- char *scrap = NULL;
- int scraplen;
-
- clipboard_get_scrap( T('T','E','X','T'), &scraplen, &scrap );
-
- if ( scraplen != 0 && strcmp( scrap, "SDL-\r-scrap") ) {
- char *cp;
- int i;
-
- for ( cp = scrap, i = 0; i < scraplen; ++cp, ++i ) {
- if ( *cp == '\r' )
- *cp = '\n';
- }
-
- tStr.assign( scrap, scraplen-1 );
- }
-
- eeSAFE_DELETE_ARRAY( scrap );
- #else
- #warning cEngine::GetClipboardText() not implemented on this platform.
- #endif
-
- return tStr;
+bool cEngine::Running() const {
+ return NULL != mWindow;
}
-std::wstring cEngine::GetClipboardTextWStr() {
- std::wstring tStr;
-
- #if EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_WIN
- char * scrap = NULL;
- int scraplen;
-
- clipboard_get_scrap( T('T','E','X','T'), &scraplen, &scrap );
-
- if ( scraplen != 0 && strcmp( scrap, "SDL-\r-scrap" ) ) {
- tStr.resize( scraplen-1, L' ' );
-
- char *cp;
- int i;
-
- for ( cp = scrap, i = 0; i < scraplen; ++cp, ++i ) {
- if ( *cp == '\r' )
- *cp = '\n';
-
- unsigned char y = *cp; // convert the nevative values to positives
- tStr[i] = y;
- }
- }
-
- eeSAFE_DELETE_ARRAY( scrap );
- #else
- #warning cEngine::GetClipboardTextWStr() not implemented on this platform.
- #endif
-
- return tStr;
+void cEngine::Close() {
+ Destroy();
}
-void cEngine::SetCurrentContext( eeWindowContex Context ) {
- if ( mInit ) {
- #ifdef EE_GLEW_AVAILABLE
-
- #if EE_PLATFORM == EE_PLATFORM_WIN
- wglMakeCurrent( GetDC( mVideoInfo.info.window ), Context );
- #elif EE_PLATFORM == EE_PLATFORM_LINUX
- mVideoInfo.info.info.x11.lock_func();
- glXMakeCurrent( mVideoInfo.info.info.x11.display, mVideoInfo.info.info.x11.window, Context );
- mVideoInfo.info.info.x11.unlock_func();
- #elif EE_PLATFORM == EE_PLATFORM_MACOSX
- //aglSetCurrentContext( Context );
- #else
- #warning No context supported on this platform
- #endif
-
- #endif
- }
+eeFloat cEngine::Elapsed() const {
+ eeASSERT( Running() );
+
+ return mWindow->Elapsed();
}
-eeWindowContex cEngine::GetContext() const {
- #if defined( EE_GLEW_AVAILABLE ) && ( EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_LINUX )
- return mContext;
- #else
- return 0;
- #endif
+const Uint32& cEngine::GetWidth() const {
+ eeASSERT( Running() );
+
+ return mWindow->GetWidth();
}
-void cEngine::GetMainContext() {
-#ifdef EE_GLEW_AVAILABLE
-
-#if EE_PLATFORM == EE_PLATFORM_WIN
- mContext = wglGetCurrentContext();
-#elif EE_PLATFORM == EE_PLATFORM_LINUX
- mContext = glXGetCurrentContext();
-#elif EE_PLATFORM == EE_PLATFORM_MACOSX
- //mContext = aglGetCurrentContext();
-#endif
-
-#endif
-}
-
-eeWindowHandler cEngine::GetWindowHandler() {
-#ifdef EE_GLEW_AVAILABLE
-
-#if EE_PLATFORM == EE_PLATFORM_WIN
- return mVideoInfo.info.window;
-#elif EE_PLATFORM == EE_PLATFORM_LINUX
- return mVideoInfo.info.info.x11.display;
-#elif EE_PLATFORM == EE_PLATFORM_MACOSX
- //return mVideoInfo.info.cocoa.window;
-#endif
-
-#else
- return 0;
-#endif
-}
-
-void cEngine::SetDefaultContext() {
- #if defined( EE_GLEW_AVAILABLE ) && ( EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_LINUX )
- SetCurrentContext( mContext );
- #endif
-}
-
-void cEngine::ClipPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) {
- cGlobalBatchRenderer::instance()->Draw();
-
- GLi->Clip2DPlaneEnable( x, y, Width, Height );
-}
-
-void cEngine::ClipPlaneDisable() {
- cGlobalBatchRenderer::instance()->Draw();
-
- GLi->Clip2DPlaneDisable();
+const Uint32& cEngine::GetHeight() const {
+ eeASSERT( Running() );
+
+ return mWindow->GetHeight();
}
}}
diff --git a/src/window/cengine.hpp b/src/window/cengine.hpp
index 678072460..1d7ce5562 100755
--- a/src/window/cengine.hpp
+++ b/src/window/cengine.hpp
@@ -2,283 +2,54 @@
#define EE_WINDOWCENGINE_H
#include "base.hpp"
-#include "cview.hpp"
+#include "cbackend.hpp"
+#include "cwindow.hpp"
+
+#if EE_PLATFORM == EE_PLATFORM_WIN
+#ifdef CreateWindow
+#undef CreateWindow
+#endif
+#endif
namespace EE { namespace Window {
-/** @brief The basic Graphics class. Here Init the context and render to screen. (Singleton Class). */
+/** @brief The window management class. Here the engine start working. (Singleton Class). */
class EE_API cEngine : public tSingleton {
friend class tSingleton;
public:
- /** Init the opengl context and the screen
- * @param Width Screen Width
- * @param Height Screen Height
- * @param BitColor Screen Color Depth
- * @param Windowed Windowed or Fullscreen
- * @param Resizeable If the Screen is resizeable
- * @param VSync Enable or Disable VSync
- * @param DoubleBuffering Enable or Disable the Double Buffering
- * @param UseDesktopResolution Instead of using Screen Width and Screen Height passed, will use the default desktop resolution
- * @param NoFrame If create the window without window manager frame.
- * @param ver Version of OpenGL to use for rendering ( experimental )
- * @return True if success
- */
- bool Init( const Uint32& Width = 640, const Uint32& Height = 480, const Uint8& BitColor = 32, const bool& Windowed = true, const bool& Resizeable = false, const bool& VSync = false, const bool& DoubleBuffering = true, const bool& UseDesktopResolution = false, const bool& NoFrame = false, EEGL_version ver = GLv_default );
+ ~cEngine();
- /** Render the Scene to Screen */
- void Display();
+ cWindow * CreateWindow( WindowSettings Settings, ContextSettings Context );
- /** Set the window background color */
- void SetBackColor(const eeColor& Color);
+ void DestroyWindow( cWindow * window );
- /** @return The background clear color */
- const eeColor& GetBackColor() const;
+ cWindow * GetCurrentWindow() const;
- /** Set the window caption */
- void SetWindowCaption(const std::string& Caption);
+ void SetCurrentWindow( cWindow * window );
- /** @return The window width */
- Uint32 GetWidth() const { return mVideoInfo.Width; }
+ Uint32 GetWindowCount() const;
- /** @return The window height */
- Uint32 GetHeight() const { return mVideoInfo.Height; }
+ bool Running() const;
- /** @return The desktop width */
- Uint32 GetDeskWidth() const { return mVideoInfo.DeskWidth; }
+ void Close();
- /** @return The desktop height */
- Uint32 GetDeskHeight() const { return mVideoInfo.DeskHeight; }
-
- /** @return The elapsed time for the last frame rendered */
eeFloat Elapsed() const;
- /** @return If the aplication is running returns true ( If you Init correctly the window and is running ). */
- bool Running() const { return mInit; }
+ const Uint32& GetWidth() const;
- /** You can stop the aplication setting running as false */
- void Running(const bool& running) { mInit = running; }
+ const Uint32& GetHeight() const;
- /** Toogle the screen to Fullscreen, if it's in fullscreen toogle to windowed mode. \n This it's not fully supported on Windows platform. Use ChangeRes instead.
- */
- void ToggleFullscreen();
-
- /** Change the screen resolution
- * @param width New screen width
- * @param height New screen height
- * @param Windowed Windowed or Fullscreen
- */
- void ChangeRes( const Uint16& width, const Uint16& height, const bool& Windowed );
-
- /** @return If the main window is resizeable */
- bool Reziseable() const { return mVideoInfo.Resizeable; }
-
- /** Set a frame per second limit. It's not 100 % accurate. */
- void SetFrameRateLimit(const Uint32& FrameRateLimit);
-
- /** Get a frame per second limit. */
- Uint32 GetFrameRateLimit() { return static_cast( mFrames.FPS.Limit ); }
-
- /** Set to show or not the curson on the main screen */
- void ShowCursor(const bool& showcursor);
-
- /** @return The current frames per second of the screen */
- Uint32 FPS() const;
-
- /** Captures the OpenGL window and saves it to disk. \n
- * You have to call it before Display, and after render all the objects. \n
- * If the file path is empty will save the files like 0001.bmp, and will check if the file exists, otherwise will create 0002.bmp, and so on... \n
- * You can set only the path to save the files, like "screenshots/"
- * @return False if failed, otherwise returns True
- */
- bool TakeScreenshot( std::string filepath = "", const EE_SAVE_TYPE& Format = EE_SAVE_TYPE_PNG );
-
- /** @return The resolutions that support the video card */
- std::vector< std::pair > GetPossibleResolutions() const;
-
- /** Set the Screen Gamma. Default is (1,1,1). Accept values between 0.1 and 10. */
- void SetGamma( const eeFloat& Red, const eeFloat& Green, const eeFloat& Blue );
-
- /** Set the line smoothing ( default enabled ) */
- void SetLineSmooth( const bool& Enable );
-
- /** Set the polygon fill mode ( wireframe or filled ) */
- void SetPolygonMode( const EE_FILL_MODE& Mode );
-
- /** @return If the screen is windowed */
- bool Windowed() const;
-
- /** @return If the extension passed is supported by the GPU */
- bool GetExtension( const std::string& Ext );
-
- /** @return True if shaders are supported by the GPU */
- bool ShadersSupported() const;
-
- /** Set a Cursor from a Texture (B/W Cursor) */
- void SetCursor( const Uint32& TexId, const eeVector2i& HotSpot = eeVector2i() );
-
- /** Set the Window icon */
- bool SetIcon( const std::string& Path );
-
- /** This will attempt to iconify/minimize the window. */
- void MinimizeWindow();
-
- /** Maximize the Window */
- void MaximizeWindow();
-
- /** This will attempt to hide the window */
- void HideWindow();
-
- /** This will attempt to raise the window */
- void RaiseWindow();
-
- /** This will attempt to show the window */
- void ShowWindow();
-
- /** This will attemp to move the window over the desktop to the position */
- void SetWindowPosition(Int16 Left, Int16 Top);
-
- /** Set the current Viewport ( and create a new ortho proyection ) */
- void SetViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height );
-
- /** The Video Info Struct */
- typedef struct {
- Uint32 Width;
- Uint32 Height;
-
- Uint8 ColorDepth;
-
- Uint32 DeskWidth;
- Uint32 DeskHeight;
-
- SDL_Surface * Screen;
-
- bool Resizeable;
- bool NoFrame;
- bool Windowed;
- bool DoubleBuffering;
- bool VSync;
- bool LineSmooth;
-
- Int32 WWidth;
- Int32 WHeight;
- bool Maximized;
-
- Uint32 Flags;
-
- SDL_SysWMinfo info;
- } VideoInfo;
-
- /** @return The internal video info */
- const VideoInfo* GetVideoInfo() const { return &mVideoInfo; }
-
- /** @return The Clipboard Text if available */
- std::string GetClipboardText();
-
- /** @return The Clipboard Text if available ( as std::wstring ) */
- std::wstring GetClipboardTextWStr();
-
- /** Set the current Clipping area ( default the entire window, SCISSOR TEST ). */
- void ClipEnable( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height );
-
- /** Disable the Clipping area */
- void ClipDisable();
-
- /** Clip the area with a plane. */
- void ClipPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height );
-
- /** Disable the clip plane area. */
- void ClipPlaneDisable();
-
- /** @return If the current window is active */
- bool WindowActive();
-
- /** @return If the current window is visible */
- bool WindowVisible();
-
- /** This will set the default rendering states and view to render in 2D mode */
- void Setup2D( const bool& KeepView = false );
-
- /** Set the current active view
- @param View New view to use (pass GetDefaultView() to set the default view)
- */
- void SetView( const cView& View );
-
- /** Get the current view */
- const cView& GetView() const;
-
- /** Get the default view of the window */
- const cView& GetDefaultView() const;
-
- /** @return The company responsible for this GL implementation. */
- std::string GetVendor();
-
- /** @return The name of the renderer.\n This name is typically specific to a particular configuration of a hardware platform. */
- std::string GetRenderer();
-
- /** @return A GL version or release number. */
- std::string GetVersion();
-
- /** @return The Current Window Position */
- eeVector2i GetWindowPosition();
-
- /** Set the size of the window for a windowed window */
- void SetWindowSize( const Uint32& Width, const Uint32& Height );
-
- #if ( EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_LINUX )
- void SetCurrentContext( eeWindowContex Context );
-
- eeWindowContex GetContext() const;
-
- eeWindowHandler GetWindowHandler();
- #endif
-
- void SetDefaultContext();
-
- ~cEngine();
+ bool ExistsWindow( cWindow * window );
protected:
+ friend class cWindow;
+
+ Backend::cBackend * mBackend;
+ std::list mWindows;
+ cWindow * mWindow;
+
cEngine();
- private:
- bool mInit;
- VideoInfo mVideoInfo;
- eeColor mBackColor;
- SDL_Cursor * mCursor;
- bool mShowCursor;
- struct _Frames {
- struct _FPS {
- Uint32 LastCheck;
- Uint32 Current;
- Uint32 Count;
- eeFloat Limit;
- Int32 Error;
- } FPS;
- cTimeElapsed FrameElapsed;
- eeFloat ElapsedTime;
- } mFrames;
- cView mDefaultView;
- const cView * mCurrentView;
-
- #if defined( EE_GLEW_AVAILABLE ) && ( EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_LINUX )
- eeWindowContex mContext;
- #endif
-
- std::string mIcon;
-
- void CalculateFps();
-
- void LimitFps();
-
- void GetElapsedTime();
-
- SDL_Cursor * CreateCursor( const Uint32& TexId, const eeVector2i& HotSpot );
-
- eeScrapType clipboard_convert_format(int type);
-
- int clipboard_convert_scrap(int type, char *dst, char *src, int srclen);
-
- void clipboard_get_scrap(int type, int *dstlen, char **dst);
-
- void GetMainContext();
+ void Destroy();
};
}}
diff --git a/src/window/cinput.cpp b/src/window/cinput.cpp
index 06caa7e0f..033d2bfb6 100644
--- a/src/window/cinput.cpp
+++ b/src/window/cinput.cpp
@@ -1,153 +1,159 @@
#include "cinput.hpp"
-#include "cengine.hpp"
#include "cview.hpp"
namespace EE { namespace Window {
-cInput::cInput() :
+cInput::cInput( cWindow * window, cJoystickManager * joystickmanager ) :
+ mWindow( window ),
+ mJoystickManager( joystickmanager ),
mPressTrigger(0), mReleaseTrigger(0), mLastPressTrigger(0), mClickTrigger(0), mDoubleClickTrigger(0), mInputMod(0),
mDoubleClickInterval(500),
mLastButtonLeftClicked(0), mLastButtonRightClicked(0), mLastButtonMiddleClicked(0),
mLastButtonLeftClick(0), mLastButtonRightClick(0), mLastButtonMiddleClick(0),
- mTClick(0), mVRCall(), mNumCallBacks(0), mInputGrabed(false),
+ mTClick(0), mNumCallBacks(0),
#if EE_PLATFORM == EE_PLATFORM_LINUX
- mMouseSpeed(1.75f)
+ mMouseSpeed(1.75f),
#else
- mMouseSpeed(1.0f)
+ mMouseSpeed(1.0f),
#endif
+ mInputGrabed( false )
{
- eeVector2if mTempMouse;
- SDL_GetMouseState( &mTempMouse.x, &mTempMouse.y );
- mMousePos.x = (eeInt)mTempMouse.x;
- mMousePos.y = (eeInt)mTempMouse.y;
-
- SDL_EnableUNICODE(1);
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-
memset( mKeysDown , 0, EE_KEYS_SPACE );
memset( mKeysUp , 0, EE_KEYS_SPACE );
}
cInput::~cInput() {
- mCallbacks.clear();
+ eeSAFE_DELETE( mJoystickManager );
}
-void cInput::Update() {
+void cInput::CleanStates() {
memset( mKeysUp, 0, EE_KEYS_SPACE );
mReleaseTrigger = 0;
mLastPressTrigger = mPressTrigger;
mClickTrigger = 0;
mDoubleClickTrigger = 0;
- mInputMod = 0;
+ mInputMod = 0;
+}
- while ( SDL_PollEvent( &mEvent ) ) {
- switch( mEvent.type ) {
- case SDL_KEYDOWN:
- mInputMod = mEvent.key.keysym.mod;
-
- PushKey( &mKeysDown [ mEvent.key.keysym.sym / 8 ], mEvent.key.keysym.sym % 8, true );
- break;
- case SDL_KEYUP:
- mInputMod = mEvent.key.keysym.mod;
-
- PushKey( &mKeysDown [ mEvent.key.keysym.sym / 8 ], mEvent.key.keysym.sym % 8, false );
- PushKey( &mKeysUp [ mEvent.key.keysym.sym / 8 ], mEvent.key.keysym.sym % 8, true );
- break;
- case SDL_MOUSEMOTION:
- {
- if ( !mInputGrabed ) {
- mMousePos.x = mEvent.motion.x;
- mMousePos.y = mEvent.motion.y;
- } else {
- mMousePos.x += static_cast( (eeFloat)mEvent.motion.xrel * mMouseSpeed );
- mMousePos.y += static_cast( (eeFloat)mEvent.motion.yrel * mMouseSpeed );
- }
-
- bool bInject = false;
-
- if ( mMousePos.x >= (eeInt)cEngine::instance()->GetWidth() )
- mMousePos.x = cEngine::instance()->GetWidth();
- else if ( mMousePos.x < 0 ) {
- mMousePos.x = 0;
- bInject = true;
- }
-
- if ( mMousePos.y >= (eeInt)cEngine::instance()->GetHeight() )
- mMousePos.y = cEngine::instance()->GetHeight();
- else if ( mMousePos.y < 0 ) {
- mMousePos.y = 0;
- bInject = true;
- }
-
- #if EE_PLATFORM == EE_PLATFORM_WIN
- if ( bInject )
- InjectMousePos( mMousePos.x, mMousePos.y );
- #endif
-
- break;
- }
- case SDL_MOUSEBUTTONDOWN:
- mPressTrigger |= EE_BUTTON( mEvent.button.button );
- break;
- case SDL_MOUSEBUTTONUP:
- mPressTrigger &= ~EE_BUTTON( mEvent.button.button );
- mReleaseTrigger |= EE_BUTTON( mEvent.button.button );
- mClickTrigger |= EE_BUTTON( mEvent.button.button );
-
- if ( mEvent.button.button == EE_BUTTON_LEFT ) {
- mLastButtonLeftClicked = mLastButtonLeftClick;
- mLastButtonLeftClick = eeGetTicks();
-
- mTClick = mLastButtonLeftClick - mLastButtonLeftClicked;
- if (mTClick < mDoubleClickInterval && mTClick > 0) {
- mDoubleClickTrigger |= EE_BUTTON(EE_BUTTON_LEFT);
- mLastButtonLeftClick = 0;
- mLastButtonLeftClicked = 0;
- }
- } else if ( mEvent.button.button == EE_BUTTON_RIGHT ) {
- mLastButtonRightClicked = mLastButtonRightClick;
- mLastButtonRightClick = eeGetTicks();
-
- mTClick = mLastButtonRightClick - mLastButtonRightClicked;
- if (mTClick < mDoubleClickInterval && mTClick > 0) {
- mDoubleClickTrigger |= EE_BUTTON(EE_BUTTON_RIGHT);
- mLastButtonRightClick = 0;
- mLastButtonRightClicked = 0;
- }
- } else if( mEvent.button.button == EE_BUTTON_MIDDLE ) {
- mLastButtonMiddleClicked = mLastButtonMiddleClick;
- mLastButtonMiddleClick = eeGetTicks();
-
- mTClick = mLastButtonMiddleClick - mLastButtonMiddleClicked;
- if (mTClick < mDoubleClickInterval && mTClick > 0) {
- mDoubleClickTrigger |= EE_BUTTON(EE_BUTTON_MIDDLE);
- mLastButtonMiddleClick = 0;
- mLastButtonMiddleClicked = 0;
- }
- }
-
- break;
- case SDL_VIDEORESIZE:
- cEngine::instance()->ChangeRes(mEvent.resize.w, mEvent.resize.h, cEngine::instance()->Windowed() );
-
- CallVideoResize();
-
- break;
- case SDL_QUIT:
- cEngine::instance()->Running(false);
- break;
- }
-
- for ( std::map::iterator i = mCallbacks.begin(); i != mCallbacks.end(); i++ ) {
- i->second( &mEvent );
- }
+void cInput::SendEvent( InputEvent * Event ) {
+ for ( std::map::iterator i = mCallbacks.begin(); i != mCallbacks.end(); i++ ) {
+ i->second( Event );
}
}
-void cInput::CallVideoResize() {
- if ( mVRCall.IsSet() )
- mVRCall();
+void cInput::ProcessEvent( InputEvent * Event ) {
+ switch( Event->Type ) {
+ case InputEvent::KeyDown:
+ {
+ mInputMod = Event->key.keysym.mod;
+
+ PushKey( &mKeysDown [ Event->key.keysym.sym / 8 ], Event->key.keysym.sym % 8, true );
+ break;
+ }
+ case InputEvent::KeyUp:
+ {
+ mInputMod = Event->key.keysym.mod;
+
+ PushKey( &mKeysDown [ Event->key.keysym.sym / 8 ], Event->key.keysym.sym % 8, false );
+ PushKey( &mKeysUp [ Event->key.keysym.sym / 8 ], Event->key.keysym.sym % 8, true );
+ break;
+ }
+ case InputEvent::MouseMotion:
+ {
+ if ( !mInputGrabed ) {
+ mMousePos.x = Event->motion.x;
+ mMousePos.y = Event->motion.y;
+ } else {
+ mMousePos.x += static_cast( (eeFloat)Event->motion.xrel * mMouseSpeed );
+ mMousePos.y += static_cast( (eeFloat)Event->motion.yrel * mMouseSpeed );
+ }
+
+ bool bInject = false;
+
+ if ( mMousePos.x >= (eeInt)mWindow->GetWidth() ) {
+ mMousePos.x = mWindow->GetWidth();
+ } else if ( mMousePos.x < 0 ) {
+ mMousePos.x = 0;
+ bInject = true;
+ }
+
+ if ( mMousePos.y >= (eeInt)mWindow->GetHeight() ) {
+ mMousePos.y = mWindow->GetHeight();
+ } else if ( mMousePos.y < 0 ) {
+ mMousePos.y = 0;
+ bInject = true;
+ }
+
+ #if EE_PLATFORM == EE_PLATFORM_WIN
+ if ( bInject ) {
+ InjectMousePos( mMousePos.x, mMousePos.y );
+ }
+ #endif
+
+ break;
+ }
+ case InputEvent::MouseButtonDown:
+ {
+ mPressTrigger |= EE_BUTTON_MASK( Event->button.button );
+ break;
+ }
+ case InputEvent::MouseButtonUp:
+ {
+ mPressTrigger &= ~EE_BUTTON_MASK( Event->button.button );
+ mReleaseTrigger |= EE_BUTTON_MASK( Event->button.button );
+ mClickTrigger |= EE_BUTTON_MASK( Event->button.button );
+
+ if ( Event->button.button == EE_BUTTON_LEFT ) {
+ mLastButtonLeftClicked = mLastButtonLeftClick;
+ mLastButtonLeftClick = eeGetTicks();
+
+ mTClick = mLastButtonLeftClick - mLastButtonLeftClicked;
+
+ if ( mTClick < mDoubleClickInterval && mTClick > 0 ) {
+ mDoubleClickTrigger |= EE_BUTTON_MASK(EE_BUTTON_LEFT);
+ mLastButtonLeftClick = 0;
+ mLastButtonLeftClicked = 0;
+ }
+ } else if ( Event->button.button == EE_BUTTON_RIGHT ) {
+ mLastButtonRightClicked = mLastButtonRightClick;
+ mLastButtonRightClick = eeGetTicks();
+
+ mTClick = mLastButtonRightClick - mLastButtonRightClicked;
+
+ if ( mTClick < mDoubleClickInterval && mTClick > 0 ) {
+ mDoubleClickTrigger |= EE_BUTTON_MASK(EE_BUTTON_RIGHT);
+ mLastButtonRightClick = 0;
+ mLastButtonRightClicked = 0;
+ }
+ } else if( Event->button.button == EE_BUTTON_MIDDLE ) {
+ mLastButtonMiddleClicked = mLastButtonMiddleClick;
+ mLastButtonMiddleClick = eeGetTicks();
+
+ mTClick = mLastButtonMiddleClick - mLastButtonMiddleClicked;
+
+ if ( mTClick < mDoubleClickInterval && mTClick > 0 ) {
+ mDoubleClickTrigger |= EE_BUTTON_MASK(EE_BUTTON_MIDDLE);
+ mLastButtonMiddleClick = 0;
+ mLastButtonMiddleClicked = 0;
+ }
+ }
+
+ break;
+ }
+ case InputEvent::VideoResize:
+ {
+ mWindow->Size( Event->resize.w, Event->resize.h, mWindow->Windowed() );
+ break;
+ }
+ case InputEvent::Quit:
+ {
+ mWindow->Close();
+ break;
+ }
+ }
+
+ SendEvent( Event );
}
bool cInput::GetKey( Uint8 * Key, Uint8 Pos ) {
@@ -184,20 +190,20 @@ void cInput::InjectKeyUp( const EE_KEY& Key ) {
void cInput::InjectButtonPress( const Uint32& Button ) {
if ( Button < 8 )
- if ( !( mPressTrigger & EE_BUTTON( Button ) ) )
- mPressTrigger |= EE_BUTTON( Button );
+ if ( !( mPressTrigger & EE_BUTTON_MASK( Button ) ) )
+ mPressTrigger |= EE_BUTTON_MASK( Button );
}
void cInput::InjectButtonRelease( const Uint32& Button ) {
if ( Button < 8 ) {
- if ( mPressTrigger & EE_BUTTON( Button ) )
- mPressTrigger &= ~EE_BUTTON( Button );
+ if ( mPressTrigger & EE_BUTTON_MASK( Button ) )
+ mPressTrigger &= ~EE_BUTTON_MASK( Button );
- if ( !( mReleaseTrigger & EE_BUTTON( Button ) ) )
- mReleaseTrigger |= EE_BUTTON( Button );
+ if ( !( mReleaseTrigger & EE_BUTTON_MASK( Button ) ) )
+ mReleaseTrigger |= EE_BUTTON_MASK( Button );
- if ( !( mClickTrigger & EE_BUTTON( Button ) ) )
- mClickTrigger |= EE_BUTTON( Button );
+ if ( !( mClickTrigger & EE_BUTTON_MASK( Button ) ) )
+ mClickTrigger |= EE_BUTTON_MASK( Button );
}
}
@@ -234,27 +240,6 @@ void cInput::PopCallback( const Uint32& CallbackId ) {
mCallbacks.erase( mCallbacks.find(CallbackId) );
}
-void cInput::SetVideoResizeCallback( const VideoResizeCallback& vrc ) {
- mVRCall = vrc;
-}
-
-bool cInput::GrabInput() {
- return ( SDL_WM_GrabInput( SDL_GRAB_QUERY ) == SDL_GRAB_ON ) ? true : false;
-}
-
-void cInput::GrabInput( const bool& Grab ) {
- mInputGrabed = Grab;
-
- if ( Grab )
- SDL_WM_GrabInput(SDL_GRAB_ON);
- else
- SDL_WM_GrabInput(SDL_GRAB_OFF);
-}
-
-void cInput::InjectMousePos( const Uint16& x, const Uint16& y ) {
- SDL_WarpMouse( x, y );
-}
-
void cInput::InjectMousePos( const eeVector2i& Pos ) {
InjectMousePos( Pos.x, Pos.y );
}
@@ -355,4 +340,8 @@ void cInput::DoubleClickInterval( const Uint32& Interval ) {
mDoubleClickInterval = Interval;
}
+cJoystickManager * cInput::GetJoystickManager() const {
+ return mJoystickManager;
+}
+
}}
diff --git a/src/window/cinput.hpp b/src/window/cinput.hpp
old mode 100755
new mode 100644
index 196dd307f..06a6e0a89
--- a/src/window/cinput.hpp
+++ b/src/window/cinput.hpp
@@ -2,36 +2,45 @@
#define EE_WINDOWCINPUT_H
#include "base.hpp"
+#include "cwindow.hpp"
#include "inputhelper.hpp"
+#include "inputevent.hpp"
+#include "cjoystickmanager.hpp"
namespace EE { namespace Window {
class cView;
/** @brief The basic input class. For mouse and keyboard. */
-class EE_API cInput : public tSingleton {
- friend class tSingleton;
+class EE_API cInput {
public:
- typedef cb::Callback1 InputCallback;
- typedef cb::Callback0 VideoResizeCallback;
+ typedef cb::Callback1 InputCallback;
+
+ virtual ~cInput();
/** Update the Input */
- void Update();
+ virtual void Update() = 0;
- /** @return If keyboard key was released */
- bool IsKeyUp(const EE_KEY& Key);
+ /** @return If the mouse and keyboard are grabed. */
+ virtual bool GrabInput() = 0;
- /** @return If keyboard key it's pressed */
- bool IsKeyDown(const EE_KEY& Key);
-
- /** Inject the key state of a key as KEY UP or RELEASE */
- void InjectKeyUp(const EE_KEY& Key);
-
- /** Inject the key state of a key as KEY DOWN or PRESSED */
- void InjectKeyDown(const EE_KEY& Key);
+ /** Grab or Ungrab the mouse and keyboard. */
+ virtual void GrabInput( const bool& Grab ) = 0;
/** Inject the mouse position given */
- void InjectMousePos( const Uint16& x, const Uint16& y );
+ virtual void InjectMousePos( const Uint16& x, const Uint16& y ) = 0;
+
+ /** @return If keyboard key was released */
+ bool IsKeyUp( const EE_KEY& Key );
+
+ /** @return If keyboard key it's pressed */
+ bool IsKeyDown( const EE_KEY& Key );
+
+ /** Inject the key state of a key as KEY UP or RELEASE */
+ void InjectKeyUp( const EE_KEY& Key );
+
+ /** Inject the key state of a key as KEY DOWN or PRESSED */
+ void InjectKeyDown( const EE_KEY& Key );
/** Inject the mouse position given */
void InjectMousePos( const eeVector2i& Pos );
@@ -95,12 +104,6 @@ class EE_API cInput : public tSingleton {
/** Pop the callback id indicated. */
void PopCallback( const Uint32& CallbackId );
- /** @return If the mouse and keyboard are grabed. */
- bool GrabInput();
-
- /** Grab or Ungrab the mouse and keyboard. */
- void GrabInput( const bool& Grab );
-
/** @return The Mouse position vector */
eeVector2i GetMousePos() const;
@@ -116,9 +119,6 @@ class EE_API cInput : public tSingleton {
/** @return The Mouse Y axis position */
Uint16 MouseY() const;
- /** Sets a callback for the video resize ( usefull on windows for reloading textures loaded from memory ) */
- void SetVideoResizeCallback( const VideoResizeCallback& vrc );
-
/** Set the mouse speed ( only affects grabed windows ) */
void MouseSpeed( const eeFloat& Speed );
@@ -146,42 +146,51 @@ class EE_API cInput : public tSingleton {
/** Set the double click interval in milliseconds */
void DoubleClickInterval( const Uint32& Interval );
- ~cInput();
-
- void CallVideoResize();
+ void CleanStates();
+
+ void SendEvent( InputEvent * Event );
+
+ cJoystickManager * GetJoystickManager() const;
protected:
- cInput();
-
- EE_Event mEvent;
+ friend class cWindow;
+
+ cInput( cWindow * window, cJoystickManager * joystickmanager );
+
+ virtual void Init() = 0;
+ cWindow * mWindow;
+ cJoystickManager * mJoystickManager;
Uint8 mKeysDown [EE_KEYS_SPACE];
Uint8 mKeysUp [EE_KEYS_SPACE];
-
+ Uint32 mPressTrigger;
+ Uint32 mReleaseTrigger;
+ Uint32 mLastPressTrigger;
+ Uint32 mClickTrigger;
+ Uint32 mDoubleClickTrigger;
+ Uint32 mInputMod;
+ Uint32 mDoubleClickInterval; //!< Determine the double click inverval in milliseconds ( default 500 ms )
+ Uint32 mLastButtonLeftClicked;
+ Uint32 mLastButtonRightClicked;
+ Uint32 mLastButtonMiddleClicked;
+ Uint32 mLastButtonLeftClick;
+ Uint32 mLastButtonRightClick;
+ Uint32 mLastButtonMiddleClick;
+ Uint32 mTClick;
+ eeVector2i mMousePos;
+ Uint32 mNumCallBacks;
+ eeFloat mMouseSpeed;
+ bool mInputGrabed;
+
std::map mCallbacks;
-
- Uint32 mPressTrigger;
- Uint32 mReleaseTrigger;
- Uint32 mLastPressTrigger;
- Uint32 mClickTrigger;
- Uint32 mDoubleClickTrigger;
- Uint32 mInputMod;
- Uint32 mDoubleClickInterval; //!< Determine the double click inverval in milliseconds ( default 500 ms )
- Uint32 mLastButtonLeftClicked, mLastButtonRightClicked, mLastButtonMiddleClicked;
- Uint32 mLastButtonLeftClick, mLastButtonRightClick, mLastButtonMiddleClick;
-
- Uint32 mTClick;
- eeVector2i mMousePos;
-
- VideoResizeCallback mVRCall;
- Uint32 mNumCallBacks;
-
- bool mInputGrabed;
- eeFloat mMouseSpeed;
-
+
bool GetKey( Uint8 * Key, Uint8 Pos );
+
void PushKey( Uint8 * Key, Uint8 Pos, bool BitWrite );
+
+ void ProcessEvent( InputEvent * Event );
};
}}
#endif
+
diff --git a/src/window/cinputtextbuffer.cpp b/src/window/cinputtextbuffer.cpp
index 64b995a8e..b4dd0ed6c 100755
--- a/src/window/cinputtextbuffer.cpp
+++ b/src/window/cinputtextbuffer.cpp
@@ -1,14 +1,20 @@
#include "cinputtextbuffer.hpp"
#include "cengine.hpp"
+#include "cclipboard.hpp"
namespace EE { namespace Window {
-cInputTextBuffer::cInputTextBuffer( const bool& active, const bool& supportNewLine, const bool& supportFreeEditing, const Uint32& maxLenght ) :
+cInputTextBuffer::cInputTextBuffer( const bool& active, const bool& supportNewLine, const bool& supportFreeEditing, cWindow * window, const Uint32& maxLenght ) :
+ mWindow( window ),
mFlags(0),
mCallback(0),
mPromptPos(0),
mMaxLenght(0xFFFFFFFF)
{
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
+
Active( active );
SupportFreeEditing( supportFreeEditing );
@@ -22,12 +28,17 @@ cInputTextBuffer::cInputTextBuffer( const bool& active, const bool& supportNewLi
mMaxLenght = maxLenght;
}
-cInputTextBuffer::cInputTextBuffer() :
+cInputTextBuffer::cInputTextBuffer( cWindow * window ) :
+ mWindow( window ),
mFlags(0),
mCallback(0),
mPromptPos(0),
mMaxLenght(0xFFFFFFFF)
{
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
+
Active( true );
SupportFreeEditing( true );
@@ -40,32 +51,44 @@ cInputTextBuffer::cInputTextBuffer() :
}
cInputTextBuffer::~cInputTextBuffer() {
- if ( 0 != mCallback && NULL != cInput::ExistsSingleton() )
- cInput::instance()->PopCallback( mCallback );
+ if ( 0 != mCallback &&
+ cEngine::ExistsSingleton() &&
+ cEngine::instance()->ExistsWindow( mWindow ) )
+ {
+ mWindow->GetInput()->PopCallback( mCallback );
+ }
mText.clear();
}
void cInputTextBuffer::Start() {
- mCallback = cInput::instance()->PushCallback( cb::Make1( this, &cInputTextBuffer::Update ) );
+ if ( NULL == mWindow ) {
+ mWindow = cEngine::instance()->GetCurrentWindow();
+ }
+
+ if ( cEngine::instance()->ExistsWindow( mWindow ) ) {
+ mCallback = mWindow->GetInput()->PushCallback( cb::Make1( this, &cInputTextBuffer::Update ) );
+ }
}
-void cInputTextBuffer::Update( EE_Event* Event ) {
+void cInputTextBuffer::Update( InputEvent* Event ) {
if ( Active() ) {
+ cInput * Input = mWindow->GetInput();
+
ChangedSinceLastUpdate( false );
Int32 c = eeConvertKeyCharacter( Event->key.keysym.sym, Event->key.keysym.unicode, Event->key.keysym.mod );
if ( SupportFreeEditing() ) {
- switch ( Event->type ) {
- case SDL_KEYDOWN:
+ switch ( Event->Type ) {
+ case InputEvent::KeyDown:
{
- if ( cInput::instance()->ShiftPressed() || cInput::instance()->ControlPressed() ) {
+ if ( Input->ShiftPressed() || Input->ControlPressed() ) {
if ( !AllowOnlyNumbers() &&
( ( ( Event->key.keysym.mod & KEYMOD_SHIFT ) && c == KEY_INSERT ) ||
- ( ( Event->key.keysym.mod & KEYMOD_CTRL ) && Event->key.keysym.sym == SDLK_v ) )
+ ( ( Event->key.keysym.mod & KEYMOD_CTRL ) && Event->key.keysym.sym == KEY_V ) )
)
{
- std::wstring txt = cEngine::instance()->GetClipboardTextWStr();
+ std::wstring txt = mWindow->GetClipboard()->GetTextWStr();
if ( !SupportNewLine() ) {
Uint32 pos = txt.find_first_of( L'\n' );
@@ -170,7 +193,7 @@ void cInputTextBuffer::Update( EE_Event* Event ) {
break;
}
- case SDL_KEYUP:
+ case InputEvent::KeyUp:
{
if ( SupportNewLine() ) {
if ( c == KEY_END ) {
@@ -220,18 +243,18 @@ void cInputTextBuffer::Update( EE_Event* Event ) {
}
}
} else {
- if ( Event->type == SDL_KEYDOWN ) {
+ if ( Event->Type == InputEvent::KeyDown ) {
ChangedSinceLastUpdate( true );
if ( c == KEY_BACKSPACE && mText.size() > 0 ) {
mText.resize( mText.size() - 1 );
- } else if ( ( c == KEY_RETURN || c == KEY_KP_ENTER ) && !cInput::instance()->MetaPressed() && !cInput::instance()->AltPressed() && !cInput::instance()->ControlPressed() ) {
+ } else if ( ( c == KEY_RETURN || c == KEY_KP_ENTER ) && !Input->MetaPressed() && !Input->AltPressed() && !Input->ControlPressed() ) {
if ( SupportNewLine() && CanAdd() )
mText += L'\n';
if ( mEnterCall.IsSet() )
mEnterCall();
- } else if ( CanAdd() && isCharacter(c) && !cInput::instance()->MetaPressed() && !cInput::instance()->AltPressed() && !cInput::instance()->ControlPressed() ) {
+ } else if ( CanAdd() && isCharacter(c) && !Input->MetaPressed() && !Input->AltPressed() && !Input->ControlPressed() ) {
if ( !( AllowOnlyNumbers() && !isNumber( c, AllowDotsInNumbers() ) ) ) {
mText += c;
}
diff --git a/src/window/cinputtextbuffer.hpp b/src/window/cinputtextbuffer.hpp
index 7b069b8d1..18a0a9d49 100755
--- a/src/window/cinputtextbuffer.hpp
+++ b/src/window/cinputtextbuffer.hpp
@@ -3,6 +3,7 @@
#include "base.hpp"
#include "cinput.hpp"
+#include "cwindow.hpp"
namespace EE { namespace Window {
@@ -21,9 +22,9 @@ class EE_API cInputTextBuffer {
public:
typedef cb::Callback0 EnterCallback;
- cInputTextBuffer( const bool& active, const bool& supportNewLine, const bool& supportFreeEditing, const Uint32& maxLenght = 0xFFFFFFFF );
+ cInputTextBuffer( const bool& active, const bool& supportNewLine, const bool& supportFreeEditing, cWindow * window = NULL, const Uint32& maxLenght = 0xFFFFFFFF );
- cInputTextBuffer();
+ cInputTextBuffer( cWindow * window = NULL );
~cInputTextBuffer();
@@ -67,7 +68,7 @@ class EE_API cInputTextBuffer {
void Clear();
/** Internal callback, don't call it */
- void Update( EE_Event* Event );
+ void Update( InputEvent * Event );
/** A callback for the key return */
void SetReturnCallback( EnterCallback EC );
@@ -108,6 +109,7 @@ class EE_API cInputTextBuffer {
/** Set the cursor to the last character of the buffer. */
void CursorToEnd();
protected:
+ cWindow * mWindow;
std::wstring mText;
Uint32 mFlags;
Uint32 mCallback;
diff --git a/src/window/cjoystick.cpp b/src/window/cjoystick.cpp
index 6f445d51f..68963c142 100644
--- a/src/window/cjoystick.cpp
+++ b/src/window/cjoystick.cpp
@@ -5,7 +5,6 @@ namespace EE { namespace Window {
cJoystick::cJoystick( const Uint32& index ) :
mIndex( index ),
- mJoystick( NULL ),
mHats(0),
mButtons(0),
mAxes(0),
@@ -21,74 +20,52 @@ cJoystick::~cJoystick() {
Close();
}
-void cJoystick::Open() {
- mJoystick = SDL_JoystickOpen( mIndex );
-
- if ( NULL == mJoystick ) {
-
- } else {
- mName = SDL_JoystickName( mIndex );
- mHats = SDL_JoystickNumHats( mJoystick );
- mButtons = SDL_JoystickNumButtons( mJoystick );
- mAxes = SDL_JoystickNumAxes( mJoystick );
- mBalls = SDL_JoystickNumBalls( mJoystick );
-
- mButtonDown = mButtonDownLast = mButtonUp = 0;
-
- if ( mButtons > 32 )
- mButtons = 32;
- }
-}
-
-void cJoystick::Close() {
- if( SDL_JoystickOpened( mIndex ) )
- SDL_JoystickClose( mJoystick );
-
- mJoystick = NULL;
- mName = "";
- mHats = mButtons = mAxes = mBalls = 0;
-}
-
void cJoystick::ReOpen() {
Close();
Open();
}
-bool cJoystick::Plugged() const {
- return NULL != mJoystick;
+void cJoystick::ClearStates() {
+ mButtonUp = 0;
+ mButtonDownLast = mButtonDown;
}
-void cJoystick::Update() {
- if ( NULL != mJoystick ) {
- Int32 i;
- Uint8 v;
-
- mButtonUp = 0;
- mButtonDownLast = mButtonDown;
-
- for ( i = 0; i < mButtons; i++ ) {
- v = SDL_JoystickGetButton( mJoystick, i );
-
- if ( v ) {
- mButtonDown |= ( 1 << i );
- } else {
- if ( ( mButtonDown ) & ( 1 << i ) )
- mButtonDown &= ~( 1 << i );
- }
-
- if ( !( ( mButtonDown ) & ( 1 << i ) ) && ( ( mButtonDownLast ) & ( 1 << i ) ) )
- mButtonUp |= ( 1 << i );
- }
+void cJoystick::UpdateButton( const Uint32& index, const bool& down ) {
+ if ( down ) {
+ mButtonDown |= ( 1 << index );
+ } else {
+ if ( ( mButtonDown ) & ( 1 << index ) )
+ mButtonDown &= ~( 1 << index );
+ }
+ if ( !( ( mButtonDown ) & ( 1 << index ) ) && ( ( mButtonDownLast ) & ( 1 << index ) ) ) {
+ mButtonUp |= ( 1 << index );
}
}
-Uint8 cJoystick::GetHat( const Int32& index ) {
- if ( index >= 0 && index < mHats )
- return SDL_JoystickGetHat( mJoystick, index );
+const Int32& cJoystick::GetNumHats() const {
+ return mHats;
+}
- return HAT_CENTERED;
+const Int32& cJoystick::GetNumButtons() const {
+ return mButtons;
+}
+
+const Int32& cJoystick::GetNumAxes() const {
+ return mAxes;
+}
+
+const Int32& cJoystick::GetNumBalls() const {
+ return mBalls;
+}
+
+const Uint32& cJoystick::GetButtonTrigger() const {
+ return mButtonDown;
+}
+
+const Uint32& cJoystick::GetButtonUpTrigger() const {
+ return mButtonUp;
}
bool cJoystick::IsButtonDown( const Int32& index ) {
@@ -105,20 +82,10 @@ bool cJoystick::IsButtonUp( const Int32& index ) {
return false;
}
-Int16 cJoystick::GetAxis( const Int32& axis ) {
- if ( axis >= 0 && axis < mAxes )
- return SDL_JoystickGetAxis( mJoystick, axis );
-
- return 0;
+void cJoystick::Close() {
}
-eeVector2i cJoystick::GetBallMotion( const Int32& ball ) {
- eeVector2i v;
-
- if ( ball >= 0 && ball < mBalls )
- SDL_JoystickGetBall( mJoystick, ball, &v.x, &v.y );
-
- return v;
+void cJoystick::Open() {
}
}}
diff --git a/src/window/cjoystick.hpp b/src/window/cjoystick.hpp
index 64ee65a16..b821b12f4 100644
--- a/src/window/cjoystick.hpp
+++ b/src/window/cjoystick.hpp
@@ -2,67 +2,50 @@
#define EE_WINDOWCJOYSTICK_HPP
#include "base.hpp"
+#include "joycodes.hpp"
namespace EE { namespace Window {
-#define HAT_CENTERED 0x00
-#define HAT_UP 0x01
-#define HAT_RIGHT 0x02
-#define HAT_DOWN 0x04
-#define HAT_LEFT 0x08
-#define HAT_RIGHTUP (HAT_RIGHT|HAT_UP)
-#define HAT_RIGHTDOWN (HAT_RIGHT|HAT_DOWN)
-#define HAT_LEFTUP (HAT_LEFT|HAT_UP)
-#define HAT_LEFTDOWN (HAT_LEFT|HAT_DOWN)
-
-#define AXIS_X (0)
-#define AXIS_Y (1)
-#define AXIS_X2 (3)
-#define AXIS_Y2 (2)
-
-#define AXIS_MAX (32768)
-#define AXIS_MIN (-32768)
-
class EE_API cJoystick {
public:
cJoystick( const Uint32& index );
~cJoystick();
- void Close();
+ virtual void Close();
- void Open();
+ virtual void Open();
- void ReOpen();
+ virtual void Update() = 0;
- bool Plugged() const;
+ virtual Uint8 GetHat( const Int32& index = 0 ) = 0;
- void Update();
+ virtual Int16 GetAxis( const Int32& axis ) = 0;
- const Int32& GetNumHats() const { return mHats; }
+ virtual eeVector2i GetBallMotion( const Int32& ball ) = 0;
- const Int32& GetNumButtons() const { return mButtons; }
+ virtual bool Plugged() const = 0;
+
+ virtual void ReOpen();
- const Int32& GetNumAxes() const { return mAxes; }
+ const Int32& GetNumHats() const;
- const Int32& GetNumBalls() const { return mBalls; }
+ const Int32& GetNumButtons() const;
- const Uint32& GetButtonTrigger() const { return mButtonDown; }
+ const Int32& GetNumAxes() const;
- const Uint32& GetButtonUpTrigger() const { return mButtonUp; }
+ const Int32& GetNumBalls() const;
- Uint8 GetHat( const Int32& index = 0 );
+ const Uint32& GetButtonTrigger() const;
- Int16 GetAxis( const Int32& axis );
+ const Uint32& GetButtonUpTrigger() const;
- eeVector2i GetBallMotion( const Int32& ball );
+ bool IsButtonDown( const Int32& index );
- bool IsButtonDown( const Int32& index );
-
- bool IsButtonUp( const Int32& index );
+ bool IsButtonUp( const Int32& index );
protected:
+ friend class cJoystickManager;
Uint32 mIndex;
- SDL_Joystick * mJoystick;
std::string mName;
Int32 mHats;
Int32 mButtons;
@@ -71,8 +54,13 @@ class EE_API cJoystick {
Uint32 mButtonDown;
Uint32 mButtonDownLast;
Uint32 mButtonUp;
+
+ void UpdateButton( const Uint32& index, const bool& down );
+
+ virtual void ClearStates();
};
}}
#endif
+
diff --git a/src/window/cjoystickmanager.cpp b/src/window/cjoystickmanager.cpp
index de2e4576f..d2c8d4245 100644
--- a/src/window/cjoystickmanager.cpp
+++ b/src/window/cjoystickmanager.cpp
@@ -19,43 +19,8 @@ cJoystickManager::~cJoystickManager() {
Close();
}
-void cJoystickManager::Update() {
- if ( mInit ) {
- SDL_JoystickUpdate();
-
- for ( eeUint i = 0; i < mCount; i++ )
- if ( NULL != mJoysticks[i] )
- mJoysticks[i]->Update();
- }
-}
-
Uint32 cJoystickManager::Count() {
- return SDL_NumJoysticks();
-}
-
-void cJoystickManager::Open() {
- eeInt error = SDL_InitSubSystem( SDL_INIT_JOYSTICK );
-
- if ( !error ) {
- mCount = Count();
-
- for ( eeUint i = 0; i < mCount; i++ )
- Create(i);
-
- mInit = true;
- }
-}
-
-void cJoystickManager::Create( const Uint32& index ) {
- if ( NULL != mJoysticks[ index ] )
- mJoysticks[ index ]->ReOpen();
- else
- mJoysticks[ index ] = eeNew( cJoystick, ( index ) );
-}
-
-void cJoystickManager::Close() {
- if ( SDL_WasInit( SDL_INIT_JOYSTICK ) )
- SDL_QuitSubSystem( SDL_INIT_JOYSTICK );
+ return mCount;
}
cJoystick * cJoystickManager::GetJoystick( const Uint32& index ) {
@@ -71,4 +36,10 @@ void cJoystickManager::Rescan() {
Open();
}
+void cJoystickManager::Close() {
+}
+
+void cJoystickManager::Open() {
+}
+
}}
diff --git a/src/window/cjoystickmanager.hpp b/src/window/cjoystickmanager.hpp
index 16d172d65..9d1f9e6f4 100644
--- a/src/window/cjoystickmanager.hpp
+++ b/src/window/cjoystickmanager.hpp
@@ -6,38 +6,35 @@
namespace EE { namespace Window {
-#define MAX_JOYSTICKS (16)
-
-class EE_API cJoystickManager : public tSingleton {
- friend class tSingleton;
- friend class cJoystick;
+class EE_API cJoystickManager {
public:
cJoystickManager();
~cJoystickManager();
- Uint32 Count();
+ virtual Uint32 Count();
- void Update();
+ virtual void Update() = 0;
cJoystick * GetJoystick( const Uint32& index );
- void Rescan();
+ virtual void Rescan();
protected:
+ friend class cJoystick;
+
bool mInit;
cJoystick * mJoysticks[ MAX_JOYSTICKS ];
Uint32 mCount;
- private:
- void Close();
- void Open();
+ virtual void Close();
- void Create( const Uint32& index );
+ virtual void Open();
+
+ virtual void Create( const Uint32& index ) = 0;
};
}}
#endif
-
diff --git a/src/window/cwindow.cpp b/src/window/cwindow.cpp
new file mode 100644
index 000000000..ad2f7eb7b
--- /dev/null
+++ b/src/window/cwindow.cpp
@@ -0,0 +1,308 @@
+#include "cwindow.hpp"
+#include "cclipboard.hpp"
+#include "cinput.hpp"
+#include "../graphics/ctexturefactory.hpp"
+
+namespace EE { namespace Window {
+
+cWindow::cWindow( WindowSettings Settings, ContextSettings Context, cClipboard * Clipboard, cInput * Input ) :
+ mClipboard( Clipboard ),
+ mInput( Input ),
+ mNumCallBacks( 0 )
+{
+ mWindow.WindowConfig = Settings;
+ mWindow.ContextConfig = Context;
+}
+
+cWindow::~cWindow() {
+ eeSAFE_DELETE( mClipboard );
+ eeSAFE_DELETE( mInput );
+}
+
+eeSize cWindow::Size() {
+ return eeSize( mWindow.WindowConfig.Width, mWindow.WindowConfig.Height );
+}
+
+const Uint32& cWindow::GetWidth() const {
+ return mWindow.WindowConfig.Width;
+}
+
+const Uint32& cWindow::GetHeight() const {
+ return mWindow.WindowConfig.Height;
+}
+
+const eeSize& cWindow::GetDesktopResolution() const {
+ return mWindow.DesktopResolution;
+}
+
+bool cWindow::Windowed() const {
+ return 0 != !( mWindow.WindowConfig.Style & WindowStyle::Fullscreen );
+}
+
+bool cWindow::Resizeable() const {
+ return 0 != ( mWindow.WindowConfig.Style & WindowStyle::Resize );
+}
+
+void cWindow::SetViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height, const bool& UpdateProjectionMatrix ) {
+ GLi->Viewport( x, GetHeight() - Height - y, Width, Height );
+
+ if ( UpdateProjectionMatrix ) {
+ GLi->MatrixMode( GL_PROJECTION );
+ GLi->LoadIdentity();
+
+ GLi->Ortho( 0.0f, Width, Height, 0.0f, -1000.0f, 1000.0f );
+
+ GLi->MatrixMode( GL_MODELVIEW );
+ GLi->LoadIdentity();
+ }
+}
+
+void cWindow::SetView( const cView& View ) {
+ mCurrentView = &View;
+
+ eeRecti RView = mCurrentView->GetView();
+ SetViewport( RView.Left, RView.Top, RView.Right, RView.Bottom );
+}
+
+const cView& cWindow::GetDefaultView() const {
+ return mDefaultView;
+}
+
+const cView& cWindow::GetView() const {
+ return *mCurrentView;
+}
+
+void cWindow::CreateView() {
+ mDefaultView.SetView( 0, 0, mWindow.WindowConfig.Width, mWindow.WindowConfig.Height );
+ mCurrentView = &mDefaultView;
+}
+
+void cWindow::Setup2D( const bool& KeepView ) {
+ BackColor( mWindow.BackgroundColor );
+
+ GLi->LineSmooth();
+
+ GLi->Enable ( GL_TEXTURE_2D ); // Enable Textures
+ GLi->Disable( GL_DEPTH_TEST );
+ GLi->Disable( GL_LIGHTING );
+
+ if ( !KeepView )
+ SetView( mDefaultView );
+
+ cTextureFactory::instance()->SetPreBlendFunc( ALPHA_NORMAL, true );
+
+ if ( GLv_3 != GLi->Version() ) {
+ #ifndef EE_GLES
+ GLi->TexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
+ GLi->TexEnvi( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE );
+ #endif
+ }
+
+ GLi->EnableClientState( GL_VERTEX_ARRAY );
+ GLi->EnableClientState( GL_TEXTURE_COORD_ARRAY );
+ GLi->EnableClientState( GL_COLOR_ARRAY );
+}
+
+const WindowInfo * cWindow::GetWindowInfo() const {
+ return &mWindow;
+}
+
+void cWindow::BackColor( const eeColor& Color ) {
+ mWindow.BackgroundColor = Color;
+ GLi->ClearColor( static_cast( mWindow.BackgroundColor.R() ) / 255.0f, static_cast( mWindow.BackgroundColor.G() ) / 255.0f, static_cast( mWindow.BackgroundColor.B() ) / 255.0f, 255.0f );
+}
+
+const eeColor& cWindow::BackColor() const {
+ return mWindow.BackgroundColor;
+}
+
+bool cWindow::TakeScreenshot( std::string filepath, const EE_SAVE_TYPE& Format ) {
+ bool CreateNewFile = false;
+ std::string File, Ext;
+
+ if ( filepath.size() ) {
+ File = filepath.substr( filepath.find_last_of("/\\") + 1 );
+ Ext = File.substr( File.find_last_of(".") + 1 );
+
+ if ( IsDirectory( filepath ) || !Ext.size() )
+ CreateNewFile = true;
+ } else {
+ filepath = AppPath();
+ CreateNewFile = true;
+ }
+
+ if ( CreateNewFile ) { // Search if file path is given, and if have and extension
+ bool find = false;
+ Int32 FileNum = 1;
+ std::string TmpPath = filepath, Ext;
+
+ if ( !IsDirectory( filepath ) )
+ MakeDir( filepath );
+
+ Ext = "." + SaveTypeToExtension( Format );
+
+ while ( !find && FileNum < 10000 ) {
+ TmpPath = StrFormated( "%s%05d%s", filepath.c_str(), FileNum, Ext.c_str() );
+
+ FileNum++;
+
+ if ( !FileExists( TmpPath ) )
+ find = true;
+
+ if ( FileNum == 10000 && find == false )
+ return false;
+ }
+
+ return 0 != SOIL_save_screenshot(TmpPath.c_str(), Format, 0, 0, mWindow.WindowConfig.Width, mWindow.WindowConfig.Height );
+ } else {
+ std::string Direc = filepath.substr( 0, filepath.find_last_of("/\\") );
+ if ( !IsDirectory( Direc ) )
+ MakeDir( Direc );
+
+ return 0 != SOIL_save_screenshot(filepath.c_str(), Format, 0, 0, mWindow.WindowConfig.Width, mWindow.WindowConfig.Height );
+ }
+}
+
+bool cWindow::Running() const {
+ return mWindow.Created;
+}
+
+bool cWindow::Created() const {
+ return mWindow.Created;
+}
+
+void cWindow::Close() {
+ mWindow.Created = false;
+}
+
+void cWindow::FrameRateLimit( const Uint32& FrameRateLimit ) {
+ mFrameData.FPS.Limit = (eeFloat)FrameRateLimit;
+}
+
+Uint32 cWindow::FrameRateLimit() {
+ return static_cast( mFrameData.FPS.Limit );
+}
+
+Uint32 cWindow::FPS() const {
+ return mFrameData.FPS.Current;
+}
+
+eeFloat cWindow::Elapsed() const {
+ return mFrameData.ElapsedTime;
+}
+
+void cWindow::GetElapsedTime() {
+ mFrameData.ElapsedTime = static_cast ( mFrameData.FrameElapsed.Elapsed() );
+}
+
+void cWindow::CalculateFps() {
+ if ( eeGetTicks() - mFrameData.FPS.LastCheck >= 1000 ) {
+ mFrameData.FPS.Current = mFrameData.FPS.Count;
+ mFrameData.FPS.Count = 0;
+ mFrameData.FPS.LastCheck = eeGetTicks();
+ }
+
+ mFrameData.FPS.Count++;
+}
+
+void cWindow::LimitFps() {
+ if ( mFrameData.FPS.Limit > 0 ) {
+ mFrameData.FPS.Error = 0;
+ eeFloat RemainT = 1000.f / mFrameData.FPS.Limit - ( mFrameData.ElapsedTime * 0.1f );
+
+ if ( RemainT < 0 ) {
+ mFrameData.FPS.Error = 0;
+ } else {
+ mFrameData.FPS.Error += 1000 % (Int32)mFrameData.FPS.Limit;
+
+ if ( mFrameData.FPS.Error > (Int32)mFrameData.FPS.Limit ) {
+ ++RemainT;
+ mFrameData.FPS.Error -= (Int32)mFrameData.FPS.Limit;
+ }
+
+ if ( RemainT > 0 ) {
+ eeSleep( (Uint32) RemainT );
+ }
+ }
+ }
+}
+
+void cWindow::ViewCheckUpdate() {
+ if ( mCurrentView->NeedUpdate() ) {
+ SetView( *mCurrentView );
+ }
+}
+
+void cWindow::Display() {
+ cGlobalBatchRenderer::instance()->Draw();
+
+ if ( mCurrentView->NeedUpdate() )
+ SetView( *mCurrentView );
+
+ SwapBuffers();
+
+ GLi->Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
+
+ GetElapsedTime();
+
+ CalculateFps();
+
+ LimitFps();
+}
+
+void cWindow::ClipEnable( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height ) {
+ cGlobalBatchRenderer::instance()->Draw();
+ GLi->Scissor( x, GetHeight() - Height - y, Width, Height );
+ GLi->Enable( GL_SCISSOR_TEST );
+}
+
+void cWindow::ClipDisable() {
+ cGlobalBatchRenderer::instance()->Draw();
+ GLi->Disable( GL_SCISSOR_TEST );
+}
+
+
+void cWindow::ClipPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height ) {
+ cGlobalBatchRenderer::instance()->Draw();
+ GLi->Clip2DPlaneEnable( x, y, Width, Height );
+}
+
+void cWindow::ClipPlaneDisable() {
+ cGlobalBatchRenderer::instance()->Draw();
+ GLi->Clip2DPlaneDisable();
+}
+
+cClipboard * cWindow::GetClipboard() const {
+ return mClipboard;
+}
+
+cInput * cWindow::GetInput() const {
+ return mInput;
+}
+
+Uint32 cWindow::PushResizeCallback( const WindowResizeCallback& cb ) {
+ mNumCallBacks++;
+ mCallbacks[ mNumCallBacks ] = cb;
+ return mNumCallBacks;
+}
+
+void cWindow::PopResizeCallback( const Uint32& CallbackId ) {
+ mCallbacks[ CallbackId ] = 0;
+ mCallbacks.erase( mCallbacks.find(CallbackId) );
+}
+
+void cWindow::SendVideoResizeCb() {
+ for ( std::map::iterator i = mCallbacks.begin(); i != mCallbacks.end(); i++ ) {
+ i->second();
+ }
+}
+
+void cWindow::LogSuccessfulInit( const std::string& BackendName ) {
+ cLog::instance()->Write( "Engine Initialized Succesfully.\n\tUsing " + BackendName + " backend.\n\tGL Vendor: " + GLi->GetVendor() + "\n\tGL Renderer: " + GLi->GetRenderer() + "\n\tGL Version: " + GLi->GetVersion() );
+}
+
+void cWindow::LogFailureInit( const std::string& ClassName, const std::string& BackendName ) {
+ cLog::instance()->Write( "Error on " + ClassName + "::Init . Backend " + BackendName + " failed to start." );
+}
+
+}}
diff --git a/src/window/cwindow.hpp b/src/window/cwindow.hpp
new file mode 100644
index 000000000..3f7ce9f70
--- /dev/null
+++ b/src/window/cwindow.hpp
@@ -0,0 +1,329 @@
+#ifndef EE_WINDOWCWINDOW_HPP
+#define EE_WINDOWCWINDOW_HPP
+
+#include "base.hpp"
+#include "cview.hpp"
+
+namespace EE { namespace Window {
+
+class cClipboard;
+class cInput;
+
+namespace WindowStyle {
+ enum
+ {
+ NoBorder = ( 0 << 0 ),
+ Titlebar = ( 1 << 0 ),
+ Resize = ( 1 << 1 ),
+ Fullscreen = ( 1 << 2 ),
+ UseDesktopResolution = ( 1 << 3 ),
+ Default = Titlebar | Resize
+ };
+}
+
+class WindowSettings {
+ public:
+
+ inline WindowSettings( Uint32 width, Uint32 height, Uint32 bpp, Uint32 style = WindowStyle::Default, const std::string& icon = std::string(), const std::string& caption = std::string() ) :
+ Style( style ),
+ Width( width ),
+ Height( height ),
+ BitsPerPixel( bpp ),
+ Icon( icon ),
+ Caption( caption )
+ {}
+
+ inline WindowSettings() :
+ Style( WindowStyle::Default ),
+ Width( 800 ),
+ Height( 600 ),
+ BitsPerPixel( 32 )
+ {}
+
+ Uint32 Style;
+ Uint32 Width;
+ Uint32 Height;
+ Uint32 BitsPerPixel;
+ std::string Icon;
+ std::string Caption;
+};
+
+class ContextSettings {
+ public:
+
+ inline ContextSettings( bool vsync, EEGL_version version = GLv_default, bool doubleBuffering = true, Uint32 depthBufferSize = 24, Uint32 stencilBufferSize = 1 ) :
+ Version( version ),
+ DepthBufferSize( depthBufferSize ),
+ StencilBufferSize( stencilBufferSize ),
+ VSync( vsync ),
+ DoubleBuffering( doubleBuffering )
+ {}
+
+ inline ContextSettings() :
+ Version( GLv_default ),
+ DepthBufferSize( 24 ),
+ StencilBufferSize( 1 ),
+ VSync( false ),
+ DoubleBuffering( true )
+ {}
+
+ EEGL_version Version;
+ Uint32 DepthBufferSize;
+ Uint32 StencilBufferSize;
+ bool VSync;
+ bool DoubleBuffering;
+};
+
+class WindowInfo {
+ public:
+
+ inline WindowInfo() :
+ BackgroundColor(0,0,0),
+ Created( false ),
+ Maximized( false ),
+ CursorVisible( true )
+ {}
+
+ WindowSettings WindowConfig;
+ ContextSettings ContextConfig;
+ Uint32 Backend;
+ eeSize DesktopResolution;
+ eeSize WindowSize;
+ Uint32 Flags;
+ eeColor BackgroundColor;
+ bool Created;
+ bool Maximized;
+ bool CursorVisible;
+ eeWindowContex Context;
+};
+
+class EE_API cWindow {
+ public:
+ typedef cb::Callback0 WindowResizeCallback;
+
+ cWindow( WindowSettings Settings, ContextSettings Context, cClipboard * Clipboard, cInput * Input );
+
+ virtual ~cWindow();
+
+ /** Creates a new window and GL context */
+ virtual bool Create( WindowSettings Settings, ContextSettings Context ) = 0;
+
+ /** Toogle the screen to Fullscreen, if it's in fullscreen toogle to windowed mode. */
+ virtual void ToggleFullscreen() = 0;
+
+ /** Set the window caption */
+ virtual void Caption( const std::string& Caption ) = 0;
+
+ /** @return The caption of the titlebar */
+ virtual std::string Caption() = 0;
+
+ /** Set the Window icon */
+ virtual bool Icon( const std::string& Path ) = 0;
+
+ /** This will attempt to iconify/minimize the window. */
+ virtual void Minimize() = 0;
+
+ /** Maximize the Window */
+ virtual void Maximize() = 0;
+
+ /** This will attempt to hide the window */
+ virtual void Hide() = 0;
+
+ /** This will attempt to raise the window */
+ virtual void Raise() = 0;
+
+ /** This will attempt to show the window */
+ virtual void Show() = 0;
+
+ /** This will attemp to move the window over the desktop to the position */
+ virtual void Position( Int16 Left, Int16 Top ) = 0;
+
+ /** @return If the current window is active */
+ virtual bool Active() = 0;
+
+ /** @return If the current window is visible */
+ virtual bool Visible() = 0;
+
+ /** @return The Current Window Position */
+ virtual eeVector2i Position() = 0;
+
+ /** Set to show or not the curson on the main screen */
+ virtual void ShowCursor( const bool& showcursor ) = 0;
+
+ /** Set the size of the window for a windowed window */
+ virtual void Size( const Uint32& Width, const Uint32& Height ) = 0;
+
+ /** Change the window size or the screen resolution
+ * @param Width New screen width
+ * @param Height New screen height
+ * @param Windowed Windowed or Fullscreen
+ */
+ virtual void Size( const Uint16& Width, const Uint16& Height, const bool& Windowed ) = 0;
+
+ /** @return The resolutions that support the video card */
+ virtual std::vector< std::pair > GetPossibleResolutions() const = 0;
+
+ /** Set the Screen Gamma. Default is (1,1,1). Accept values between 0.1 and 10. */
+ virtual void SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ) = 0;
+
+ /** The the OpenGL context as the current context */
+ virtual void SetCurrentContext( eeWindowContex Context ) = 0;
+
+ /** @return The current OpenGL context */
+ virtual eeWindowContex GetContext() const = 0;
+
+ /** @return The window handler */
+ virtual eeWindowHandler GetWindowHandler() = 0;
+
+ /** Set as current context the default context ( the context used for the window creation ) */
+ virtual void SetDefaultContext() = 0;
+
+ /** Render the Scene to Screen */
+ virtual void Display();
+
+ /** @return The elapsed time for the last frame rendered */
+ virtual eeFloat Elapsed() const;
+
+ /** @return The current frames per second of the screen */
+ virtual Uint32 FPS() const;
+
+ /** @return If the screen is windowed */
+ virtual bool Windowed() const;
+
+ /** @return If the main window is resizeable */
+ virtual bool Resizeable() const;
+
+ /** @return The window size */
+ virtual eeSize Size();
+
+ /** @return The Window Width */
+ virtual const Uint32& GetWidth() const;
+
+ /** @return The Window Height */
+ virtual const Uint32& GetHeight() const;
+
+ /** @return The current desktop resolution */
+ virtual const eeSize& GetDesktopResolution() const;
+
+ /** @return If the aplication is running returns true ( If you Init correctly the window and is running ). */
+ bool Running() const;
+
+ /** @return If the window was created */
+ bool Created() const;
+
+ /** Close the window if is running */
+ virtual void Close();
+
+ /** Set the current active view
+ @param View New view to use (pass GetDefaultView() to set the default view)
+ */
+ void SetView( const cView& View );
+
+ /** Get the current view */
+ const cView& GetView() const;
+
+ /** Get the default view of the window */
+ const cView& GetDefaultView() const;
+
+ /** This will set the default rendering states and view to render in 2D mode */
+ void Setup2D( const bool& KeepView = false );
+
+ /** Set the current Viewport ( and creates a new ortho proyection if needed ) */
+ void SetViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height, const bool& UpdateProjectionMatrix = true );
+
+ /** Set the window background color */
+ void BackColor( const eeColor& Color );
+
+ /** @return The background clear color */
+ const eeColor& BackColor() const;
+
+ /** Captures the window front buffer and saves it to disk. \n
+ * You have to call it before Display, and after render all the objects. \n
+ * If the file path is empty will save the files like 0001.bmp, and will check if the file exists, otherwise will create 0002.bmp, and so on... \n
+ * You can set only the path to save the files, like "screenshots/"
+ * @return False if failed, otherwise returns True
+ */
+ bool TakeScreenshot( std::string filepath = "", const EE_SAVE_TYPE& Format = EE_SAVE_TYPE_PNG );
+
+ /** @return The pointer to the Window Info ( read only ) */
+ const WindowInfo * GetWindowInfo() const;
+
+ /** Set a frame per second limit. It's not 100 % accurate. */
+ void FrameRateLimit( const Uint32& FrameRateLimit );
+
+ /** Get a frame per second limit. */
+ Uint32 FrameRateLimit();
+
+ /** Set the current Clipping area ( default the entire window, SCISSOR TEST ). */
+ void ClipEnable( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height );
+
+ /** Disable the Clipping area */
+ void ClipDisable();
+
+ /** Clip the area with a plane. */
+ void ClipPlaneEnable( const Int32& x, const Int32& y, const Int32& Width, const Int32& Height );
+
+ /** Disable the clip plane area. */
+ void ClipPlaneDisable();
+
+ /** @return The clipboard manager */
+ cClipboard * GetClipboard() const;
+
+ /** @return The input manager */
+ cInput * GetInput() const;
+
+ /** Push a new window resize callback.
+ * @return The Callback Id
+ */
+ Uint32 PushResizeCallback( const WindowResizeCallback& cb );
+
+ /** Pop the callback id indicated. */
+ void PopResizeCallback( const Uint32& CallbackId );
+ protected:
+ WindowInfo mWindow;
+ cClipboard * mClipboard;
+ cInput * mInput;
+ cView mDefaultView;
+ const cView * mCurrentView;
+ Uint32 mNumCallBacks;
+ std::map mCallbacks;
+
+ struct _FrameData {
+ public:
+ struct FPSData {
+ Uint32 LastCheck;
+ Uint32 Current;
+ Uint32 Count;
+ eeFloat Limit;
+ Int32 Error;
+ } FPS;
+ cTimeElapsed FrameElapsed;
+ eeFloat ElapsedTime;
+ } mFrameData;
+
+ /** Swap Buffers call */
+ virtual void SwapBuffers() = 0;
+
+ /** Obtain the Main Context, this is called after the OpenGL context creation. */
+ virtual void GetMainContext() = 0;
+
+ void SendVideoResizeCb();
+
+ void CreateView();
+
+ void CalculateFps();
+
+ void LimitFps();
+
+ void GetElapsedTime();
+
+ void ViewCheckUpdate();
+
+ void LogSuccessfulInit( const std::string& BackendName );
+
+ void LogFailureInit( const std::string& ClassName, const std::string& BackendName );
+};
+
+}}
+
+#endif
diff --git a/src/window/inputevent.hpp b/src/window/inputevent.hpp
new file mode 100644
index 000000000..20465d92b
--- /dev/null
+++ b/src/window/inputevent.hpp
@@ -0,0 +1,157 @@
+#ifndef EE_WINDOWINPUTEVENT_HPP
+#define EE_WINDOWINPUTEVENT_HPP
+
+namespace EE { namespace Window {
+
+class InputEvent {
+ public:
+ inline InputEvent() {}
+
+ inline InputEvent( Uint32 type ) : Type( type ) {}
+
+ struct KeySym {
+ Uint32 sym; /** virtual keysym */
+ Uint32 mod; /** current key modifiers */
+ Uint16 unicode; /** translated character */
+ };
+
+ /** Application visibility event structure */
+ struct ActiveEvent {
+ Uint8 gain; /** Whether given states were gained or lost (1/0) */
+ Uint8 state; /** A mask of the focus states */
+ };
+
+ /** Keyboard event structure */
+ struct KeyboardEvent {
+ Uint8 which; /** The keyboard device index */
+ Uint8 state;
+ KeySym keysym;
+ };
+
+ /** Mouse motion event structure */
+ struct MouseMotionEvent {
+ Uint8 which; /** The mouse device index */
+ Uint8 state; /** The current button state */
+ Uint16 x, y; /** The X/Y coordinates of the mouse */
+ Int16 xrel; /** The relative motion in the X direction */
+ Int16 yrel; /** The relative motion in the Y direction */
+ };
+
+ /** Mouse button event structure */
+ struct MouseButtonEvent {
+ Uint8 which; /** The mouse device index */
+ Uint8 button; /** The mouse button index */
+ Uint8 state; /** EE_PRESSED or EE_RELEASED */
+ Uint16 x, y; /** The X/Y coordinates of the mouse at press time */
+ };
+
+ /** Joystick axis motion event structure */
+ struct JoyAxisEvent {
+ Uint8 which; /** The joystick device index */
+ Uint8 axis; /** The joystick axis index */
+ Int16 value; /** The axis value (range: -32768 to 32767) */
+ };
+
+ /** Joystick trackball motion event structure */
+ struct JoyBallEvent {
+ Uint8 which; /** The joystick device index */
+ Uint8 ball; /** The joystick trackball index */
+ Int16 xrel; /** The relative motion in the X direction */
+ Int16 yrel; /** The relative motion in the Y direction */
+ };
+
+ /** Joystick hat position change event structure */
+ struct JoyHatEvent {
+ Uint8 which; /** The joystick device index */
+ Uint8 hat; /** The joystick hat index */
+ Uint8 value; /** The hat position value:
+ * EE_HAT_LEFTUP EE_HAT_UP EE_HAT_RIGHTUP
+ * EE_HAT_LEFT EE_HAT_CENTERED EE_HAT_RIGHT
+ * EE_HAT_LEFTDOWN EE_HAT_DOWN EE_HAT_RIGHTDOWN
+ * Note that zero means the POV is centered.
+ */
+ };
+
+ /** Joystick button event structure */
+ struct JoyButtonEvent {
+ Uint8 which; /** The joystick device index */
+ Uint8 button; /** The joystick button index */
+ Uint8 state; /** EE_PRESSED or EE_RELEASED */
+ };
+
+ /** The "window resized" event */
+ struct ResizeEvent {
+ int w; /** New width */
+ int h; /** New height */
+ };
+
+ /** The "screen redraw" event */
+ struct ExposeEvent {
+ Uint8 type;
+ };
+
+ /** The "quit requested" event */
+ struct QuitEvent {
+ Uint8 type;
+ };
+
+ /** A user-defined event type */
+ struct UserEvent {
+ Uint8 type; /** EE_USEREVENT through EE_NUMEVENTS-1 */
+ int code; /** User defined event code */
+ void *data1; /** User defined data pointer */
+ void *data2; /** User defined data pointer */
+ };
+
+ /** If you want to use this event, you should include EE_syswm.h */
+ struct SysWMmsg;
+ typedef struct SysWMmsg SysWMmsg;
+ struct SysWMEvent {
+ SysWMmsg * msg;
+ };
+
+ enum EventType {
+ NoEvent = 0,
+ Active,
+ KeyDown,
+ KeyUp,
+ MouseMotion,
+ MouseButtonDown,
+ MouseButtonUp,
+ JoyAxisMotion,
+ JoyBallMotion,
+ JoyHatMotion,
+ JoyButtonDown,
+ JoyButtonUp,
+ Quit,
+ SysWM,
+ VideoResize,
+ VideoExpose,
+ EventUser,
+ EventCount = 32
+ };
+
+ /** Event Type */
+ Uint32 Type;
+
+ /** General event structure */
+ union {
+ ActiveEvent active;
+ KeyboardEvent key;
+ MouseMotionEvent motion;
+ MouseButtonEvent button;
+ JoyAxisEvent jaxis;
+ JoyBallEvent jball;
+ JoyHatEvent jhat;
+ JoyButtonEvent jbutton;
+ ResizeEvent resize;
+ ExposeEvent expose;
+ QuitEvent quit;
+ UserEvent user;
+ SysWMEvent syswm;
+ };
+};
+
+}}
+
+#endif
diff --git a/src/window/inputhelper.hpp b/src/window/inputhelper.hpp
index 005941d22..ff4af4b28 100644
--- a/src/window/inputhelper.hpp
+++ b/src/window/inputhelper.hpp
@@ -6,309 +6,10 @@
namespace EE { namespace Window {
-#define EE_BUTTON(X) ( 1 << ( ( X ) - 1 ) )
-#define EE_BUTTON_LEFT (1)
-#define EE_BUTTON_MIDDLE (2)
-#define EE_BUTTON_RIGHT (3)
-#define EE_BUTTON_WHEELUP (4)
-#define EE_BUTTON_WHEELDOWN (5)
-#define EE_BUTTON_X1 (6)
-#define EE_BUTTON_X2 (7)
-#define EE_BUTTON_LMASK (EE_BUTTON(EE_BUTTON_LEFT))
-#define EE_BUTTON_MMASK (EE_BUTTON(EE_BUTTON_MIDDLE))
-#define EE_BUTTON_RMASK (EE_BUTTON(EE_BUTTON_RIGHT))
-#define EE_BUTTON_X1MASK (EE_BUTTON(EE_BUTTON_X1))
-#define EE_BUTTON_X2MASK (EE_BUTTON(EE_BUTTON_X2))
-#define EE_BUTTON_WUMASK (EE_BUTTON(EE_BUTTON_WHEELUP))
-#define EE_BUTTON_WDMASK (EE_BUTTON(EE_BUTTON_WHEELDOWN))
-
-#define EE_BUTTONS_LRM ( EE_BUTTON(EE_BUTTON_LEFT) | EE_BUTTON(EE_BUTTON_MIDDLE) | EE_BUTTON(EE_BUTTON_RIGHT) )
-#define EE_BUTTONS_WUWD ( EE_BUTTON(EE_BUTTON_WHEELUP) | EE_BUTTON(EE_BUTTON_WHEELDOWN) )
-#define EE_BUTTONS_ALL (0xFFffFFff)
-
#define EE_KEYS_SPACE (336/8)
-/** EE_Event is just an SDL_Event */
-typedef SDL_Event EE_Event;
-
Uint32 EE_API eeConvertKeyCharacter( const Uint32& KeyCode, const Uint16& Unicode, const Uint32& Modifiers );
-/** @enum EE_KEY Enum of keyboard keys. */
-enum EE_KEY {
- KEY_UNKNOWN = SDLK_UNKNOWN,
- KEY_FIRST = SDLK_FIRST,
- KEY_BACKSPACE = SDLK_BACKSPACE,
- KEY_TAB = SDLK_TAB,
- KEY_CLEAR = SDLK_CLEAR,
- KEY_RETURN = SDLK_RETURN,
- KEY_PAUSE = SDLK_PAUSE,
- KEY_ESCAPE = SDLK_ESCAPE,
- KEY_SPACE = SDLK_SPACE,
- KEY_EXCLAIM = SDLK_EXCLAIM,
- KEY_QUOTEDBL = SDLK_QUOTEDBL,
- KEY_HASH = SDLK_HASH,
- KEY_DOLLAR = SDLK_DOLLAR,
- KEY_AMPERSAND = SDLK_AMPERSAND,
- KEY_QUOTE = SDLK_QUOTE,
- KEY_LEFTPAREN = SDLK_LEFTPAREN,
- KEY_RIGHTPAREN = SDLK_RIGHTPAREN,
- KEY_ASTERISK = SDLK_ASTERISK,
- KEY_PLUS = SDLK_PLUS,
- KEY_COMMA = SDLK_COMMA,
- KEY_MINUS = SDLK_MINUS,
- KEY_PERIOD = SDLK_PERIOD,
- KEY_SLASH = SDLK_SLASH,
- KEY_0 = SDLK_0,
- KEY_1 = SDLK_1,
- KEY_2 = SDLK_2,
- KEY_3 = SDLK_3,
- KEY_4 = SDLK_4,
- KEY_5 = SDLK_5,
- KEY_6 = SDLK_6,
- KEY_7 = SDLK_7,
- KEY_8 = SDLK_8,
- KEY_9 = SDLK_9,
- KEY_COLON = SDLK_COLON,
- KEY_SEMICOLON = SDLK_SEMICOLON,
- KEY_LESS = SDLK_LESS,
- KEY_EQUALS = SDLK_EQUALS,
- KEY_GREATER = SDLK_GREATER,
- KEY_QUESTION = SDLK_QUESTION,
- KEY_AT = SDLK_AT,
-
-
- /*
- Skip uppercase letters
- */
- KEY_LEFTBRACKET = SDLK_LEFTBRACKET,
- KEY_BACKSLASH = SDLK_BACKSLASH,
- KEY_RIGHTBRACKET = SDLK_RIGHTBRACKET,
- KEY_CARET = SDLK_CARET,
- KEY_UNDERSCORE = SDLK_UNDERSCORE,
- KEY_BACKQUOTE = SDLK_BACKQUOTE, ///< GRAVE
- KEY_A = SDLK_a,
- KEY_B = SDLK_b,
- KEY_C = SDLK_c,
- KEY_D = SDLK_d,
- KEY_E = SDLK_e,
- KEY_F = SDLK_f,
- KEY_G = SDLK_g,
- KEY_H = SDLK_h,
- KEY_I = SDLK_i,
- KEY_J = SDLK_j,
- KEY_K = SDLK_k,
- KEY_L = SDLK_l,
- KEY_M = SDLK_m,
- KEY_N = SDLK_n,
- KEY_O = SDLK_o,
- KEY_P = SDLK_p,
- KEY_Q = SDLK_q,
- KEY_R = SDLK_r,
- KEY_S = SDLK_s,
- KEY_T = SDLK_t,
- KEY_U = SDLK_u,
- KEY_V = SDLK_v,
- KEY_W = SDLK_w,
- KEY_X = SDLK_x,
- KEY_Y = SDLK_y,
- KEY_Z = SDLK_z,
- KEY_DELETE = SDLK_DELETE,
- /* End of ASCII mapped keysyms */
-
- /* Numeric keypad */
- KEY_KP0 = SDLK_KP0,
- KEY_KP1 = SDLK_KP1,
- KEY_KP2 = SDLK_KP2,
- KEY_KP3 = SDLK_KP3,
- KEY_KP4 = SDLK_KP4,
- KEY_KP5 = SDLK_KP5,
- KEY_KP6 = SDLK_KP6,
- KEY_KP7 = SDLK_KP7,
- KEY_KP8 = SDLK_KP8,
- KEY_KP9 = SDLK_KP9,
- KEY_KP_PEROID = SDLK_KP_PERIOD,
- KEY_KP_DIVIDE = SDLK_KP_DIVIDE,
- KEY_KP_MULTIPLY = SDLK_KP_MULTIPLY,
- KEY_KP_MINUS = SDLK_KP_MINUS,
- KEY_KP_PLUS = SDLK_KP_PLUS,
- KEY_KP_ENTER = SDLK_KP_ENTER,
- KEY_KP_EQUALS = SDLK_KP_EQUALS,
-
- /* Arrows + Home/End pad */
- KEY_UP = SDLK_UP,
- KEY_DOWN = SDLK_DOWN,
- KEY_RIGHT = SDLK_RIGHT,
- KEY_LEFT = SDLK_LEFT,
- KEY_INSERT = SDLK_INSERT,
- KEY_HOME = SDLK_HOME,
- KEY_END = SDLK_END,
- KEY_PAGEUP = SDLK_PAGEUP,
- KEY_PAGEDOWN = SDLK_PAGEDOWN,
-
- /* Function keys */
- KEY_F1 = SDLK_F1,
- KEY_F2 = SDLK_F2,
- KEY_F3 = SDLK_F3,
- KEY_F4 = SDLK_F4,
- KEY_F5 = SDLK_F5,
- KEY_F6 = SDLK_F6,
- KEY_F7 = SDLK_F7,
- KEY_F8 = SDLK_F8,
- KEY_F9 = SDLK_F9,
- KEY_F10 = SDLK_F10,
- KEY_F11 = SDLK_F11,
- KEY_F12 = SDLK_F12,
- KEY_F13 = SDLK_F13,
- KEY_F14 = SDLK_F14,
- KEY_F15 = SDLK_F15,
-
- /* Key state modifier keys */
- KEY_NUMLOCK = SDLK_NUMLOCK,
- KEY_CAPSLOCK = SDLK_CAPSLOCK,
- KEY_SCROLLOCK = SDLK_SCROLLOCK,
- KEY_RSHIFT = SDLK_RSHIFT,
- KEY_LSHIFT = SDLK_LSHIFT,
- KEY_RCTRL = SDLK_RCTRL,
- KEY_LCTRL = SDLK_LCTRL,
- KEY_RALT = SDLK_RALT,
- KEY_LALT = SDLK_LALT,
- KEY_RMETA = SDLK_RMETA,
- KEY_LMETA = SDLK_LMETA,
- KEY_LSUPER = SDLK_LSUPER, ///< Left "Windows" key
- KEY_RSUPER = SDLK_RSUPER, ///< Right "Windows" key
-
- /* Miscellaneous function keys */
- KEY_HELP = SDLK_HELP,
- KEY_PRINT = SDLK_PRINT,
- KEY_SYSREQ = SDLK_SYSREQ,
- KEY_BREAK = SDLK_BREAK,
- KEY_MENU = SDLK_MENU,
- KEY_MODE = SDLK_MODE, ///< "Alt Gr" key
- KEY_COMPOSE = SDLK_COMPOSE, ///< Multi-key compose key
- KEY_POWER = SDLK_POWER, ///< Power Macintosh power key
- KEY_EURO = SDLK_EURO, ///< Some european keyboards
- KEY_UNDO = SDLK_UNDO, ///< Atari keyboard has Undo
-
- /* International keyboard syms */
- KEY_WORLD_0 = SDLK_WORLD_0,
- KEY_WORLD_1 = SDLK_WORLD_1,
- KEY_WORLD_2 = SDLK_WORLD_2,
- KEY_WORLD_3 = SDLK_WORLD_3,
- KEY_WORLD_4 = SDLK_WORLD_4,
- KEY_WORLD_5 = SDLK_WORLD_5,
- KEY_WORLD_6 = SDLK_WORLD_6,
- KEY_WORLD_7 = SDLK_WORLD_7,
- KEY_WORLD_8 = SDLK_WORLD_8,
- KEY_WORLD_9 = SDLK_WORLD_9,
- KEY_WORLD_10 = SDLK_WORLD_10,
- KEY_WORLD_11 = SDLK_WORLD_11,
- KEY_WORLD_12 = SDLK_WORLD_12,
- KEY_WORLD_13 = SDLK_WORLD_13,
- KEY_WORLD_14 = SDLK_WORLD_14,
- KEY_WORLD_15 = SDLK_WORLD_15,
- KEY_WORLD_16 = SDLK_WORLD_16,
- KEY_WORLD_17 = SDLK_WORLD_17,
- KEY_WORLD_18 = SDLK_WORLD_18,
- KEY_WORLD_19 = SDLK_WORLD_19,
- KEY_WORLD_20 = SDLK_WORLD_20,
- KEY_WORLD_21 = SDLK_WORLD_21,
- KEY_WORLD_22 = SDLK_WORLD_22,
- KEY_WORLD_23 = SDLK_WORLD_23,
- KEY_WORLD_24 = SDLK_WORLD_24,
- KEY_WORLD_25 = SDLK_WORLD_25,
- KEY_WORLD_26 = SDLK_WORLD_26,
- KEY_WORLD_27 = SDLK_WORLD_27,
- KEY_WORLD_28 = SDLK_WORLD_28,
- KEY_WORLD_29 = SDLK_WORLD_29,
- KEY_WORLD_30 = SDLK_WORLD_30,
- KEY_WORLD_31 = SDLK_WORLD_31,
- KEY_WORLD_32 = SDLK_WORLD_32,
- KEY_WORLD_33 = SDLK_WORLD_33,
- KEY_WORLD_34 = SDLK_WORLD_34,
- KEY_WORLD_35 = SDLK_WORLD_35,
- KEY_WORLD_36 = SDLK_WORLD_36,
- KEY_WORLD_37 = SDLK_WORLD_37,
- KEY_WORLD_38 = SDLK_WORLD_38,
- KEY_WORLD_39 = SDLK_WORLD_39,
- KEY_WORLD_40 = SDLK_WORLD_40,
- KEY_WORLD_41 = SDLK_WORLD_41,
- KEY_WORLD_42 = SDLK_WORLD_42,
- KEY_WORLD_43 = SDLK_WORLD_43,
- KEY_WORLD_44 = SDLK_WORLD_44,
- KEY_WORLD_45 = SDLK_WORLD_45,
- KEY_WORLD_46 = SDLK_WORLD_46,
- KEY_WORLD_47 = SDLK_WORLD_47,
- KEY_WORLD_48 = SDLK_WORLD_48,
- KEY_WORLD_49 = SDLK_WORLD_49,
- KEY_WORLD_50 = SDLK_WORLD_50,
- KEY_WORLD_51 = SDLK_WORLD_51,
- KEY_WORLD_52 = SDLK_WORLD_52,
- KEY_WORLD_53 = SDLK_WORLD_53,
- KEY_WORLD_54 = SDLK_WORLD_54,
- KEY_WORLD_55 = SDLK_WORLD_55,
- KEY_WORLD_56 = SDLK_WORLD_56,
- KEY_WORLD_57 = SDLK_WORLD_57,
- KEY_WORLD_58 = SDLK_WORLD_58,
- KEY_WORLD_59 = SDLK_WORLD_59,
- KEY_WORLD_60 = SDLK_WORLD_60,
- KEY_WORLD_61 = SDLK_WORLD_61,
- KEY_WORLD_62 = SDLK_WORLD_62,
- KEY_WORLD_63 = SDLK_WORLD_63,
- KEY_WORLD_64 = SDLK_WORLD_64,
- KEY_WORLD_65 = SDLK_WORLD_65,
- KEY_WORLD_66 = SDLK_WORLD_66,
- KEY_WORLD_67 = SDLK_WORLD_67,
- KEY_WORLD_68 = SDLK_WORLD_68,
- KEY_WORLD_69 = SDLK_WORLD_69,
- KEY_WORLD_70 = SDLK_WORLD_70,
- KEY_WORLD_71 = SDLK_WORLD_71,
- KEY_WORLD_72 = SDLK_WORLD_72,
- KEY_WORLD_73 = SDLK_WORLD_73,
- KEY_WORLD_74 = SDLK_WORLD_74,
- KEY_WORLD_75 = SDLK_WORLD_75,
- KEY_WORLD_76 = SDLK_WORLD_76,
- KEY_WORLD_77 = SDLK_WORLD_77,
- KEY_WORLD_78 = SDLK_WORLD_78,
- KEY_WORLD_79 = SDLK_WORLD_79,
- KEY_WORLD_80 = SDLK_WORLD_80,
- KEY_WORLD_81 = SDLK_WORLD_81,
- KEY_WORLD_82 = SDLK_WORLD_82,
- KEY_WORLD_83 = SDLK_WORLD_83,
- KEY_WORLD_84 = SDLK_WORLD_84,
- KEY_WORLD_85 = SDLK_WORLD_85,
- KEY_WORLD_86 = SDLK_WORLD_86,
- KEY_WORLD_87 = SDLK_WORLD_87,
- KEY_WORLD_88 = SDLK_WORLD_88,
- KEY_WORLD_89 = SDLK_WORLD_89,
- KEY_WORLD_90 = SDLK_WORLD_90,
- KEY_WORLD_91 = SDLK_WORLD_91,
- KEY_WORLD_92 = SDLK_WORLD_92,
- KEY_WORLD_93 = SDLK_WORLD_93,
- KEY_WORLD_94 = SDLK_WORLD_94,
- KEY_WORLD_95 = SDLK_WORLD_95
-};
-
-enum EE_KEY_MOD {
- KEYMOD_NONE = KMOD_NONE,
- KEYMOD_LSHIFT = KMOD_LSHIFT,
- KEYMOD_RSHIFT = KMOD_RSHIFT,
- KEYMOD_LCTRL = KMOD_LCTRL,
- KEYMOD_RCTRL = KMOD_RCTRL,
- KEYMOD_LALT = KMOD_LALT,
- KEYMOD_RALT = KMOD_RALT,
- KEYMOD_LMETA = KMOD_LMETA,
- KEYMOD_RMETA = KMOD_RMETA,
- KEYMOD_NUM = KMOD_NUM,
- KEYMOD_CAPS = KMOD_CAPS,
- KEYMOD_MODE = KMOD_MODE,
- KEYMOD_RESERVED = KMOD_RESERVED
-};
-
-#define KEYMOD_CTRL ( KEYMOD_LCTRL | KEYMOD_RCTRL )
-#define KEYMOD_SHIFT ( KEYMOD_LSHIFT | KEYMOD_RSHIFT )
-#define KEYMOD_ALT ( KEYMOD_LALT | KEYMOD_RALT )
-#define KEYMOD_META ( KEYMOD_LMETA | KEYMOD_RMETA )
-
}}
#endif
diff --git a/src/window/joycodes.hpp b/src/window/joycodes.hpp
new file mode 100644
index 000000000..8b3a315bc
--- /dev/null
+++ b/src/window/joycodes.hpp
@@ -0,0 +1,32 @@
+#ifndef EE_WINDOWJOYCODES_HPP
+#define EE_WINDOWJOYCODES_HPP
+
+namespace EE { namespace Window {
+
+enum EE_HAT_POS {
+ HAT_CENTERED = 0x00,
+ HAT_UP = 0x01,
+ HAT_RIGHT = 0x02,
+ HAT_DOWN = 0x04,
+ HAT_LEFT = 0x08,
+ HAT_RIGHTUP = (HAT_RIGHT|HAT_UP),
+ HAT_RIGHTDOWN = (HAT_RIGHT|HAT_DOWN),
+ HAT_LEFTUP = (HAT_LEFT|HAT_UP),
+ HAT_LEFTDOWN = (HAT_LEFT|HAT_DOWN)
+};
+
+enum EE_JOYAXIS {
+ AXIS_X = 0,
+ AXIS_Y = 1,
+ AXIS_X2 = 3,
+ AXIS_Y2 = 2
+};
+
+#define AXIS_MAX (32768)
+#define AXIS_MIN (-32768)
+
+#define MAX_JOYSTICKS (16)
+
+}}
+
+#endif
diff --git a/src/window/keycodes.hpp b/src/window/keycodes.hpp
new file mode 100644
index 000000000..a803c4292
--- /dev/null
+++ b/src/window/keycodes.hpp
@@ -0,0 +1,310 @@
+#ifndef EE_INPUT_KEYKODES_HPP
+#define EE_INPUT_KEYKODES_HPP
+
+namespace EE { namespace Window {
+
+/** @enum EE_KEY Enum of keyboard keys. */
+enum EE_KEY {
+ KEY_UNKNOWN = 0,
+ KEY_FIRST = 0,
+ KEY_BACKSPACE = 8,
+ KEY_TAB = 9,
+ KEY_CLEAR = 12,
+ KEY_RETURN = 13,
+ KEY_PAUSE = 19,
+ KEY_ESCAPE = 27,
+ KEY_SPACE = 32,
+ KEY_EXCLAIM = 33,
+ KEY_QUOTEDBL = 34,
+ KEY_HASH = 35,
+ KEY_DOLLAR = 36,
+ KEY_AMPERSAND = 38,
+ KEY_QUOTE = 39,
+ KEY_LEFTPAREN = 40,
+ KEY_RIGHTPAREN = 41,
+ KEY_ASTERISK = 42,
+ KEY_PLUS = 43,
+ KEY_COMMA = 44,
+ KEY_MINUS = 45,
+ KEY_PERIOD = 46,
+ KEY_SLASH = 47,
+ KEY_0 = 48,
+ KEY_1 = 49,
+ KEY_2 = 50,
+ KEY_3 = 51,
+ KEY_4 = 52,
+ KEY_5 = 53,
+ KEY_6 = 54,
+ KEY_7 = 55,
+ KEY_8 = 56,
+ KEY_9 = 57,
+ KEY_COLON = 58,
+ KEY_SEMICOLON = 59,
+ KEY_LESS = 60,
+ KEY_EQUALS = 61,
+ KEY_GREATER = 62,
+ KEY_QUESTION = 63,
+ KEY_AT = 64,
+
+ /*
+ Skip uppercase letters
+ */
+ KEY_LEFTBRACKET = 91,
+ KEY_BACKSLASH = 92,
+ KEY_RIGHTBRACKET = 93,
+ KEY_CARET = 94,
+ KEY_UNDERSCORE = 95,
+ KEY_BACKQUOTE = 96, ///< GRAVE
+ KEY_A = 97,
+ KEY_B = 98,
+ KEY_C = 99,
+ KEY_D = 100,
+ KEY_E = 101,
+ KEY_F = 102,
+ KEY_G = 103,
+ KEY_H = 104,
+ KEY_I = 105,
+ KEY_J = 106,
+ KEY_K = 107,
+ KEY_L = 108,
+ KEY_M = 109,
+ KEY_N = 110,
+ KEY_O = 111,
+ KEY_P = 112,
+ KEY_Q = 113,
+ KEY_R = 114,
+ KEY_S = 115,
+ KEY_T = 116,
+ KEY_U = 117,
+ KEY_V = 118,
+ KEY_W = 119,
+ KEY_X = 120,
+ KEY_Y = 121,
+ KEY_Z = 122,
+ KEY_DELETE = 127,
+ /* End of ASCII mapped keysyms */
+
+ /* International keyboard syms */
+ KEY_WORLD_0 = 160,
+ KEY_WORLD_1 = 161,
+ KEY_WORLD_2 = 162,
+ KEY_WORLD_3 = 163,
+ KEY_WORLD_4 = 164,
+ KEY_WORLD_5 = 165,
+ KEY_WORLD_6 = 166,
+ KEY_WORLD_7 = 167,
+ KEY_WORLD_8 = 168,
+ KEY_WORLD_9 = 169,
+ KEY_WORLD_10 = 170,
+ KEY_WORLD_11 = 171,
+ KEY_WORLD_12 = 172,
+ KEY_WORLD_13 = 173,
+ KEY_WORLD_14 = 174,
+ KEY_WORLD_15 = 175,
+ KEY_WORLD_16 = 176,
+ KEY_WORLD_17 = 177,
+ KEY_WORLD_18 = 178,
+ KEY_WORLD_19 = 179,
+ KEY_WORLD_20 = 180,
+ KEY_WORLD_21 = 181,
+ KEY_WORLD_22 = 182,
+ KEY_WORLD_23 = 183,
+ KEY_WORLD_24 = 184,
+ KEY_WORLD_25 = 185,
+ KEY_WORLD_26 = 186,
+ KEY_WORLD_27 = 187,
+ KEY_WORLD_28 = 188,
+ KEY_WORLD_29 = 189,
+ KEY_WORLD_30 = 190,
+ KEY_WORLD_31 = 191,
+ KEY_WORLD_32 = 192,
+ KEY_WORLD_33 = 193,
+ KEY_WORLD_34 = 194,
+ KEY_WORLD_35 = 195,
+ KEY_WORLD_36 = 196,
+ KEY_WORLD_37 = 197,
+ KEY_WORLD_38 = 198,
+ KEY_WORLD_39 = 199,
+ KEY_WORLD_40 = 200,
+ KEY_WORLD_41 = 201,
+ KEY_WORLD_42 = 202,
+ KEY_WORLD_43 = 203,
+ KEY_WORLD_44 = 204,
+ KEY_WORLD_45 = 205,
+ KEY_WORLD_46 = 206,
+ KEY_WORLD_47 = 207,
+ KEY_WORLD_48 = 208,
+ KEY_WORLD_49 = 209,
+ KEY_WORLD_50 = 210,
+ KEY_WORLD_51 = 211,
+ KEY_WORLD_52 = 212,
+ KEY_WORLD_53 = 213,
+ KEY_WORLD_54 = 214,
+ KEY_WORLD_55 = 215,
+ KEY_WORLD_56 = 216,
+ KEY_WORLD_57 = 217,
+ KEY_WORLD_58 = 218,
+ KEY_WORLD_59 = 219,
+ KEY_WORLD_60 = 220,
+ KEY_WORLD_61 = 221,
+ KEY_WORLD_62 = 222,
+ KEY_WORLD_63 = 223,
+ KEY_WORLD_64 = 224,
+ KEY_WORLD_65 = 225,
+ KEY_WORLD_66 = 226,
+ KEY_WORLD_67 = 227,
+ KEY_WORLD_68 = 228,
+ KEY_WORLD_69 = 229,
+ KEY_WORLD_70 = 230,
+ KEY_WORLD_71 = 231,
+ KEY_WORLD_72 = 232,
+ KEY_WORLD_73 = 233,
+ KEY_WORLD_74 = 234,
+ KEY_WORLD_75 = 235,
+ KEY_WORLD_76 = 236,
+ KEY_WORLD_77 = 237,
+ KEY_WORLD_78 = 238,
+ KEY_WORLD_79 = 239,
+ KEY_WORLD_80 = 240,
+ KEY_WORLD_81 = 241,
+ KEY_WORLD_82 = 242,
+ KEY_WORLD_83 = 243,
+ KEY_WORLD_84 = 244,
+ KEY_WORLD_85 = 245,
+ KEY_WORLD_86 = 246,
+ KEY_WORLD_87 = 247,
+ KEY_WORLD_88 = 248,
+ KEY_WORLD_89 = 249,
+ KEY_WORLD_90 = 250,
+ KEY_WORLD_91 = 251,
+ KEY_WORLD_92 = 252,
+ KEY_WORLD_93 = 253,
+ KEY_WORLD_94 = 254,
+ KEY_WORLD_95 = 255,
+
+ /* Numeric keypad */
+ KEY_KP0 = 256,
+ KEY_KP1 = 257,
+ KEY_KP2 = 258,
+ KEY_KP3 = 259,
+ KEY_KP4 = 260,
+ KEY_KP5 = 261,
+ KEY_KP6 = 262,
+ KEY_KP7 = 263,
+ KEY_KP8 = 264,
+ KEY_KP9 = 265,
+ KEY_KP_PEROID = 266,
+ KEY_KP_DIVIDE = 267,
+ KEY_KP_MULTIPLY = 268,
+ KEY_KP_MINUS = 269,
+ KEY_KP_PLUS = 270,
+ KEY_KP_ENTER = 271,
+ KEY_KP_EQUALS = 272,
+
+ /* Arrows + Home/End pad */
+ KEY_UP = 273,
+ KEY_DOWN = 274,
+ KEY_RIGHT = 275,
+ KEY_LEFT = 276,
+ KEY_INSERT = 277,
+ KEY_HOME = 278,
+ KEY_END = 279,
+ KEY_PAGEUP = 280,
+ KEY_PAGEDOWN = 281,
+
+ /* Function keys */
+ KEY_F1 = 282,
+ KEY_F2 = 283,
+ KEY_F3 = 284,
+ KEY_F4 = 285,
+ KEY_F5 = 286,
+ KEY_F6 = 287,
+ KEY_F7 = 288,
+ KEY_F8 = 289,
+ KEY_F9 = 290,
+ KEY_F10 = 291,
+ KEY_F11 = 292,
+ KEY_F12 = 293,
+ KEY_F13 = 294,
+ KEY_F14 = 295,
+ KEY_F15 = 296,
+
+ /* Key state modifier keys */
+ KEY_NUMLOCK = 300,
+ KEY_CAPSLOCK = 301,
+ KEY_SCROLLOCK = 302,
+ KEY_RSHIFT = 303,
+ KEY_LSHIFT = 304,
+ KEY_RCTRL = 305,
+ KEY_LCTRL = 306,
+ KEY_RALT = 307,
+ KEY_LALT = 308,
+ KEY_RMETA = 309,
+ KEY_LMETA = 310,
+ KEY_LSUPER = 311, ///< Left "Windows" key
+ KEY_RSUPER = 312, ///< Right "Windows" key
+ KEY_MODE = 313, ///< "Alt Gr" key
+ KEY_COMPOSE = 314, ///< Multi-key compose key
+
+ /* Miscellaneous function keys */
+ KEY_HELP = 315,
+ KEY_PRINT = 316,
+ KEY_SYSREQ = 317,
+ KEY_BREAK = 318,
+ KEY_MENU = 319,
+ KEY_POWER = 320, ///< Power Macintosh power key
+ KEY_EURO = 321, ///< Some european keyboards
+ KEY_UNDO = 322, ///< Atari keyboard has Undo
+
+ KEY_LAST
+};
+
+enum EE_KEY_MOD {
+ KEYMOD_NONE = 0x0000,
+ KEYMOD_LSHIFT = 0x0001,
+ KEYMOD_RSHIFT = 0x0002,
+ KEYMOD_LCTRL = 0x0040,
+ KEYMOD_RCTRL = 0x0080,
+ KEYMOD_LALT = 0x0100,
+ KEYMOD_RALT = 0x0200,
+ KEYMOD_LMETA = 0x0400,
+ KEYMOD_RMETA = 0x0800,
+ KEYMOD_NUM = 0x1000,
+ KEYMOD_CAPS = 0x2000,
+ KEYMOD_MODE = 0x4000,
+ KEYMOD_RESERVED = 0x8000
+};
+
+#define KEYMOD_CTRL ( KEYMOD_LCTRL | KEYMOD_RCTRL )
+#define KEYMOD_SHIFT ( KEYMOD_LSHIFT | KEYMOD_RSHIFT )
+#define KEYMOD_ALT ( KEYMOD_LALT | KEYMOD_RALT )
+#define KEYMOD_META ( KEYMOD_LMETA | KEYMOD_RMETA )
+
+enum EE_BUTTON {
+ EE_BUTTON_LEFT = 1,
+ EE_BUTTON_MIDDLE = 2,
+ EE_BUTTON_RIGHT = 3,
+ EE_BUTTON_WHEELUP = 4,
+ EE_BUTTON_WHEELDOWN = 5,
+ EE_BUTTON_X1 = 6,
+ EE_BUTTON_X2 = 7
+};
+
+#define EE_BUTTON_MASK(X) ( 1 << ( ( X ) - 1 ) )
+
+enum EE_BUTTON_MASKS {
+ EE_BUTTON_LMASK = EE_BUTTON_MASK( EE_BUTTON_LEFT ),
+ EE_BUTTON_MMASK = EE_BUTTON_MASK( EE_BUTTON_MIDDLE ),
+ EE_BUTTON_RMASK = EE_BUTTON_MASK( EE_BUTTON_RIGHT ),
+ EE_BUTTON_X1MASK = EE_BUTTON_MASK( EE_BUTTON_X1 ),
+ EE_BUTTON_X2MASK = EE_BUTTON_MASK( EE_BUTTON_X2 ),
+ EE_BUTTON_WUMASK = EE_BUTTON_MASK( EE_BUTTON_WHEELUP ),
+ EE_BUTTON_WDMASK = EE_BUTTON_MASK( EE_BUTTON_WHEELDOWN ),
+ EE_BUTTONS_LRM = ( EE_BUTTON_MASK(EE_BUTTON_LEFT) | EE_BUTTON_MASK(EE_BUTTON_MIDDLE) | EE_BUTTON_MASK(EE_BUTTON_RIGHT) ),
+ EE_BUTTONS_WUWD = ( EE_BUTTON_MASK(EE_BUTTON_WHEELUP) | EE_BUTTON_MASK(EE_BUTTON_WHEELDOWN) ),
+ EE_BUTTONS_ALL = 0xFFFFFFFF
+};
+
+}}
+
+#endif