由于要从底层重新写自己的控件,花了一定的时间,目前已经完成基类的工作,并用基类派生了三个简单的控件(Button,Label和CheckBox),均已调试完毕。
下面直接给出完整的D3D_Control类。
public abstract class D3D_Control
{
private string m_ControlName;
private D3D_Scene m_Scene;
private D3D_Control m_Parent;
private bool m_Loaded;
private bool m_Show;
private Point m_Location;
private Size m_Size;
private bool m_TopMost;
private bool m_Visible;
private bool m_Enable;
private bool m_CanFocus;
private bool m_Focus;
private bool m_MouseEntered;
private Sprite m_Sprite;
private Color m_TextureBackColor;
private float m_TextureTransparency;
private Texture m_Texture;
private int m_CurState;
private List<Rectangle> m_RectanglesInTexture;
private Color m_BGIColor;
private float m_BGITransparency;
private bool m_BGIAutoScaleEnable;
private bool m_BGIAutoScrollEnable;
private Rectangle m_RectangleInBGI;
private Size m_BGISize;
private Texture m_BGITexture;
private int m_BGIBorderWidth;
private int m_BGIScrollDefaultStep;
private int m_BGIScrollXStep;
private int m_BGIScrollYStep;
private string m_Text;
private Color m_TextColor;
private System.Drawing.Font m_TextFont;
public string Name { get { return m_ControlName; } set { m_ControlName = value; } }
public D3D_Scene Scene
{
get { return m_Scene; }
private set
{
m_Scene = value;
}
}
public D3DDevice Device
{
get
{
if(Scene!=null) return Scene.Device;
return null;
}
}
public D3D_Control Parent { get { return m_Parent; } set { m_Parent = value; } }
public bool Loaded
{
get { return m_Loaded; }
set
{
if (Loaded == value) return;
m_Loaded = value;
if (Loaded && Load != null) Load(this, null);
}
}
public bool Show
{
get { return m_Show; }
set
{
if (Show == value) return;
m_Show = value;
if (Show && !Loaded) Loaded = true;
}
}
public Point Location
{
get
{
return m_Location;
}
set
{
m_Location = value;
if (LocationChanged != null) LocationChanged(this, null);
}
}
public Size Size
{
get
{
return m_Size;
}
set
{
m_Size = value;
if (SizeChanged != null) SizeChanged(this, null);
}
}
public int Left { get { return Location.X; } }
public int Top { get { return Location.Y; } }
public int Right { get { return Location.X + Size.Width - 1; } }
public int Bottom { get { return Location.Y + Size.Height - 1; } }
public int Width { get { return Size.Width; } }
public int Height { get { return Size.Height; } }
public virtual Rectangle DisplayRectangle
{
get
{
Rectangle rect = new Rectangle(this.Location, this.Size);
if (Parent != null)
{
rect.Offset(Parent.ClientRectangle.Location);
}
return rect;
}
}
public virtual Rectangle ClientRectangle { get { return new Rectangle(Location, Size); } }
public Point MousePosition
{
get
{
if (Scene != null && Scene.Form != null) return this.Scene.Form.PointToClient(Cursor.Position);
return Cursor.Position;
}
}
public bool TopMost { get { return m_TopMost; } set { m_TopMost = value; } }
public float ZPos { get { return TopMost ? 0.0f : 1.0f; } }
public virtual bool Visibled { get { return m_Visible; } set { m_Visible = value; } }
public virtual bool Enabled { get { return m_Enable; } set { m_Enable = value; } }
public bool CanFocus { get { return m_CanFocus; } set { m_CanFocus = value; } }
public bool Focused
{
get
{
return m_Focus;
}
set
{
m_Focus = value;
if (Focused)
{
if (GotFocus != null) GotFocus(this, null);
}
else
{
if (LostFocus != null) LostFocus(this, null);
}
}
}
public bool MouseEntered
{
get
{
return m_MouseEntered;
}
set
{
m_MouseEntered = value;
if (MouseEntered && MouseEnter != null) MouseEnter(this, null);
if (!MouseEntered && MouseLeave != null) MouseLeave(this, null);
}
}
protected Sprite Sprite { get { return m_Sprite; } private set { m_Sprite = value; } }
public Color TextureBackColor { get { return m_TextureBackColor; } set { m_TextureBackColor = value; } }
public float TextureTransparency
{
get { return m_TextureTransparency; }
set
{
m_TextureTransparency = value;
if (m_TextureTransparency < 0.0f) m_TextureTransparency = 0.0f;
if (m_TextureTransparency > 100.0f) m_TextureTransparency = 100.0f;
TextureBackColor = Color.FromArgb((byte)(2.55f * (100.0f - TextureTransparency)), TextureBackColor);
}
}
public Texture Texture { get { return m_Texture; }