using System;
using System .Collections .Generic;
using System .ComponentModel;
using System .Drawing;
using System .Windows .Forms;
using Microsoft .Win32;
using MoveGraphLibrary;
namespace GraphicalPrimitives
{
public class SpotCC : GraphicalObject
{
int m_version = 618;
Form form;
Mover supervisor;
PointF m_center;
int m_radius = 5;
Color m_color = Color .Red;
static int radMin = 3;
static int radMax = 12;
// -------------------------------------------------
public SpotCC (Form frm, Mover mvr, PointF ptC, int radius, Color color)
{
form = frm;
supervisor = mvr;
m_center = ptC;
m_radius = Math .Min (Math .Max (radMin, radius), radMax);
m_color = color;
}
public SpotCC (Form frm, Mover mvr, PointF ptC, int radius)
: this (frm, mvr, ptC, radius, Color .Red)
{
}
public SpotCC (Form frm, Mover mvr, PointF ptC, Color color)
: this (frm, mvr, ptC, 5, color)
{
}
public SpotCC (Form frm, Mover mvr, PointF ptC)
: this (frm, mvr, ptC, 5, Color .Red)
{
}
public SpotCC (Form frm, Mover mvr, double fx, double fy)
: this (frm, mvr, new PointF (Convert .ToSingle (fx), Convert .ToSingle (fy)), 5, Color .Red)
{
}
// ------------------------------------------------- CopyView
public void CopyView (SpotCC src)
{
m_radius = src .Radius;
m_color = src .Color;
DefineCover ();
}
// ------------------------------------------------- RectAround
new public RectangleF RectAround
{
get
{
return (new RectangleF (m_center .X - m_radius, m_center .Y - m_radius, 2 * m_radius, 2 * m_radius));
}
}
// ------------------------------------------------- Center
public PointF Center
{
get { return (m_center); }
set
{
m_center = value;
DefineCover ();
}
}
// ------------------------------------------------- Radius
public int Radius
{
get { return (m_radius); }
set
{
m_radius = Math .Min (Math .Max (radMin, value), radMax);
DefineCover ();
}
}
// ------------------------------------------------- MinRadius
static public int MinRadius
{
get { return (radMin); }
}
// ------------------------------------------------- MaxRadius
static public int MaxRadius
{
get { return (radMax); }
}
// ------------------------------------------------- Color
public Color Color
{
get { return (m_color); }
set { m_color = value; }
}
// ------------------------------------------------- Draw
public void Draw (Graphics grfx)
{
Auxi_Drawing .FillEllipse (grfx, m_center, m_radius, m_color);
}
// ------------------------------------------------- StartMoving
public void StartMoving ()
{
supervisor .MouseTraced = false;
Cursor .Position = form .PointToScreen (Point .Round (m_center));
supervisor .MouseTraced = true;
}
// ------------------------------------------------- DefineCover
public override void DefineCover ()
{
cover = new Cover (new CoverNode (0, m_center, Math .Max (m_radius, 5)));
}
// ------------------------------------------------- Move
public override void Move (int dx, int dy)
{
m_center += new Size (dx, dy);
}
// ------------------------------------------------- MoveNode
public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons catcher)
{
bool bRet = false;
if (catcher == MouseButtons .Left)
{
Center = ptM;
bRet = true;
}
return (bRet);
}
// ------------------------------------------------- IntoRegistry
public void IntoRegistry (RegistryKey regkey, string name)
{
try
{
regkey .SetValue (name, new string [] { m_version .ToString (), // 0
m_center .X .ToString (), // 1
m_center .Y .ToString (), // 2
m_radius .ToString (), // 3
((int) (m_color .A)) .ToString (), // 4
((int) (m_color .R)) .ToString (), // 5
((int) (m_color .G)) .ToString (), // 6
((int) (m_color .B)) .ToString () }, // 7
RegistryValueKind .MultiString);
}
catch
{
}
finally
{
}
}
// -------------------------------------------------
public static SpotCC FromRegistry (Form frm, Mover mvr, RegistryKey regkey, string name)
{
try
{
string [] str = (string []) regkey .GetValue (name);
if (frm != null && mvr != null &&
str != null && str .Length >= 8 && Convert .ToInt32 (str [0]) >= 618)
{
SpotCC spot = new SpotCC (frm, mvr,
Auxi_Convert .ToPointF (str, 1), // 1, 2 point
Convert .ToInt32 (str [3]), // 3 radius
Auxi_Convert .ToColor (str, 4)); // 4 - 7 color
return (spot);
}
else
{
return (null);
}
}
catch
{
return (null);
}
finally
{
}
}
}
}