GUIEngine addition. Now a queue of dialog windows.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13514 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
ac6ce5a4f0
commit
f43c5c915f
@ -51,6 +51,7 @@ src/graphics/stars.cpp
|
||||
src/guiengine/abstract_state_manager.cpp
|
||||
src/guiengine/abstract_top_level_container.cpp
|
||||
src/guiengine/CGUISpriteBank.cpp
|
||||
src/guiengine/dialog_queue.cpp
|
||||
src/guiengine/engine.cpp
|
||||
src/guiengine/event_handler.cpp
|
||||
src/guiengine/layout_manager.cpp
|
||||
@ -347,6 +348,7 @@ src/graphics/slip_stream.hpp
|
||||
src/graphics/stars.hpp
|
||||
src/guiengine/abstract_state_manager.hpp
|
||||
src/guiengine/abstract_top_level_container.hpp
|
||||
src/guiengine/dialog_queue.hpp
|
||||
src/guiengine/engine.hpp
|
||||
src/guiengine/event_handler.hpp
|
||||
src/guiengine/layout_manager.hpp
|
||||
|
74
src/guiengine/dialog_queue.cpp
Normal file
74
src/guiengine/dialog_queue.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Glenn De Jonghe
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "guiengine/dialog_queue.hpp"
|
||||
#include "assert.h"
|
||||
|
||||
using namespace GUIEngine;
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
static DialogQueue* dialog_queue_singleton(NULL);
|
||||
|
||||
DialogQueue* DialogQueue::get()
|
||||
{
|
||||
if (dialog_queue_singleton == NULL)
|
||||
dialog_queue_singleton = new DialogQueue();
|
||||
return dialog_queue_singleton;
|
||||
}
|
||||
|
||||
void DialogQueue::deallocate()
|
||||
{
|
||||
delete dialog_queue_singleton;
|
||||
dialog_queue_singleton = NULL;
|
||||
} // deallocate
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
DialogQueue::DialogQueue()
|
||||
{
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void DialogQueue::pushDialog(ModalDialog * dialog, bool closes_any_dialog)
|
||||
{
|
||||
assert(!dialog->isInited());
|
||||
m_queue.push( new Entry(dialog, closes_any_dialog)); }
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void DialogQueue::update()
|
||||
{
|
||||
|
||||
if(!m_queue.empty())
|
||||
{
|
||||
Entry * entry = m_queue.front();
|
||||
if(entry->closes() || !ModalDialog::isADialogActive())
|
||||
{
|
||||
ModalDialog::dismiss();
|
||||
entry->get()->doInit();
|
||||
m_queue.pop();
|
||||
delete entry;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
55
src/guiengine/dialog_queue.hpp
Normal file
55
src/guiengine/dialog_queue.hpp
Normal file
@ -0,0 +1,55 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Glenn De Jonghe
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_DIALOG_QUEUE_HPP
|
||||
#define HEADER_DIALOG_QUEUE_HPP
|
||||
|
||||
#include <queue>
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
|
||||
/**
|
||||
* \ingroup guiengine
|
||||
*/
|
||||
namespace GUIEngine
|
||||
{
|
||||
|
||||
class DialogQueue
|
||||
{
|
||||
private :
|
||||
|
||||
class Entry
|
||||
{
|
||||
ModalDialog * m_dialog;
|
||||
bool m_closes_any_dialog;
|
||||
public :
|
||||
Entry(ModalDialog * dialog, bool closes_any_dialog) : m_dialog(dialog), m_closes_any_dialog(closes_any_dialog) {}
|
||||
bool closes() { return m_closes_any_dialog; }
|
||||
ModalDialog* get() { return m_dialog; }
|
||||
};
|
||||
std::queue<Entry *> m_queue;
|
||||
DialogQueue();
|
||||
public :
|
||||
/**Singleton */
|
||||
static DialogQueue * get();
|
||||
static void deallocate();
|
||||
void pushDialog(ModalDialog * dialog, bool closes_any_dialog);
|
||||
void update();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
@ -657,6 +657,7 @@ namespace GUIEngine
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "guiengine/skin.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/dialog_queue.hpp"
|
||||
#include "modes/demo_world.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "states_screens/race_gui_base.hpp"
|
||||
@ -835,6 +836,7 @@ namespace GUIEngine
|
||||
{
|
||||
widget->update(dt);
|
||||
}
|
||||
DialogQueue::get()->update();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,11 +47,12 @@ using namespace GUIEngine;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ModalDialog::ModalDialog(const float percentWidth, const float percentHeight,
|
||||
ModalDialogLocation location)
|
||||
ModalDialog::ModalDialog(const float percentWidth, const float percentHeight, bool do_init, ModalDialogLocation location)
|
||||
{
|
||||
m_dialog_location = location;
|
||||
doInit(percentWidth, percentHeight);
|
||||
m_init = false;
|
||||
if(do_init)
|
||||
doInit();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -82,15 +83,16 @@ void ModalDialog::loadFromFile(const char* xmlFile)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ModalDialog::doInit(const float percentWidth, const float percentHeight)
|
||||
void ModalDialog::doInit()
|
||||
{
|
||||
m_init = true;
|
||||
pointer_was_shown = irr_driver->isPointerShown();
|
||||
irr_driver->showPointer();
|
||||
|
||||
const core::dimension2d<u32>& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize();
|
||||
|
||||
const int w = (int)(frame_size.Width*percentWidth);
|
||||
const int h = (int)(frame_size.Height*percentHeight);
|
||||
const int w = (int)(frame_size.Width* m_percent_width);
|
||||
const int h = (int)(frame_size.Height* m_percent_height);
|
||||
|
||||
assert(frame_size.Width > 0);
|
||||
assert(frame_size.Height > 0);
|
||||
|
@ -55,11 +55,12 @@ namespace GUIEngine
|
||||
class ModalDialog : public SkinWidgetContainer, public AbstractTopLevelContainer
|
||||
{
|
||||
private:
|
||||
/** Because C++ doesn't support constructor delegation... */
|
||||
void doInit(const float percentWidth, const float percentHeight);
|
||||
|
||||
ModalDialogLocation m_dialog_location;
|
||||
|
||||
float m_percent_width, m_percent_height;
|
||||
bool m_init;
|
||||
|
||||
|
||||
protected:
|
||||
irr::gui::IGUIWindow* m_irrlicht_window;
|
||||
@ -70,7 +71,7 @@ namespace GUIEngine
|
||||
/**
|
||||
* \brief Creates a modal dialog with given percentage of screen width and height
|
||||
*/
|
||||
ModalDialog(const float percentWidth, const float percentHeight,
|
||||
ModalDialog(const float percentWidth, const float percentHeight, bool do_init = true,
|
||||
ModalDialogLocation location = MODAL_DIALOG_LOCATION_CENTER);
|
||||
|
||||
/** \brief Load a XML file to create the dialog from
|
||||
@ -89,6 +90,10 @@ namespace GUIEngine
|
||||
public:
|
||||
LEAK_CHECK()
|
||||
|
||||
/** Because C++ doesn't support constructor delegation... */
|
||||
void doInit();
|
||||
bool isInited() {return m_init;}
|
||||
|
||||
virtual ~ModalDialog();
|
||||
|
||||
/** Returns whether to block event propagation (usually, you will want to block events you processed) */
|
||||
|
Loading…
Reference in New Issue
Block a user