private void GetInsidePixel(out int ax, out int ay) { /* * // Find a random point "inside" the polygon (assume it only have one simple region) * // Average X and average Y * ax = ay = 0; * for (int i = 0; i < Points.Count; i++) * { * ax += Points[i].X; * ay += Points[i].Y; * } * ax /= Points.Count; * ay /= Points.Count; */ // Or use a library function to get inside System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddPolygon(Points.ToArray()); int n = Points.Count; for (int i = 0; i < n; i++) { int x = Points[i].X + Points[(i + 1) % n].X + Points[(i + 2) % n].X; int y = Points[i].Y + Points[(i + 1) % n].Y + Points[(i + 2) % n].Y; x /= 3; y /= 3; if (path.IsVisible(x, y)) { ax = x; ay = y; return; } } // The function should stop here // If can't find (unlucky) :) brute force all pixel int maxX = GetMaxX(); int minX = GetMinX(); int maxY = GetMaxY(); int minY = GetMinY(); for (int x = minX; x < maxX; x++) { for (int y = minY; y < maxY; y++) { if (path.IsVisible(x, y)) { ax = x; ay = y; return; } } } // This line will never be called ax = 0; ay = 0; }
public override bool HitTest(System.Drawing.Point p) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); Pen pn = new Pen(Color.Black, 10); gp.AddLines(myPts); gp.Widen(pn); gp.IsVisible(p); pn.Dispose(); return(gp.IsVisible(p)); }
public override bool HitTest(System.Drawing.PointF point, float precisionDelta) { bool result = false; if (_pen != null || _brush != null) { using (System.Drawing.Drawing2D.GraphicsPath actualPath = (System.Drawing.Drawing2D.GraphicsPath) this.Path.Clone()) { actualPath.Transform(_matrix); if (_pen != null) { using (System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black, _pen.Width + precisionDelta)) result = actualPath.IsOutlineVisible(point, pen); } if (!result && _brush != null) { result = actualPath.IsVisible(point); } } } return(result); }
public virtual void finish() { m_bZeichenMode = false; //UPGRADE_TODO: Constructor 'java.awt.Polygon.Polygon' was converted to 'SupportClass.CreateGraphicsPath' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtPolygonPolygon_int[]_int[]_int"' m_Polygon = SupportClass.CreateGraphicsPath(m_EckeX, m_EckeY, m_iEcken); int i = 0; for (; i <= iMaxColors; i++) { //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"' int iFarbe = System.Math.Min((int)System.Math.Round(m_RandomFarbe * SupportClass.Random.NextDouble()) + m_MinFarbe, m_MaxFarbe); m_Colors[i] = System.Drawing.Color.FromArgb(iFarbe, iFarbe, iFarbe); } for (i = m_iEcken; i < m_iEcken * 2; i++) { int x, y; do { //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"' x = (int)System.Math.Round(SupportClass.Random.NextDouble() * m_Ground.Size.Width); //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"' y = (int)System.Math.Round(SupportClass.Random.NextDouble() * m_Ground.Size.Height); }while (!m_Polygon.IsVisible(x, y)); m_EckeX[i] = x; m_EckeY[i] = y; } }
public override bool HitTest(System.Drawing.Point point, ICoordinateMapper coordinateMapper) { if (coordinateMapper == null) { throw new System.ArgumentNullException("coordinateMapper"); } bool result = false; if (base.Enabled && _path != null) { System.Drawing.Point convertedPoint = coordinateMapper.WorkspaceToControl(base.Location, Aurigma.GraphicsMill.Unit.Point); point.X -= convertedPoint.X; point.Y -= convertedPoint.Y; result = _path.IsVisible(point); if (!result && this.Pen != null) { result = _path.IsOutlineVisible(point, this.Pen); } } return(result); }
public override bool Inside(int x, int y) { using (var gp = new System.Drawing.Drawing2D.GraphicsPath()) { gp.AddEllipse(bounds); return(gp.IsVisible(x, y)); } }
public bool contains(System.Drawing.Point p) { System.Drawing.Drawing2D.GraphicsPath myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath(); //Region myRegion=new Region(); myGraphicsPath.Reset(); myGraphicsPath.AddPolygon(toPoints()); return(myGraphicsPath.IsVisible(p)); }
/// <summary> /// Get is mouse on the annotation polygon or not. /// </summary> /// <param name="point"></param> /// <returns></returns> internal override bool IsMouseOnTheElement(PointF point) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); if (DrawPoints.Length > 5) { gp.AddLines(DrawPoints); } return(gp.IsVisible(point)); }
public virtual bool contains(int x, int y) { if (m_Polygon != null) { return(m_Polygon.IsVisible(x, y)); } else { return(false); } }
internal static bool IsEllipse(int x, int y, int width, int height, int mouseX, int mouseY) { using (var path = new System.Drawing.Drawing2D.GraphicsPath()) { path.AddEllipse(x, y, width, height); return(path.IsVisible(mouseX, mouseY)); } }
public override bool HitTest(System.Drawing.PointF point, float precisionDelta) { bool result = false; using (System.Drawing.Drawing2D.GraphicsPath boundsPath = (System.Drawing.Drawing2D.GraphicsPath)_boundsPath.Clone()) { boundsPath.Transform(base.Transform); result = boundsPath.IsVisible(point); } return(result); }
public override bool HitTest(System.Drawing.Point pt) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(); gp.AddRectangle(new System.Drawing.Rectangle(this.m_Position.X - (int)(0.25 * this.m_Size.Width), this.m_Position.Y - (int)(0.25 * this.m_Size.Height), (int)(1.25 * this.m_Size.Width), (int)(1.25 * this.m_Size.Height))); if (this.m_Rotation != 0) { myMatrix.RotateAt((float)(this.m_Rotation), new System.Drawing.PointF((float)this.X, (float)this.Y), System.Drawing.Drawing2D.MatrixOrder.Append); } gp.Transform(myMatrix); return(gp.IsVisible(pt)); }
/// <summary> /// 未知方法,(现已废弃,替代方法 PointInPolygon) /// </summary> /// <param name="point"></param> /// <param name="pointColl"></param> /// <returns></returns> public static bool IsVisible_GraphicsPath(Point point, List <Point> pointColl) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); List <System.Drawing.Point> pathPoints = new List <System.Drawing.Point>(); foreach (var pathPoint in pointColl) { pathPoints.Add(new System.Drawing.Point((int)Math.Round(pathPoint.X), (int)Math.Round(pathPoint.Y))); } path.AddPolygon(pathPoints.ToArray()); path.CloseFigure(); return(path.IsVisible(new System.Drawing.Point((int)Math.Round(point.X), (int)Math.Round(point.Y)))); }
private void FrmPolygonShape2_Paint(object sender, PaintEventArgs e) { /// zoom and shift the output Form f = (Form)sender; double d = f.ClientSize.Width / (double)f.ClientSize.Height; _shiftX = pt.Min(a => a.X); _shiftY = pt.Min(a => a.Y); float distX = Math.Abs(pt.Max(a => a.X) - _shiftX); float distY = Math.Abs(pt.Max(a => a.Y) - _shiftY); double factor = distX / distY; _zoom = 1.0f; _zoom = factor >= d ? (float)(f.ClientSize.Width / distX) : (float)(f.ClientSize.Height / distY); e.Graphics.ScaleTransform(_zoom, _zoom); e.Graphics.TranslateTransform(-_shiftX * _zoom, -_shiftY * _zoom, System.Drawing.Drawing2D.MatrixOrder.Append); /// make nicer look e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; /// setup the path and test for being inside using (System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath()) { myPath.AddLines(pt); myPath.CloseFigure(); using (Pen pen = new Pen(Color.Blue, 4)) e.Graphics.DrawPath(pen, myPath); using (Pen pen = new Pen(Color.Blue)) { /// IsoutlineVisible is not needed normally if (myPath.IsVisible(ptCheck) || myPath.IsOutlineVisible(ptCheck, pen)) { this.Text = "inside - Origin at " + new PointF(_shiftX, _shiftY).ToString() + "; ZoomFacotr: ";// + _zoom.ToString(); } else { this.Text = "outside - Origin at " + new PointF(_shiftX, _shiftY).ToString() + "; ZoomFacotr: ";// + _zoom.ToString(); } } } /// draw the testpoint as a small cross using (Pen pen = new Pen(Color.Red, 4)) { e.Graphics.DrawLine(pen, ptCheck.X - 5 / _zoom, ptCheck.Y, ptCheck.X + 5 / _zoom, ptCheck.Y); e.Graphics.DrawLine(pen, ptCheck.X, ptCheck.Y - 5 / _zoom, ptCheck.X, ptCheck.Y + 5 / _zoom); } }
private bool CheckMouseHover(int x, int y) { using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath()) { path.AddEllipse(0, 0, this.ClientSize.Width - 1, this.ClientSize.Height - 1); bool flag = path.IsVisible(x, y); if (flag != bolMouseHoverFlag) { bolMouseHoverFlag = flag; this.Invalidate(); } return(flag); } }
private int getActiveIndexAtPoint(Point point) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.GraphicsPathIterator iterator = new System.Drawing.Drawing2D.GraphicsPathIterator(_pathData); iterator.Rewind(); for (int current = 0; current < iterator.SubpathCount; current++) { iterator.NextMarker(path); if (path.IsVisible(point, _graphics)) { return(current); } } return(-1); }
/// <summary> /// 確定前のタイルを描画 /// </summary> protected virtual void drawTemporaryTiles() { DX.SetDrawBlendMode(DX.DX_BLENDMODE_NOBLEND, -1); if (this.parent.PuttingTileStart != null) { //実際の描画領域を生成する var tempPath = new System.Drawing.Drawing2D.GraphicsPath(); switch (this.parent.EditMode) { case mgrMapObject.TileEditMode.Rectangle: tempPath.AddRectangle(this.parent.PuttingTileRange); break; case mgrMapObject.TileEditMode.Ellipse: tempPath.AddEllipse(this.parent.PuttingTileRange.X - 1, this.parent.PuttingTileRange.Y - 1, this.parent.PuttingTileRange.Width + 1, this.parent.PuttingTileRange.Height + 1); break; } //確定前のタイルを描画する for (int a = 0, x = this.parent.PuttingTileRange.Left; x < this.parent.PuttingTileRange.Right; x++, a++) { for (int b = 0, y = this.parent.PuttingTileRange.Top; y < this.parent.PuttingTileRange.Bottom; y++, b++) { if (!tempPath.IsVisible(x, y)) { //描画領域に該当しない部分はスキップする continue; } //単一タイルを描画 if (this.parent.ClippingTiles != null) { //クリッピングしている場合 this.drawTileWithAutotilePattern(x, y, this.parent.ClippingTiles[a % this.parent.ClippingTiles.GetLength(0), b % this.parent.ClippingTiles.GetLength(1)].PalletPosition, Map.AutoTilePattern.AllSide); } else { //パレットで選択している場合 this.drawTileWithAutotilePattern(x, y, new Point((this.parent.SelectedPalletRange.Location.X + (a % this.parent.SelectedPalletRange.Width)), (this.parent.SelectedPalletRange.Location.Y + (b % this.parent.SelectedPalletRange.Height))), Map.AutoTilePattern.AllSide); } } } } }
public UIElement GetHitElement(System.Drawing.Point hittedPoint) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); Shape temp; for (int i = canvas.Children.Count - 1; i >= 0; i--) { temp = (Shape)canvas.Children[i]; System.Drawing.Size childSize = new System.Drawing.Size((int)temp.Width, (int)temp.Height); System.Drawing.Point childPos = new System.Drawing.Point(); childPos.X = (int)canvas.Children[i].TranslatePoint(new System.Windows.Point(0, 0), canvas).X; childPos.Y = (int)canvas.Children[i].TranslatePoint(new System.Windows.Point(0, 0), canvas).Y; path.AddRectangle(new System.Drawing.Rectangle(childPos, childSize)); if (path.IsVisible(hittedPoint)) { return(canvas.Children[i]); } } return(null); }
//タイマーの時間がたったとき、、、 private void timer_Tick(object sender, EventArgs e) { //バックバッファに描画開始 Graphics g = Graphics.FromImage(backbuffer); g.Clear(Color.White); //現在のゲームで見分ける switch (nowGameType) { case GameType.Title: //タイトル { Font font = new Font(this.Font.FontFamily, 40, FontStyle.Bold); g.DrawString(Application.ProductName, font, Brushes.Black, WindowSize.Width / 2 - g.MeasureString(Application.ProductName, font).Width / 2, 20); font = new Font(this.Font.FontFamily, 20); string text = "ゲームスタート"; int titleY = 200; g.DrawRectangle(new Pen(Brushes.Black), WindowSize.Width / 2 - 100, titleY, 200, 30); g.DrawString(text, font, Brushes.Black, WindowSize.Width / 2 - g.MeasureString(text, font).Width / 2, titleY); text = "ハイスコア"; titleY = 250; g.DrawRectangle(new Pen(Brushes.Black), WindowSize.Width / 2 - 100, titleY, 200, 30); g.DrawString(text, font, Brushes.Black, WindowSize.Width / 2 - g.MeasureString(text, font).Width / 2, titleY); text = "終了"; titleY = 300; g.DrawRectangle(new Pen(Brushes.Black), WindowSize.Width / 2 - 100, titleY, 200, 30); g.DrawString(text, font, Brushes.Black, WindowSize.Width / 2 - g.MeasureString(text, font).Width / 2, titleY); break; } case GameType.Game: //ゲーム中 { //障害物を描画する g.FillPolygon(Brushes.Green, syougaiObject); //敵の基地を描画する g.FillRectangle(Brushes.Black, enemyRectangle); //敵の移動 if (gameStopWatch.IsRunning) { if (enemyMoveAdvance) { enemyRectangle.X += enemyMovedt; if (enemyRectangle.X > WindowSize.Width - BaseSize) { enemyMoveAdvance = false; } } else { enemyRectangle.X -= enemyMovedt; if (enemyRectangle.X < enemyStartX) { enemyMoveAdvance = true; } } } //自分の基地を描画 g.FillRectangle(Brushes.Black, myRectangle); //砲弾シミュレート中ならば、、、 if (timeStopwatch.IsRunning) { //現時点での時間を保存する double time = timeStopwatch.Elapsed.TotalSeconds; //現時点の砲弾位置を計算する x = v0 * Math.Cos(angle) * time + myRectangle.X + (myRectangle.Width / 2); y = v0 * Math.Sin(angle) * time - 0.5 * Gravity * Math.Pow(time, 2) + (WindowSize.Height - myRectangle.Y - myRectangle.Height / 2); //砲弾を描画する g.FillPie(Brushes.Black, (float)x - 5, WindowSize.Height - (float)y - 5, 10, 10, 0, 360); //あたり判定 if (enemyRectangle.IntersectsWith(new Rectangle((int)x - 5, WindowSize.Height - (int)y - 5, 10, 10))) { //時間を停止する timeStopwatch.Stop(); //ゲーム時間を停止する gameStopWatch.Stop(); //自分の位置決定 myRectangle = new Rectangle(10, WindowSize.Height - BaseSize, BaseSize, BaseSize); //敵の位置決定 Random rnd = new Random(); enemyRectangle = new Rectangle(rnd.Next(enemyStartX, WindowSize.Width - BaseSize), WindowSize.Height - BaseSize, BaseSize, BaseSize); //スコアに追加する。 int i = hiScore.Add(new ScoreClass(ShotNumber, gameStopWatch.Elapsed, DateTime.Now)); //ゲームタイプを変更 nowGameType = GameType.Title; //砲撃完了したメッセージを表示する。 if (i == -1) { MessageBox.Show("砲撃完了!\n残念ながらスコア外です。。。\n次はがんばってくださいぃ。。。\n\n" + "発射回数=" + ShotNumber + "回\n所要時間=" + gameStopWatch.Elapsed.ToString()); } else { MessageBox.Show("砲撃完了!\nすごいですぅ。。。\n" + (i + 1) + "位です!!さすがぁ。。。\n\n" + "発射回数=" + ShotNumber + "回\n所要時間=" + gameStopWatch.Elapsed.ToString()); } break; } //砲弾が地面よりも下と右を超えてしまったならば、、、 if (y < 0 || x < 0 || x >= WindowSize.Width) { timeStopwatch.Stop(); } //砲弾と障害物との当たり判定 if (syougaiObject[1].X <= x && x <= syougaiObject[2].X && syougaiObject[0].Y <= WindowSize.Height - y && WindowSize.Height - y <= syougaiObject[1].Y) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddPolygon(syougaiObject); if (gp.IsVisible((int)x, WindowSize.Height - (int)y)) { timeStopwatch.Stop(); } gp.Dispose(); } } else if (gameStopWatch.IsRunning) //ゲームが動いているならば、、、 { //指示線を描画する Pen pen = new Pen(Brushes.Black, 5); pen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; g.DrawLine(pen, myRectangle.X + (myRectangle.Width / 2), myRectangle.Y + (myRectangle.Height / 2), mousePoint.X, mousePoint.Y); } //情報表示 int showV0 = (int)v0; int showAngle = (int)(angle * 180 / Math.PI); g.DrawString("初速度=" + showV0.ToString("d3") + "[m/s]\n角度=" + showAngle.ToString("d3") + "[°]" + "\n発射回数=" + ShotNumber + "回\n自分の基地をクリックするとゲームを終了します。", this.Font, Brushes.Red, 10, 10); break; } case GameType.Hiscore: //ハイスコア画面 { Font font = new Font(this.Font.FontFamily, 40, FontStyle.Bold); g.DrawString("ハイスコア", font, Brushes.Black, WindowSize.Width / 2 - g.MeasureString("ハイスコア", font).Width / 2, 20); font = new Font(this.Font.FontFamily, 20); g.DrawString("クリックするとタイトル画面に戻れます。", font, Brushes.Black, WindowSize.Width / 2 - g.MeasureString("クリックするとタイトル画面に戻れます。", font).Width / 2, 70); //水平線を描画する。 int yy = -1; for (; yy <= 10; yy++) { g.DrawLine(new Pen(Brushes.Black), 50, yy * 30 + 200, 750, yy * 30 + 200); } //垂直線を描画する g.DrawLine(new Pen(Brushes.Black), 50, 170, 50, 500); g.DrawLine(new Pen(Brushes.Black), 120, 170, 120, 500); g.DrawLine(new Pen(Brushes.Black), 240, 170, 240, 500); g.DrawLine(new Pen(Brushes.Black), 500, 170, 500, 500); g.DrawLine(new Pen(Brushes.Black), 750, 170, 750, 500); //ヘッダを描画する string text = "順位"; g.DrawString(text, font, Brushes.Black, (120 - 50) / 2 + 50 - g.MeasureString(text, font).Width / 2, 170); text = "発射回数"; g.DrawString(text, font, Brushes.Black, (240 - 120) / 2 + 120 - g.MeasureString(text, font).Width / 2, 170); text = "所要時間"; g.DrawString(text, font, Brushes.Black, (500 - 240) / 2 + 240 - g.MeasureString(text, font).Width / 2, 170); text = "達成日時"; g.DrawString(text, font, Brushes.Black, (750 - 500) / 2 + 500 - g.MeasureString(text, font).Width / 2, 170); yy = 0; foreach (ScoreClass sc in hiScore) { text = (yy + 1).ToString(); g.DrawString(text, font, Brushes.Black, (120 - 50) / 2 + 50 - g.MeasureString(text, font).Width / 2, yy * 30 + 200); text = sc.ShotNumber.ToString(); g.DrawString(text, font, Brushes.Black, (240 - 120) / 2 + 120 - g.MeasureString(text, font).Width / 2, yy * 30 + 200); text = sc.GameTime.ToString(); g.DrawString(text, font, Brushes.Black, (500 - 240) / 2 + 240 - g.MeasureString(text, font).Width / 2, yy * 30 + 200); text = sc.dateTime.ToString(); g.DrawString(text, font, Brushes.Black, (750 - 500) / 2 + 500 - g.MeasureString(text, font).Width / 2, yy * 30 + 200); yy++; } for (; yy < 10; yy++) { text = (yy + 1).ToString(); g.DrawString(text, font, Brushes.Black, (120 - 50) / 2 + 50 - g.MeasureString(text, font).Width / 2, yy * 30 + 200); text = "----"; g.DrawString(text, font, Brushes.Black, (240 - 120) / 2 + 120 - g.MeasureString(text, font).Width / 2, yy * 30 + 200); text = "--:--:--.-----"; g.DrawString(text, font, Brushes.Black, (500 - 240) / 2 + 240 - g.MeasureString(text, font).Width / 2, yy * 30 + 200); text = "----/--/-- --:--:--"; g.DrawString(text, font, Brushes.Black, (750 - 500) / 2 + 500 - g.MeasureString(text, font).Width / 2, yy * 30 + 200); } break; } } //デバッグメッセージ描画 #if DEBUG g.DrawString("DebugMessage Mouse=(" + mousePoint.X + "," + mousePoint.Y + ") TIME=" + timeStopwatch.Elapsed + " Fire=(" + (int)x + "," + (int)y + ")" + " GameTime=" + gameStopWatch.Elapsed, this.Font, Brushes.Black, 0, 0); #endif //描画終了 g.Dispose(); //描画 g = CreateGraphics(); g.DrawImage(backbuffer, 0, 0); g.Dispose(); }
public override bool HitTest(System.Drawing.Point p) { return(gp.IsVisible(p)); }
private int getActiveIndexAtPoint(Point point) { System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Drawing2D.GraphicsPathIterator iterator = new System.Drawing.Drawing2D.GraphicsPathIterator(_pathData); iterator.Rewind(); for (int current = 0; current < iterator.SubpathCount; current++) { iterator.NextMarker(path); if (path.IsVisible(point, this.g)) return current; } return -1; }
protected override void OnPaintBackground(PaintEventArgs pevent) { //Simulate Transparency System.Drawing.Drawing2D.GraphicsContainer g = pevent.Graphics.BeginContainer(); Rectangle translateRect = this.Bounds; pevent.Graphics.TranslateTransform(-this.Left, -this.Top); PaintEventArgs pe = new PaintEventArgs(pevent.Graphics, translateRect); this.InvokePaintBackground(this.Parent, pe); this.InvokePaint(this.Parent, pe); pevent.Graphics.ResetTransform(); pevent.Graphics.EndContainer(g); pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Color shadeColor, fillColor; Color darkColor = DarkenColor(this.BackColor, 10); Color darkDarkColor = DarkenColor(this.BackColor, 25); Color lightColor = LightenColor(this.BackColor, 25); Color lightLightColor = LightenColor(this.BackColor, 60); // 不显示渐变 if (!GradientMode) { darkColor = this.BackColor; darkDarkColor = this.BackColor; lightColor = this.BackColor; lightLightColor = this.BackColor; } else { } if (this.ButtonState == CustomButtonState.Hot) { fillColor = lightColor; shadeColor = darkDarkColor; } else if (this.ButtonState == CustomButtonState.Pressed) { fillColor = this.BackColor; shadeColor = this.BackColor; } else { fillColor = this.BackColor; shadeColor = darkDarkColor; } Rectangle r = this.ClientRectangle; System.Drawing.Drawing2D.GraphicsPath path = RoundRectangle(r, this.CornerRadius, this.RoundCorners); System.Drawing.Drawing2D.LinearGradientBrush paintBrush = new System.Drawing.Drawing2D.LinearGradientBrush(r, fillColor, shadeColor, System.Drawing.Drawing2D.LinearGradientMode.Vertical); //We want a sharp change in the colors so define a Blend for the brush if (ShadeMode) { System.Drawing.Drawing2D.Blend b = new System.Drawing.Drawing2D.Blend(); b.Positions = new float[] { 0, 0.45F, 0.55F, 1 }; b.Factors = new float[] { 0, 0, 1, 1 }; paintBrush.Blend = b; } //Draw the Button Background pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; pevent.Graphics.FillPath(paintBrush, path); paintBrush.Dispose(); //...and border Pen drawingPen = new Pen(BorderColor); pevent.Graphics.DrawPath(drawingPen, path); drawingPen.Dispose(); //Get the Rectangle to be used for Content bool inBounds = false; //We could use some Math to get this from the radius but I'm //not great at Math so for the example this hack will suffice. while (!inBounds && r.Width >= 1 && r.Height >= 1) { inBounds = path.IsVisible(r.Left, r.Top) && path.IsVisible(r.Right, r.Top) && path.IsVisible(r.Left, r.Bottom) && path.IsVisible(r.Right, r.Bottom); r.Inflate(-1, -1); } contentRect = r; }
/// <summary> /// Determine is the point on the annotation or not. /// </summary> /// <param name="point"></param> /// <returns></returns> internal override bool IsMouseOnTheElement(System.Drawing.PointF point) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddEllipse(rectangle); return(gp.IsVisible(point)); }
/// <summary> /// 指定したタイル座標にパレットで選択されたタイルを配置します。 /// 鉛筆ツールのときのみ、配置したタイルの前後情報をリストにして返します。 /// </summary> /// <param name="absolutely">オートタイルを更新せずに原形を留めるかどうか</param> public List <TileBuffer> PutTiles(int dx, int dy, bool absolutely) { var list = new List <TileBuffer>(); if (!Enum.IsDefined(typeof(Map.Layer), this.CurrentLayer)) { //無効なレイヤー return(list); } //編集モードに従った処理 switch (this.EditMode) { case TileEditMode.Pencil: if (this.ClippingTiles == null) { //パレットの選択領域を使って配置する var put = new TileBuffer((Map.Layer) this.CurrentLayer, new Point(dx, dy), this.MapData.LayerTiles[this.CurrentLayer, dx, dy]); this.MapData.LayerTiles[this.CurrentLayer, dx, dy].PalletPosition = this.SelectedPalletRange.Location; if (!absolutely) { this.ApplyAutoTile((Map.Layer) this.CurrentLayer, dx, dy); } put.After = this.MapData.LayerTiles[this.CurrentLayer, dx, dy]; list.Add(put); } else { //クリッピング領域を使って配置する for (var x = 0; x < this.ClippingTiles.GetLength(0) && dx + x < this.MapData.MapSize.Width; x++) { for (var y = 0; y < this.ClippingTiles.GetLength(1) && dy + y < this.MapData.MapSize.Height; y++) { var put = new TileBuffer((Map.Layer) this.CurrentLayer, new Point(dx + x, dy + y), this.MapData.LayerTiles[this.CurrentLayer, dx + x, dy + y]); this.MapData.LayerTiles[this.CurrentLayer, dx + x, dy + y].PalletPosition = this.ClippingTiles[x, y].PalletPosition; this.MapData.LayerTiles[this.CurrentLayer, dx + x, dy + y].SetQuarters(this.ClippingTiles[x, y].GetQuarters()); if (!absolutely) { this.ApplyAutoTile((Map.Layer) this.CurrentLayer, dx + x, dy + y); } put.After = this.MapData.LayerTiles[this.CurrentLayer, dx + x, dy + y]; list.Add(put); } } } break; case TileEditMode.Rectangle: case TileEditMode.Ellipse: //確定前矩形領域の有効範囲を生成する var tempPath = new System.Drawing.Drawing2D.GraphicsPath(); switch (this.EditMode) { case TileEditMode.Rectangle: tempPath.AddRectangle(this.PuttingTileRange); break; case TileEditMode.Ellipse: tempPath.AddEllipse(this.PuttingTileRange.X - 1, this.PuttingTileRange.Y - 1, this.PuttingTileRange.Width + 1, this.PuttingTileRange.Height + 1); break; } //有効範囲内にタイルを配置する for (int a = 0, x = this.PuttingTileRange.Left; x < this.PuttingTileRange.Right; x++, a++) { for (int b = 0, y = this.PuttingTileRange.Top; y < this.PuttingTileRange.Bottom; y++, b++) { if (!tempPath.IsVisible(x, y)) { continue; //描画範囲外 } else if (this.ClippingTiles == null) { //パレットの選択領域を使って配置する this.MapData.LayerTiles[this.CurrentLayer, x, y].PalletPosition = this.SelectedPalletRange.Location; } else { //クリッピング領域を使って配置する this.MapData.LayerTiles[this.CurrentLayer, x, y].PalletPosition = this.ClippingTiles[a % this.ClippingTiles.GetLength(0), b % this.ClippingTiles.GetLength(1)].PalletPosition; this.MapData.LayerTiles[this.CurrentLayer, x, y].SetQuarters(this.ClippingTiles[a % this.ClippingTiles.GetLength(0), b % this.ClippingTiles.GetLength(1)].GetQuarters()); } if (!absolutely) { this.ApplyAutoTile((Map.Layer) this.CurrentLayer, x, y); } } } break; } return(list); }
/// <summary> /// Performs a hit test on the polygon /// </summary> /// <param name="point"></param> /// <returns></returns> public bool HitTest(PointF point) { return(graphicsPath.IsVisible(point)); }