Commit 538dd72a SK

ImageBox

1 个父辈 fe860d03
......@@ -21,7 +21,8 @@ namespace Cyotek.Windows.Forms
[DefaultProperty("Image")]
[ToolboxBitmap(typeof(ImageBox), "ImageBox.bmp")]
[ToolboxItem(true)]
/* [Designer("Cyotek.Windows.Forms.Design.ImageBoxDesigner", Cyotek.Windows.Forms.ImageBox.Design.dll, PublicKeyToken=58daa28b0b2de221")] */ public class ImageBox : VirtualScrollableControl
/* [Designer("Cyotek.Windows.Forms.Design.ImageBoxDesigner", Cyotek.Windows.Forms.ImageBox.Design.dll, PublicKeyToken=58daa28b0b2de221")] */
public class ImageBox : VirtualScrollableControl
{
#region Constants
......@@ -83,7 +84,7 @@ namespace Cyotek.Windows.Forms
private ImageBoxSelectionMode _selectionMode;
private RectangleF _selectionRegion;
private GraphicsPath _selectionRegion = new GraphicsPath();
private bool _shortcutsEnabled;
......@@ -892,8 +893,9 @@ namespace Cyotek.Windows.Forms
this.DrawPixelGrid(e.Graphics);
}
// draw the selection
if (this.SelectionRegion != Rectangle.Empty)
if (this.SelectionRegion.PointCount > 0)
{
this.DrawSelection(e);
}
......@@ -1526,7 +1528,7 @@ namespace Cyotek.Windows.Forms
/// </value>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual RectangleF SelectionRegion
public virtual GraphicsPath SelectionRegion
{
get { return _selectionRegion; }
set
......@@ -2378,20 +2380,26 @@ namespace Cyotek.Windows.Forms
result = null;
if (!this.SelectionRegion.IsEmpty)
var bounds = this.SelectionRegion.GetBounds();
if (this.SelectionRegion.PointCount > 0)
{
Rectangle rect;
rect = this.FitRectangle(new Rectangle((int)this.SelectionRegion.X, (int)this.SelectionRegion.Y, (int)this.SelectionRegion.Width, (int)this.SelectionRegion.Height));
if (rect.Width > 0 && rect.Height > 0)
if (bounds.Width > 0 && bounds.Height > 0)
{
result = new Bitmap(rect.Width, rect.Height);
Bitmap mask = new Bitmap(this.Image.Width, this.Image.Height);
using (Graphics g = Graphics.FromImage(mask))
{
var br = new TextureBrush(this.Image);
g.FillPath(br, this.SelectionRegion);
}
var dstRect = new RectangleF(0, 0, bounds.Width, bounds.Height);
var srcRect = new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(result))
{
g.DrawImage(this.Image, new Rectangle(Point.Empty, rect.Size), rect, GraphicsUnit.Pixel);
result = new Bitmap((int)bounds.Width, (int)bounds.Width);
g.DrawImage(mask, dstRect, srcRect, GraphicsUnit.Pixel);
}
return result;
}
}
......@@ -2629,20 +2637,11 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Creates a selection region which encompasses the entire image
/// </summary>
/// <exception cref="System.InvalidOperationException">Thrown if no image is currently set</exception>
public virtual void SelectAll()
{
this.SelectionRegion = new RectangleF(PointF.Empty, this.ViewSize);
}
/// <summary>
/// Clears any existing selection region
/// </summary>
public virtual void SelectNone()
{
this.SelectionRegion = RectangleF.Empty;
this.SelectionRegion = new GraphicsPath();
}
/// <summary>
......@@ -3160,20 +3159,36 @@ namespace Cyotek.Windows.Forms
/// </param>
protected virtual void DrawSelection(PaintEventArgs e)
{
RectangleF rect;
e.Graphics.SetClip(this.GetInsideViewPort(true));
rect = this.GetOffsetRectangle(this.SelectionRegion);
GraphicsPath newPath = new GraphicsPath(this.SelectionRegion.PathPoints, this.SelectionRegion.PathTypes);
Matrix matrix = new Matrix();
matrix.Scale((float)this.ZoomFactor, (float)this.ZoomFactor);
newPath.Transform(matrix);
var viewport = this.GetImageViewPort();
var offsetX = viewport.Left + this.Padding.Left + this.AutoScrollPosition.X;
var offsetY = viewport.Top + this.Padding.Top + this.AutoScrollPosition.Y;
matrix = new Matrix();
matrix.Translate(offsetX, offsetY);
newPath.Transform(matrix);
//rect = this.GetOffsetRectangle(this.SelectionRegion);
using (Brush brush = new SolidBrush(Color.FromArgb(128, this.SelectionColor)))
{
e.Graphics.FillRectangle(brush, rect);
e.Graphics.FillPath(brush, newPath);
}
using (Pen pen = new Pen(this.SelectionColor))
{
e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
//e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
e.Graphics.DrawPath(pen, newPath);
}
e.Graphics.ResetClip();
......@@ -3670,16 +3685,16 @@ namespace Cyotek.Windows.Forms
{
EventHandler<EventArgs> handler;
switch (this.SelectionMode)
{
case ImageBoxSelectionMode.Zoom:
if (this.SelectionRegion.Width > SelectionDeadZone && this.SelectionRegion.Height > SelectionDeadZone)
{
this.ZoomToRegion(this.SelectionRegion);
this.SelectNone();
}
break;
}
//switch (this.SelectionMode)
//{
// case ImageBoxSelectionMode.Zoom:
// if (this.SelectionRegion.Width > SelectionDeadZone && this.SelectionRegion.Height > SelectionDeadZone)
// {
// this.ZoomToRegion(this.SelectionRegion);
// this.SelectNone();
// }
// break;
//}
handler = this.Selected;
......@@ -4205,8 +4220,10 @@ namespace Cyotek.Windows.Forms
{
selection = this.FitRectangle(selection);
}
this.SelectionRegion = selection;
GraphicsPath path = new GraphicsPath();
Region re = new Region();
path.AddRectangle(selection);
this.SelectionRegion = path;
}
}
}
......
......@@ -27,6 +27,6 @@
/// <summary>
/// Zoom selection.
/// </summary>
Zoom
Eclipse,
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!