UiImage.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:6k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // Copyright : Kingsoft 2002
  3. // Author :   Wooy(Wu yue)
  4. // CreateTime: 2002-7-25
  5. ------------------------------------------------------------------------------------------
  6. *****************************************************************************************/
  7. #include "KWin32.h"
  8. #include "Windows.h"
  9. #include "UiImage.h"
  10. #include "../../../Represent/iRepresent/iRepresentShell.h"
  11. unsigned int l_Time = 0;
  12. //绘图设备
  13. extern iRepresentShell* g_pRepresentShell;
  14. unsigned int IR_GetCurrentTime()
  15. {
  16. return l_Time;
  17. }
  18. //--------------------------------------------------------------------------
  19. // 功能:更新图形换帧计算用时钟
  20. //--------------------------------------------------------------------------
  21. void IR_UpdateTime()
  22. {
  23. l_Time = GetTickCount();
  24. }
  25. //--------------------------------------------------------------------------
  26. // 功能:初始化结构数据
  27. //--------------------------------------------------------------------------
  28. void IR_InitUiImageRef(KUiImageRef& Img)
  29. {
  30. memset(&Img, 0, sizeof(KUiImageRef));
  31. Img.Color.Color_b.a = 255;
  32. }
  33. //--------------------------------------------------------------------------
  34. // 功能:初始化结构数据
  35. //--------------------------------------------------------------------------
  36. void IR_InitUiImagePartRef(KUiImagePartRef& Img)
  37. {
  38. memset(&Img, 0, sizeof(KUiImagePartRef));
  39. Img.Color.Color_b.a = 255;
  40. }
  41. int IR_IsTimePassed(unsigned int uInterval, unsigned int& uLastTimer)
  42. {
  43. if ((l_Time - uLastTimer) >= uInterval)
  44. {
  45. uLastTimer += uInterval;
  46. return 1;
  47. }
  48. return 0;
  49. }
  50. //获取剩余时间,如果时间已经到了/过了,返回值都为0
  51. unsigned int IR_GetRemainTime(unsigned int uInterval, unsigned int uLastTimer)
  52. {
  53. register unsigned int uRemain;
  54. if ((uRemain = l_Time - uLastTimer) < uInterval)
  55. return (uInterval - uRemain);
  56. return 0;
  57. }
  58. //--------------------------------------------------------------------------
  59. // 功能:换帧计算
  60. //--------------------------------------------------------------------------
  61. int IR_NextFrame(KUiImageRef& Img)
  62. {
  63. if (Img.nNumFrames > 1)
  64. {
  65. if ((l_Time - Img.nFlipTime) >= (DWORD)Img.nInterval)
  66. {
  67. Img.nFlipTime += Img.nInterval;
  68. if ((++Img.nFrame) >= Img.nNumFrames)
  69. {
  70. Img.nFlipTime = l_Time;
  71. Img.nFrame = 0;
  72. return true;
  73. }
  74. }
  75. }
  76. else if (Img.nNumFrames == 0)
  77. {
  78. KImageParam Param;
  79. Param.nNumFrames = 0;
  80. if (g_pRepresentShell)
  81. g_pRepresentShell->GetImageParam(Img.szImage, &Param, Img.nType);
  82. if (Param.nNumFrames > 0)
  83. {
  84. Img.nFlipTime  = l_Time;
  85. Img.nNumFrames = Param.nNumFrames;
  86. Img.nInterval = Param.nInterval;
  87. }
  88. else
  89. Img.nNumFrames = 1;
  90. return false;
  91. }
  92. return false;
  93. }
  94. //--------------------------------------------------------------------------
  95. // 功能:设置绘制图的局部
  96. //--------------------------------------------------------------------------
  97. void IR_UpdateImagePart(KUiImagePartRef& Img, int nPartValue, int nFullValue)
  98. {
  99. if (Img.Width == 0 && Img.szImage[0])
  100. {
  101. KImageParam Param;
  102. Param.nWidth = 0;
  103. if (g_pRepresentShell)
  104. g_pRepresentShell->GetImageParam(Img.szImage, &Param, Img.nType);
  105. Img.Width = Param.nWidth;
  106. Img.Height = Param.nHeight;
  107. if (Img.Width == 0 || Img.Height == 0)
  108. Img.szImage[0] = 0;
  109. }
  110. if (nPartValue >= nFullValue)
  111. {
  112. Img.oImgLTPos.nX = Img.oImgLTPos.nY = 0;
  113. Img.oImgRBPos.nX = Img.Width;
  114. Img.oImgRBPos.nY = Img.Height;
  115. return;
  116. }
  117. if (nPartValue < 0)
  118. {
  119. Img.oImgLTPos.nX = Img.oImgLTPos.nY =
  120. Img.oImgRBPos.nX = Img.oImgRBPos.nY = 0;
  121. return;
  122. }
  123. switch(Img.nDivideFashion)
  124. {
  125. case  IDF_RIGHT_TO_LEFT:
  126. Img.oImgLTPos.nY = 0;
  127. Img.oImgRBPos.nX = Img.Width;
  128. Img.oImgRBPos.nY = Img.Height;
  129. if (nFullValue)
  130. Img.oImgLTPos.nX = Img.Width - Img.Width * nPartValue / nFullValue;
  131. else
  132. Img.oImgLTPos.nX = 0;
  133. break;
  134. case IDF_TOP_TO_BOTTOM:
  135. Img.oImgLTPos.nX = 0;
  136. Img.oImgLTPos.nY = 0;
  137. Img.oImgRBPos.nX = Img.Width;
  138. if (nFullValue)
  139. Img.oImgRBPos.nY = Img.Height * nPartValue / nFullValue;
  140. else
  141. Img.oImgRBPos.nY = Img.Height;
  142. break;
  143. case IDF_BOTTOM_TO_TOP:
  144. Img.oImgLTPos.nX = 0;
  145. Img.oImgRBPos.nX = Img.Width;
  146. Img.oImgRBPos.nY = Img.Height;
  147. if (nFullValue)
  148. Img.oImgLTPos.nY = Img.Height - Img.Height * nPartValue / nFullValue;
  149. else
  150. Img.oImgLTPos.nY = 0;
  151. break;
  152. default: //include IDF_LEFT_TO_RIGHT
  153. Img.oImgLTPos.nX = 0;
  154. Img.oImgLTPos.nY = 0;
  155. Img.oImgRBPos.nY = Img.Height;
  156. if (nFullValue)
  157. Img.oImgRBPos.nX = Img.Width * nPartValue / nFullValue;
  158. else
  159. Img.oImgRBPos.nX = Img.Width;
  160. break;
  161. }
  162. }
  163. //--------------------------------------------------------------------------
  164. // 功能:绘制图形
  165. //--------------------------------------------------------------------------
  166. void IR_DrawImage(KUiImageRef* pImg)
  167. {
  168. if (g_pRepresentShell)
  169. g_pRepresentShell->DrawPrimitives(1, pImg, RU_T_IMAGE, true);
  170. }
  171. //--------------------------------------------------------------------------
  172. // 功能:绘制图形的局部
  173. //--------------------------------------------------------------------------
  174. void IR_DrawImagePart(KUiImagePartRef* pImg)
  175. {
  176. if (g_pRepresentShell)
  177. g_pRepresentShell->DrawPrimitives(1, pImg, RU_T_IMAGE_PART, true);
  178. }
  179. //--------------------------------------------------------------------------
  180. // 功能:获得图形资源的KSprite对象
  181. //--------------------------------------------------------------------------
  182. int IR_GetSpritePixcelAlpha(KUiImageRef& Img, int h, int v)
  183. {
  184. if (g_pRepresentShell)
  185. return g_pRepresentShell->GetImagePixelAlpha(Img.szImage, Img.nFrame, h, v, Img.nType);
  186. return 0;
  187. }
  188. //--------------------------------------------------------------------------
  189. // 功能:获得图像参考点(一般所说为重心)
  190. //--------------------------------------------------------------------------
  191. void IR_GetReferenceSpot(KUiImageRef& Img, int& h, int& v)
  192. {
  193. KImageParam Param;
  194. if (g_pRepresentShell && g_pRepresentShell->GetImageParam(Img.szImage, &Param, Img.nType))
  195. {
  196. h = Param.nReferenceSpotX;
  197. v = Param.nReferenceSpotY;
  198. }
  199. else
  200. {
  201. h = 0;
  202. v = 0;
  203. }
  204. }