Some minor fixes. Nothing relevant.

This commit is contained in:
spartanj
2011-02-16 05:14:42 -03:00
parent 9c81b69e8c
commit d34c8d768e
7 changed files with 157 additions and 95 deletions

View File

@@ -33,7 +33,7 @@ bool cWindowSDL::Create( WindowSettings Settings, ContextSettings 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;
@@ -151,23 +151,17 @@ void cWindowSDL::SetGLConfig() {
}
void cWindowSDL::ToggleFullscreen() {
#if EE_PLATFORM == EE_PLATFORM_WIN
bool WasMaximized = mWindow.Maximized;
bool WasMaximized = mWindow.Maximized;
if ( Windowed() ) {
Size( mWindow.WindowConfig.Width, mWindow.WindowConfig.Height, !Windowed() );
} else {
Size( mWindow.WindowSize.Width(), mWindow.WindowSize.Height(), !Windowed() );
}
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
if ( WasMaximized ) {
Maximize();
}
ShowCursor( mWindow.CursorVisible );
}
@@ -181,7 +175,7 @@ void cWindowSDL::Caption( const std::string& Caption ) {
bool cWindowSDL::Icon( const std::string& Path ) {
int x, y, c;
if ( !FileExists( Path ) ) {
if ( !FileExists( Path ) ) {
return false;
}
@@ -249,13 +243,15 @@ bool cWindowSDL::Visible() {
return 0 != ( SDL_GetAppState() & SDL_APPACTIVE );
}
void cWindowSDL::Size( const Uint32& Width, const Uint32& Height ) {
if ( Windowed() ) {
Size( Width, Height, true );
void cWindowSDL::Size( Uint32 Width, Uint32 Height, bool Windowed ) {
if ( ( !Width || !Height ) ) {
Width = mWindow.DesktopResolution.Width();
Height = mWindow.DesktopResolution.Height();
}
}
void cWindowSDL::Size( const Uint16& Width, const Uint16& Height, const bool& Windowed ) {
if ( this->Windowed() == Windowed && Width == mWindow.WindowConfig.Width && Height == mWindow.WindowConfig.Height )
return;
try {
cLog::instance()->Writef( "Switching from %s to %s. Width: %d Height %d.", this->Windowed() ? "windowed" : "fullscreen", Windowed ? "windowed" : "fullscreen", Width, Height );
@@ -270,6 +266,9 @@ void cWindowSDL::Size( const Uint16& Width, const Uint16& Height, const bool& Wi
Graphics::cTextureFactory::instance()->GrabTextures();
#endif
Uint32 oldWidth = mWindow.WindowConfig.Width;
Uint32 oldHeight = mWindow.WindowConfig.Height;
SetFlagValue( &mWindow.WindowConfig.Style, WindowStyle::Fullscreen, !Windowed );
mWindow.WindowConfig.Width = Width;
@@ -277,10 +276,10 @@ void cWindowSDL::Size( const Uint16& Width, const Uint16& Height, const bool& Wi
if ( Windowed ) {
mWindow.WindowSize = eeSize( Width, Height );
} else {
mWindow.WindowSize = eeSize( oldWidth, oldHeight );
}
mDefaultView.SetView( 0, 0, Width, Height );
SetGLConfig();
if ( Windowed ) {
@@ -292,13 +291,7 @@ void cWindowSDL::Size( const Uint16& Width, const Uint16& Height, const bool& Wi
#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX
if ( Reload ) {
cGL::instance()->Init();
}
#endif
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
@@ -308,6 +301,10 @@ void cWindowSDL::Size( const Uint16& Width, const Uint16& Height, const bool& Wi
}
#endif
mDefaultView.SetView( 0, 0, Width, Height );
Setup2D();
SendVideoResizeCb();
if ( NULL == mSurface ) {

View File

@@ -29,9 +29,7 @@ class EE_API cWindowSDL : public cWindow {
bool Visible();
void Size( const Uint32& Width, const Uint32& Height );
void Size( const Uint16& Width, const Uint16& Height, const bool& Windowed );
void Size( Uint32 Width, Uint32 Height, bool Windowed );
void ShowCursor( const bool& showcursor );

View File

@@ -9,16 +9,16 @@
#include "../../../graphics/cvertexbuffermanager.hpp"
#include "../../../graphics/cframebuffermanager.hpp"
#include "../../../graphics/ctexturefactory.hpp"
#include "../../platform/platformimpl.hpp"
#if EE_PLATFORM == EE_PLATFORM_WIN
#include <allegro5/allegro_windows.h>
#include <allegro5/allegro_windows.h>
#define WGL_NV_video_out
#elif EE_PLATFORM == EE_PLATFORM_LINUX
#include <allegro5/platform/aintuthr.h>
#include <allegro5/internal/aintern_system.h>
#include <allegro5/internal/aintern_system.h>
struct ALLEGRO_SYSTEM_XGLX
{
@@ -98,7 +98,7 @@ static void al_display_unlock() {
}
#endif
#include <allegro5/allegro_opengl.h>
#include <allegro5/internal/aintern_system.h>
#include <allegro5/internal/aintern_thread.h>
@@ -196,6 +196,10 @@ bool cWindowAl::Create( WindowSettings Settings, ContextSettings Context ) {
mWindow.Created = true;
if ( "" != mWindow.WindowConfig.Icon ) {
Icon( mWindow.WindowConfig.Icon );
}
LogSuccessfulInit( "Allegro 5" );
/// Init the clipboard after the window creation
@@ -253,16 +257,12 @@ void cWindowAl::Caption( const std::string& Caption ) {
al_set_window_title( mDisplay, Caption.c_str() );
}
bool cWindowAl::Icon( const std::string& Path ) {
return false;
}
bool cWindowAl::Active() {
return mActive;
}
bool cWindowAl::Visible() {
return true;
return !( 0 != ( al_get_display_flags( mDisplay ) & ALLEGRO_MINIMIZED ) );
}
eeVector2i cWindowAl::Position() {
@@ -271,73 +271,64 @@ eeVector2i cWindowAl::Position() {
return Pos;
}
void cWindowAl::Size( const Uint32& Width, const Uint32& Height ) {
if ( Windowed() ) {
Size( Width, Height, true );
void cWindowAl::Size( Uint32 Width, Uint32 Height, bool Windowed ) {
if ( ( !Width || !Height ) ) {
Width = mWindow.DesktopResolution.Width();
Height = mWindow.DesktopResolution.Height();
}
}
void cWindowAl::Size( const Uint16& Width, const Uint16& Height, const bool& Windowed ) {
cLog::instance()->Writef( "Switching from %s to %s. Width: %d Height %d.", this->Windowed() ? "windowed" : "fullscreen", Windowed ? "windowed" : "fullscreen", Width, Height );
if ( !Width || !Height )
if ( this->Windowed() == Windowed && Width == mWindow.WindowConfig.Width && Height == mWindow.WindowConfig.Height )
return;
cLog::instance()->Writef( "Switching from %s to %s. Width: %d Height %d.", this->Windowed() ? "windowed" : "fullscreen", Windowed ? "windowed" : "fullscreen", Width, Height );
try {
bool Reload = this->Windowed() != Windowed;
bool Reload = this->Windowed() != Windowed;
bool WinFullscreen = eeSize( Width, Height ) == mWindow.DesktopResolution && !Windowed;
bool WinIsFullscreen = eeSize( mWindow.WindowConfig.Width, mWindow.WindowConfig.Height ) == mWindow.DesktopResolution && !this->Windowed();
if ( !Reload ) {
SetFlagValue( &mWindow.WindowConfig.Style, WindowStyle::Fullscreen, !Windowed );
Uint32 oldWidth = mWindow.WindowConfig.Width;
Uint32 oldHeight = mWindow.WindowConfig.Height;
mWindow.WindowConfig.Width = Width;
mWindow.WindowConfig.Height = Height;
SetFlagValue( &mWindow.WindowConfig.Style, WindowStyle::Fullscreen, !Windowed );
if ( Windowed ) {
mWindow.WindowSize = eeSize( Width, Height );
mWindow.WindowConfig.Width = Width;
mWindow.WindowConfig.Height = Height;
if ( Windowed ) {
mWindow.WindowSize = eeSize( Width, Height );
} else {
mWindow.WindowSize = eeSize( oldWidth, oldHeight );
}
if ( !Reload || WinFullscreen || WinIsFullscreen ) {
if ( !WinFullscreen ) {
al_toggle_display_flag( mDisplay, ALLEGRO_FULLSCREEN_WINDOW, 0 );
al_toggle_display_flag( mDisplay, ALLEGRO_FULLSCREEN, Windowed ? 0 : 1 );
} else {
al_toggle_display_flag( mDisplay, ALLEGRO_FULLSCREEN_WINDOW, 1 );
}
al_toggle_display_flag( mDisplay, ALLEGRO_FULLSCREEN, Windowed ? 0 : 1 );
al_resize_display( mDisplay, Width, Height );
mDefaultView.SetView( 0, 0, Width, Height );
Setup2D();
SendVideoResizeCb();
} else {
SetFlagValue( &mWindow.WindowConfig.Style, WindowStyle::Fullscreen, !Windowed );
Uint32 oldWidth = mWindow.WindowConfig.Width;
Uint32 oldHeight = mWindow.WindowConfig.Height;
mWindow.WindowConfig.Width = Width;
mWindow.WindowConfig.Height = Height;
if ( Windowed ) {
mWindow.WindowSize = eeSize( Width, Height );
}
Graphics::cTextureFactory::instance()->GrabTextures();
Create( mWindow.WindowConfig, mWindow.ContextConfig );
if ( !Windowed ) {
mWindow.WindowSize = eeSize( oldWidth, oldHeight );
}
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
mDefaultView.SetView( 0, 0, Width, Height );
Setup2D();
SendVideoResizeCb();
}
mDefaultView.SetView( 0, 0, Width, Height );
Setup2D();
SendVideoResizeCb();
ShowCursor( mWindow.CursorVisible );
} catch (...) {
cLog::instance()->Write( "Unable to change resolution" );
cLog::instance()->Save();
@@ -346,6 +337,8 @@ void cWindowAl::Size( const Uint16& Width, const Uint16& Height, const bool& Win
}
void cWindowAl::ShowCursor( const bool& showcursor ) {
mWindow.CursorVisible = showcursor;
if ( showcursor )
al_show_mouse_cursor( mDisplay );
else
@@ -406,6 +399,78 @@ ALLEGRO_DISPLAY * cWindowAl::GetDisplay() const {
return mDisplay;
}
bool cWindowAl::Icon( const std::string& Path ) {
int x, y, c;
if ( !mWindow.Created ) {
if ( stbi_info( Path.c_str(), &x, &y, &c ) ) {
mWindow.WindowConfig.Icon = Path;
return true;
}
return false;
}
if ( !FileExists( Path ) ) {
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 ) {
int nbfl = al_get_new_bitmap_flags();
al_set_new_bitmap_flags( ALLEGRO_MEMORY_BITMAP );
ALLEGRO_BITMAP * icon;
icon = al_create_bitmap( W, H );
al_set_target_bitmap( icon );
if ( icon && al_lock_bitmap( icon, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY ) ) {
eeUint Pos;
for ( y = 0; y < H; y++ ) {
for ( x = 0; x < W; x++ ) {
Pos = ( x + y * W ) * c;
if ( 4 == c )
al_put_pixel( x, y, al_map_rgba( Ptr[Pos], Ptr[Pos+1], Ptr[Pos+2], Ptr[Pos+3] ) );
else
al_put_pixel( x, y, al_map_rgb( Ptr[Pos], Ptr[Pos+1], Ptr[Pos+2] ) );
}
}
al_unlock_bitmap( icon );
al_set_display_icon( mDisplay, icon );
}
if ( icon )
al_destroy_bitmap( icon );
al_set_new_bitmap_flags( nbfl );
al_set_target_backbuffer( mDisplay );
free( Ptr );
mWindow.WindowConfig.Icon = Path;
return true;
}
free( Ptr );
}
return false;
}
}}}}
#endif

View File

@@ -4,8 +4,8 @@
#include "../../cbackend.hpp"
#ifdef EE_BACKEND_ALLEGRO_ACTIVE
#define ALLEGRO_LIB_BUILD
#define ALLEGRO_LIB_BUILD
#include <allegro5/debug.h>
#include <allegro5/allegro.h>
#include "../../cwindow.hpp"
@@ -32,9 +32,7 @@ class EE_API cWindowAl : public cWindow {
eeVector2i Position();
void Size( const Uint32& Width, const Uint32& Height );
void Size( const Uint16& Width, const Uint16& Height, const bool& Windowed );
void Size( Uint32 Width, Uint32 Height, bool Windowed );
void ShowCursor( const bool& showcursor );

View File

@@ -38,6 +38,10 @@ const eeSize& cWindow::GetDesktopResolution() const {
return mWindow.DesktopResolution;
}
void cWindow::Size( Uint32 Width, Uint32 Height ) {
Size( Width, Height, Windowed() );
}
bool cWindow::Windowed() const {
return 0 != !( mWindow.WindowConfig.Style & WindowStyle::Fullscreen );
}

View File

@@ -152,7 +152,7 @@ class EE_API cWindow {
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;
virtual void Size( Uint32 Width, Uint32 Height );
/** @return The caption of the titlebar */
virtual std::string Caption();
@@ -162,7 +162,7 @@ class EE_API cWindow {
* @param Height New screen height
* @param Windowed Windowed or Fullscreen
*/
virtual void Size( const Uint16& Width, const Uint16& Height, const bool& Windowed ) = 0;
virtual void Size( Uint32 Width, Uint32 Height, bool Windowed ) = 0;
/** @return The resolutions that support the video card */
virtual std::vector< std::pair<unsigned int, unsigned int> > GetPossibleResolutions() const = 0;

View File

@@ -18,7 +18,7 @@ cX11Impl::~cX11Impl() {
void cX11Impl::MinimizeWindow() {
mLock();
XIconifyWindow( mDisplay, DefaultRootWindow( mDisplay ), 0 );
XIconifyWindow( mDisplay, mWindow, 0 );
XFlush(mDisplay);
mUnlock();
}