mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-13 04:42:12 +03:00
Added Window::setCloseRequestCallback to be able to control the window close request from the window manager.
--HG-- branch : dev-2.1-float
This commit is contained in:
@@ -29,6 +29,8 @@ class EE_API TextureAtlasEditor {
|
||||
UISpinBox * getSpinOffX() const { return mSpinOffX; }
|
||||
|
||||
UISpinBox * getSpinOffY() const { return mSpinOffY; }
|
||||
|
||||
bool isEdited() { return mEdited; }
|
||||
protected:
|
||||
class UITGEUpdater : public UINode
|
||||
{
|
||||
@@ -58,6 +60,7 @@ class EE_API TextureAtlasEditor {
|
||||
UIDropDownList * mTextureFilterList;
|
||||
TextureAtlasTextureRegionEditor * mTextureRegionEditor;
|
||||
UITGEUpdater * mTGEU;
|
||||
bool mEdited;
|
||||
|
||||
void windowClose( const UIEvent * Event );
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ class DisplayMode {
|
||||
class EE_API Window {
|
||||
public:
|
||||
typedef cb::Callback1<void, Window*> WindowResizeCallback;
|
||||
typedef cb::Callback1<bool, Window*> WindowRequestCloseCallback;
|
||||
|
||||
Window( WindowSettings Settings, ContextSettings Context, Clipboard * Clipboard, Input * Input, CursorManager * CursorManager );
|
||||
|
||||
@@ -424,6 +425,8 @@ class EE_API Window {
|
||||
Vector2i mapCoordsToPixel(const Vector2f & point);
|
||||
|
||||
Vector2i mapCoordsToPixel(const Vector2f & point, const View & view);
|
||||
|
||||
void setCloseRequestCallback( const WindowRequestCloseCallback& closeRequestCallback );
|
||||
protected:
|
||||
friend class Engine;
|
||||
friend class Input;
|
||||
@@ -437,6 +440,7 @@ class EE_API Window {
|
||||
const View * mCurrentView;
|
||||
Uint32 mNumCallBacks;
|
||||
std::map<Uint32, WindowResizeCallback> mCallbacks;
|
||||
WindowRequestCloseCallback mCloseRequestCallback;
|
||||
|
||||
class FrameData {
|
||||
public:
|
||||
@@ -494,6 +498,8 @@ class EE_API Window {
|
||||
void logSuccessfulInit( const std::string& BackendName );
|
||||
|
||||
void logFailureInit( const std::string& ClassName, const std::string& BackendName );
|
||||
|
||||
void onCloseRequest();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -26,7 +26,8 @@ TextureAtlasEditor::TextureAtlasEditor( UIWindow * AttatchTo, const TGEditorClos
|
||||
mCloseCb( callback ),
|
||||
mTexturePacker( NULL ),
|
||||
mTextureAtlasLoader( NULL ),
|
||||
mCurTextureRegion( NULL )
|
||||
mCurTextureRegion( NULL ),
|
||||
mEdited( false )
|
||||
{
|
||||
if ( NULL == UIThemeManager::instance()->getDefaultTheme() ) {
|
||||
eePRINTL( "TextureAtlasEditor needs a default theme assigned to work." );
|
||||
@@ -169,6 +170,7 @@ void TextureAtlasEditor::onResetDestSize( const UIEvent * Event ) {
|
||||
|
||||
mSpinDestW->setValue( RealSize.getWidth() );
|
||||
mSpinDestH->setValue( RealSize.getHeight() );
|
||||
mEdited = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,6 +180,7 @@ void TextureAtlasEditor::onResetOffset( const UIEvent * Event ) {
|
||||
if ( NULL != mCurTextureRegion && MouseEvent->getFlags() & EE_BUTTON_LMASK ) {
|
||||
mSpinOffX->setValue( 0 );
|
||||
mSpinOffY->setValue( 0 );
|
||||
mEdited = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +192,7 @@ void TextureAtlasEditor::onCenterOffset( const UIEvent * Event ) {
|
||||
|
||||
mSpinOffX->setValue( NSize.x );
|
||||
mSpinOffY->setValue( NSize.y );
|
||||
mEdited = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,18 +204,21 @@ void TextureAtlasEditor::onHBOffset( const UIEvent * Event ) {
|
||||
|
||||
mSpinOffX->setValue( NSize.x );
|
||||
mSpinOffY->setValue( NSize.y );
|
||||
mEdited = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TextureAtlasEditor::onOffXChange( const UIEvent * Event ) {
|
||||
if ( NULL != mCurTextureRegion ) {
|
||||
mCurTextureRegion->setOffset( Vector2i( (Int32)mSpinOffX->getValue(), mCurTextureRegion->getOffset().y ) );
|
||||
mEdited = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TextureAtlasEditor::onOffYChange( const UIEvent * Event ) {
|
||||
if ( NULL != mCurTextureRegion ) {
|
||||
mCurTextureRegion->setOffset( Vector2i( mCurTextureRegion->getOffset().x, (Int32)mSpinOffY->getValue() ) );
|
||||
mEdited = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +226,7 @@ void TextureAtlasEditor::onDestWChange( const UIEvent * Event ) {
|
||||
if ( NULL != mCurTextureRegion ) {
|
||||
mCurTextureRegion->setOriDestSize( Sizef( (Int32)mSpinDestW->getValue(), mCurTextureRegion->getDpSize().y ) );
|
||||
mTextureRegionEditor->getGfx()->setSize( (Int32)mSpinDestW->getValue(), mTextureRegionEditor->getGfx()->getSize().getHeight() );
|
||||
mEdited = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +234,7 @@ void TextureAtlasEditor::onDestHChange( const UIEvent * Event ) {
|
||||
if ( NULL != mCurTextureRegion ) {
|
||||
mCurTextureRegion->setOriDestSize( Sizef( mCurTextureRegion->getDpSize().x, (Int32)mSpinDestH->getValue() ) );
|
||||
mTextureRegionEditor->getGfx()->setSize( mTextureRegionEditor->getGfx()->getSize().getWidth(), (Int32)mSpinDestH->getValue() );
|
||||
mEdited = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ void Input::processEvent( InputEvent * Event ) {
|
||||
}
|
||||
case InputEvent::Quit:
|
||||
{
|
||||
mWindow->close();
|
||||
mWindow->onCloseRequest();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,10 @@ Vector2i Window::mapCoordsToPixel(const Vector2f& point, const View& view) {
|
||||
return pixel;
|
||||
}
|
||||
|
||||
void Window::setCloseRequestCallback( const WindowRequestCloseCallback & closeRequestCallback ) {
|
||||
mCloseRequestCallback = closeRequestCallback;
|
||||
}
|
||||
|
||||
void Window::setViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height ) {
|
||||
GLi->viewport( x, getHeight() - ( y + Height ), Width, Height );
|
||||
}
|
||||
@@ -435,6 +439,14 @@ void Window::logFailureInit( const std::string& ClassName, const std::string& Ba
|
||||
eePRINTL( "Error on %s::Init. Backend %s failed to start.", ClassName.c_str(), BackendName.c_str() );
|
||||
}
|
||||
|
||||
void Window::onCloseRequest() {
|
||||
if ( mCloseRequestCallback.IsSet() && !mCloseRequestCallback.Call( this ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
std::string Window::getCaption() {
|
||||
return mWindow.WindowConfig.Caption;
|
||||
}
|
||||
|
||||
@@ -2,17 +2,27 @@
|
||||
|
||||
EE::Window::Window * win = NULL;
|
||||
UIMessageBox * MsgBox = NULL;
|
||||
MapEditor * Editor = NULL;
|
||||
|
||||
void mainLoop() {
|
||||
win->getInput()->update();
|
||||
|
||||
if ( win->getInput()->isKeyUp( KEY_ESCAPE ) && NULL == MsgBox ) {
|
||||
bool onCloseRequestCallback( EE::Window::Window * w ) {
|
||||
if ( NULL != Editor ) {
|
||||
MsgBox = UIMessageBox::New( MSGBOX_OKCANCEL, "Do you really want to close the current map?\nAll changes will be lost." );
|
||||
MsgBox->addEventListener( UIEvent::MsgBoxConfirmClick, cb::Make1<void, const UIEvent*>( []( const UIEvent * event ) { win->close(); } ) );
|
||||
MsgBox->addEventListener( UIEvent::OnClose, cb::Make1<void, const UIEvent*>( []( const UIEvent * event ) { MsgBox = NULL; } ) );
|
||||
MsgBox->setTitle( "Close Map?" );
|
||||
MsgBox->center();
|
||||
MsgBox->show();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void mainLoop() {
|
||||
win->getInput()->update();
|
||||
|
||||
if ( win->getInput()->isKeyUp( KEY_ESCAPE ) && NULL == MsgBox && onCloseRequestCallback( win ) ) {
|
||||
win->close();
|
||||
}
|
||||
|
||||
UIManager::instance()->update();
|
||||
@@ -39,6 +49,8 @@ EE_MAIN_FUNC int main (int argc, char * argv []) {
|
||||
win = Engine::instance()->createWindow( WindowSettings( width, height, "eepp - Map Editor", WindowStyle::Default, WindowBackend::Default, 32, "assets/icon/ee.png", pixelDensity ), ContextSettings( true, GLv_default, true, 24, 1, 0, false ) );
|
||||
|
||||
if ( win->isOpen() ) {
|
||||
win->setCloseRequestCallback( cb::Make1( onCloseRequestCallback ) );
|
||||
|
||||
UIManager::instance()->init( UI_MANAGER_USE_DRAW_INVALIDATION );
|
||||
|
||||
{
|
||||
@@ -55,7 +67,7 @@ EE_MAIN_FUNC int main (int argc, char * argv []) {
|
||||
UIThemeManager::instance()->setDefaultEffectsEnabled( true )->setDefaultTheme( theme )->setDefaultFont( font )->add( theme );
|
||||
}
|
||||
|
||||
MapEditor::New();
|
||||
Editor = MapEditor::New();
|
||||
|
||||
win->runMainLoop( &mainLoop );
|
||||
}
|
||||
|
||||
@@ -1,12 +1,29 @@
|
||||
#include <eepp/ee.hpp>
|
||||
|
||||
EE::Window::Window * win = NULL;
|
||||
UIMessageBox * MsgBox = NULL;
|
||||
TextureAtlasEditor * Editor = NULL;
|
||||
|
||||
bool onCloseRequestCallback( EE::Window::Window * w ) {
|
||||
if ( NULL != Editor && Editor->isEdited() ) {
|
||||
MsgBox = UIMessageBox::New( MSGBOX_OKCANCEL, "Do you really want to close the texture atlas editor?\nAll changes will be lost." );
|
||||
MsgBox->addEventListener( UIEvent::MsgBoxConfirmClick, cb::Make1<void, const UIEvent*>( []( const UIEvent * event ) { win->close(); } ) );
|
||||
MsgBox->addEventListener( UIEvent::OnClose, cb::Make1<void, const UIEvent*>( []( const UIEvent * event ) { MsgBox = NULL; } ) );
|
||||
MsgBox->setTitle( "Close Texture Atlas Editor?" );
|
||||
MsgBox->center();
|
||||
MsgBox->show();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void mainLoop() {
|
||||
win->getInput()->update();
|
||||
|
||||
if ( win->getInput()->isKeyDown( KEY_ESCAPE ) )
|
||||
if ( win->getInput()->isKeyUp( KEY_ESCAPE ) && NULL == MsgBox && onCloseRequestCallback( win ) ) {
|
||||
win->close();
|
||||
}
|
||||
|
||||
UIManager::instance()->update();
|
||||
|
||||
@@ -32,6 +49,8 @@ EE_MAIN_FUNC int main (int argc, char * argv []) {
|
||||
win = Engine::instance()->createWindow( WindowSettings( width, height, "eepp - Texture Atlas Editor", WindowStyle::Default, WindowBackend::Default, 32, "assets/icon/ee.png", pixelDensity ), ContextSettings( true, GLv_default, true, 24, 1, 0, false ) );
|
||||
|
||||
if ( win->isOpen() ) {
|
||||
win->setCloseRequestCallback( cb::Make1( onCloseRequestCallback ) );
|
||||
|
||||
UIManager::instance()->init( UI_MANAGER_USE_DRAW_INVALIDATION );
|
||||
|
||||
{
|
||||
@@ -48,7 +67,7 @@ EE_MAIN_FUNC int main (int argc, char * argv []) {
|
||||
UIThemeManager::instance()->setDefaultEffectsEnabled( true )->setDefaultTheme( theme )->setDefaultFont( font )->add( theme );
|
||||
}
|
||||
|
||||
TextureAtlasEditor::New();
|
||||
Editor = TextureAtlasEditor::New();
|
||||
|
||||
win->runMainLoop( &mainLoop );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user