From 46a62c6fdbb9d903a1189193fcd15cbbd9a7682f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 5 Nov 2019 01:35:02 -0300 Subject: [PATCH] More clean up. --HG-- branch : dev --- include/eepp/scene/node.hpp | 11 +++--- src/eepp/maps/mapeditor/mapeditor.cpp | 36 +++++++++---------- .../maps/mapeditor/maplayerproperties.cpp | 8 ++--- .../maps/mapeditor/mapobjectproperties.cpp | 8 ++--- src/eepp/maps/mapeditor/tilemapproperties.cpp | 8 ++--- src/eepp/maps/mapeditor/uimap.cpp | 2 +- src/eepp/scene/scenemanager.cpp | 2 +- src/eepp/ui/tools/textureatlaseditor.cpp | 6 ++-- src/eepp/ui/tools/textureatlasnew.cpp | 5 ++- src/eepp/ui/uilistboxitem.cpp | 6 ++-- src/eepp/ui/uimenu.cpp | 12 +++---- src/eepp/ui/uimenucheckbox.cpp | 2 +- src/eepp/ui/uimenuitem.cpp | 2 +- src/eepp/ui/uimenusubmenu.cpp | 8 ++--- src/eepp/ui/uiradiobutton.cpp | 8 ++--- src/eepp/ui/uisliderbutton.cpp | 3 +- src/eepp/ui/uitab.cpp | 2 +- src/eepp/ui/uitablecell.cpp | 10 +++--- src/eepp/ui/uitabwidget.cpp | 2 +- src/eepp/ui/uitooltip.cpp | 2 +- src/eepp/ui/uiwinmenu.cpp | 2 +- src/test/eetest.cpp | 8 ++--- src/tools/uieditor/uieditor.cpp | 26 +++++--------- 23 files changed, 84 insertions(+), 95 deletions(-) diff --git a/include/eepp/scene/node.hpp b/include/eepp/scene/node.hpp index 6c3616e1f..652591b8e 100644 --- a/include/eepp/scene/node.hpp +++ b/include/eepp/scene/node.hpp @@ -215,18 +215,21 @@ class EE_API Node : public Transformable { Node * find( const std::string& id ) const; template - T * find( const std::string& id ) const - { + T * find( const std::string& id ) const { return reinterpret_cast( find( id ) ); } template - T * bind( const std::string& id, T*& ctrl ) - { + T * bind( const std::string& id, T*& ctrl ) { ctrl = find( id ); return ctrl; } + template + T * asType() { + return reinterpret_cast(this); + } + bool isReverseDraw() const; void setReverseDraw( bool reverseDraw ); diff --git a/src/eepp/maps/mapeditor/mapeditor.cpp b/src/eepp/maps/mapeditor/mapeditor.cpp index 3235fe7ca..caddccf54 100644 --- a/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/eepp/maps/mapeditor/mapeditor.cpp @@ -115,18 +115,18 @@ void MapEditor::createWinMenu() { UIPopUpMenu * PU3 = UIPopUpMenu::New(); PU3->setParent( mUIContainer ); - mChkShowGrid = reinterpret_cast( PU3->getItem( PU3->addCheckBox( "Show Grid" ) ) ); + mChkShowGrid = PU3->getItem( PU3->addCheckBox( "Show Grid" ) )->asType(); mChkShowGrid->setActive( true ); - mChkMarkTileOver = reinterpret_cast( PU3->getItem( PU3->addCheckBox( "Mark Tile Over" ) ) ); + mChkMarkTileOver = PU3->getItem( PU3->addCheckBox( "Mark Tile Over" ) )->asType(); - mChkShowBlocked = reinterpret_cast( PU3->getItem( PU3->addCheckBox( "Show Blocked" ) ) ); + mChkShowBlocked = PU3->getItem( PU3->addCheckBox( "Show Blocked" ) )->asType(); PU3->addSeparator(); - mUIWindow->addShortcut( KEY_KP_PLUS , KEYMOD_CTRL, reinterpret_cast ( PU3->getItem( PU3->add( "Zoom In", mTheme->getIconByName( "zoom-in" ) ) ) ) ); - mUIWindow->addShortcut( KEY_KP_MINUS, KEYMOD_CTRL, reinterpret_cast ( PU3->getItem( PU3->add( "Zoom Out", mTheme->getIconByName( "zoom-out" ) ) ) ) ); - mUIWindow->addShortcut( KEY_KP0 , KEYMOD_CTRL, reinterpret_cast ( PU3->getItem( PU3->add( "Normal Size", mTheme->getIconByName( "zoom-original" ) ) ) ) ); + mUIWindow->addShortcut( KEY_KP_PLUS , KEYMOD_CTRL, PU3->getItem( PU3->add( "Zoom In", mTheme->getIconByName( "zoom-in" ) ) )->asType() ); + mUIWindow->addShortcut( KEY_KP_MINUS, KEYMOD_CTRL, PU3->getItem( PU3->add( "Zoom Out", mTheme->getIconByName( "zoom-out" ) ) )->asType() ); + mUIWindow->addShortcut( KEY_KP0 , KEYMOD_CTRL, PU3->getItem( PU3->add( "Normal Size", mTheme->getIconByName( "zoom-original" ) ) )->asType() ); PU3->addSeparator(); PU3->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::viewMenuClick ) ); @@ -154,12 +154,12 @@ void MapEditor::createWinMenu() { PU5->addSeparator(); Uint32 LayerChkBoxIndex = PU5->addCheckBox( "Lights Enabled" ); - mLayerChkLights = reinterpret_cast ( PU5->getItem( LayerChkBoxIndex ) ); + mLayerChkLights = PU5->getItem( LayerChkBoxIndex )->asType(); PU5->addSeparator(); LayerChkBoxIndex = PU5->addCheckBox( "Visible" ); - mLayerChkVisible = reinterpret_cast ( PU5->getItem( LayerChkBoxIndex ) ); + mLayerChkVisible = PU5->getItem( LayerChkBoxIndex )->asType(); PU5->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::layerMenuClick ) ); WinMenu->addMenuButton( "Layer", PU5 ); @@ -895,7 +895,7 @@ void MapEditor::updateScroll() { } void MapEditor::mapOpen( const Event * Event ) { - UICommonDialog * CDL = reinterpret_cast ( Event->getNode() ); + UICommonDialog * CDL = Event->getNode()->asType(); if ( mUIMap->Map()->loadFromFile( CDL->getFullPath() ) ) { onMapLoad(); @@ -915,7 +915,7 @@ void MapEditor::onMapLoad() { } void MapEditor::mapSave( const Event * Event ) { - UICommonDialog * CDL = reinterpret_cast ( Event->getNode() ); + UICommonDialog * CDL = Event->getNode()->asType(); std::string path( CDL->getFullPath() ); @@ -930,7 +930,7 @@ void MapEditor::fileMenuClick( const Event * Event ) { if ( !Event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; - const String& txt = reinterpret_cast ( Event->getNode() )->getText(); + const String& txt = Event->getNode()->asType()->getText(); if ( "New..." == txt ) { createNewMap(); @@ -981,14 +981,14 @@ void MapEditor::viewMenuClick( const Event * Event ) { if ( !Event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; - const String& txt = reinterpret_cast ( Event->getNode() )->getText(); + const String& txt = Event->getNode()->asType()->getText(); if ( "Show Grid" == txt ) { - mUIMap->Map()->setDrawGrid( reinterpret_cast ( Event->getNode() )->isActive() ); + mUIMap->Map()->setDrawGrid( Event->getNode()->asType()->isActive() ); } else if ( "Mark Tile Over" == txt ) { - mUIMap->Map()->setDrawTileOver( reinterpret_cast ( Event->getNode() )->isActive() ); + mUIMap->Map()->setDrawTileOver( Event->getNode()->asType()->isActive() ); } else if ( "Show Blocked" == txt ) { - mUIMap->Map()->setShowBlocked( reinterpret_cast ( Event->getNode() )->isActive() ); + mUIMap->Map()->setShowBlocked( Event->getNode()->asType()->isActive() ); } else if ( "Zoom In" == txt ) { zoomIn(); } else if ( "Zoom Out" == txt ) { @@ -1060,7 +1060,7 @@ void MapEditor::mapMenuClick( const Event * Event ) { if ( !Event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; - const String& txt = reinterpret_cast ( Event->getNode() )->getText(); + const String& txt = Event->getNode()->asType()->getText(); if ( "New Texture Atlas..." == txt ) { UIWindow * tWin = UIWindow::New(); @@ -1089,7 +1089,7 @@ void MapEditor::layerMenuClick( const Event * Event ) { if ( !Event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; - const String& txt = reinterpret_cast ( Event->getNode() )->getText(); + const String& txt = Event->getNode()->asType()->getText(); if ( "Add Tile Layer..." == txt ) { eeNew( UIMapLayerNew, ( mUIMap, MAP_LAYER_TILED, cb::Make1( this, &MapEditor::onLayerAdd ) ) ); @@ -1182,7 +1182,7 @@ void MapEditor::refreshLayersList() { } void MapEditor::cextureAtlasOpen( const Event * Event ) { - UICommonDialog * CDL = reinterpret_cast ( Event->getNode() ); + UICommonDialog * CDL = Event->getNode()->asType(); std::string sgname = FileSystem::fileRemoveExtension( FileSystem::fileNameFromPath( CDL->getFullPath() ) ); diff --git a/src/eepp/maps/mapeditor/maplayerproperties.cpp b/src/eepp/maps/mapeditor/maplayerproperties.cpp index 4916f03ed..e5a7b448b 100644 --- a/src/eepp/maps/mapeditor/maplayerproperties.cpp +++ b/src/eepp/maps/mapeditor/maplayerproperties.cpp @@ -113,8 +113,8 @@ void MapLayerProperties::saveProperties() { for ( Uint32 i = 0; i < mGenGrid->getCount(); i++ ) { UITableCell * Cell = mGenGrid->getCell( i ); - UITextInput * Input = reinterpret_cast( Cell->getCell( 1 ) ); - UITextInput * Input2 = reinterpret_cast( Cell->getCell( 3 ) ); + UITextInput * Input = Cell->getCell( 1 )->asType(); + UITextInput * Input2 = Cell->getCell( 3 )->asType(); if ( NULL != Cell && Input->getText().size() && Input2->getText().size() ) { mLayer->addProperty( Input->getText(), Input2->getText() ); @@ -128,8 +128,8 @@ void MapLayerProperties::loadProperties() { for ( MapLayer::PropertiesMap::iterator it = Proper.begin(); it != Proper.end(); ++it ) { UITableCell * Cell = createCell(); - UITextInput * Input = reinterpret_cast( Cell->getCell( 1 ) ); - UITextInput * Input2 = reinterpret_cast( Cell->getCell( 3 ) ); + UITextInput * Input = Cell->getCell( 1 )->asType(); + UITextInput * Input2 = Cell->getCell( 3 )->asType(); Input->setText( it->first ); Input2->setText( it->second ); diff --git a/src/eepp/maps/mapeditor/mapobjectproperties.cpp b/src/eepp/maps/mapeditor/mapobjectproperties.cpp index 5eed8b49c..36f4c053e 100644 --- a/src/eepp/maps/mapeditor/mapobjectproperties.cpp +++ b/src/eepp/maps/mapeditor/mapobjectproperties.cpp @@ -117,8 +117,8 @@ void MapObjectProperties::saveProperties() { for ( Uint32 i = 0; i < mGenGrid->getCount(); i++ ) { UITableCell * Cell = mGenGrid->getCell( i ); - UITextInput * Input = reinterpret_cast( Cell->getCell( 1 ) ); - UITextInput * Input2 = reinterpret_cast( Cell->getCell( 3 ) ); + UITextInput * Input = Cell->getCell( 1 )->asType(); + UITextInput * Input2 = Cell->getCell( 3 )->asType(); if ( NULL != Cell && Input->getText().size() && Input2->getText().size() ) { mObj->addProperty( Input->getText(), Input2->getText() ); @@ -132,8 +132,8 @@ void MapObjectProperties::loadProperties() { for ( GameObjectObject::PropertiesMap::iterator it = Proper.begin(); it != Proper.end(); ++it ) { UITableCell * Cell = createCell(); - UITextInput * Input = reinterpret_cast( Cell->getCell( 1 ) ); - UITextInput * Input2 = reinterpret_cast( Cell->getCell( 3 ) ); + UITextInput * Input = Cell->getCell( 1 )->asType(); + UITextInput * Input2 = Cell->getCell( 3 )->asType(); Input->setText( it->first ); Input2->setText( it->second ); diff --git a/src/eepp/maps/mapeditor/tilemapproperties.cpp b/src/eepp/maps/mapeditor/tilemapproperties.cpp index a248bc9f8..f582c76bf 100644 --- a/src/eepp/maps/mapeditor/tilemapproperties.cpp +++ b/src/eepp/maps/mapeditor/tilemapproperties.cpp @@ -179,8 +179,8 @@ void TileMapProperties::saveProperties() { for ( Uint32 i = 0; i < mGenGrid->getCount(); i++ ) { UITableCell * Cell = mGenGrid->getCell( i ); - UITextInput * Input = reinterpret_cast( Cell->getCell( 1 ) ); - UITextInput * Input2 = reinterpret_cast( Cell->getCell( 3 ) ); + UITextInput * Input = Cell->getCell( 1 )->asType(); + UITextInput * Input2 = Cell->getCell( 3 )->asType(); if ( NULL != Cell && Input->getText().size() && Input2->getText().size() ) { mMap->addProperty( Input->getText(), Input2->getText() ); @@ -194,8 +194,8 @@ void TileMapProperties::loadProperties() { for ( TileMap::PropertiesMap::iterator it = Proper.begin(); it != Proper.end(); ++it ) { UITableCell * Cell = createCell(); - UITextInput * Input = reinterpret_cast( Cell->getCell( 1 ) ); - UITextInput * Input2 = reinterpret_cast( Cell->getCell( 3 ) ); + UITextInput * Input = Cell->getCell( 1 )->asType(); + UITextInput * Input2 = Cell->getCell( 3 )->asType(); Input->setText( it->first ); Input2->setText( it->second ); diff --git a/src/eepp/maps/mapeditor/uimap.cpp b/src/eepp/maps/mapeditor/uimap.cpp index 533d063d1..054b81c82 100644 --- a/src/eepp/maps/mapeditor/uimap.cpp +++ b/src/eepp/maps/mapeditor/uimap.cpp @@ -559,7 +559,7 @@ void UIMap::objItemClick( const Event * Event ) { return; if ( NULL != mSelObj && NULL != mCurLayer && mCurLayer->getType() == MAP_LAYER_OBJECT && mSelObj->getLayer() == mCurLayer ) { - const String& txt = reinterpret_cast ( Event->getNode() )->getText(); + const String& txt = Event->getNode()->asType()->getText(); MapObjectLayer * tLayer = reinterpret_cast( mCurLayer ); diff --git a/src/eepp/scene/scenemanager.cpp b/src/eepp/scene/scenemanager.cpp index f43c3ddf7..ed6e8222c 100644 --- a/src/eepp/scene/scenemanager.cpp +++ b/src/eepp/scene/scenemanager.cpp @@ -52,7 +52,7 @@ UISceneNode * SceneManager::getUISceneNode() { SceneNode * sceneNode = (*it); if ( sceneNode->isUISceneNode() ) { - mUISceneNode = reinterpret_cast( sceneNode ); + mUISceneNode = sceneNode->asType(); break; } } diff --git a/src/eepp/ui/tools/textureatlaseditor.cpp b/src/eepp/ui/tools/textureatlaseditor.cpp index 61e6c3cc4..d3ba5648d 100644 --- a/src/eepp/ui/tools/textureatlaseditor.cpp +++ b/src/eepp/ui/tools/textureatlaseditor.cpp @@ -249,7 +249,7 @@ void TextureAtlasEditor::fileMenuClick( const Event * Event ) { if ( !Event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; - const String& txt = reinterpret_cast ( Event->getNode() )->getText(); + const String& txt = Event->getNode()->asType()->getText(); if ( "New..." == txt ) { eeNew( TextureAtlasNew, ( cb::Make1( this, &TextureAtlasEditor::onTextureAtlasCreate ) ) ); @@ -393,15 +393,13 @@ void TextureAtlasEditor::update() { } void TextureAtlasEditor::openTextureAtlas( const Event * Event ) { - UICommonDialog * CDL = reinterpret_cast ( Event->getNode() ); - eeSAFE_DELETE( mTextureAtlasLoader ); bool threaded = true; #if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN threaded = false; #endif - mTextureAtlasLoader = TextureAtlasLoader::New( CDL->getFullPath(), threaded, cb::Make1( this, &TextureAtlasEditor::onTextureAtlasLoaded ) ); + mTextureAtlasLoader = TextureAtlasLoader::New( Event->getNode()->asType()->getFullPath(), threaded, cb::Make1( this, &TextureAtlasEditor::onTextureAtlasLoaded ) ); } void TextureAtlasEditor::onTextureAtlasLoaded( TextureAtlasLoader * ) { diff --git a/src/eepp/ui/tools/textureatlasnew.cpp b/src/eepp/ui/tools/textureatlasnew.cpp index 46c231610..18b5be28e 100644 --- a/src/eepp/ui/tools/textureatlasnew.cpp +++ b/src/eepp/ui/tools/textureatlasnew.cpp @@ -148,8 +148,7 @@ static bool isValidExtension( const std::string& ext ) { } void TextureAtlasNew::textureAtlasSave( const Event * Event ) { - UICommonDialog * CDL = reinterpret_cast ( Event->getNode() ); - std::string FPath( CDL->getFullPath() ); + std::string FPath( Event->getNode()->asType()->getFullPath() ); if ( !FileSystem::isDirectory( FPath ) ) { Int32 w = 0, h = 0, b; @@ -201,7 +200,7 @@ void TextureAtlasNew::onDialogFolderSelect( const Event * event ) { } void TextureAtlasNew::onSelectFolder( const Event * Event ) { - UICommonDialog * CDL = reinterpret_cast ( Event->getNode() ); + UICommonDialog * CDL = Event->getNode()->asType(); UIMessageBox * MsgBox; std::string FPath( CDL->getFullPath() ); FileSystem::dirPathAddSlashAtEnd( FPath ); diff --git a/src/eepp/ui/uilistboxitem.cpp b/src/eepp/ui/uilistboxitem.cpp index 5f220bb9f..495e238e2 100644 --- a/src/eepp/ui/uilistboxitem.cpp +++ b/src/eepp/ui/uilistboxitem.cpp @@ -47,7 +47,7 @@ Uint32 UIListBoxItem::onMouseUp( const Vector2i& Pos, const Uint32& Flags ) { UITextView::onMouseUp( Pos, Flags ); if ( mEnabled && mVisible ) { - UIListBox * LBParent = reinterpret_cast ( getParent()->getParent() ); + UIListBox * LBParent = getParent()->getParent()->asType(); if ( Flags & EE_BUTTONS_WUWD && LBParent->getVerticalScrollBar()->isVisible() ) { // Manage click can delete _this_ @@ -60,7 +60,7 @@ Uint32 UIListBoxItem::onMouseUp( const Vector2i& Pos, const Uint32& Flags ) { Uint32 UIListBoxItem::onMouseClick( const Vector2i& Pos, const Uint32& Flags ) { if ( Flags & EE_BUTTONS_LRM ) { - reinterpret_cast ( getParent()->getParent() )->itemClicked( this ); + getParent()->getParent()->asType()->itemClicked( this ); select(); } @@ -69,7 +69,7 @@ Uint32 UIListBoxItem::onMouseClick( const Vector2i& Pos, const Uint32& Flags ) { } void UIListBoxItem::select() { - UIListBox * LBParent = reinterpret_cast ( getParent()->getParent() ); + UIListBox * LBParent = getParent()->getParent()->asType(); bool wasSelected = 0 != ( mNodeFlags & NODE_FLAG_SELECTED ); diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 925e5e640..696762dbb 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -106,7 +106,7 @@ Uint32 UIMenu::addSubMenu( const String& Text, Drawable * Icon, UIMenu * SubMenu bool UIMenu::checkControlSize( UINode * Control, const bool& Resize ) { if ( Control->isType( UI_TYPE_MENUITEM ) ) { - UIMenuItem * tItem = reinterpret_cast ( Control ); + UIMenuItem * tItem = Control->asType(); if ( NULL != tItem->getIcon() && tItem->getIconHorizontalMargin() + tItem->getIcon()->getSize().getWidth() > (Int32)mBiggestIcon ) { mBiggestIcon = tItem->getIconHorizontalMargin() + tItem->getIcon()->getSize().getWidth(); @@ -116,7 +116,7 @@ bool UIMenu::checkControlSize( UINode * Control, const bool& Resize ) { if ( Control->isType( UI_TYPE_MENUSUBMENU ) ) { Int32 textWidth = tItem->getTextBox()->getTextWidth(); - UIMenuSubMenu * tMenu = reinterpret_cast ( tItem ); + UIMenuSubMenu * tMenu = tItem->asType(); if ( textWidth + PixelDensity::dpToPxI( mBiggestIcon ) + tMenu->getArrow()->getPixelsSize().getWidth() + PixelDensity::dpToPxI( mStyleConfig.MinRightMargin ) > (Int32)mMaxWidth ) { mMaxWidth = textWidth + mRealPadding.Left + mRealPadding.Right + PixelDensity::dpToPxI( mBiggestIcon + mStyleConfig.MinRightMargin ) + tMenu->getArrow()->getPixelsSize().getWidth(); @@ -190,7 +190,7 @@ UINode * UIMenu::getItem( const Uint32& Index ) { UINode * UIMenu::getItem( const String& Text ) { for ( Uint32 i = 0; i < mItems.size(); i++ ) { if ( mItems[i]->isType( UI_TYPE_MENUITEM ) ) { - UIMenuItem * tMenuItem = reinterpret_cast( mItems[i] ); + UIMenuItem * tMenuItem = mItems[i]->asType(); if ( tMenuItem->getText() == Text ) return tMenuItem; @@ -261,7 +261,7 @@ void UIMenu::insert( UINode * Control, const Uint32& Index ) { bool UIMenu::isSubMenu( Node * Ctrl ) { for ( Uint32 i = 0; i < mItems.size(); i++ ) { if ( NULL != mItems[i] && mItems[i]->isType( UI_TYPE_MENUSUBMENU ) ) { - UIMenuSubMenu * tMenu = reinterpret_cast ( mItems[i] ); + UIMenuSubMenu * tMenu = mItems[i]->asType(); if ( tMenu->getSubMenu() == Ctrl ) return true; @@ -378,7 +378,7 @@ bool UIMenu::hide() { void UIMenu::setItemSelected( UINode * Item ) { if ( NULL != mItemSelected ) { if ( mItemSelected->isType( UI_TYPE_MENUSUBMENU ) ) { - UIMenuSubMenu * tMenu = reinterpret_cast ( mItemSelected ); + UIMenuSubMenu * tMenu = mItemSelected->asType(); if ( NULL != tMenu->getSubMenu() ) tMenu->getSubMenu()->hide(); @@ -473,7 +473,7 @@ Uint32 UIMenu::onKeyDown( const KeyEvent& Event ) { break; case KEY_RIGHT: if ( NULL != mItemSelected && ( mItemSelected->isType( UI_TYPE_MENUSUBMENU ) ) ) { - UIMenuSubMenu * tMenu = reinterpret_cast ( mItemSelected ); + UIMenuSubMenu * tMenu = mItemSelected->asType(); tMenu->showSubMenu(); } diff --git a/src/eepp/ui/uimenucheckbox.cpp b/src/eepp/ui/uimenucheckbox.cpp index 0f48093bd..993e96804 100644 --- a/src/eepp/ui/uimenucheckbox.cpp +++ b/src/eepp/ui/uimenucheckbox.cpp @@ -77,7 +77,7 @@ void UIMenuCheckBox::setActive( const bool& active ) { } if ( oActive != active ) { - UIMenu * Menu = reinterpret_cast ( getParent() ); + UIMenu * Menu = getParent()->asType(); if ( !Menu->checkControlSize( this ) ) { if ( NULL != getIcon()->getDrawable() ) { diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index b6b60f6f0..4ca7a8667 100644 --- a/src/eepp/ui/uimenuitem.cpp +++ b/src/eepp/ui/uimenuitem.cpp @@ -39,7 +39,7 @@ void UIMenuItem::setTheme( UITheme * Theme ) { Uint32 UIMenuItem::onMouseOver( const Vector2i& Pos, const Uint32& Flags ) { UIPushButton::onMouseOver( Pos, Flags ); - reinterpret_cast ( getParent() )->setItemSelected( this ); + getParent()->asType()->setItemSelected( this ); return 1; } diff --git a/src/eepp/ui/uimenusubmenu.cpp b/src/eepp/ui/uimenusubmenu.cpp index 45d8d1c76..aaa167ee2 100644 --- a/src/eepp/ui/uimenusubmenu.cpp +++ b/src/eepp/ui/uimenusubmenu.cpp @@ -106,9 +106,9 @@ void UIMenuSubMenu::showSubMenu() { Vector2f Pos = getPixelsPosition(); nodeToWorldTranslation( Pos ); - Pos.x += mSize.getWidth() + reinterpret_cast ( getParent() )->getPadding().Right; + Pos.x += mSize.getWidth() + getParent()->asType()->getPadding().Right; - UIMenu::fixMenuPos( Pos, mSubMenu, reinterpret_cast ( getParent() ), this ); + UIMenu::fixMenuPos( Pos, mSubMenu, getParent()->asType(), this ); mSubMenu->getParent()->worldToNode( Pos ); mSubMenu->setPixelsPosition( Pos ); @@ -142,7 +142,7 @@ void UIMenuSubMenu::onSubMenuFocusLoss( const Event * ) { } if ( mSubMenu->mClickHide ) { - UIMenu * parentMenu = reinterpret_cast( getParent() ); + UIMenu * parentMenu = getParent()->asType(); if ( !parentMenu->isSubMenu( focusCtrl ) && focusCtrl != this ) { parentMenu->sendCommonEvent( Event::OnHideByClick ); @@ -154,7 +154,7 @@ void UIMenuSubMenu::onSubMenuFocusLoss( const Event * ) { } void UIMenuSubMenu::onHideByClick( const Event * ) { - UIMenu * tMenu = reinterpret_cast( getParent() ); + UIMenu * tMenu = getParent()->asType(); tMenu->mClickHide = true; tMenu->sendCommonEvent( Event::OnHideByClick ); diff --git a/src/eepp/ui/uiradiobutton.cpp b/src/eepp/ui/uiradiobutton.cpp index 02025c285..8d5ed723a 100644 --- a/src/eepp/ui/uiradiobutton.cpp +++ b/src/eepp/ui/uiradiobutton.cpp @@ -160,7 +160,7 @@ void UIRadioButton::setActive( const bool& active ) { while ( NULL != tChild ) { if ( tChild->isType( UI_TYPE_RADIOBUTTON ) ) { if ( tChild != this ) { - UIRadioButton * tRB = reinterpret_cast ( tChild ); + UIRadioButton * tRB = tChild->asType(); if ( tRB->isActive() ) tRB->setActive( false ); @@ -179,7 +179,7 @@ bool UIRadioButton::checkActives() { while ( NULL != tChild ) { if ( tChild->isType( UI_TYPE_RADIOBUTTON ) ) { if ( tChild != this ) { - UIRadioButton * tRB = reinterpret_cast ( tChild ); + UIRadioButton * tRB = tChild->asType(); if ( tRB->isActive() ) return true; @@ -202,7 +202,7 @@ void UIRadioButton::autoActivate() { while ( NULL != tChild ) { if ( tChild->isType( UI_TYPE_RADIOBUTTON ) ) { if ( tChild != this ) { - UIRadioButton * tRB = reinterpret_cast ( tChild ); + UIRadioButton * tRB = tChild->asType(); if ( tRB->isActive() ) { return; @@ -290,7 +290,7 @@ Uint32 UIRadioButton::onKeyDown( const KeyEvent& Event ) { void UIRadioButton::onAlphaChange() { UITextView::onAlphaChange(); - + mActiveButton->setAlpha( mAlpha ); mInactiveButton->setAlpha( mAlpha ); } diff --git a/src/eepp/ui/uisliderbutton.cpp b/src/eepp/ui/uisliderbutton.cpp index 5457c2000..435edaf73 100644 --- a/src/eepp/ui/uisliderbutton.cpp +++ b/src/eepp/ui/uisliderbutton.cpp @@ -19,8 +19,7 @@ UISliderButton::~UISliderButton() { void UISliderButton::onPositionChange() { UIWidget::onPositionChange(); - UISlider * Slider = reinterpret_cast ( mParentCtrl ); - Slider->fixSliderPos(); + mParentCtrl->asType()->fixSliderPos(); } }}} diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index ceede2500..78324c7ec 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -32,7 +32,7 @@ bool UITab::isType( const Uint32& type ) const { UITabWidget * UITab::getTabWidget() { if ( NULL != getParent() && NULL != getParent()->getParent() && getParent()->getParent()->isType( UI_TYPE_TABWIDGET ) ) { - return reinterpret_cast ( getParent()->getParent() ); + return getParent()->getParent()->asType(); } return NULL; diff --git a/src/eepp/ui/uitablecell.cpp b/src/eepp/ui/uitablecell.cpp index 9631519e5..c354bbe9b 100644 --- a/src/eepp/ui/uitablecell.cpp +++ b/src/eepp/ui/uitablecell.cpp @@ -32,7 +32,7 @@ void UITableCell::setTheme( UITheme * Theme ) { } UITable * UITableCell::gridParent() const { - return reinterpret_cast ( mParentCtrl->getParent() ); + return mParentCtrl->getParent()->asType(); } void UITableCell::setCell( const Uint32& CollumnIndex, UINode * Ctrl ) { @@ -73,7 +73,7 @@ void UITableCell::fixCell() { } void UITableCell::select() { - UITable * MyParent = reinterpret_cast ( getParent()->getParent() ); + UITable * MyParent = getParent()->getParent()->asType(); if ( MyParent->getItemSelected() != this ) { if ( NULL != MyParent->getItemSelected() ) @@ -131,7 +131,7 @@ Uint32 UITableCell::onMessage( const NodeMessage * Msg ) { } case NodeMessage::MouseUp: { - UITable * MyParent = reinterpret_cast ( getParent()->getParent() ); + UITable * MyParent = getParent()->getParent()->asType(); if ( ( Msg->getFlags() & EE_BUTTONS_WUWD ) && MyParent->getVerticalScrollBar()->isVisible() ) { MyParent->getVerticalScrollBar()->getSlider()->manageClick( Msg->getFlags() ); @@ -145,7 +145,7 @@ Uint32 UITableCell::onMessage( const NodeMessage * Msg ) { } void UITableCell::onAutoSize() { - UITable * MyParent = reinterpret_cast ( getParent()->getParent() ); + UITable * MyParent = getParent()->getParent()->asType(); setInternalSize( Sizef( MyParent->mTotalWidth, MyParent->mRowHeight ) ); } @@ -165,7 +165,7 @@ void UITableCell::onParentChange() { void UITableCell::onAlphaChange() { if ( mEnabled && mVisible ) { - UITable * MyParent = reinterpret_cast ( getParent()->getParent() ); + UITable * MyParent = getParent()->getParent()->asType(); if ( NULL != MyParent && MyParent->getAlpha() != mAlpha ) { setAlpha( MyParent->getAlpha() ); diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index ae5885b72..1b8887edb 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -355,7 +355,7 @@ UITab * UITabWidget::getTab( const Uint32& Index ) { UITab * UITabWidget::getTab( const String& Text ) { for ( Uint32 i = 0; i < mTabs.size(); i++ ) { if ( mTabs[i]->isType( UI_TYPE_TAB ) ) { - UITab * tTab = reinterpret_cast( mTabs[i] ); + UITab * tTab = mTabs[i]->asType(); if ( tTab->getText() == Text ) return tTab; diff --git a/src/eepp/ui/uitooltip.cpp b/src/eepp/ui/uitooltip.cpp index 24520c9a9..a1eb7f517 100644 --- a/src/eepp/ui/uitooltip.cpp +++ b/src/eepp/ui/uitooltip.cpp @@ -43,7 +43,7 @@ UITooltip::~UITooltip() { eeSAFE_DELETE( mTextCache ); if ( NULL != mTooltipOf && mTooltipOf->isWidget() ) { - reinterpret_cast( mTooltipOf )->tooltipRemove(); + mTooltipOf->asType()->tooltipRemove(); } } diff --git a/src/eepp/ui/uiwinmenu.cpp b/src/eepp/ui/uiwinmenu.cpp index c26985483..47b233c5f 100644 --- a/src/eepp/ui/uiwinmenu.cpp +++ b/src/eepp/ui/uiwinmenu.cpp @@ -226,7 +226,7 @@ Uint32 UIWinMenu::onMessage( const NodeMessage * Msg ) { case NodeMessage::MouseOver: { if ( Msg->getSender()->isType( UI_TYPE_SELECTBUTTON ) ) { - UISelectButton * tbut = reinterpret_cast ( Msg->getSender() ); + UISelectButton * tbut = Msg->getSender()->asType(); UIPopUpMenu * tpop = getMenuFromButton( tbut ); Vector2f pos( tbut->getPosition().x, tbut->getPosition().y + tbut->getSize().getHeight() ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index fbd3b7d78..4e5cabb33 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -490,7 +490,7 @@ void EETest::createBaseUI() { //w->setBackgroundColor( UIState::StateFlagHover, Color::Yellow ); //w->setBackgroundColor( UIState::StateFlagPressed, Color::Red ); - C = reinterpret_cast ( C->getParent() ); + C = C->getParent()->asType(); Menu = UIPopUpMenu::New(); Menu->add( "New", mTheme->getIconByName( "document-new" ) ); @@ -990,7 +990,7 @@ void EETest::createDecoratedWindow() { if ( NULL == win ) return; - UIMenuItem* menuItem = reinterpret_cast ( Event->getNode() ); + UIMenuItem* menuItem = Event->getNode()->asType(); const String& txt = menuItem->getText(); if ( "Hide Border" == txt ) { @@ -1055,7 +1055,7 @@ void EETest::onItemClick( const Event * Event ) { if ( !Event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; - const String& txt = reinterpret_cast ( Event->getNode() )->getText(); + const String& txt = Event->getNode()->asType()->getText(); if ( "Show Screen 1" == txt ) { setScreen( 0 ); @@ -1078,7 +1078,7 @@ void EETest::onItemClick( const Event * Event ) { mWindow->stopTextInput(); } } else if ( "Show Window" == txt ) { - UIMenuCheckBox * Chk = reinterpret_cast ( Event->getNode() ); + UIMenuCheckBox * Chk = Event->getNode()->asType(); C->toFront(); C->setVisible( true ); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index 989e2f5a8..36198cd64 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -245,7 +245,7 @@ void onRecentProjectClick( const Event * event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; - const String& txt = reinterpret_cast ( event->getNode() )->getText(); + const String& txt = event->getNode()->asType()->getText(); std::string path( txt.toUtf8() ); if ( FileSystem::fileExists( path ) && !FileSystem::isDirectory( path ) ) { @@ -335,7 +335,7 @@ void onLayoutSelected( const Event * event ) { if ( !event->getNode()->isType( UI_TYPE_MENUCHECKBOX) ) return; - const String& txt = reinterpret_cast ( event->getNode() )->getText(); + const String& txt = event->getNode()->asType()->getText(); UIPopUpMenu * uiLayoutsMenu; @@ -629,40 +629,30 @@ void mainLoop() { } void imagePathOpen( const Event * event ) { - UICommonDialog * CDL = reinterpret_cast ( event->getNode() ); - - loadImagesFromFolder( CDL->getFullPath() ); + loadImagesFromFolder( event->getNode()->asType()->getFullPath() ); } void fontPathOpen( const Event * event ) { - UICommonDialog * CDL = reinterpret_cast ( event->getNode() ); - - loadFontsFromFolder( CDL->getFullPath() ); + loadFontsFromFolder( event->getNode()->asType()->getFullPath() ); } void styleSheetPathOpen( const Event * event ) { - UICommonDialog * CDL = reinterpret_cast ( event->getNode() ); - - loadStyleSheet( CDL->getFullPath() ); + loadStyleSheet( event->getNode()->asType()->getFullPath() ); } void layoutOpen( const Event * event ) { - UICommonDialog * CDL = reinterpret_cast ( event->getNode() ); - - loadLayout( CDL->getFullPath() ); + loadLayout( event->getNode()->asType()->getFullPath() ); } void projectOpen( const Event * event ) { - UICommonDialog * CDL = reinterpret_cast ( event->getNode() ); - - loadProject( CDL->getFullPath() ); + loadProject( event->getNode()->asType()->getFullPath() ); } void fileMenuClick( const Event * event ) { if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) return; - const String& txt = reinterpret_cast ( event->getNode() )->getText(); + const String& txt = event->getNode()->asType()->getText(); UITheme * prevTheme = UIThemeManager::instance()->getDefaultTheme(); UIThemeManager::instance()->setDefaultTheme( theme );