using ComPDFKit.Tool.DrawTool;
using ComPDFKitViewer.Layer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows;
using ComPDFKit.PDFAnnotation;
using ComPDFKit.PDFPage;
using ComPDFKit.PDFDocument;
using ComPDFKitViewer.BaseObject;
using ComPDFKit.PDFAnnotation.Form;
using System.Windows.Media;
namespace ComPDFKit.Tool
{
public partial class CPDFViewerTool
{
///
///Identity whether to draw the custom tool
///
protected bool isDrawAnnot { get; set; }
public event EventHandler> DeleteChanged;
int customizeToolViewTag = -1;
private bool UnCheckCustomizeToolViewerModel()
{
if (currentModel == ToolType.Customize)
{
return false;
}
return true;
}
private void InsertCustomizeToolView()
{
CreateCustomizeTool createAnnotTool = new CreateCustomizeTool();
createAnnotTool.PDFViewer = PDFViewer;
int customizeToolViewindex = PDFViewer.GetMaxViewIndex();
createAnnotTool.DeleteChanged += CreateAnnotTool_DeleteChanged;
PDFViewer.InsertView(customizeToolViewindex, createAnnotTool);
customizeToolViewTag= createAnnotTool.GetResTag();
}
private void CreateAnnotTool_DeleteChanged(object sender, List e)
{
DeleteChanged?.Invoke(this, e);
}
///
/// Begin to draw the custom tool
///
public void DrawStartCustomizeTool(CustomizeToolType ToolType)
{
if (UnCheckCustomizeToolViewerModel())
{
return;
}
Point point = Mouse.GetPosition(this);
BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
PDFViewer.GetPointPageInfo(point, out int index, out Rect paintRect, out Rect pageBound);
if (index < 0)
{
return;
}
CPDFDocument cPDFDocument = PDFViewer.GetDocument();
CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
BaseLayer layer = PDFViewer.GetViewForTag(PDFViewer.GetAnnotViewTag());
if (ToolType == CustomizeToolType.kErase)
{
(baseLayer as CreateCustomizeTool).SetAnnotLayer(layer as AnnotLayer);
}
(baseLayer as CreateCustomizeTool).StartDraw(point, cPDFPage, paintRect, pageBound, ToolType);
}
///
/// Custom tool move call
///
public void DrawMoveCustomizeTool()
{
if (UnCheckCustomizeToolViewerModel())
{
return;
}
Point point = Mouse.GetPosition(this);
BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
(baseLayer as CreateCustomizeTool).MoveDraw(point, PDFViewer.GetZoom());
}
///
/// Custom tool end call
///
public void DrawEndCustomizeTool()
{
if (UnCheckCustomizeToolViewerModel())
{
return;
}
Point point = Mouse.GetPosition(this);
BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
(baseLayer as CreateCustomizeTool).EndDraw();
return;
}
///
/// Clear the custom tool
///
public void CleanCustomizeTool()
{
BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
(baseLayer as CreateCustomizeTool).ClearDraw();
}
///
/// Set the thickness of the custom tool
///
public void SetEraseZoom(double eraseZoom)
{
BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
(baseLayer as CreateCustomizeTool)?.SetEraseZoom(eraseZoom);
}
///
/// Clear the custom tool
///
public void SetDefEraseThickness(double defEraseThickness)
{
BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
(baseLayer as CreateCustomizeTool)?.SetDefEraseThickness(defEraseThickness);
}
///
/// Clear the custom tool
///
public void SetEraseBrush(SolidColorBrush drawBrush)
{
if(PDFViewer!=null)
{
BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
(baseLayer as CreateCustomizeTool)?.SetEraseBrush(drawBrush);
}
}
}
}