Add Advance Controls option for Vanishing Points
This commit is contained in:
parent
05ae5b446c
commit
2754104e00
4 changed files with 96 additions and 9 deletions
|
@ -757,19 +757,25 @@ class PerspectiveGridToolOptionBox final : public ToolOptionsBox {
|
|||
QPushButton *m_addPresetButton;
|
||||
QPushButton *m_removePresetButton;
|
||||
|
||||
ToolOptionCombo *m_perspectiveType;
|
||||
ToolOptionCheckbox *m_parallel, *m_advancedControls;
|
||||
|
||||
private:
|
||||
class PresetNamePopup;
|
||||
PresetNamePopup *m_presetNamePopup;
|
||||
void filterControls();
|
||||
|
||||
public:
|
||||
PerspectiveGridToolOptionBox(QWidget *parent, TTool *tool,
|
||||
TPaletteHandle *pltHandle,
|
||||
ToolHandle *toolHandle);
|
||||
void updateStatus();
|
||||
|
||||
protected slots:
|
||||
|
||||
void onAddPreset();
|
||||
void onRemovePreset();
|
||||
void onPerspectiveTypeChanged(int);
|
||||
};
|
||||
|
||||
//=============================================================================
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
TEnv::IntVar PerspectiveToolAdvancedControls("PerspectiveToolAdvancedControls",
|
||||
0);
|
||||
|
||||
PerspectiveTool perspectiveTool;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------
|
||||
|
@ -344,7 +347,8 @@ void PerspectiveControls::drawControls() {
|
|||
m_spacingPos + unit * TPointD(4, -4));
|
||||
}
|
||||
|
||||
if (m_perspective->getType() == PerspectiveType::VanishingPoint) {
|
||||
if (m_perspective->getType() == PerspectiveType::VanishingPoint &&
|
||||
m_showAdvanced) {
|
||||
// Draw Left Handle
|
||||
glColor3d(0.70, 0.70, 0.70);
|
||||
tglDrawSegment(m_leftPivotPos, m_leftHandlePos);
|
||||
|
@ -457,6 +461,7 @@ PerspectiveTool::PerspectiveTool()
|
|||
, m_color("Color:")
|
||||
, m_horizon("Horizon", false)
|
||||
, m_parallel("Parallel", false)
|
||||
, m_advancedControls("Advanced Controls", false)
|
||||
, m_preset("Preset:")
|
||||
, m_presetsLoaded(false)
|
||||
, m_modified(false)
|
||||
|
@ -478,6 +483,7 @@ PerspectiveTool::PerspectiveTool()
|
|||
m_prop.bind(m_color);
|
||||
m_prop.bind(m_horizon);
|
||||
m_prop.bind(m_parallel);
|
||||
m_prop.bind(m_advancedControls);
|
||||
m_prop.bind(m_preset);
|
||||
|
||||
m_type.addValue(L"Vanishing Point");
|
||||
|
@ -493,6 +499,8 @@ PerspectiveTool::PerspectiveTool()
|
|||
m_color.addValue(L"Black", TPixel::Black);
|
||||
m_color.setId("Color");
|
||||
|
||||
m_advancedControls.setValue(PerspectiveToolAdvancedControls);
|
||||
|
||||
m_preset.setId("PerspectivePreset");
|
||||
m_preset.addValue(CUSTOM_WSTR);
|
||||
|
||||
|
@ -519,6 +527,7 @@ void PerspectiveTool::updateTranslation() {
|
|||
m_opacity.setQStringName(tr("Opacity:"));
|
||||
m_horizon.setQStringName(tr("Horizon"));
|
||||
m_parallel.setQStringName(tr("Parallel"));
|
||||
m_advancedControls.setQStringName(tr("Advanced Controls"));
|
||||
|
||||
m_preset.setQStringName(tr("Preset:"));
|
||||
m_preset.setItemUIName(CUSTOM_WSTR, tr("<custom>"));
|
||||
|
@ -549,6 +558,15 @@ bool PerspectiveTool::onPropertyChanged(std::string propertyName) {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (propertyName == m_advancedControls.getName()) {
|
||||
PerspectiveToolAdvancedControls = m_advancedControls.getValue();
|
||||
|
||||
for (int i = 0; i < m_perspectiveObjs.size(); i++)
|
||||
m_perspectiveObjs[i]->setShowAdvancedControls(
|
||||
PerspectiveToolAdvancedControls);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::set<int> selectedObjects = m_selection.getSelectedObjects();
|
||||
std::set<int>::iterator it;
|
||||
|
||||
|
@ -667,7 +685,10 @@ void PerspectiveTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
|
|||
}
|
||||
m_selection.makeCurrent();
|
||||
invalidateControl(controlIdx);
|
||||
m_modified = true;
|
||||
m_modified = true;
|
||||
m_propertyUpdating = true;
|
||||
getApplication()->getCurrentTool()->notifyToolChanged();
|
||||
m_propertyUpdating = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -764,6 +785,7 @@ void PerspectiveTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
|
|||
newObject->setColor(m_color.getColorValue());
|
||||
newObject->setHorizon(m_horizon.getValue());
|
||||
newObject->setParallel(m_parallel.getValue());
|
||||
newObject->setShowAdvancedControls(PerspectiveToolAdvancedControls);
|
||||
newObject->setActive(true);
|
||||
|
||||
m_perspectiveObjs.push_back(newObject);
|
||||
|
@ -777,6 +799,10 @@ void PerspectiveTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
|
|||
m_isShifting = true; // Allow click and shift
|
||||
m_modified = true;
|
||||
|
||||
m_propertyUpdating = true;
|
||||
getApplication()->getCurrentTool()->notifyToolChanged();
|
||||
m_propertyUpdating = false;
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
@ -1210,6 +1236,7 @@ std::vector<PerspectiveObject *> PerspectiveTool::copyPerspectiveSet(
|
|||
newObject->setColor(currentObject->getColor());
|
||||
newObject->setHorizon(currentObject->isHorizon());
|
||||
newObject->setParallel(currentObject->isParallel());
|
||||
newObject->setShowAdvancedControls(PerspectiveToolAdvancedControls);
|
||||
|
||||
copy.push_back(newObject);
|
||||
}
|
||||
|
@ -1253,6 +1280,7 @@ void PerspectiveTool::loadPreset() {
|
|||
if (it == presets.end()) return;
|
||||
|
||||
m_perspectiveObjs = preset.m_perspectiveSet;
|
||||
onPropertyChanged(m_advancedControls.getName());
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
@ -1293,6 +1321,7 @@ void PerspectiveTool::removePreset() {
|
|||
|
||||
void PerspectiveTool::loadLastPreset() {
|
||||
m_perspectiveObjs = m_lastPreset;
|
||||
onPropertyChanged(m_advancedControls.getName());
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
|
|
@ -97,6 +97,7 @@ class PerspectiveControls {
|
|||
PerspectiveData *m_perspective;
|
||||
TPointD m_cursorPos;
|
||||
bool m_active;
|
||||
bool m_showAdvanced;
|
||||
|
||||
double m_handleRadius = 10;
|
||||
// Common Controls
|
||||
|
@ -111,7 +112,7 @@ class PerspectiveControls {
|
|||
|
||||
public:
|
||||
PerspectiveControls(PerspectiveData *perspective)
|
||||
: m_perspective(perspective), m_active(false) {}
|
||||
: m_perspective(perspective), m_active(false), m_showAdvanced(false) {}
|
||||
~PerspectiveControls() {}
|
||||
|
||||
void setCursorPos(TPointD pos) { m_cursorPos = pos; }
|
||||
|
@ -120,6 +121,9 @@ public:
|
|||
void setActive(bool active) { m_active = active; }
|
||||
bool isActive() { return m_active; }
|
||||
|
||||
void setShowAdvancedControls(bool show) { m_showAdvanced = show; }
|
||||
bool showAdvancedControls() { return m_showAdvanced; }
|
||||
|
||||
void setRotationPos(TPointD pos) { m_rotationPos = pos; }
|
||||
TPointD getRotationPos() { return m_rotationPos; }
|
||||
|
||||
|
@ -161,7 +165,7 @@ public:
|
|||
}
|
||||
|
||||
bool isOverLeftPivot() {
|
||||
if (!m_perspective ||
|
||||
if (!m_showAdvanced || !m_perspective ||
|
||||
m_perspective->getType() != PerspectiveType::VanishingPoint)
|
||||
return false;
|
||||
|
||||
|
@ -170,7 +174,7 @@ public:
|
|||
}
|
||||
|
||||
bool isOverLeftHandle() {
|
||||
if (!m_perspective ||
|
||||
if (!m_showAdvanced || !m_perspective ||
|
||||
m_perspective->getType() != PerspectiveType::VanishingPoint)
|
||||
return false;
|
||||
|
||||
|
@ -179,7 +183,7 @@ public:
|
|||
}
|
||||
|
||||
bool isOverRightPivot() {
|
||||
if (!m_perspective ||
|
||||
if (!m_showAdvanced || !m_perspective ||
|
||||
m_perspective->getType() != PerspectiveType::VanishingPoint)
|
||||
return false;
|
||||
|
||||
|
@ -188,7 +192,7 @@ public:
|
|||
}
|
||||
|
||||
bool isOverRightHandle() {
|
||||
if (!m_perspective ||
|
||||
if (!m_showAdvanced || !m_perspective ||
|
||||
m_perspective->getType() != PerspectiveType::VanishingPoint)
|
||||
return false;
|
||||
|
||||
|
@ -251,7 +255,7 @@ public:
|
|||
TPointD centerPoint = TPointD(0, 0), double rotation = 0.0,
|
||||
double spacing = 100.0, bool horizon = false,
|
||||
double opacity = 30.0, TPixel32 color = TPixel::Magenta,
|
||||
bool parallel = true)
|
||||
bool parallel = true, bool showAdvanced = false)
|
||||
: PerspectiveData(perspectiveType, centerPoint, rotation, spacing,
|
||||
horizon, opacity, color, parallel)
|
||||
, PerspectiveControls(this){};
|
||||
|
@ -468,6 +472,7 @@ protected:
|
|||
TBoolProperty m_horizon;
|
||||
TBoolProperty m_parallel;
|
||||
TEnumProperty m_preset;
|
||||
TBoolProperty m_advancedControls;
|
||||
|
||||
std::vector<PerspectiveObject *> m_perspectiveObjs;
|
||||
std::vector<PerspectiveObject *> m_lastPreset;
|
||||
|
|
|
@ -2959,14 +2959,55 @@ PerspectiveGridToolOptionBox::PerspectiveGridToolOptionBox(
|
|||
m_addPresetButton->setFixedSize(QSize(20, 20));
|
||||
m_removePresetButton->setFixedSize(QSize(20, 20));
|
||||
|
||||
m_perspectiveType =
|
||||
dynamic_cast<ToolOptionCombo *>(m_controls.value("Type:"));
|
||||
m_parallel = dynamic_cast<ToolOptionCheckbox *>(m_controls.value("Parallel"));
|
||||
m_advancedControls =
|
||||
dynamic_cast<ToolOptionCheckbox *>(m_controls.value("Advanced Controls"));
|
||||
|
||||
hLayout()->addWidget(m_addPresetButton);
|
||||
hLayout()->addWidget(m_removePresetButton);
|
||||
|
||||
connect(m_addPresetButton, SIGNAL(clicked()), this, SLOT(onAddPreset()));
|
||||
connect(m_removePresetButton, SIGNAL(clicked()), this,
|
||||
SLOT(onRemovePreset()));
|
||||
|
||||
connect(m_perspectiveType, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(onPerspectiveTypeChanged(int)));
|
||||
m_layout->addStretch(1);
|
||||
|
||||
filterControls();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void PerspectiveGridToolOptionBox::filterControls() {
|
||||
PerspectiveTool *perspectiveTool = dynamic_cast<PerspectiveTool *>(m_tool);
|
||||
|
||||
std::vector<PerspectiveObject *> objs =
|
||||
perspectiveTool->getPerspectiveObjects();
|
||||
bool isVanishingSelected =
|
||||
m_perspectiveType->getProperty()->getValue() == L"Vanishing Point";
|
||||
bool isLineSelected = m_perspectiveType->getProperty()->getValue() == L"Line";
|
||||
for (int i = 0; i < objs.size(); i++) {
|
||||
if (!objs[i]->isActive()) continue;
|
||||
if (objs[i]->getType() == PerspectiveType::VanishingPoint)
|
||||
isVanishingSelected = true;
|
||||
else if (objs[i]->getType() == PerspectiveType::Line)
|
||||
isLineSelected = true;
|
||||
}
|
||||
|
||||
m_parallel->setEnabled(isLineSelected);
|
||||
m_advancedControls->setEnabled(isVanishingSelected);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void PerspectiveGridToolOptionBox::updateStatus() {
|
||||
filterControls();
|
||||
|
||||
QMap<std::string, ToolOptionControl *>::iterator it;
|
||||
for (it = m_controls.begin(); it != m_controls.end(); it++)
|
||||
it.value()->updateStatus();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -2997,6 +3038,12 @@ void PerspectiveGridToolOptionBox::onRemovePreset() {
|
|||
m_presetCombo->loadEntries();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void PerspectiveGridToolOptionBox::onPerspectiveTypeChanged(int index) {
|
||||
filterControls();
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
// ZoomToolOptionBox
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue