示例#1
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if ((action_status == ActionMode.Add || action_status == ActionMode.RangeQuery || action_status == ActionMode.WindowQuery) && is_draggin)
            {
                PointF prevPos = ConvertCoordFromScreen(mouse_down_pos.X, mouse_down_pos.Y);
                PointF curPos  = ConvertCoordFromScreen(current_mouse_pos.X, current_mouse_pos.Y);

                Point pPos = new Point((int)prevPos.X, (int)prevPos.Y);
                Point cPos = new Point((int)curPos.X, (int)curPos.Y);

                RectangleObj newRectangle = new RectangleObj();
                newRectangle.SetRectangleByCoords(pPos, cPos);

                if (action_status == ActionMode.RangeQuery)
                {
                    int rad = Math.Max(newRectangle.rect_height, newRectangle.rect_width);
                    newRectangle.UpdateWH(rad, rad);
                }

                newRectangle.rect_color       = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
                newRectangle.importance_layer = -1;

                OnRectangleAdded(newRectangle);

                is_draggin = false;
                RedrawCanvas();
            }
            else if (action_status == ActionMode.PointQuery || action_status == ActionMode.Remove || action_status == ActionMode.IncrementalNN)
            {
                PointF curPos = ConvertCoordFromScreen(e.Location.X, e.Location.Y);
                OnPointQueryRequested(new Point((int)curPos.X, (int)curPos.Y));
                if (action_status == ActionMode.IncrementalNN)
                {
                    incrementalSet = true;
                    incrementalPos = e.Location;
                }
                else
                {
                    incrementalSet = false;
                }
            }
            else if (action_status == ActionMode.Move)
            {
                is_draggin = false;
                OnPointQueryRequested(new Point(-1, -1));
                RedrawCanvas();
            }
        }
示例#2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (all_layer_bounds.Count < 1)
            {
                return;
            }

            foreach (LayerBounds bound in all_layer_bounds)
            {
                int   colval    = ((bound.layerNum) * 220) / num_layers;
                int   pen_width = Math.Max(1, 5 - bound.layerNum);
                Brush br        = new SolidBrush(Color.FromArgb(colval, colval, colval));
                Pen   pen       = new Pen(br, pen_width);

                PointF p1 = ConvertCoordToScreen(bound.bounds.X, bound.bounds.Y);
                PointF p2 = ConvertCoordToScreen(bound.bounds.Width, bound.bounds.Height);

                e.Graphics.DrawRectangle(pen, p1.X, p1.Y, p2.X, p2.Y);
            }

            if (is_draggin && action_status != ActionMode.Move)
            {
                Brush br = new SolidBrush(Color.Black);

                PointF prevPos = ConvertCoordFromScreen(mouse_down_pos.X, mouse_down_pos.Y);
                PointF curPos  = ConvertCoordFromScreen(current_mouse_pos.X, current_mouse_pos.Y);

                Point pPos = new Point((int)prevPos.X, (int)prevPos.Y);
                Point cPos = new Point((int)curPos.X, (int)curPos.Y);

                RectangleObj newRectangle = new RectangleObj();
                newRectangle.SetRectangleByCoords(pPos, cPos);
                if (action_status == ActionMode.RangeQuery)
                {
                    int rad = Math.Max(newRectangle.rect_width, newRectangle.rect_height);
                    newRectangle.UpdateWH(rad, rad);
                }

                prevPos = ConvertCoordToScreen(newRectangle.min_extent_X, newRectangle.min_extent_Y);
                curPos  = ConvertCoordToScreen(newRectangle.rect_width, newRectangle.rect_height);
                if (action_status == ActionMode.Add || action_status == ActionMode.WindowQuery)
                {
                    e.Graphics.DrawRectangle(new Pen(br), prevPos.X, prevPos.Y, curPos.X, curPos.Y);
                }
                else if (action_status == ActionMode.RangeQuery)
                {
                    e.Graphics.DrawEllipse(new Pen(br), prevPos.X, prevPos.Y, curPos.X, curPos.Y);
                }
            }
            if (rects_to_draw != null && rects_to_draw.Count > 0)
            {
                foreach (RectangleObj rect in rects_to_draw)
                {
                    Brush  br           = new SolidBrush(rect.rect_color);
                    PointF corner_coord = ConvertCoordToScreen(rect.min_extent_X, rect.min_extent_Y);
                    PointF wh_extent    = ConvertCoordToScreen(rect.rect_width, rect.rect_height);
                    e.Graphics.FillRectangle(br, corner_coord.X, corner_coord.Y, wh_extent.X, wh_extent.Y);
                }
            }
            if (hollow_rects_to_draw.Count > 0)
            {
                foreach (RectangleObj rect in hollow_rects_to_draw)
                {
                    Brush  br           = new SolidBrush(Color.Red);
                    PointF corner_coord = ConvertCoordToScreen(rect.min_extent_X, rect.min_extent_Y);
                    PointF wh_extent    = ConvertCoordToScreen(rect.rect_width, rect.rect_height);
                    Pen    pen          = new Pen(br, 3);
                    e.Graphics.DrawRectangle(pen, corner_coord.X, corner_coord.Y, wh_extent.X, wh_extent.Y);
                    pen.Dispose();
                }
            }
            if (incrementalSet)
            {
                Brush br = new SolidBrush(Color.Orange);
                e.Graphics.FillRectangle(br, incrementalPos.X, incrementalPos.Y, 5, 5);
            }
            if (hollow_circles.Count > 0)
            {
                foreach (RectangleObj rect in hollow_circles)
                {
                    PointF corner_coord = ConvertCoordToScreen(rect.min_extent_X, rect.min_extent_Y);
                    PointF wh_extent    = ConvertCoordToScreen(rect.rect_width, rect.rect_height);
                    Brush  br           = new SolidBrush(rect.rect_color);
                    Pen    pen          = new Pen(br, 2);
                    e.Graphics.DrawEllipse(pen, corner_coord.X, corner_coord.Y, wh_extent.X, wh_extent.Y);
                    pen.Dispose();
                }
            }
        }