/// <summary> /// Sets the control bounds. /// </summary> /// <param name="x">X position.</param> /// <param name="y">Y position.</param> /// <param name="width">Width.</param> /// <param name="height">Height.</param> /// <returns> /// True if bounds changed. /// </returns> public virtual bool SetBounds(int x, int y, int width, int height) { width = Math.Max( MinimumSize.Width, Math.Min(MaximumSize.Width, width)); height = Math.Max( MinimumSize.Height, Math.Min(MaximumSize.Height, height)); if (m_Bounds.X == x && m_Bounds.Y == y && m_Bounds.Width == width && m_Bounds.Height == height) { return(false); } Rectangle oldBounds = Bounds; m_Bounds.X = x; m_Bounds.Y = y; m_Bounds.Width = width; m_Bounds.Height = height; OnBoundsChanged(oldBounds); if (BoundsChanged != null) { BoundsChanged.Invoke(this, EventArgs.Empty); } return(true); }
public void DrawBezier(Pen pen, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { int maxX = (int)Math.Max(Math.Max(Math.Max(Math.Max(x1 + pen.Width, x2 + pen.Width), x3 + pen.Width), x4 + pen.Width), Bitmap.Width); int maxY = (int)Math.Max(Math.Max(Math.Max(Math.Max(y1 + pen.Width, y2 + pen.Width), y3 + pen.Width), y4 + pen.Width), Bitmap.Height); if (maxX > Bitmap.Width || maxY > Bitmap.Height) { Bitmap newBitmap = new Bitmap(maxX, maxY); using (Graphics g = Graphics.FromImage(newBitmap)) { g.DrawImageUnscaled(Bitmap, new Point(0, 0)); g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.DrawBezier(pen, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); } Bitmap = newBitmap; BoundsChanged?.Invoke(this, EventArgs.Empty); } else { using (Graphics g = Graphics.FromImage(Bitmap)) { g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.DrawBezier(pen, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4); } } Changed = true; }
void IPlatformWindowBox.SetLocation(int x, int y) { //invoke Before accept new location PreviewBoundChanged?.Invoke(this, EventArgs.Empty); //------------------ _formLocalX = x; _formLocalY = y; //Console.WriteLine("set location " + x + "," + y); // if (this.UseRelativeLocationToParent) { if (!_evalLocationRelativeToDesktop) { _locationRelToDesktop = new System.Drawing.Point(); if (_form.LinkedParentControl != null) { //get location of this control relative to desktop _locationRelToDesktop = _form.LinkedParentControl.PointToScreen(System.Drawing.Point.Empty);//** } _evalLocationRelativeToDesktop = true; } _form.Location = new System.Drawing.Point( _locationRelToDesktop.X + x, _locationRelToDesktop.Y + y); } else { _form.Location = new System.Drawing.Point(x, y); } BoundsChanged?.Invoke(this, EventArgs.Empty); }
public void Clear() { Bitmap.Dispose(); Bitmap = new Bitmap(1, 1); using (Graphics g = Graphics.FromImage(Bitmap)) { g.Clear(Color.Transparent); } BoundsChanged?.Invoke(this, EventArgs.Empty); Changed = true; }
protected override void OnResize(EventArgs e) { base.OnResize(e); BoundsChanged.OnNext(DIPHelpers.DIP(Bounds)); if (loaded) { Text = "cw: " + ClientSize.Width + " ch: " + ClientSize.Height; } pictureBox.ClientSize = ClientSize; }
public Settings() { InitializeComponent(); this.radioButton1.CheckedChanged += (s, e) => ModeChaged?.Invoke(s, e); this.radioButton2.CheckedChanged += (s, e) => ModeChaged?.Invoke(s, e); this.radioButton3.CheckedChanged += (s, e) => ModeChaged?.Invoke(s, e); this.trackBar1.ValueChanged += (s, e) => BoundsChanged?.Invoke(s, e); this.trackBar2.ValueChanged += (s, e) => BoundsChanged?.Invoke(s, e); }
internal void UpdateFrom(Win32Window window) { Title = window.Title; bool boundsChanged = !window.Bounds.Equals(Bounds); Bounds = window.Bounds; if (boundsChanged) { BoundsChanged.Invoke(this, new EventArgs()); } }
public void FillRectangles(Pen pen, PreciseRectangle[] rects) { int maxWidth = Bitmap.Width; int maxHeight = Bitmap.Height; for (int i = 0; i < rects.Length; i++) { if (rects[i].X + rects[i].Width + pen.Width > maxWidth) { maxWidth = (int)(rects[i].X + rects[i].Width + pen.Width); } if (rects[i].Y + rects[i].Height + pen.Width > maxHeight) { maxHeight = (int)(rects[i].Y + rects[i].Height + pen.Width); } } if (maxWidth > Bitmap.Width || maxHeight > Bitmap.Height) { Bitmap newBitmap = new Bitmap(maxWidth, maxHeight); using (Graphics g = Graphics.FromImage(newBitmap)) { g.DrawImageUnscaled(Bitmap, new Point(0, 0)); g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.FillRectangles(pen.Brush, preciseRectangleArrayToRectangleFArray(rects)); } Bitmap = newBitmap; BoundsChanged?.Invoke(this, EventArgs.Empty); } else { using (Graphics g = Graphics.FromImage(Bitmap)) { g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.FillRectangles(pen.Brush, preciseRectangleArrayToRectangleFArray(rects)); } } Changed = true; }
public void DrawBeziers(Pen pen, PrecisePoint[] points) { int maxX = Bitmap.Width; int maxY = Bitmap.Height; for (int i = 0; i < points.Length; i++) { if (points[i].X + pen.Width > maxX) { maxX = (int)(points[i].X + pen.Width); } if (points[i].Y + pen.Width > maxY) { maxY = (int)(points[i].Y + pen.Width); } } if (maxX > Bitmap.Width || maxY > Bitmap.Height) { Bitmap newBitmap = new Bitmap(maxX, maxY); using (Graphics g = Graphics.FromImage(newBitmap)) { g.DrawImageUnscaled(Bitmap, new Point(0, 0)); g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.DrawBeziers(pen, precisePointArrayToPointFArray(points)); } Bitmap = newBitmap; BoundsChanged?.Invoke(this, EventArgs.Empty); } else { using (Graphics g = Graphics.FromImage(Bitmap)) { g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.DrawBeziers(pen, precisePointArrayToPointFArray(points)); } } Changed = true; }
public void FillClosedCurve(Pen pen, PrecisePoint[] points, FillMode fillMode, double tension) { int maxX = Bitmap.Width; int maxY = Bitmap.Height; for (int i = 0; i < points.Length; i++) { if ((points[i].X * tension) + pen.Width > maxX) { maxX = (int)((points[i].X * tension) + pen.Width); } if ((points[i].Y * tension) + pen.Width > maxY) { maxY = (int)((points[i].Y * tension) + pen.Width); } } if (maxX > Bitmap.Width || maxY > Bitmap.Height) { Bitmap newBitmap = new Bitmap(maxX, maxY); using (Graphics g = Graphics.FromImage(newBitmap)) { g.DrawImageUnscaled(Bitmap, new Point(0, 0)); g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.FillClosedCurve(pen.Brush, precisePointArrayToPointFArray(points), fillMode, (float)tension); } Bitmap = newBitmap; BoundsChanged?.Invoke(this, EventArgs.Empty); } else { using (Graphics g = Graphics.FromImage(Bitmap)) { g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.FillClosedCurve(pen.Brush, precisePointArrayToPointFArray(points), fillMode, (float)tension); } } Changed = true; }
public void FillRectangle(Pen pen, double x, double y, double width, double height) { if (x + width + pen.Width > Bitmap.Width || y + height + pen.Width > Bitmap.Height) { Bitmap newBitmap = new Bitmap((int)Math.Max(x + width + pen.Width, Bitmap.Width), (int)Math.Max(y + height + pen.Width, Bitmap.Height)); using (Graphics g = Graphics.FromImage(newBitmap)) { g.DrawImageUnscaled(Bitmap, new Point(0, 0)); g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.FillRectangle(pen.Brush, (float)x, (float)y, (float)width, (float)height); } Bitmap = newBitmap; BoundsChanged?.Invoke(this, EventArgs.Empty); } else { using (Graphics g = Graphics.FromImage(Bitmap)) { g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; g.FillRectangle(pen.Brush, (float)x, (float)y, (float)width, (float)height); } } Changed = true; }
public UIElement CreateVisual(VirtualCanvas parent) { if (Visual == null) { switch (_shape) { case TestShapeType.Curve: { PathGeometry g = new PathGeometry(); PathFigure f = new PathFigure { StartPoint = _points[0] }; g.Figures.Add(f); for (Int32 i = 0, n = _points.Length; i < n; i += 3) { BezierSegment s = new BezierSegment(_points[i], _points[i + 1], _points[i + 2], true); f.Segments.Add(s); } Path p = new Path { Data = g, Stroke = Stroke, StrokeThickness = 2 }; //DropShadowBitmapEffect effect = new DropShadowBitmapEffect(); //effect.Opacity = 0.8; //effect.ShadowDepth = 3; //effect.Direction = 270; //c.BitmapEffect = effect; Visual = p; break; } case TestShapeType.Ellipse: { Canvas c = new Canvas(); Ellipse e = new Ellipse(); c.Width = e.Width = _bounds.Width; c.Height = e.Height = _bounds.Height; c.Children.Add(e); Size s = MeasureText(parent, Label); Double x = (_bounds.Width - s.Width) / 2; Double y = (_bounds.Height - s.Height) / 2; TextBlock text = new TextBlock { Text = Label }; Canvas.SetLeft(text, x); Canvas.SetTop(text, y); c.Children.Add(text); e.StrokeThickness = 2; e.Stroke = Stroke; e.Fill = Fill; //DropShadowBitmapEffect effect = new DropShadowBitmapEffect(); //effect.Opacity = 0.8; //effect.ShadowDepth = 3; //effect.Direction = 270; //c.BitmapEffect = effect; Visual = c; break; } case TestShapeType.Rectangle: { Border b = new Border { CornerRadius = new CornerRadius(3), Width = _bounds.Width, Height = _bounds.Height }; TextBlock text = new TextBlock { Text = Label, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; // Testing for BoundsChanged event. b.MouseRightButtonDown += (s, e) => { _bounds = new Rect( Bounds.X + 10, Bounds.Y + 10, b.Width, b.Height); BoundsChanged?.Invoke(this, null); }; b.Child = text; b.Background = Fill; //DropShadowBitmapEffect effect = new DropShadowBitmapEffect(); //effect.Opacity = 0.8; //effect.ShadowDepth = 3; //effect.Direction = 270; //b.BitmapEffect = effect; Visual = b; break; } } } return(Visual); }
protected void OnBoundsChanged() { BoundsChanged?.Invoke(); }
public TestShape(Rect bounds, TestShapeType s, Random r) { _bounds = bounds; _shape = s; if (s == TestShapeType.Curve) { _bounds.Width *= 2; _bounds.Height *= 2; BoundsChanged?.Invoke(this, null); _points = new Point[3]; bounds = new Rect(0, 0, _bounds.Width, _bounds.Height); switch (r.Next(0, 8)) { case 0: _points[0] = bounds.TopLeft; _points[1] = bounds.TopRight; _points[2] = bounds.BottomRight; break; case 1: _points[0] = bounds.TopRight; _points[1] = bounds.BottomRight; _points[2] = bounds.BottomLeft; break; case 2: _points[0] = bounds.BottomRight; _points[1] = bounds.BottomLeft; _points[2] = bounds.TopLeft; break; case 3: _points[0] = bounds.BottomLeft; _points[1] = bounds.TopLeft; _points[2] = bounds.TopRight; break; case 4: _points[0] = bounds.TopLeft; _points[1] = new Point(bounds.Right, bounds.Height / 2); _points[2] = bounds.BottomLeft; break; case 5: _points[0] = bounds.TopRight; _points[1] = new Point(bounds.Left, bounds.Height / 2); _points[2] = bounds.BottomRight; break; case 6: _points[0] = bounds.TopLeft; _points[1] = new Point(bounds.Width / 2, bounds.Bottom); _points[2] = bounds.TopRight; break; case 7: _points[0] = bounds.BottomLeft; _points[1] = new Point(bounds.Width / 2, bounds.Top); _points[2] = bounds.BottomRight; break; } } }
protected void OnBoundsChanged(EventArgs e) { BoundsChanged?.Invoke(this, e); }
protected virtual void OnBoundsChanged() { BoundsChanged.SafeInvoke(this, EventArgs.Empty); }
internal void OnSettingChange() { Rectangle newWorkArea; Rectangle newBounds; double newScaling; int newRefreshRate; try { // Device name cannot change var(_, workArea, bounds, scaling, refreshRate) = m_manager.GetMonitorSettings(m_hMonitor); newWorkArea = workArea; newBounds = bounds; newScaling = scaling; newRefreshRate = refreshRate; } catch (InvalidDisplayReferenceException) { return; } if (newWorkArea != m_workArea) { Rectangle oldWorkArea; lock (m_syncRoot) { oldWorkArea = m_workArea; m_workArea = newWorkArea; } WorkAreaChanged?.Invoke(this, new DisplayRectangleChangedEventArgs(this, newWorkArea, oldWorkArea)); } if (newBounds != m_bounds) { Rectangle oldBounds; lock (m_syncRoot) { oldBounds = m_bounds; m_bounds = newBounds; } BoundsChanged?.Invoke(this, new DisplayRectangleChangedEventArgs(this, newBounds, oldBounds)); } if (newScaling != m_scaling) { double oldScaling; lock (m_syncRoot) { oldScaling = m_scaling; m_scaling = newScaling; } ScalingChanged?.Invoke(this, new DisplayScalingChangedEventArgs(this, newScaling, oldScaling)); } if (newRefreshRate != m_refreshRate) { int oldRefreshRate; lock (m_syncRoot) { oldRefreshRate = m_refreshRate; m_refreshRate = newRefreshRate; } RefreshRateChanged?.Invoke(this, new DisplayRefreshRateChangedEventArgs(this, newRefreshRate, oldRefreshRate)); } }
protected virtual void OnBoundsChanged() { BoundsChanged?.Invoke(this, EventArgs.Empty); OnPropertyChanged(nameof(Bounds)); }
protected override void OnLocationChanged(EventArgs e) { base.OnLocationChanged(e); BoundsChanged.OnNext(DIPHelpers.DIP(Bounds)); }
void IPlatformWindowBox.SetSize(int w, int h) { PreviewBoundChanged?.Invoke(this, EventArgs.Empty); _form.Size = new System.Drawing.Size(w, h); BoundsChanged?.Invoke(this, EventArgs.Empty); }
protected virtual void OnBoundsChanged() { BoundsChanged?.Invoke(this, new EventArgs <Rectangle>(this.previousBounds)); }
private void OnBoundsChanged() { BoundsChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Handles when th control has been resized /// </summary> /// <param name="bounds">The new bounds for the control</param> protected virtual void OnBoundsChanged(Rectangle bounds) { BoundsChanged?.Invoke(this, bounds); }
protected override void OnResize(EventArgs e) { base.OnResize(e); BoundsChanged.OnNext(Settings.DIP(Bounds)); pictureBox.ClientSize = ClientSize; }