Don't use static custom node image

This commit is contained in:
Jaex 2017-10-30 11:20:03 +03:00
parent 255f9f99e2
commit 0c30cb832f
4 changed files with 37 additions and 45 deletions

View file

@ -85,8 +85,8 @@ public Color CurrentColor
internal List<DrawableObject> DrawableObjects { get; private set; }
internal bool IsClosing { get; private set; }
internal IContainer components = null;
internal int toolbarHeight;
internal Image CustomNodeImage = Resources.CircleNode;
internal int ToolbarHeight;
private InputManager InputManager => ShapeManager.InputManager;
@ -136,8 +136,6 @@ public RegionCaptureForm(RegionCaptureMode mode, RegionCaptureOptions options)
private void InitializeComponent()
{
components = new Container();
SuspendLayout();
AutoScaleDimensions = new SizeF(6F, 13F);
@ -328,7 +326,7 @@ private void AutomaticPan(Vector2 center)
if (IsEditorMode)
{
int x = (int)Math.Round(ScreenRectangle0Based.Width * center.X);
int y = (int)Math.Round(toolbarHeight + (ScreenRectangle0Based.Height - toolbarHeight) * center.Y);
int y = (int)Math.Round(ToolbarHeight + (ScreenRectangle0Based.Height - ToolbarHeight) * center.Y);
int newX = x - CanvasRectangle.Width / 2;
int newY = y - CanvasRectangle.Height / 2;
int deltaX = newX - CanvasRectangle.X;
@ -1362,42 +1360,29 @@ private Image GetOutputImage()
protected override void Dispose(bool disposing)
{
if (ShapeManager != null)
{
ShapeManager.Dispose();
}
if (bmpBackgroundImage != null)
{
bmpBackgroundImage.Dispose();
}
if (disposing && (components != null))
{
components.Dispose();
}
if (backgroundBrush != null) backgroundBrush.Dispose();
if (backgroundHighlightBrush != null) backgroundHighlightBrush.Dispose();
if (borderPen != null) borderPen.Dispose();
if (borderDotPen != null) borderDotPen.Dispose();
if (borderDotStaticPen != null) borderDotStaticPen.Dispose();
if (nodeBackgroundBrush != null) nodeBackgroundBrush.Dispose();
if (infoFont != null) infoFont.Dispose();
if (infoFontMedium != null) infoFontMedium.Dispose();
if (infoFontBig != null) infoFontBig.Dispose();
if (textBackgroundBrush != null) textBackgroundBrush.Dispose();
if (textOuterBorderPen != null) textOuterBorderPen.Dispose();
if (textInnerBorderPen != null) textInnerBorderPen.Dispose();
if (markerPen != null) markerPen.Dispose();
if (defaultCursor != null) defaultCursor.Dispose();
ShapeManager?.Dispose();
bmpBackgroundImage?.Dispose();
backgroundBrush?.Dispose();
backgroundHighlightBrush?.Dispose();
borderPen?.Dispose();
borderDotPen?.Dispose();
borderDotStaticPen?.Dispose();
nodeBackgroundBrush?.Dispose();
infoFont?.Dispose();
infoFontMedium?.Dispose();
infoFontBig?.Dispose();
textBackgroundBrush?.Dispose();
textOuterBorderPen?.Dispose();
textInnerBorderPen?.Dispose();
markerPen?.Dispose();
defaultCursor?.Dispose();
CustomNodeImage?.Dispose();
if (regionFillPath != null)
{
if (Result == RegionResult.Region)
{
if (LastRegionFillPath != null) LastRegionFillPath.Dispose();
LastRegionFillPath?.Dispose();
LastRegionFillPath = regionFillPath;
}
else
@ -1406,8 +1391,8 @@ protected override void Dispose(bool disposing)
}
}
if (regionDrawPath != null) regionDrawPath.Dispose();
if (Image != null) Image.Dispose();
regionDrawPath?.Dispose();
Image?.Dispose();
base.Dispose(disposing);
}

View file

@ -24,7 +24,6 @@
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using ShareX.ScreenCaptureLib.Properties;
using System.Drawing;
namespace ShareX.ScreenCaptureLib
@ -53,13 +52,20 @@ public Point Position
public NodeShape Shape { get; set; }
private static Image customNodeImage = Resources.CircleNode;
public Image CustomNodeImage { get; private set; }
public ResizeNode(int x = 0, int y = 0)
{
Shape = NodeShape.CustomNode;
Shape = NodeShape.Square;
Position = new Point(x, y);
Size = customNodeImage.Width;
Size = DefaultSize;
}
public void SetCustomNode(Image customNodeImage)
{
Shape = NodeShape.CustomNode;
CustomNodeImage = customNodeImage;
Size = CustomNodeImage.Width;
}
public override void Draw(Graphics g)
@ -80,8 +86,8 @@ public override void Draw(Graphics g)
g.DrawDiamond(Pens.White, rect.Offset(-1));
g.DrawDiamond(Pens.Black, rect);
break;
case NodeShape.CustomNode:
g.DrawImage(customNodeImage, Rectangle);
case NodeShape.CustomNode when CustomNodeImage != null:
g.DrawImage(CustomNodeImage, Rectangle);
break;
}
}

View file

@ -217,6 +217,7 @@ public ShapeManager(RegionCaptureForm form)
for (int i = 0; i < 9; i++)
{
ResizeNode node = new ResizeNode();
node.SetCustomNode(form.CustomNodeImage);
form.DrawableObjects.Add(node);
ResizeNodes.Add(node);
}

View file

@ -903,7 +903,7 @@ internal void CreateToolbar()
private void MenuForm_Shown(object sender, EventArgs e)
{
form.toolbarHeight = menuForm.Height;
form.ToolbarHeight = menuForm.Height;
form.CenterCanvas();
}