Hold selection state in a separate variable, and treat all sections equal.

Notice that the selection state of individual piece sections are stored,
but never queried: the result of neither version of IsSelected() depends
on the section whose state is selected. Do not hold the state of
individual sections.

There is a theoretical change in behavior: Before, when a particular
section was unselected with SetSelected(Section, false), the focus state
of only the requested section was removed; now we remove the complete
focus. This change has no practical relevance, because there is no
user interface that can unselect individual piece sections.
This commit is contained in:
Johannes Sixt 2021-05-16 00:40:48 +02:00
parent f81f949dc6
commit d7ed7aaef4
2 changed files with 24 additions and 109 deletions

View file

@ -38,6 +38,7 @@ lcPiece::lcPiece(const lcPiece& Other)
mMesh = nullptr;
SetPieceInfo(Other.mPieceInfo, Other.mID, true);
mHidden = Other.mHidden;
mSelected = Other.mSelected;
mState = 0;
mColorIndex = Other.mColorIndex;
mColorCode = Other.mColorCode;

View file

@ -6,35 +6,22 @@ class PieceInfo;
#include "lc_colors.h"
#include "lc_math.h"
#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 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
@ -75,105 +62,28 @@ 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)
mState &= ~LC_PIECE_FOCUS_MASK;
}
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)
mState &= ~LC_PIECE_FOCUS_MASK;
}
bool IsFocused() const override
@ -224,81 +134,84 @@ public:
void SetFocused(quint32 Section, bool Focused) override
{
if (Focused)
mSelected = true;
switch (Section)
{
case LC_PIECE_SECTION_POSITION:
if (Focused)
mState |= (LC_PIECE_POSITION_SELECTED | LC_PIECE_POSITION_FOCUSED);
mState |= 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);
mState |= 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);
mState |= 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);
mState |= 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);
mState |= 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);
mState |= 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);
mState |= 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);
mState |= 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);
mState |= 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);
mState |= 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);
mState |= LC_PIECE_CONTROL_POINT_10_FOCUSED;
else
mState &= ~LC_PIECE_CONTROL_POINT_10_FOCUSED;
break;
@ -643,6 +556,7 @@ protected:
bool mPivotPointValid = false;
bool mHidden = false;
bool mSelected = false;
quint32 mState;
lcArray<lcPieceControlPoint> mControlPoints;
lcMesh* mMesh;