using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace UA_AtlasEditor { public partial class WeightSlider : Form { readonly float _min; readonly float _max; float _start; float _current; readonly AtlasShape.Info _info = AtlasShape.Info.Weight; readonly int _margin = 0; readonly int _width = 0; readonly AtlasShape.AtlasPoint _point; readonly MainForm _mainForm; public WeightSlider(float min, float max, AtlasShape.AtlasPoint point, MainForm mainForm, AtlasShape.Info info) { _mainForm = mainForm; _point = point; _info = info; _min = min; _max = max; switch(_info) { default: case AtlasShape.Info.Weight: _start = _current = point.Weight; break; case AtlasShape.Info.Depth: _start = _current = point.Depth; break; case AtlasShape.Info.OffsetX: _start = _current = point.OffsetX; break; case AtlasShape.Info.OffsetY: _start = _current = point.OffsetY; break; case AtlasShape.Info.OffsetSinus: _start = _current = point.OffsetSinus; break; } InitializeComponent(); trackBarWeight.Minimum = -1000; trackBarWeight.Maximum = 1000; _margin = trackBarWeight.Left; _width = trackBarWeight.Width; _margin = 12; _width = Width - 2 * _margin; } private void WeightSlider_Load(object sender, EventArgs e) { trackBarWeight.Capture = true; } public int valueToTrack( float value ) { float ratio = 0; if (value < _min) ratio = 0; else if (value > _max) ratio = 1; else ratio = (value - _min) / (_max - _min); return trackBarWeight.Minimum + (int)(ratio * (trackBarWeight.Maximum - trackBarWeight.Minimum)); } public int valueToPos(float value) { float ratio = 0; if (value < _min) ratio = 0; else if (value > _max) ratio = 1; else ratio = (value - _min) / (_max - _min); return _margin + (int)(ratio * _width); } public float posToRatio(int pos) { if (pos < _margin) return 0; if (pos > _margin + _width) return 1; return ((float)( pos - _margin) / (float) _width); } public float posToValue( int pos) { float value = _min + posToRatio(pos) * (_max - _min); bool canSnap = _mainForm._options._editSnapEnable; if (_mainForm.shortcutOn(MainForm.Shortcut.toggleSnap)) canSnap = !canSnap; if (canSnap) { int pos0 = valueToPos(0); int pos1 = valueToPos(value); if (Math.Abs(pos1 - pos0) < 5) value = 0; } return value; } public int posToTrack(int pos) { return valueToTrack(posToValue(pos)); } private void trackBarWeight_MouseDown(object sender, MouseEventArgs e) { trackBarWeight.Value = posToTrack(e.Location.X); } private void trackBarWeight_MouseMove(object sender, MouseEventArgs e) { trackBarWeight.Value = posToTrack(e.Location.X); switch (_info) { default: case AtlasShape.Info.Weight: _point.Weight = posToValue(e.Location.X); break; case AtlasShape.Info.Depth: _point.Depth = posToValue(e.Location.X); break; case AtlasShape.Info.OffsetX: _point.OffsetX = posToValue(e.Location.X); break; case AtlasShape.Info.OffsetY: _point.OffsetY = posToValue(e.Location.X); break; case AtlasShape.Info.OffsetSinus: _point.OffsetSinus = posToValue(e.Location.X); break; } _mainForm.Invalidate(); } private void trackBarWeight_MouseUp(object sender, MouseEventArgs e) { Console.WriteLine("MouseUp track"); Close(); } } }