-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify guide snap distance via guide panel slider (#151)
* Implemented changing the guide snap distance using a slider in the guide panel. * Fixed slider knob not initialized to the correct value.
- Loading branch information
Showing
11 changed files
with
985 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
Assets/Scripts/Commands/ModifyStencilAttractDistanceCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2021 The Open Brush Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace TiltBrush | ||
{ | ||
public class ModifyStencilAttractDistanceCommand : BaseCommand | ||
{ | ||
private readonly float m_StartDistance; | ||
private float m_EndDistance; | ||
private bool m_Final; | ||
|
||
public ModifyStencilAttractDistanceCommand(float endDistance, bool final = false, | ||
BaseCommand parent = null) : base(parent) | ||
{ | ||
m_StartDistance = WidgetManager.m_Instance.StencilAttractDist; | ||
m_EndDistance = endDistance; | ||
m_Final = final; | ||
} | ||
|
||
public override bool NeedsSave => true; | ||
|
||
protected override void OnUndo() | ||
{ | ||
WidgetManager.m_Instance.StencilAttractDist = m_StartDistance; | ||
} | ||
|
||
protected override void OnRedo() | ||
{ | ||
WidgetManager.m_Instance.StencilAttractDist = m_EndDistance; | ||
} | ||
|
||
public override bool Merge(BaseCommand other) | ||
{ | ||
if (base.Merge(other)) { return true; } | ||
if (m_Final) { return false; } | ||
ModifyStencilAttractDistanceCommand distanceCommand = other as ModifyStencilAttractDistanceCommand; | ||
if (distanceCommand == null) { return false; } | ||
m_EndDistance = distanceCommand.m_EndDistance; | ||
m_Final = distanceCommand.m_Final; | ||
return true; | ||
} | ||
} | ||
} // namespace TiltBrush |
3 changes: 3 additions & 0 deletions
3
Assets/Scripts/Commands/ModifyStencilAttractDistanceCommand.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2021 The Open Brush Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using UnityEngine; | ||
using System; | ||
|
||
namespace TiltBrush | ||
{ | ||
public class StencilAttractDistanceSlider : BaseSlider | ||
{ | ||
[SerializeField] private float m_MinAttractDistance = 0.25f; | ||
[SerializeField] private float m_MaxAttractDistance = 2f; | ||
|
||
void OnEnable() | ||
{ | ||
App.Switchboard.StencilAttractDistChanged += OnStencilAttractDistChanged; | ||
OnStencilAttractDistChanged(); | ||
} | ||
|
||
protected override void OnDestroy() | ||
{ | ||
base.OnDestroy(); | ||
App.Switchboard.StencilAttractDistChanged -= OnStencilAttractDistChanged; | ||
} | ||
|
||
public override void UpdateValue(float value) | ||
{ | ||
base.UpdateValue(value); | ||
SetSliderPositionToReflectValue(); | ||
|
||
SetDescriptionText(m_DescriptionText, $"{value * 100:0}%"); | ||
} | ||
|
||
// If some other logic (not the slider) changes the value, we | ||
// will be notified here so that we can update the slider visuals | ||
private void OnStencilAttractDistChanged() | ||
{ | ||
if (WidgetManager.m_Instance != null) | ||
{ | ||
float value = WidgetManager.m_Instance.StencilAttractDist; | ||
float range = m_MaxAttractDistance - m_MinAttractDistance; | ||
float newSliderValue = (value - m_MinAttractDistance) / range; | ||
UpdateValue(newSliderValue); | ||
} | ||
} | ||
|
||
public override void ButtonReleased() | ||
{ | ||
base.ButtonReleased(); | ||
EndModifyCommand(); | ||
} | ||
|
||
public override void ResetState() | ||
{ | ||
if (m_HadButtonPress) | ||
{ | ||
EndModifyCommand(); | ||
} | ||
base.ResetState(); | ||
} | ||
|
||
void EndModifyCommand() | ||
{ | ||
float percent = GetCurrentValue(); | ||
float displacement = m_MaxAttractDistance - m_MinAttractDistance; | ||
float newDistance = m_MinAttractDistance + percent * displacement; | ||
|
||
SketchMemoryScript.m_Instance.PerformAndRecordCommand( | ||
new ModifyStencilAttractDistanceCommand(newDistance, true)); | ||
} | ||
} | ||
} // namespace TiltBrush |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters