-
Notifications
You must be signed in to change notification settings - Fork 96
/
SCAN_ColorSlope.cs
146 lines (115 loc) · 3.86 KB
/
SCAN_ColorSlope.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#region license
/*
* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* SCAN_ColorSlope - Script for controlling the slope color management UI
*
* Copyright (c)2014 David Grandy <david.grandy@gmail.com>;
* Copyright (c)2014 technogeeky <technogeeky@gmail.com>;
* Copyright (c)2014 (Your Name Here) <your email here>; see LICENSE.txt for licensing details.
*/
#endregion
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using SCANsat.Unity.Interfaces;
using SCANsat.Unity.HSVPicker.UI;
namespace SCANsat.Unity.Unity
{
public class SCAN_ColorSlope : SettingsPage
{
[SerializeField]
private SCAN_ColorPicker m_ColorPickerOne = null;
[SerializeField]
private SCAN_ColorPicker m_ColorPickerTwo = null;
[SerializeField]
private Slider m_CutoffSlider = null;
[SerializeField]
private TextHandler m_CutoffText = null;
[SerializeField]
private InputHandler m_CutoffInputField = null;
private bool loaded;
private ISCAN_Color colorInterface;
private ISCAN_Settings settingsInterface;
private void Awake()
{
if (m_CutoffInputField != null)
m_CutoffInputField.OnValueChange.AddListener(new UnityAction<string>(OnCutoffInputChange));
}
private void Update()
{
if (settingsInterface == null)
return;
if (settingsInterface.LockInput)
{
if (m_CutoffInputField != null && !m_CutoffInputField.IsFocused
&& m_ColorPickerOne != null && !m_ColorPickerOne.AnyInputActive
&& m_ColorPickerTwo != null && !m_ColorPickerTwo.AnyInputActive)
settingsInterface.LockInput = false;
}
}
public void SetSlope(ISCAN_Color color, ISCAN_Settings settings)
{
if (color == null)
return;
colorInterface = color;
settingsInterface = settings;
color.Refresh();
if (m_CutoffSlider != null)
m_CutoffSlider.value = color.SlopeCutoff;
if (m_ColorPickerOne != null)
m_ColorPickerOne.Setup(color.SlopeColorOneLo, color.SlopeColorOneHi, true);
if (m_ColorPickerTwo != null)
m_ColorPickerTwo.Setup(color.SlopeColorTwoLo, color.SlopeColorTwoHi, true);
loaded = true;
}
public void OnInputClick(BaseEventData eventData)
{
if (!(eventData is PointerEventData) || settingsInterface == null)
return;
if (((PointerEventData)eventData).button != PointerEventData.InputButton.Left)
return;
settingsInterface.LockInput = true;
}
public void Cutoff(float value)
{
if (m_CutoffText != null)
m_CutoffText.OnTextUpdate.Invoke(string.Format("Slope Cutoff: {0:N1}", value));
if (!loaded || colorInterface == null)
return;
colorInterface.SlopeCutoff = value;
}
public void OnCutoffInputChange(string input)
{
if (m_CutoffSlider == null)
return;
float cutoff = SCAN_ColorControl.ParseInput(input, m_CutoffSlider.value, m_CutoffSlider.minValue, m_CutoffSlider.maxValue, 1);
if (cutoff != m_CutoffSlider.value)
m_CutoffSlider.value = cutoff;
}
public void Apply()
{
if (colorInterface == null || m_ColorPickerOne == null || m_ColorPickerTwo == null)
return;
colorInterface.SlopeApply(m_ColorPickerOne.GetColorOne, m_ColorPickerOne.GetColorTwo, m_ColorPickerTwo.GetColorOne, m_ColorPickerTwo.GetColorTwo);
if (m_ColorPickerOne != null)
m_ColorPickerOne.Setup(m_ColorPickerOne.GetColorOne, m_ColorPickerOne.GetColorTwo, false);
if (m_ColorPickerTwo != null)
m_ColorPickerTwo.Setup(m_ColorPickerTwo.GetColorOne, m_ColorPickerTwo.GetColorTwo, false);
}
public void Default()
{
if (colorInterface == null)
return;
colorInterface.SlopeDefault();
if (m_ColorPickerOne != null)
m_ColorPickerOne.Setup(colorInterface.SlopeColorOneLo, colorInterface.SlopeColorOneHi, false);
if (m_ColorPickerTwo != null)
m_ColorPickerTwo.Setup(colorInterface.SlopeColorTwoLo, colorInterface.SlopeColorTwoHi, false);
}
}
}