Ejemplo n.º 1
0
        /// <summary>
        /// 创建指定皮肤唯一名的皮肤管理器,此方法调用后,新皮肤资源将载入,就皮肤资源将被释放
        /// </summary>
        /// <param name="skinName">皮肤唯一名(皮肤根目录名)</param>
        /// <param name="recreate">是否强制重新创建</param>
        /// <returns>皮肤管理器</returns>
        public static DUISkinManager CreateSkinManager(DUISkinInfo skinInfo, bool recreate)
        {
            if (recreate || _instance == null || _instance.CurrentSkinInfo == null ||
                !_instance.CurrentSkinInfo.SkinName.Equals(skinInfo.SkinName))
            {
                lock (_lockObj)
                {
                    //二次判断,以支持多线程
                    if (recreate || _instance == null || _instance.CurrentSkinInfo == null ||
                        !_instance.CurrentSkinInfo.SkinName.Equals(skinInfo.SkinName))
                    {
                        try
                        {
                            DUIForm.FlushBackgroundBitmapDict();
                            _instance = new DUISkinManager(skinInfo);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("换肤时产生异常:" + ex.Message);
                        }

                        BroadCastSkinChangeEvent();
                    }
                }
            }
            return(_instance);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <param name="backgroundBitmap"></param>
        /// <param name="form"></param>
        /// <param name="offsetPoint"></param>
        public void RenderBackground(Graphics g, Image backgroundBitmap, DUIForm form, Point offsetPoint)
        {
            TextureBrush      brush;
            DUIBackgroundInfo backgroundInfo;
            Image             backgroundImage;
            int bWidth  = offsetPoint.X;
            int bHeight = offsetPoint.Y;

            if (form.WindowState == FormWindowState.Maximized)
            {
                //获得布局最大化状态下背景信息
                backgroundInfo = this.MaximizedbackgroundInfo;
                //获得最大化状态下的背景图
                backgroundImage = DUISkinManager.GetCurrentSkinManager().GetImageSource(this.MaximizedbackgroundInfo.SourceName);
            }
            else
            {
                //获得布局普通状态下背景信息
                backgroundInfo = this.NormalBackgroundInfo;
                //获得非最大化状态下的背景图
                backgroundImage = DUISkinManager.GetCurrentSkinManager().GetImageSource(this.NormalBackgroundInfo.SourceName);
            }
            //--------------------------------------------------------
            //绘制顶部中间段边框
            //brush = new TextureBrush(Resources.IMBorderTop2, WrapMode.Tile, new Rectangle(10, 0, 1, 24));
            brush = new TextureBrush(
                backgroundImage,
                WrapMode.Tile,
                new Rectangle(
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).X,
                    0,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).X - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).X,//+99,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).Y));

            //g.FillRectangle(brush, new Rectangle(0, 0, Width, 24));
            //利用TextureBrush时的图像偏移问题http://www.cnblogs.com/lx1988729/articles/2605477.html
            brush.TranslateTransform(CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).X, 0);
            g.FillRectangle(
                brush,
                new Rectangle(
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).X,
                    0,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).X - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).X,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).Y));
            brush.Dispose();
            //---------------------------------------------------------
            //绘制左部中间段边框
            //brush = new TextureBrush(Resources.IMBorderLeft);
            //g.FillRectangle(brush, new Rectangle(0, 0, 3, Height));
            brush = new TextureBrush(
                backgroundImage,
                WrapMode.Tile,
                new Rectangle(
                    0,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).Y,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).X,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomLeftPoint).Y - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).Y));
            brush.TranslateTransform(0, CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).Y);
            g.FillRectangle(
                brush,
                new Rectangle(
                    0,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).Y,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).X,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomLeftPoint).Y - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).Y));
            brush.Dispose();


            //---------------------------------------------------------
            //绘制右部中间段边框
            //brush = new TextureBrush(Resources.IMBorderRight);
            //brush.TranslateTransform(base.Width - bWidth * 2, 0);
            //g.FillRectangle(brush, new Rectangle(base.Width - bWidth * 2 - 3, 0, 3, Height));
            brush = new TextureBrush(
                backgroundImage,
                WrapMode.Tile,
                new Rectangle(
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).X - 2 * bWidth,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).Y,
                    backgroundImage.Width + bWidth - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).X,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomRightPoint).Y - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).Y));
            brush.TranslateTransform(CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).X - 2 * bWidth,
                                     CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).Y);
            g.FillRectangle(
                brush,
                new Rectangle(
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).X, //- 2 * bWidth, //????原始代码中减了2bWidth,因为BackBufferBitmap的宽度已经减了bWidth,故此处只减一个bWidth
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).Y,
                    backgroundBitmap.Width + bWidth - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).X,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomRightPoint).Y - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).Y));
            brush.Dispose();

            //---------------------------------------------------------
            //绘制下部中间段边框
            //brush = new TextureBrush(Resources.IMBorderBottom, new Rectangle(10, 0, 1, 8));
            //brush.TranslateTransform(0, base.Height - bHeight * 2);
            //g.FillRectangle(brush, new Rectangle(0, base.Height - bHeight * 2 - 3, Width, 3));
            brush = new TextureBrush(
                backgroundImage,
                WrapMode.Tile,
                new Rectangle(
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomLeftPoint).X,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomLeftPoint).Y - 2 * bHeight,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomRightPoint).X - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomLeftPoint).X,
                    backgroundImage.Height + bHeight - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomLeftPoint).Y));
            brush.TranslateTransform(CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomLeftPoint).X,
                                     CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomLeftPoint).Y - 2 * bHeight);
            g.FillRectangle(
                brush,
                new Rectangle(
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomLeftPoint).X,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomLeftPoint).Y - 2 * bHeight,//????原始代码中减了2bHeight,因为BackBufferBitmap的高度已经减了bHeight,故此处只减一个bHeight
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomRightPoint).X - CommonFunctions.GetImagePoint(backgroundImage, bWidth, bHeight, backgroundInfo.BottomLeftPoint).X,
                    backgroundBitmap.Height + bHeight - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomLeftPoint).Y));
            brush.Dispose();

            //---------------------------------------------------------
            //绘制四个角
            //if (WindowState == FormWindowState.Maximized)
            //{
            //    g.DrawImage(Resources.IMBorderLeftTop2, 0, 0, 3, 24);
            //    g.DrawImage(Resources.IMBorderRightTop2, base.Width - bWidth * 2 - 3, 0, 3, 24);
            //    g.DrawImage(Resources.IMBorderLeftBottom2, 0, base.Height - bHeight * 2 - 3, 3, 3);
            //    g.DrawImage(Resources.IMBorderRightBottom2, base.Width - bWidth * 2 - 3, base.Height - bHeight * 2 - 3, 3, 3);
            //}
            //else
            //{
            //    g.DrawImage(Resources.IMBorderTop, new Rectangle(0, 0, 25, 24), new Rectangle(0, 0, 25, 24), GraphicsUnit.Pixel);
            //    g.DrawImage(Resources.IMBorderTop, new Rectangle(base.Width - bWidth * 2 - 25, 0, 25, 24), new Rectangle(25, 0, 25, 24), GraphicsUnit.Pixel);
            //    g.DrawImage(Resources.IMBorderBottom, new Rectangle(0, base.Height - bHeight * 2 - 8, 10, 8), new Rectangle(0, 0, 10, 8), GraphicsUnit.Pixel);
            //    g.DrawImage(Resources.IMBorderBottom, new Rectangle(base.Width - bWidth * 2 - 10, base.Height - bHeight * 2 - 8, 10, 8), new Rectangle(40, 0, 10, 8), GraphicsUnit.Pixel);
            //}
            //---------------------------------------------------------
            //绘制左上角
            g.DrawImage(
                backgroundImage,
                new Rectangle(
                    0,
                    0,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).X,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).Y),
                0,
                0,
                CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).X,
                CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).Y,
                GraphicsUnit.Pixel);
            //---------------------------------------------------------
            //绘制右上角
            g.DrawImage(
                backgroundImage,
                new Rectangle(
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).X,
                    0,
                    backgroundBitmap.Width + bWidth - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).X,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).Y),
                CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).X,
                0,
                backgroundImage.Width - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).X,
                CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).Y,
                GraphicsUnit.Pixel);
            //---------------------------------------------------------
            //绘制左下角
            g.DrawImage(
                backgroundImage,
                new Rectangle(
                    0,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomLeftPoint).Y,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomLeftPoint).X,
                    backgroundBitmap.Height + bHeight - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomLeftPoint).Y),
                0,
                CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomLeftPoint).Y,
                CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomLeftPoint).X,
                backgroundImage.Height - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomLeftPoint).Y,
                GraphicsUnit.Pixel);
            //---------------------------------------------------------
            //绘制右下角
            g.DrawImage(
                backgroundImage,
                new Rectangle(
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).X,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomLeftPoint).Y,
                    backgroundBitmap.Width + bWidth - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomRightPoint).X,
                    backgroundBitmap.Height + bHeight - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomRightPoint).Y),

                CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomRightPoint).X,
                CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomRightPoint).Y,
                backgroundImage.Width - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomRightPoint).X,
                backgroundImage.Height - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomRightPoint).Y,
                GraphicsUnit.Pixel);

            //---------------------------------------------------------
            //绘制中间内容区
            //g.DrawImage(
            //    backgroundImage,
            //    new Rectangle(
            //        CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).X ,
            //        CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).Y ,
            //        CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).X
            //            - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).X,
            //        CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomRightPoint).Y
            //            - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).Y),

            //        CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).X,
            //        CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).Y,
            //        CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).X
            //            - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).X,
            //        CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomRightPoint).Y
            //            - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).Y,
            //        GraphicsUnit.Pixel);
            brush = new TextureBrush(
                backgroundImage,
                WrapMode.Tile,
                new Rectangle(
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).X,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).Y,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).X
                    - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopLeftPoint).X,
                    CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.BottomRightPoint).Y
                    - CommonFunctions.GetImagePoint(backgroundImage, 0, 0, backgroundInfo.TopRightPoint).Y));
            brush.TranslateTransform(CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).X,
                                     CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).Y);
            g.FillRectangle(
                brush,
                new Rectangle(
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).X,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).Y,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).X
                    - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopLeftPoint).X,
                    CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.BottomRightPoint).Y
                    - CommonFunctions.GetImagePoint(backgroundBitmap, bWidth, bHeight, backgroundInfo.TopRightPoint).Y));
            brush.Dispose();

            //绘制背景图片
            this._imageManager.RenderImages(backgroundBitmap, g, offsetPoint);
        }