Example #1
0
        public OgmoWindow(HorizontalSnap startHSnap, VerticalSnap startVSnap)
        {
            this.startHSnap = startHSnap;
            this.startVSnap = startVSnap;
            InitializeComponent();

            userVisible = true;
            editorVisible = false;

            //Events
            Shown += onShown;
            Resize += enforceSnap;
            Move += checkSnap;
            if (Ogmo.MainWindow != null)
            {
                Ogmo.MainWindow.Resize += enforceSnap;
                Ogmo.MainWindow.LocationChanged += enforceSnap;
                Ogmo.MainWindow.KeyDown += onKeyDown;
            }
            KeyDown += onKeyDown;
            if (Ogmo.MainWindow != null)
            {
                Ogmo.OnProjectClose += onProjectClose;
                Ogmo.OnLevelClosed += onLevelClose;
                Ogmo.OnLevelChanged += new Ogmo.LevelCallback(Ogmo_OnLevelChanged);
            }
        }
Example #2
0
        public OgmoWindow(HorizontalSnap startHSnap, VerticalSnap startVSnap)
        {
            this.startHSnap = startHSnap;
            this.startVSnap = startVSnap;
            InitializeComponent();

            userVisible   = true;
            editorVisible = false;

            //Events
            Shown  += onShown;
            Resize += enforceSnap;
            Move   += checkSnap;
            Ogmo.MainWindow.Resize          += enforceSnap;
            Ogmo.MainWindow.LocationChanged += enforceSnap;
            Ogmo.MainWindow.KeyDown         += onKeyDown;
            KeyDown             += onKeyDown;
            Ogmo.OnProjectClose += onProjectClose;
            Ogmo.OnLevelClosed  += onLevelClose;
            Ogmo.OnLevelChanged += new Ogmo.LevelCallback(Ogmo_OnLevelChanged);
        }
Example #3
0
        /*
         *  Snapping to edges helpers
         */
        private void checkSnap(object sender = null, EventArgs e = null)
        {
            Rectangle r = Ogmo.MainWindow.EditBounds;
            Point     p = Location;

            //Check for X snap
            if (Math.Abs(p.X - r.X) <= SNAP_RANGE)
            {
                hSnap = HorizontalSnap.Left;
                p.X   = r.X;
            }
            else if (Math.Abs((p.X + Width) - (r.X + r.Width)) <= SNAP_RANGE)
            {
                hSnap = HorizontalSnap.Right;
                p.X   = r.X + r.Width - Width;
            }
            else
            {
                hSnap = HorizontalSnap.None;
            }

            //Check for Y snap
            if (Math.Abs(p.Y - r.Y) <= SNAP_RANGE)
            {
                vSnap = VerticalSnap.Top;
                p.Y   = r.Y;
            }
            else if (Math.Abs((p.Y + Height) - (r.Y + r.Height)) <= SNAP_RANGE)
            {
                vSnap = VerticalSnap.Bottom;
                p.Y   = r.Y + r.Height - Height;
            }
            else
            {
                vSnap = VerticalSnap.None;
            }

            Location = p;
        }
Example #4
0
 private void onShown(object sender, EventArgs e)
 {
     hSnap = startHSnap;
     vSnap = startVSnap;
     enforceSnap();
 }
Example #5
0
 private void onShown(object sender, EventArgs e)
 {
     hSnap = startHSnap;
     vSnap = startVSnap;
     enforceSnap();
 }
Example #6
0
        /*
         *  Snapping to edges helpers
         */
        private void checkSnap(object sender = null, EventArgs e = null)
        {
            if (Ogmo.MainWindow == null)
                return;

            Rectangle r = Ogmo.MainWindow.EditBounds;
            Point p = Location;

            //Check for X snap
            if (Math.Abs(p.X - r.X) <= SNAP_RANGE)
            {
                hSnap = HorizontalSnap.Left;
                p.X = r.X;
            }
            else if (Math.Abs((p.X + Width) - (r.X + r.Width)) <= SNAP_RANGE)
            {
                hSnap = HorizontalSnap.Right;
                p.X = r.X + r.Width - Width;
            }
            else
                hSnap = HorizontalSnap.None;

            //Check for Y snap
            if (Math.Abs(p.Y - r.Y) <= SNAP_RANGE)
            {
                vSnap = VerticalSnap.Top;
                p.Y = r.Y;
            }
            else if (Math.Abs((p.Y + Height) - (r.Y + r.Height)) <= SNAP_RANGE)
            {
                vSnap = VerticalSnap.Bottom;
                p.Y = r.Y + r.Height - Height;
            }
            else
                vSnap = VerticalSnap.None;

            Location = p;
        }