Added widget cast helper method to widget to accomodate windows not having RTTI

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3720 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2009-07-09 01:29:23 +00:00
parent 18f898f34e
commit ae33627515
5 changed files with 63 additions and 27 deletions

View File

@@ -64,7 +64,7 @@ void ModalDialog::clearWindow()
const int children_amount = m_children.size();
for(int i=0; i<children_amount; i++)
{
m_irrlicht_window->removeChild( m_children[i].m_element );
m_irrlicht_window->removeChild( m_children[i].getIrrlichtElement() );
}
m_children.clearAndDeleteAll();
@@ -199,7 +199,7 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
textCtrl->setParent(m_irrlicht_window);
m_children.push_back(textCtrl);
textCtrl->add();
GUIEngine::getGUIEnv()->setFocus( textCtrl->m_element );
GUIEngine::getGUIEnv()->setFocus( textCtrl->getIrrlichtElement() );
// TODO : add Ok button
@@ -218,7 +218,7 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
}
EnterPlayerNameDialog::~EnterPlayerNameDialog()
{
textCtrl->m_element->remove();
textCtrl->getIrrlichtElement()->remove();
}
void EnterPlayerNameDialog::processEvent(std::string& eventSource)
{
@@ -231,7 +231,7 @@ void EnterPlayerNameDialog::processEvent(std::string& eventSource)
void EnterPlayerNameDialog::onEnterPressedInternal()
{
// ---- Cancel button pressed
if( GUIEngine::getGUIEnv()->hasFocus(cancelButton->m_element) )
if( GUIEngine::getGUIEnv()->hasFocus(cancelButton->getIrrlichtElement()) )
{
std::string fakeEvent = "cancel";
processEvent(fakeEvent);
@@ -245,7 +245,7 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand
GUIEngine::getGUIEnv()->removeFocus( textCtrl->m_element );
GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss();
@@ -280,8 +280,8 @@ TrackInfoDialog::TrackInfoDialog(const char* trackName, ITexture* screenshot, co
m_children.push_back(spinner);
spinner->add();
spinner->setValue(3);
spinner->m_element->setTabStop(true);
spinner->m_element->setTabGroup(false);
spinner->getIrrlichtElement()->setTabStop(true);
spinner->getIrrlichtElement()->setTabGroup(false);
ButtonWidget* okBtn = new ButtonWidget();
okBtn->m_properties[PROP_ID] = "start";
@@ -293,10 +293,10 @@ TrackInfoDialog::TrackInfoDialog(const char* trackName, ITexture* screenshot, co
okBtn->setParent(m_irrlicht_window);
m_children.push_back(okBtn);
okBtn->add();
okBtn->m_element->setTabStop(true);
okBtn->m_element->setTabGroup(false);
okBtn->getIrrlichtElement()->setTabStop(true);
okBtn->getIrrlichtElement()->setTabGroup(false);
GUIEngine::getGUIEnv()->setFocus( okBtn->m_element );
GUIEngine::getGUIEnv()->setFocus( okBtn->getIrrlichtElement() );
core::rect< s32 > area_top(0, 0, m_area.getWidth(), y1);
@@ -405,7 +405,7 @@ void PlayerInfoDialog::showRegularDialog()
textCtrl->setParent(m_irrlicht_window);
m_children.push_back(textCtrl);
textCtrl->add();
GUIEngine::getGUIEnv()->setFocus( textCtrl->m_element );
GUIEngine::getGUIEnv()->setFocus( textCtrl->getIrrlichtElement() );
}
{
@@ -506,7 +506,7 @@ void PlayerInfoDialog::showConfirmDialog()
widget->setParent(m_irrlicht_window);
m_children.push_back(widget);
widget->add();
GUIEngine::getGUIEnv()->setFocus( widget->m_element );
GUIEngine::getGUIEnv()->setFocus( widget->getIrrlichtElement() );
}
@@ -528,7 +528,7 @@ void PlayerInfoDialog::processEvent(std::string& eventSource)
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand
GUIEngine::getGUIEnv()->removeFocus( textCtrl->m_element );
GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss();
@@ -546,7 +546,7 @@ void PlayerInfoDialog::processEvent(std::string& eventSource)
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand
GUIEngine::getGUIEnv()->removeFocus( textCtrl->m_element );
GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss();
@@ -561,7 +561,7 @@ void PlayerInfoDialog::processEvent(std::string& eventSource)
{
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand
GUIEngine::getGUIEnv()->removeFocus( textCtrl->m_element );
GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() );
GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window );
ModalDialog::dismiss();

View File

@@ -515,7 +515,7 @@ namespace StateManager
// re-select the previous button
ButtonWidget* btn = getCurrentScreen()->getWidget<ButtonWidget>(binding_to_set_button.c_str());
if(btn != NULL) GUIEngine::getGUIEnv()->setFocus( btn->m_element );
if(btn != NULL) GUIEngine::getGUIEnv()->setFocus( btn->getIrrlichtElement() );
// save new binding to file
input_manager->getDeviceList()->serialize();

View File

@@ -69,6 +69,16 @@ Widget::Widget()
m_parent = NULL;
}
// -----------------------------------------------------------------------------
template<typename T> T* Widget::getIrrlichtElement()
{
#ifdef __WIN32__
return static_cast<T*>(m_element);
#else
T* out = dynamic_cast<T*>(m_element);
return out;
#endif
}
// -----------------------------------------------------------------------------
/**
* Receives as string the raw property value retrieved from XML file.
* Will try to make sense of it, as an absolute value or a percentage.
@@ -299,7 +309,7 @@ void LabelWidget::add()
void LabelWidget::setText(stringw newText)
{
IGUIStaticText* irrwidget = static_cast<IGUIStaticText*>(m_element);
IGUIStaticText* irrwidget = getIrrlichtElement<IGUIStaticText>();
irrwidget->setText(newText.c_str());
}
@@ -784,9 +794,11 @@ void SpinnerWidget::add()
if(m_graphical)
{
std::ostringstream icon_stream;
icon_stream<<file_manager->getDataDir() << "/" << m_properties[PROP_ICON];
icon_stream << file_manager->getDataDir() << "/" << m_properties[PROP_ICON];
std::string imagefile = StringUtils::insert_values(icon_stream.str(), m_value);
ITexture* texture = irr_driver->getTexture(imagefile);
assert(texture != NULL);
const int texture_width = texture->getSize().Width;
const int free_h_space = w-h*2-texture_width; // to center image

View File

@@ -126,12 +126,22 @@ namespace GUIEngine
IGUIElement* m_parent;
static bool convertToCoord(std::string& x, int* absolute, int* percentage);
/**
* IrrLicht widget created to represent this object.
*/
IGUIElement* m_element;
public:
Widget();
virtual ~Widget() {}
bool m_show_bounding_box;
template<typename T> T* getIrrlichtElement();
IGUIElement* getIrrlichtElement() { return m_element; }
virtual void update(float delta) { }
/**
@@ -163,11 +173,6 @@ namespace GUIEngine
*/
int id;
/**
* IrrLicht widget created to represent this object.
*/
IGUIElement* m_element;
/** A map that holds values for all specified widget properties (in the XML file)*/
std::map<Property, std::string> m_properties;

View File

@@ -241,6 +241,9 @@
9551CBD60FC1BB7600DB481B /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95F4231E0E26E44800692113 /* Cocoa.framework */; };
9551CBD70FC1BB7600DB481B /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95F423120E26E3DC00692113 /* OpenGL.framework */; };
9551CBDA0FC1BB9200DB481B /* AGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9551CBD90FC1BB9200DB481B /* AGL.framework */; };
955DE88310042701006A4F3C /* check_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 955DE88110042701006A4F3C /* check_manager.cpp */; };
955DE88C1004273B006A4F3C /* check_structure.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 955DE8871004273B006A4F3C /* check_structure.cpp */; };
955DE88D1004273B006A4F3C /* checkline.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 955DE8891004273B006A4F3C /* checkline.cpp */; };
95CB476C0FF30EF400413BAE /* bezier_curve.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95CB476B0FF30EF400413BAE /* bezier_curve.cpp */; };
95D1F5F70FC8C3E300FF6968 /* input.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95D1F5F60FC8C3E300FF6968 /* input.cpp */; };
95D1F6190FC8CDBB00FF6968 /* options_screen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95D1F6180FC8CDBB00FF6968 /* options_screen.cpp */; };
@@ -366,6 +369,12 @@
9551C9F80FC1B87600DB481B /* Config.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = SOURCE_ROOT; wrapsLines = 1; };
9551CA100FC1BB6400DB481B /* SuperTuxKart-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "SuperTuxKart-Info.plist"; sourceTree = SOURCE_ROOT; };
9551CBD90FC1BB9200DB481B /* AGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AGL.framework; path = /System/Library/Frameworks/AGL.framework; sourceTree = "<absolute>"; };
955DE88110042701006A4F3C /* check_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = check_manager.cpp; path = ../../tracks/check_manager.cpp; sourceTree = SOURCE_ROOT; };
955DE88210042701006A4F3C /* check_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = check_manager.hpp; path = ../../tracks/check_manager.hpp; sourceTree = SOURCE_ROOT; };
955DE8871004273B006A4F3C /* check_structure.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = check_structure.cpp; path = ../../tracks/check_structure.cpp; sourceTree = SOURCE_ROOT; };
955DE8881004273B006A4F3C /* check_structure.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = check_structure.hpp; path = ../../tracks/check_structure.hpp; sourceTree = SOURCE_ROOT; };
955DE8891004273B006A4F3C /* checkline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = checkline.cpp; path = ../../tracks/checkline.cpp; sourceTree = SOURCE_ROOT; };
955DE88A1004273B006A4F3C /* checkline.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = checkline.hpp; path = ../../tracks/checkline.hpp; sourceTree = SOURCE_ROOT; };
95A118290F77EA3100B18B3D /* input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = input.hpp; path = ../../input/input.hpp; sourceTree = SOURCE_ROOT; };
95A1182A0F77EA3100B18B3D /* input_manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = input_manager.cpp; path = ../../input/input_manager.cpp; sourceTree = SOURCE_ROOT; };
95A1182B0F77EA3100B18B3D /* input_manager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = input_manager.hpp; path = ../../input/input_manager.hpp; sourceTree = SOURCE_ROOT; };
@@ -1795,14 +1804,20 @@
children = (
95CB476B0FF30EF400413BAE /* bezier_curve.cpp */,
95CB476A0FF30EF400413BAE /* bezier_curve.hpp */,
953789810FC7831400DD1F8E /* quad.cpp */,
953789800FC7831400DD1F8E /* quad.hpp */,
951C35800FC05BF400A48379 /* quad_graph.cpp */,
951C357F0FC05BF400A48379 /* quad_graph.hpp */,
955DE88110042701006A4F3C /* check_manager.cpp */,
955DE88210042701006A4F3C /* check_manager.hpp */,
955DE8871004273B006A4F3C /* check_structure.cpp */,
955DE8881004273B006A4F3C /* check_structure.hpp */,
955DE8891004273B006A4F3C /* checkline.cpp */,
955DE88A1004273B006A4F3C /* checkline.hpp */,
953789720FC7829100DD1F8E /* graph_node.cpp */,
953789710FC7829100DD1F8E /* graph_node.hpp */,
951C357E0FC05BF400A48379 /* quad_set.cpp */,
951C357D0FC05BF400A48379 /* quad_set.hpp */,
953789810FC7831400DD1F8E /* quad.cpp */,
953789800FC7831400DD1F8E /* quad.hpp */,
951C35800FC05BF400A48379 /* quad_graph.cpp */,
951C357F0FC05BF400A48379 /* quad_graph.hpp */,
953EAAAE0F30A4220000D57D /* terrain_info.cpp */,
953EAAAD0F30A4220000D57D /* terrain_info.hpp */,
95C2B1CF0F296545000D3E5D /* track.cpp */,
@@ -2327,6 +2342,9 @@
954E4C300FF98B6F0047FE3E /* three_d_animation.cpp in Sources */,
951BC65E0FFAF290006B5FF1 /* ipo.cpp in Sources */,
9516162D0FFFB12B004B16D8 /* kart_selection.cpp in Sources */,
955DE88310042701006A4F3C /* check_manager.cpp in Sources */,
955DE88C1004273B006A4F3C /* check_structure.cpp in Sources */,
955DE88D1004273B006A4F3C /* checkline.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2377,6 +2395,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
GCC_DEBUGGING_SYMBOLS = full;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_ENABLE_SYMBOL_SEPARATION = NO;