Пример #1
0
		protected override void OnMouseMove(MouseEventArgs e)
		{
			base.OnMouseMove(e);
			if (!Enabled) return;

			if (panMode)
			{
				Point ptDev = new Point(e.X, e.Y);
				int dx = ptDev.X - ptStartDragDev.X;
				int dy = ptDev.Y - ptStartDragDev.Y;

				Graphics gp = this.CreateGraphics();
				gp.ResetTransform();
				gp.PageUnit = measureUnit;
				gp.PageScale = zoomFactor / 100F;
				PointF diff = Utilities.deviceToDoc(gp, dx, dy);
				RectangleF rcPage = Utilities.deviceToDoc(gp, ClientRectangle);
				gp.Dispose();

				float sx = panPoint.X - diff.X;
				float sy = panPoint.Y - diff.Y;
				scrollStayInDoc(sx, sy, rcPage);
				return;
			}

			// get mouse position in document coordinates
			Graphics g = this.CreateGraphics();
			setTransforms(g);
			PointF ptCurr = Utilities.deviceToDoc(g, e.X, e.Y);

			if (interaction != null && interaction.CurrentObject != null &&
				Behavior != BehaviorType.DoNothing && this.Capture && buttonDown[0])
			{
				if (autoScroll) checkAutoScroll(e);

				// for easier selection check if distance the mouse moved is not too small
				if (Math.Abs(ptStartDragDev.X - e.X) > 2 || 
					Math.Abs(ptStartDragDev.Y - e.Y) > 2)
					mouseMoved = true;

				// set the mouse pointer
				if (mouseMoved)
					interaction.setCursor(ptCurr, this);

				// prepare for drawing
				Bitmap tempBuffer = createBackBuffer(ClientRectangle, g);
				Graphics tg = Graphics.FromImage(tempBuffer);
				tg.SmoothingMode = antiAlias;
				tg.TextRenderingHint = textRendering;

				// update the item position
				redrawNonModified = false;
				bool redrawBack = interaction.update(ptCurr, this);
				if (redrawBack || redrawNonModified)
				{
					drawFlowChart(docBuffer, ClientRectangle, true);
					redrawNonModified = false;
				}

				// update document size if needed
				if (autoSizeDoc != MindFusion.FlowChartX.AutoSize.None)
					sizeDocForItem(interaction.CurrentObject);

				// paint the invalid rect
				RectangleF rcInvDoc = interaction.InvalidRect;
				Rectangle rcInvDev = Utilities.docToDevice(g, rcInvDoc);
				rcInvDev.Inflate(2, 2);
				rcInvDev.Intersect(ClientRectangle);
				if (forceCacheRedraw)
				{
					rcInvDev = ClientRectangle;
					forceCacheRedraw = false;
				}
				tg.DrawImage(docBuffer, rcInvDev, rcInvDev, GraphicsUnit.Pixel);

				// redraw the items
				setTransforms(tg);
				if (!selectionOnTop)
				{
					// all items must be repainted in order to
					// preserve their Z order appearance
					drawAllItems(tg, rcInvDoc);

					// item being created
					if (interaction.Action == Action.Create && interaction.CurrentObject != null)
					{
						if (interaction.CurrentObject != selection)
						{
							if (shadowsStyle != ShadowsStyle.None)
								drawObjectWithShadow(tg, interaction.CurrentObject, false);
							else
								drawObject(tg, interaction.CurrentObject, false);
						}
						else
						{
							selection.Draw(tg, false);
						}
					}
				}
				else
				{
					// items that aren't being modified are already painted in the
					// back buffer; now repaint only the items being modified
					if (interaction.CurrentObject != selection)
					{
						if (shadowsStyle != ShadowsStyle.None)
							drawObjectWithShadow(tg, interaction.CurrentObject, interaction.Action == Action.Modify);
						else
							drawObject(tg, interaction.CurrentObject, interaction.Action == Action.Modify);
					}
					else
					{
						// draw selection
						PainterVisitor painter = new PainterVisitor(tg, false);
						selection.visitHierarchy(painter);
						selection.Draw(tg, false);
					}
				}

				if (interaction.Action == Action.Modify && showHandlesOnDrag)
					interaction.CurrentObject.drawSelHandles(tg, ActiveMnpColor);
				if ((showAnchors & ShowAnchors.Auto) != 0 && autoAnchorsObj != null)
					autoAnchorsObj.drawAnchors(tg);

				// blit offscreen to screen
				unsetTransforms(g);
				Rectangle clr = ClientRectangle;
				if (hScrollBar != null && hScrollBar.Visible)
					clr.Height -= hScrollBar.Height;
				if (vScrollBar != null && vScrollBar.Visible)
					clr.Width -= vScrollBar.Width;
				rcInvDev.Intersect(clr);
				g.DrawImage(tempBuffer, rcInvDev, rcInvDev, GraphicsUnit.Pixel);

				// clean up
				tg.Dispose();
				tempBuffer.Dispose();
			}
			else // not dragging
			{
				if ((showAnchors & ShowAnchors.Auto) != 0)
					drawAutoAnchors(g, ptCurr);
				if (modificationStart == ModificationStyle.AutoHandles)
					drawAutoHandles(g, ptCurr);
				currentBehavior.SetMouseCursor(ptCurr);
				setTooltipText(ptCurr);
			}

			// clean up
			g.Dispose();
		}
Пример #2
0
		private void drawHierarchy(Graphics g, ChartObject obj, bool shadows)
		{
			if (!sortGroupsByZ)
			{
				PainterVisitor painter = new PainterVisitor(g, shadows);
				obj.visitHierarchy(painter);
			}
			else
			{
				MethodCallVisitor visitor =
					new MethodCallVisitor(new VisitOperation(addToSortedList));
				obj.visitHierarchy(visitor);
				foreach (ChartObject item in sortedByZ.Keys)
					item.Draw(g, shadows);
				sortedByZ.Clear();
			}
		}