The function is called when the user clicks the mouse button.
The function checks if the user is using the line, polygon, freeform, rectangle, ellipse, delete, or text tool.
If the user is using the line tool, the function creates a new ROI object and adds it to the image's annotations.
If the user is using the polygon tool, the function creates a new ROI object and adds it to the image's annotations.
If the user is using the freeform tool, the function creates a new ROI object and adds it to the image's annotations.
If the user is using the rectangle tool, the function creates a new ROI object and adds it to the image's annotations.
If the user is using the ellipse tool, the function creates a new ROI object and adds it to the image's annotations.
260 {
262 return;
265 PointD roiPoint = GetAnnotationPoint(e);
267 {
268 if (anno.type != ROI.Type.Line)
269 {
270 anno = new ROI();
271 anno.type = ROI.Type.Line;
272 anno.AddPoint(roiPoint);
273 anno.AddPoint(roiPoint);
276 RefreshRoiManager();
277 }
278 }
279 else
280 if (
currentTool.
type == Tool.Type.polygon && buts == MouseButtons.Left)
281 {
282 if (anno.type != ROI.Type.Polygon)
283 {
284 anno = new ROI();
285 anno.type = ROI.Type.Polygon;
286 anno.closed = false;
287 anno.AddPoint(roiPoint);
290 RefreshRoiManager();
291 }
292 else
293 {
294
296 PointD firstPoint = anno.Points[0];
297 double dx = roiPoint.X - firstPoint.X;
298 double dy = roiPoint.Y - firstPoint.Y;
299 if ((dx * dx) + (dy * dy) <= (hitSize * hitSize))
300 {
301 anno.closed = true;
302 anno.UpdateBoundingBox();
303 RefreshRoiManager();
304 anno = new ROI();
305 }
306 else
307 {
308 anno.AddPoint(roiPoint);
309 RefreshRoiManager();
310 }
311 }
312 }
313 else
314 if (
currentTool.
type == Tool.Type.freeform && buts == MouseButtons.Left)
315 {
316 if (anno.type != ROI.Type.Freeform)
317 {
318 anno = new ROI();
319 anno.type = ROI.Type.Freeform;
320 anno.closed = false;
321 anno.AddPoint(roiPoint);
324 RefreshRoiManager();
325 }
326 else
327 {
328 anno.AddPoint(roiPoint);
329 RefreshRoiManager();
330 }
331 }
332 else
334 {
335 anno = new ROI();
336 anno.type = ROI.Type.Rectangle;
337 rectStart = roiPoint;
338 anno.BoundingBox =
new RectangleD(roiPoint.X, roiPoint.Y, 0, 0);
339 anno.Validate();
342 currentTool.Rectangle = anno.BoundingBox;
343 }
344 else
345 if (
currentTool.
type == Tool.Type.ellipse && buts == MouseButtons.Left)
346 {
347 anno = new ROI();
348 anno.type = ROI.Type.Ellipse;
349 rectStart = roiPoint;
350 anno.BoundingBox =
new RectangleD(roiPoint.X, roiPoint.Y, 0, 0);
351 anno.Validate();
354 currentTool.Rectangle = anno.BoundingBox;
355 }
356 else
358 {
360 {
362 if (an.BoundingBox.IntersectsWith(
new RectangleD(roiPoint.X, roiPoint.Y, 1, 1)))
363 {
364 if (an.selectedPoints.Count == 0)
365 {
367 RefreshRoiManager();
368 break;
369 }
370 else
371 if (an.selectedPoints.Count == 1 && !(an.type == ROI.Type.Polygon || an.type == ROI.Type.Polyline || an.type == ROI.Type.Freeform))
372 {
374 RefreshRoiManager();
375 break;
376 }
377 else
378 {
379 if (an.type == ROI.Type.Polygon ||
380 an.type == ROI.Type.Polyline ||
381 an.type == ROI.Type.Freeform)
382 {
383 an.closed = false;
384 an.RemovePoints(an.selectedPoints.ToArray());
385 break;
386 }
387 }
388 }
389 }
391 }
392 else
394 {
395 ROI an = new ROI();
396 an.type = ROI.Type.Label;
397 an.AddPoint(roiPoint);
400 if (ti.ShowDialog() != DialogResult.OK)
401 return;
402 Font labelFont = ti.font ?? SystemFonts.DefaultFont;
403 string labelText = ti.TextValue ?? string.Empty;
404 System.Drawing.Size labelSize = TextRenderer.MeasureText(labelText, labelFont);
406 an.family = labelFont.FontFamily.Name;
407 an.fontSize = labelFont.Size;
409 an.Text = labelText;
410 an.BoundingBox =
new RectangleD(roiPoint.X, roiPoint.Y, labelBox.Width, labelBox.Height);
412 RefreshRoiManager();
413 }
414
415 if (buts == MouseButtons.Middle)
416 {
419 panPanel.BackColor = System.Drawing.Color.LightGray;
420 }
421
422
424 }
AForge.RectangleD RectangleD
ImageView control for image stacks, pyramidal and whole-slide-images.
static BioImage SelectedImage
double GetSelectionBoxHitSize()
static State GetDown(PointD pf, MouseButtons mb)
static void UpdateState(State s)