diff --git a/src/guiengine/widget.hpp b/src/guiengine/widget.hpp index d59e55ddd..1e957a807 100644 --- a/src/guiengine/widget.hpp +++ b/src/guiengine/widget.hpp @@ -196,7 +196,17 @@ namespace GUIEngine return out; #endif } - + + template const T* getIrrlichtElement() const + { + #if defined(WIN32) || defined(NDEBUG) + return static_cast(m_element); + #else + T* out = dynamic_cast(m_element); + return out; + #endif + } + IGUIElement* getIrrlichtElement() { return m_element; } void setParent(IGUIElement* parent); diff --git a/src/guiengine/widgets/list_widget.cpp b/src/guiengine/widgets/list_widget.cpp index 654c99dbb..f15d2843c 100644 --- a/src/guiengine/widgets/list_widget.cpp +++ b/src/guiengine/widgets/list_widget.cpp @@ -32,7 +32,7 @@ void ListWidget::add() void ListWidget::clear() { - IGUIListBox* list = dynamic_cast(m_element); + IGUIListBox* list = getIrrlichtElement(); assert(list != NULL); list->clear(); @@ -40,20 +40,20 @@ void ListWidget::clear() void ListWidget::addItem(const char* item) { - IGUIListBox* list = dynamic_cast(m_element); + IGUIListBox* list = getIrrlichtElement(); assert(list != NULL); list->addItem( stringw(item).c_str() ); } int ListWidget::getSelection() const { - IGUIListBox* list = dynamic_cast(m_element); + const IGUIListBox* list = getIrrlichtElement(); assert(list != NULL); return list->getSelected(); } std::string ListWidget::getSelectionName() const { - IGUIListBox* list = dynamic_cast(m_element); + const IGUIListBox* list = getIrrlichtElement(); assert(list != NULL); return stringc( list->getListItem( list->getSelected() ) ).c_str(); } diff --git a/src/guiengine/widgets/text_box_widget.cpp b/src/guiengine/widgets/text_box_widget.cpp index ef72d604e..3e5e3c351 100644 --- a/src/guiengine/widgets/text_box_widget.cpp +++ b/src/guiengine/widgets/text_box_widget.cpp @@ -39,7 +39,7 @@ void TextBoxWidget::add() // ----------------------------------------------------------------------------- stringw TextBoxWidget::getText() const { - IGUIEditBox* textCtrl = dynamic_cast(m_element); + const IGUIEditBox* textCtrl = Widget::getIrrlichtElement(); assert(textCtrl != NULL); return stringw(textCtrl->getText());