Example #1
0
 public static RatioEventArgs getInstance(HNStruct.HNRectRatio ratio)
 {
     return(new RatioEventArgs()
     {
         Ratio = ratio
     });
 }
Example #2
0
        public static HNStruct.HNRectRatio rotateRatio(HNStruct.HNRectRatio src, int angle)
        {
            HNStruct.HNRectRatio hnRectRatio = src;
            switch (angle)
            {
            case -270:
                hnRectRatio.l = 1f - src.b;
                hnRectRatio.t = src.l;
                hnRectRatio.r = 1f - src.t;
                hnRectRatio.b = src.r;
                break;

            case -180:
                hnRectRatio.l = 1f - src.r;
                hnRectRatio.t = 1f - src.b;
                hnRectRatio.r = 1f - src.l;
                hnRectRatio.b = 1f - src.t;
                break;

            case -90:
                hnRectRatio.l = src.t;
                hnRectRatio.t = 1f - src.r;
                hnRectRatio.r = src.b;
                hnRectRatio.b = 1f - src.l;
                break;

            case 90:
                hnRectRatio.t = src.l;
                hnRectRatio.r = 1f - src.t;
                hnRectRatio.b = src.r;
                hnRectRatio.l = 1f - src.b;
                break;

            case 180:
                hnRectRatio.r = 1f - src.l;
                hnRectRatio.b = 1f - src.t;
                hnRectRatio.l = 1f - src.r;
                hnRectRatio.t = 1f - src.b;
                break;

            case 270:
                hnRectRatio.b = 1f - src.l;
                hnRectRatio.l = src.t;
                hnRectRatio.t = 1f - src.r;
                hnRectRatio.r = src.b;
                break;
            }

            return(hnRectRatio);
        }
Example #3
0
        public static Rectangle rotateRatioRect(Rectangle src, HNStruct.HNRectRatio ratio, int angle)
        {
            Rectangle rectangle = src;

            switch (angle)
            {
            case 90:
                rectangle.X      = (int)Math.Round((double)src.X + (double)src.Width * (1.0 - (double)ratio.b));
                rectangle.Y      = (int)Math.Round((double)src.Y + (double)src.Height * (double)ratio.l);
                rectangle.Width  = (int)Math.Round((double)src.Width * ((double)ratio.r - (double)ratio.l));
                rectangle.Height = (int)Math.Round((double)src.Height * ((double)ratio.b - (double)ratio.t));
                break;

            case 180:
                rectangle.X      = (int)Math.Round((double)src.X + (double)src.Width * (1.0 - (double)ratio.r));
                rectangle.Y      = (int)Math.Round((double)src.Y + (double)src.Height * (1.0 - (double)ratio.b));
                rectangle.Width  = (int)Math.Round((double)src.Width * ((double)ratio.r - (double)ratio.l));
                rectangle.Height = (int)Math.Round((double)src.Height * ((double)ratio.b - (double)ratio.t));
                break;

            case 270:
                rectangle.X      = (int)Math.Round((double)src.X + (double)src.Width * (double)ratio.l);
                rectangle.Y      = (int)Math.Round((double)src.Y + (double)src.Height * (1.0 - (double)ratio.r));
                rectangle.Width  = (int)Math.Round((double)src.Width * ((double)ratio.r - (double)ratio.l));
                rectangle.Height = (int)Math.Round((double)src.Height * ((double)ratio.b - (double)ratio.t));
                break;

            default:
                rectangle.X      = (int)Math.Round((double)src.X + (double)src.Width * (double)ratio.l);
                rectangle.Y      = (int)Math.Round((double)src.Y + (double)src.Height * (double)ratio.t);
                rectangle.Width  = (int)Math.Round((double)src.Width * ((double)ratio.r - (double)ratio.l));
                rectangle.Height = (int)Math.Round((double)src.Height * ((double)ratio.b - (double)ratio.t));
                break;
            }

            return(rectangle);
        }
Example #4
0
        private static void onRectChanged(ref HNStruct.HNRectRatio rectRatio, MouseLocationType mouseType, float ratioX,
                                          float ratioY)
        {
            if (mouseType == MouseLocationType.INNER)
            {
                if ((double)rectRatio.l + (double)ratioX >= 0.0 && (double)rectRatio.r + (double)ratioX <= 1.0)
                {
                    rectRatio.l += ratioX;
                    rectRatio.r += ratioX;
                }

                if ((double)rectRatio.t + (double)ratioY >= 0.0 && (double)rectRatio.b + (double)ratioY <= 1.0)
                {
                    rectRatio.t += ratioY;
                    rectRatio.b += ratioY;
                }
            }
            else
            {
                if ((mouseType & MouseLocationType.LEFT) == MouseLocationType.LEFT && (double)ratioX != 0.0)
                {
                    if ((double)rectRatio.l + (double)ratioX < 0.0)
                    {
                        rectRatio.l = 0.0f;
                    }
                    else if ((double)rectRatio.l + (double)ratioX > (double)rectRatio.r)
                    {
                        rectRatio.l = rectRatio.r;
                    }
                    else
                    {
                        rectRatio.l += ratioX;
                    }
                }

                if ((mouseType & MouseLocationType.RIGHT) == MouseLocationType.RIGHT && (double)ratioX != 0.0)
                {
                    if ((double)rectRatio.r + (double)ratioX > 1.0)
                    {
                        rectRatio.r = 1f;
                    }
                    else if ((double)rectRatio.r + (double)ratioX < (double)rectRatio.l)
                    {
                        rectRatio.r = rectRatio.l;
                    }
                    else
                    {
                        rectRatio.r += ratioX;
                    }
                }

                if ((mouseType & MouseLocationType.TOP) == MouseLocationType.TOP && (double)ratioY != 0.0)
                {
                    if ((double)rectRatio.t + (double)ratioY < 0.0)
                    {
                        rectRatio.t = 0.0f;
                    }
                    else if ((double)rectRatio.t + (double)ratioY > (double)rectRatio.b)
                    {
                        rectRatio.t = rectRatio.b;
                    }
                    else
                    {
                        rectRatio.t += ratioY;
                    }
                }

                if ((mouseType & MouseLocationType.BOTTOM) == MouseLocationType.BOTTOM && (double)ratioY != 0.0)
                {
                    if ((double)rectRatio.b + (double)ratioY > 1.0)
                    {
                        rectRatio.b = 1f;
                    }
                    else if ((double)rectRatio.b + (double)ratioY < (double)rectRatio.t)
                    {
                        rectRatio.b = rectRatio.t;
                    }
                    else
                    {
                        rectRatio.b += ratioY;
                    }
                }
            }

            rectRatio.l = (float)Math.Round((double)rectRatio.l, 3);
            rectRatio.t = (float)Math.Round((double)rectRatio.t, 3);
            rectRatio.r = (float)Math.Round((double)rectRatio.r, 3);
            rectRatio.b = (float)Math.Round((double)rectRatio.b, 3);
        }