diff --git a/include/eepp/ee.hpp b/include/eepp/ee.hpp index cda6d7d51..a58dbe547 100755 --- a/include/eepp/ee.hpp +++ b/include/eepp/ee.hpp @@ -24,8 +24,7 @@ /** @TODO Add PVRTC and ETC support. @TODO Check for endianness problems, and make EEPP endianness agnostic. - @TODO Support for Android ( work in progress, it's working ) and iOS. - @TODO Add Scripting support ( squirrel or angel script ). + @TODO Add Scripting support ( squirrel or angel script or lua ). */ // General includes and declarations diff --git a/include/eepp/gaming/cmap.hpp b/include/eepp/gaming/cmap.hpp index 209088898..ceb302dc8 100644 --- a/include/eepp/gaming/cmap.hpp +++ b/include/eepp/gaming/cmap.hpp @@ -13,6 +13,9 @@ #include using namespace EE::Window; +#include +using namespace EE::Graphics; + namespace EE { namespace Gaming { #define EE_MAP_LAYER_UNKNOWN 0xFFFFFFFF diff --git a/include/eepp/graphics.hpp b/include/eepp/graphics.hpp index 1ef9a3ae5..964510b6d 100644 --- a/include/eepp/graphics.hpp +++ b/include/eepp/graphics.hpp @@ -1,8 +1,8 @@ #ifndef EEPP_GRAPHICS_HPP #define EEPP_GRAPHICS_HPP -#include #include +#include #include #include #include diff --git a/include/eepp/graphics/cconsole.hpp b/include/eepp/graphics/cconsole.hpp index 1387e7291..7185aa9b8 100755 --- a/include/eepp/graphics/cconsole.hpp +++ b/include/eepp/graphics/cconsole.hpp @@ -2,12 +2,13 @@ #define EE_GRAPHICSCCONSOLE_H #include -#include #include #include #include #include +namespace EE { namespace Window { class cWindow; class cInputTextBuffer; class InputEvent; } } + using namespace EE::Window; namespace EE { namespace Graphics { @@ -148,7 +149,7 @@ class EE_API cConsole{ Uint32 mMaxLogLines; eeInt mLastLogPos; - cInputTextBuffer mTBuf; + cInputTextBuffer * mTBuf; cFont * mFont; diff --git a/include/eepp/system/cmutex.hpp b/include/eepp/system/cmutex.hpp index e6dff7111..62b7d9791 100755 --- a/include/eepp/system/cmutex.hpp +++ b/include/eepp/system/cmutex.hpp @@ -19,6 +19,9 @@ class EE_API cMutex { /** Unlock the mutex */ void Unlock(); + + /** Tries to lock de mutex */ + int TryLock(); private: Platform::cMutexImpl * mMutexImpl; }; diff --git a/include/eepp/window/base.hpp b/include/eepp/window/base.hpp index 0e9646ae2..b190968f7 100644 --- a/include/eepp/window/base.hpp +++ b/include/eepp/window/base.hpp @@ -18,62 +18,8 @@ using namespace EE::System; #include using namespace EE::Graphics; -#if EE_PLATFORM == EE_PLATFORM_WIN - #ifndef WIN32_LEAN_AND_MEAN - #define WIN32_LEAN_AND_MEAN - #endif - #include - #undef GetDiskFreeSpace - - inline BOOL WIN_ShowWindow( HWND hWnd, int nCmdShow ) { - return ShowWindow( hWnd, nCmdShow ); - } - - typedef UINT eeScrapType; - typedef HWND eeWindowHandler; - - #ifdef CreateWindow - #undef CreateWindow - #endif -#elif defined( EE_X11_PLATFORM ) - #include - #include - #include - #include - typedef Atom eeScrapType; - typedef Window X11Window; - typedef Display * eeWindowHandler; - typedef Cursor X11Cursor; - #undef Window - #undef Display - #undef Cursor -#elif EE_PLATFORM == EE_PLATFORM_MACOSX - typedef unsigned int eeScrapType; - typedef void * eeWindowHandler; // NSWindow * -#else - typedef unsigned int eeWindowHandler; //! Fallback - typedef unsigned int eeScrapType; -#endif - -#ifdef EE_GLEW_AVAILABLE - #if EE_PLATFORM == EE_PLATFORM_WIN - #include - typedef HGLRC eeWindowContex; - - #elif defined( EE_X11_PLATFORM ) - - #include - typedef GLXContext eeWindowContex; - - #elif EE_PLATFORM == EE_PLATFORM_MACOSX - #include - - typedef AGLContext eeWindowContex; - #endif -#else - typedef unsigned int eeWindowContex; //! Fallback -#endif - +#include +#include #include #endif diff --git a/include/eepp/window/cwindow.hpp b/include/eepp/window/cwindow.hpp index 9c254e616..16722a896 100644 --- a/include/eepp/window/cwindow.hpp +++ b/include/eepp/window/cwindow.hpp @@ -3,10 +3,11 @@ #include #include -#include namespace EE { namespace Window { +namespace Platform { class cPlatformImpl; } + class cClipboard; class cInput; class cCursorManager; @@ -191,7 +192,7 @@ class EE_API cWindow { virtual eeWindowContex GetContext() const; /** @return The window handler */ - virtual eeWindowHandler GetWindowHandler() = 0; + virtual eeWindowHandle GetWindowHandler() = 0; /** Clear the current window This function is usually called once every frame, to clear the previous frame content. diff --git a/include/eepp/window/windowcontext.hpp b/include/eepp/window/windowcontext.hpp new file mode 100644 index 000000000..3ee778efe --- /dev/null +++ b/include/eepp/window/windowcontext.hpp @@ -0,0 +1,29 @@ +#ifndef EE_WINDOWCONTEXT_HPP +#define EE_WINDOWCONTEXT_HPP + +#include + +#ifdef EE_GLEW_AVAILABLE + #if EE_PLATFORM == EE_PLATFORM_WIN + + typedef void * eeWindowContex; + + #elif defined( EE_X11_PLATFORM ) + + #include + #undef Window + #undef Display + #undef Cursor + typedef GLXContext eeWindowContex; + + #elif EE_PLATFORM == EE_PLATFORM_MACOSX + + #include + typedef AGLContext eeWindowContex; + + #endif +#else + typedef unsigned int eeWindowContex; //! Fallback +#endif + +#endif diff --git a/include/eepp/window/windowhandle.hpp b/include/eepp/window/windowhandle.hpp new file mode 100644 index 000000000..925ea1721 --- /dev/null +++ b/include/eepp/window/windowhandle.hpp @@ -0,0 +1,33 @@ +#ifndef EE_WINDOWHANDLE_HPP +#define EE_WINDOWHANDLE_HPP + +#include + +#if EE_PLATFORM == EE_PLATFORM_WIN + + struct HWND__; + typedef HWND__* eeWindowHandle; + +#elif defined( EE_X11_PLATFORM ) + #include + #include + #include + #undef Window + #undef Display + #undef Cursor + + typedef unsigned long X11Window; + typedef unsigned long X11Cursor; + + typedef Display * eeWindowHandle; + + +#elif EE_PLATFORM == EE_PLATFORM_MACOSX + typedef void * eeWindowHandle; // NSWindow * +#else + typedef unsigned int eeWindowHandle; //! Fallback +#endif + + +#endif + diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 9d6221348..ff1a7a3eb 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -57,7 +57,7 @@ false - -j4 -e DEBUGBUILD=yes SHARED_BACKEND=yes BACKENDS_ALL=yes test + -j4 -e DEBUGBUILD=yes BACKEND_SDL=yes test make true diff --git a/src/eepp/graphics/cconsole.cpp b/src/eepp/graphics/cconsole.cpp index 135e61aae..55e16db84 100755 --- a/src/eepp/graphics/cconsole.cpp +++ b/src/eepp/graphics/cconsole.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,7 @@ cConsole::cConsole( Window::cWindow * window ) : mVidCb(0), mMaxLogLines(1024), mLastLogPos(0), + mTBuf( eeNew( cInputTextBuffer, () ) ), mFont(NULL), mTexId(0), mCurAlpha(0), @@ -57,6 +59,8 @@ cConsole::~cConsole() { mWindow->GetInput()->PopCallback( mMyCallback ); mWindow->PopResizeCallback( mVidCb ); } + + eeSAFE_DELETE( mTBuf ); } void cConsole::Create( cFont* Font, const bool& MakeDefaultCommands, const eeUint& MaxLogLines, const Uint32& TextureId ) { @@ -93,10 +97,10 @@ void cConsole::Create( cFont* Font, const bool& MakeDefaultCommands, const eeUin mVidCb = mWindow->PushResizeCallback( cb::Make0( this, &cConsole::PrivVideoResize ) ); } - mTBuf.SetReturnCallback( cb::Make0( this, &cConsole::ProcessLine ) ); - mTBuf.Start(); - mTBuf.SupportNewLine( false ); - mTBuf.Active( false ); + mTBuf->SetReturnCallback( cb::Make0( this, &cConsole::ProcessLine ) ); + mTBuf->Start(); + mTBuf->SupportNewLine( false ); + mTBuf->Active( false ); IgnoreCharOnPrompt( KEY_TAB ); mCon.ConModif = 0; @@ -159,17 +163,17 @@ void cConsole::Draw() { CurY = mTempY + mY + mCurHeight - mFontSize - 1; mFont->Color( eeColorA ( mFontLineColor.R(), mFontLineColor.G(), mFontLineColor.B(), static_cast(mA) ) ); - mFont->SetText( "> " + mTBuf.Buffer() ); + mFont->SetText( "> " + mTBuf->Buffer() ); mFont->Draw( mFontSize, CurY ); mFont->Color( eeColorA ( mFontLineColor.R(), mFontLineColor.G(), mFontLineColor.B(), static_cast(mCurAlpha) ) ); mFont->Color( OldColor ); - if ( (eeUint)mTBuf.CurPos() == mTBuf.Buffer().size() ) { + if ( (eeUint)mTBuf->CurPos() == mTBuf->Buffer().size() ) { mFont->Draw( "_", mFontSize + mFont->GetTextWidth() , CurY ); } else { - mFont->SetText( "> " + mTBuf.Buffer().substr( 0, mTBuf.CurPos() ) ); + mFont->SetText( "> " + mTBuf->Buffer().substr( 0, mTBuf->CurPos() ) ); mFont->Draw( "_", mFontSize + mFont->GetTextWidth() , CurY ); } } @@ -190,7 +194,7 @@ void cConsole::FadeIn() { mFadeIn = true; mVisible = true; mY = 0.0f; - mTBuf.Active( true ); + mTBuf->Active( true ); } } @@ -199,12 +203,12 @@ void cConsole::FadeOut() { mFading = true; mFadeOut = true; mVisible = false; - mTBuf.Active( false ); + mTBuf->Active( false ); } } void cConsole::ProcessLine() { - String str = mTBuf.Buffer(); + String str = mTBuf->Buffer(); std::vector < String > params = String::SplitString( str, ' ' ); mLastCommands.push_back( str ); @@ -222,7 +226,7 @@ void cConsole::ProcessLine() { PushText( "Unknown Command: '" + params[0] + "'" ); } } - mTBuf.Clear(); + mTBuf->Clear(); } void cConsole::PrivPushText( const String& str ) { @@ -332,7 +336,7 @@ void cConsole::PrintCommandsStartingWith( const String& start ) { } if ( cmds.size() > 1 ) { - PushText( "> " + mTBuf.Buffer() ); + PushText( "> " + mTBuf->Buffer() ); std::list::iterator ite; @@ -340,8 +344,8 @@ void cConsole::PrintCommandsStartingWith( const String& start ) { PushText( (*ite) ); } else if ( cmds.size() ) { - mTBuf.Buffer( cmds.front() ); - mTBuf.CursorToEnd(); + mTBuf->Buffer( cmds.front() ); + mTBuf->CursorToEnd(); } } @@ -367,8 +371,8 @@ void cConsole::PrivInputCallback( InputEvent * Event ) { Uint32 Button = Event->button.button; if ( InputEvent::KeyDown == etype ) { - if ( ( KeyCode == KEY_TAB ) && (eeUint)mTBuf.CurPos() == mTBuf.Buffer().size() ) { - PrintCommandsStartingWith( mTBuf.Buffer() ); + if ( ( KeyCode == KEY_TAB ) && (eeUint)mTBuf->CurPos() == mTBuf->Buffer().size() ) { + PrintCommandsStartingWith( mTBuf->Buffer() ); } if ( mLastCommands.size() > 0 ) { @@ -382,10 +386,10 @@ void cConsole::PrivInputCallback( InputEvent * Event ) { if ( KeyCode == KEY_UP || KeyCode == KEY_DOWN ) { if ( mLastLogPos == static_cast( mLastCommands.size() ) ) { - mTBuf.Buffer( "" ); + mTBuf->Buffer( "" ); } else { - mTBuf.Buffer( mLastCommands[mLastLogPos] ); - mTBuf.CursorToEnd(); + mTBuf->Buffer( mLastCommands[mLastLogPos] ); + mTBuf->CursorToEnd(); } } } @@ -661,7 +665,7 @@ void cConsole::CmdShowFps( const std::vector < String >& params ) { } void cConsole::IgnoreCharOnPrompt( const Uint32& ch ) { - mTBuf.PushIgnoredChar( ch ); + mTBuf->PushIgnoredChar( ch ); } const bool& cConsole::IsShowingFps() const { diff --git a/src/eepp/graphics/cframebufferpbuffer.cpp b/src/eepp/graphics/cframebufferpbuffer.cpp index c8fd9cf8b..d840e2646 100644 --- a/src/eepp/graphics/cframebufferpbuffer.cpp +++ b/src/eepp/graphics/cframebufferpbuffer.cpp @@ -64,21 +64,21 @@ cFrameBufferPBuffer::~cFrameBufferPBuffer() { #if EE_PLATFORM == EE_PLATFORM_WIN if ( mContext ) - wglDeleteContext( mContext ); + wglDeleteContext( (HGLRC)mContext ); if ( mPBuffer && mDeviceContext ) { - wglReleasePbufferDCARB( mPBuffer, mDeviceContext ); - wglDestroyPbufferARB( mPBuffer ); + wglReleasePbufferDCARB( (HPBUFFERARB)mPBuffer, (HDC)mDeviceContext ); + wglDestroyPbufferARB( (HPBUFFERARB)mPBuffer ); } #elif defined( EE_X11_PLATFORM ) if ( mContext ) - glXDestroyContext( mDisplay, mContext ); + glXDestroyContext( (Display*)mDisplay, (GLXContext)mContext ); if ( mPBuffer ) - glXDestroyGLXPbufferSGIX( mDisplay, mPBuffer ); + glXDestroyGLXPbufferSGIX( (Display*)mDisplay, mPBuffer ); if ( mDisplay ) - XCloseDisplay( mDisplay ); + XCloseDisplay( (Display*)mDisplay ); #endif #endif @@ -145,15 +145,15 @@ bool cFrameBufferPBuffer::Create( const Uint32& Width, const Uint32& Height, boo return false; mPBuffer = wglCreatePbufferARB( currentDC, pixelFormat, Width, Height, NULL ); - mDeviceContext = wglGetPbufferDCARB( mPBuffer ); - mContext = wglCreateContext( mDeviceContext ); + mDeviceContext = wglGetPbufferDCARB( (HPBUFFERARB)mPBuffer ); + mContext = wglCreateContext( (HDC)mDeviceContext ); if ( !mPBuffer || !mDeviceContext || !mContext ) return false; int actualWidth, actualHeight; - wglQueryPbufferARB( mPBuffer, WGL_PBUFFER_WIDTH_ARB, &actualWidth ); - wglQueryPbufferARB( mPBuffer, WGL_PBUFFER_HEIGHT_ARB, &actualHeight ); + wglQueryPbufferARB( (HPBUFFERARB)mPBuffer, WGL_PBUFFER_WIDTH_ARB, &actualWidth ); + wglQueryPbufferARB( (HPBUFFERARB)mPBuffer, WGL_PBUFFER_HEIGHT_ARB, &actualHeight ); if ( ( actualWidth != static_cast(Width) ) || ( actualHeight != static_cast(Height) ) ) return false; @@ -161,7 +161,7 @@ bool cFrameBufferPBuffer::Create( const Uint32& Width, const Uint32& Height, boo HGLRC currentContext = wglGetCurrentContext(); if (currentContext) { wglMakeCurrent( NULL, NULL ); - wglShareLists( currentContext, mContext ); + wglShareLists( currentContext, (HGLRC)mContext ); wglMakeCurrent( currentDC, currentContext ); } #elif defined( EE_X11_PLATFORM ) @@ -185,12 +185,12 @@ bool cFrameBufferPBuffer::Create( const Uint32& Width, const Uint32& Height, boo }; int nbConfigs = 0; - GLXFBConfig* configs = glXChooseFBConfigSGIX( mDisplay, DefaultScreen( mDisplay ), visualAttributes, &nbConfigs ); + GLXFBConfig* configs = glXChooseFBConfigSGIX( (Display*)mDisplay, DefaultScreen( (Display*)mDisplay ), visualAttributes, &nbConfigs ); if (!configs || !nbConfigs) return false; - mPBuffer = glXCreateGLXPbufferSGIX( mDisplay, configs[0], Width, Height, PBufferAttributes ); + mPBuffer = glXCreateGLXPbufferSGIX( (Display*)mDisplay, configs[0], Width, Height, PBufferAttributes ); if ( !mPBuffer ) { XFree(configs); @@ -198,8 +198,8 @@ bool cFrameBufferPBuffer::Create( const Uint32& Width, const Uint32& Height, boo } unsigned int actualWidth, actualHeight; - glXQueryGLXPbufferSGIX( mDisplay, mPBuffer, GLX_WIDTH_SGIX, &actualWidth); - glXQueryGLXPbufferSGIX( mDisplay, mPBuffer, GLX_HEIGHT_SGIX, &actualHeight); + glXQueryGLXPbufferSGIX( (Display*)mDisplay, mPBuffer, GLX_WIDTH_SGIX, &actualWidth); + glXQueryGLXPbufferSGIX( (Display*)mDisplay, mPBuffer, GLX_HEIGHT_SGIX, &actualHeight); if ( ( actualWidth != Width ) || ( actualHeight != Height ) ) { XFree(configs); @@ -210,10 +210,10 @@ bool cFrameBufferPBuffer::Create( const Uint32& Width, const Uint32& Height, boo GLXContext currentContext = glXGetCurrentContext(); if ( currentContext ) - glXMakeCurrent( mDisplay, 0, NULL ); + glXMakeCurrent( (Display*)mDisplay, 0, NULL ); - XVisualInfo* visual = glXGetVisualFromFBConfig( mDisplay, configs[0] ); - mContext = glXCreateContext( mDisplay, visual, currentContext, true ); + XVisualInfo* visual = glXGetVisualFromFBConfig( (Display*)mDisplay, configs[0] ); + mContext = glXCreateContext( (Display*)mDisplay, visual, currentContext, true ); if ( !mContext ) { XFree(configs); @@ -222,7 +222,7 @@ bool cFrameBufferPBuffer::Create( const Uint32& Width, const Uint32& Height, boo } if ( currentContext ) - glXMakeCurrent( mDisplay, currentDrawable, currentContext ); + glXMakeCurrent( (Display*)mDisplay, currentDrawable, currentContext ); XFree(configs); XFree(visual); @@ -252,14 +252,14 @@ void cFrameBufferPBuffer::Bind() { if ( mDeviceContext && mContext ) { if ( wglGetCurrentContext() != mContext ) { ChangeContext = true; - wglMakeCurrent( mDeviceContext, mContext ); + wglMakeCurrent( (HDC)mDeviceContext, (HGLRC)mContext ); } } #elif defined( EE_X11_PLATFORM ) if ( mPBuffer && mContext ) { if ( glXGetCurrentContext() != mContext ) { ChangeContext = true; - glXMakeCurrent( mDisplay, mPBuffer, mContext ); + glXMakeCurrent( (Display*)mDisplay, mPBuffer, (GLXContext)mContext ); } } #endif diff --git a/src/eepp/graphics/cframebufferpbuffer.hpp b/src/eepp/graphics/cframebufferpbuffer.hpp index 952fd780a..89d348fce 100644 --- a/src/eepp/graphics/cframebufferpbuffer.hpp +++ b/src/eepp/graphics/cframebufferpbuffer.hpp @@ -54,13 +54,13 @@ class EE_API cFrameBufferPBuffer : public cFrameBuffer { #ifdef EE_GLEW_AVAILABLE #if EE_PLATFORM == EE_PLATFORM_WIN - HDC mDeviceContext; - HPBUFFERARB mPBuffer; - HGLRC mContext; + void * mDeviceContext; + void * mPBuffer; + void * mContext; #elif defined( EE_X11_PLATFORM ) - ::Display * mDisplay; - GLXPbuffer mPBuffer; - GLXContext mContext; + void * mDisplay; + unsigned long mPBuffer; + void * mContext; #endif #endif diff --git a/src/eepp/helper/haikuttf/hkbase.hpp b/src/eepp/helper/haikuttf/hkbase.hpp index 6197ddf14..1340629c2 100644 --- a/src/eepp/helper/haikuttf/hkbase.hpp +++ b/src/eepp/helper/haikuttf/hkbase.hpp @@ -39,15 +39,6 @@ typedef SOPHIST_uint32 u32; #define HK_PLATFORM_POSIX #endif -#if HK_PLATFORM == HK_PLATFORM_WIN -#ifndef WIN32_LEAN_AND_MEAN - #define WIN32_LEAN_AND_MEAN -#endif -#include -#elif defined( HK_PLATFORM_POSIX ) -#include -#endif - #include #include FT_FREETYPE_H #include FT_OUTLINE_H diff --git a/src/eepp/helper/haikuttf/hkmutex.cpp b/src/eepp/helper/haikuttf/hkmutex.cpp index 88706c4e2..6307b3d53 100644 --- a/src/eepp/helper/haikuttf/hkmutex.cpp +++ b/src/eepp/helper/haikuttf/hkmutex.cpp @@ -2,36 +2,75 @@ namespace HaikuTTF { -hkMutex::hkMutex() { - #if HK_PLATFORM == HK_PLATFORM_WIN - InitializeCriticalSection(&mMutex); - #elif defined( HK_PLATFORM_POSIX ) - pthread_mutex_init(&mMutex, NULL); - #endif +#if HK_PLATFORM == HK_PLATFORM_WIN + +#ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN +#endif +#include + +class hkMutexImpl { + public: + hkMutexImpl() { + InitializeCriticalSection(&mMutex); + } + + ~hkMutexImpl() { + DeleteCriticalSection(&mMutex); + } + + void Lock() { + EnterCriticalSection(&mMutex); + } + + void Unlock() { + LeaveCriticalSection(&mMutex); + } + protected: + CRITICAL_SECTION mMutex; +}; + +#elif defined( HK_PLATFORM_POSIX ) + +#include +class hkMutexImpl { + public: + hkMutexImpl() { + pthread_mutex_init(&mMutex, NULL); + } + + ~hkMutexImpl() { + pthread_mutex_destroy(&mMutex); + } + + void Lock() { + pthread_mutex_lock(&mMutex); + } + + void Unlock() { + pthread_mutex_unlock(&mMutex); + } + protected: + pthread_mutex_t mMutex; +}; + +#endif + +hkMutex::hkMutex() : + mImpl( hkNew( hkMutexImpl, () ) ) +{ } hkMutex::~hkMutex() { - #if HK_PLATFORM == HK_PLATFORM_WIN - DeleteCriticalSection(&mMutex); - #elif defined( HK_PLATFORM_POSIX ) - pthread_mutex_destroy(&mMutex); - #endif + hkSAFE_DELETE( mImpl ) } void hkMutex::Lock() { - #if HK_PLATFORM == HK_PLATFORM_WIN - EnterCriticalSection(&mMutex); - #elif defined( HK_PLATFORM_POSIX ) - pthread_mutex_lock(&mMutex); - #endif + mImpl->Lock(); } void hkMutex::Unlock() { - #if HK_PLATFORM == HK_PLATFORM_WIN - LeaveCriticalSection(&mMutex); - #elif defined( HK_PLATFORM_POSIX ) - pthread_mutex_unlock(&mMutex); - #endif + mImpl->Unlock(); } } diff --git a/src/eepp/helper/haikuttf/hkmutex.hpp b/src/eepp/helper/haikuttf/hkmutex.hpp index 97e440eaa..ad924863f 100644 --- a/src/eepp/helper/haikuttf/hkmutex.hpp +++ b/src/eepp/helper/haikuttf/hkmutex.hpp @@ -5,6 +5,8 @@ namespace HaikuTTF { +class hkMutexImpl; + class hkMutex { public: hkMutex(); @@ -15,11 +17,7 @@ class hkMutex { void Unlock(); protected: - #if HK_PLATFORM == HK_PLATFORM_WIN - CRITICAL_SECTION mMutex; - #elif defined( HK_PLATFORM_POSIX ) - pthread_mutex_t mMutex; - #endif + hkMutexImpl * mImpl; }; } diff --git a/src/eepp/system/clog.cpp b/src/eepp/system/clog.cpp index 900759939..d9c2a49e9 100755 --- a/src/eepp/system/clog.cpp +++ b/src/eepp/system/clog.cpp @@ -90,7 +90,7 @@ void cLog::openfs() { std::string str = mFilePath + "log.log"; mFS = eeNew( cIOStreamFile, ( str, std::ios::app | std::ios::out | std::ios::binary ) ); - } + } } void cLog::closefs() { @@ -173,7 +173,7 @@ const bool& cLog::LiveWrite() const { } void cLog::LiveWrite( const bool& lw ) { - mLiveWrite = lw; + mLiveWrite = lw; } }} diff --git a/src/eepp/system/cmutex.cpp b/src/eepp/system/cmutex.cpp index 48e6e3685..251376acf 100755 --- a/src/eepp/system/cmutex.cpp +++ b/src/eepp/system/cmutex.cpp @@ -20,4 +20,8 @@ void cMutex::Unlock() { mMutexImpl->Unlock(); } +int cMutex::TryLock() { + return mMutexImpl->TryLock(); +} + }} diff --git a/src/eepp/system/platform/posix/cmuteximpl.cpp b/src/eepp/system/platform/posix/cmuteximpl.cpp index 465764cbd..d11dd374c 100644 --- a/src/eepp/system/platform/posix/cmuteximpl.cpp +++ b/src/eepp/system/platform/posix/cmuteximpl.cpp @@ -23,6 +23,10 @@ void cMutexImpl::Unlock() { pthread_mutex_unlock(&mMutex); } +int cMutexImpl::TryLock() { + return pthread_mutex_trylock(&mMutex); +} + }}} #endif diff --git a/src/eepp/system/platform/posix/cmuteximpl.hpp b/src/eepp/system/platform/posix/cmuteximpl.hpp index 1aee23938..72c55d8cf 100644 --- a/src/eepp/system/platform/posix/cmuteximpl.hpp +++ b/src/eepp/system/platform/posix/cmuteximpl.hpp @@ -18,6 +18,8 @@ class cMutexImpl { void Lock(); void Unlock(); + + int TryLock(); private: pthread_mutex_t mMutex; }; @@ -27,4 +29,4 @@ class cMutexImpl { #endif #endif - \ No newline at end of file + diff --git a/src/eepp/system/platform/win/cmuteximpl.cpp b/src/eepp/system/platform/win/cmuteximpl.cpp index 443b2a75c..711013c37 100644 --- a/src/eepp/system/platform/win/cmuteximpl.cpp +++ b/src/eepp/system/platform/win/cmuteximpl.cpp @@ -20,6 +20,10 @@ void cMutexImpl::Unlock() { LeaveCriticalSection(&mMutex); } +int cMutexImpl::TryLock() { + return TryEnterCriticalSection(&mMutex); +} + }}} #endif diff --git a/src/eepp/system/platform/win/cmuteximpl.hpp b/src/eepp/system/platform/win/cmuteximpl.hpp index e49d1b7ff..24198e75a 100644 --- a/src/eepp/system/platform/win/cmuteximpl.hpp +++ b/src/eepp/system/platform/win/cmuteximpl.hpp @@ -21,6 +21,8 @@ class cMutexImpl { void Lock(); void Unlock(); + + int TryLock(); private: CRITICAL_SECTION mMutex; }; diff --git a/src/eepp/window/backend/SDL/cclipboardsdl.cpp b/src/eepp/window/backend/SDL/cclipboardsdl.cpp index abeb37662..af3066f96 100644 --- a/src/eepp/window/backend/SDL/cclipboardsdl.cpp +++ b/src/eepp/window/backend/SDL/cclipboardsdl.cpp @@ -6,6 +6,20 @@ #include #include +#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) + #include +#endif + +#if EE_PLATFORM == EE_PLATFORM_WIN + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + #include +#elif defined( EE_X11_PLATFORM ) + #include + #include +#endif + namespace EE { namespace Window { namespace Backend { namespace SDL { #define T(A, B, C, D) (int)((A<<24)|(B<<16)|(C<<8)|(D<<0)) @@ -103,7 +117,7 @@ void cClipboardSDL::Init() { void cClipboardSDL::SetText( const std::string& Text ) { #if defined( EE_X11_PLATFORM ) - eeWindowHandler display = mInfo->info.x11.display; + eeWindowHandle display = mInfo->info.x11.display; X11Window window = mInfo->info.x11.wmwindow; Atom format = TEXT_FORMAT; diff --git a/src/eepp/window/backend/SDL/cclipboardsdl.hpp b/src/eepp/window/backend/SDL/cclipboardsdl.hpp index ddb66d9bd..e5ca38c53 100644 --- a/src/eepp/window/backend/SDL/cclipboardsdl.hpp +++ b/src/eepp/window/backend/SDL/cclipboardsdl.hpp @@ -10,12 +10,18 @@ class SDL_SysWMinfo; -#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || defined( EE_X11_PLATFORM ) - #include -#endif - namespace EE { namespace Window { namespace Backend { namespace SDL { +#if EE_PLATFORM == EE_PLATFORM_WIN + typedef unsigned int eeScrapType; +#elif defined( EE_X11_PLATFORM ) + typedef unsigned long eeScrapType; +#elif EE_PLATFORM == EE_PLATFORM_MACOSX + typedef unsigned int eeScrapType; +#else + typedef unsigned int eeScrapType; +#endif + class EE_API cClipboardSDL : public cClipboard { public: virtual ~cClipboardSDL(); @@ -38,7 +44,7 @@ class EE_API cClipboardSDL : public cClipboard { void * mInfo; #endif - eeScrapType clipboard_convert_format(int type); + eeScrapType clipboard_convert_format( int type ); int clipboard_convert_scrap(int type, char *dst, char *src, int srclen); diff --git a/src/eepp/window/backend/SDL/ccursormanagersdl.cpp b/src/eepp/window/backend/SDL/ccursormanagersdl.cpp index c50361165..fe8835555 100644 --- a/src/eepp/window/backend/SDL/ccursormanagersdl.cpp +++ b/src/eepp/window/backend/SDL/ccursormanagersdl.cpp @@ -3,6 +3,7 @@ #ifdef EE_BACKEND_SDL_1_2 +#include #include namespace EE { namespace Window { namespace Backend { namespace SDL { diff --git a/src/eepp/window/backend/SDL/cwindowsdl.cpp b/src/eepp/window/backend/SDL/cwindowsdl.cpp index 9d5ce9bc3..bb658beab 100644 --- a/src/eepp/window/backend/SDL/cwindowsdl.cpp +++ b/src/eepp/window/backend/SDL/cwindowsdl.cpp @@ -27,13 +27,13 @@ namespace EE { namespace Window { namespace Backend { namespace SDL { cWindowSDL::cWindowSDL( WindowSettings Settings, ContextSettings Context ) : cWindow( Settings, Context, eeNew( cClipboardSDL, ( this ) ), eeNew( cInputSDL, ( this ) ), eeNew( cCursorManagerSDL, ( this ) ) ), mSurface( NULL ), - mWMinfo( (SDL_SysWMinfo*)eeMalloc( sizeof( mWMinfo ) ) ) + mWMinfo( eeNew( SDL_SysWMinfo, () ) ) { Create( Settings, Context ); } cWindowSDL::~cWindowSDL() { - eeSAFE_FREE( mWMinfo ); + eeSAFE_DELETE( mWMinfo ); } bool cWindowSDL::Create( WindowSettings Settings, ContextSettings Context ) { @@ -382,7 +382,7 @@ void cWindowSDL::SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ) { SDL_SetGamma( Red, Green, Blue ); } -eeWindowHandler cWindowSDL::GetWindowHandler() { +eeWindowHandle cWindowSDL::GetWindowHandler() { #if EE_PLATFORM == EE_PLATFORM_WIN return mWMinfo->window; #elif defined( EE_X11_PLATFORM ) diff --git a/src/eepp/window/backend/SDL/cwindowsdl.hpp b/src/eepp/window/backend/SDL/cwindowsdl.hpp index 32204bc19..40c1768c8 100644 --- a/src/eepp/window/backend/SDL/cwindowsdl.hpp +++ b/src/eepp/window/backend/SDL/cwindowsdl.hpp @@ -37,7 +37,7 @@ class EE_API cWindowSDL : public cWindow { void SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ); - eeWindowHandler GetWindowHandler(); + eeWindowHandle GetWindowHandler(); protected: friend class cClipboardSDL; diff --git a/src/eepp/window/backend/SDL2/ccursormanagersdl2.cpp b/src/eepp/window/backend/SDL2/ccursormanagersdl2.cpp index 01186d8cb..7a1f38477 100644 --- a/src/eepp/window/backend/SDL2/ccursormanagersdl2.cpp +++ b/src/eepp/window/backend/SDL2/ccursormanagersdl2.cpp @@ -1,5 +1,6 @@ #include #include +#include #ifdef EE_BACKEND_SDL2 diff --git a/src/eepp/window/backend/SDL2/cwindowsdl2.cpp b/src/eepp/window/backend/SDL2/cwindowsdl2.cpp index 80305ee80..16633d6eb 100644 --- a/src/eepp/window/backend/SDL2/cwindowsdl2.cpp +++ b/src/eepp/window/backend/SDL2/cwindowsdl2.cpp @@ -380,7 +380,7 @@ void cWindowSDL::SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ) { SDL_SetWindowGammaRamp( mSDLWindow, red_ramp, green_ramp, blue_ramp ); } -eeWindowHandler cWindowSDL::GetWindowHandler() { +eeWindowHandle cWindowSDL::GetWindowHandler() { #if EE_PLATFORM == EE_PLATFORM_WIN return mWMinfo.info.win.window; #elif defined( EE_X11_PLATFORM ) diff --git a/src/eepp/window/backend/SDL2/cwindowsdl2.hpp b/src/eepp/window/backend/SDL2/cwindowsdl2.hpp index 72c653fa5..252ecd4f7 100644 --- a/src/eepp/window/backend/SDL2/cwindowsdl2.hpp +++ b/src/eepp/window/backend/SDL2/cwindowsdl2.hpp @@ -38,7 +38,7 @@ class EE_API cWindowSDL : public cWindow { void SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ); - eeWindowHandler GetWindowHandler(); + eeWindowHandle GetWindowHandler(); virtual void Minimize(); diff --git a/src/eepp/window/backend/SFML/ccursormanagersfml.cpp b/src/eepp/window/backend/SFML/ccursormanagersfml.cpp index 5b602b726..629041137 100644 --- a/src/eepp/window/backend/SFML/ccursormanagersfml.cpp +++ b/src/eepp/window/backend/SFML/ccursormanagersfml.cpp @@ -8,7 +8,7 @@ #undef None #endif #include - +#include namespace EE { namespace Window { namespace Backend { namespace SFML { diff --git a/src/eepp/window/backend/SFML/cwindowsfml.cpp b/src/eepp/window/backend/SFML/cwindowsfml.cpp index dbeb85233..9bdf5baa4 100644 --- a/src/eepp/window/backend/SFML/cwindowsfml.cpp +++ b/src/eepp/window/backend/SFML/cwindowsfml.cpp @@ -198,7 +198,7 @@ eeWindowContex cWindowSFML::GetContext() const { void cWindowSFML::GetMainContext() { } -eeWindowHandler cWindowSFML::GetWindowHandler() { +eeWindowHandle cWindowSFML::GetWindowHandler() { #if defined( EE_X11_PLATFORM ) if ( 0 == mWinHandler ) { #ifdef EE_SUPPORT_EXCEPTIONS @@ -214,9 +214,9 @@ eeWindowHandler cWindowSFML::GetWindowHandler() { return mWinHandler; #elif EE_PLATFORM == EE_PLATFORM_WIN - return (eeWindowHandler)mSFMLWindow.getSystemHandle(); + return (eeWindowHandle)mSFMLWindow.getSystemHandle(); #elif EE_PLATFORM == EE_PLATFORM_MACOSX - return (eeWindowHandler)mSFMLWindow.getSystemHandle(); + return (eeWindowHandle)mSFMLWindow.getSystemHandle(); #else return 0; #endif diff --git a/src/eepp/window/backend/SFML/cwindowsfml.hpp b/src/eepp/window/backend/SFML/cwindowsfml.hpp index 93d1f202b..355c31160 100644 --- a/src/eepp/window/backend/SFML/cwindowsfml.hpp +++ b/src/eepp/window/backend/SFML/cwindowsfml.hpp @@ -46,7 +46,7 @@ class EE_API cWindowSFML : public cWindow { eeWindowContex GetContext() const; - eeWindowHandler GetWindowHandler(); + eeWindowHandle GetWindowHandler(); void SetDefaultContext(); @@ -57,7 +57,7 @@ class EE_API cWindowSFML : public cWindow { sf::Window mSFMLWindow; - eeWindowHandler mWinHandler; + eeWindowHandle mWinHandler; bool mVisible; diff --git a/src/eepp/window/backend/allegro5/cclipboardal.cpp b/src/eepp/window/backend/allegro5/cclipboardal.cpp index 3bd2bf499..5d53c108c 100644 --- a/src/eepp/window/backend/allegro5/cclipboardal.cpp +++ b/src/eepp/window/backend/allegro5/cclipboardal.cpp @@ -28,7 +28,7 @@ String cClipboardAl::GetWideText() { /** Not sure if activate this, sometimes freeze the application because of the notification delay. */ /** cWindowAl * win = reinterpret_cast ( mWindow ); - eeWindowHandler mDisplay = win->GetWindowHandler(); + eeWindowHandle mDisplay = win->GetWindowHandler(); X11Window mWin = win->GetX11Window(); Atom clipboard = XInternAtom(mDisplay, "CLIPBOARD", True); diff --git a/src/eepp/window/backend/allegro5/cwindowal.cpp b/src/eepp/window/backend/allegro5/cwindowal.cpp index ffd65c36a..9203202de 100644 --- a/src/eepp/window/backend/allegro5/cwindowal.cpp +++ b/src/eepp/window/backend/allegro5/cwindowal.cpp @@ -388,7 +388,7 @@ std::vector< std::pair > cWindowAl::GetPossibleResol void cWindowAl::SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ) { } -eeWindowHandler cWindowAl::GetWindowHandler() { +eeWindowHandle cWindowAl::GetWindowHandler() { #if EE_PLATFORM == EE_PLATFORM_WIN return al_get_win_window_handle( mDisplay ); #elif defined( EE_X11_PLATFORM ) diff --git a/src/eepp/window/backend/allegro5/cwindowal.hpp b/src/eepp/window/backend/allegro5/cwindowal.hpp index 88c29ad9d..0de86b140 100644 --- a/src/eepp/window/backend/allegro5/cwindowal.hpp +++ b/src/eepp/window/backend/allegro5/cwindowal.hpp @@ -38,7 +38,7 @@ class EE_API cWindowAl : public cWindow { void SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ); - eeWindowHandler GetWindowHandler(); + eeWindowHandle GetWindowHandler(); #if defined( EE_X11_PLATFORM ) X11Window GetX11Window(); diff --git a/src/eepp/window/backend/null/cwindownull.cpp b/src/eepp/window/backend/null/cwindownull.cpp index 805035900..678b54702 100644 --- a/src/eepp/window/backend/null/cwindownull.cpp +++ b/src/eepp/window/backend/null/cwindownull.cpp @@ -82,7 +82,7 @@ eeWindowContex cWindowNull::GetContext() const { void cWindowNull::GetMainContext() { } -eeWindowHandler cWindowNull::GetWindowHandler() { +eeWindowHandle cWindowNull::GetWindowHandler() { return 0; } diff --git a/src/eepp/window/backend/null/cwindownull.hpp b/src/eepp/window/backend/null/cwindownull.hpp index a684a087f..f05d0f93d 100644 --- a/src/eepp/window/backend/null/cwindownull.hpp +++ b/src/eepp/window/backend/null/cwindownull.hpp @@ -47,7 +47,7 @@ class EE_API cWindowNull : public cWindow { eeWindowContex GetContext() const; - eeWindowHandler GetWindowHandler(); + eeWindowHandle GetWindowHandler(); void SetDefaultContext(); protected: diff --git a/src/eepp/window/cwindow.cpp b/src/eepp/window/cwindow.cpp index 7d53f5ac7..104d8df75 100644 --- a/src/eepp/window/cwindow.cpp +++ b/src/eepp/window/cwindow.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -12,6 +13,17 @@ #include +#ifdef EE_GLEW_AVAILABLE + #if EE_PLATFORM == EE_PLATFORM_WIN + #include + #undef GetDiskFreeSpace + #elif defined( EE_X11_PLATFORM ) + #include + #elif EE_PLATFORM == EE_PLATFORM_MACOSX + #include + #endif +#endif + #ifdef EE_GLES1_LATE_INCLUDE #if EE_PLATFORM == EE_PLATFORM_IOS #include diff --git a/src/eepp/window/platform/osx/cosximpl.hpp b/src/eepp/window/platform/osx/cosximpl.hpp index 903530198..2cd640f5e 100644 --- a/src/eepp/window/platform/osx/cosximpl.hpp +++ b/src/eepp/window/platform/osx/cosximpl.hpp @@ -2,10 +2,11 @@ #define EE_WINDOWCOSXIMPL_HPP #include -#include #if EE_PLATFORM == EE_PLATFORM_MACOSX +#include + namespace EE { namespace Window { namespace Platform { using namespace EE::Window; diff --git a/src/eepp/window/platform/win/ccursorwin.cpp b/src/eepp/window/platform/win/ccursorwin.cpp index 1051c3ca5..f627a08f0 100644 --- a/src/eepp/window/platform/win/ccursorwin.cpp +++ b/src/eepp/window/platform/win/ccursorwin.cpp @@ -1,215 +1,217 @@ #include #if EE_PLATFORM == EE_PLATFORM_WIN - -#include - -#define WINDOWS_RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) + +#include + +#include + +#define WINDOWS_RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) namespace EE { namespace Window { namespace Platform { cCursorWin::cCursorWin( cTexture * tex, const eeVector2i& hotspot, const std::string& name, cWindow * window ) : cCursor( tex, hotspot, name, window ) -{ +{ Create(); } cCursorWin::cCursorWin( cImage * img, const eeVector2i& hotspot, const std::string& name, cWindow * window ) : cCursor( img, hotspot, name, window ) -{ +{ Create(); } cCursorWin::cCursorWin( const std::string& path, const eeVector2i& hotspot, const std::string& name, cWindow * window ) : cCursor( path, hotspot, name, window ) -{ +{ Create(); -} - -cCursorWin::~cCursorWin() { - if ( NULL != mCursor ) - DestroyIcon( mCursor ); -} - -static BITMAPINFO *get_bitmap_info( cImage * bitmap ) { - BITMAPINFO *bi; - int i; - - bi = (BITMAPINFO *) eeMalloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 256); - - ZeroMemory(&bi->bmiHeader, sizeof(BITMAPINFOHEADER)); - - bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bi->bmiHeader.biBitCount = 32; - bi->bmiHeader.biPlanes = 1; - bi->bmiHeader.biWidth = (int)bitmap->Width(); - bi->bmiHeader.biHeight = -((int)bitmap->Height()); - bi->bmiHeader.biClrUsed = 256; - bi->bmiHeader.biCompression = BI_RGB; - - for (i = 0; i < 256; i++) { - bi->bmiColors[i].rgbRed = 0; - bi->bmiColors[i].rgbGreen = 0; - bi->bmiColors[i].rgbBlue = 0; - bi->bmiColors[i].rgbReserved = 0; - } - - return bi; -} - -static BYTE *get_dib_from_bitmap_32(cImage *bitmap) { - int w, h; - int x, y; - int pitch; - BYTE *pixels; - BYTE *dst; - - w = (int)bitmap->Width(); - h = (int)bitmap->Height(); - pitch = w * 4; - - pixels = (BYTE *) eeMalloc(h * pitch); - if (!pixels) - return NULL; - - for (y = 0; y < h; y++) { - dst = pixels + y * pitch; - - for (x = 0; x < w; x++) { - eeColorA C = bitmap->GetPixel( x, y ); - - /* BGR */ - dst[0] = C.B(); - dst[1] = C.G(); - dst[2] = C.R(); - dst[3] = C.A(); - - dst += 4; - } - } - - return pixels; -} - -static void local_stretch_blit_to_hdc( cImage *bitmap, HDC dc, int src_x, int src_y, int src_w, int src_h, int dest_x, int dest_y, int dest_w, int dest_h) { - const int bitmap_h = (const int)bitmap->Height(); - const int bottom_up_src_y = bitmap_h - src_y - src_h; - BYTE *pixels; - BITMAPINFO *bi; - - bi = get_bitmap_info(bitmap); - pixels = get_dib_from_bitmap_32(bitmap); - - /* Windows treats all source bitmaps as bottom-up when using StretchDIBits - * unless the source (x,y) is (0,0). To work around this buggy behavior, we - * can use negative heights to reverse the direction of the blits. - * - * See for a detailed explanation. - */ - if (bottom_up_src_y == 0 && src_x == 0 && src_h != bitmap_h) { - StretchDIBits( dc, dest_x, dest_h+dest_y-1, dest_w, -dest_h, src_x, bitmap_h - src_y + 1, src_w, -src_h, pixels, bi, DIB_RGB_COLORS, SRCCOPY ); - } - else { - StretchDIBits( dc, dest_x, dest_y, dest_w, dest_h, src_x, bottom_up_src_y, src_w, src_h, pixels, bi, DIB_RGB_COLORS, SRCCOPY ); - } - - eeFree(pixels); - eeFree(bi); -} - -static void local_draw_to_hdc( HDC dc, cImage * bitmap, int x, int y ) { - int w = bitmap->Width(); - int h = bitmap->Height(); - local_stretch_blit_to_hdc(bitmap, dc, 0, 0, w, h, x, y, w, h); -} - -void cCursorWin::Create() { - if ( NULL == mImage && mImage->Size() ) - return; - - int x, y; - int sys_sm_cx, sys_sm_cy; - HDC h_dc; - HDC h_and_dc; - HDC h_xor_dc; - ICONINFO iconinfo; - HBITMAP and_mask; - HBITMAP xor_mask; - HBITMAP hOldAndMaskBitmap; - HBITMAP hOldXorMaskBitmap; - HICON icon; - - /* Get allowed cursor size - Windows can't make cursors of arbitrary size */ - sys_sm_cx = GetSystemMetrics(SM_CXCURSOR); - sys_sm_cy = GetSystemMetrics(SM_CYCURSOR); - - if ( ( (int)mImage->Width() > sys_sm_cx ) || ( (int)mImage->Height() > sys_sm_cy ) ) { - return; - } - - /* Create bitmap */ - h_dc = GetDC( GetPlatform()->GetHandler() ); - h_xor_dc = CreateCompatibleDC(h_dc); - h_and_dc = CreateCompatibleDC(h_dc); - - /* Prepare AND (monochrome) and XOR (colour) mask */ - and_mask = CreateBitmap(sys_sm_cx, sys_sm_cy, 1, 1, NULL); - xor_mask = CreateCompatibleBitmap(h_dc, sys_sm_cx, sys_sm_cy); - hOldAndMaskBitmap = (HBITMAP) SelectObject(h_and_dc, and_mask); - hOldXorMaskBitmap = (HBITMAP) SelectObject(h_xor_dc, xor_mask); - - /* Create transparent cursor */ - for (y = 0; y < sys_sm_cy; y++) { - for (x = 0; x < sys_sm_cx; x++) { - SetPixel(h_and_dc, x, y, WINDOWS_RGB(255, 255, 255)); - SetPixel(h_xor_dc, x, y, WINDOWS_RGB(0, 0, 0)); - } - } - - local_draw_to_hdc( h_xor_dc, mImage, 0, 0 ); - - /* Make cursor background transparent */ - for (y = 0; y < (int)mImage->Height(); y++) { - for (x = 0; x < (int)mImage->Width(); x++) { - eeColorA C = mImage->GetPixel( x, y ); - - if ( C.A() != 0 ) { - /* Don't touch XOR value */ - SetPixel( h_and_dc, x, y, 0 ); - } else { - /* No need to touch AND value */ - SetPixel( h_xor_dc, x, y, WINDOWS_RGB( 0, 0, 0 ) ); - } - } - } - - SelectObject(h_and_dc, hOldAndMaskBitmap); - SelectObject(h_xor_dc, hOldXorMaskBitmap); - DeleteDC(h_and_dc); - DeleteDC(h_xor_dc); - ReleaseDC( GetPlatform()->GetHandler() , h_dc ); - - iconinfo.fIcon = false; - iconinfo.xHotspot = mHotSpot.x; - iconinfo.yHotspot = mHotSpot.y; - iconinfo.hbmMask = and_mask; - iconinfo.hbmColor = xor_mask; - - icon = CreateIconIndirect(&iconinfo); - - DeleteObject(and_mask); - DeleteObject(xor_mask); - - mCursor = (HCURSOR)icon; } - -cWinImpl * cCursorWin::GetPlatform() { - return reinterpret_cast( mWindow->GetPlatform() ); -} - -HCURSOR cCursorWin::GetCursor() const { - return mCursor; -} + +cCursorWin::~cCursorWin() { + if ( NULL != mCursor ) + DestroyIcon( (HCURSOR)mCursor ); +} + +static BITMAPINFO *get_bitmap_info( cImage * bitmap ) { + BITMAPINFO *bi; + int i; + + bi = (BITMAPINFO *) eeMalloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 256); + + ZeroMemory(&bi->bmiHeader, sizeof(BITMAPINFOHEADER)); + + bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bi->bmiHeader.biBitCount = 32; + bi->bmiHeader.biPlanes = 1; + bi->bmiHeader.biWidth = (int)bitmap->Width(); + bi->bmiHeader.biHeight = -((int)bitmap->Height()); + bi->bmiHeader.biClrUsed = 256; + bi->bmiHeader.biCompression = BI_RGB; + + for (i = 0; i < 256; i++) { + bi->bmiColors[i].rgbRed = 0; + bi->bmiColors[i].rgbGreen = 0; + bi->bmiColors[i].rgbBlue = 0; + bi->bmiColors[i].rgbReserved = 0; + } + + return bi; +} + +static BYTE *get_dib_from_bitmap_32(cImage *bitmap) { + int w, h; + int x, y; + int pitch; + BYTE *pixels; + BYTE *dst; + + w = (int)bitmap->Width(); + h = (int)bitmap->Height(); + pitch = w * 4; + + pixels = (BYTE *) eeMalloc(h * pitch); + if (!pixels) + return NULL; + + for (y = 0; y < h; y++) { + dst = pixels + y * pitch; + + for (x = 0; x < w; x++) { + eeColorA C = bitmap->GetPixel( x, y ); + + /* BGR */ + dst[0] = C.B(); + dst[1] = C.G(); + dst[2] = C.R(); + dst[3] = C.A(); + + dst += 4; + } + } + + return pixels; +} + +static void local_stretch_blit_to_hdc( cImage *bitmap, HDC dc, int src_x, int src_y, int src_w, int src_h, int dest_x, int dest_y, int dest_w, int dest_h) { + const int bitmap_h = (const int)bitmap->Height(); + const int bottom_up_src_y = bitmap_h - src_y - src_h; + BYTE *pixels; + BITMAPINFO *bi; + + bi = get_bitmap_info(bitmap); + pixels = get_dib_from_bitmap_32(bitmap); + + /* Windows treats all source bitmaps as bottom-up when using StretchDIBits + * unless the source (x,y) is (0,0). To work around this buggy behavior, we + * can use negative heights to reverse the direction of the blits. + * + * See for a detailed explanation. + */ + if (bottom_up_src_y == 0 && src_x == 0 && src_h != bitmap_h) { + StretchDIBits( dc, dest_x, dest_h+dest_y-1, dest_w, -dest_h, src_x, bitmap_h - src_y + 1, src_w, -src_h, pixels, bi, DIB_RGB_COLORS, SRCCOPY ); + } + else { + StretchDIBits( dc, dest_x, dest_y, dest_w, dest_h, src_x, bottom_up_src_y, src_w, src_h, pixels, bi, DIB_RGB_COLORS, SRCCOPY ); + } + + eeFree(pixels); + eeFree(bi); +} + +static void local_draw_to_hdc( HDC dc, cImage * bitmap, int x, int y ) { + int w = bitmap->Width(); + int h = bitmap->Height(); + local_stretch_blit_to_hdc(bitmap, dc, 0, 0, w, h, x, y, w, h); +} + +void cCursorWin::Create() { + if ( NULL == mImage && mImage->Size() ) + return; + + int x, y; + int sys_sm_cx, sys_sm_cy; + HDC h_dc; + HDC h_and_dc; + HDC h_xor_dc; + ICONINFO iconinfo; + HBITMAP and_mask; + HBITMAP xor_mask; + HBITMAP hOldAndMaskBitmap; + HBITMAP hOldXorMaskBitmap; + HICON icon; + + /* Get allowed cursor size - Windows can't make cursors of arbitrary size */ + sys_sm_cx = GetSystemMetrics(SM_CXCURSOR); + sys_sm_cy = GetSystemMetrics(SM_CYCURSOR); + + if ( ( (int)mImage->Width() > sys_sm_cx ) || ( (int)mImage->Height() > sys_sm_cy ) ) { + return; + } + + /* Create bitmap */ + h_dc = GetDC( GetPlatform()->GetHandler() ); + h_xor_dc = CreateCompatibleDC(h_dc); + h_and_dc = CreateCompatibleDC(h_dc); + + /* Prepare AND (monochrome) and XOR (colour) mask */ + and_mask = CreateBitmap(sys_sm_cx, sys_sm_cy, 1, 1, NULL); + xor_mask = CreateCompatibleBitmap(h_dc, sys_sm_cx, sys_sm_cy); + hOldAndMaskBitmap = (HBITMAP) SelectObject(h_and_dc, and_mask); + hOldXorMaskBitmap = (HBITMAP) SelectObject(h_xor_dc, xor_mask); + + /* Create transparent cursor */ + for (y = 0; y < sys_sm_cy; y++) { + for (x = 0; x < sys_sm_cx; x++) { + SetPixel(h_and_dc, x, y, WINDOWS_RGB(255, 255, 255)); + SetPixel(h_xor_dc, x, y, WINDOWS_RGB(0, 0, 0)); + } + } + + local_draw_to_hdc( h_xor_dc, mImage, 0, 0 ); + + /* Make cursor background transparent */ + for (y = 0; y < (int)mImage->Height(); y++) { + for (x = 0; x < (int)mImage->Width(); x++) { + eeColorA C = mImage->GetPixel( x, y ); + + if ( C.A() != 0 ) { + /* Don't touch XOR value */ + SetPixel( h_and_dc, x, y, 0 ); + } else { + /* No need to touch AND value */ + SetPixel( h_xor_dc, x, y, WINDOWS_RGB( 0, 0, 0 ) ); + } + } + } + + SelectObject(h_and_dc, hOldAndMaskBitmap); + SelectObject(h_xor_dc, hOldXorMaskBitmap); + DeleteDC(h_and_dc); + DeleteDC(h_xor_dc); + ReleaseDC( GetPlatform()->GetHandler() , h_dc ); + + iconinfo.fIcon = false; + iconinfo.xHotspot = mHotSpot.x; + iconinfo.yHotspot = mHotSpot.y; + iconinfo.hbmMask = and_mask; + iconinfo.hbmColor = xor_mask; + + icon = CreateIconIndirect(&iconinfo); + + DeleteObject(and_mask); + DeleteObject(xor_mask); + + mCursor = (void*)icon; +} + +cWinImpl * cCursorWin::GetPlatform() { + return reinterpret_cast( mWindow->GetPlatform() ); +} + +void * cCursorWin::GetCursor() const { + return mCursor; +} }}} diff --git a/src/eepp/window/platform/win/ccursorwin.hpp b/src/eepp/window/platform/win/ccursorwin.hpp index 54dd55c4a..5e13d7520 100644 --- a/src/eepp/window/platform/win/ccursorwin.hpp +++ b/src/eepp/window/platform/win/ccursorwin.hpp @@ -8,27 +8,27 @@ using namespace EE::Window; namespace EE { namespace Window { namespace Platform { - -class cWinImpl; -class cCursorWin : public cCursor { - public: - HCURSOR GetCursor() const; +class cWinImpl; + +class cCursorWin : public cCursor { + public: + void * GetCursor() const; protected: - friend class cWinImpl; - - HCURSOR mCursor; + friend class cWinImpl; + + void * mCursor; cCursorWin( cTexture * tex, const eeVector2i& hotspot, const std::string& name, cWindow * window ); cCursorWin( cImage * img, const eeVector2i& hotspot, const std::string& name, cWindow * window ); - cCursorWin( const std::string& path, const eeVector2i& hotspot, const std::string& name, cWindow * window ); - + cCursorWin( const std::string& path, const eeVector2i& hotspot, const std::string& name, cWindow * window ); + ~cCursorWin(); - void Create(); - + void Create(); + cWinImpl * GetPlatform(); }; diff --git a/src/eepp/window/platform/win/cwinimpl.cpp b/src/eepp/window/platform/win/cwinimpl.cpp index 78eeb2512..1af2b3404 100644 --- a/src/eepp/window/platform/win/cwinimpl.cpp +++ b/src/eepp/window/platform/win/cwinimpl.cpp @@ -1,16 +1,26 @@ -#include +#include #if EE_PLATFORM == EE_PLATFORM_WIN +#ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN +#endif +#include +#undef CreateWindow + +static BOOL WIN_ShowWindow( HWND hWnd, int nCmdShow ) { + return ShowWindow( hWnd, nCmdShow ); +} + +#include #include - -#include - -using namespace EE::Window::Cursor; +#include + +using namespace EE::Window::Cursor; namespace EE { namespace Window { namespace Platform { -cWinImpl::cWinImpl( cWindow * window, eeWindowHandler handler ) : +cWinImpl::cWinImpl( cWindow * window, eeWindowHandle handler ) : cPlatformImpl( window ), mHandler( handler ), mCursorCurrent( NULL ), @@ -53,7 +63,7 @@ void cWinImpl::MoveWindow( int left, int top ) { } void cWinImpl::SetContext( eeWindowContex Context ) { - wglMakeCurrent( GetDC( mHandler ), Context ); + wglMakeCurrent( (HDC)GetDC( mHandler ), (HGLRC)Context ); } eeVector2i cWinImpl::Position() { @@ -62,16 +72,16 @@ eeVector2i cWinImpl::Position() { return eeVector2i( r.left, r.top ); } -void cWinImpl::ShowMouseCursor() { - mCursorHidden = false; +void cWinImpl::ShowMouseCursor() { + mCursorHidden = false; if ( !mCursorCurrent ) { SetSystemMouseCursor( Cursor::SYS_CURSOR_DEFAULT ); } else { - SetCursor( mCursorCurrent ); + SetCursor( (HCURSOR)mCursorCurrent ); POINT p; GetCursorPos( &p ); - SetCursorPos( p.x, p.y ); + SetCursorPos( p.x, p.y ); } } @@ -96,11 +106,11 @@ cCursor * cWinImpl::CreateMouseCursor( const std::string& path, const eeVector2i return eeNew( cCursorWin, ( path, hotspot, name, mWindow ) ); } -void cWinImpl::SetMouseCursor( cCursor * cursor ) { - mCursorCurrent = reinterpret_cast ( cursor )->GetCursor(); - +void cWinImpl::SetMouseCursor( cCursor * cursor ) { + mCursorCurrent = reinterpret_cast ( cursor )->GetCursor(); + if ( !mCursorHidden ) { - SetCursor( mCursorCurrent ); + SetCursor( (HCURSOR)mCursorCurrent ); POINT p; GetCursorPos( &p ); SetCursorPos( p.x, p.y ); @@ -146,8 +156,8 @@ void cWinImpl::SetSystemMouseCursor( Cursor::EE_SYSTEM_CURSOR syscursor ) { mc = LoadCursor(NULL, IDC_NO); break; default: return; - - mCursorCurrent = mc; + + mCursorCurrent = mc; if ( !mCursorHidden ) { SetCursor( mc ); @@ -158,16 +168,16 @@ void cWinImpl::SetSystemMouseCursor( Cursor::EE_SYSTEM_CURSOR syscursor ) { } } -void cWinImpl::RestoreCursor() { +void cWinImpl::RestoreCursor() { if ( !mCursorHidden ) { ShowMouseCursor(); } else { HideMouseCursor(); } } - -eeWindowHandler cWinImpl::GetHandler() const { - return mHandler; + +eeWindowHandle cWinImpl::GetHandler() const { + return mHandler; } }}} diff --git a/src/eepp/window/platform/win/cwinimpl.hpp b/src/eepp/window/platform/win/cwinimpl.hpp index ffe237d95..d1e69f11d 100644 --- a/src/eepp/window/platform/win/cwinimpl.hpp +++ b/src/eepp/window/platform/win/cwinimpl.hpp @@ -2,17 +2,18 @@ #define EE_WINDOWCWINIMPL_HPP #include -#include #if EE_PLATFORM == EE_PLATFORM_WIN +#include + namespace EE { namespace Window { namespace Platform { using namespace EE::Window; class cWinImpl : public cPlatformImpl { public: - cWinImpl( Window::cWindow * window, eeWindowHandler handler ); + cWinImpl( Window::cWindow * window, eeWindowHandle handler ); ~cWinImpl(); @@ -48,10 +49,10 @@ class cWinImpl : public cPlatformImpl { void RestoreCursor(); - eeWindowHandler GetHandler() const; + eeWindowHandle GetHandler() const; protected: - eeWindowHandler mHandler; - HCURSOR mCursorCurrent; + eeWindowHandle mHandler; + void * mCursorCurrent; bool mCursorHidden; }; diff --git a/src/eepp/window/platform/x11/cx11impl.cpp b/src/eepp/window/platform/x11/cx11impl.cpp index 43e117492..db26cae09 100644 --- a/src/eepp/window/platform/x11/cx11impl.cpp +++ b/src/eepp/window/platform/x11/cx11impl.cpp @@ -7,7 +7,7 @@ using namespace EE::Window::Cursor; namespace EE { namespace Window { namespace Platform { -cX11Impl::cX11Impl( cWindow * window, eeWindowHandler display, X11Window xwindow, X11Window mainwindow, LockFunc lock, UnlockFunc unlock ) : +cX11Impl::cX11Impl( cWindow * window, eeWindowHandle display, X11Window xwindow, X11Window mainwindow, LockFunc lock, UnlockFunc unlock ) : cPlatformImpl( window ), mDisplay( display ), mX11Window( xwindow ), @@ -279,7 +279,7 @@ void cX11Impl::SetSystemMouseCursor( Cursor::EE_SYSTEM_CURSOR syscursor ) { Unlock(); } -eeWindowHandler cX11Impl::GetDisplay() const { +eeWindowHandle cX11Impl::GetDisplay() const { return mDisplay; } diff --git a/src/eepp/window/platform/x11/cx11impl.hpp b/src/eepp/window/platform/x11/cx11impl.hpp index 401a56a4d..27a826991 100644 --- a/src/eepp/window/platform/x11/cx11impl.hpp +++ b/src/eepp/window/platform/x11/cx11impl.hpp @@ -2,10 +2,11 @@ #define EE_WINDOWCX11IMPL_HPP #include -#include #if defined( EE_X11_PLATFORM ) +#include + namespace EE { namespace Window { namespace Platform { using namespace EE::Window; @@ -15,7 +16,7 @@ class cX11Impl : public cPlatformImpl { typedef void (*LockFunc)(void); typedef void (*UnlockFunc)(void); - cX11Impl( Window::cWindow * window, eeWindowHandler display, X11Window xwindow, X11Window mainwindow, LockFunc lock, UnlockFunc unlock ); + cX11Impl( Window::cWindow * window, eeWindowHandle display, X11Window xwindow, X11Window mainwindow, LockFunc lock, UnlockFunc unlock ); ~cX11Impl(); @@ -51,13 +52,13 @@ class cX11Impl : public cPlatformImpl { void RestoreCursor(); - eeWindowHandler GetDisplay() const; + eeWindowHandle GetDisplay() const; void Lock(); void Unlock(); protected: - eeWindowHandler mDisplay; + eeWindowHandle mDisplay; X11Window mX11Window; X11Window mMainWindow; LockFunc mLock;