public ExitButton(Vec2 loc, Vec2 size, Image parent, Forms.Form parf) { if (size.X == 0 || size.Y == 0) { throw new Exception("No dimention of size can be zero!"); } this.X = loc.X; this.Y = loc.Y; this.Size = size; this.iSize = new Vec2(size.X - 1, size.Y - 1); this.parent = parent; this.parForm = parf; this.bounds = new BoundingBox(this.X, this.X + Size.X, this.Y + Size.Y, this.Y); Click = new ObjectClick(this.ExitButtonClicked); MouseEnter = new ObjectClick(this.ExitButtonEnter); MouseLeave = new ObjectClick(this.ExitButtonLeave); MouseDown = new ObjectClick(this.ExitButtonMouseDown); MouseUp = new ObjectClick(this.ExitButtonMouseUp); evnts = new ObjectEvents( new ObjectClick(Click), new ObjectClick(MouseEnter), new ObjectClick(MouseLeave), new ObjectClick(MouseDown), new ObjectClick(MouseUp), new DrawMethod(Draw), bounds); i = new Image(size); this.DrawDefault(); }
public ObjectEvents(ObjectClick onClick, ObjectClick onEnter, ObjectClick onLeave, ObjectClick onMouseDown, ObjectClick onMouseUp, DrawMethod drawMethod, BoundingBox b) { this.MouseClick = onClick; this.MouseEnter = onEnter; this.MouseLeave = onLeave; this.MouseDown = onMouseDown; this.MouseUp = onMouseUp; this.Draw = drawMethod; this.IsIn = false; this.IsMouseDown = false; this.Bounds = b; }
/// <summary> /// Draws the over WindowButton. /// </summary> /// <param name="bounds">The bounds of the window to draw.</param> /// <param name="w">The window to draw.</param> private void DrawOverButton(BoundingBox bounds, Window w) { Vec2 tl = new Vec2(bounds.Left, bounds.Bottom) - TaskbarLocation; Vec2 tr = new Vec2(bounds.Right, bounds.Bottom) - TaskbarLocation; Vec2 br = new Vec2(bounds.Right, bounds.Top) - TaskbarLocation; Vec2 bl = new Vec2(bounds.Left, bounds.Top) - TaskbarLocation; if (w.IsActiveWindow && w.CurrentState != WindowState.Minimized) { Buffer.DrawRectangle(tl, br, WindowActiveOverBackColor); Buffer.DrawLines(new Vec2[] { tl, tr, br, bl, tl }, WindowActiveLineColor); } else { Buffer.DrawRectangle(tl, br, WindowInactiveOverBackColor); Buffer.DrawLines(new Vec2[] { tl, tr, br, bl, tl }, WindowInactiveLineColor); } DrawWindowName(bounds, w); WasOverButton = true; }
/// <summary> /// Redraws the Buffer. /// </summary> private void RedrawBuffer() { WindowButtonBounds = new BoundingBox[Windows.Length]; Buffer.Clear(TaskbarClearColor); int loc = 20; if (Windows.Length * (WindowButtonWidth + (2 * WindowButtonMargin)) < Manager.Size.X - 20) { #region No Dynamic Size Vec2 tl; Vec2 tr; Vec2 br; Vec2 bl; Window w; for (uint ind = 0; ind < Windows.Length; ind++) { w = Windows[ind]; tl = new Vec2( loc + WindowButtonMargin, (TaskBarHeight - (TaskBarHeight - 2 - WindowButtonMargin)) ); tr = new Vec2( loc + WindowButtonMargin + WindowButtonWidth, (TaskBarHeight - (TaskBarHeight - 2 - WindowButtonMargin)) ); br = new Vec2( loc + WindowButtonMargin + WindowButtonWidth, (TaskBarHeight - 2 - WindowButtonMargin) ); bl = new Vec2( loc + WindowButtonMargin, (TaskBarHeight - 2 - WindowButtonMargin) ); WindowButtonBounds[ind] = new BoundingBox( loc + WindowButtonMargin, loc + WindowButtonMargin + WindowButtonWidth, Manager.Size.Y - (TaskBarHeight - (TaskBarHeight - 2 - WindowButtonMargin)), Manager.Size.Y - (TaskBarHeight - 2 - WindowButtonMargin) ); if (w.IsActiveWindow && w.CurrentState != WindowState.Minimized) { Buffer.DrawRectangle(tl, br, WindowActiveBackColor); Buffer.DrawLines(new Vec2[] { tl, tr, br, bl, tl }, WindowActiveLineColor); } else { Buffer.DrawRectangle(tl, br, WindowInactiveBackColor); Buffer.DrawLines(new Vec2[] { tl, tr, br, bl, tl }, WindowInactiveLineColor); } DrawWindowName(WindowButtonBounds[ind], w); loc += WindowButtonMargin + WindowButtonMargin + WindowButtonWidth; } #endregion } else { #region Dynamic Size uint len = (uint)Manager.Size.X - 20; int ButtonWidth = (int)Math.Floor((double)((len / Windows.Length) - 2)); if (ButtonWidth > 5) { Vec2 tl; Vec2 tr; Vec2 br; Vec2 bl; Window w; for (uint ind = 0; ind < Windows.Length; ind++) { w = Windows[ind]; tl = new Vec2( loc + WindowButtonMargin, (TaskBarHeight - (TaskBarHeight - 2 - WindowButtonMargin)) ); tr = new Vec2( loc + WindowButtonMargin + ButtonWidth, (TaskBarHeight - (TaskBarHeight - 2 - WindowButtonMargin)) ); br = new Vec2( loc + WindowButtonMargin + ButtonWidth, (TaskBarHeight - 2 - WindowButtonMargin) ); bl = new Vec2( loc + WindowButtonMargin, (TaskBarHeight - 2 - WindowButtonMargin) ); WindowButtonBounds[ind] = new BoundingBox( loc + WindowButtonMargin, loc + WindowButtonMargin + ButtonWidth, Manager.Size.Y - (TaskBarHeight - (TaskBarHeight - 2 - WindowButtonMargin)), Manager.Size.Y - (TaskBarHeight - 2 - WindowButtonMargin) ); if (w.IsActiveWindow && w.CurrentState != WindowState.Minimized) { Buffer.DrawRectangle(tl, br, WindowActiveBackColor); Buffer.DrawLines(new Vec2[] { tl, tr, br, bl, tl }, WindowActiveLineColor); } else { Buffer.DrawRectangle(tl, br, WindowInactiveBackColor); Buffer.DrawLines(new Vec2[] { tl, tr, br, bl, tl }, WindowInactiveLineColor); } DrawWindowName(WindowButtonBounds[ind], w); loc += WindowButtonMargin + WindowButtonMargin + ButtonWidth; } } else { Buffer.DrawRectangle(new Vec2(24, 4), new Vec2(Buffer.Width - 10, Buffer.Height - 4), Colors.Cyan); } #endregion } Modified = false; Drawn = true; }
/// <summary> /// Draws the window's name on the taskbar, /// using the specified bounds. /// </summary> /// <param name="bounds">Bounds to use.</param> /// <param name="w">Window to draw.</param> private void DrawWindowName(BoundingBox bounds, Window w) { BoundingBox bnds = bounds - TaskbarLocation; //throw new Exception(); //if (WindowManager.WindowFont.GetFontMetrics().StringWidth(w.Name) > bnds.Width - 6) //{ // // Doesn't fit on the button, need to remove some characters. // string s = w.Name.Substring(0, w.Name.Length - 3) + "..."; // while (WindowManager.WindowFont.GetFontMetrics().StringWidth(s) > bnds.Width - 6) // { // if (s.Length == 3) // { // s = "."; // button is to small to have a name drawn. // break; // } // else // { // // It's 4 to make up for the 3 extra characters we add. // s = s.Substring(0, s.Length - 4) + "..."; // } // } // //throw new Exception(); // Buffer.DrawString(new Vec2(bnds.Left + 2, bnds.Bottom + 2), s, WindowManager.WindowFont, 10, Orvid.Graphics.FontSupport.FontStyle.Normal, TaskbarTextColor); //} //else // Fits on button. //{ // Buffer.DrawString(new Vec2(bnds.Left + 2, bnds.Bottom + 2), w.Name, WindowManager.WindowFont, 10, Orvid.Graphics.FontSupport.FontStyle.Normal, TaskbarTextColor); //} }
/// <summary> /// The default constructor /// </summary> /// <param name="mangr">The parent window manager.</param> public Taskbar(WindowManager mangr) { this.Windows = new Window[0]; this.Manager = mangr; this.Bounds = new BoundingBox(0, mangr.Size.X, mangr.Size.Y, mangr.Size.Y - TaskBarHeight); this.Buffer = new Image(mangr.Size.X, WindowManager.TaskBarHeight + 1); this.Buffer.Clear(TaskbarClearColor); this.WindowButtonBounds = new BoundingBox[0]; this.TaskbarLocation = new Vec2(0, Manager.Size.Y - TaskBarHeight); }
/// <summary> /// Re-Computes all of the bounding boxes. /// </summary> private void ComputeBounds() { this.Bounds = new BoundingBox( iLocation.X, iLocation.X + iSize.X, iLocation.Y + iSize.Y, iLocation.Y ); this.HeaderBounds = new BoundingBox( iLocation.X, iLocation.X + iSize.X, iLocation.Y + HeaderHeight, iLocation.Y ); this.ContentBounds = new BoundingBox( iLocation.X + WindowBorderSize, iLocation.X + (iSize.X - WindowBorderSize - WindowBorderSize), iLocation.Y + (iSize.Y - HeaderHeight), iLocation.Y + HeaderHeight ); this.CloseButtonBounds = new BoundingBox( iLocation.X + (iSize.X - HeaderHeight + 2), iLocation.X + (iSize.X - WindowBorderSize - 2), iLocation.Y + (HeaderHeight - 2), iLocation.Y + (WindowBorderSize + 1) ); this.MaxButtonBounds = new BoundingBox( iLocation.X + (iSize.X - (HeaderHeight + HeaderHeight - 2)), iLocation.X + (iSize.X - (HeaderHeight + WindowBorderSize + 2)), iLocation.Y + (HeaderHeight - 2), iLocation.Y + (WindowBorderSize + 1) ); this.MinButtonBounds = new BoundingBox( iLocation.X + (iSize.X - (HeaderHeight + HeaderHeight + HeaderHeight - 2)), iLocation.X + (iSize.X - (HeaderHeight + HeaderHeight + WindowBorderSize + 2)), iLocation.Y + (HeaderHeight - 2), iLocation.Y + (WindowBorderSize + 1) ); }
/// <summary> /// Disposes of all of the resources used by this window. /// </summary> public void Dispose() { this.Bounds = null; this.CloseButtonBounds = null; this.ContentBounds = null; this.ContentBuffer = null; foreach (Control c in Controls) { c.DoBeforeDispose(); c.Dispose(); c.DoAfterDispose(); } this.Controls = null; this.HeaderBounds = null; this.HeaderBuffer = null; this.MaxButtonBounds = null; this.MinButtonBounds = null; this.Parent = null; this.WindowBuffer = null; this.Name = null; }
private static Image AddAdditiveNoise(Image i, BoundingBox b, int strength) { Random r = new Random(0); uint startY = (uint)b.Top; uint stopY = (uint)(startY + b.Height); uint startX = (uint)b.Left; uint stopX = (uint)(startX + b.Width); Pixel p; for (uint y = startY; y < stopY; y++) { for (uint x = startX; x < stopX; x++) { p = i.GetPixel(x, y); i.SetPixel(x, y, new Pixel((byte)Math.Max(0, Math.Min(255, p.R + (r.NextDouble() * strength - strength))), (byte)Math.Max(0, Math.Min(255, p.G + (r.NextDouble() * strength - strength))), (byte)Math.Max(0, Math.Min(255, p.B + (r.NextDouble() * strength - strength))), 255)); } } return i; }
public static Image AddNoise(Image i, BoundingBox bounds, int strength = 10, NoiseGenerationMethod method = NoiseGenerationMethod.Additive) { Image im = null; switch (method) { case NoiseGenerationMethod.Additive: im = AddAdditiveNoise(i, bounds, strength); break; //case NoiseGenerationMethod.SaltAndPepper: // im = AddSaltAndPepperNoise(i, bounds); // break; } return im; }