Map Editor polygon editing points implemented.

This commit is contained in:
Martín Lucas Golini
2013-01-14 16:25:44 -03:00
parent 1584b68981
commit 86aed4994d
8 changed files with 128 additions and 62 deletions

View File

@@ -11,6 +11,7 @@ namespace EE { namespace Gaming {
cGameObjectObject::cGameObjectObject( Uint32 DataId, const eeRectf& rect, cLayer * Layer, const Uint32& Flags ) :
cGameObject( Flags, Layer ),
mRect( rect ),
mPoly( rect ),
mPos( mRect.Pos() ),
mDataId( DataId ),
mSelected( false )
@@ -29,7 +30,8 @@ bool cGameObjectObject::IsType( const Uint32& type ) {
}
eeSize cGameObjectObject::Size() {
return eeSize( mRect.Size().x, mRect.Size().y );
eeSizef size( mRect.Size() );
return eeSize( size.x, size.y );
}
void cGameObjectObject::Draw() {
@@ -51,10 +53,46 @@ eeVector2f cGameObjectObject::Pos() const {
}
void cGameObjectObject::Pos( eeVector2f pos ) {
mPoly.Move( pos - mPos );
mPos = pos;
mRect = eeRectf( pos, eeSizef( Size().x, Size().y ) );
}
void cGameObjectObject::SetPolygonPoint( Uint32 index, eeVector2f p ) {
switch ( index ) {
case 0:
{
mPoly.SetAt( 1, eeVector2f( p.x, mPoly[1].y ) );
mPoly.SetAt( 3, eeVector2f( mPoly[3].x, p.y ) );
break;
}
case 1:
{
mPoly.SetAt( 0, eeVector2f( p.x, mPoly[0].y ) );
mPoly.SetAt( 2, eeVector2f( mPoly[2].x, p.y ) );
break;
}
case 2:
{
mPoly.SetAt( 3, eeVector2f( p.x, mPoly[3].y ) );
mPoly.SetAt( 1, eeVector2f( mPoly[1].x, p.y ) );
break;
}
case 3:
default:
{
mPoly.SetAt( 2, eeVector2f( p.x, mPoly[2].y ) );
mPoly.SetAt( 0, eeVector2f( mPoly[0].x, p.y ) );
break;
}
}
mPoly.SetAt( index, p );
mRect = mPoly.ToAABB();
mPos = eeVector2f( mRect.Left, mRect.Top );
mPoly = mRect;
}
Uint32 cGameObjectObject::DataId() {
return mDataId;
}
@@ -103,8 +141,8 @@ void cGameObjectObject::TypeName( const std::string& type ) {
mType = type;
}
eePolygon2f cGameObjectObject::GetPolygon() {
return eePolygon2f( mRect );
eePolygon2f& cGameObjectObject::GetPolygon() {
return mPoly;
}
bool cGameObjectObject::PointInside( const eeVector2f& p ) {
@@ -115,10 +153,6 @@ void cGameObjectObject::SetProperties( const PropertiesMap& prop ) {
mProperties = prop;
}
eeRectf& cGameObjectObject::Rect() {
return mRect;
}
const bool& cGameObjectObject::Selected() const {
return mSelected;
}

View File

@@ -7,9 +7,9 @@ using namespace EE::Graphics;
namespace EE { namespace Gaming {
cGameObjectPolygon::cGameObjectPolygon( Uint32 DataId, eePolygon2f poly, cLayer * Layer, const Uint32& Flags ) :
cGameObjectObject( DataId, poly.ToAABB(), Layer, Flags ),
mPoly( poly )
cGameObjectObject( DataId, poly.ToAABB(), Layer, Flags )
{
mPoly = eePolygon2f( poly );
}
cGameObjectPolygon::~cGameObjectPolygon() {
@@ -41,18 +41,10 @@ void cGameObjectPolygon::Draw() {
P.DrawPolygon( mPoly );
}
eeVector2f cGameObjectPolygon::Pos() const {
return mPos;
}
void cGameObjectPolygon::Pos( eeVector2f pos ) {
mPoly.Move( pos - mPos );
cGameObjectObject::Pos( pos );
}
eePolygon2f cGameObjectPolygon::GetPolygon() {
return mPoly;
void cGameObjectPolygon::SetPolygonPoint( Uint32 index, eeVector2f p ) {
mPoly.SetAt( index, p );
mRect = mPoly.ToAABB();
mPos = eeVector2f( mRect.Left, mRect.Top );
}
bool cGameObjectPolygon::PointInside( const eeVector2f& p ) {

View File

@@ -21,7 +21,8 @@ cUIMap::cUIMap( const cUIComplexControl::CreateParams& Params, cUITheme * Theme,
mObjDragging( false ),
mSelObj( NULL ),
mTheme( Theme ),
mSelPointIndex( eeINDEX_NOT_FOUND )
mSelPointIndex( eeINDEX_NOT_FOUND ),
mSelPoint( false )
{
if ( NULL == Map ) {
mMap = eeNew( cMap, () );
@@ -150,8 +151,40 @@ void cUIMap::SelectPolyObj() {
}
}
void cUIMap::SelectPolyPoint() {
if ( NULL != mCurLayer && mCurLayer->Type() == MAP_LAYER_OBJECT && NULL != mSelObj ) {
if ( mSelObj->PointInside( mMap->GetMouseMapPosf() ) ) {
mSelPointIndex = mSelObj->GetPolygon().ClosestPoint( mMap->GetMouseMapPosf() );
SetPointRect( mSelObj->GetPolygon().GetAt( mSelPointIndex ) );
}
}
}
void cUIMap::DragPoly( Uint32 Flags, Uint32 PFlags ) {
if ( ( PFlags & EE_BUTTON_MMASK ) && NULL != mSelObj ) {
if ( mSelObj->PointInside( mMap->GetMouseMapPosf() ) ) {
if ( !mObjDragging ) {
mObjDragging = true;
mObjDragDist = GetMouseMapPos() - mSelObj->Pos();
}
}
mSelObj->Pos( GetMouseMapPos() - mObjDragDist );
if ( EDIT_POLYGONS == mEditingObjMode ) {
SelectPolyPoint();
}
} else if ( Flags & EE_BUTTON_MMASK ) {
if ( mObjDragging ) {
mObjDragging = false;
mObjDragDist = eeVector2f(0,0);
}
}
}
void cUIMap::ManageObject( Uint32 Flags ) {
Uint32 PFlags = cUIManager::instance()->GetInput()->PressTrigger();
Uint32 PFlags = cUIManager::instance()->GetInput()->PressTrigger();
Uint32 LPFlags = cUIManager::instance()->GetInput()->LastPressTrigger();
switch ( mEditingObjMode )
{
@@ -196,20 +229,8 @@ void cUIMap::ManageObject( Uint32 Flags ) {
{
if ( ( Flags & EE_BUTTON_LMASK ) ) {
SelectPolyObj();
} else if ( ( PFlags & EE_BUTTON_MMASK ) && NULL != mSelObj ) {
if ( mSelObj->PointInside( mMap->GetMouseMapPosf() ) ) {
if ( !mObjDragging ) {
mObjDragging = true;
mObjDragDist = GetMouseMapPos() - mSelObj->Pos();
}
mSelObj->Pos( GetMouseMapPos() - mObjDragDist );
}
} else if ( ( Flags & EE_BUTTON_MMASK ) && NULL != mSelObj ) {
if ( mObjDragging ) {
mObjDragging = false;
mObjDragDist = eeVector2f(0,0);
}
} else {
DragPoly( Flags, PFlags );
}
break;
@@ -217,17 +238,23 @@ void cUIMap::ManageObject( Uint32 Flags ) {
case EDIT_POLYGONS:
{
if ( ( Flags & EE_BUTTON_LMASK ) ) {
if ( NULL != mCurLayer && mCurLayer->Type() == MAP_LAYER_OBJECT ) {
if ( !mSelPoint ) {
SelectPolyObj();
if ( NULL != mSelObj ) {
if ( mSelObj->PointInside( mMap->GetMouseMapPosf() ) ) {
mSelPointIndex = mSelObj->GetPolygon().ClosestPoint( mMap->GetMouseMapPosf() );
eeVector2f p( mSelObj->GetPolygon().GetAt( mSelPointIndex ) );
mSelPointRect = eeRectf( eeVector2f( p.x - 10, p.y - 10 ), eeSizef( 20, 20 ) );
}
}
SelectPolyPoint();
} else {
mSelPoint = false;
}
} else if ( !( LPFlags & EE_BUTTON_LMASK ) && ( PFlags & EE_BUTTON_LMASK ) ) {
if ( NULL != mSelObj && eeINDEX_NOT_FOUND != mSelPointIndex && mSelPointRect.Contains( mMap->GetMouseMapPosf() ) ) {
mSelPoint = true;
}
} else if ( ( PFlags & EE_BUTTON_LMASK ) ) {
if ( mSelPoint && NULL != mSelObj && eeINDEX_NOT_FOUND != mSelPointIndex ) {
mSelObj->SetPolygonPoint( mSelPointIndex, GetMouseMapPos() );
SetPointRect( GetMouseMapPos() );
}
} else {
DragPoly( Flags, PFlags );
}
break;
@@ -238,6 +265,10 @@ void cUIMap::ManageObject( Uint32 Flags ) {
}
}
void cUIMap::SetPointRect( eeVector2f p ) {
mSelPointRect = eeRectf( eeVector2f( p.x - 10, p.y - 10 ), eeSizef( 20, 20 ) );
}
void cUIMap::TryToSelectLight() {
cLight * tLight = mSelLight;
mSelLight = mMap->GetLightManager()->GetLightOver( mMap->GetMouseMapPosf(), mSelLight );

View File

@@ -114,6 +114,7 @@ class EE_API cUIMap : public cUIComplexControl {
Uint32 mSelPointIndex;
eeRectf mSelPointRect;
bool mSelPoint;
virtual Uint32 OnMessage( const cUIMessage * Msg );
@@ -136,6 +137,12 @@ class EE_API cUIMap : public cUIComplexControl {
eeVector2f GetMouseMapPos();
void SelectPolyObj();
void SelectPolyPoint();
void SetPointRect( eeVector2f p );
void DragPoly( Uint32 Flags, Uint32 PFlags );
};
}}}