Exemplo n.º 1
0
        public CONTROL_POSITION GetControlPositon(REGION_CONTROL_STYLES ControlStyle)
        {
            switch (ControlStyle)
            {
            case REGION_CONTROL_STYLES.TL: return(CONTROL_POSITION.TL);

            case REGION_CONTROL_STYLES.TR: return(CONTROL_POSITION.TR);

            case REGION_CONTROL_STYLES.BR: return(CONTROL_POSITION.BR);

            case REGION_CONTROL_STYLES.BL: return(CONTROL_POSITION.BL);

            case REGION_CONTROL_STYLES.TC: return(CONTROL_POSITION.TC);

            case REGION_CONTROL_STYLES.MR: return(CONTROL_POSITION.MR);

            case REGION_CONTROL_STYLES.BC: return(CONTROL_POSITION.BC);

            case REGION_CONTROL_STYLES.ML: return(CONTROL_POSITION.ML);

            case REGION_CONTROL_STYLES.MC: return(CONTROL_POSITION.MC);

            case REGION_CONTROL_STYLES.TT: return(CONTROL_POSITION.TT);
            }
            return(CONTROL_POSITION.MC);
        }
Exemplo n.º 2
0
        public REGION_CONTROL_STYLES HitTest(float fX, float fY, float fSpaces, Keys nFlags)
        {
            PointF[] cp = GetCP();
            REGION_CONTROL_STYLES SelectRCS = REGION_CONTROL_STYLES.NONE;

            for (int n = 0; n < (int)CONTROL_POSITION.MAX; n++)
            {
                float ax = fSpaces - Math.Abs(cp[n].X - fX);                 // fZoomX
                float ay = fSpaces - Math.Abs(cp[n].Y - fY);                 // fZoomY
                if (ax > 0 && ay > 0)
                {
                    SelectRCS = (REGION_CONTROL_STYLES)(1 << n);
                    if ((m_RCS & SelectRCS) != 0 || nFlags == Keys.Alt)
                    {
                        if (SelectRCS != REGION_CONTROL_STYLES.NONE)
                        {
                            break;
                        }
                    }
                    else
                    {
                        SelectRCS = REGION_CONTROL_STYLES.NONE;
                    }
                }
            }

            if (SelectRCS != REGION_CONTROL_STYLES.NONE)
            {
                bHitOn = true;
            }
            return(SelectRCS);
        }
Exemplo n.º 3
0
 private void InitRegion()
 {
     m_fSpaces      = 5.0f;
     m_cBorderColor = Color.Blue;
     m_RCS          = REGION_CONTROL_STYLES.ALL;
     m_SelectRCS    = REGION_CONTROL_STYLES.NONE;
     m_dBorderStyle = DashStyle.Solid;
     m_cFillImage   = null;
 }
Exemplo n.º 4
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if ((e.Button & MouseButtons.Left) != 0)
            {
                PointF point = new PointF(e.X - m_pOrigin.X, e.Y - m_pOrigin.Y);
                switch (m_eControlMode)
                {
                case E_VIEW_CONTROL_MODE.VCM_POINT:
                {
                    if (ModifierKeys == Keys.Alt)
                    {
                        REGION_CONTROL_STYLES HitRCS = REGION_CONTROL_STYLES.NONE;
                        XRegion xRegion = (XRegion)m_xOverlay.First();
                        for (int n = 0; n < m_xOverlay.Count; n++)
                        {
                            if (xRegion != null)
                            {
                                HitRCS = xRegion.HitTest(point.X / m_fZ, point.Y / m_fZ, xRegion.Spaces / m_fZ, ModifierKeys);
                                if (HitRCS != REGION_CONTROL_STYLES.NONE)
                                {
                                    if (m_xActiveRegion != null && xRegion != null && m_xActiveRegion != xRegion)
                                    {
                                        m_xActiveRegion.SetAlign(xRegion, HitRCS);
                                        break;
                                    }
                                }
                                else
                                {
                                    xRegion.SetAlign(null, HitRCS);
                                }
                                xRegion = (XRegion)m_xOverlay.Next();
                            }
                        }
                    }
                    else if (m_xSelectRegion.ControlSelect == REGION_CONTROL_STYLES.BR)
                    {
                        SelectControl();
                        m_xSelectRegion.ControlSelect = REGION_CONTROL_STYLES.NONE;
                        Refresh();
                    }
                    if (m_bMouseMove == true)
                    {
                        m_bMouseMove = false;
                        Refresh();
                    }
                    InvokeOnClick(this, null);
                } break;

                case E_VIEW_CONTROL_MODE.VCM_PAN:
                {
                    m_pOrigin.X = e.X - m_pStartPan.X;
                    m_pOrigin.Y = e.Y - m_pStartPan.Y;
                    Refresh();
                } break;
                }
            }
        }
Exemplo n.º 5
0
 public XRegion()
 {
     bHitOn           = false;
     m_ObjectAlignRCS = REGION_CONTROL_STYLES.NONE;
     m_fSpaces        = 5.0f;
     m_cBorderColor   = Color.Blue;
     m_RCS            = REGION_CONTROL_STYLES.ALL;
     m_SelectRCS      = REGION_CONTROL_STYLES.NONE;
     m_dBorderStyle   = DashStyle.Solid;
     m_cFillImage     = null;
 }
Exemplo n.º 6
0
        private void Set(XRegion xRegion)
        {
            base.Set(xRegion);

            m_cBorderColor = xRegion.BorderColor;
            m_cFillColor   = xRegion.FillColor;
            m_cFillImage   = new Bitmap(xRegion.FillImage);
            m_dBorderStyle = xRegion.BorderStyle;
            m_RCS          = xRegion.ControlStyle;
            m_SelectRCS    = xRegion.ControlSelect;
            m_sCaption     = xRegion.Caption;
        }
Exemplo n.º 7
0
 public void SetAlign(XRegion TargetRegion, REGION_CONTROL_STYLES AlignTargetStyles)
 {
     if ((m_RCS & AlignTargetStyles) != 0)
     {
         if (TargetRegion.m_RegionAlign.TargetRegion != this)
         {
             m_RegionAlign.SetAlign(TargetRegion, GetControlPositon(AlignTargetStyles), GetControlPositon(m_ObjectAlignRCS));
             Align();
         }
     }
     else
     {
         m_RegionAlign.SetAlign(null, CONTROL_POSITION.TT, CONTROL_POSITION.TT);
     }
 }
Exemplo n.º 8
0
        public REGION_CONTROL_STYLES SelectControl(float fX, float fY, float fSpaces, Keys nFlags)
        {
            REGION_CONTROL_STYLES RetRCS = HitTest(fX, fY, fSpaces, nFlags);

            if (RetRCS == REGION_CONTROL_STYLES.NONE)
            {
                RetRCS = HitTestBolder(fX, fY, fSpaces, nFlags);
            }

            m_SelectRCS = RetRCS;
            PointF[] cp = GetCP();
            float    x  = p[0];
            float    y  = p[1];
            float    w  = p[2];
            float    h  = p[3];
            double   t  = p[4];

            if (nFlags == Keys.Alt)
            {
                if (m_SelectRCS != REGION_CONTROL_STYLES.NONE)
                {
                    fix.X = x - fX;
                    fix.Y = y - fY;
                    if ((m_SelectRCS & m_RCS) != 0)
                    {
                        m_ObjectAlignRCS           = m_SelectRCS;
                        m_RegionAlign.TargetRegion = null;
                        m_SelectRCS = REGION_CONTROL_STYLES.MC;
                    }
                    else
                    {
                        m_ObjectAlignRCS = REGION_CONTROL_STYLES.NONE;
                    }
                }
            }
            else
            {
                switch (m_SelectRCS)
                {
                case REGION_CONTROL_STYLES.TL:
                    fix = cp[(int)CONTROL_POSITION.BR]; break;

                case REGION_CONTROL_STYLES.TR:
                    fix = cp[(int)CONTROL_POSITION.BL]; break;

                case REGION_CONTROL_STYLES.BR:
                    fix = cp[(int)CONTROL_POSITION.TL]; break;

                case REGION_CONTROL_STYLES.BL:
                    fix = cp[(int)CONTROL_POSITION.TR]; break;

                case REGION_CONTROL_STYLES.TC:
                    fix = cp[(int)CONTROL_POSITION.BC]; break;

                case REGION_CONTROL_STYLES.MR:
                    fix = cp[(int)CONTROL_POSITION.ML]; break;

                case REGION_CONTROL_STYLES.BC:
                    fix = cp[(int)CONTROL_POSITION.TC]; break;

                case REGION_CONTROL_STYLES.ML:
                    fix = cp[(int)CONTROL_POSITION.MR]; break;

                case REGION_CONTROL_STYLES.MC:
                case REGION_CONTROL_STYLES.TT:
                    fix.X = 0;
                    fix.Y = 0;
                    break;
                }

                if ((m_RCS & REGION_CONTROL_STYLES.ALL) != 0 && m_SelectRCS == REGION_CONTROL_STYLES.NONE)
                {
                    double dx = fX - x;
                    double dy = fY - y;
                    double dw = dx * Math.Cos(-t) + dy * Math.Sin(-t);
                    double dh = -dx *Math.Sin(-t) + dy * Math.Cos(-t);

                    if ((w - Math.Abs(dw)) > 0 && (h - Math.Abs(dh)) > 0)
                    {
                        if (m_eRShape == SHAPE.ELLIPSE)
                        {
                            if (dx != 0 && dy != 0)
                            {
                                double dt = Math.Atan(dy / dx);
                                double l  = Math.Sqrt(w * w + h * h);
                                double tx = l * Math.Cos(dt);
                                double ty = l * Math.Sin(dt);

                                if ((dx * dx) <= (tx * tx) && (dy * dy) <= (ty * ty))
                                {
                                    fix.X       = x - fX;
                                    fix.Y       = y - fY;
                                    m_SelectRCS = REGION_CONTROL_STYLES.ALL;
                                }
                            }
                            else
                            {
                                fix.X       = x - fX;
                                fix.Y       = y - fY;
                                m_SelectRCS = REGION_CONTROL_STYLES.ALL;
                            }
                        }
                        else
                        {
                            fix.X       = x - fX;
                            fix.Y       = y - fY;
                            m_SelectRCS = REGION_CONTROL_STYLES.ALL;
                        }
                    }
                }
            }
            return(RetRCS);
        }
Exemplo n.º 9
0
        public REGION_CONTROL_STYLES HitTestBolder(float fX, float fY, float fSpaces, Keys nFlags)        //Graphics gp, float fOx, float fOy, float fZoomX, float fZoomY)
        {
            REGION_CONTROL_STYLES SelectRCS = REGION_CONTROL_STYLES.NONE;

            PointF[] dp = GetCP();
            float    x  = p[0];
            float    y  = p[1];
            float    w  = p[2];
            float    h  = p[3];
            double   t  = p[4];

            switch (RegionShape)
            {
            case SHAPE.CLOSE:
            {
            } break;

            case SHAPE.ELLIPSE:
            {
                double nt   = 0;
                double cost = Math.Cos(t);
                double sint = Math.Sin(t);
                for (long n = 0; n < 6284; n++)
                {
                    nt += 0.001;
                    double tx    = w * Math.Cos(nt);
                    double ty    = h * Math.Sin(nt);
                    float  drawX = (float)(x + tx * cost + ty * sint);
                    float  drawY = (float)(y - tx * sint + ty * cost);

                    if (Math.Abs(fX - drawX) < fSpaces && Math.Abs(fY - drawY) < fSpaces)
                    {
                        SelectRCS = REGION_CONTROL_STYLES.SELECT;
                        break;
                    }
                }
            } break;

            case SHAPE.RECTANGLE:
            default:
            {
                PointF[] pDraw = new PointF[5];
                for (int n = 0; n < 4; n++)
                {
                    pDraw[n].X = dp[n].X;
                    pDraw[n].Y = dp[n].Y;
                }
                pDraw[4] = pDraw[0];

                for (int n = 0; n < 4; n++)
                {
                    float Lx = pDraw[n].X - pDraw[n + 1].X;
                    float Ly = pDraw[n].Y - pDraw[n + 1].Y;

                    float Fx = pDraw[n].X - fX;
                    float Fy = pDraw[n].Y - fY;

                    if (Lx == 0 && Math.Abs(Fx) < fSpaces)
                    {
                        if ((pDraw[n].Y < fY && fY < pDraw[n + 1].Y) || (pDraw[n + 1].Y < fY && fY < pDraw[n].Y))
                        {
                            SelectRCS = REGION_CONTROL_STYLES.SELECT;
                            break;
                        }
                    }
                    else if (Ly == 0 && Math.Abs(Fy) < fSpaces)
                    {
                        if ((pDraw[n].X < fX && fX < pDraw[n + 1].X) || (pDraw[n + 1].X < fX && fX < pDraw[n].X))
                        {
                            SelectRCS = REGION_CONTROL_STYLES.SELECT;
                            break;
                        }
                    }
                    else
                    {
                        if (Math.Abs((Ly / Lx) * Fx - Fy) < fSpaces)
                        {
                            SelectRCS = REGION_CONTROL_STYLES.SELECT;
                            break;
                        }
                    }
                }
            } break;
            }

            if (SelectRCS != REGION_CONTROL_STYLES.NONE)
            {
                bHitOn = true;
            }
            return(SelectRCS);
        }
Exemplo n.º 10
0
        public void Control(float _x, float _y, float fZoomX, float fZoomY)
        {
            if (fZoomX == 0 || fZoomY == 0)
            {
                return;
            }

            float fX = _x / fZoomX;
            float fY = _y / fZoomY;
            float dw = fX - fix.X;
            float dh = fY - fix.Y;

            REGION_CONTROL_STYLES ControlRCS = m_SelectRCS & m_RCS;

            double t = p[4];

            switch (ControlRCS)
            {
            case REGION_CONTROL_STYLES.MC:
            {
                p[0] = fix.X + fX;
                p[1] = fix.Y + fY;
            } break;

            case REGION_CONTROL_STYLES.TT:
            {
                double dx = fX - p[0];
                double dy = p[1] - fY;
                p[4] = (float)Math.Atan(dy / dx);
                if (dx < 0)
                {
                    p[4] = (float)(Math.PI + p[4]);
                }
                if (t < 0)
                {
                    p[4] = (float)(2.0 * Math.PI + p[4]);
                }
            } break;


            case REGION_CONTROL_STYLES.TC:
            {
                p[3] = (float)Math.Abs(-dw * Math.Sin(-t) + dh * Math.Cos(-t)) / 2.0f;
                p[0] = fix.X - p[3] * (float)Math.Sin(t);
                p[1] = fix.Y - p[3] * (float)Math.Cos(t);
            } break;

            case REGION_CONTROL_STYLES.BC:
            {
                p[3] = (float)Math.Abs(-dw * Math.Sin(-t) + dh * Math.Cos(-t)) / 2.0f;
                p[0] = fix.X + p[3] * (float)Math.Sin(t);
                p[1] = fix.Y + p[3] * (float)Math.Cos(t);
            } break;

            case REGION_CONTROL_STYLES.ML:
            {
                p[2] = (float)Math.Abs(dw * Math.Cos(-t) + dh * Math.Sin(-t)) / 2.0f;
                p[0] = fix.X - p[2] * (float)Math.Cos(t);
                p[1] = fix.Y + p[2] * (float)Math.Sin(t);
            } break;

            case REGION_CONTROL_STYLES.MR:
            {
                p[2] = (float)Math.Abs(dw * Math.Cos(-t) + dh * Math.Sin(-t)) / 2.0f;
                p[0] = fix.X + p[2] * (float)Math.Cos(t);
                p[1] = fix.Y - p[2] * (float)Math.Sin(t);
            } break;

            case REGION_CONTROL_STYLES.TL:
            case REGION_CONTROL_STYLES.TR:
            case REGION_CONTROL_STYLES.BL:
            case REGION_CONTROL_STYLES.BR:
            {
                p[0] = (fix.X + fX) / 2.0f;
                p[1] = (fix.Y + fY) / 2.0f;
                p[2] = (float)Math.Abs(dw * Math.Cos(-t) + dh * Math.Sin(-t)) / 2.0f;
                p[3] = (float)Math.Abs(-dw * Math.Sin(-t) + dh * Math.Cos(-t)) / 2.0f;
                if (m_eRShape == SHAPE.ELLIPSE)
                {
                    dw = (float)(dw * Math.Cos(Math.PI / 4));
                    dh = (float)(dh * Math.Sin(Math.PI / 4));

                    p[2] = (float)Math.Abs(dw * Math.Cos(-t) + dh * Math.Sin(-t));
                    p[3] = (float)Math.Abs(-dw * Math.Sin(-t) + dh * Math.Cos(-t));
                }
            } break;
            }
        }