You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/KevServer/WebDrawToolSelect.cs

143 lines
4.6 KiB
C#

using GeoSigmaDrawLib;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using UCDraw;
namespace KevServer
{
public class WebDrawToolSelect : WebDrawTool
{
private Point pointStart = new Point(0, 0);
private Point pointPrev = new Point(0, 0);
private Point pointCur = new Point(0, 0);
public Point CacheImgLocation { get; set; } = new Point(0, 0);
public WebDrawToolSelect() : base()
{
ToolCursor = CursorType.Select;
ItemType = DrawItemType.ITEM_SELECT;
}
public WebDrawToolSelect(GeoSigmaXY geo)
: this()
{
this.Geo = geo;
}
public override void Start()
{
base.Start();
}
public Bitmap OnLButtonDown(MouseEventArgs e, Keys key = Keys.None)
{
Bitmap bmpBack = null;
bool bMoving = Geo.SelectIsOnMoving();
Geo.OnLButtonDown(e.X, e.Y, IntPtr.Zero);
bMoving = Geo.SelectIsOnMoving();
pointStart = e.Location;
pointPrev = new Point(e.X, e.Y);
// 移动轮廓图
if (Geo.SelectIsOnMoving())
{
int kind = Geo.Select_GetKindOfSelectedElement();
if ((DrawElementType)kind == DrawElementType.ELEMENT_MESH
&& Geo.SelectGetCount() == 1)
{
return bmpBack;
}
try
{
int nLeft = 0, nTop = 0, nRight = 0, nBottom = 0;
Geo.SelectGetTrackerRect(ref nLeft, ref nTop, ref nRight, ref nBottom);
bmpBack = new Bitmap(nRight - nLeft + 1, nBottom - nTop + 1,
PixelFormat.Format16bppRgb555);
Graphics gBack = Graphics.FromImage(bmpBack);
gBack.Clear(Color.White);
IntPtr pBmpDC = gBack.GetHdc();
Geo.SelectDrawTrackPath(pBmpDC);
gBack.ReleaseHdc();
CacheImgLocation = new Point(nLeft, nTop);
// bmpBack.Save("C:\\temp\\bmpSelect.bmp", ImageFormat.Bmp);
//bmpBack.MakeTransparent(Color.White);
}
catch (Exception ex)
{
Trace.WriteLine("图形放的太大了!\r\n" + ex.Message);
}
}
else
{
return bmpBack;
}
return bmpBack;
}
public bool OnLButtonUp(MouseEventArgs e, Keys key = Keys.None)
{
//Bitmap bmp = (Bitmap)drawArea.Bmp.Clone();
if (Geo == null)
{
return false;
}
Geo.OnLButtonUp(e.X, e.Y, IntPtr.Zero, key);
//if (drawArea.PaintingImage != null)
//{
// drawArea.Bmp = (Bitmap)drawArea.PaintingImage.Clone();
// drawArea.PaintingImage = null;
//}
// 判断选中数量和是否移动状态
if (Geo.SelectStatusChanged() == false && Geo.SelectGetCount() == 0)
{
return false;
}
return true;
}
/// <summary>
/// Moves the elements to.
/// </summary>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
/// <returns>A bool.</returns>
public bool MoveElementsTo(int x, int y)
{
if (Geo == null)
{
return false;
}
this.Geo.SelectMoveElementsTo(x, y);
return true;
}
public int OnMouseMove(MouseEventArgs e)
{
//Trace.WriteLine($"{e.X}, {e.Y}");
if (e.X == pointPrev.X && e.Y == pointPrev.Y)
{
return -2;
}
// Trace.WriteLine($"{DateTime.Now}:{e.X},{e.Y}--{pointPrev.X},{pointPrev.Y}");
//if (cursorType == -1)
//{
// drawArea.Cursor = ToolCursor;
//}
int handleType = -2;
handleType = Geo.SelectSetCursor(e.X, e.Y);
//bool shiftPressed = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;
//if (shiftPressed == true && handleType == 5)
//{
// handleType = -1;
//}
pointPrev.X = e.X;
pointPrev.Y = e.Y;
return handleType;
}
public void SelectAll()
{
Geo.Select_SelectAll();
}
}
}