示例#1
0
        private void ResizeAllGUIs(Size oldResolution, Size newResolution)
        {
            int oldWidth  = oldResolution.Width;
            int oldHeight = oldResolution.Height;
            int newWidth  = newResolution.Width;
            int newHeight = newResolution.Height;

            foreach (GUI gui in Factory.AGSEditor.CurrentGame.RootGUIFolder.AllItemsFlat)
            {
                NormalGUI theGui = gui as NormalGUI;
                if (theGui != null)
                {
                    theGui.Width  = Math.Max((theGui.Width * newWidth) / oldWidth, 1);
                    theGui.Height = Math.Max((theGui.Height * newHeight) / oldHeight, 1);
                    theGui.Left   = (theGui.Left * newWidth) / oldWidth;
                    theGui.Top    = (theGui.Top * newHeight) / oldHeight;

                    foreach (GUIControl control in theGui.Controls)
                    {
                        control.Width  = Math.Max((control.Width * newWidth) / oldWidth, 1);
                        control.Height = Math.Max((control.Height * newHeight) / oldHeight, 1);
                        control.Left   = (control.Left * newWidth) / oldWidth;
                        control.Top    = (control.Top * newHeight) / oldHeight;
                    }
                }
            }
        }
示例#2
0
        private void ResizeAllGUIs(GameResolutions oldResolution, GameResolutions newResolution)
        {
            int oldWidth  = AGS.Types.Utilities.GetGameResolutionWidth(oldResolution);
            int oldHeight = AGS.Types.Utilities.GetGameResolutionHeight(oldResolution);
            int newWidth  = AGS.Types.Utilities.GetGameResolutionWidth(newResolution);
            int newHeight = AGS.Types.Utilities.GetGameResolutionHeight(newResolution);

            foreach (GUI gui in Factory.AGSEditor.CurrentGame.RootGUIFolder.AllItemsFlat)
            {
                NormalGUI theGui = gui as NormalGUI;
                if (theGui != null)
                {
                    theGui.Width  = Math.Max((theGui.Width * newWidth) / oldWidth, 1);
                    theGui.Height = Math.Max((theGui.Height * newHeight) / oldHeight, 1);
                    theGui.Left   = (theGui.Left * newWidth) / oldWidth;
                    theGui.Top    = (theGui.Top * newHeight) / oldHeight;

                    foreach (GUIControl control in theGui.Controls)
                    {
                        control.Width  = Math.Max((control.Width * newWidth) / oldWidth, 1);
                        control.Height = Math.Max((control.Height * newHeight) / oldHeight, 1);
                        control.Left   = (control.Left * newWidth) / oldWidth;
                        control.Top    = (control.Top * newHeight) / oldHeight;
                    }
                }
            }
        }
示例#3
0
        private void MoveControlWithMouse(int mouseX, int mouseY)
        {
            NormalGUI normalGui = (NormalGUI)_gui;

            //int _changex = (mouseX - _mouseXOffset) - _selectedControl.Left;
            //int _changey = (mouseY - _mouseYOffset) - _selectedControl.Top;
            int[] _diffx = new int[_selected.Count];
            int[] _diffy = new int[_selected.Count];
            for (int i = 0; i < _selected.Count; i++)
            {
                _diffx[i] = _selected[i].Left - _selectedControl.Left;
                _diffy[i] = _selected[i].Top - _selectedControl.Top;
            }

            _selectedControl.Left = mouseX - _mouseXOffset;
            _selectedControl.Top  = mouseY - _mouseYOffset;



            if (_selectedControl.Left >= normalGui.Width)
            {
                _selectedControl.Left = normalGui.Width - 1;
            }
            if (_selectedControl.Top >= normalGui.Height)
            {
                _selectedControl.Top = normalGui.Height - 1;
            }

            _snappedx = -1;
            _snappedy = -1;
            if (!Utilities.IsControlPressed())
            {
                foreach (GUIControl _gc in normalGui.Controls)
                {
                    if (_gc != _selectedControl && !_selected.Contains(_gc))
                    {
                        if (Math.Abs(_selectedControl.Left - _gc.Left) < 5)
                        {
                            _selectedControl.Left = _gc.Left;
                            _snappedx             = _gc.Left;
                        }
                        if (Math.Abs(_selectedControl.Top - _gc.Top) < 5)
                        {
                            _selectedControl.Top = _gc.Top;
                            _snappedy            = _gc.Top;
                        }
                    }
                }
            }

            for (int i = 0; i < _selected.Count; i++)
            {
                if (!_selected[i].Locked)
                {
                    _selected[i].Left = _diffx[i] + _selectedControl.Left;
                    _selected[i].Top  = _diffy[i] + _selectedControl.Top;
                }
            }

            bgPanel.Invalidate();
        }
示例#4
0
        private void bgPanel_Paint(object sender, PaintEventArgs e)
        {
            if (_gui != null)
            {
                _state.UpdateScroll(bgPanel.AutoScrollPosition);

                e.Graphics.SetClip(new Rectangle(0, 0, _state.GUISizeToWindow(_gui.EditorWidth), _state.GUISizeToWindow(_gui.EditorHeight)));

                int drawOffsX = _state.GUIXToWindow(0);
                int drawOffsY = _state.GUIYToWindow(0);

                IntPtr hdc = e.Graphics.GetHdc();
                //Factory.NativeProxy.DrawGUI(hdc, 0, 0, _gui, _state.ScaleFactor, (_selectedControl == null) ? -1 : _selectedControl.ID);
                Factory.NativeProxy.DrawGUI(hdc, drawOffsX, drawOffsY, _gui, Factory.AGSEditor.CurrentGame.GUIScaleFactor, _state.Scale, -1);
                e.Graphics.ReleaseHdc(hdc);

                if (_addingControl)
                {
                    DrawSelectionRectangle(e.Graphics);
                }

                if (_drawingSelectionBox)
                {
                    Rectangle _rectToDraw = new Rectangle(_state.GUIXToWindow(_selectionRect.X),
                                                          _state.GUIYToWindow(_selectionRect.Y),
                                                          _state.GUISizeToWindow(_selectionRect.Width),
                                                          _state.GUISizeToWindow(_selectionRect.Height));

                    e.Graphics.DrawRectangle(_drawRectanglePen, _rectToDraw);
                }
                //draw selection handles
                if (_selected.Count > 0)
                {
                    foreach (GUIControl _gc in _selected)
                    {
                        Rectangle _topleft     = new Rectangle(_state.GUIXToWindow(_gc.Left), _state.GUIYToWindow(_gc.Top), 2, 2);
                        Rectangle _topright    = new Rectangle(_state.GUIXToWindow(_gc.Left + _gc.Width - 1), _state.GUIYToWindow(_gc.Top), 2, 2);
                        Rectangle _bottomleft  = new Rectangle(_state.GUIXToWindow(_gc.Left), _state.GUIYToWindow(_gc.Top + _gc.Height - 1), 2, 2);
                        Rectangle _bottomright = new Rectangle(_state.GUIXToWindow(_gc.Left + _gc.Width - 1), _state.GUIYToWindow(_gc.Top + _gc.Height - 1), 2, 2);
                        Pen       _pen;
                        if (_gc == _selectedControl)
                        {
                            _pen = _drawSelectedPen;
                        }
                        else
                        {
                            _pen = _drawRectanglePen;
                        }
                        e.Graphics.DrawRectangle(_pen, _topleft);
                        e.Graphics.DrawRectangle(_pen, _topright);
                        e.Graphics.DrawRectangle(_pen, _bottomleft);
                        e.Graphics.DrawRectangle(_pen, _bottomright);

                        //draw cross if locked
                        if (_gc.Locked)
                        {
                            Point center = new Point(_gc.Left + (_gc.Width / 2), _gc.Top + (_gc.Height / 2));
                            center.X = _state.GUIXToWindow(center.X);
                            center.Y = _state.GUIYToWindow(center.Y);

                            e.Graphics.DrawLine(_pen, center.X - 3, center.Y - 3, center.X + 3, center.Y + 3);
                            e.Graphics.DrawLine(_pen, center.X - 3, center.Y + 3, center.X + 3, center.Y - 3);
                        }
                    }
                }

                if (_snappedx != -1)
                {
                    NormalGUI g = (NormalGUI)_gui;
                    e.Graphics.DrawLine(_drawSnapPen, _state.GUIXToWindow(_snappedx), _state.GUIYToWindow(0), _state.GUIXToWindow(_snappedx), _state.GUIYToWindow(g.Height));
                    string snapxstring = String.Format("{0}px", _snappedx);

                    e.Graphics.DrawString(snapxstring,
                                          DefaultFont,
                                          _drawSnapPen.Brush,
                                          _state.GUIXToWindow(_snappedx) - e.Graphics.MeasureString(snapxstring, DefaultFont).Width,
                                          _state.GUIYToWindow(_selectedControl.Top)
                                          );
                }
                if (_snappedy != -1)
                {
                    NormalGUI g           = (NormalGUI)_gui;
                    string    snapystring = String.Format("{0}px", _snappedy);
                    e.Graphics.DrawLine(_drawSnapPen, _state.GUIXToWindow(0), _state.GUIYToWindow(_snappedy), _state.GUIXToWindow(g.Width), _state.GUIYToWindow(_snappedy));

                    e.Graphics.DrawString(snapystring,
                                          DefaultFont,
                                          _drawSnapPen.Brush,
                                          _state.GUIXToWindow(_selectedControl.Left),
                                          _state.GUIYToWindow(_selectedControl.Top) - e.Graphics.MeasureString(snapystring, DefaultFont).Height
                                          );
                }
            }
            base.OnPaint(e);
        }
示例#5
0
        protected override void OnPropertyChanged(string propertyName, object oldValue)
        {
            if (propertyName == "Name")
            {
                object objectBeingChanged = _gui;
                string newName            = _gui.Name;
                if (_selectedControl != null)
                {
                    objectBeingChanged = _selectedControl;
                    newName            = _selectedControl.Name;
                }
                Game game      = Factory.AGSEditor.CurrentGame;
                bool nameInUse = game.IsScriptNameAlreadyUsed(newName, objectBeingChanged);
                if (newName.StartsWith("g") && newName.Length > 1)
                {
                    nameInUse |= game.IsScriptNameAlreadyUsed(newName.Substring(1).ToUpper(), objectBeingChanged);
                }

                if (nameInUse)
                {
                    Factory.GUIController.ShowMessage("This script name is already used by another item.", MessageBoxIcon.Warning);
                    if (_selectedControl != null)
                    {
                        _selectedControl.Name = (string)oldValue;
                    }
                    else
                    {
                        _gui.Name = (string)oldValue;
                    }
                }
                else if (_selectedControl == null)
                {
                    RaiseOnGuiNameChanged();
                }
            }
            else if (propertyName == "Image")
            {
                if ((_selectedControl != null) && (_selectedControl is GUIButton))
                {
                    GUIButton selectedButton = (GUIButton)_selectedControl;
                    if (selectedButton.Image > 0)
                    {
                        int newWidth, newHeight;
                        Utilities.GetSizeSpriteWillBeRenderedInGame(selectedButton.Image, out newWidth, out newHeight);
                        selectedButton.Width  = newWidth;
                        selectedButton.Height = newHeight;
                    }
                }
            }
            else if (propertyName == "Width" || propertyName == "Height")
            {
                UpdateScrollableWindowSize();
            }
            else if (propertyName == "PopupStyle")
            {
                NormalGUI normalGui = (NormalGUI)_gui;
                if (normalGui != null)
                {
                    // Force Modal GUIs not visible by default
                    if (normalGui.PopupStyle == GUIPopupStyle.PopupModal)
                    {
                        normalGui.Visible = false;
                    }
                }
            }

            bgPanel.Invalidate(true);
        }
示例#6
0
文件: GuiComponent.cs 项目: wlads/ags
 protected override void ItemCommandClick(string controlID)
 {
     if (controlID == COMMAND_NEW_GUI)
     {
         GUI newGUI = new NormalGUI();
         AddNewGUI(newGUI);
         _agsEditor.CurrentGame.NotifyClientsGUIAddedOrRemoved(newGUI);
     }
     else if (controlID == COMMAND_NEW_TEXTWINDOW)
     {
         GUI newGUI = new TextWindowGUI();
         AddNewGUI(newGUI);
         _agsEditor.CurrentGame.NotifyClientsGUIAddedOrRemoved(newGUI);
     }
     else if (controlID == COMMAND_IMPORT_GUI)
     {
         string fileName = _guiController.ShowOpenFileDialog("Import GUI...", GUI_FILE_FILTER);
         if (fileName != null)
         {
             try
             {
                 GUI newGUI = ImportExport.ImportGUIFromFile(fileName, _agsEditor.CurrentGame);
                 newGUI.ID = _agsEditor.CurrentGame.RootGUIFolder.GetAllItemsCount();
                 AddSingleItem(newGUI);
                 _agsEditor.CurrentGame.NotifyClientsGUIAddedOrRemoved(newGUI);
             }
             catch (Exception ex)
             {
                 _guiController.ShowMessage("There was an error importing the GUI. The error was: " + ex.Message, MessageBoxIcon.Warning);
             }
         }
     }
     else if (controlID == COMMAND_FIND_ALL_USAGES)
     {
         FindAllUsages findAllUsage = new FindAllUsages(null, null, null, _agsEditor);
         findAllUsage.Find(null, _guiRightClicked.Name);
     }
     else if (controlID == COMMAND_EXPORT_GUI)
     {
         string fileName = _guiController.ShowSaveFileDialog("Export GUI as...", GUI_FILE_FILTER);
         if (fileName != null)
         {
             try
             {
                 ImportExport.ExportGUIToFile(_guiRightClicked, fileName, _agsEditor.CurrentGame);
             }
             catch (Exception ex)
             {
                 _guiController.ShowMessage("There was an error exporting the GUI. The error was: " + ex.Message, MessageBoxIcon.Warning);
             }
         }
     }
     else if (controlID == COMMAND_DELETE_GUI)
     {
         if (MessageBox.Show("Are you sure you want to delete this GUI? Doing so could break any scripts that refer to GUIs by number.", "Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             _agsEditor.CurrentGame.NotifyClientsGUIAddedOrRemoved(_guiRightClicked);
             DeleteSingleItem(_guiRightClicked);
         }
     }
     else if ((!controlID.StartsWith(NODE_ID_PREFIX_FOLDER)) &&
              (controlID != TOP_LEVEL_COMMAND_ID))
     {
         GUI chosenGui = _agsEditor.CurrentGame.RootGUIFolder.FindGUIByID
                             (Convert.ToInt32(controlID.Substring(ITEM_COMMAND_PREFIX.Length)), true);
         ShowOrAddPane(chosenGui);
     }
 }
示例#7
0
        private void bgPanel_Paint(object sender, PaintEventArgs e)
        {
            if (_gui != null)
            {
                IntPtr hdc = e.Graphics.GetHdc();
                //Factory.NativeProxy.DrawGUI(hdc, 0, 0, _gui, Factory.AGSEditor.CurrentGame.GUIScaleFactor, (_selectedControl == null) ? -1 : _selectedControl.ID);
                Factory.NativeProxy.DrawGUI(hdc, 0, 0, _gui, Factory.AGSEditor.CurrentGame.GUIScaleFactor, -1);
                e.Graphics.ReleaseHdc(hdc);

                if (_addingControl)
                {
                    DrawSelectionRectangle(e.Graphics);
                }

                if (_drawingSelectionBox)
                {
                    Rectangle _rectToDraw = new Rectangle(_selectionRect.X * Factory.AGSEditor.CurrentGame.GUIScaleFactor,
                                                          _selectionRect.Y * Factory.AGSEditor.CurrentGame.GUIScaleFactor,
                                                          _selectionRect.Width * Factory.AGSEditor.CurrentGame.GUIScaleFactor,
                                                          _selectionRect.Height * Factory.AGSEditor.CurrentGame.GUIScaleFactor);

                    e.Graphics.DrawRectangle(_drawRectanglePen, _rectToDraw);
                }
                //draw selection handles
                if (_selected.Count > 0)
                {
                    foreach (GUIControl _gc in _selected)
                    {
                        Rectangle _topleft     = new Rectangle(_gc.Left * Factory.AGSEditor.CurrentGame.GUIScaleFactor, _gc.Top * Factory.AGSEditor.CurrentGame.GUIScaleFactor, 2, 2);
                        Rectangle _topright    = new Rectangle((_gc.Left + _gc.Width - 1) * Factory.AGSEditor.CurrentGame.GUIScaleFactor, _gc.Top * Factory.AGSEditor.CurrentGame.GUIScaleFactor, 2, 2);
                        Rectangle _bottomleft  = new Rectangle(_gc.Left * Factory.AGSEditor.CurrentGame.GUIScaleFactor, (_gc.Top + _gc.Height - 1) * Factory.AGSEditor.CurrentGame.GUIScaleFactor, 2, 2);
                        Rectangle _bottomright = new Rectangle((_gc.Left + _gc.Width - 1) * Factory.AGSEditor.CurrentGame.GUIScaleFactor, (_gc.Top + _gc.Height - 1) * Factory.AGSEditor.CurrentGame.GUIScaleFactor, 2, 2);
                        Pen       _pen;
                        if (_gc == _selectedControl)
                        {
                            _pen = _drawSelectedPen;
                        }
                        else
                        {
                            _pen = _drawRectanglePen;
                        }
                        e.Graphics.DrawRectangle(_pen, _topleft);
                        e.Graphics.DrawRectangle(_pen, _topright);
                        e.Graphics.DrawRectangle(_pen, _bottomleft);
                        e.Graphics.DrawRectangle(_pen, _bottomright);

                        //draw cross if locked
                        if (_gc.Locked)
                        {
                            Point center = new Point(_gc.Left + (_gc.Width / 2), _gc.Top + (_gc.Height / 2));
                            center.X *= Factory.AGSEditor.CurrentGame.GUIScaleFactor;
                            center.Y *= Factory.AGSEditor.CurrentGame.GUIScaleFactor;

                            e.Graphics.DrawLine(_pen, center.X - 3, center.Y - 3, center.X + 3, center.Y + 3);
                            e.Graphics.DrawLine(_pen, center.X - 3, center.Y + 3, center.X + 3, center.Y - 3);
                        }
                    }
                }

                if (_snappedx != -1)
                {
                    NormalGUI g = (NormalGUI)_gui;
                    e.Graphics.DrawLine(_drawSnapPen, _snappedx * Factory.AGSEditor.CurrentGame.GUIScaleFactor, 0, _snappedx * Factory.AGSEditor.CurrentGame.GUIScaleFactor, g.Height * Factory.AGSEditor.CurrentGame.GUIScaleFactor);
                    string snapxstring = String.Format("{0}px", _snappedx);

                    e.Graphics.DrawString(snapxstring,
                                          DefaultFont,
                                          _drawSnapPen.Brush,
                                          _snappedx * Factory.AGSEditor.CurrentGame.GUIScaleFactor - e.Graphics.MeasureString(snapxstring, DefaultFont).Width,
                                          _selectedControl.Top * Factory.AGSEditor.CurrentGame.GUIScaleFactor
                                          );
                }
                if (_snappedy != -1)
                {
                    NormalGUI g           = (NormalGUI)_gui;
                    string    snapystring = String.Format("{0}px", _snappedy);
                    e.Graphics.DrawLine(_drawSnapPen, 0, _snappedy * Factory.AGSEditor.CurrentGame.GUIScaleFactor, g.Width * Factory.AGSEditor.CurrentGame.GUIScaleFactor, _snappedy * Factory.AGSEditor.CurrentGame.GUIScaleFactor);

                    e.Graphics.DrawString(snapystring,
                                          DefaultFont,
                                          _drawSnapPen.Brush,
                                          _selectedControl.Left * Factory.AGSEditor.CurrentGame.GUIScaleFactor,
                                          _selectedControl.Top * Factory.AGSEditor.CurrentGame.GUIScaleFactor - e.Graphics.MeasureString(snapystring, DefaultFont).Height
                                          );
                }
            }
            base.OnPaint(e);
        }
示例#8
0
 protected override void ItemCommandClick(string controlID)
 {
     if (controlID == COMMAND_NEW_GUI)
     {
         Size gameRes = _agsEditor.CurrentGame.Settings.CustomResolution;
         GUI  newGUI  = new NormalGUI(Math.Min(gameRes.Width, GUI_DEFAULT_WIDTH_MAX), Math.Min(gameRes.Height, GUI_DEFAULT_HEIGHT_MAX));
         AddNewGUI(newGUI);
         _agsEditor.CurrentGame.NotifyClientsGUIAddedOrRemoved(newGUI);
     }
     else if (controlID == COMMAND_NEW_TEXTWINDOW)
     {
         GUI newGUI = new TextWindowGUI();
         AddNewGUI(newGUI);
         _agsEditor.CurrentGame.NotifyClientsGUIAddedOrRemoved(newGUI);
     }
     else if (controlID == COMMAND_IMPORT_GUI)
     {
         string fileName = _guiController.ShowOpenFileDialog("Import GUI...", GUI_FILE_FILTER);
         if (fileName != null)
         {
             try
             {
                 GUI newGUI = ImportExport.ImportGUIFromFile(fileName, _agsEditor.CurrentGame);
                 newGUI.ID = _agsEditor.CurrentGame.RootGUIFolder.GetAllItemsCount();
                 AddSingleItem(newGUI);
                 _agsEditor.CurrentGame.NotifyClientsGUIAddedOrRemoved(newGUI);
             }
             catch (Exception ex)
             {
                 _guiController.ShowMessage("There was an error importing the GUI. The error was: " + ex.Message, MessageBoxIcon.Warning);
             }
         }
     }
     else if (controlID == COMMAND_FIND_ALL_USAGES)
     {
         FindAllUsages findAllUsage = new FindAllUsages(null, null, null, _agsEditor);
         findAllUsage.Find(null, _guiRightClicked.Name);
     }
     else if (controlID == COMMAND_EXPORT_GUI)
     {
         string fileName = _guiController.ShowSaveFileDialog("Export GUI as...", GUI_FILE_FILTER);
         if (fileName != null)
         {
             try
             {
                 ImportExport.ExportGUIToFile(_guiRightClicked, fileName, _agsEditor.CurrentGame);
             }
             catch (Exception ex)
             {
                 _guiController.ShowMessage("There was an error exporting the GUI. The error was: " + ex.Message, MessageBoxIcon.Warning);
             }
         }
     }
     else if (controlID == COMMAND_DELETE_GUI)
     {
         if (MessageBox.Show("Are you sure you want to delete this GUI? Doing so could break any scripts that refer to GUIs by number.", "Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             _agsEditor.CurrentGame.NotifyClientsGUIAddedOrRemoved(_guiRightClicked);
             DeleteSingleItem(_guiRightClicked);
         }
     }
     else if (controlID == COMMAND_CHANGE_ID)
     {
         int oldNumber = _guiRightClicked.ID;
         int newNumber = Factory.GUIController.ShowChangeObjectIDDialog("GUI", oldNumber, 0, _items.Count - 1);
         if (newNumber < 0)
         {
             return;
         }
         foreach (var obj in _items)
         {
             if (obj.Value.ID == newNumber)
             {
                 obj.Value.ID = oldNumber;
                 break;
             }
         }
         _guiRightClicked.ID = newNumber;
         GetFlatList().Swap(oldNumber, newNumber);
         OnItemIDChanged(_guiRightClicked);
     }
     else if ((!controlID.StartsWith(NODE_ID_PREFIX_FOLDER)) &&
              (controlID != TOP_LEVEL_COMMAND_ID))
     {
         GUI chosenGui = _agsEditor.CurrentGame.RootGUIFolder.FindGUIByID
                             (Convert.ToInt32(controlID.Substring(ITEM_COMMAND_PREFIX.Length)), true);
         ShowOrAddPane(chosenGui);
     }
 }