diff --git a/common/lc_viewmanipulator.cpp b/common/lc_viewmanipulator.cpp index d8c13497..11a25a5c 100644 --- a/common/lc_viewmanipulator.cpp +++ b/common/lc_viewmanipulator.cpp @@ -790,7 +790,7 @@ lcTrackTool lcViewManipulator::UpdateSelectMove() quint32 Section = Piece->GetFocusSection(); if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST && Section <= LC_PIECE_SECTION_CONTROL_POINT_LAST) - ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1; + ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; } quint32 AllowedTransforms = Focus ? Focus->GetAllowedTransforms() : LC_OBJECT_TRANSFORM_MOVE_X | LC_OBJECT_TRANSFORM_MOVE_Y | LC_OBJECT_TRANSFORM_MOVE_Z | LC_OBJECT_TRANSFORM_ROTATE_X | LC_OBJECT_TRANSFORM_ROTATE_Y | LC_OBJECT_TRANSFORM_ROTATE_Z; diff --git a/common/piece.cpp b/common/piece.cpp index 3a0338fb..ce098c63 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -22,7 +22,7 @@ lcPiece::lcPiece(PieceInfo* Info) { mMesh = nullptr; SetPieceInfo(Info, QString(), true); - mState = 0; + mFocusedSection = LC_PIECE_SECTION_INVALID; mColorIndex = gDefaultColor; mColorCode = 16; mStepShow = 1; @@ -37,7 +37,9 @@ lcPiece::lcPiece(const lcPiece& Other) { mMesh = nullptr; SetPieceInfo(Other.mPieceInfo, Other.mID, true); - mState = 0; + mHidden = Other.mHidden; + mSelected = Other.mSelected; + mFocusedSection = LC_PIECE_SECTION_INVALID; mColorIndex = Other.mColorIndex; mColorCode = Other.mColorCode; mStepShow = Other.mStepShow; @@ -46,7 +48,7 @@ lcPiece::lcPiece(const lcPiece& Other) mFileLine = -1; mPivotMatrix = Other.mPivotMatrix; - mState |= ( Other.mState & LC_PIECE_PIVOT_POINT_VALID ); + mPivotPointValid = Other.mPivotPointValid; mPositionKeys = Other.mPositionKeys; mRotationKeys = Other.mRotationKeys; @@ -109,7 +111,7 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const if (IsHidden()) Stream << QLatin1String("0 !LEOCAD PIECE HIDDEN") << LineEnding; - if (mState & LC_PIECE_PIVOT_POINT_VALID) + if (mPivotPointValid) { const float* PivotMatrix = mPivotMatrix; float PivotNumbers[12] = { PivotMatrix[12], -PivotMatrix[14], PivotMatrix[13], PivotMatrix[0], -PivotMatrix[8], PivotMatrix[4], -PivotMatrix[2], PivotMatrix[10], -PivotMatrix[6], PivotMatrix[1], -PivotMatrix[9], PivotMatrix[5] }; @@ -160,7 +162,7 @@ bool lcPiece::ParseLDrawLine(QTextStream& Stream) lcVector4(-PivotNumbers[4], -PivotNumbers[10], PivotNumbers[7], 0.0f), lcVector4(PivotNumbers[0], PivotNumbers[2], -PivotNumbers[1], 1.0f)); mPivotMatrix = PivotMatrix; - mState |= LC_PIECE_PIVOT_POINT_VALID; + mPivotPointValid = true; } else if (Token == QLatin1String("POSITION_KEY")) mPositionKeys.LoadKeysLDraw(Stream); @@ -346,7 +348,7 @@ bool lcPiece::FileLoad(lcFile& file) quint8 Hidden; file.ReadU8(&Hidden, 1); if (Hidden & 1) - mState |= LC_PIECE_HIDDEN; + mHidden = true; file.ReadU8(&ch, 1); file.Seek(ch, SEEK_CUR); } @@ -355,7 +357,7 @@ bool lcPiece::FileLoad(lcFile& file) qint32 hide; file.ReadS32(&hide, 1); if (hide != 0) - mState |= LC_PIECE_HIDDEN; + mHidden = true; file.Seek(81, SEEK_CUR); } @@ -375,7 +377,7 @@ bool lcPiece::FileLoad(lcFile& file) file.ReadU8(&ch, 1); if (ch & 0x01) - mState |= LC_PIECE_HIDDEN; + mHidden = true; } return true; @@ -495,7 +497,7 @@ void lcPiece::RayTest(lcObjectRayTest& ObjectRayTest) const continue; ObjectRayTest.ObjectSection.Object = const_cast(this); - ObjectRayTest.ObjectSection.Section = LC_PIECE_SECTION_CONTROL_POINT_1 + ControlPointIdx; + ObjectRayTest.ObjectSection.Section = LC_PIECE_SECTION_CONTROL_POINT_FIRST + ControlPointIdx; ObjectRayTest.Distance = Distance; } } @@ -623,7 +625,7 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const Context->SetVertexFormatPosition(3); Context->SetIndexBufferPointer(Indices); - if (IsFocused(LC_PIECE_SECTION_CONTROL_POINT_1 + ControlPointIdx)) + if (IsFocused(LC_PIECE_SECTION_CONTROL_POINT_FIRST + ControlPointIdx)) Context->SetInterfaceColor(LC_COLOR_CONTROL_POINT_FOCUSED); else Context->SetInterfaceColor(LC_COLOR_CONTROL_POINT); @@ -734,7 +736,7 @@ void lcPiece::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance) } else { - int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1; + int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) { @@ -772,7 +774,7 @@ void lcPiece::Rotate(lcStep Step, bool AddKey, const lcMatrix33& RotationMatrix, } else { - int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1; + int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) { @@ -797,7 +799,7 @@ void lcPiece::MovePivotPoint(const lcVector3& Distance) return; mPivotMatrix.SetTranslation(mPivotMatrix.GetTranslation() + lcMul30(Distance, lcMatrix44AffineInverse(mModelWorld))); - mState |= LC_PIECE_PIVOT_POINT_VALID; + mPivotPointValid = true; } void lcPiece::RotatePivotPoint(const lcMatrix33& RotationMatrix) @@ -809,7 +811,7 @@ void lcPiece::RotatePivotPoint(const lcMatrix33& RotationMatrix) NewPivotRotationMatrix.Orthonormalize(); mPivotMatrix = lcMatrix44(NewPivotRotationMatrix, mPivotMatrix.GetTranslation()); - mState |= LC_PIECE_PIVOT_POINT_VALID; + mPivotPointValid = true; } quint32 lcPiece::GetAllowedTransforms() const @@ -867,7 +869,7 @@ bool lcPiece::InsertControlPoint(const lcVector3& WorldStart, const lcVector3& W if (ControlPointIndex) { SetFocused(GetFocusSection(), false); - SetFocused(LC_PIECE_SECTION_CONTROL_POINT_1 + ControlPointIndex, true); + SetFocused(LC_PIECE_SECTION_CONTROL_POINT_FIRST + ControlPointIndex, true); UpdateMesh(); return true; } @@ -877,7 +879,7 @@ bool lcPiece::InsertControlPoint(const lcVector3& WorldStart, const lcVector3& W bool lcPiece::RemoveFocusedControlPoint() { - int ControlPointIndex = GetFocusSection() - LC_PIECE_SECTION_CONTROL_POINT_1; + int ControlPointIndex = GetFocusSection() - LC_PIECE_SECTION_CONTROL_POINT_FIRST; if (ControlPointIndex < 0 || ControlPointIndex >= mControlPoints.GetSize() || mControlPoints.GetSize() <= 2) return false; @@ -914,15 +916,12 @@ QString lcPiece::GetName() const bool lcPiece::IsVisible(lcStep Step) const { - if (mState & LC_PIECE_HIDDEN) - return false; - - return (mStepShow <= Step) && (mStepHide > Step || mStepHide == LC_STEP_MAX); + return !mHidden && (mStepShow <= Step) && (mStepHide > Step || mStepHide == LC_STEP_MAX); } bool lcPiece::IsVisibleInSubModel() const { - return (mStepHide == LC_STEP_MAX) && !(mState & LC_PIECE_HIDDEN); + return (mStepHide == LC_STEP_MAX) && !mHidden; } void lcPiece::GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector& ModelParts) const diff --git a/common/piece.h b/common/piece.h index 1cb36acd..a5c91ddb 100644 --- a/common/piece.h +++ b/common/piece.h @@ -6,58 +6,16 @@ class PieceInfo; #include "lc_colors.h" #include "lc_math.h" -#define LC_PIECE_HIDDEN 0x000001 -#define LC_PIECE_PIVOT_POINT_VALID 0x000002 -#define LC_PIECE_POSITION_SELECTED 0x000004 -#define LC_PIECE_POSITION_FOCUSED 0x000008 -#define LC_PIECE_CONTROL_POINT_1_SELECTED 0x000010 -#define LC_PIECE_CONTROL_POINT_1_FOCUSED 0x000020 -#define LC_PIECE_CONTROL_POINT_2_SELECTED 0x000040 -#define LC_PIECE_CONTROL_POINT_2_FOCUSED 0x000080 -#define LC_PIECE_CONTROL_POINT_3_SELECTED 0x000100 -#define LC_PIECE_CONTROL_POINT_3_FOCUSED 0x000200 -#define LC_PIECE_CONTROL_POINT_4_SELECTED 0x000400 -#define LC_PIECE_CONTROL_POINT_4_FOCUSED 0x000800 -#define LC_PIECE_CONTROL_POINT_5_SELECTED 0x001000 -#define LC_PIECE_CONTROL_POINT_5_FOCUSED 0x002000 -#define LC_PIECE_CONTROL_POINT_6_SELECTED 0x004000 -#define LC_PIECE_CONTROL_POINT_6_FOCUSED 0x008000 -#define LC_PIECE_CONTROL_POINT_7_SELECTED 0x010000 -#define LC_PIECE_CONTROL_POINT_7_FOCUSED 0x020000 -#define LC_PIECE_CONTROL_POINT_8_SELECTED 0x040000 -#define LC_PIECE_CONTROL_POINT_8_FOCUSED 0x080000 -#define LC_PIECE_CONTROL_POINT_9_SELECTED 0x100000 -#define LC_PIECE_CONTROL_POINT_9_FOCUSED 0x200000 -#define LC_PIECE_CONTROL_POINT_10_SELECTED 0x400000 -#define LC_PIECE_CONTROL_POINT_10_FOCUSED 0x800000 +#define LC_MAX_CONTROL_POINTS 1000 -#define LC_MAX_CONTROL_POINTS 10 - -#define LC_PIECE_CONTROL_POINT_SELECTION_MASK (LC_PIECE_CONTROL_POINT_1_SELECTED | LC_PIECE_CONTROL_POINT_2_SELECTED | LC_PIECE_CONTROL_POINT_3_SELECTED | LC_PIECE_CONTROL_POINT_4_SELECTED | LC_PIECE_CONTROL_POINT_5_SELECTED | LC_PIECE_CONTROL_POINT_6_SELECTED | LC_PIECE_CONTROL_POINT_7_SELECTED | LC_PIECE_CONTROL_POINT_8_SELECTED | LC_PIECE_CONTROL_POINT_9_SELECTED | LC_PIECE_CONTROL_POINT_10_SELECTED) -#define LC_PIECE_CONTROL_POINT_FOCUS_MASK (LC_PIECE_CONTROL_POINT_1_FOCUSED | LC_PIECE_CONTROL_POINT_2_FOCUSED | LC_PIECE_CONTROL_POINT_3_FOCUSED | LC_PIECE_CONTROL_POINT_4_FOCUSED | LC_PIECE_CONTROL_POINT_5_FOCUSED | LC_PIECE_CONTROL_POINT_6_FOCUSED | LC_PIECE_CONTROL_POINT_7_FOCUSED | LC_PIECE_CONTROL_POINT_8_FOCUSED | LC_PIECE_CONTROL_POINT_9_FOCUSED | LC_PIECE_CONTROL_POINT_10_FOCUSED) - -#define LC_PIECE_SELECTION_MASK (LC_PIECE_POSITION_SELECTED | LC_PIECE_CONTROL_POINT_SELECTION_MASK) -#define LC_PIECE_FOCUS_MASK (LC_PIECE_POSITION_FOCUSED | LC_PIECE_CONTROL_POINT_FOCUS_MASK) - -enum lcPieceSection +enum lcPieceSection : quint32 { - LC_PIECE_SECTION_POSITION, + LC_PIECE_SECTION_INVALID = ~0U, + LC_PIECE_SECTION_POSITION = 0, LC_PIECE_SECTION_CONTROL_POINT_FIRST, - LC_PIECE_SECTION_CONTROL_POINT_1 = LC_PIECE_SECTION_CONTROL_POINT_FIRST, - LC_PIECE_SECTION_CONTROL_POINT_2, - LC_PIECE_SECTION_CONTROL_POINT_3, - LC_PIECE_SECTION_CONTROL_POINT_4, - LC_PIECE_SECTION_CONTROL_POINT_5, - LC_PIECE_SECTION_CONTROL_POINT_6, - LC_PIECE_SECTION_CONTROL_POINT_7, - LC_PIECE_SECTION_CONTROL_POINT_8, - LC_PIECE_SECTION_CONTROL_POINT_9, - LC_PIECE_SECTION_CONTROL_POINT_10, - LC_PIECE_SECTION_CONTROL_POINT_LAST = LC_PIECE_SECTION_CONTROL_POINT_10 + LC_PIECE_SECTION_CONTROL_POINT_LAST = LC_PIECE_SECTION_CONTROL_POINT_FIRST + LC_MAX_CONTROL_POINTS - 1, }; -#define LC_PIECE_SECTION_INVALID (~0U) - struct lcPieceControlPoint { lcMatrix44 Transform; @@ -77,315 +35,76 @@ public: bool IsSelected() const override { - return (mState & LC_PIECE_SELECTION_MASK) != 0; + return mSelected; } bool IsSelected(quint32 Section) const override { Q_UNUSED(Section); - return (mState & LC_PIECE_SELECTION_MASK) != 0; + return mSelected; } void SetSelected(bool Selected) override { - if (Selected) - mState |= LC_PIECE_SELECTION_MASK; - else - mState &= ~(LC_PIECE_SELECTION_MASK | LC_PIECE_FOCUS_MASK); + mSelected = Selected; + if (!Selected) + mFocusedSection = LC_PIECE_SECTION_INVALID; } void SetSelected(quint32 Section, bool Selected) override { - switch (Section) - { - case LC_PIECE_SECTION_POSITION: - if (Selected) - mState |= LC_PIECE_POSITION_SELECTED; - else - mState &= ~(LC_PIECE_POSITION_SELECTED | LC_PIECE_POSITION_FOCUSED); - break; - - case LC_PIECE_SECTION_CONTROL_POINT_1: - if (Selected) - mState |= LC_PIECE_CONTROL_POINT_1_SELECTED; - else - mState &= ~(LC_PIECE_CONTROL_POINT_1_SELECTED | LC_PIECE_CONTROL_POINT_1_FOCUSED); - break; - - case LC_PIECE_SECTION_CONTROL_POINT_2: - if (Selected) - mState |= LC_PIECE_CONTROL_POINT_2_SELECTED; - else - mState &= ~(LC_PIECE_CONTROL_POINT_2_SELECTED | LC_PIECE_CONTROL_POINT_2_FOCUSED); - break; - - case LC_PIECE_SECTION_CONTROL_POINT_3: - if (Selected) - mState |= LC_PIECE_CONTROL_POINT_3_SELECTED; - else - mState &= ~(LC_PIECE_CONTROL_POINT_3_SELECTED | LC_PIECE_CONTROL_POINT_3_FOCUSED); - break; - - case LC_PIECE_SECTION_CONTROL_POINT_4: - if (Selected) - mState |= LC_PIECE_CONTROL_POINT_4_SELECTED; - else - mState &= ~(LC_PIECE_CONTROL_POINT_4_SELECTED | LC_PIECE_CONTROL_POINT_4_FOCUSED); - break; - - case LC_PIECE_SECTION_CONTROL_POINT_5: - if (Selected) - mState |= LC_PIECE_CONTROL_POINT_5_SELECTED; - else - mState &= ~(LC_PIECE_CONTROL_POINT_5_SELECTED | LC_PIECE_CONTROL_POINT_5_FOCUSED); - break; - - case LC_PIECE_SECTION_CONTROL_POINT_6: - if (Selected) - mState |= LC_PIECE_CONTROL_POINT_6_SELECTED; - else - mState &= ~(LC_PIECE_CONTROL_POINT_6_SELECTED | LC_PIECE_CONTROL_POINT_6_FOCUSED); - break; - - case LC_PIECE_SECTION_CONTROL_POINT_7: - if (Selected) - mState |= LC_PIECE_CONTROL_POINT_7_SELECTED; - else - mState &= ~(LC_PIECE_CONTROL_POINT_7_SELECTED | LC_PIECE_CONTROL_POINT_7_FOCUSED); - break; - - case LC_PIECE_SECTION_CONTROL_POINT_8: - if (Selected) - mState |= LC_PIECE_CONTROL_POINT_8_SELECTED; - else - mState &= ~(LC_PIECE_CONTROL_POINT_8_SELECTED | LC_PIECE_CONTROL_POINT_8_FOCUSED); - break; - - case LC_PIECE_SECTION_CONTROL_POINT_9: - if (Selected) - mState |= LC_PIECE_CONTROL_POINT_9_SELECTED; - else - mState &= ~(LC_PIECE_CONTROL_POINT_9_SELECTED | LC_PIECE_CONTROL_POINT_9_FOCUSED); - break; - - case LC_PIECE_SECTION_CONTROL_POINT_10: - if (Selected) - mState |= LC_PIECE_CONTROL_POINT_10_SELECTED; - else - mState &= ~(LC_PIECE_CONTROL_POINT_10_SELECTED | LC_PIECE_CONTROL_POINT_10_FOCUSED); - break; - } + mSelected = Selected; + if (!Selected) + mFocusedSection = LC_PIECE_SECTION_INVALID; } bool IsFocused() const override { - return (mState & LC_PIECE_FOCUS_MASK) != 0; + return mFocusedSection != LC_PIECE_SECTION_INVALID; } bool IsFocused(quint32 Section) const override { - switch (Section) - { - case LC_PIECE_SECTION_POSITION: - return (mState & LC_PIECE_POSITION_FOCUSED) != 0; - - case LC_PIECE_SECTION_CONTROL_POINT_1: - return (mState & LC_PIECE_CONTROL_POINT_1_FOCUSED) != 0; - - case LC_PIECE_SECTION_CONTROL_POINT_2: - return (mState & LC_PIECE_CONTROL_POINT_2_FOCUSED) != 0; - - case LC_PIECE_SECTION_CONTROL_POINT_3: - return (mState & LC_PIECE_CONTROL_POINT_3_FOCUSED) != 0; - - case LC_PIECE_SECTION_CONTROL_POINT_4: - return (mState & LC_PIECE_CONTROL_POINT_4_FOCUSED) != 0; - - case LC_PIECE_SECTION_CONTROL_POINT_5: - return (mState & LC_PIECE_CONTROL_POINT_5_FOCUSED) != 0; - - case LC_PIECE_SECTION_CONTROL_POINT_6: - return (mState & LC_PIECE_CONTROL_POINT_6_FOCUSED) != 0; - - case LC_PIECE_SECTION_CONTROL_POINT_7: - return (mState & LC_PIECE_CONTROL_POINT_7_FOCUSED) != 0; - - case LC_PIECE_SECTION_CONTROL_POINT_8: - return (mState & LC_PIECE_CONTROL_POINT_8_FOCUSED) != 0; - - case LC_PIECE_SECTION_CONTROL_POINT_9: - return (mState & LC_PIECE_CONTROL_POINT_9_FOCUSED) != 0; - - case LC_PIECE_SECTION_CONTROL_POINT_10: - return (mState & LC_PIECE_CONTROL_POINT_10_FOCUSED) != 0; - } - - return false; + return mFocusedSection == Section; } void SetFocused(quint32 Section, bool Focused) override { - switch (Section) + if (Focused) { - case LC_PIECE_SECTION_POSITION: - if (Focused) - mState |= (LC_PIECE_POSITION_SELECTED | LC_PIECE_POSITION_FOCUSED); - else - mState &= ~LC_PIECE_POSITION_FOCUSED; - break; - - case LC_PIECE_SECTION_CONTROL_POINT_1: - if (Focused) - mState |= (LC_PIECE_CONTROL_POINT_1_SELECTED | LC_PIECE_CONTROL_POINT_1_FOCUSED); - else - mState &= ~LC_PIECE_CONTROL_POINT_1_FOCUSED; - break; - - case LC_PIECE_SECTION_CONTROL_POINT_2: - if (Focused) - mState |= (LC_PIECE_CONTROL_POINT_2_SELECTED | LC_PIECE_CONTROL_POINT_2_FOCUSED); - else - mState &= ~LC_PIECE_CONTROL_POINT_2_FOCUSED; - break; - - case LC_PIECE_SECTION_CONTROL_POINT_3: - if (Focused) - mState |= (LC_PIECE_CONTROL_POINT_3_SELECTED | LC_PIECE_CONTROL_POINT_3_FOCUSED); - else - mState &= ~LC_PIECE_CONTROL_POINT_3_FOCUSED; - break; - - case LC_PIECE_SECTION_CONTROL_POINT_4: - if (Focused) - mState |= (LC_PIECE_CONTROL_POINT_4_SELECTED | LC_PIECE_CONTROL_POINT_4_FOCUSED); - else - mState &= ~LC_PIECE_CONTROL_POINT_4_FOCUSED; - break; - - case LC_PIECE_SECTION_CONTROL_POINT_5: - if (Focused) - mState |= (LC_PIECE_CONTROL_POINT_5_SELECTED | LC_PIECE_CONTROL_POINT_5_FOCUSED); - else - mState &= ~LC_PIECE_CONTROL_POINT_5_FOCUSED; - break; - - case LC_PIECE_SECTION_CONTROL_POINT_6: - if (Focused) - mState |= (LC_PIECE_CONTROL_POINT_6_SELECTED | LC_PIECE_CONTROL_POINT_6_FOCUSED); - else - mState &= ~LC_PIECE_CONTROL_POINT_6_FOCUSED; - break; - - case LC_PIECE_SECTION_CONTROL_POINT_7: - if (Focused) - mState |= (LC_PIECE_CONTROL_POINT_7_SELECTED | LC_PIECE_CONTROL_POINT_7_FOCUSED); - else - mState &= ~LC_PIECE_CONTROL_POINT_7_FOCUSED; - break; - - case LC_PIECE_SECTION_CONTROL_POINT_8: - if (Focused) - mState |= (LC_PIECE_CONTROL_POINT_8_SELECTED | LC_PIECE_CONTROL_POINT_8_FOCUSED); - else - mState &= ~LC_PIECE_CONTROL_POINT_8_FOCUSED; - break; - - case LC_PIECE_SECTION_CONTROL_POINT_9: - if (Focused) - mState |= (LC_PIECE_CONTROL_POINT_9_SELECTED | LC_PIECE_CONTROL_POINT_9_FOCUSED); - else - mState &= ~LC_PIECE_CONTROL_POINT_9_FOCUSED; - break; - - case LC_PIECE_SECTION_CONTROL_POINT_10: - if (Focused) - mState |= (LC_PIECE_CONTROL_POINT_10_SELECTED | LC_PIECE_CONTROL_POINT_10_FOCUSED); - else - mState &= ~LC_PIECE_CONTROL_POINT_10_FOCUSED; - break; + mFocusedSection = Section; + mSelected = true; } + else + mFocusedSection = LC_PIECE_SECTION_INVALID; } quint32 GetFocusSection() const override { - if (mState & LC_PIECE_POSITION_FOCUSED) - return LC_PIECE_SECTION_POSITION; - - if (mState & LC_PIECE_CONTROL_POINT_1_FOCUSED) - return LC_PIECE_SECTION_CONTROL_POINT_1; - - if (mState & LC_PIECE_CONTROL_POINT_2_FOCUSED) - return LC_PIECE_SECTION_CONTROL_POINT_2; - - if (mState & LC_PIECE_CONTROL_POINT_3_FOCUSED) - return LC_PIECE_SECTION_CONTROL_POINT_3; - - if (mState & LC_PIECE_CONTROL_POINT_4_FOCUSED) - return LC_PIECE_SECTION_CONTROL_POINT_4; - - if (mState & LC_PIECE_CONTROL_POINT_5_FOCUSED) - return LC_PIECE_SECTION_CONTROL_POINT_5; - - if (mState & LC_PIECE_CONTROL_POINT_6_FOCUSED) - return LC_PIECE_SECTION_CONTROL_POINT_6; - - if (mState & LC_PIECE_CONTROL_POINT_7_FOCUSED) - return LC_PIECE_SECTION_CONTROL_POINT_7; - - if (mState & LC_PIECE_CONTROL_POINT_8_FOCUSED) - return LC_PIECE_SECTION_CONTROL_POINT_8; - - if (mState & LC_PIECE_CONTROL_POINT_9_FOCUSED) - return LC_PIECE_SECTION_CONTROL_POINT_9; - - if (mState & LC_PIECE_CONTROL_POINT_10_FOCUSED) - return LC_PIECE_SECTION_CONTROL_POINT_10; - - return LC_PIECE_SECTION_INVALID; + return mFocusedSection; } quint32 GetAllowedTransforms() const override; lcVector3 GetSectionPosition(quint32 Section) const override { - switch (Section) + if (Section == LC_PIECE_SECTION_POSITION) { - case LC_PIECE_SECTION_POSITION: - if (mState & LC_PIECE_PIVOT_POINT_VALID) + if (mPivotPointValid) return lcMul(mPivotMatrix, mModelWorld).GetTranslation(); else return mModelWorld.GetTranslation(); + } + else + { + const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; - case LC_PIECE_SECTION_CONTROL_POINT_1: - return lcMul(mControlPoints[0].Transform, mModelWorld).GetTranslation(); - - case LC_PIECE_SECTION_CONTROL_POINT_2: - return lcMul(mControlPoints[1].Transform, mModelWorld).GetTranslation(); - - case LC_PIECE_SECTION_CONTROL_POINT_3: - return lcMul(mControlPoints[2].Transform, mModelWorld).GetTranslation(); - - case LC_PIECE_SECTION_CONTROL_POINT_4: - return lcMul(mControlPoints[3].Transform, mModelWorld).GetTranslation(); - - case LC_PIECE_SECTION_CONTROL_POINT_5: - return lcMul(mControlPoints[4].Transform, mModelWorld).GetTranslation(); - - case LC_PIECE_SECTION_CONTROL_POINT_6: - return lcMul(mControlPoints[5].Transform, mModelWorld).GetTranslation(); - - case LC_PIECE_SECTION_CONTROL_POINT_7: - return lcMul(mControlPoints[6].Transform, mModelWorld).GetTranslation(); - - case LC_PIECE_SECTION_CONTROL_POINT_8: - return lcMul(mControlPoints[7].Transform, mModelWorld).GetTranslation(); - - case LC_PIECE_SECTION_CONTROL_POINT_9: - return lcMul(mControlPoints[8].Transform, mModelWorld).GetTranslation(); - - case LC_PIECE_SECTION_CONTROL_POINT_10: - return lcMul(mControlPoints[9].Transform, mModelWorld).GetTranslation(); + if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) + { + const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; + return lcMul(Transform, mModelWorld).GetTranslation(); + } } return lcVector3(0.0f, 0.0f, 0.0f); @@ -419,15 +138,12 @@ public: bool IsHidden() const { - return (mState & LC_PIECE_HIDDEN) != 0; + return mHidden; } void SetHidden(bool Hidden) { - if (Hidden) - mState |= LC_PIECE_HIDDEN; - else - mState &= ~LC_PIECE_HIDDEN; + mHidden = Hidden; } const lcArray& GetControlPoints() const @@ -563,14 +279,14 @@ public: if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID) { - if (mState & LC_PIECE_PIVOT_POINT_VALID) + if (mPivotPointValid) return lcMul31(mPivotMatrix.GetTranslation(), mModelWorld); else return mModelWorld.GetTranslation(); } else { - const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1; + const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) { @@ -588,14 +304,14 @@ public: if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID) { - if (mState & LC_PIECE_PIVOT_POINT_VALID) + if (mPivotPointValid) return lcMatrix33(lcMul(mModelWorld, mPivotMatrix)); else return lcMatrix33(mModelWorld); } else { - const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_1; + const int ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; if (ControlPointIndex >= 0 && ControlPointIndex < mControlPoints.GetSize()) { @@ -609,7 +325,7 @@ public: void ResetPivotPoint() { - mState &= ~LC_PIECE_PIVOT_POINT_VALID; + mPivotPointValid = false; mPivotMatrix = lcMatrix44Identity(); } @@ -624,7 +340,7 @@ protected: bool IsPivotPointVisible() const { - return (mState & LC_PIECE_PIVOT_POINT_VALID) && IsFocused(); + return mPivotPointValid && IsFocused(); } bool AreControlPointsVisible() const @@ -646,7 +362,10 @@ protected: lcStep mStepShow; lcStep mStepHide; - quint32 mState; + bool mPivotPointValid = false; + bool mHidden = false; + bool mSelected = false; + quint32 mFocusedSection; lcArray mControlPoints; lcMesh* mMesh; };