123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using Client.MirGraphics;
- using Client.MirSounds;
- using Microsoft.DirectX;
- using Microsoft.DirectX.Direct3D;
- namespace Client.MirControls
- {
- public class MirControl : IDisposable
- {
- public static MirControl ActiveControl, MouseControl;
-
- public virtual Point DisplayLocation { get { return Parent == null ? Location : Parent.DisplayLocation.Add(Location); } }
- public Rectangle DisplayRectangle { get { return new Rectangle(DisplayLocation, Size); } }
- public bool GrayScale { get; set; }
- public bool Blending { get; set; }
- public float BlendingRate { get; set; }
- public BlendMode BlendMode { get; set; }
- public bool drawimgaes=true;
- public bool Zoom = false;
- public float zoomrate;
- #region Back Colour
- private Color _backColour;
- public Color BackColour
- {
- get { return _backColour; }
- set
- {
- if (_backColour == value)
- return;
- _backColour = value;
- OnBackColourChanged();
- }
- }
- public event EventHandler BackColourChanged;
- protected virtual void OnBackColourChanged()
- {
- TextureValid = false;
- Redraw();
- if (BackColourChanged != null)
- BackColourChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Border
- protected Rectangle BorderRectangle;
- private bool _border;
- protected Vector2[] _borderInfo;
- protected virtual Vector2[] BorderInfo
- {
- get
- {
- if (Size == Size.Empty)
- return null;
- if (BorderRectangle != DisplayRectangle)
- {
- _borderInfo = new[]
- {
- new Vector2(DisplayRectangle.Left - 1, DisplayRectangle.Top - 1),
- new Vector2(DisplayRectangle.Right, DisplayRectangle.Top - 1),
- new Vector2(DisplayRectangle.Left - 1, DisplayRectangle.Top - 1),
- new Vector2(DisplayRectangle.Left - 1, DisplayRectangle.Bottom),
- new Vector2(DisplayRectangle.Left - 1, DisplayRectangle.Bottom),
- new Vector2(DisplayRectangle.Right, DisplayRectangle.Bottom),
- new Vector2(DisplayRectangle.Right, DisplayRectangle.Top - 1),
- new Vector2(DisplayRectangle.Right, DisplayRectangle.Bottom)
- };
- BorderRectangle = DisplayRectangle;
- }
- return _borderInfo;
- }
- }
- public virtual bool Border
- {
- get { return _border; }
- set
- {
- if (_border == value)
- return;
- _border = value;
- OnBorderChanged();
- }
- }
- public event EventHandler BorderChanged;
- private void OnBorderChanged()
- {
- Redraw();
- if (BorderChanged != null)
- BorderChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Border Colour
- private Color _borderColour;
- public Color BorderColour
- {
- get { return _borderColour; }
- set
- {
- if (_borderColour == value)
- return;
- _borderColour = value;
- OnBorderColourChanged();
- }
- }
- public event EventHandler BorderColourChanged;
- private void OnBorderColourChanged()
- {
- Redraw();
- if (BorderColourChanged != null)
- BorderColourChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Control Texture
- public long CleanTime;
- protected Texture ControlTexture;
- protected internal bool TextureValid;
- private bool _drawControlTexture;
- protected Size TextureSize;
- public bool DrawControlTexture
- {
- get { return _drawControlTexture; }
- set
- {
- if (_drawControlTexture == value)
- return;
- _drawControlTexture = value;
- Redraw();
- }
- }
- protected virtual void CreateTexture()
- {
- if (ControlTexture != null && !ControlTexture.Disposed && Size != TextureSize)
- ControlTexture.Dispose();
- if (ControlTexture == null || ControlTexture.Disposed)
- {
- DXManager.ControlList.Add(this);
-
- // ControlTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
- try
- {
- ControlTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 0, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
- }
- catch (Exception)
- {
- throw;
- }
- ControlTexture.Disposing += ControlTexture_Disposing;
- TextureSize = Size;
- }
- Surface oldSurface = DXManager.CurrentSurface;
- Surface surface = ControlTexture.GetSurfaceLevel(0);
- DXManager.SetSurface(surface);
- DXManager.Device.Clear(ClearFlags.Target, BackColour, 0, 0);
- DXManager.SetSurface(oldSurface);
- TextureValid = true;
- surface.Dispose();
- }
- protected void ControlTexture_Disposing(object sender, EventArgs e)
- {
- ControlTexture = null;
- TextureValid = false;
- TextureSize = Size.Empty;
- DXManager.ControlList.Remove(this);
- }
- internal void DisposeTexture()
- {
- if (ControlTexture == null || ControlTexture.Disposed) return;
- ControlTexture.Dispose();
- }
- #endregion
- #region Controls
- public List<MirControl> Controls { get; private set; }
- public event EventHandler ControlAdded , ControlRemoved;
- private void AddControl(MirControl control)
- {
- Controls.Add(control);
- OnControlAdded();
- }
- public void InsertControl(int index, MirControl control)
- {
- if (control.Parent != this)
- {
- control.Parent = null;
- control._parent = this;
- }
- if (index >= Controls.Count)
- Controls.Add(control);
- else
- {
- Controls.Insert(index, control);
- OnControlAdded();
- }
- }
- private void RemoveControl(MirControl control)
- {
- Controls.Remove(control);
- OnControlRemoved();
- }
- private void OnControlAdded()
- {
- Redraw();
- if (ControlAdded != null)
- ControlAdded.Invoke(this, EventArgs.Empty);
- }
- private void OnControlRemoved()
- {
- Redraw();
- if (ControlRemoved != null)
- ControlRemoved.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Enabled
- private bool _enabled;
- public bool Enabled
- {
- internal get { return Parent == null ? _enabled : Parent.Enabled && _enabled; }
- set
- {
- if (_enabled == value)
- return;
- _enabled = value;
- OnEnabledChanged();
- }
- }
- public event EventHandler EnabledChanged;
- protected virtual void OnEnabledChanged()
- {
- Redraw();
- if (EnabledChanged != null)
- EnabledChanged.Invoke(this, EventArgs.Empty);
- if (!Enabled && ActiveControl == this)
- ActiveControl.Deactivate();
- if (Controls != null)
- foreach (MirControl control in Controls)
- control.OnEnabledChanged();
- }
- #endregion
- #region Events
- protected bool HasShown;
- public event EventHandler Click , DoubleClick, BeforeDraw , AfterDraw , MouseEnter , MouseLeave , Shown , BeforeShown, Disposing;
- public event MouseEventHandler MouseWheel,MouseMove, MouseDown, MouseUp;
- public event KeyEventHandler KeyDown , KeyUp;
- public event KeyPressEventHandler KeyPress;
- #endregion
- #region Fore Colour
- private Color _foreColour;
- public Color ForeColour
- {
- get { return _foreColour; }
- set
- {
- if (_foreColour == value)
- return;
- _foreColour = value;
- OnForeColourChanged();
- }
- }
- public event EventHandler ForeColourChanged;
- protected virtual void OnForeColourChanged()
- {
- TextureValid = false;
- if (ForeColourChanged != null)
- ForeColourChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Location
- private Point _location;
- public Point Location
- {
- get { return _location; }
- set
- {
- if (_location == value)
- return;
- _location = value;
- OnLocationChanged();
- }
- }
- public event EventHandler LocationChanged;
- protected virtual void OnLocationChanged()
- {
- Redraw();
- if (Controls != null)
- for (int i = 0; i < Controls.Count; i++)
- Controls[i].OnLocationChanged();
- if (LocationChanged != null)
- LocationChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Hint
- private string _hint;
- public string Hint
- {
- get { return _hint; }
- set
- {
- if (_hint == value)
- return;
- _hint = value;
- OnHintChanged(EventArgs.Empty);
- }
- }
- public event EventHandler HintChanged;
- private void OnHintChanged(EventArgs e)
- {
- Redraw();
- if (HintChanged != null)
- HintChanged.Invoke(this, e);
- }
- #endregion
- #region Modal
- private bool _modal;
- public bool Modal
- {
- get { return _modal; }
- set
- {
- if (_modal == value)
- return;
- _modal = value;
- OnModalChanged();
- }
- }
- public event EventHandler ModalChanged;
- private void OnModalChanged()
- {
- Redraw();
- if (ModalChanged != null)
- ModalChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Movable
- protected internal bool Moving;
- private bool _movable;
- private Point _movePoint;
- public bool Movable
- {
- get { return _movable; }
- set
- {
- if (_movable == value)
- return;
- _movable = value;
- OnMovableChanged();
- }
- }
- public event EventHandler MovableChanged;
- public event MouseEventHandler OnMoving;
- private void OnMovableChanged()
- {
- Redraw();
- if (MovableChanged != null)
- MovableChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Not Control
- private bool _notControl;
- public bool NotControl
- {
- private get { return _notControl; }
- set
- {
- if (_notControl == value)
- return;
- _notControl = value;
- OnNotControlChanged();
- }
- }
- public event EventHandler NotControlChanged;
- private void OnNotControlChanged()
- {
- Redraw();
- if (NotControlChanged != null)
- NotControlChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Opacity
- private float _opacity;
- public float Opacity
- {
- get { return _opacity; }
- set
- {
- if (value > 1F)
- value = 1F;
- if (value < 0F)
- value = 0;
- if (_opacity == value)
- return;
- _opacity = value;
- OnOpacityChanged();
- }
- }
- public event EventHandler OpacityChanged;
- private void OnOpacityChanged()
- {
- Redraw();
- if (OpacityChanged != null)
- OpacityChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Parent
- private MirControl _parent;
- public MirControl Parent
- {
- get { return _parent; }
- set
- {
- if (_parent == value) return;
- if (_parent != null)
- _parent.RemoveControl(this);
- _parent = value;
- if (_parent != null)
- _parent.AddControl(this);
- OnParentChanged();
- }
- }
- public event EventHandler ParentChanged;
- protected virtual void OnParentChanged()
- {
- OnLocationChanged();
- if (ParentChanged != null)
- ParentChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Size
- // ReSharper disable InconsistentNaming
- protected Size _size;
- // ReSharper restore InconsistentNaming
- public virtual Size Size
- {
- get { return _size; }
- set
- {
- if (_size == value)
- return;
- _size = value;
- OnSizeChanged();
- }
- }
- public virtual Size TrueSize
- {
- get { return _size; }
- }
- public event EventHandler SizeChanged;
- protected virtual void OnSizeChanged()
- {
- TextureValid = false;
- Redraw();
-
- if (SizeChanged != null)
- SizeChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Sound
- private int _sound;
- public int Sound
- {
- get { return _sound; }
- set
- {
- if (_sound == value)
- return;
- _sound = value;
- OnSoundChanged();
- }
- }
- public event EventHandler SoundChanged;
- private void OnSoundChanged()
- {
- if (SoundChanged != null)
- SoundChanged.Invoke(this, EventArgs.Empty);
- }
- #endregion
- #region Sort
- private bool _sort;
- public bool Sort
- {
- get { return _sort; }
- set
- {
- if (_sort == value)
- return;
- _sort = value;
- OnSortChanged();
- }
- }
- public event EventHandler SortChanged;
- private void OnSortChanged()
- {
- Redraw();
- if (SortChanged != null)
- SortChanged.Invoke(this, EventArgs.Empty);
- }
- public void TrySort()
- {
- if (Parent == null)
- return;
- Parent.TrySort();
- if (Parent.Controls[Parent.Controls.Count - 1] == this)
- return;
- if (!Sort) return;
- Parent.Controls.Remove(this);
- Parent.Controls.Add(this);
- Redraw();
- }
- #endregion
- #region Visible
- private bool _visible;
- public virtual bool Visible
- {
- get { return Parent == null ? _visible : Parent.Visible && _visible; }
- set
- {
- if (_visible == value)
- return;
- _visible = value;
- OnVisibleChanged();
- }
- }
- public event EventHandler VisibleChanged;
- protected virtual void OnVisibleChanged()
- {
- Redraw();
- if (VisibleChanged != null)
- VisibleChanged.Invoke(this, EventArgs.Empty);
- Moving = false;
- _movePoint = Point.Empty;
- if (Sort && Parent != null)
- {
- Parent.Controls.Remove(this);
- Parent.Controls.Add(this);
- }
- if (MouseControl == this && !Visible)
- {
- Dehighlight();
- Deactivate();
- }
- else if (IsMouseOver(CMain.MPoint))
- Highlight();
- if (Controls != null)
- foreach (MirControl control in Controls)
- control.OnVisibleChanged();
- }
- protected void OnBeforeShown()
- {
- if (HasShown)
- return;
- if (Visible && IsMouseOver(CMain.MPoint))
- Highlight();
- if (BeforeShown != null)
- BeforeShown.Invoke(this, EventArgs.Empty);
- }
- protected void OnShown()
- {
- if (HasShown)
- return;
- if (Shown != null)
- Shown.Invoke(this, EventArgs.Empty);
-
- HasShown = true;
- }
- #endregion
- #region MultiLine
- public virtual void MultiLine()
- {
- }
- #endregion
- #region Positions
- protected Point Center
- {
- get { return new Point((Settings.ScreenWidth - Size.Width) / 2, (Settings.ScreenHeight - Size.Height) / 2); }
- }
- protected Point Left
- {
- get { return new Point(0, (Settings.ScreenHeight - Size.Height) / 2); }
- }
- protected Point Top
- {
- get { return new Point((Settings.ScreenWidth - Size.Width) / 2, 0); }
- }
- protected Point Right
- {
- get { return new Point(Settings.ScreenWidth - Size.Width, (Settings.ScreenHeight - Size.Height) / 2); }
- }
- protected Point Bottom
- {
- get { return new Point((Settings.ScreenWidth - Size.Width) / 2, Settings.ScreenHeight - Size.Height); }
- }
- protected Point TopLeft
- {
- get { return new Point(0, 0); }
- }
- protected Point TopRight
- {
- get { return new Point(Settings.ScreenWidth - Size.Width, 0); }
- }
- protected Point BottomRight
- {
- get { return new Point(Settings.ScreenWidth - Size.Width, Settings.ScreenHeight - Size.Height); }
- }
- protected Point BottomLeft
- {
- get { return new Point(0, Settings.ScreenHeight - Size.Height); }
- }
- #endregion
- public void BringToFront()
- {
- if (Parent == null) return;
- int index = _parent.Controls.IndexOf(this);
- if (index == _parent.Controls.Count - 1) return;
- _parent.Controls.RemoveAt(index);
- _parent.Controls.Add(this);
- Redraw();
- }
- public MirControl()
- {
- Controls = new List<MirControl>();
- _opacity = 1F;
- _enabled = true;
- _foreColour = Color.White;
- _visible = true;
- _sound = SoundList.None;
- }
- public virtual void Draw()
- {
- // if (IsDisposed || !Visible ||!drawimgaes/*|| Size.Width == 0 || Size.Height == 0*/ || Size.Width > Settings.ScreenWidth || Size.Height > Settings.ScreenHeight)
- // return;
- if (IsDisposed || !Visible || !drawimgaes/*|| Size.Width == 0 || Size.Height == 0*/ || (!Zoom && Size.Width > Settings.ScreenWidth) || (!Zoom&& Size.Height > Settings.ScreenHeight))
- return;
- OnBeforeShown();
- BeforeDrawControl();
- DrawControl();
- DrawChildControls();
- DrawBorder();
- AfterDrawControl();
- CleanTime = CMain.Time + Settings.CleanDelay;
- OnShown();
- }
- protected virtual void BeforeDrawControl()
- {
- if (BeforeDraw != null)
- BeforeDraw.Invoke(this, EventArgs.Empty);
- }
- protected internal virtual void DrawControl()
- {
- if (!DrawControlTexture)
- return;
- if (!TextureValid)
- CreateTexture();
- if (ControlTexture == null || ControlTexture.Disposed)
- return;
- float oldOpacity = DXManager.Opacity;
- DXManager.SetOpacity(Opacity);
- DXManager.Device.RenderState.AlphaBlendEnable = true;
- DXManager.Sprite.Transform = Microsoft.DirectX.Matrix.Translation(DisplayLocation.X, DisplayLocation.Y, 0f);
- DXManager.Sprite.Draw(ControlTexture, Rectangle.Empty, Vector3.Empty, new Vector3(0, 0, 0), Color.White);
- DXManager.Sprite.Transform = Microsoft.DirectX.Matrix.Identity;
- // DXManager.Sprite.Draw2D(ControlTexture, Point.Empty, 0F, DisplayLocation, Color.White);
-
- DXManager.SetOpacity(oldOpacity);
- CleanTime = CMain.Time + Settings.CleanDelay;
- }
- protected void DrawChildControls()
- {
- if (Controls != null)
- for (int i = 0; i < Controls.Count; i++)
- {
- if (Controls[i] == null) continue;
- if (Controls[i] != null)
- Controls[i].Draw();
- }
- }
- protected virtual void DrawBorder()
- {
- if (!Border || BorderInfo == null)
- return;
- DXManager.Sprite.Flush();
- DXManager.Line.Draw(BorderInfo, _borderColour);
- }
- protected void AfterDrawControl()
- {
- if (AfterDraw != null)
- AfterDraw.Invoke(this, EventArgs.Empty);
- }
- protected virtual void Deactivate()
- {
- if (ActiveControl != this)
- return;
- ActiveControl = null;
- Moving = false;
- _movePoint = Point.Empty;
- }
- protected virtual void Dehighlight()
- {
- if (MouseControl != this)
- return;
- MouseControl.OnMouseLeave();
- MouseControl = null;
- }
- protected virtual void Activate()
- {
- if (ActiveControl == this)
- return;
- if (ActiveControl != null)
- ActiveControl.Deactivate();
- ActiveControl = this;
- }
- protected virtual void Highlight()
- {
- if (MouseControl == this)
- return;
- if (NotControl)
- {
- }
- if (MouseControl != null)
- MouseControl.Dehighlight();
- if (ActiveControl != null && ActiveControl != this) return;
- OnMouseEnter();
- MouseControl = this;
- }
- public virtual bool IsMouseOver(Point p)
- {
- return Visible && (DisplayRectangle.Contains(p) || Moving || Modal) && !NotControl;
- }
- protected virtual void OnMouseEnter()
- {
- if (!_enabled)
- return;
- Redraw();
- if (MouseEnter != null)
- MouseEnter.Invoke(this, EventArgs.Empty);
- }
- protected virtual void OnMouseLeave()
- {
- if (!_enabled)
- return;
- Redraw();
- if (MouseLeave != null)
- MouseLeave.Invoke(this, EventArgs.Empty);
- }
- public virtual void OnMouseClick(MouseEventArgs e)
- {
-
- if (!Enabled)
- return;
- if (Sound != SoundList.None)
- SoundManager.PlaySound(Sound);
- if (Click != null)
- InvokeMouseClick(e);
- }
- public virtual void OnMouseDoubleClick(MouseEventArgs e)
- {
- if (!Enabled)
- return;
- if (DoubleClick != null)
- {
- if (Sound != SoundList.None)
- SoundManager.PlaySound(Sound);
- InvokeMouseDoubleClick(e);
- }
- else
- OnMouseClick(e);
- }
- public void InvokeMouseClick(EventArgs e)
- {
- if (Click != null)
- Click.Invoke(this, e);
- }
- public void InvokeMouseDoubleClick(EventArgs e)
- {
- DoubleClick.Invoke(this, e);
- }
- public virtual void OnMouseMove(MouseEventArgs e)
- {
- if (!_enabled)
- return;
- if (Moving)
- {
- Point tempPoint = CMain.MPoint.Subtract(_movePoint);
- if (Parent == null)
- {
- if (tempPoint.Y + TrueSize.Height > Settings.ScreenHeight)
- tempPoint.Y = Settings.ScreenHeight - TrueSize.Height - 1;
- if (tempPoint.X + TrueSize.Width > Settings.ScreenWidth)
- tempPoint.X = Settings.ScreenWidth - TrueSize.Width - 1;
- }
- else
- {
- if (tempPoint.Y + TrueSize.Height > Parent.TrueSize.Height)
- tempPoint.Y = Parent.TrueSize.Height - TrueSize.Height;
- if (tempPoint.X + TrueSize.Width > Parent.TrueSize.Width)
- tempPoint.X = Parent.TrueSize.Width - TrueSize.Width;
- }
- if (tempPoint.X < 0)
- tempPoint.X = 0;
- if (tempPoint.Y < 0)
- tempPoint.Y = 0;
- Location = tempPoint;
- if (OnMoving != null)
- OnMoving.Invoke(this, e);
- return;
- }
- if (Controls != null)
- for (int i = Controls.Count - 1; i >= 0; i--)
- if (Controls[i].IsMouseOver(CMain.MPoint))
- {
- Controls[i].OnMouseMove(e);
- return;
- }
- Highlight();
- if (MouseMove != null)
- MouseMove.Invoke(this, e);
- }
-
- public virtual void OnMouseDown(MouseEventArgs e)
- {
- if (!_enabled)
- return;
- Activate();
- TrySort();
- if (_movable)
- {
- Moving = true;
- _movePoint = CMain.MPoint.Subtract(Location);
- }
- if (MouseDown != null)
- MouseDown.Invoke(this, e);
- }
- public virtual void OnMouseUp(MouseEventArgs e)
- {
- if (!_enabled)
- return;
- if (Moving)
- {
- Moving = false;
- _movePoint = Point.Empty;
- }
-
- if (ActiveControl != null) ActiveControl.Deactivate();
- if (MouseUp != null)
- MouseUp.Invoke(this, e);
- }
- public virtual void OnMouseWheel(MouseEventArgs e)
- {
- if (!Enabled)
- return;
- if (MouseWheel != null)
- MouseWheel(this, e);
- }
- public virtual void OnKeyPress(KeyPressEventArgs e)
- {
- if (!_enabled)
- return;
- if (Controls != null)
- for (int i = Controls.Count - 1; i >= 0; i--)
- if (e.Handled)
- return;
- else
- Controls[i].OnKeyPress(e);
- if (KeyPress == null)
- return;
- KeyPress.Invoke(this, e);
- }
- public virtual void OnKeyDown(KeyEventArgs e)
- {
- if (!_enabled)
- return;
- if (Controls != null)
- for (int i = Controls.Count - 1; i >= 0; i--)
- if (e.Handled)
- return;
- else
- Controls[i].OnKeyDown(e);
- if (KeyDown == null)
- return;
- KeyDown.Invoke(this, e);
- }
- public virtual void OnKeyUp(KeyEventArgs e)
- {
- if (!_enabled)
- return;
- if (Controls != null)
- for (int i = Controls.Count - 1; i >= 0; i--)
- if (e.Handled)
- return;
- else
- Controls[i].OnKeyUp(e);
- if (KeyUp == null)
- return;
- KeyUp.Invoke(this, e);
- }
- public virtual void Redraw()
- {
- if (Parent != null) Parent.Redraw();
- }
- #region Disposable
- public bool IsDisposed { get; private set; }
- public void Dispose()
- {
- if (IsDisposed)
- return;
- Dispose(true);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (Disposing != null)
- Disposing.Invoke(this, EventArgs.Empty);
- Disposing = null;
- BackColourChanged = null;
- _backColour = Color.Empty;
- BorderChanged = null;
- _border = false;
- BorderRectangle = Rectangle.Empty;
- _borderInfo = null;
- BorderColourChanged = null;
- _borderColour = Color.Empty;
- DrawControlTexture = false;
- if (ControlTexture != null && !ControlTexture.Disposed)
- ControlTexture.Dispose();
- ControlTexture = null;
- TextureValid = false;
- ControlAdded = null;
- ControlRemoved = null;
- if (Controls != null)
- {
- for (int i = Controls.Count - 1; i >= 0; i--)
- {
- if (Controls[i] != null && !Controls[i].IsDisposed)
- Controls[i].Dispose();
- }
- Controls = null;
- }
- _enabled = false;
- EnabledChanged = null;
- HasShown = false;
- BeforeDraw = null;
- AfterDraw = null;
- Shown = null;
- BeforeShown = null;
- Click = null;
- DoubleClick = null;
- MouseEnter = null;
- MouseLeave = null;
- MouseMove = null;
- MouseDown = null;
- MouseUp = null;
- MouseWheel = null;
- KeyPress = null;
- KeyUp = null;
- KeyDown = null;
- ForeColourChanged = null;
- _foreColour = Color.Empty;
- LocationChanged = null;
- _location = Point.Empty;
- ModalChanged = null;
- _modal = false;
- MovableChanged = null;
- _movePoint = Point.Empty;
- Moving = false;
- OnMoving = null;
- _movable = false;
- NotControlChanged = null;
- _notControl = false;
- OpacityChanged = null;
- _opacity = 0F;
- if (Parent != null && Parent.Controls != null)
- Parent.Controls.Remove(this);
- ParentChanged = null;
- _parent = null;
- SizeChanged = null;
- _size = Size.Empty;
- SoundChanged = null;
- _sound = 0;
- VisibleChanged = null;
- _visible = false;
- if (ActiveControl == this) ActiveControl = null;
- if (MouseControl == this) MouseControl = null;
- }
- IsDisposed = true;
- }
- #endregion
- }
- }
|