public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            if (angle == 0)
            {
                transform.Reset();
                return;
            }

            if (right2Left)
            {
                curAngle -= CHANGE_VALUE;
                if (curAngle <= -angle)
                {
                    curAngle   = -angle;
                    right2Left = false;
                }
            }
            else
            {
                curAngle += CHANGE_VALUE;
                if (curAngle >= angle)
                {
                    curAngle   = angle;
                    right2Left = true;
                    repeatCount++;
                }
            }

            transform.Reset();
            transform.RotateAt(curAngle, curAngle >= 0 ? rightPivot : leftPivot);
        }
Beispiel #2
0
        public IEnumerable <System.Drawing.Rectangle> iterPreventRects()
        {
            var transform = new System.Drawing.Drawing2D.Matrix();
            var pts       = new System.Drawing.Point[1];

            int   circleCount = 16;
            float angleDelta  = 360 / circleCount;
            float angle       = 0;

            for (int i = 0; i < circleCount; ++i)
            {
                transform.Reset();
                transform.Rotate(angle);

                pts[0] = new System.Drawing.Point(0, 96);

                transform.TransformPoints(pts);

                var pt = pts[0];

                var hitRect = new System.Drawing.Rectangle(this.x + pt.X - 48, this.y + pt.Y - 48, 96, 96);
                // bool isCollision = _gamePlay.scene.hitTestCollision(snake.headPreventCollisionRect);

                //Console.WriteLine("{0} Prevent angle={1} hit={2}", snake, angle, isCollision);

                if (_headPreventCollisionRect.IntersectsWith(hitRect) == false)
                {
                    yield return(hitRect);
                }



                angle += angleDelta;
            }
        }
Beispiel #3
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            transform.Reset();
            if (fromScale != toScale)
            {
                if (small2Big)
                {
                    curScale += CHANGE_VALUE;
                    if (curScale >= toScale)
                    {
                        curScale  = toScale;
                        small2Big = false;
                        repeatCount++;
                    }
                }
                else
                {
                    curScale -= CHANGE_VALUE;
                    if (curScale <= fromScale)
                    {
                        curScale  = fromScale;
                        small2Big = true;
                    }
                }

                offsetX = pivotX * curScale - pivotX;
                offsetY = pivotY * curScale - pivotY;

                transform.Translate(-offsetX, -offsetY);
                transform.Scale(curScale, curScale);
            }
        }
Beispiel #4
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            if (toX == fromX)
            {
                curX = toX;
            }
            else if (fromX < toX)
            {
                curX += CHANGE_VALUE;
                if (curX >= toX)
                {
                    curX = toX;
                }
            }
            else
            {
                curX -= CHANGE_VALUE;
                if (curX <= toX)
                {
                    curX = toX;
                }
            }

            transform.Reset();

            transform.Translate(curX - fromX, 0);
            transform.RotateAt(-GetRotateAngle(curX), pivot);
        }
Beispiel #5
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            if (fromAngle == toAngle)
            {
                curAngle = toAngle;
            }
            else
            {
                if (fromAngle < toAngle)
                {
                    curAngle += CHANGE_VALUE;
                    if (curAngle >= toAngle)
                    {
                        curAngle = toAngle;
                    }
                }
                else
                {
                    curAngle -= CHANGE_VALUE;
                    if (curAngle <= toAngle)
                    {
                        curAngle = toAngle;
                    }
                }
            }

            transform.Reset();
            transform.RotateAt(curAngle, pivotPoint);
        }
Beispiel #6
0
 public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
 {
     transform.Reset();
     if (fromScale == toScale)
     {
         curScale = fromScale;
     }
     else if (fromScale < toScale)
     {
         curScale += CHANGE_VALUE;
         if (curScale >= toScale)
         {
             curScale = toScale;
         }
     }
     else
     {
         curScale -= CHANGE_VALUE;
         if (curScale <= toScale)
         {
             curScale = toScale;
         }
     }
     SetTransform(transform, curScale);
 }
Beispiel #7
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            transform.Reset();
            if (leftX != rightX)
            {
                if (left2Right)
                {
                    curX += CHANGE_VALUES;
                    if (curX >= rightX)
                    {
                        curX       = rightX;
                        left2Right = false;
                        repeatCount++;
                    }
                }
                else
                {
                    curX -= CHANGE_VALUES;
                    if (curX <= leftX)
                    {
                        curX       = leftX;
                        left2Right = true;
                    }
                }
            }

            transform.Shear(curX, 0);
            offset = pivotY * curX;
            transform.Translate(-offset, 0);
        }
 public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
 {
     MoveX();
     MoveY();
     transform.Reset();
     transform.Translate(curX - fromX, curY - fromY);
 }
        /// <summary>
        /// 画像をピクチャボックスのサイズに合わせて全体に表示するアフィン変換行列を求める
        /// </summary>
        /// <param name="mat">アフィン変換行列</param>
        /// <param name="image">画像データ</param>
        /// <param name="dst">描画先のピクチャボックス</param>
        private void ZoomFit(
            ref System.Drawing.Drawing2D.Matrix mat,
            ImagingSolution.Imaging.ImageData image,
            PictureBox dst)
        {
            // アフィン変換行列の初期化(単位行列へ)
            mat.Reset();

            int srcWidth  = image.Width;
            int srcHeight = image.Height;
            int dstWidth  = dst.Width;
            int dstHeight = dst.Height;

            float scale;

            // 縦に合わせるか?横に合わせるか?
            if (srcHeight * dstWidth > dstHeight * srcWidth)
            {
                // ピクチャボックスの縦方法に画像表示を合わせる場合
                scale = dstHeight / (float)srcHeight;
                mat.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);
                // 中央へ平行移動
                mat.Translate((dstWidth - srcWidth * scale) / 2f, 0f, System.Drawing.Drawing2D.MatrixOrder.Append);
            }
            else
            {
                // ピクチャボックスの横方法に画像表示を合わせる場合
                scale = dstWidth / (float)srcWidth;
                mat.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);
                // 中央へ平行移動
                mat.Translate(0f, (dstHeight - srcHeight * scale) / 2f, System.Drawing.Drawing2D.MatrixOrder.Append);
            }
        }
Beispiel #10
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            stepCount++;

            float scale  = 1 - 0.2f * (stepCount - 1);
            float offset = pivotY * scale - pivotY;

            transform.Reset();
            transform.Translate(0, -offset);
            transform.Scale(1, scale);
        }
Beispiel #11
0
        public void OnRender(System.Drawing.Graphics g)
        {
            if (TransformCallback != null)
            {
                transform.Reset();
                TransformCallback(transform);
            }

            g.Transform = transform;
            shape.Draw(g);
        }
Beispiel #12
0
        private void VObjectChangedHandler(object sender, System.EventArgs e)
        {
            if (_updatingChildren)
            {
                return;
            }

            VObject vobj = sender as VObject;

            if (vobj != null && vobj.IsDisposed)
            {
                _children.Remove(vobj);
            }

            _matrix.Reset();

            UpdateBaseRectangle();
            UpdateChildMatrices();
            UpdateControlPointsState();
            base.OnChanged(System.EventArgs.Empty);
        }
Beispiel #13
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            if (bounceBack && beginBounceBack)
            {
                BounceBack();
            }
            else
            {
                Fall();
            }

            if (curY == toY)//到达结束位置
            {
                if (bounceBack)
                {
                    if (beginBounceBack)        //已经开始了回弹,表示第二次回到结束位置。
                    {
                        curAnimationEnd = true; //当前动画结束
                        transform.Reset();
                        transform.Translate(0, toY - fromY);
                    }
                    beginBounceBack = true;//开始回弹
                }
                else//不回弹
                {
                    curAnimationEnd = true;//当前动画结束
                    transform.Reset();
                    transform.Translate(0, toY - fromY);
                }
            }
            else
            {
                transform.Reset();
                transform.Translate(0, curY - fromY);//再平移
                if (bounceBack && !back)
                {
                    transform.RotateAt(-angle, pivot);//先旋转
                }
            }
        }
Beispiel #14
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            transform.Reset();
            if (IsAnimationEnd())
            {
                return;
            }

            sineValue     = (float)Math.Sin(currentPhase);
            value         = sineValue * amplitude;
            currentPhase -= SPEED;
            //currentPhase = (float)(currentPhase % (2 * Math.PI));
            transform.Translate(0, value);
        }
Beispiel #15
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            if (frameCount < 2)
            {
                frameCount++;
                return;
            }

            offsetX = random.Next(-3, 3);
            offsetY = random.Next(-3, 3);

            transform.Reset();
            transform.Translate(offsetX, offsetY);
            repeatCount++;
            frameCount = 0;
        }
Beispiel #16
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            if (fromY == toY)
            {
                curY = toY;
            }
            else if (toY > fromY)
            {
                if (curY >= toY)
                {
                    curY = fromY;
                    repeatCount++;
                }
                else
                {
                    curY += CHANGE_VALUE;
                    if (curY >= toY)
                    {
                        curY = toY;
                    }
                }
            }
            else
            {
                if (curY <= toY)
                {
                    curY = fromY;
                    repeatCount++;
                }
                else
                {
                    curY -= CHANGE_VALUE;
                    if (curY <= toY)
                    {
                        curY = toY;
                    }
                }
            }

            transform.Reset();
            transform.Translate(0, curY - initY);
        }
Beispiel #17
0
        //=========================================
        // setScrollAmount
        //=========================================
        public void setScrollPercent(float normalizedPercent)
        {
            int maxScroll = Math.Max(this.Width, mMaxXValue * mDrawDistanceBetweenXTicks) - this.Width;


            if (normalizedPercent < 0)
            {
                normalizedPercent = 0;
            }
            if (normalizedPercent >= 1)
            {
                normalizedPercent = 1;
            }
            float scrollAmt = normalizedPercent * maxScroll;

            mTranslateAmt = -scrollAmt;// Math.Min(scrollAmt * mDrawDistanceBetweenXTicks, mMaxXValue * mDrawDistanceBetweenXTicks - this.Width);

            mTransformMat.Reset();
            mTransformMat.Translate(mTranslateAmt, 0);
        }
 public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
 {
     transform.Reset();
     if (firstTurn)
     {
         Move(initPos, toPoint);
     }
     else
     {
         Move(fromPoint, toPoint);
     }
     transform.Translate(curX - initPos.X, curY - initPos.Y);
     if (curX == toPoint.X)
     {
         curX = fromPoint.X + excess;
     }
     if (curY == toPoint.Y)
     {
         curY = fromPoint.Y + excess;
     }
 }
Beispiel #19
0
        /// <summary>
        /// 画像をピクチャボックスに合わせて表示するアフィン変換行列の計算(拡張メソッド)
        /// </summary>
        /// <param name="mat">アフィン変換行列</param>
        /// <param name="pic">描画先のピクチャボックス</param>
        /// <param name="bmp">描画するBitmapオブジェクト</param>
        public static void ZoomFit(this System.Drawing.Drawing2D.Matrix mat, PictureBox pic, Bitmap bmp)
        {
            if (bmp == null)
            {
                return;
            }

            // アフィン変換行列の初期化(単位行列へ)
            mat.Reset();

            // 0.5画素分移動
            mat.Translate(0.5f, 0.5f, System.Drawing.Drawing2D.MatrixOrder.Append);

            int srcWidth  = bmp.Width;
            int srcHeight = bmp.Height;
            int dstWidth  = pic.Width;
            int dstHeight = pic.Height;

            float scale;

            // 縦に合わせるか?横に合わせるか?
            if (srcHeight * dstWidth > dstHeight * srcWidth)
            {
                // ピクチャボックスの縦方法に画像表示を合わせる場合
                scale = dstHeight / (float)srcHeight;
                mat.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);
                // 中央へ平行移動
                mat.Translate((dstWidth - srcWidth * scale) / 2f, 0f, System.Drawing.Drawing2D.MatrixOrder.Append);
            }
            else
            {
                // ピクチャボックスの横方法に画像表示を合わせる場合
                scale = dstWidth / (float)srcWidth;
                mat.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);
                // 中央へ平行移動
                mat.Translate(0f, (dstHeight - srcHeight * scale) / 2f, System.Drawing.Drawing2D.MatrixOrder.Append);
            }
        }
Beispiel #20
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            if (fromX == toX)
            {
                curX = toX;
            }
            else if (toX > fromX)
            {
                curX += moveChangeValue;
                if (curX >= toX)
                {
                    curX = toX;
                }
            }
            else
            {
                curX -= moveChangeValue;
                if (curX <= toX)
                {
                    curX = toX;
                }
            }

            curAngle += rotationChangeValue;
            if (curAngle >= 360)
            {
                curAngle = 360;
            }

            transform.Reset();

            offsetX    = curX - fromX;
            curPivot.X = pivot.X + offsetX;
            transform.RotateAt(-curAngle, curPivot);
            transform.Translate(offsetX, 0);
        }
        /// <summary>
        /// Calculates the cumulative transform.
        /// </summary>
        /// <remarks>Once this method is executed, the <see cref="CumulativeTransform"/>
        /// property will reflect any changes in the transform parameters.</remarks>
        protected virtual void Calculate()
        {
            if (!this.RecalculationRequired)
            {
                return;
            }

            // The cumulative transform is the product of the transform of the
            // parent graphic and the transform of this graphic (i.e. the current transform)
            // If there is no parent graphic, then the cumulative transform = current transform
            if (_cumulativeTransform == null)
            {
                _cumulativeTransform = new Matrix();
            }

            _cumulativeTransform.Reset();

            IGraphic parentGraphic = this.OwnerGraphic.ParentGraphic;

            if (parentGraphic != null)
            {
                _cumulativeTransform.Multiply(parentGraphic.SpatialTransform.CumulativeTransform);
            }

            CalculatePreTransform(_cumulativeTransform);
            _cumulativeTransform.Multiply(this.Transform);
            CalculatePostTransform(_cumulativeTransform);

            this.RecalculationRequired = false;

            // Validate if there's a validation policy in place.  Otherwise, assume all is good.
            if (_validationPolicy != null)
            {
                _validationPolicy.Validate(this);
            }
        }
        /// <summary>
        /// Add a key point into this polyline link.
        /// </summary>
        /// <param name="x">X coordinate of the key point.</param>
        /// <param name="y">Y coordinate of the key point.</param>
        /// <param name="rgObjs">GOM object collection.</param>
        public void AddKeyPoint(float x, float y, GOM_Objects rgObjs)
        {
            if ( m_linkingStyle != GOM_Linking_Style.Polyline )
            {
                return;
            }

            System.Drawing.Drawing2D.Matrix	matrix;
            System.Drawing.PointF[]			rgPts, rgAllPts;
            System.Drawing.PointF			startPt, endPt;
            startPt	= StartPointInCanvas(rgObjs);
            endPt	= EndPointInCanvas(rgObjs);

            rgPts = new System.Drawing.PointF[2];
            rgAllPts = new System.Drawing.PointF[m_keyPts.Count+2];

            rgAllPts[0].X = startPt.X;
            rgAllPts[0].Y = startPt.Y;
            for(int i=0; i<m_keyPts.Count; i++)
            {
                rgAllPts[1+i].X = m_keyPts[i].x;
                rgAllPts[1+i].Y = m_keyPts[i].y;
            }
            rgAllPts[rgAllPts.Length-1].X = endPt.X;
            rgAllPts[rgAllPts.Length-1].Y = endPt.Y;

            for(int i=0; i<(rgAllPts.Length-1); i++)
            {
                rgPts[0].X = rgAllPts[i+1].X;
                rgPts[0].Y = rgAllPts[i+1].Y;
                rgPts[1].X = x;
                rgPts[1].Y = y;

                matrix = new System.Drawing.Drawing2D.Matrix();
                matrix.Translate(-rgAllPts[i].X, -rgAllPts[i].Y);
                matrix.TransformPoints(rgPts);

                float angle = (float)(System.Math.Atan2(rgAllPts[i+1].Y - rgAllPts[i].Y, rgAllPts[i+1].X - rgAllPts[i].X) / System.Math.PI) * 180;

                matrix.Reset();
                matrix.Rotate(-angle);
                matrix.TransformPoints(rgPts);

                if ((Math.Abs(rgPts[1].Y) < 2) && (-2 < rgPts[1].X) && (rgPts[1].X < rgPts[0].X + 2))
                {
                    GOM_Point point = new GOM_Point();
                    point.x = x;
                    point.y = y;
                    m_keyPts.Insert(i, point);
                    return;
                }
            }
        }
Beispiel #23
0
        public static byte[] GetCaptchaImage(string sCaptchaText, System.Drawing.Imaging.ImageFormat format)
        {
            int iHeight = 80;
            int iWidth  = 190;

            System.Random oRandom = new System.Random();

            int[] aBackgroundNoiseColor = new int[] { 150, 150, 150 };
            int[] aTextColor            = new int[] { 0, 0, 0 };
            int[] aFontEmSizes          = new int[] { 15, 20, 25, 30, 35 };

            string[] aFontNames = new string[]
            {
                "Comic Sans MS",
                "Arial",
                "Times New Roman",
                "Georgia",
                "Verdana",
                "Geneva"
            };

            System.Drawing.FontStyle[] aFontStyles = new System.Drawing.FontStyle[]
            {
                System.Drawing.FontStyle.Bold,
                System.Drawing.FontStyle.Italic,
                System.Drawing.FontStyle.Regular,
                System.Drawing.FontStyle.Strikeout,
                System.Drawing.FontStyle.Underline
            };

            System.Drawing.Drawing2D.HatchStyle[] aHatchStyles = new System.Drawing.Drawing2D.HatchStyle[]
            {
                System.Drawing.Drawing2D.HatchStyle.BackwardDiagonal
                , System.Drawing.Drawing2D.HatchStyle.Cross
                , System.Drawing.Drawing2D.HatchStyle.DashedDownwardDiagonal
                , System.Drawing.Drawing2D.HatchStyle.DashedHorizontal
                , System.Drawing.Drawing2D.HatchStyle.DashedUpwardDiagonal
                , System.Drawing.Drawing2D.HatchStyle.DashedVertical
                , System.Drawing.Drawing2D.HatchStyle.DiagonalBrick
                , System.Drawing.Drawing2D.HatchStyle.DiagonalCross
                , System.Drawing.Drawing2D.HatchStyle.Divot
                , System.Drawing.Drawing2D.HatchStyle.DottedDiamond
                , System.Drawing.Drawing2D.HatchStyle.DottedGrid
                , System.Drawing.Drawing2D.HatchStyle.ForwardDiagonal
                , System.Drawing.Drawing2D.HatchStyle.Horizontal
                , System.Drawing.Drawing2D.HatchStyle.HorizontalBrick
                , System.Drawing.Drawing2D.HatchStyle.LargeCheckerBoard
                , System.Drawing.Drawing2D.HatchStyle.LargeConfetti
                , System.Drawing.Drawing2D.HatchStyle.LargeGrid
                , System.Drawing.Drawing2D.HatchStyle.LightDownwardDiagonal
                , System.Drawing.Drawing2D.HatchStyle.LightHorizontal
                , System.Drawing.Drawing2D.HatchStyle.LightUpwardDiagonal
                , System.Drawing.Drawing2D.HatchStyle.LightVertical
                , System.Drawing.Drawing2D.HatchStyle.Max
                , System.Drawing.Drawing2D.HatchStyle.Min
                , System.Drawing.Drawing2D.HatchStyle.NarrowHorizontal
                , System.Drawing.Drawing2D.HatchStyle.NarrowVertical
                , System.Drawing.Drawing2D.HatchStyle.OutlinedDiamond
                , System.Drawing.Drawing2D.HatchStyle.Plaid
                , System.Drawing.Drawing2D.HatchStyle.Shingle
                , System.Drawing.Drawing2D.HatchStyle.SmallCheckerBoard
                , System.Drawing.Drawing2D.HatchStyle.SmallConfetti
                , System.Drawing.Drawing2D.HatchStyle.SmallGrid
                , System.Drawing.Drawing2D.HatchStyle.SolidDiamond
                , System.Drawing.Drawing2D.HatchStyle.Sphere
                , System.Drawing.Drawing2D.HatchStyle.Trellis
                , System.Drawing.Drawing2D.HatchStyle.Vertical
                , System.Drawing.Drawing2D.HatchStyle.Wave
                , System.Drawing.Drawing2D.HatchStyle.Weave
                , System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal
                , System.Drawing.Drawing2D.HatchStyle.WideUpwardDiagonal
                , System.Drawing.Drawing2D.HatchStyle.ZigZag
            };



            //Creates an output Bitmap
            System.Drawing.Bitmap oOutputBitmap = new System.Drawing.Bitmap(iWidth, iHeight
                                                                            , System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            System.Drawing.Graphics oGraphics = System.Drawing.Graphics.FromImage(oOutputBitmap);
            oGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            //Create a Drawing area
            System.Drawing.RectangleF oRectangleF =
                new System.Drawing.RectangleF(0, 0, iWidth, iHeight);
            System.Drawing.Brush oBrush = default(System.Drawing.Brush);


            //Draw background (Lighter colors RGB 100 to 255)
            oBrush = new System.Drawing.Drawing2D.HatchBrush(
                aHatchStyles[oRandom.Next(aHatchStyles.Length - 1)]
                , System.Drawing.Color.FromArgb
                (
                    oRandom.Next(100, 255)
                    , oRandom.Next(100, 255)
                    , oRandom.Next(100, 255)
                )
                , System.Drawing.Color.White
                );

            oGraphics.FillRectangle(oBrush, oRectangleF);

            System.Drawing.Drawing2D.Matrix oMatrix = new System.Drawing.Drawing2D.Matrix();
            int i = 0;

            for (i = 0; i <= sCaptchaText.Length - 1; i++)
            {
                oMatrix.Reset();
                int iChars = sCaptchaText.Length;
                int x      = iWidth / (iChars + 1) * i;
                int y      = iHeight / 2;

                //Rotate text Random
                oMatrix.RotateAt(oRandom.Next(-40, 40), new System.Drawing.PointF(x, y));
                oGraphics.Transform = oMatrix;

                //Draw the letters with Random Font Type, Size and Color
                oGraphics.DrawString
                (
                    //Text
                    sCaptchaText.Substring(i, 1),
                    //Random Font Name and Style
                    new System.Drawing.Font(aFontNames[oRandom.Next(aFontNames.Length - 1)],
                                            aFontEmSizes[oRandom.Next(aFontEmSizes.Length - 1)],
                                            aFontStyles[oRandom.Next(aFontStyles.Length - 1)]),
                    //Random Color (Darker colors RGB 0 to 100)
                    new System.Drawing.SolidBrush(
                        System.Drawing.Color.FromArgb(
                            oRandom.Next(0, 100)
                            , oRandom.Next(0, 100)
                            , oRandom.Next(0, 100)))
                    , x
                    , oRandom.Next(10, 40)
                );
                oGraphics.ResetTransform();
            }

            byte[] captchaBytes = null;

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                oOutputBitmap.Save(ms, format);
                captchaBytes = ms.ToArray();
            } // End Using ms

            return(captchaBytes);
        }
        public System.Drawing.PointF PointToObject(System.Drawing.PointF pt)
        {
            System.Drawing.Drawing2D.Matrix	matrix;
            System.Drawing.RectangleF		rc;
            System.Drawing.PointF[]			rgPts;

            rc = this.BoundingBox;

            rgPts = new System.Drawing.PointF[1];
            rgPts[0].X = pt.X;
            rgPts[0].Y = pt.Y;

            matrix = new System.Drawing.Drawing2D.Matrix();
            matrix.Translate(-this.xOffset, -this.yOffset);
            matrix.TransformPoints(rgPts);

            matrix.Reset();
            matrix.Translate(-(rc.Left + rc.Right) / 2, -(rc.Top + rc.Bottom) / 2);
            matrix.TransformPoints(rgPts);

            matrix.Reset();
            matrix.Rotate(-this.rotation);
            matrix.TransformPoints(rgPts);

            matrix.Reset();
            matrix.Translate((rc.Left + rc.Right) / 2, (rc.Top + rc.Bottom) / 2);
            matrix.TransformPoints(rgPts);

            return rgPts[0];
        }
Beispiel #25
0
        private void PictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            // 右ボタンがクリックされたとき
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                // アフィン変換行列に単位行列を設定する
                DrawMatrix.Reset();
                // 画像の描画
                DrawImage();

                return;
            }
            if (Tool == Tools.None)
            {
                // フォーカスの設定
                //(クリックしただけではMouseWheelイベントが有効にならない)
                pictureBox1.Focus();
                // マウスをクリックした位置の記録
                OldPoint.X = e.X;
                OldPoint.Y = e.Y;
                // マウスダウンフラグ
                IsMouseDown = true;
                return;
            }

            UndoStackPush();
            RedoStackClear();

            switch (Tool)
            {
            case Tools.Pencil:
                IsDrawing  = true;
                DrawStartX = e.X;
                DrawStartY = e.Y;
                break;

            case Tools.Eraser:
                IsDrawing  = true;
                DrawStartX = e.X;
                DrawStartY = e.Y;
                break;

            case Tools.Line:
                IsDrawing  = true;
                DrawStartX = e.X;
                DrawStartY = e.Y;
                Buffer     = new Bitmap(pictureBox1.Image);
                break;

            case Tools.Circle:
                IsDrawing  = true;
                DrawStartX = e.X;
                DrawStartY = e.Y;
                Buffer     = new Bitmap(pictureBox1.Image);
                break;

            case Tools.Square:
                IsDrawing  = true;
                DrawStartX = e.X;
                DrawStartY = e.Y;
                Buffer     = new Bitmap(pictureBox1.Image);
                break;

            case Tools.SquareFill:
                IsDrawing  = true;
                DrawStartX = e.X;
                DrawStartY = e.Y;
                Buffer     = new Bitmap(pictureBox1.Image);
                break;

            case Tools.Text:
                IsDrawing  = true;
                DrawStartX = e.X;
                DrawStartY = e.Y;
                break;
            }
        }
Beispiel #26
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string S = "";

            DA.GetData(0, ref S);
            string fontString = "";

            DA.GetData(1, ref fontString);
            bool close = false;

            DA.GetData(2, ref close);
            double size = 0.0;

            DA.GetData(3, ref size);
            double precision = 0.0;

            DA.GetData(4, ref precision);
            Plane basePlane = new Plane();

            DA.GetData(5, ref basePlane);
            int J = 0;

            DA.GetData(6, ref J);

            float fS         = size == 0 ? 1 : (float)size;
            Font  local_font = new Font(fontString, (float)fS);

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(S, local_font.FontFamily, (int)local_font.Style, local_font.Size, new PointF(0, 0), new StringFormat());

            System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); // transformation matrix
            matrix.Reset();                                                                 // build identity matrix

            // __________________ autoList part __________________

            // variable for the list
            Grasshopper.Kernel.Special.GH_ValueList vList;
            // tries to cast input as list
            try
            {
                // if the list is not the first parameter then change Input[6] to the corresponding value
                vList = Params.Input[6].Sources[0] as Grasshopper.Kernel.Special.GH_ValueList;

                // check if the list must be created

                if (!vList.NickName.Equals("Justification"))
                {
                    vList.ClearData();
                    vList.ListItems.Clear();
                    vList.NickName = "Justification";

                    for (int i = 0; i < justification.Length; i++)
                    {
                        vList.ListItems.Add(new Grasshopper.Kernel.Special.GH_ValueListItem(justification[i][0], justification[i][1]));
                    }

                    //var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("TopLeft", "0");
                    //var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("MiddleLeft", "1");
                    //var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("BottomLeft", "2");
                    //var item4 = new Grasshopper.Kernel.Special.GH_ValueListItem("TopCenter", "3");
                    //var item5 = new Grasshopper.Kernel.Special.GH_ValueListItem("MiddleCenter", "4");
                    //var item6 = new Grasshopper.Kernel.Special.GH_ValueListItem("BottomCenter", "5");
                    //var item7 = new Grasshopper.Kernel.Special.GH_ValueListItem("TopRight", "6");
                    //var item8 = new Grasshopper.Kernel.Special.GH_ValueListItem("MiddleRight", "7");
                    //var item9 = new Grasshopper.Kernel.Special.GH_ValueListItem("BottomRight", "8");
                    //vList.ListItems.Add(item1);
                    //vList.ListItems.Add(item2);
                    //vList.ListItems.Add(item3);
                    //vList.ListItems.Add(item4);
                    //vList.ListItems.Add(item5);
                    //vList.ListItems.Add(item6);
                    //vList.ListItems.Add(item7);
                    //vList.ListItems.Add(item8);
                    //vList.ListItems.Add(item9);

                    vList.ListItems[0].Value.CastTo(out J);
                }
            }
            catch
            {
                // handles anything that is not a value list
            }

            // ______________ text justification ______________

            RectangleF rec = path.GetBounds(); // bounding rectangle for text
            float      dX = Convert.ToSingle(rec.Width * -0.5), dY = Convert.ToSingle(rec.Height * 0.5);

            switch (J)
            {
            case 0:    // top left
                dX = 0;
                dY = fS;
                break;

            case 1:     // middle left
                dX = 0;
                dY = Convert.ToSingle((-rec.Height) * 0.5 + fS);
                break;

            case 2:      // bottom left
                dX = 0;
                dY = Convert.ToSingle(-rec.Height + fS * 0.5);
                break;

            case 3:     // top center
                dX = Convert.ToSingle(rec.Width * -0.5);
                dY = fS;
                break;

            case 4:     // middle center
                dX = Convert.ToSingle(rec.Width * -0.5);
                dY = Convert.ToSingle((-rec.Height) * 0.5 + fS);
                break;

            case 5:     // bottom center
                dX = Convert.ToSingle(rec.Width * -0.5);
                dY = Convert.ToSingle(-rec.Height + fS * 0.5);
                break;

            case 6:     // top right
                dX = Convert.ToSingle(rec.Width * -1);
                dY = fS;
                break;

            case 7:     // middle right
                dX = Convert.ToSingle(rec.Width * -1);
                dY = Convert.ToSingle((-rec.Height) * 0.5 + fS);
                break;

            case 8:     // bottom right
                dX = Convert.ToSingle(rec.Width * -1);
                dY = Convert.ToSingle(-rec.Height + fS * 0.5);
                break;
            }
            //float dX = Convert.ToSingle(rec.Width * -0.5);
            //float dY = Convert.ToSingle(rec.Height * 0.5);
            System.Drawing.Drawing2D.Matrix mTrans = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, dX, dY); // build transformation matrix
            path.Transform(mTrans);                                                                           // transform text path

            // ______________ convert to polylines ______________

            path.Flatten(matrix, (float)(size / precision)); // turns the path into a polyline that approximates the path

            PointF[]        pts     = path.PathPoints;       // get path points
            Byte[]          tps     = path.PathTypes;        // get path point types
            List <Polyline> strokes = new List <Polyline>(); // List for strokes
            Polyline        stroke  = new Polyline();

            Byte typ_start = Convert.ToByte(System.Drawing.Drawing2D.PathPointType.Start);// find start points condition

            // the conversion loop
            for (int i = 0; i < pts.Length; i++)
            {
                // if a start point is found, and the existing polyline is not null nor a single point,
                // add polyline to the strokes and create a new polyline
                if (tps[i] == typ_start)
                {
                    if (stroke != null && stroke.Count > 1)
                    {
                        if (close && !stroke.IsClosed)
                        {
                            stroke.Add(stroke[0]);                            // close polyline if necessary
                        }
                        strokes.Add(stroke);
                    }
                    stroke = new Polyline();
                }
                // in any other case add the next point to a polyline
                stroke.Add(pts[i].X, -pts[i].Y + size, 0);
                // add last stroke to the list
                if (i == pts.Length - 1)
                {
                    if (close && !stroke.IsClosed)
                    {
                        stroke.Add(stroke[0]);                            // and close it if necessary
                    }
                    strokes.Add(stroke);
                }
            }


            // ______________ align strokes to given plane ______________

            Transform align = Transform.PlaneToPlane(Plane.WorldXY, basePlane); // align transformation

            for (int j = 0; j < strokes.Count; j++)
            {
                strokes[j].Transform(align);
            }

            DA.SetDataList(0, strokes);
        }
Beispiel #27
0
        public override void ApplyTransformation(System.Drawing.Drawing2D.Matrix transform)
        {
            if (fromX == toX)
            {
                curX = toX;
                stepCount++;
                if (stepCount >= steps * 4)
                {
                    stepCount = 0;
                    isEnd     = true;
                }

                if (stepCount == steps * 2)///校正
                {
                    curScale = toScale;
                }
            }
            else if (toX > fromX)
            {
                curX += moveStepLength;
                if (curX >= toX)
                {
                    curX = toX;
                    if (reverse)
                    {
                        reverse = false;
                        isEnd   = true;
                    }
                    else
                    {
                        reverse  = true;
                        curScale = toScale;///校正
                    }
                    toX   = fromX;
                    fromX = curX;
                }
            }
            else
            {
                curX -= moveStepLength;
                if (curX <= toX)
                {
                    curX = toX;
                    if (reverse)
                    {
                        reverse = false;
                        isEnd   = true;
                    }
                    else
                    {
                        reverse  = true;
                        curScale = toScale;///校正
                    }
                    toX   = fromX;
                    fromX = curX;
                }
            }

            if (fromScale == toScale)
            {
                curScale = toScale;
            }
            else if (toScale > fromScale)
            {
                curScale += scaleStepLength;
                if (curScale >= toScale)
                {
                    curScale  = toScale;
                    toScale   = fromScale;
                    fromScale = curScale;
                }
            }
            else
            {
                curScale -= scaleStepLength;
                if (curScale <= toScale)
                {
                    curScale  = toScale;
                    toScale   = fromScale;
                    fromScale = curScale;
                }
            }


            transform.Reset();
            if (!isEnd)
            {
                offsetY = pivotY * curScale - pivotY;
                transform.Translate(curX - initX, -offsetY);
                transform.Scale(1, curScale);
            }
        }
Beispiel #28
0
 public PDFTransformationMatrix()
 {
     _matrix = new System.Drawing.Drawing2D.Matrix();
     _matrix.Reset();
 }
        /// <summary>
        /// Indicates whether a given point is on this link.
        /// </summary>
        /// <param name="x">X coordinate of the given point.</param>
        /// <param name="y">Y coordinate of the given point.</param>
        /// <param name="rgObjs">GOM object collection.</param>
        /// <returns>Whether a given point is on this link.</returns>
        public bool IsPointOnLink(float x, float y, GOM_Objects rgObjs)
        {
            switch (m_linkingStyle)
            {
                case GOM_Linking_Style.Line:
                {
                    System.Drawing.Drawing2D.Matrix	matrix;
                    System.Drawing.PointF[]			rgPts;
                    System.Drawing.PointF			startPt, endPt;

                    startPt	= StartPointInCanvas(rgObjs);
                    endPt	= EndPointInCanvas(rgObjs);

                    rgPts = new System.Drawing.PointF[2];
                    rgPts[0].X = endPt.X;
                    rgPts[0].Y = endPt.Y;
                    rgPts[1].X = x;
                    rgPts[1].Y = y;

                    matrix = new System.Drawing.Drawing2D.Matrix();
                    matrix.Translate(-startPt.X, -startPt.Y);
                    matrix.TransformPoints(rgPts);

                    float angle = (float)(System.Math.Atan2(endPt.Y - startPt.Y, endPt.X - startPt.X) / System.Math.PI) * 180;

                    matrix.Reset();
                    matrix.Rotate(-angle);
                    matrix.TransformPoints(rgPts);

                    if ((Math.Abs(rgPts[1].Y) < 2) && (-2 < rgPts[1].X) && (rgPts[1].X < rgPts[0].X + 2))
                    {
                        return true;
                    }

                    break;
                }
                case GOM_Linking_Style.Polyline:
                {
                    System.Drawing.Drawing2D.Matrix	matrix;
                    System.Drawing.PointF[]			rgPts, rgAllPts;
                    System.Drawing.PointF			startPt, endPt;
                    startPt	= StartPointInCanvas(rgObjs);
                    endPt	= EndPointInCanvas(rgObjs);

                    rgPts = new System.Drawing.PointF[2];
                    rgAllPts = new System.Drawing.PointF[m_keyPts.Count+2];

                    rgAllPts[0].X = startPt.X;
                    rgAllPts[0].Y = startPt.Y;
                    for(int i=0; i<m_keyPts.Count; i++)
                    {
                        rgAllPts[1+i].X = m_keyPts[i].x;
                        rgAllPts[1+i].Y = m_keyPts[i].y;
                    }
                    rgAllPts[rgAllPts.Length-1].X = endPt.X;
                    rgAllPts[rgAllPts.Length-1].Y = endPt.Y;

                    for(int i=0; i<(rgAllPts.Length-1); i++)
                    {
                        rgPts[0].X = rgAllPts[i+1].X;
                        rgPts[0].Y = rgAllPts[i+1].Y;
                        rgPts[1].X = x;
                        rgPts[1].Y = y;

                        matrix = new System.Drawing.Drawing2D.Matrix();
                        matrix.Translate(-rgAllPts[i].X, -rgAllPts[i].Y);
                        matrix.TransformPoints(rgPts);

                        float angle = (float)(System.Math.Atan2(rgAllPts[i+1].Y - rgAllPts[i].Y, rgAllPts[i+1].X - rgAllPts[i].X) / System.Math.PI) * 180;

                        matrix.Reset();
                        matrix.Rotate(-angle);
                        matrix.TransformPoints(rgPts);

                        if ((Math.Abs(rgPts[1].Y) < 2) && (-2 < rgPts[1].X) && (rgPts[1].X < rgPts[0].X + 2))
                        {
                            return true;
                        }
                    }

                    break;
                }
                case GOM_Linking_Style.Curve:
                {
                    break;
                }
                default:
                    System.Diagnostics.Debug.Assert(false, "Unknown link style.");
                    break;
            }

            return false;
        }