private int getDistance(int floor, Point fromLoc, Direction direction) { var toLoc = fromLoc.Add(direction.DirectionAsPoint()); return PlayingField.CanMoveHere(ref floor, fromLoc, toLoc, true) ? Distance[floor, toLoc.Y, toLoc.X] : int.MaxValue; }
public void Realign() { for (; Fraction > 1; Fraction -= 1) Location = NextLocation; for (; Fraction < 0; Fraction += 1) Location = Location.Add(Direction.Opposite.DirectionAsPoint()); }
public void AddsVector() { var point = new Point(0, 0); var vector = new Vector(1, 2); var newPoint = point.Add(vector); Assert.Equal(1, newPoint.X); Assert.Equal(2, newPoint.Y); }
static void Main(string[] args) { Point pt1 = new Point(1, 1); Point pt2 = new Point(2, 2); Point pt3; pt3 = pt1.Add(pt2); Console.WriteLine("pt3: {0}:{1}", pt3.x, pt3.y); }
public void Explore(int floor, Point fromLoc, int distance, Direction direction) { var toLoc = fromLoc.Add(direction.DirectionAsPoint()); if (!PlayingField.CanMoveHere(ref floor, fromLoc, toLoc, true)) return; var here = Distance[floor, toLoc.Y, toLoc.X]; if (here != 0 && here < distance) return; // already know shorter path Distance[floor, toLoc.Y, toLoc.X] = distance; foreach (var newDirection in Direction.AllDirections) Explore(floor, toLoc, distance + 1, newDirection); }
protected List <Point> MatchShapeOnBoard(int[,] board, FixedShape shape, Point location) { var shapePoints = shape.Points; int width = board.GetLength(0); int height = board.GetLength(1); var boardPositions = shapePoints.Select(p => location.Add(p)).ToList(); var fittingPositions = new List <Point>(); foreach (var position in boardPositions) { if (position.X < 0 || position.X >= width || position.Y < 0 || position.Y >= height) { continue; } if (board[position.X, position.Y] == EmptyField) { fittingPositions.Add(position); } } return(fittingPositions); }
public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext) { IList <IPathCommand> commands = Commands; if (layout.IsFlipped) { commands = new List <IPathCommand>(Commands.Count); foreach (IPathCommand command in Commands) { commands.Add(command.Flip(layout.Orientation == Orientation.Horizontal)); } } Point start = Start.Resolve(layout, layoutContext.Options); if (layoutContext.Options.Absolute) { drawingContext.DrawPath(Point.Add(start, layout.Location), commands, Thickness, Fill); } else { drawingContext.DrawPath(start, commands, Thickness, Fill); } }
/**<summary>Draws the object data in the dialog.</summary>*/ public override bool DrawDialog(PaletteImage p, Point position, Size dialogSize, DrawSettings drawSettings) { try { bool flat = Header.Flags.HasFlag(WallFlags.Flat); bool twoSides = Header.Flags.HasFlag(WallFlags.TwoSides); bool door = Header.Flags.HasFlag(WallFlags.Door); bool glass = Header.Flags.HasFlag(WallFlags.Glass); int offset = (2 + (!flat ? 4 : 0)) * (twoSides ? 2 : 1) * (door ? 2 : 1); DrawDialogFrame(p, Point.Add(position, new Size(dialogSize.Width / 2, dialogSize.Height / 2)), drawSettings, 0, false); if (door) { DrawDialogFrame(p, Point.Add(position, new Size(dialogSize.Width / 2, dialogSize.Height / 2)), drawSettings, 1, false); } if (glass) { DrawDialogFrame(p, Point.Add(position, new Size(dialogSize.Width / 2, dialogSize.Height / 2)), drawSettings, offset, true); } } catch (IndexOutOfRangeException) { return(false); } catch (ArgumentOutOfRangeException) { return(false); } return(true); }
internal IEnumerable <Guideline> GetSizeGuidableLines() { Point relative = AdornedElement.TranslatePoint(new Point(), Storyboard); // left yield return(new Guideline( relative, new Point(relative.X, relative.Y + AdornedElement.RenderSize.Height)) { Direction = GuidelineDirection.Left }); // right yield return(new Guideline( new Point(relative.X + AdornedElement.RenderSize.Width, relative.Y), Point.Add(relative, (Vector)AdornedElement.RenderSize)) { Direction = GuidelineDirection.Right }); // top yield return(new Guideline( relative, new Point(relative.X + AdornedElement.RenderSize.Width, relative.Y)) { Direction = GuidelineDirection.Top }); // bottom yield return(new Guideline( new Point(relative.X, relative.Y + AdornedElement.RenderSize.Height), Point.Add(relative, (Vector)AdornedElement.RenderSize)) { Direction = GuidelineDirection.Bottom }); }
/** <summary> Draws the object data in the dialog. </summary> */ public override bool DrawDialog(PaletteImage p, Point position, Size dialogSize, DrawSettings drawSettings) { try { position = Point.Add(position, new Size(dialogSize.Width / 2, dialogSize.Height / 2)); WaterSprites[2].DrawWithOffset(p, Point.Add(position, new Size(0, 0)), drawSettings.Darkness, false); WaterSprites[3].DrawWithOffset(p, Point.Add(position, new Size(2, 0)), drawSettings.Darkness, false); WaterSprites[4].DrawWithOffset(p, Point.Add(position, new Size(-2, 0)), drawSettings.Darkness, false); WaterSprites[3].DrawWithOffset(p, Point.Add(position, new Size(-30, 16)), drawSettings.Darkness, false); WaterSprites[4].DrawWithOffset(p, Point.Add(position, new Size(30, 16)), drawSettings.Darkness, false); WaterSprites[0].DrawWithOffset(p, Point.Add(position, new Size(0, -15)), drawSettings.Darkness, true); WaterSprites[1].DrawWithOffset(p, Point.Add(position, new Size(0, -15)), drawSettings.Darkness, false); /*g.DrawImage(PreviewImage, position.X - 32 + 112 / 2, position.Y - 16 + 112 / 2); * for (int i = 0; i < 5; i++) * Water.WaterPalette.Colors[230 + i] = graphicsData.Palettes[1].Colors[(i * 3) % 15]; * for (int i = 0; i < 5; i++) * Water.WaterPalette.Colors[235 + i] = graphicsData.Palettes[4].Colors[(i * 3) % 15]; * Water.WaterSparkle.Draw(g, position.X + 11 - 32 + 112 / 2, position.Y + 2 - 16 + 112 / 2, Water.WaterPalette, -1, -1, -1);*/ } catch (IndexOutOfRangeException) { return(false); } catch (ArgumentOutOfRangeException) { return(false); } return(true); }
private void ShowItemInfo(object sender, MouseEventArgs e) { var showwhat = ((PictureBox)sender) == pictureBox1 ? pictureBox1 : pictureBox2; var temp = ((PictureBox)sender) == pictureBox1 ? Items : resoult; Point p = new Point(((int)Math.Floor((double)e.X / 40 * (radioButton4.Checked ? 1 : 2))), ((int)Math.Floor((double)e.Y / 40 * (radioButton4.Checked ? 1 : 2)))); var item = temp.Where(x => PrivateFunction.IsWithin(p, x.point, Point.Add(x.point, new Size(x.w - 1, x.h - 1)))).FirstOrDefault(); // toolTip1.SetToolTip(showwhat, String.Format("{0},{1}", e.X, e.Y)); if (item != null) { if (System.Threading.Thread.CurrentThread.CurrentUICulture.Name == "en") { toolTip1.SetToolTip(showwhat, String.Format("Name:{0}\nItem level:{1}\nQuality:{2}\nRarity:{3}\nLevel:{4}", item.Name_eng, item.itemlevel, item.quality, item.Rarity, item.level)); } else { toolTip1.SetToolTip(showwhat, String.Format("物品名稱:{0}\n物品等級:{1}\n品質:{2}\n稀有度:{3}\n等級:{4}", item.Name, item.itemlevel, item.quality, item.Rarity, item.level)); } } else { toolTip1.SetToolTip(showwhat, ""); } }
public void Move(Size size) { this.startPoint = Point.Add(this.startPoint, size); this.endPoint = Point.Add(this.endPoint, size); }
/** * RenderScene */ public void RenderScene(Canvas canvas, int width, int section, int nsections) { Vector view = camera.GetViewDir(); Vector up = camera.GetOrthoUp(); Vector plane = new Vector(); Vector horIncr = new Vector(); Vector vertIncr = new Vector(); double ylen = camera.GetFocalDist() * (double)Math.Tan(0.5f * camera.GetFOV()); double xlen = ylen * canvas.GetWidth() / canvas.GetHeight(); Point upleft = new Point(); Point upright = new Point(); Point lowleft = new Point(); Point basepoint = new Point(); Point current; Ray eyeRay = new Ray(); int ypixel, xpixel; RayID = 1; plane.Cross(view, up); view.Scale(camera.GetFocalDist()); up.Scale(ylen); plane.Scale(-xlen); upleft.FindCorner(view, up, plane, camera.GetPosition()); plane.Negate(); upright.FindCorner(view, up, plane, camera.GetPosition()); up.Negate(); plane.Negate(); lowleft.FindCorner(view, up, plane, camera.GetPosition()); horIncr.Sub(upright, upleft); horIncr.Scale(horIncr.Length() / ((double)canvas.GetWidth())); vertIncr.Sub(lowleft, upleft); vertIncr.Scale(vertIncr.Length() / ((double)canvas.GetHeight())); basepoint.Set(upleft.GetX() + 0.5f * (horIncr.GetX() + vertIncr.GetX()), upleft.GetY() + 0.5f * (horIncr.GetY() + vertIncr.GetY()), upleft.GetZ() + 0.5f * (horIncr.GetZ() + vertIncr.GetZ())); eyeRay.SetOrigin(camera.GetPosition()); int xstart = section * width / nsections; int xend = xstart + width / nsections; Console.WriteLine("+" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight()); for(ypixel = 0; ypixel < canvas.GetHeight(); ypixel++) { current = new Point(basepoint); for(xpixel = 0; xpixel < canvas.GetWidth(); xpixel++) { if(xpixel >= xstart && xpixel < xend) { Color color = new Color(0.0f, 0.0f, 0.0f); eyeRay.GetDirection().Sub(current, eyeRay.GetOrigin()); eyeRay.GetDirection().Normalize(); eyeRay.SetID(RayID); this.RayID = this.RayID + 1; Shade(octree, eyeRay, color, 1.0f, 0, 0); canvas.Write(Brightness, xpixel, ypixel, color); } current.Add(horIncr); } basepoint.Add(vertIncr); } Console.WriteLine("-" + xstart + " to " + (xend - 1) + " by " + canvas.GetHeight()); }
// Keep sub-forms aligned private void MainForm_Move(object sender, EventArgs e) { _recordForm.Location = Point.Add(this.Location, new Size(0, this.Height)); }
/** <summary> Draws the object data in the dialog. </summary> */ public override bool DrawDialog(PaletteImage p, Point position, Size dialogSize, DrawSettings drawSettings) { try { position = Point.Add(position, new Size(dialogSize.Width / 2, dialogSize.Height / 2)); int xoffset = ((drawSettings.Rotation == 1 || drawSettings.Rotation == 2) ? -32 : 32); int yoffset = ((drawSettings.Rotation == 2 || drawSettings.Rotation == 3) ? -16 : 16); if (drawSettings.Rotation >= 2) { xoffset *= -1; yoffset *= -1; } int sideFrame = (drawSettings.Rotation < 2 ? 0 : 1); graphicsData.paletteImages[drawSettings.Rotation * 3 + 1 + sideFrame].DrawWithOffset(p, Point.Add(position, new Size(-xoffset, -yoffset)), drawSettings.Darkness, false); graphicsData.paletteImages[drawSettings.Rotation * 3 + 0].DrawWithOffset(p, position, drawSettings.Darkness, false); graphicsData.paletteImages[drawSettings.Rotation * 3 + 2 - sideFrame].DrawWithOffset(p, Point.Add(position, new Size(xoffset, yoffset)), drawSettings.Darkness, false); } catch (IndexOutOfRangeException) { return(false); } catch (ArgumentOutOfRangeException) { return(false); } return(true); }
public virtual void RenderWire(Wire wire, IDrawingContext drawingContext) { var size = wire.Layout.Orientation == Orientation.Horizontal ? new Point(wire.Layout.Size, 0.0) : new Point(0.0, wire.Layout.Size); drawingContext.DrawLine(wire.Layout.Location, Point.Add(wire.Layout.Location, size), 2.0); }
protected override void OnRender(DrawingContext dc) { _accentBrush.Color = AccentColor; { var or = GetRightHexOrigin(); var ol = GetLeftHexOrigin(); var distance = 0.8 * OnePerSqr3 * ActualHeight; var dv = DistanceVectors(distance); var contentHex = new StreamGeometry(); using (var gc = contentHex.Open()) { gc.BeginFigure(Point.Add(or, dv[0]), true, true); gc.PolyLineTo(new PointCollection() { Point.Add(or, dv[1]), Point.Add(ol, dv[2]), Point.Add(ol, dv[3]), Point.Add(ol, dv[4]), Point.Add(or, dv[5]), } , true, true); } dc.DrawGeometry(Brushes.White, new Pen(_accentBrush, 3), contentHex); var halfHex = new StreamGeometry(); var offset = new Vector(OnePerSqr3 * ActualHeight - distance, 0); using (var gc = halfHex.Open()) { gc.BeginFigure(Point.Add(or, dv[0]), true, true); gc.PolyLineTo(new PointCollection() { Point.Add(or, dv[1]), Point.Subtract(Point.Add(or, dv[1]), offset), Point.Subtract(Point.Add(or, dv[0]), offset), Point.Subtract(Point.Add(or, dv[5]), offset), Point.Add(or, dv[5]) }, false, true); } dc.DrawGeometry(_accentBrush, _hairlinePen, halfHex); } { var bigHex = new StreamGeometry(); using (var gc = bigHex.Open()) { var hp = DistanceVectors(OnePerSqr3 * ActualHeight); var o = GetLeftHexOrigin(); gc.BeginFigure(Point.Add(o, hp[0]), true, true); gc.PolyLineTo(new PointCollection() { Point.Add(o, hp[1]), Point.Add(o, hp[2]), Point.Add(o, hp[3]), Point.Add(o, hp[4]), Point.Add(o, hp[5]), }, false, true); } dc.DrawGeometry(_accentBrush, _hairlinePen, bigHex); } { var innerHex = new StreamGeometry(); using (var gc = innerHex.Open()) { var hp = DistanceVectors(InnerHexRadius * OnePerSqr3 * ActualHeight); var o = GetLeftHexOrigin(); gc.BeginFigure(Point.Add(o, hp[0]), true, true); gc.PolyLineTo(new PointCollection() { Point.Add(o, hp[1]), Point.Add(o, hp[2]), Point.Add(o, hp[3]), Point.Add(o, hp[4]), Point.Add(o, hp[5]), }, false, true); } dc.DrawGeometry(Brushes.White, _hairlinePen, innerHex); } { _glyphBrush.Color = GlyphColor; var ft = new FormattedText(Glyph.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, FontAwesome, ActualHeight / 2, _glyphBrush); dc.DrawText(ft, Point.Subtract(GetLeftHexOrigin(), new Vector(ft.Width / 2, ft.Height / 2))); } { var tf = new Typeface(new FontFamily("Sergoe UI"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal); var ft = new FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, tf, TextScale * ActualHeight / 3, _accentBrush); var cr = GetContentRect(); var offset = new Vector((cr.Width - ft.Width) / 2, (cr.Height - ft.Height) / 2); dc.DrawText(ft, Point.Add(cr.TopLeft, offset)); } }
/// <summary> /// Renders the document using the specified renderer. /// </summary> /// <param name="dc">The renderer to use.</param> public void Render(IRenderContext dc) { // Render components foreach (Component component in Components) { foreach (var renderDescription in component.Description.RenderDescriptions) { if (renderDescription.Conditions.IsMet(component)) { foreach (CircuitDiagram.Components.Description.Render.IRenderCommand renderCommand in renderDescription.Value) { renderCommand.Render(component, dc, true); } } } } // Determine connections List <ConnectionCentre> connectionCentres = new List <ConnectionCentre>(); List <Point> connectionPoints = new List <Point>(); foreach (Component component in Components) { foreach (var connection in component.GetConnections()) { if (connection.Value.IsConnected && !connectionCentres.Contains(connection.Value.Centre)) { bool draw = false; if (connection.Value.ConnectedTo.Length >= 3) { draw = true; } foreach (Connection connectedConnection in connection.Value.ConnectedTo) { if ((connectedConnection.Flags & ConnectionFlags.Horizontal) == ConnectionFlags.Horizontal && (connection.Value.Flags & ConnectionFlags.Vertical) == ConnectionFlags.Vertical && (connection.Value.Flags & ConnectionFlags.Edge) != (connectedConnection.Flags & ConnectionFlags.Edge)) { draw = true; } else if ((connectedConnection.Flags & ConnectionFlags.Vertical) == ConnectionFlags.Vertical && (connection.Value.Flags & ConnectionFlags.Horizontal) == ConnectionFlags.Horizontal && (connection.Value.Flags & ConnectionFlags.Edge) != (connectedConnection.Flags & ConnectionFlags.Edge)) { draw = true; } if (draw) { break; } } if (draw) { connectionCentres.Add(connection.Value.Centre); connectionPoints.Add(Point.Add(connection.Key, component.Location)); } } } } // Render connections foreach (Point connectionPoint in connectionPoints) { dc.DrawEllipse(connectionPoint, 2d, 2d, 2d, true); } }
/// <summary> /// OnRender /// </summary> /// <param name="dc">dc</param> public override void OnRender(DrawingContext dc) { dc.DrawEllipse(this.GetBrush(this.BackColor), this.GetPen(this.ForeColor), Point.Add(this.Location, new Vector() { X = this.Parent.Location.X, Y = this.Parent.Location.Y }), this.Radius, this.Radius); }
/// <summary> /// Finds the neighbor directions in relation to x,y. /// </summary> /// <returns> /// The neighbor directions. /// </returns> /// <param name='x'> /// X. /// </param> /// <param name='y'> /// Y. /// </param> /// <param name='index'> /// Index. /// </param> public Facing[] FindTileNeighborDirections(Point p, int index) { List<Facing> answer = new List<Facing> (); List<Point> neighbors = GetNeighboringPoints (p.X, p.Y); Facing f; foreach (Point n in neighbors) if (_tiles [n.X, n.Y].Index == index) { if(n == p.Add(Assets.FacingDirection(Facing.North))) answer.Add (Facing.North); else if(n == p.Add(Assets.FacingDirection(Facing.South))) answer.Add (Facing.South); else if(n == p.Add(Assets.FacingDirection(Facing.East))) answer.Add (Facing.East); else if(n == p.Add (Assets.FacingDirection(Facing.West))) answer.Add (Facing.West); } return answer.ToArray();; }
/// <summary> /// Pointクラスのテスト /// <para>NMEAファイルから測位点情報を読み出し、KMLへPoint情報として出力します。</para> /// </summary> public static void ReadNmeaToKmlPoint() { NmeaReader reader = new NmeaReader(); reader.OpenWithDialog(); // NMEAファイル読み出し if (reader.IsOpen) { Blh[] pos = reader.GetPositions(); // 測位情報のうちから位置座標のみを取得 DateTime[] times = reader.GetDateTimes(); // 測位情報から時刻情報のみを取得 if (pos.Length != 0 && times.Length != 0) { Point point = new Point(pos[0], Icon.shaded_dot); point.description = reader.FileName; point.AddDescription("0"); point.AddDescription(pos[0].ToString()); point.AddDescription(times[0].ToString()); point.Time = new KML.Time.TimeStamp(times[0]); if (pos.Length >= 1 && times.Length >= 1) { for (int i = 1; i < pos.Length && i < times.Length; i++) { if (!(pos[i].B == 0.0 && pos[i].L == 0.0)) // 未測位分は除く…最初の奴は例外(対処しようとすると結構長くなる) { Point p = new Point(pos[i]); p.description = i.ToString(); p.AddDescription(pos[i].ToString()); p.AddDescription(times[i].ToString()); p.Time = new KML.Time.TimeStamp(times[i]); point.Add(p); } } } // ファイル出力 // KML出力はUTF8で出力してください。 using (System.IO.StreamWriter fwriter = new System.IO.StreamWriter("NMEAtoPoint.kml", false, Encoding.UTF8)) { try { fwriter.Write(point.GetKmlCode()); } catch { // エラー処理があれば記述 } } } } return; }
/** * Intersect * * @param ray * @param intersect * @param Threshold * @return OctNode */ public OctNode Intersect(Ray ray, Point intersect, double Threshold) { Vector delta = new Vector(0.0f, 0.0f, 0.0f); double current = 0.0f; double t; int[] facehits = new int[3]; facehits[0] = -1; facehits[1] = -1; facehits[2] = -1; OctNode adjacent = null; Face[] OFaces = this.OctFaces; Face MAXXF = OFaces[MAXX]; Face MAXYF = OFaces[MAXY]; Face MAXZF = OFaces[MAXZ]; Face MINXF = OFaces[MINX]; Face MINYF = OFaces[MINY]; Face MINZF = OFaces[MINZ]; if(ray.GetDirection().GetX() != 0.0) { t = -(ray.GetOrigin().GetX() - OctFaces[MAXX].GetVert(0).GetX()) / ray.GetDirection().GetX(); if(t > Threshold && t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits[0] = MAXX; delta.SetX(Threshold); } } t = -(ray.GetOrigin().GetX() - OctFaces[MINX].GetVert(0).GetX()) / ray.GetDirection().GetX(); if(t > Threshold && t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits[0] = MINX; delta.SetX(-Threshold); } } } if(ray.GetDirection().GetY() != 0.0) { t = -(ray.GetOrigin().GetY() - OctFaces[MAXY].GetVert(0).GetY()) / ray.GetDirection().GetY(); if(t > Threshold) { if(t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits[0] = MAXY; delta.Set(0.0f, Threshold, 0.0f); } } else if(t == current) { facehits[1] = MAXY; delta.SetY(Threshold); } } t = -(ray.GetOrigin().GetY() - OctFaces[MINY].GetVert(0).GetY()) / ray.GetDirection().GetY(); if(t > Threshold) { if(t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetZ() <= MAXZF.GetVert(0).GetZ()) && (intersect.GetZ() >= MINZF.GetVert(0).GetZ())) { current = t; facehits[0] = MINY; delta.Set(0.0f, -Threshold, 0.0f); } } else if(t == current) { facehits[1] = MINY; delta.SetY(-Threshold); } } } if(ray.GetDirection().GetZ() != 0.0) { t = -(ray.GetOrigin().GetZ() - OctFaces[MAXZ].GetVert(0).GetZ()) / ray.GetDirection().GetZ(); if(t > Threshold) { if(t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY())) { current = t; facehits[0] = MAXZ; delta.Set(0.0f, 0.0f, Threshold); } } else if(t == current) { if(facehits[1] < 0) { facehits[1] = MAXZ; } else { facehits[2] = MAXZ; } delta.SetZ(Threshold); } } t = -(ray.GetOrigin().GetZ() - OctFaces[MINZ].GetVert(0).GetZ()) / ray.GetDirection().GetZ(); if(t > Threshold) { if(t > current) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, t); if((intersect.GetX() <= MAXXF.GetVert(0).GetX()) && (intersect.GetX() >= MINXF.GetVert(0).GetX()) && (intersect.GetY() <= MAXYF.GetVert(0).GetY()) && (intersect.GetY() >= MINYF.GetVert(0).GetY())) { current = t; facehits[0] = MINZ; delta.Set(0.0f, 0.0f, -Threshold); } } else if(t == current) { if(facehits[1] < 0) { facehits[1] = MINZ; } else { facehits[2] = MINZ; } delta.SetZ(-Threshold); } } } if(facehits[0] >= MAXX) { intersect.Combine(ray.GetOrigin(), ray.GetDirection(), 1.0f, current); intersect.Add(delta); adjacent = Adjacent[facehits[0]]; if(facehits[1] >= MAXX) { if(adjacent != null) { adjacent = adjacent.GetAdjacent(facehits[1]); if(facehits[2] >= MAXX) { if(adjacent != null) { adjacent = adjacent.GetAdjacent(facehits[2]); } else { adjacent = null; } } } else { adjacent = null; } } } return (adjacent); }
public void ReadAndShiftElementsAndConnections(XmlReader reader, Vector elementsShiftVector) { List <Element> ReadElements = new List <Element>(); List <ConnectionModel> ReadConnectionModels = new List <ConnectionModel>(); try { reader.MoveToContent(); reader.Read(); if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "SimulationProperties") { if (reader.Read() && reader.Name == "ReferenceImpedance") { ReferenceImpedance = double.Parse(reader.ReadString()); OnPropertyChanged(nameof(ReferenceImpedance)); } else { throw new Exception("ReferenceImpedance is missing or it is in the wrong place"); } if (reader.Read() && reader.Name == "FromFreq") { FromFreq = double.Parse(reader.ReadString()); OnPropertyChanged(nameof(FromFreq)); } else { throw new Exception("FromFreq is missing or it is in the wrong place"); } if (reader.Read() && reader.Name == "ToFreq") { ToFreq = double.Parse(reader.ReadString()); OnPropertyChanged(nameof(ToFreq)); } else { throw new Exception("ToFreq is missing or it is in the wrong place"); } if (reader.Read() && reader.Name == "Step") { Step = double.Parse(reader.ReadString()); OnPropertyChanged(nameof(Step)); } else { throw new Exception("Step is missing or it is in the wrong place"); } } } do { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Element": Element readElement = ReadElement(reader); readElement.Position = Point.Add(readElement.Position, elementsShiftVector); ReadElements.Add(readElement); break; case "Connection": ReadConnectionModels.Add(ReadConnectionModel(reader, ReadElements)); break; } } } while (reader.Read()); } catch (Exception e) { Console.WriteLine(e); return; } //changing ID's that every Element, connector and connection have unique foreach (Element readElement in ReadElements) { readElement.ID = Guid.NewGuid(); foreach (ConnectorModel connectorModel in readElement.Connectors) { connectorModel.ID = Guid.NewGuid(); } } foreach (ConnectionModel readConnectionModel in ReadConnectionModels) { readConnectionModel.ID = Guid.NewGuid(); } PasteCommand newPasteCommand = new PasteCommand(ReadElements, ReadConnectionModels, this); MyCommandManager.AddToList(newPasteCommand); newPasteCommand.Execute(); RenumberPorts(Elements); }
/** <summary> Sets if the specified quadrant is solid. </summary> */ public void SetQuadrantSolid(Point point, bool solid) { if (point.X < 0 || point.X >= this.blocks.GetLength(0) * 2 || point.Y < 0 || point.Y >= this.blocks.GetLength(1) * 2) { return; } MazeBlock block = this.blocks[point.X / 2, point.Y / 2]; if (point.Y % 2 == 0) { if (point.X % 2 == 0) { if (solid) { block.Walls |= MazeWalls.QuadrantNorthWest; } else { block.Walls &= ~MazeWalls.QuadrantNorthWest; } } else { if (solid) { block.Walls |= MazeWalls.QuadrantNorthEast; } else { block.Walls &= ~MazeWalls.QuadrantNorthEast; } } } else { if (point.X % 2 == 0) { if (solid) { block.Walls |= MazeWalls.QuadrantSouthWest; } else { block.Walls &= ~MazeWalls.QuadrantSouthWest; } } else { if (solid) { block.Walls |= MazeWalls.QuadrantSouthEast; } else { block.Walls &= ~MazeWalls.QuadrantSouthEast; } } } if (solid) { SetWallXSolid(point, true); SetWallXSolid(Point.Add(point, new Size(0, -1)), true); SetWallYSolid(point, true); SetWallYSolid(Point.Add(point, new Size(-1, 0)), true); } }
/// <summary> /// Initializes a new instance of the <see cref="Vector2"/> class. /// </summary> /// <param name="start">The starting point.</param> /// <param name="lengthX">The length by X-coordinate.</param> /// <param name="lengthY">The length by Y-coordinate.</param> public Vector2(Point start, double lengthX, double lengthY) { this.Start = start; this.End = start.Add(lengthX, lengthY); }
/**<summary>Draws the path scaffold supports.</summary>*/ public void DrawScaffoldSupport(PaletteImage p, Point position, DrawSettings drawSettings, int rotation) { int offset = 109; if (drawSettings.Slope == -1) { graphicsData.paletteImages[offset + (rotation % 2 == 0 ? 46 : 22)].DrawWithOffset(p, Point.Add(position, new Size(12, 32 - 6)), drawSettings.Darkness, false); } else { int offset2 = 0; switch (drawSettings.Slope) { case 0: offset2 = 5; break; case 1: offset2 = 11; break; case 2: offset2 = 8; break; case 3: offset2 = 2; break; } graphicsData.paletteImages[offset + (drawSettings.Slope % 2 == 0 ? 24 : 0) + offset2].DrawWithOffset(p, Point.Add(position, new Size(12, 32 - 6)), drawSettings.Darkness, false); graphicsData.paletteImages[offset + (drawSettings.Slope % 2 == 0 ? 47 : 23)].DrawWithOffset(p, Point.Add(position, new Size(12, 16 - 6)), drawSettings.Darkness, false); offset = 164; graphicsData.paletteImages[offset + (drawSettings.Slope + 3) % 4].DrawWithOffset(p, Point.Add(position, new Size(12, -6)), drawSettings.Darkness, false); } }
public static Line ToOriginCenteredLine(Point origin, Vector axis) { return(Line.ByStartPointEndPoint(origin.Add(axis.Scale(-axisScaleFactor)), origin.Add(axis.Scale(axisScaleFactor)))); }
protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); Graphics g = CreateGraphics(); g.Clear(BackColor); int start_x = 0; int start_y = 0; float scale = 1; if (bmap != null) { scale = Math.Min((float)Width / bmap.Width, (float)Height / bmap.Height); start_x = (Width - (int)(bmap.Width * scale)) / 2; start_y = (Height - (int)(bmap.Height * scale)) / 2; g.DrawImage(bmap, start_x, start_y, bmap.Width * scale, bmap.Height * scale); computed_bmp_start_x = start_x; computed_bmp_start_y = start_y; } computed_bmp_start_x = start_x; computed_bmp_start_y = start_y; computed_scale = scale; if (highlight_map != null) { Brush b = new SolidBrush(highlight_color); int size = (int)Math.Ceiling(computed_scale); for (int i = 0; i < highlight_map.GetLength(0); i++) { for (int j = 0; j < highlight_map.GetLength(1); j++) { if (highlight_map[i, j]) { Rectangle dest = new Rectangle((int)(computed_bmp_start_x + j * computed_scale), (int)(computed_bmp_start_y + i * computed_scale), size, size); g.FillRectangle(b, dest); } } } } int real_start_x = start_x - (int)(computed_start_pixel.x * scale); int real_start_y = start_y - (int)(computed_start_pixel.y * scale); void drawRectangle(Rectangle r, Color c, bool fill = true) { float x = r.X; float y = r.Y; float w = r.Width; float h = r.Height; if (fill) { g.FillRectangle(new SolidBrush(c), real_start_x + x * scale, real_start_y + y * scale, w * scale, h * scale); } else { g.DrawRectangle(new Pen(c, 1), real_start_x + x * scale, real_start_y + y * scale, (w - 1) * scale, (h - 1) * scale); } } void drawCircle(int cx, int cy, int r, Color c, bool fill = true) { float x = cx - r; float y = cy - r; float w = 2 * r - 1; float h = 2 * r - 1; if (fill) { g.FillEllipse(new SolidBrush(c), real_start_x + x * scale, real_start_y + y * scale, w * scale, h * scale); } else { g.DrawEllipse(new Pen(c, 1), real_start_x + x * scale, real_start_y + y * scale, w * scale, h * scale); } } if (showO && m != null && (helirin == null || !helirin.Value.hasBonus)) { Rectangle?bonus = m.GetBonusPxRect(); if (bonus.HasValue) { drawRectangle(bonus.Value, Color.MediumPurple); } if (helirin != null && Settings.enable_moving_objects) { foreach (Piston p in m.Pistons) { drawRectangle(p.PreciseBoxAtTime(helirin.Value.frameNumber), Color.FromArgb(0xFF, 0x77, 0x22, 0x77), false); } foreach (Roller r in m.Rollers) { Roller.Ball b = r.PreciseBoxAtTime(helirin.Value.frameNumber); if (b != null) { drawCircle(b.cx, b.cy, b.r, Color.FromArgb(0xFF, 0x77, 0x77, 0x22), false); } } } } if (helirin != null) { GraphicalHelirin h = helirin.Value; Pen myPen = new Pen(Color.Black, 1); int offset_x = h.pixelX - Map.helirin_radius; int offset_y = h.pixelY - Map.helirin_radius; int size = Map.helirin_radius * 2; g.DrawEllipse(myPen, real_start_x + offset_x * scale, real_start_y + offset_y * scale, size * scale, size * scale); offset_x = h.pixelX - 2; offset_y = h.pixelY - 2; size = 4; g.DrawEllipse(myPen, real_start_x + offset_x * scale, real_start_y + offset_y * scale, size * scale, size * scale); Size o = new Size(real_start_x, real_start_y); Point p1 = new Point((int)(h.pixelX + Math.Sin(h.angle) * Map.helirin_radius), (int)(h.pixelY - Math.Cos(h.angle) * Map.helirin_radius)); Point p2 = new Point((int)(h.pixelX - Math.Sin(h.angle) * Map.helirin_radius), (int)(h.pixelY + Math.Cos(h.angle) * Map.helirin_radius)); p1 = new Point((int)(p1.X * scale), (int)(p1.Y * scale)); p2 = new Point((int)(p2.X * scale), (int)(p2.Y * scale)); g.DrawLine(myPen, Point.Add(p1, o), Point.Add(p2, o)); } }
//=========== DRAWING ============ #region Drawing /**<summary>Draws the path railing.</summary>*/ public void DrawRailing(PaletteImage p, Point position, DrawSettings drawSettings, uint pathConnections) { int offset = (drawSettings.Queue ? 51 : 0); int connection = 0; if (PathSpriteIndexes.ContainsKey(pathConnections) && !(drawSettings.Elevation > 0 && !Header.Flags.HasFlag(FootpathFlags.OverlayPath))) { connection = PathSpriteIndexes[pathConnections]; } else if (PathSpriteIndexes.ContainsKey(pathConnections & 0xF)) { pathConnections &= 0xF; connection = PathSpriteIndexes[pathConnections & 0xF]; } if (drawSettings.Slope == -1) { if (drawSettings.Queue) { offset = 87; } else if (drawSettings.Elevation > 0) { offset = 73; } // Even offset additions are SW to NE direction railings // Odd offset additions are NW to SE direction railings // Offset additions 0-1 are no-ending railings // Offset additions 2-3 are South-ending railings // Offset additions 4-5 are North-ending railings // Outside corners use ending railings at the corner if (drawSettings.Queue || drawSettings.Elevation > 0) { // Draw ending railings if (CheckConnections(pathConnections, "####0#10")) // NE N-ending { graphicsData.paletteImages[offset + 4].DrawWithOffset(p, Point.Add(position, new Size(-4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####1#00")) // NE S-ending { graphicsData.paletteImages[offset + 2].DrawWithOffset(p, Point.Add(position, new Size(-4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####01#0")) // NW N-ending { graphicsData.paletteImages[offset + 5].DrawWithOffset(p, Point.Add(position, new Size(4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####00#1")) // NW S-ending { graphicsData.paletteImages[offset + 3].DrawWithOffset(p, Point.Add(position, new Size(4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "#####100")) // SE N-ending { graphicsData.paletteImages[offset + 5].DrawWithOffset(p, Point.Add(position, new Size(32 - 4, 16 - 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "#####001")) // SE S-ending { graphicsData.paletteImages[offset + 3].DrawWithOffset(p, Point.Add(position, new Size(32 - 4, 16 - 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####001#")) // SW N-ending { graphicsData.paletteImages[offset + 4].DrawWithOffset(p, Point.Add(position, new Size(-32 + 4, 16 - 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####100#")) // SW S-ending { graphicsData.paletteImages[offset + 2].DrawWithOffset(p, Point.Add(position, new Size(-32 + 4, 16 - 2)), drawSettings.Darkness, false); } // Draw no-ending railings if (CheckConnections(pathConnections, "####01#1")) // NW { graphicsData.paletteImages[offset + 1].DrawWithOffset(p, Point.Add(position, new Size(4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "#####101")) // SE { graphicsData.paletteImages[offset + 1].DrawWithOffset(p, Point.Add(position, new Size(32 - 4, 16 - 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####1#10")) // NE { graphicsData.paletteImages[offset + 0].DrawWithOffset(p, Point.Add(position, new Size(-4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####101#")) // SW { graphicsData.paletteImages[offset + 0].DrawWithOffset(p, Point.Add(position, new Size(-32 + 4, 16 - 2)), drawSettings.Darkness, false); } // Draw inside corner railings if (CheckConnections(pathConnections, "###0##11")) // E { graphicsData.paletteImages[offset + 11].DrawWithOffset(p, position, drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "##0##11#")) // S { graphicsData.paletteImages[offset + 12].DrawWithOffset(p, position, drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "#0##11##")) // W { graphicsData.paletteImages[offset + 13].DrawWithOffset(p, position, drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "0###1##1")) // N { graphicsData.paletteImages[offset + 10].DrawWithOffset(p, position, drawSettings.Darkness, false); } } } else { if (drawSettings.Queue) { offset = 87; } else { offset = 73; } switch (drawSettings.Slope) { case 0: graphicsData.paletteImages[offset + 6].DrawWithOffset(p, Point.Add(position, new Size(-4, 2)), drawSettings.Darkness, false); graphicsData.paletteImages[offset + 6].DrawWithOffset(p, Point.Add(position, new Size(-32 + 4, 16 - 2)), drawSettings.Darkness, false); break; case 1: graphicsData.paletteImages[offset + 8].DrawWithOffset(p, Point.Add(position, new Size(4, 2)), drawSettings.Darkness, false); graphicsData.paletteImages[offset + 8].DrawWithOffset(p, Point.Add(position, new Size(32 - 4, 16 - 2)), drawSettings.Darkness, false); break; case 2: graphicsData.paletteImages[offset + 7].DrawWithOffset(p, Point.Add(position, new Size(-4, 2)), drawSettings.Darkness, false); graphicsData.paletteImages[offset + 7].DrawWithOffset(p, Point.Add(position, new Size(-32 + 4, 16 - 2)), drawSettings.Darkness, false); break; case 3: graphicsData.paletteImages[offset + 9].DrawWithOffset(p, Point.Add(position, new Size(4, 2)), drawSettings.Darkness, false); graphicsData.paletteImages[offset + 9].DrawWithOffset(p, Point.Add(position, new Size(32 - 4, 16 - 2)), drawSettings.Darkness, false); break; } } }
public static Line ToOriginCenteredLine(Point origin, Vector axis) { return Line.ByStartPointEndPoint(origin.Add(axis.Scale(-axisScaleFactor)), origin.Add(axis.Scale(axisScaleFactor))); }
private Region GetClipRegion(IMapViewPort map) { return(new Region(new Rectangle(Point.Add(GetLocation(map), BorderMargin), _cachedSize))); }
//=========== DRAWING ============ #region Drawing /** <summary> Draws the path railing. </summary> */ public void DrawRailing(PaletteImage p, Point position, DrawSettings drawSettings, uint pathConnections) { int offset = (drawSettings.Queue ? 51 : 0); int connection = 0; if (Pathing.PathSpriteIndexes.ContainsKey(pathConnections) && !(drawSettings.Elevation > 0 && !Header.Flags.HasFlag(PathingFlags.OverlayPath))) { connection = Pathing.PathSpriteIndexes[pathConnections]; } else if (Pathing.PathSpriteIndexes.ContainsKey(pathConnections & 0xF)) { pathConnections &= 0xF; connection = Pathing.PathSpriteIndexes[pathConnections & 0xF]; } if (drawSettings.Slope == -1) { if (drawSettings.Queue) { offset = 87; } else if (drawSettings.Elevation > 0) { offset = 73; } if (drawSettings.Queue || drawSettings.Elevation > 0) { if (CheckConnections(pathConnections, "####00#1")) { graphicsData.paletteImages[offset + 3].DrawWithOffset(p, Point.Add(position, new Size(4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "#####001")) { graphicsData.paletteImages[offset + 3].DrawWithOffset(p, Point.Add(position, new Size(32 - 4, 16 - 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####0#10")) { graphicsData.paletteImages[offset + 4].DrawWithOffset(p, Point.Add(position, new Size(-4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####001#")) { graphicsData.paletteImages[offset + 4].DrawWithOffset(p, Point.Add(position, new Size(-32 + 4, 16 - 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "#####100")) { graphicsData.paletteImages[offset + 5].DrawWithOffset(p, Point.Add(position, new Size(32 - 4, 16 - 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####01#0")) { graphicsData.paletteImages[offset + 5].DrawWithOffset(p, Point.Add(position, new Size(4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####100#")) { graphicsData.paletteImages[offset + 2].DrawWithOffset(p, Point.Add(position, new Size(-32 + 4, 16 - 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####1#00")) { graphicsData.paletteImages[offset + 2].DrawWithOffset(p, Point.Add(position, new Size(-4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####01#1")) { graphicsData.paletteImages[offset + 1].DrawWithOffset(p, Point.Add(position, new Size(4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "#####101")) { graphicsData.paletteImages[offset + 1].DrawWithOffset(p, Point.Add(position, new Size(32 - 4, 16 - 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####1#10")) { graphicsData.paletteImages[offset + 0].DrawWithOffset(p, Point.Add(position, new Size(-4, 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "####101#")) { graphicsData.paletteImages[offset + 0].DrawWithOffset(p, Point.Add(position, new Size(-32 + 4, 16 - 2)), drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "###0##11")) { graphicsData.paletteImages[offset + 11].DrawWithOffset(p, position, drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "##0##11#")) { graphicsData.paletteImages[offset + 12].DrawWithOffset(p, position, drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "#0##11##")) { graphicsData.paletteImages[offset + 13].DrawWithOffset(p, position, drawSettings.Darkness, false); } if (CheckConnections(pathConnections, "0###1##1")) { graphicsData.paletteImages[offset + 10].DrawWithOffset(p, position, drawSettings.Darkness, false); } } } else { if (drawSettings.Queue) { offset = 87; } else { offset = 73; } switch (drawSettings.Slope) { case 0: graphicsData.paletteImages[offset + 6].DrawWithOffset(p, Point.Add(position, new Size(-4, 2)), drawSettings.Darkness, false); graphicsData.paletteImages[offset + 6].DrawWithOffset(p, Point.Add(position, new Size(-32 + 4, 16 - 2)), drawSettings.Darkness, false); break; case 1: graphicsData.paletteImages[offset + 8].DrawWithOffset(p, Point.Add(position, new Size(4, 2)), drawSettings.Darkness, false); graphicsData.paletteImages[offset + 8].DrawWithOffset(p, Point.Add(position, new Size(32 - 4, 16 - 2)), drawSettings.Darkness, false); break; case 2: graphicsData.paletteImages[offset + 7].DrawWithOffset(p, Point.Add(position, new Size(-4, 2)), drawSettings.Darkness, false); graphicsData.paletteImages[offset + 7].DrawWithOffset(p, Point.Add(position, new Size(-32 + 4, 16 - 2)), drawSettings.Darkness, false); break; case 3: graphicsData.paletteImages[offset + 9].DrawWithOffset(p, Point.Add(position, new Size(4, 2)), drawSettings.Darkness, false); graphicsData.paletteImages[offset + 9].DrawWithOffset(p, Point.Add(position, new Size(32 - 4, 16 - 2)), drawSettings.Darkness, false); break; } } }
public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext) { Point renderLocation = Location.Resolve(layout, layoutContext.Options); TextAlignment tempAlignment = Alignment; var flipType = layout.GetFlipType(); if ((flipType & FlipType.Horizontal) == FlipType.Horizontal) { switch (Alignment) { case TextAlignment.BottomLeft: tempAlignment = TextAlignment.BottomRight; break; case TextAlignment.BottomRight: tempAlignment = TextAlignment.BottomLeft; break; case TextAlignment.CentreLeft: tempAlignment = TextAlignment.CentreRight; break; case TextAlignment.CentreRight: tempAlignment = TextAlignment.CentreLeft; break; case TextAlignment.TopLeft: tempAlignment = TextAlignment.TopRight; break; case TextAlignment.TopRight: tempAlignment = TextAlignment.TopLeft; break; } } if ((flipType & FlipType.Vertical) == FlipType.Vertical) { switch (Alignment) { case TextAlignment.BottomCentre: tempAlignment = TextAlignment.TopCentre; break; case TextAlignment.BottomLeft: tempAlignment = TextAlignment.TopLeft; break; case TextAlignment.BottomRight: tempAlignment = TextAlignment.TopRight; break; case TextAlignment.TopCentre: tempAlignment = TextAlignment.BottomCentre; break; case TextAlignment.TopLeft: tempAlignment = TextAlignment.BottomLeft; break; case TextAlignment.TopRight: tempAlignment = TextAlignment.BottomRight; break; } } List <TextRun> renderTextRuns = new List <TextRun>(TextRuns.Count); // Build runs foreach (TextRun run in TextRuns) { // Resolve value string renderValue; if (run.Text.StartsWith("$")) { renderValue = layoutContext.GetFormattedVariable(run.Text); } else { renderValue = run.Text; } System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\\[uU]([0-9A-F]{4})"); renderValue = regex.Replace(renderValue, match => ((char)int.Parse(match.Value.Substring(2), System.Globalization.NumberStyles.HexNumber)).ToString()); renderTextRuns.Add(new TextRun(renderValue, run.Formatting)); } if (layoutContext.Options.Absolute) { drawingContext.DrawText(Point.Add(renderLocation, layout.Location), tempAlignment, (int)Rotation * 90, renderTextRuns); } else { drawingContext.DrawText(renderLocation, tempAlignment, (int)Rotation * 90, renderTextRuns); } }
public override void Process() { bool update = CMain.Time >= NextMotion || GameScene.CanMove; ProcessFrames(); if (update) { UpdateBestQuestIcon(); } if (Frame == null) { DrawFrame = 0; DrawWingFrame = 0; } else { DrawFrame = Frame.Start + (Frame.OffSet * (byte)Direction) + FrameIndex; DrawWingFrame = Frame.EffectStart + (Frame.EffectOffSet * (byte)Direction) + EffectFrameIndex; } DrawY = CurrentLocation.Y; DrawLocation = new Point((Movement.X - User.Movement.X + MapControl.OffSetX) * MapControl.CellWidth, (Movement.Y - User.Movement.Y + MapControl.OffSetY) * MapControl.CellHeight); DrawLocation.Offset(User.OffSetMove); if (BodyLibrary != null) { FinalDrawLocation = DrawLocation.Add(BodyLibrary.GetOffSet(DrawFrame)); } if (BodyLibrary != null && update) { FinalDrawLocation = DrawLocation.Add(BodyLibrary.GetOffSet(DrawFrame)); DisplayRectangle = new Rectangle(DrawLocation, BodyLibrary.GetTrueSize(DrawFrame)); } for (int i = 0; i < Effects.Count; i++) { Effects[i].Process(); } Color colour = DrawColour; switch (Poison) { case PoisonType.None: DrawColour = Color.White; break; case PoisonType.Green: DrawColour = Color.Green; break; case PoisonType.Red: DrawColour = Color.Red; break; case PoisonType.Bleeding: DrawColour = Color.DarkRed; break; case PoisonType.Slow: DrawColour = Color.Purple; break; case PoisonType.Stun: DrawColour = Color.Yellow; break; case PoisonType.Frozen: DrawColour = Color.Blue; break; case PoisonType.Paralysis: DrawColour = Color.Gray; break; } if (colour != DrawColour) { GameScene.Scene.MapControl.TextureValid = false; } if (CMain.Time > QuestTime) { QuestTime = CMain.Time + 500; if (++QuestIndex > 1) { QuestIndex = 0; } } }
public static DrawingImage CreateImage(PointPattern[] pointPatterns, Size size, Color color) { if (pointPatterns == null) { return(null); } DrawingGroup drawingGroup = new DrawingGroup(); for (int i = 0; i < pointPatterns.Length; i++) { PathGeometry pathGeometry = new PathGeometry(); color.A = (byte)(0xFF - i * 0x55); SolidColorBrush brush = new SolidColorBrush(color); Pen drawingPen = new Pen(brush, size.Height / 20 + i * 1.5) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round }; if (pointPatterns[i].Points == null) { return(null); } for (int j = 0; j < pointPatterns[i].Points.Length; j++) { if (pointPatterns[i].Points[j].Length == 1) { Geometry ellipse = new EllipseGeometry(new Point(size.Width * j + size.Width / 2, size.Height / 2), drawingPen.Thickness / 2, drawingPen.Thickness / 2); pathGeometry.AddGeometry(ellipse); continue; } StreamGeometry sg = new StreamGeometry { FillRule = FillRule.EvenOdd }; using (StreamGeometryContext sgc = sg.Open()) { // Create new size object accounting for pen width Size szeAdjusted = new Size(size.Width - drawingPen.Thickness - 1, (size.Height - drawingPen.Thickness - 1)); Size scaledSize; Point[] scaledPoints = ScaleGesture(pointPatterns[i].Points[j], szeAdjusted.Width - 10, szeAdjusted.Height - 10, out scaledSize); // Define size that will mark the offset to center the gesture double iLeftOffset = (size.Width / 2) - (scaledSize.Width / 2); double iTopOffset = (size.Height / 2) - (scaledSize.Height / 2); Vector sizOffset = new Vector(iLeftOffset + j * size.Width, iTopOffset); sgc.BeginFigure(Point.Add(scaledPoints[0], sizOffset), false, false); foreach (Point p in scaledPoints) { sgc.LineTo(Point.Add(p, sizOffset), true, true); } DrawArrow(sgc, scaledPoints, sizOffset, drawingPen.Thickness); } sg.Freeze(); pathGeometry.AddGeometry(sg); } pathGeometry.Freeze(); GeometryDrawing drawing = new GeometryDrawing(null, drawingPen, pathGeometry); drawing.Freeze(); drawingGroup.Children.Add(drawing); } // myPath.Data = sg; drawingGroup.Freeze(); DrawingImage drawingImage = new DrawingImage(drawingGroup); drawingImage.Freeze(); return(drawingImage); }
void CompositionTarget_Rendering(object sender, EventArgs e) { var renderingEventArgs = (RenderingEventArgs)e; var service = ApplicationData.Service; var progressAnimationDurationMS = service.ProgressAnimationDuration.TimeSpan.TotalMilliseconds; var accelerationRatio = 0.2; var decelerationRatio = 0.7; var renderingTimeMS = renderingEventArgs.RenderingTime.TotalMilliseconds; /*var renderingTimeS = renderingEventArgs.RenderingTime.TotalSeconds; * * if (previousRenderingTimeS == -1) * { * previousRenderingTimeS = renderingTimeS; * return; * } * * var timeElapsedBetweenRendersS = renderingTimeS - previousRenderingTimeS; * * var acceleration = 1; // units/s * * barContainer.Width += acceleration * timeElapsedBetweenRendersS;*/ if (previousProgressValue != service.ProgressValue) { previousProgressValue = service.ProgressValue; animationStartTimeMS = renderingTimeMS; var initialBarContainerPosition = barContainer.Width / ActualWidth; var targetBarContainerPosition = service.ProgressValue / service.MaxValue; var barContainerPathLength = targetBarContainerPosition - initialBarContainerPosition; var accelerationPathLength = barContainerPathLength * accelerationRatio; var decelerationPathLength = barContainerPathLength * decelerationRatio; var constantPathLength = barContainerPathLength - accelerationPathLength - decelerationPathLength; var startingPoint = new Point(initialBarContainerPosition, 0); var accelerationEndPoint = Point.Add(startingPoint, new Vector(accelerationPathLength, accelerationPathLength)); var accelerationControlPoint = new Point(startingPoint.X, accelerationEndPoint.Y); var decelerationStartPoint = Point.Add(accelerationEndPoint, new Vector(constantPathLength, 0)); var decelerationEndPoint = Point.Add(decelerationStartPoint, new Vector(decelerationPathLength, decelerationPathLength)); var decelerationControlPoint = new Point(decelerationEndPoint.X, decelerationStartPoint.Y); pathGeometry = new PathGeometry(new PathFigure[] { new PathFigure(startingPoint, new PathSegment[] { new QuadraticBezierSegment(accelerationControlPoint, accelerationEndPoint, true), new LineSegment(decelerationStartPoint, true), new QuadraticBezierSegment(decelerationControlPoint, decelerationEndPoint, true) }, false) }); } var animationTimeRatio = Math.Min((renderingTimeMS - animationStartTimeMS) / progressAnimationDurationMS, 1); Point point = new Point(); if (pathGeometry.Bounds.Width > 0) { pathGeometry.GetPointAtFractionLength(animationTimeRatio, out point, out _); } barContainer.Width = ActualWidth * point.X; }
private Point GetNewLocation(MouseEventArgs e) { Point empty = Point.Empty; return(Point.Add(Point.Subtract(e.Location, new Size(this.captureCursor)), new Size(this.captureLocation))); }
public void Drag(Point offset) { drag = drag.Add(offset); }
public static Point Add(this Point point, int offset) { return(point.Add(offset, offset)); }
public void AddTest() { Assert.AreEqual(pt1_1, Point.Add(pt1_0, new Size(0, 1)), "#1"); Assert.AreEqual(pt1_1, Point.Add(pt0_1, new Size(1, 0)), "#2"); }