duilib 使用图片素材或者算法给窗体增加阴影(源码和demo) - Go语言中文社区

duilib 使用图片素材或者算法给窗体增加阴影(源码和demo)


转载原出处:http://blog.csdn.net/zhuhongshu/article/details/42580877


         之前我写的程序使用阴影时,一直是使用codeproject网站上的WndShadow类,并且把它当作单独的模块来使用,后来觉得使用阴影的情况非常多,所以今天就把这个类改写了一下,让他融入到duilib,并且可以直接使用xml来描述阴影,不需要写任何c++代码。


        以前的WndShadow类是用算法来计算阴影,灵活性很大,但是缺点就是效果不够理想,所以我另外给他附加了使用图片素材来贴阴影的功能。最终的新类名为CShadowUI。这个类可以单独使用,我把他集成到了自己的库里。为了融合到Duilib我修改了UiLib.h文件、UIDlgBuilder.cpp文件、UIManager.h文件、UIManager.cpp文件。


        先贴两张效果图,以下是素材阴影和算法阴影的效果图:





        通过设置xml的Window标签可以添加阴影,阴影的xml属性描述如下:


[html] view plain copy
  1. <Attribute name="showshadow" default="false" type="BOOL" comment="是否启用窗体阴影"/>  
  2. <Attribute name="shadowimage" default="" type="STRING" comment="阴影图片,使用此属性后自动屏蔽算法阴影(不支持source等属性设置)"/>  
  3. <Attribute name="shadowcorner" default="0,0,0,0" type="RECT" comment="图片阴影的九宫格描述"/>  
  4. <Attribute name="shadowsize" default="0" type="BYTE" comment="算法阴影的宽度(-20到20)"/>  
  5. <Attribute name="shadowsharpness" default="255" type="BYTE" comment="算法阴影的锐度"/>  
  6. <Attribute name="shadowdarkness" default="255" type="BYTE" comment="算法阴影的深度(相当于透明度)"/>  
  7. <Attribute name="shadowposition" default="0,0" type="SIZE" comment="算法阴影的偏移量"/>  
  8. <Attribute name="shadowcolor" default="0x000000" type="DWORD" comment="算法阴影的颜色,RGB格式,不支持透明度,使用shadowdarkness设置透明度"/>  

        前面的两个效果图的对应xml描述如下:


[html] view plain copy
  1. <!-- 图片阴影 -->  
  2. <Window size="840,600" sizebox="4,4,4,4" caption="0,0,0,75" mininfo="840,600" showshadow="true" shadowimage="shadow.png" shadowcorner="23,13,23,33">  
  3. <!-- 算法阴影 -->  
  4. <Window size="840,600" sizebox="4,4,4,4" caption="0,0,0,75" mininfo="840,600" showshadow="true" shadowsize="5" shadowposition="1,1" shadowcolor="#333333">  


源码:


       UIShadow.h源码为:


[cpp] view plain copy
  1. // WndShadow.h : header file  
  2. //  
  3. // Version 0.1  
  4. //  
  5. // Copyright (c) 2006 Perry Zhu, All Rights Reserved.  
  6. //  
  7. // mailto:perry@live.com  
  8. //  
  9. //  
  10. // This source file may be redistributed unmodified by any means PROVIDING   
  11. // it is NOT sold for profit without the authors expressed written   
  12. // consent, and providing that this notice and the author's name and all   
  13. // copyright notices remain intact. This software is by no means to be   
  14. // included as part of any third party components library, or as part any  
  15. // development solution that offers MFC extensions that are sold for profit.   
  16. //   
  17. // If the source code is used in any commercial applications then a statement   
  18. // along the lines of:  
  19. //   
  20. // "Portions Copyright (c) 2006 Perry Zhu" must be included in the "Startup   
  21. // Banner", "About Box" or "Printed Documentation". This software is provided   
  22. // "as is" without express or implied warranty. Use it at your own risk! The   
  23. // author accepts no liability for any damage/loss of business that this   
  24. // product may cause.  
  25. //  
  26. /////////////////////////////////////////////////////////////////////////////  
  27. //****************************************************************************  
  28.   
  29. /********************************************************************  
  30.     created:    2015/01/09  
  31.     filename:   UIShadow.h  
  32.     author:     Redrain  
  33.       
  34.     purpose:    DuiLib阴影类,在原WndShadow类的基础上,增加了通过PNG图片设置阴影的功能,并且把代码与DuiLib融合  
  35. *********************************************************************/  
  36.   
  37. #ifndef __UISHADOW_H__  
  38. #define __UISHADOW_H__  
  39.   
  40. #pragma once  
  41. #include "map"  
  42.   
    版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
    原文链接:https://blog.csdn.net/dongchongyang/article/details/73303130
    站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
    • 发表于 2020-03-07 18:15:40
    • 阅读 ( 1133 )
    • 分类:算法

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢