253 lines
9.5 KiB
C#
253 lines
9.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using System.Text;
|
|
using System.Drawing;
|
|
|
|
namespace UA_AtlasEditor
|
|
{
|
|
public partial class MainForm
|
|
{
|
|
//-----------------------------------------------------------------------------------------
|
|
Point _paintPosition = new Point(0, 0);
|
|
Cursor _paintCursor = null;
|
|
Cursor _paintCursorNeg = null;
|
|
AtlasShape.Info _paintInfo = AtlasShape.Info.Weight;
|
|
float _paintRadiusOox2 = 1;
|
|
float _paintRadiusOoy2 = 1;
|
|
bool _paintNeg = false;
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintSetMode( bool value)
|
|
{
|
|
_options._paintMode = value;
|
|
paintModeCursorDestroy();
|
|
if (_options._paintMode)
|
|
paintModeCursorCreate();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintSetFlat(bool value)
|
|
{
|
|
_options._paintFlat = value;
|
|
if (!_options._paintMode) return;
|
|
paintModeCursorDestroy();
|
|
paintModeCursorCreate();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintSetOpacity( int value)
|
|
{
|
|
if (value <= 0) _options._paintOpacity = 0;
|
|
else if (value >= 100) _options._paintOpacity = 1;
|
|
else _options._paintOpacity = ((float)value) / 100;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintSetAdd(bool value)
|
|
{
|
|
_options._paintAdd = value;
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintSetRadius( int value)
|
|
{
|
|
if (value == _options._paintRadius)
|
|
return;
|
|
_options._paintRadius = Math.Min(200, Math.Max(10, value));
|
|
if (!_options._paintMode) return;
|
|
paintModeCursorDestroy();
|
|
paintModeCursorCreate();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintSetValueSetMin(float value)
|
|
{
|
|
_options._paintValueSetMin = value;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintSetValueSetMax(float value)
|
|
{
|
|
_options._paintValueSetMax = value;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintSetValueAdd(float value)
|
|
{
|
|
_options._paintValueAdd = value;
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintModePaint(Graphics graphics)
|
|
{
|
|
if (!_options._paintMode) return;
|
|
|
|
Pen pen = new Pen(Color.Black, 1);
|
|
graphics.DrawEllipse(pen, _paintPosition.X - _options._paintRadius, _paintPosition.Y - _options._paintRadius, _options._paintRadius * 2, _options._paintRadius * 2);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private bool paintModePaintSetCursor(Point pos)
|
|
{
|
|
if (!_options._paintMode) return false;
|
|
if (!_atlasArea.isWinPointInside(pos)) return false;
|
|
|
|
paintModeCursorCreate();
|
|
_paintNeg = ((Control.ModifierKeys & Keys.Alt) == Keys.Alt);
|
|
|
|
if (!_paintNeg )
|
|
Cursor = _paintCursor;
|
|
|
|
Cursor = _paintNeg ? _paintCursorNeg : _paintCursor;
|
|
_paintPosition = pos;
|
|
return true;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintModeCursorDestroy()
|
|
{
|
|
if (_paintCursor != null) _paintCursor.Dispose();
|
|
_paintCursor = null;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void paintModeCursorCreate()
|
|
{
|
|
if (_paintCursor != null) return;
|
|
|
|
int radius = _options._paintRadius;
|
|
Bitmap bitmap = new Bitmap(radius * 2 + 1, radius * 2 + 1);
|
|
|
|
Graphics graphics = Graphics.FromImage(bitmap);
|
|
Pen pen = new Pen(Color.Black);
|
|
|
|
graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
|
|
graphics.Clear(Color.FromArgb(0, 0, 0, 0));
|
|
graphics.DrawEllipse(pen, 0, 0, bitmap.Width - 1, bitmap.Height - 1);
|
|
|
|
if (_options._paintFlat)
|
|
graphics.FillEllipse(new SolidBrush(Color.Black), radius - 5, radius - 5, 10, 10);
|
|
else
|
|
{
|
|
graphics.FillEllipse(new SolidBrush(Color.LightGray), radius - 5, radius - 5, 10, 10);
|
|
graphics.FillEllipse(new SolidBrush(Color.DarkGray), radius - 4, radius - 4, 8, 8);
|
|
graphics.FillEllipse(new SolidBrush(Color.Black), radius - 3, radius - 3, 6, 6);
|
|
}
|
|
|
|
pen.Color = Color.White;
|
|
graphics.DrawLine(pen, radius - 3, radius, radius + 3, radius);
|
|
|
|
_paintCursorNeg = CreateCursor(bitmap, radius, radius);
|
|
|
|
graphics.DrawLine(pen, radius, radius-3, radius, radius+3);
|
|
_paintCursor = CreateCursor(bitmap, radius, radius);
|
|
|
|
graphics.Dispose();
|
|
bitmap.Dispose();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private bool paintModeApplyOnPoint( AtlasShape shape, int point, PointF center, PointF radius )
|
|
{
|
|
PointF diff = new PointF(shape._listPoint[point].Position.X - center.X, shape._listPoint[point].Position.Y - center.Y);
|
|
|
|
float value0;
|
|
value0 = diff.X * diff.X * _paintRadiusOox2;
|
|
value0 += diff.Y * diff.Y * _paintRadiusOoy2;
|
|
|
|
if (value0 > 1) return false;
|
|
|
|
float value1 = shape.GetPointInfo(point, _paintInfo);
|
|
|
|
float ratio = _options._paintFlat ? 1 : value0;
|
|
ratio *= _options._paintOpacity;
|
|
|
|
if (_options._paintAdd)
|
|
{
|
|
value0 = value1 + _options._paintValueAdd * ratio * (_paintNeg ? -1 : 1);
|
|
}
|
|
else
|
|
{
|
|
value0 = ratio * (_paintNeg ? _options._paintValueSetMin : _options._paintValueSetMax) + (1 - ratio) * value1;
|
|
}
|
|
|
|
if (Math.Abs(value0 - value1) < float.Epsilon) return false;
|
|
|
|
shape.SetPointInfo(point, _paintInfo, value0);
|
|
return true;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private bool paintModeApply( Point pos)
|
|
{
|
|
PointF center = _atlasArea.point_win2atlas(pos);
|
|
PointF border = _atlasArea.point_win2atlas(new Point(pos.X + _options._paintRadius, pos.Y + _options._paintRadius));
|
|
PointF radius = new PointF(border.X - center.X, border.Y - center.Y);
|
|
_paintRadiusOox2 = 1 / (radius.X * radius.X);
|
|
_paintRadiusOoy2 = 1 / (radius.Y * radius.Y);
|
|
bool result = false;
|
|
|
|
for (int i = 0; i < _displayedAtlas.Shape.Count; i++)
|
|
{
|
|
if (!_displayedAtlas.Shape[i]._draw) continue;
|
|
if (!_displayedAtlas.Shape[i]._selected) continue;
|
|
|
|
AtlasShape shape = _displayedAtlas.Shape[i];
|
|
|
|
if (!shape.UseListPoint()) continue;
|
|
|
|
if (shape._drawPointWeight)
|
|
_paintInfo = AtlasShape.Info.Weight;
|
|
else if (shape._drawPointDepth)
|
|
_paintInfo = AtlasShape.Info.Depth;
|
|
else if (shape._drawPointOffsetX)
|
|
_paintInfo = AtlasShape.Info.OffsetX;
|
|
else if (shape._drawPointOffsetY)
|
|
_paintInfo = AtlasShape.Info.OffsetY;
|
|
else if (shape._drawPointOffsetSinus)
|
|
_paintInfo = AtlasShape.Info.OffsetSinus;
|
|
else if (shape._drawPointColor)
|
|
_paintInfo = AtlasShape.Info.VertexColor;
|
|
else
|
|
continue;
|
|
|
|
for (int j = 0; j < shape._listPoint.Count; j++)
|
|
result |= paintModeApplyOnPoint( shape, j, center, radius);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private int paintModeMouseDown(Point pos)
|
|
{
|
|
if (!_options._paintMode) return 0;
|
|
if (_capturedBy != 0)
|
|
{
|
|
if (_capturedBy != c_capturedby_atlaspaintmode) return 0;
|
|
return 0;
|
|
}
|
|
|
|
if (!_atlasArea.isWinPointInside(pos)) return 0;
|
|
|
|
undoPush(true);
|
|
return (c_result_capture | (paintModeApply(pos) ? c_result_invalidate : 0));
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private int paintModeMouseMove(Point pos)
|
|
{
|
|
if (!_options._paintMode) return 0;
|
|
if (_capturedBy != c_capturedby_atlaspaintmode)
|
|
return 0;
|
|
|
|
return (paintModeApply(pos) ? c_result_invalidate : 0);
|
|
}
|
|
|
|
|
|
}
|
|
}
|