Beispiel #1
0
        /// <summary>
        /// 克隆函数
        /// </summary>
        /// <returns>克隆后的DUIButtonGroup对象</returns>
        public object Clone()
        {
            DUIButtonGroup newDUIButtonGroup
                = new DUIButtonGroup(this._name, this._ownerButtonManager, this._buttonDict);

            return(newDUIButtonGroup);
        }
Beispiel #2
0
 /// <summary>
 /// 绘制按钮
 /// </summary>
 /// <param name="backBufferBitmap">当前双缓冲绘图缓存的背景图片</param>
 /// <param name="g">与背景缓冲图绑定的绘图对象</param>
 /// <param name="offsetPoint">偏移点,用于消除窗口最大化时窗口边框厚度对点计算造成的误差</param>
 public void RenderButtons(Image backBufferBitmap, Graphics g, Point offsetPoint)
 {
     //绘制按钮时,按照配置文件出现的顺序依次绘制,越晚出现的按钮越在上层
     for (int i = 0; i < this._buttonGroupList.Count; i++)
     {
         DUIButtonGroup buttonGroup = this._buttonGroupList[i];
         buttonGroup.RenderButtonGroup(backBufferBitmap, g, offsetPoint);
     }
 }
Beispiel #3
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._buttonGroupList.Count - 1; i >= 0; i--)
     {
         DUIButtonGroup buttonGroup = this._buttonGroupList[i];
         buttonGroup.OnMouseUp(backBufferBitmap, offsetPoint, p);
     }
 }
Beispiel #4
0
 /// <summary>
 /// 供克隆函数调用的私有构造函数
 /// </summary>
 /// <param name="ownerLayout"></param>
 /// <param name="buttonGroupDict"></param>
 private DUIButtonManager(DUILayout ownerLayout, IDictionary <string, DUIButtonGroup> buttonGroupDict)
 {
     _ownerLayout = ownerLayout;
     if (buttonGroupDict != null && buttonGroupDict.Count > 0)
     {
         foreach (string groupName in buttonGroupDict.Keys)
         {
             DUIButtonGroup newButtonGroup = (DUIButtonGroup)buttonGroupDict[groupName].Clone();
             newButtonGroup.OwnerButtonManager = this;
             this._buttonGroupDict.Add(groupName, newButtonGroup);
             this._buttonGroupList.Add(newButtonGroup);
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// 处理布局所有按钮的鼠标按下事件
        /// </summary>
        /// <param name="backBufferBitmap">当前双缓冲绘图缓存的背景图片</param>
        /// <param name="offsetPoint">偏移点,用于消除窗口最大化时窗口边框厚度对点计算造成的误差</param>
        /// <param name="p">鼠标位置</param>
        public void OnMouseDown(Image backBufferBitmap, Point offsetPoint, Point p)
        {
            //绘制按钮组时,按照配置文件出现的顺序依次绘制,越晚出现的按钮组越在上层
            //当Button有重叠的时候,从最上层的Button开始遍历
            for (int i = this._buttonGroupList.Count - 1; i >= 0; i--)
            {
                DUIButtonGroup buttonGroup = this._buttonGroupList[i];

                ////只要任意按钮组的任意按钮命中按下事件,则返回
                //if (buttonGroup.OnMouseDown(backBufferBitmap, offsetPoint, p) == true)
                //{
                //    return;
                //}
                buttonGroup.OnMouseDown(backBufferBitmap, offsetPoint, p);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 处理布局所有按钮的鼠标移过焦点事件
        /// </summary>
        /// <param name="backBufferBitmap">当前双缓冲绘图缓存的背景图片</param>
        /// <param name="offsetPoint">偏移点,用于消除窗口最大化时窗口边框厚度对点计算造成的误差</param>
        /// <param name="p">鼠标位置</param>
        public bool OnMouseMove(Image backBufferBitmap, Point offsetPoint, Point p)
        {
            bool HitButton = false;

            //绘制按钮组时,按照配置文件出现的顺序依次绘制,越晚出现的按钮组越在上层
            //当Button有重叠的时候,从最上层的Button开始遍历
            for (int i = this._buttonGroupList.Count - 1; i >= 0; i--)
            {
                DUIButtonGroup buttonGroup = this._buttonGroupList[i];

                ////只要任意按钮组的任意按钮命中移过焦点处理,则返回
                //if (buttonGroup.OnMouseMove(backBufferBitmap, offsetPoint, p) == true)
                //{
                //    return;
                //}
                HitButton = HitButton || buttonGroup.OnMouseMove(backBufferBitmap, offsetPoint, p);
            }
            return(HitButton);
        }
Beispiel #7
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);
                            }
                        }
                    }
                }
            }
        }