当前位置: 首页>>代码示例>>C#>>正文


C# PointD.Distance方法代码示例

本文整理汇总了C#中Cairo.PointD.Distance方法的典型用法代码示例。如果您正苦于以下问题:C# PointD.Distance方法的具体用法?C# PointD.Distance怎么用?C# PointD.Distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cairo.PointD的用法示例。


在下文中一共展示了PointD.Distance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleMouseDown

        public virtual void HandleMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            //If we are already drawing, ignore any additional mouse down events.
			if (is_drawing)
			{
				return;
			}

			//Redraw the previously (and possibly currently) active shape without any control points in case another shape is made active.
			DrawActiveShape(false, false, false, false, false);
			
            Document doc = PintaCore.Workspace.ActiveDocument;

            shape_origin = new PointD(Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1), Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1));
            current_point = shape_origin;

            bool shiftKey = (args.Event.State & Gdk.ModifierType.ShiftMask) == Gdk.ModifierType.ShiftMask;

            if (shiftKey)
            {
                CalculateModifiedCurrentPoint();
            }

            is_drawing = true;


            //Right clicking changes tension.
            if (args.Event.Button == 1)
            {
                changing_tension = false;
            }
            else
            {
                changing_tension = true;
            }


			bool ctrlKey = (args.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask;


			int closestCPIndex, closestCPShapeIndex;
			ControlPoint closestControlPoint;
			double closestCPDistance;

			SEngines.FindClosestControlPoint(current_point,
				out closestCPShapeIndex, out closestCPIndex, out closestControlPoint, out closestCPDistance);

            int closestShapeIndex, closestPointIndex;
            PointD closestPoint;
            double closestDistance;

            OrganizedPointCollection.FindClosestPoint(SEngines, current_point,
                out closestShapeIndex, out closestPointIndex, out closestPoint, out closestDistance);

            bool clickedOnControlPoint = false;

			double currentClickRange = ShapeClickStartingRange + BrushWidth * ShapeClickThicknessFactor;

			//Determine if the closest ControlPoint is within the expected click range.
			if (closestControlPoint != null && closestCPDistance < currentClickRange)
			{
				//User clicked directly on a ControlPoint on a shape.

				clicked_without_modifying = true;

				SelectedPointIndex = closestCPIndex;
				SelectedShapeIndex = closestCPShapeIndex;

				clickedOnControlPoint = true;
			}
			else if (closestDistance < currentClickRange) //Determine if the user clicked close enough to a shape.
			{
				//User clicked on a generated point on a shape.

				List<ControlPoint> controlPoints = SEngines[closestShapeIndex].ControlPoints;

				//Note: compare the currentPoint's distance here because it's the actual mouse position.
				if (controlPoints.Count > closestPointIndex && current_point.Distance(controlPoints[closestPointIndex].Position) < currentClickRange)
				{
					//User clicked on a control point (on the "previous order" side of the point).

					clicked_without_modifying = true;

					SelectedPointIndex = closestPointIndex;
					SelectedShapeIndex = closestShapeIndex;

					clickedOnControlPoint = true;
				}
				else if (closestPointIndex > 0)
				{
					if (current_point.Distance(controlPoints[closestPointIndex - 1].Position) < currentClickRange)
					{
						//User clicked on a control point (on the "following order" side of the point).

						clicked_without_modifying = true;

						SelectedPointIndex = closestPointIndex - 1;
						SelectedShapeIndex = closestShapeIndex;

						clickedOnControlPoint = true;
//.........这里部分代码省略.........
开发者ID:msiyer,项目名称:Pinta,代码行数:101,代码来源:BaseEditEngine.cs

示例2: eraseSmooth

        protected unsafe void eraseSmooth(ImageSurface surf, Context g, PointD start, PointD end)
        {
            int rad = (int)(BrushWidth / 2.0) + 1;
            //Premultiply with alpha value
            byte bk_col_a = (byte)(PintaCore.Palette.SecondaryColor.A * 255.0);
            byte bk_col_r = (byte)(PintaCore.Palette.SecondaryColor.R * bk_col_a);
            byte bk_col_g = (byte)(PintaCore.Palette.SecondaryColor.G * bk_col_a);
            byte bk_col_b = (byte)(PintaCore.Palette.SecondaryColor.B * bk_col_a);
            int num_steps = (int)start.Distance(end) / rad + 1; 
            //Initialize lookup table when first used (to prevent slower startup of the application)
            initLookupTable ();

            for (int step = 0; step < num_steps; step++) {
                PointD pt = Utility.Lerp(start, end, (float)step / num_steps);
                int x = (int)pt.X, y = (int)pt.Y;

                Gdk.Rectangle surface_rect = new Gdk.Rectangle (0, 0, surf.Width, surf.Height);
                Gdk.Rectangle brush_rect = new Gdk.Rectangle (x - rad, y - rad, 2 * rad, 2 * rad);
                Gdk.Rectangle dest_rect = Gdk.Rectangle.Intersect (surface_rect, brush_rect);

                if ((dest_rect.Width > 0) && (dest_rect.Height > 0)) {
                    //Allow Clipping through a temporary surface
                    using (ImageSurface tmp_surface = copySurfacePart (surf, dest_rect)) {

                        for (int iy = dest_rect.Top; iy < dest_rect.Bottom; iy++) {
                            ColorBgra* srcRowPtr = tmp_surface.GetRowAddressUnchecked (iy - dest_rect.Top);
                            int dy = ((iy - y) * LUT_Resolution) / rad;
                            if (dy < 0)
                                dy = -dy;      
                            byte[] lut_factor_row = lut_factor [dy];

                            for (int ix = dest_rect.Left; ix < dest_rect.Right; ix++) {
                                ColorBgra col = *srcRowPtr;
                                int dx = ((ix - x) * LUT_Resolution) / rad;
                                if (dx < 0)
                                    dx = -dx;

                                int force = lut_factor_row [dx]; 
                                //Note: premultiplied alpha is used!
                                if (mouse_button == 3) {
                                    col.A = (byte)((col.A * force + bk_col_a * (255 - force)) / 255);         
                                    col.R = (byte)((col.R * force + bk_col_r * (255 - force)) / 255);
                                    col.G = (byte)((col.G * force + bk_col_g * (255 - force)) / 255);
                                    col.B = (byte)((col.B * force + bk_col_b * (255 - force)) / 255);
                                } else {
                                    col.A = (byte)(col.A * force / 255);
                                    col.R = (byte)(col.R * force / 255);
                                    col.G = (byte)(col.G * force / 255);
                                    col.B = (byte)(col.B * force / 255);
                                }
                                *srcRowPtr = col;
                                srcRowPtr++;
                            }
                        }
                        //Draw the final result on the surface
                        pasteSurfacePart (g, tmp_surface, dest_rect);
                    }
                }
            }
        }
开发者ID:msiyer,项目名称:Pinta,代码行数:60,代码来源:EraserTool.cs


注:本文中的Cairo.PointD.Distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。