Example #1
0
        /// <summary>
        /// 处理分组内所有按钮的鼠标按下事件
        /// </summary>
        /// <param name="backBufferBitmap">当前双缓冲绘图缓存的背景图片</param>
        /// <param name="offsetPoint">偏移点,用于消除窗口最大化时窗口边框厚度对点计算造成的误差</param>
        /// <param name="p">鼠标位置</param>
        /// <returns>若本组内有按钮命中移过测试,且状态被改变,则返回true,否则返回false.</returns>
        public void OnMouseDown(Image backBufferBitmap, Point offsetPoint, Point p)
        {
            ////当Button有重叠的时候,从最上层的Button开始遍历
            //for (int i = this._buttonList.Count - 1; i >= 0; i--)
            //{
            //    Button button = this._buttonList[i];
            //    if (button.Visible == true
            //        && button.Status != ButtonStatus.Down
            //        && button.RectangleContains(backBufferBitmap, offsetPoint, p))
            //    {
            //        //ResetAllButtonStatus(ButtonStatus.Normal);
            //        button.Status = ButtonStatus.Down;

            //        //当有一个按钮获得鼠标按下焦点时,立即返回true,那么其他分组将不再做按下焦点处理
            //        //任何时候只有一个按钮能获得按下焦点
            //        return true;
            //    }
            //}
            //return false;

            for (int i = this._buttonList.Count - 1; i >= 0; i--)
            {
                DUIButton button = this._buttonList[i];
                if (button.Visible == true &&
                    button.Status != ButtonStatus.Down &&
                    button.RectangleContains(backBufferBitmap, offsetPoint, p))
                {
                    //ResetAllButtonStatus(ButtonStatus.Normal);
                    button.Status = ButtonStatus.Down;
                }
            }
        }
Example #2
0
        protected override void ProcessUserButtons()
        {
            base.ProcessUserButtons();

            //获取背景按钮对象
            if (this.Layout.ButtonManager["TestGroup"] != null)
            {
                maxButton2   = this.Layout.ButtonManager["TestGroup"]["btMax2"];
                minButton2   = this.Layout.ButtonManager["TestGroup"]["btMin2"];
                closeButton2 = this.Layout.ButtonManager["TestGroup"]["btClose2"];
            }

            if (maxButton2 != null)
            {
                maxButton2.SetClickEventHandler(OnMaxButton2Click);
            }
            if (minButton2 != null)
            {
                minButton2.SetClickEventHandler(OnMiniButton2Click);
            }
            if (closeButton2 != null)
            {
                closeButton2.SetClickEventHandler(OnCloseButton2Click);
            }
        }
Example #3
0
 /// <summary>
 /// 向按钮组添加一个指定名称的按钮对象
 /// </summary>
 /// <param name="buttonName"></param>
 /// <param name="button"></param>
 public void AddButton(string buttonName, DUIButton button)
 {
     if (_buttonDict.ContainsKey(buttonName))
     {
         throw new Exception("布局" + this._ownerButtonManager.OwnerLayout.Name + "的按钮组" + _name + "中已经存在名为" + buttonName + "的按钮,不能重复加载,请检查局部配置文件!");
     }
     this._buttonDict.Add(buttonName, button);
     this._buttonList.Add(button);
 }
Example #4
0
 /// <summary>
 /// 绘制按钮
 /// </summary>
 /// <param name="backBufferBitmap">当前双缓冲绘图缓存的背景图片</param>
 /// <param name="g">与背景缓冲图绑定的绘图对象</param>
 /// <param name="offsetPoint">偏移点,用于消除窗口最大化时窗口边框厚度对点计算造成的误差</param>
 public void RenderButtonGroup(Image backBufferBitmap, Graphics g, Point offsetPoint)
 {
     //绘制按钮时,按照配置文件出现的顺序依次绘制,越晚出现的按钮越在上层
     for (int i = 0; i < this._buttonList.Count; i++)
     {
         DUIButton button = this._buttonList[i];
         if (button.Visible == true)
         {
             button.Render(backBufferBitmap, g, offsetPoint);
         }
     }
 }
Example #5
0
 /// <summary>
 /// 处理分组内所有按钮的鼠标弹起事件
 /// </summary>
 /// <param name="backBufferBitmap">当前双缓冲绘图缓存的背景图片</param>
 /// <param name="offsetPoint">偏移点,用于消除窗口最大化时窗口边框厚度对点计算造成的误差</param>
 /// <param name="p">鼠标位置</param>
 public void OnMouseUp(Image backBufferBitmap, Point offsetPoint, Point p)
 {
     //当Button有重叠的时候,从最上层的Button开始遍历
     for (int i = this._buttonList.Count - 1; i >= 0; i--)
     {
         DUIButton button = this._buttonList[i];
         if (button.Visible == true &&
             button.Status == ButtonStatus.Down &&
             button.RectangleContains(backBufferBitmap, offsetPoint, p))
         {
             button.Status = ButtonStatus.Normal;
             button.InvokeClickHandler();
         }
     }
 }
Example #6
0
 /// <summary>
 /// 供克隆函数调用的私有构造函数
 /// </summary>
 /// <param name="name"></param>
 /// <param name="ownerButtonManager"></param>
 /// <param name="buttonDict"></param>
 private DUIButtonGroup(string name, DUIButtonManager ownerButtonManager,
                        IDictionary <string, DUIButton> buttonDict)
 {
     this._name = name;
     this._ownerButtonManager = ownerButtonManager;
     if (buttonDict != null && buttonDict.Count > 0)
     {
         foreach (string buttonName in buttonDict.Keys)
         {
             DUIButton newButton = (DUIButton)buttonDict[buttonName].Clone();
             newButton.OwnerGroup = this;
             _buttonDict.Add(buttonName, newButton);
             _buttonList.Add(newButton);
         }
     }
 }
Example #7
0
        /// <summary>
        /// 处理分组内所有按钮的鼠标移过焦点事件
        /// </summary>
        /// <param name="backBufferBitmap">当前双缓冲绘图缓存的背景图片</param>
        /// <param name="offsetPoint">偏移点,用于消除窗口最大化时窗口边框厚度对点计算造成的误差</param>
        /// <param name="p">鼠标位置</param>
        /// <returns>若本组内有按钮命中移过测试,且状态被改变,则返回true,否则返回false.</returns>
        public bool OnMouseMove(Image backBufferBitmap, Point offsetPoint, Point p)
        {
            ////当Button有重叠的时候,从最上层的Button开始遍历
            //for (int i = this._buttonList.Count-1; i >=0 ; i--)
            //{
            //    Button button = this._buttonList[i];
            //    if (button.Visible == true
            //        && button.Status != ButtonStatus.Hover
            //        && button.RectangleContains(backBufferBitmap, offsetPoint, p))
            //    {
            //        ResetAllButtonStatus(ButtonStatus.Normal);
            //        button.Status = ButtonStatus.Hover;

            //        //当有一个按钮获得鼠标焦点时,立即返回true,那么其他分组将不再做焦点获得处理
            //        //任何时候只有一个按钮能获得焦点
            //        return true;
            //    }
            //}
            //return false;
            bool HitButton = false; //标识是否有按钮命中

            for (int i = this._buttonList.Count - 1; i >= 0; i--)
            {
                DUIButton button = this._buttonList[i];
                if (button.Visible == true)
                {
                    if (button.RectangleContains(backBufferBitmap, offsetPoint, p))
                    {
                        if (button.Status != ButtonStatus.Down)
                        {
                            button.Status = ButtonStatus.Hover;
                            HitButton     = true;
                        }
                    }
                    else
                    {
                        button.Status = ButtonStatus.Normal;
                    }
                }
            }
            return(HitButton);
        }
Example #8
0
        /// <summary>
        /// 克隆函数
        /// </summary>
        /// <returns>克隆后的对象</returns>
        public object Clone()
        {
            DUIButton newButton = new DUIButton();

            newButton.Name             = this._name;
            newButton.Position         = this._position;
            newButton.Text             = this._text;
            newButton.TextAlignment    = this._textAlignment;
            newButton.TextOffsetX      = this._textOffsetX;
            newButton.TextOffsetY      = this._textOffsetY;
            newButton.NormalSourceName = this._normalSourceName;
            newButton.NormalFontName   = this._normalFontName;
            newButton.HoverSourceName  = this._hoverSourceName;
            newButton.HoverFontName    = this._hoverFontName;
            newButton.DownSourceName   = this._downSourceName;
            newButton.DownFontName     = this._downFontName;
            newButton.Status           = this._status;
            newButton.HoldDown         = this._holdDown;
            newButton.Visible          = this._visible;
            newButton.OwnerGroup       = this._ownerGroup;

            return(newButton);
        }
Example #9
0
        /// <summary>
        /// 从XML配置文件加载按钮信息,形成分组和按钮对象
        /// </summary>
        /// <param name="xmlDoc"></param>
        public void LoadButtonFromXml(XmlDocument xmlDoc)
        {
            if (xmlDoc == null)
            {
                throw new Exception("加载布局" + this._ownerLayout.Name + "中的背景按钮时,文档对象为空!");
            }
            XmlElement layoutElement = xmlDoc.DocumentElement;

            foreach (XmlNode childNode in layoutElement.ChildNodes)
            {
                if (childNode.Name == "buttons")
                {
                    foreach (XmlNode buttonNode in childNode.ChildNodes)
                    {
                        if (buttonNode.Name == "button")
                        {
                            if (buttonNode.Attributes["name"] != null &&
                                buttonNode.Attributes["position"] != null &&
                                buttonNode.Attributes["enable"] != null &&
                                buttonNode.Attributes["normalSourceName"] != null &&
                                buttonNode.Attributes["hoverSourceName"] != null &&
                                buttonNode.Attributes["downSourceName"] != null)
                            {
                                //enble属性为false,或者该属性不存在或非法值时,不加载该按钮
                                string enableString = buttonNode.Attributes["enable"].Value;
                                if (string.IsNullOrEmpty(enableString) ||
                                    (enableString.ToLower() != "true" && enableString.ToLower() != "false"))
                                {
                                    continue;
                                }
                                bool enble = Convert.ToBoolean(enableString);
                                if (enble == false)
                                {
                                    continue;
                                }

                                //创建按钮对象
                                DUIButton newButton = new DUIButton();
                                newButton.Name             = buttonNode.Attributes["name"].Value;
                                newButton.Position         = ConvertStringToPoint(newButton.Name, buttonNode.Attributes["position"].Value);
                                newButton.NormalSourceName = buttonNode.Attributes["normalSourceName"].Value;
                                newButton.HoverSourceName  = buttonNode.Attributes["hoverSourceName"].Value;
                                newButton.DownSourceName   = buttonNode.Attributes["downSourceName"].Value;
                                newButton.Status           = ButtonStatus.Normal;
                                newButton.HoldDown         = false;
                                newButton.Visible          = true;

                                //新加属性
                                newButton.Text           = XMLConfigReader.ReadString("text", buttonNode.Attributes["text"]);
                                newButton.TextAlignment  = XMLConfigReader.ReadEnumTypeConfig <ContentAlignment>(buttonNode.Name, "textAlignment", buttonNode.Attributes["textAlignment"]);
                                newButton.TextOffsetX    = XMLConfigReader.ReadInt(buttonNode.Name, "textOffsetX", buttonNode.Attributes["textOffsetX"]);
                                newButton.TextOffsetY    = XMLConfigReader.ReadInt(buttonNode.Name, "textOffsetY", buttonNode.Attributes["textOffsetY"]);
                                newButton.NormalFontName = XMLConfigReader.ReadString("normalFontName", buttonNode.Attributes["normalFontName"]);
                                newButton.HoverFontName  = XMLConfigReader.ReadString("hoverFontName", buttonNode.Attributes["hoverFontName"]);
                                newButton.DownFontName   = XMLConfigReader.ReadString("downFontName", buttonNode.Attributes["downFontName"]);

                                string buttonGroupName = buttonNode.Attributes["group"] == null ? string.Empty : buttonNode.Attributes["group"].Value;
                                if (buttonGroupName == string.Empty)
                                {
                                    buttonGroupName = DUIButtonGroup.NormalGroupName;
                                }
                                if (!this._buttonGroupDict.ContainsKey(buttonGroupName))
                                {
                                    DUIButtonGroup newButtonGroup = new DUIButtonGroup(buttonGroupName, this);
                                    this._buttonGroupDict.Add(buttonGroupName, newButtonGroup);
                                    this._buttonGroupList.Add(newButtonGroup);
                                }

                                DUIButtonGroup buttonGroup = this._buttonGroupDict[buttonGroupName];
                                newButton.OwnerGroup = buttonGroup;
                                buttonGroup.AddButton(newButton.Name, newButton);
                            }
                        }
                    }
                }
            }
        }
Example #10
0
 private void OnMaxButton2Click(EricYou.DirectUI.Skin.Buttons.DUIButton sender)
 {
     //MessageBox.Show("You click max button!这是一个Hold住的按钮!");
     sender.OwnerGroup.ResetAllButtonHoldDownStatus();
     sender.HoldDown = true;
 }