From 58cbdebb3bfca93c2b277f6a1995c69c8cbf334d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Thu, 23 Feb 2017 00:08:38 -0300 Subject: [PATCH] More fixes. --HG-- branch : dev --- include/eepp/gaming/tilemap.hpp | 22 ++++---- include/eepp/ui/uispinbox.hpp | 2 + src/eepp/gaming/mapeditor/mapeditor.cpp | 4 +- src/eepp/gaming/mapeditor/uimap.cpp | 5 +- src/eepp/gaming/tilemap.cpp | 52 +++++++++---------- src/eepp/ui/tools/textureatlaseditor.cpp | 2 +- .../ui/tools/textureatlassubtextureeditor.cpp | 8 ++- src/eepp/ui/uicheckbox.cpp | 8 ++- src/eepp/ui/uicontrol.cpp | 2 +- src/eepp/ui/uicontrolanim.cpp | 2 +- src/eepp/ui/uispinbox.cpp | 6 +++ 11 files changed, 65 insertions(+), 48 deletions(-) diff --git a/include/eepp/gaming/tilemap.hpp b/include/eepp/gaming/tilemap.hpp index 411c8d095..ff0786f05 100644 --- a/include/eepp/gaming/tilemap.hpp +++ b/include/eepp/gaming/tilemap.hpp @@ -284,27 +284,27 @@ class EE_API TileMap { virtual GameObject * CreateGameObject( const Uint32& Type, const Uint32& Flags, MapLayer * Layer, const Uint32& DataId = 0 ); - void CalcTilesClip(); + void calcTilesClip(); - void Clamp(); + void clamp(); - void GetMouseOverTile(); + void getMouseOverTile(); - void GridDraw(); + void gridDraw(); - void MouseOverDraw(); + void mouseOverDraw(); - void DeleteLayers(); + void deleteLayers(); - std::vector GetTextureAtlases(); + std::vector getTextureAtlases(); - void CreateEmptyTile(); + void createEmptyTile(); - void UpdateScreenAABB(); + void updateScreenAABB(); - void CreateLightManager(); + void createLightManager(); - virtual void OnMapLoaded(); + virtual void onMapLoaded(); }; }} diff --git a/include/eepp/ui/uispinbox.hpp b/include/eepp/ui/uispinbox.hpp index 7dc42b649..88c157b69 100644 --- a/include/eepp/ui/uispinbox.hpp +++ b/include/eepp/ui/uispinbox.hpp @@ -77,6 +77,8 @@ class EE_API UISpinBox : public UIComplexControl { void adjustChilds(); void internalValue( const Float& Val, const bool& Force = false ); + + virtual void onSizeChange(); virtual void onAlphaChange(); }; diff --git a/src/eepp/gaming/mapeditor/mapeditor.cpp b/src/eepp/gaming/mapeditor/mapeditor.cpp index f6edc31f3..cc2b6dfa3 100644 --- a/src/eepp/gaming/mapeditor/mapeditor.cpp +++ b/src/eepp/gaming/mapeditor/mapeditor.cpp @@ -779,7 +779,7 @@ void MapEditor::CreateNewMap() { } void MapEditor::CreateNewEmptyMap() { - mUIMap->Map()->create( Sizei( 100, 100 ), 16, Sizei( 32, 32 ), MAP_EDITOR_DEFAULT_FLAGS | MAP_FLAG_LIGHTS_ENABLED, mUIMap->getSize() ); + mUIMap->Map()->create( Sizei( 100, 100 ), 16, Sizei( 32, 32 ), MAP_EDITOR_DEFAULT_FLAGS | MAP_FLAG_LIGHTS_ENABLED, mUIMap->getRealSize() ); } void MapEditor::MapCreated() { @@ -854,7 +854,7 @@ void MapEditor::MapOpen( const UIEvent * Event ) { void MapEditor::OnMapLoad() { mCurLayer = NULL; - mUIMap->Map()->setViewSize( mUIMap->getSize() ); + mUIMap->Map()->setViewSize( mUIMap->getRealSize() ); MapCreated(); diff --git a/src/eepp/gaming/mapeditor/uimap.cpp b/src/eepp/gaming/mapeditor/uimap.cpp index b74c8d1e1..bd5ae45aa 100644 --- a/src/eepp/gaming/mapeditor/uimap.cpp +++ b/src/eepp/gaming/mapeditor/uimap.cpp @@ -31,8 +31,9 @@ UIMap::UIMap( const UIComplexControl::CreateParams& Params, UITheme * Theme, Til mMap->setBackColor( ColorA( 100, 100, 100, 100 ) ); mMap->setGridLinesColor( ColorA( 150, 150, 150, 150 ) ); - + mMap->setScale( getPixelDensity() ); mMap->setDrawCallback( cb::Make0( this, &UIMap::mapDraw ) ); + mMap->setViewSize( mRealSize ); mDragButton = EE_BUTTON_MMASK; setDragEnabled( true ); @@ -319,7 +320,7 @@ void UIMap::tryToSelectLight() { void UIMap::onSizeChange() { if ( NULL != mMap ) { mMap->setPosition( mScreenPos ); - mMap->setViewSize( mSize ); + mMap->setViewSize( mRealSize ); } UIComplexControl::onSizeChange(); diff --git a/src/eepp/gaming/tilemap.cpp b/src/eepp/gaming/tilemap.cpp index d515897dd..f951590c5 100644 --- a/src/eepp/gaming/tilemap.cpp +++ b/src/eepp/gaming/tilemap.cpp @@ -47,12 +47,12 @@ TileMap::TileMap() : } TileMap::~TileMap() { - DeleteLayers(); + deleteLayers(); disableForcedHeaders(); } void TileMap::reset() { - DeleteLayers(); + deleteLayers(); mWindow = NULL; mLayers = NULL; @@ -73,7 +73,7 @@ void TileMap::disableForcedHeaders() { eeSAFE_DELETE( mForcedHeaders ); } -void TileMap::DeleteLayers() { +void TileMap::deleteLayers() { eeSAFE_DELETE( mLightManager ); for ( Uint32 i = 0; i < mLayerCount; i++ ) @@ -100,22 +100,22 @@ void TileMap::create( Sizei Size, Uint32 MaxLayers, Sizei TileSize, Uint32 Flags mLayers = eeNewArray( MapLayer*, mMaxLayers ); if ( getLightsEnabled() ) - CreateLightManager(); + createLightManager(); for ( Uint32 i = 0; i < mMaxLayers; i++ ) mLayers[i] = NULL; setViewSize( viewSize ); - CreateEmptyTile(); + createEmptyTile(); } -void TileMap::CreateLightManager() { +void TileMap::createLightManager() { eeSAFE_DELETE( mLightManager ); mLightManager = eeNew( MapLightManager, ( this, ( mFlags & MAP_FLAG_LIGHTS_BYVERTEX ) ? true : false ) ); } -void TileMap::CreateEmptyTile() { +void TileMap::createEmptyTile() { //! I create a texture representing an empty tile to render instead of rendering with primitives because is a lot faster, at least with NVIDIA GPUs. TextureFactory * TF = TextureFactory::instance(); @@ -234,14 +234,14 @@ void TileMap::draw() { GLi->translatef( (Float)static_cast( mScreenPos.x + mOffset.x ), (Float)static_cast( mScreenPos.y + mOffset.y ), 0 ); GLi->scalef( mScale, mScale, 0 ); - GridDraw(); + gridDraw(); for ( Uint32 i = 0; i < mLayerCount; i++ ) { if ( mLayers[i]->isVisible() ) mLayers[i]->draw(); } - MouseOverDraw(); + mouseOverDraw(); if ( mDrawCb.IsSet() ) mDrawCb(); @@ -256,14 +256,14 @@ void TileMap::draw() { } } -void TileMap::MouseOverDraw() { +void TileMap::mouseOverDraw() { if ( !getDrawTileOver() || NULL == mTileTex ) return; mTileTex->draw( mMouseOverTileFinal.x * mTileSize.x, mMouseOverTileFinal.y * mTileSize.y, 0, Vector2f::One, mTileOverColor ); } -void TileMap::GridDraw() { +void TileMap::gridDraw() { if ( !getDrawGrid() ) return; @@ -315,7 +315,7 @@ const bool& TileMap::isMouseOver() const { return mMouseOver; } -void TileMap::GetMouseOverTile() { +void TileMap::getMouseOverTile() { Vector2i mouse = mWindow->getInput()->getMousePos(); Vector2i MapPos( static_cast( mouse.x - mScreenPos.x - mOffset.x ) / mScale, static_cast( mouse.y - mScreenPos.y - mOffset.y ) / mScale ); @@ -339,7 +339,7 @@ void TileMap::GetMouseOverTile() { mMouseMapPos = MapPos; } -void TileMap::CalcTilesClip() { +void TileMap::calcTilesClip() { if ( mTileSize.x > 0 && mTileSize.y > 0 ) { Vector2f ffoff( mOffset ); Vector2i foff( (Int32)ffoff.x, (Int32)ffoff.y ); @@ -364,7 +364,7 @@ void TileMap::CalcTilesClip() { } } -void TileMap::Clamp() { +void TileMap::clamp() { if ( !getClampBorders() ) return; @@ -407,9 +407,9 @@ void TileMap::Clamp() { void TileMap::setOffset( const Vector2f& offset ) { mOffset = offset; - Clamp(); + clamp(); - CalcTilesClip(); + calcTilesClip(); } Vector2i TileMap::getMaxOffset() { @@ -432,7 +432,7 @@ void TileMap::setScale( const Float& scale ) { setOffset( mOffset ); } -void TileMap::UpdateScreenAABB() { +void TileMap::updateScreenAABB() { mScreenAABB = eeAABB( -mOffset.x, -mOffset.y, -mOffset.x + mViewSize.getWidth(), -mOffset.y + mViewSize.getHeight() ); } @@ -441,9 +441,9 @@ const eeAABB& TileMap::getViewAreaAABB() const { } void TileMap::update() { - GetMouseOverTile(); + getMouseOverTile(); - UpdateScreenAABB(); + updateScreenAABB(); if ( NULL != mLightManager ) mLightManager->Update(); @@ -486,9 +486,9 @@ Vector2i TileMap::getTileCoords( const Vector2i& TilePos ) { void TileMap::setViewSize( const Sizei& viewSize ) { mViewSize = viewSize; - Clamp(); + clamp(); - CalcTilesClip(); + calcTilesClip(); } const Vector2i& TileMap::getPosition() const { @@ -999,7 +999,7 @@ bool TileMap::loadFromStream( IOStream& IOS ) { //! Load the lights if ( MapHdr.LightsCount ) { - CreateLightManager(); + createLightManager(); sMapLightHdr * tLighsHdr = eeNewArray( sMapLightHdr, MapHdr.LightsCount ); sMapLightHdr * tLightHdr; @@ -1023,7 +1023,7 @@ bool TileMap::loadFromStream( IOStream& IOS ) { eeSAFE_DELETE_ARRAY( tLayersHdr ); } - OnMapLoaded(); + onMapLoaded(); mPolyObjs.clear(); @@ -1081,7 +1081,7 @@ void TileMap::saveToStream( IOStream& IOS ) { sMapHdr MapHdr; MapLayer * tLayer; - std::vector TextureAtlases = GetTextureAtlases(); + std::vector TextureAtlases = getTextureAtlases(); MapHdr.Magic = EE_MAP_MAGIC; MapHdr.Flags = mFlags; @@ -1371,7 +1371,7 @@ void TileMap::save( const std::string& path ) { } } -std::vector TileMap::GetTextureAtlases() { +std::vector TileMap::getTextureAtlases() { TextureAtlasManager * SGM = TextureAtlasManager::instance(); std::list& Res = SGM->getResources(); @@ -1427,7 +1427,7 @@ void * TileMap::getData() const { return mData; } -void TileMap::OnMapLoaded() { +void TileMap::onMapLoaded() { } GameObject * TileMap::IsTypeInTilePos( const Uint32& Type, const Vector2i& TilePos ) { diff --git a/src/eepp/ui/tools/textureatlaseditor.cpp b/src/eepp/ui/tools/textureatlaseditor.cpp index 703c311e8..ad08916e0 100644 --- a/src/eepp/ui/tools/textureatlaseditor.cpp +++ b/src/eepp/ui/tools/textureatlaseditor.cpp @@ -36,7 +36,7 @@ TextureAtlasEditor::TextureAtlasEditor( UIWindow * AttatchTo, const TGEditorClos } UITextBox * TxtBox; - Uint32 Flags = UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_CLIP_ENABLE | UI_AUTO_SIZE | UI_TEXT_SELECTION_ENABLED; + Uint32 Flags = UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_TOP | UI_CLIP_ENABLE | UI_AUTO_SIZE | UI_TEXT_SELECTION_ENABLED; Uint32 InitY = 230; createTextBox( Vector2i( mUIContainer->getSize().getWidth() - 205, 30 ), "SubTexture List:" ); diff --git a/src/eepp/ui/tools/textureatlassubtextureeditor.cpp b/src/eepp/ui/tools/textureatlassubtextureeditor.cpp index 8ce8237d5..735f0c610 100644 --- a/src/eepp/ui/tools/textureatlassubtextureeditor.cpp +++ b/src/eepp/ui/tools/textureatlassubtextureeditor.cpp @@ -35,8 +35,12 @@ TextureAtlasSubTextureEditor::~TextureAtlasSubTextureEditor() { void TextureAtlasSubTextureEditor::draw() { Primitives P; P.setColor( ColorA( 255, 0, 0, mAlpha ) ); - P.drawLine( Line2f( Vector2f( mScreenPos.x, mScreenPos.y + mUICenter.y ), Vector2f( mScreenPos.x + mSize.getWidth(), mScreenPos.y + mUICenter.y ) ) ); - P.drawLine( Line2f( Vector2f( mScreenPos.x + mUICenter.x, mScreenPos.y ), Vector2f( mScreenPos.x + mUICenter.x, mScreenPos.y + mSize.getHeight() ) ) ); + P.setLineWidth( dpToPx( 1.f ) ); + + Vector2i uiCenterPx = dpToPxI( mUICenter ); + + P.drawLine( Line2f( Vector2f( mScreenPos.x, mScreenPos.y + uiCenterPx.y ), Vector2f( mScreenPos.x + mRealSize.getWidth(), mScreenPos.y + uiCenterPx.y ) ) ); + P.drawLine( Line2f( Vector2f( mScreenPos.x + uiCenterPx.x, mScreenPos.y ), Vector2f( mScreenPos.x + uiCenterPx.x, mScreenPos.y + mRealSize.getHeight() ) ) ); UIComplexControl::draw(); } diff --git a/src/eepp/ui/uicheckbox.cpp b/src/eepp/ui/uicheckbox.cpp index 0bc36168c..f66c39bf4 100644 --- a/src/eepp/ui/uicheckbox.cpp +++ b/src/eepp/ui/uicheckbox.cpp @@ -103,10 +103,14 @@ void UICheckBox::doAftersetTheme() { void UICheckBox::autoSize() { if ( mFlags & UI_AUTO_SIZE ) { + setInternalPixelsWidth( (int)mTextCache->getTextWidth() + mActiveButton->getRealSize().getWidth() ); + + if ( mSize.getHeight() == 0 ) { + setInternalHeight( mActiveButton->getSize().getHeight() ); + } + mActiveButton->centerVertical(); mInactiveButton->centerVertical(); - - setInternalPixelsWidth( (int)mTextCache->getTextWidth() + mActiveButton->getRealSize().getWidth() ); } } diff --git a/src/eepp/ui/uicontrol.cpp b/src/eepp/ui/uicontrol.cpp index 960048b02..943a1f751 100644 --- a/src/eepp/ui/uicontrol.cpp +++ b/src/eepp/ui/uicontrol.cpp @@ -709,7 +709,7 @@ void UIControl::borderDraw() { Primitives P; P.setFillMode( DRAW_LINE ); P.setBlendMode( getBlendMode() ); - P.setLineWidth( (Float)mBorder->getWidth() ); + P.setLineWidth( dpToPx( mBorder->getWidth() ) ); P.setColor( mBorder->getColor() ); //! @TODO: Check why was this +0.1f -0.1f? diff --git a/src/eepp/ui/uicontrolanim.cpp b/src/eepp/ui/uicontrolanim.cpp index 72db4ad5b..d93bf8b5f 100644 --- a/src/eepp/ui/uicontrolanim.cpp +++ b/src/eepp/ui/uicontrolanim.cpp @@ -385,7 +385,7 @@ void UIControlAnim::borderDraw() { Primitives P; P.setFillMode( DRAW_LINE ); P.setBlendMode( getBlendMode() ); - P.setLineWidth( (Float)mBorder->getWidth() ); + P.setLineWidth( dpToPx( mBorder->getWidth() ) ); P.setColor( getColor( mBorder->getColor() ) ); //! @TODO: Check why was this +0.1f -0.1f? diff --git a/src/eepp/ui/uispinbox.cpp b/src/eepp/ui/uispinbox.cpp index fb927edbf..746f8cace 100644 --- a/src/eepp/ui/uispinbox.cpp +++ b/src/eepp/ui/uispinbox.cpp @@ -161,6 +161,12 @@ void UISpinBox::internalValue( const Float& Val, const bool& Force ) { } } +void UISpinBox::onSizeChange() { + UIComplexControl::onSizeChange(); + + adjustChilds(); +} + void UISpinBox::setValue( const Float& Val ) { internalValue( Val, false ); }