Пример #1
0
        public Toolbar(string path){
            var sr = new StreamReader(path);
            var str = sr.ReadToEnd();
            var ctorData = JsonConvert.DeserializeObject<ToolbarCtorData>(str);
            _Enabled = true;

            #region some validity checks

            if (ctorData.ButtonIcons == null)
                throw new InvalidDataException("ButtonIcons invalid");
            if (ctorData.NumButtons == 0)
                throw new InvalidDataException("NumButtons invalid");
            if (ctorData.ButtonIcons.Length != ctorData.NumButtons)
                throw new InvalidDataException("NumButtons is not equal to the number of ButtonIcons");

            #endregion

            #region set ctor data

            _position = ctorData.Position;
            _buttonSize = ctorData.ButtonSize;
            _orientation = ctorData.Orientation;
            _numButtons = ctorData.NumButtons;

            #endregion

            #region create the buttons

            var buttonGen = new ButtonGenerator(ctorData.ButtonTemplate);
            ToolbarButtons = new Button[ctorData.NumButtons];

            int xPos = _position.X;
            int yPos = _position.Y;
            int xIncrement = 0, yIncrement = 0;
            if (_orientation == ToolbarOrientation.Horizontal)
                xIncrement = _buttonSize.X;
            else
                yIncrement = _buttonSize.Y;

            for (int i = 0; i < ctorData.NumButtons; i++){
                buttonGen.Identifier = i;
                buttonGen.X = xPos;
                buttonGen.Y = yPos;
                buttonGen.TextureName = ctorData.ButtonIcons[i];

                ToolbarButtons[i] = buttonGen.GenerateButton();

                xPos += xIncrement;
                yPos += yIncrement;
            }
            foreach (var button in ToolbarButtons){
                button.OnLeftClickDispatcher += HandleButtonClick;
            }

            #endregion

            #region finalize construction

            _nullTool = new NullTool();
            _activeTool = _nullTool;

            _buttonTools = new IToolbarTool[_numButtons];
            for (int i = 0; i < _numButtons; i++)
                _buttonTools[i] = _nullTool;

            #endregion
        }
Пример #2
0
 public void ClearActiveTool(){
     _activeTool.Enabled = false;
     _activeTool = _nullTool;
     foreach (var button in ToolbarButtons){
         button.GetComponent<HighlightComponent>("ClickHoldEffect").UnprocHighlight();
         button.GetComponent<HighlightComponent>("HoverMask").Enabled = true;
         button.GetComponent<HighlightComponent>("HoverMask").UnprocHighlight();
     }
 }
Пример #3
0
        void HandleButtonClick(int identifier){
            if (Enabled){
                Debug.Assert(identifier < _buttonTools.Length);

                ClearActiveTool();
                _buttonTools[identifier].Enabled = true;
                ToolbarButtons[identifier].GetComponent<HighlightComponent>("ClickHoldEffect").ProcHighlight();
                ToolbarButtons[identifier].GetComponent<HighlightComponent>("HoverMask").Enabled = false;
                _activeTool = _buttonTools[identifier];
            }
        }
Пример #4
0
 public void BindButtonToTool(int buttonIdentifier, IToolbarTool tool){
     Debug.Assert(buttonIdentifier < _buttonTools.Length);
     _buttonTools[buttonIdentifier] = tool;
 }