Esempio n. 1
0
 private void SwapTile(TileWindow wnd)
 {
     wnd.Selected  = true;
     Transfer.Dest = wnd.CurrentSelection();
     Transfer.Swap();
     Draw();
 }
Esempio n. 2
0
        private void layoutHandler(object sender, LayoutEventArgs e)
        {
            int totalH   = this.ClientSize.Height;
            int menuH    = this.menuStrip1.Height;
            int tileBoxW = this.ClientSize.Width / 2;

            var tbLayout = ToolBoxOrientation.None;

            TileWindow tbWnd = toolBox.CurrentWindow;

            if (tbWnd == inputWnd)
            {
                tbLayout = ToolBoxOrientation.Left;
            }
            else if (tbWnd == spriteWnd)
            {
                tbLayout = ToolBoxOrientation.Right;
            }

            inputWnd.UpdateLayout(0, tileBoxW, totalH, menuH);
            spriteWnd.UpdateLayout(tileBoxW, tileBoxW, totalH, menuH);

            toolBox.UpdateLayout(tbLayout, this.ClientSize);
            if (toolBox.IsActive && tbWnd != null)
            {
                int wndMaxH = totalH - (menuH + tbWnd.ScrollXHeight);
                tbWnd.ReduceWindowTo(wndMaxH - toolBox.Minimum.Height);
            }

            UpdateMinimumSize();

            inputWnd.UpdateBars();
            spriteWnd.UpdateBars();
            Draw();
        }
Esempio n. 3
0
        public static void Swap()
        {
            _completed = false;

            Tile cur = _obj as Tile;

            if (cur == null || _src == null || _dst == null)
            {
                return;
            }

            Tile other = _dst.Piece as Tile;

            if (other == null)
            {
                return;
            }

            TileWindow recver = _dst.Window;
            TileWindow sender = _src.Window;

            if (recver == null || sender == null)
            {
                return;
            }

            sender.ReceiveTile(other.Clone() as Tile, _src.Location);
            recver.ReceiveTile(cur, _dst.Location);

            _completed = true;
        }
Esempio n. 4
0
        public ToolBox(MainForm main, TileWindow initialWnd)
        {
            _wnd       = initialWnd;
            _refresh   = main.PerformLayout;
            _configure = main.ConfigureControls;

            _switch        = new ToolBoxButton(ToolBoxShapes.Switch, new Size(20, 140));
            _switch.Name   = "toolBoxSwitchWindow";
            _switch.Click += (s, e) => main.SwitchToolBoxWindow();

            _minimise        = new ToolBoxButton(ToolBoxShapes.Minimise, new Size(40, 21), 1);
            _minimise.Name   = "toolBoxMinimise";
            _minimise.Click += (s, e) => { Minimise(); Refresh(); };

            _ui = new Panel();
            _ui.Controls.Add(_switch);
            _ui.Controls.Add(_minimise);

            _tabButtons      = new Panel();
            _tabButtons.Size = new Size(0, 0);

            //_wnd.ProvideTabButtons(this);

            _ui.Controls.Add(_tabButtons);
            main.Controls.Add(_ui);

            _switch.Visible = false;

            IsActive = false;
            _isOpen  = true;
        }
Esempio n. 5
0
        public DragObject(TileWindow wnd, int x, int y)
        {
            _lastX = x;
            _lastY = y;

            _lastWnd = wnd;
            _orgWnd  = wnd;

            bool wasOob;

            _orgPos = _orgWnd.GetPosition(x, y, out wasOob);
            if (wasOob)
            {
                throw new ArgumentOutOfRangeException();
            }

            _selObj = _orgWnd.PieceAt(_orgPos);
            if (_selObj is Tile)
            {
                Bitmap img = _orgWnd.TileBitmap(_selObj as Tile);
                img  = img.SetAlpha(curAlpha).Scale(curScale);
                _cur = new Cursor(img.GetHicon());
            }

            _orgWnd.Cursor = new Selection(_selObj, _orgWnd, _orgPos);
            _orgWnd.AdoptCursor();
            Transfer.Source = _orgWnd.Cursor;
        }
Esempio n. 6
0
        public Selection Update(TileWindow wnd, int x, int y)
        {
            _lastX = x;
            _lastY = y;

            if (!_escaped && this.HasLeft(wnd))
            {
                Escape();
            }

            if (_selObj is Edge)
            {
                wnd = _orgWnd;
            }

            if (wnd != _lastWnd && _lastWnd != null)
            {
                _lastWnd.Cursor   = null;
                _lastWnd.Selected = false;
                _lastWnd.Draw();
            }

            _lastWnd = wnd;

            Selection sel = this.Current();

            if (_lastWnd != null)
            {
                _lastWnd.Cursor = sel;
            }

            return(sel);
        }
Esempio n. 7
0
        public void Activate(TileWindow wnd)
        {
            this.IsActive = true;
            _wnd          = wnd;
            Select(0);
            if (!_isOpen)
            {
                Minimise();
            }

            Refresh();
        }
Esempio n. 8
0
        public void PasteTile(TileWindow wnd)
        {
            wnd.Selected  = true;
            Transfer.Dest = wnd.CurrentSelection();
            Transfer.Paste();

            if (wnd == spriteWnd && Transfer.Completed)
            {
                toolBox.Switch = true;
            }

            Draw();
        }
Esempio n. 9
0
        private void mouseDownHandler(object sender, MouseEventArgs e)
        {
            if (_mouseHeld)
            {
                return;
            }

            var ctrl = sender as Control;

            if (ctrl is TabControl)
            {
                toolBox.RefreshTab();
                this.PerformLayout();
            }
            else if (_drag == null)
            {
                if (ctrl is PictureBox)
                {
                    this.ActiveControl = ctrl;
                }

                TileWindow wnd = null;
                if (inputWnd.WindowIs(ctrl))
                {
                    wnd = inputWnd;
                }
                else if (spriteWnd.WindowIs(ctrl))
                {
                    wnd = spriteWnd;
                }

                if (wnd != null)
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        StartDrag(wnd, e.X, e.Y);
                    }
                    else if (e.Button == MouseButtons.Right)
                    {
                        ShowMenuAt(wnd, e.X, e.Y);
                    }
                }
            }

            _mouseHeld = true;
            Draw();
        }
Esempio n. 10
0
        private bool HasLeft(TileWindow wnd)
        {
            if (wnd == null || wnd != _orgWnd)
            {
                return(true);
            }

            if (_selObj is Edge)
            {
                var dist = ((Edge)_selObj).Distance;
                return(dist.col != 0 || dist.row != 0);
            }

            bool     wasOob;
            Position loc = wnd.GetPosition(_lastX, _lastY, out wasOob);

            return(!wasOob && (loc.col != _orgPos.col || loc.row != _orgPos.row));
        }
Esempio n. 11
0
        public PaletteTab(MainForm main, SpriteWindow wnd)
        {
            _main = main;
            _wnd  = wnd;
            _id   = "paletteTab";
            _name = "Palette";

            _tabButton     = new ToolBoxButton(_name);
            _tabButton.Tag = this;

            _panel      = new Panel();
            _panel.Name = "palettePanel";

            _primary      = new PalettePanel(this, _wnd.Collage);
            _primary.Name = "primaryBox";

            _panel.Controls.Add(_primary);
        }
Esempio n. 12
0
        private void StartDrag(TileWindow wnd, int x, int y)
        {
            Transfer.Dest = null;

            try {
                _drag = new DragObject(wnd, x, y);
            }
            catch (ArgumentOutOfRangeException) {
                _drag = null;
                ClearSelection();
                SetSample(null);
            }

            if (_drag != null && wnd == inputWnd)
            {
                Tile t = _drag.Current().Piece as Tile;
                if (t != null)
                {
                    SetSample(t);
                }
            }
        }
Esempio n. 13
0
        public static void Paste()
        {
            _completed = false;

            if (_obj == null || _src == null || _dst == null || _dst.Window == null)
            {
                return;
            }

            TileWindow wnd = _dst.Window;
            Edge       e   = _obj as Edge;

            if (e != null)
            {
                _dst.Window.ResizeCollage(e);
            }
            else
            {
                _dst.Window.ReceiveTile(_obj as Tile);
                _completed = true;
            }
        }
Esempio n. 14
0
        private void ShowMenuAt(TileWindow wnd, int x, int y)
        {
            bool wasOob;

            wnd.Position = wnd.GetPosition(x, y, out wasOob);
            if (wasOob)
            {
                ClearSelection();
                SetSample(null);
                return;
            }

            if (wnd == inputWnd)
            {
                SetSample(inputWnd.PieceAt(inputWnd.Position) as Tile);
            }

            Transfer.Source = wnd.CurrentSelection();
            if (wnd.EdgeOf(wnd.Position) == EdgeKind.None)
            {
                wnd.ShowMenu(x, y);
            }
        }
Esempio n. 15
0
 public Selection(IPiece selObj, TileWindow wnd, Position loc)
 {
     _piece = selObj;
     _wnd   = wnd;
     _loc   = loc;
 }
Esempio n. 16
0
 public void CopyTile(TileWindow wnd)
 {
     wnd.Selected    = true;
     Transfer.Source = wnd.CurrentSelection();
     Transfer.Start();
 }
Esempio n. 17
0
        private void mouseMoveHandler(object sender, MouseEventArgs e)
        {
            var startCtrl = sender as Control;
            var curCtrl   = Utils.ApplyRecursiveControlFunc(this, FindControlWithMouse) as Control;

            TileWindow wnd = null;

            if (inputWnd.WindowIs(curCtrl))
            {
                wnd = inputWnd;
            }
            else if (spriteWnd.WindowIs(curCtrl))
            {
                wnd = spriteWnd;
            }

            int x = 0, y = 0;

            if (_drag != null && _drag.IsEdge)
            {
                x = e.X;
                y = e.Y;
            }
            else if (wnd != null)
            {
                // When the mouse is held, e.X and e.Y are relative to startCtrl.Location
                Point toCur = new Point(
                    curCtrl.Location.X - startCtrl.Location.X,
                    curCtrl.Location.Y - startCtrl.Location.Y
                    );

                x = e.X - toCur.X;
                y = e.Y - toCur.Y;
            }

            bool changed;

            if (_drag == null)
            {
                if (wnd == spriteWnd)
                {
                    changed = spriteWnd.HighlightEdgeAt(x, y);
                }
                else
                {
                    changed = spriteWnd.ClearMousedEdge();
                }
            }
            else
            {
                Selection sel = _drag.Update(wnd, x, y);

                if (Transfer.Dest == null)
                {
                    changed = sel != null;
                }
                else
                {
                    changed = !Transfer.Dest.Equals(sel);
                }

                Transfer.Dest = sel;
            }

            if (wnd != null && changed)
            {
                wnd.Draw();
            }
        }