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

模拟服务器

开发平台:

C/C++

  1. //////////////////////////////////////////////////////////////////////////////////////
  2. // 文件名 : TextPic.cpp
  3. // 创建人 : 王西贝
  4. // 创建时间 : 2003-6-22 23:13:12
  5. // 文件说明 : 文字嵌入式图片
  6. //////////////////////////////////////////////////////////////////////////////////////
  7. #include "KWin32.h"
  8. #include "TextPic.h"
  9. #include "KIniFile.h"
  10. #include "CrtDbg.h"
  11. #include "../../../Represent/iRepresent/iRepresentShell.h"
  12. #include "../../../Represent/iRepresent/KRepresentUnit.h"
  13. KInlinePicSink::KInlinePicSink()
  14. {
  15. m_pRepShell = NULL;
  16. }
  17. BOOL KInlinePicSink::Init(iRepresentShell* pShell)
  18. {
  19. m_pRepShell = pShell;
  20. if (!m_pRepShell)
  21. return FALSE;
  22. KIniFile ini;
  23. #define CHAR_BUFFER_LEN 32
  24. char szBuffer[CHAR_BUFFER_LEN], szPath[CHAR_BUFFER_LEN],
  25.  szIndex[4], szBuffer2[CHAR_BUFFER_LEN * 2];
  26. int nPicCount = 0, i = 0;
  27. KUiImageRef CurrentImg;
  28. KImageParam Param;
  29. if (!ini.Load("\Ui\ChatPics.ini"))
  30. return FALSE;
  31. ini.GetString("Main", "Path", "\spr\Ui\聊天\表情", szPath, CHAR_BUFFER_LEN);
  32. ini.GetInteger("Main", "Count", 0, &nPicCount);
  33. if (nPicCount > MAX_SYSTEM_INLINE_PICTURES)
  34. nPicCount = MAX_SYSTEM_INLINE_PICTURES;
  35. for (i = 0; i < nPicCount; i++)
  36. {
  37. sprintf(szIndex, "%d", i);
  38. if (!ini.GetString("Main", szIndex, "", szBuffer, CHAR_BUFFER_LEN))
  39. {
  40. _ASSERT(0);
  41. break;
  42. }
  43. strcpy(szBuffer2, szPath);
  44. strcat(szBuffer2, "\");
  45. strcat(szBuffer2, szBuffer);
  46. IR_InitUiImageRef(CurrentImg);
  47. CurrentImg.nFlipTime = 0;
  48. CurrentImg.nInterval = 0;
  49. CurrentImg.nNumFrames = 0;
  50. strncpy(CurrentImg.szImage, szBuffer2, sizeof(CurrentImg.szImage));
  51. CurrentImg.szImage[sizeof(CurrentImg.szImage) - 1] = 0;
  52. CurrentImg.bRenderFlag = RUIMAGE_RENDER_FLAG_REF_SPOT;
  53. CurrentImg.nType = ISI_T_SPR;
  54. memset(&Param, 0, sizeof(Param));
  55. pShell->GetImageParam(CurrentImg.szImage, &Param, CurrentImg.nType);
  56. m_Images.push_back(CurrentImg);
  57. m_ImageParams.push_back(Param);
  58. }
  59. if (FAILED(m_pRepShell->AdviseRepresent(this)))
  60. return FALSE;
  61. if (FAILED(AdviseEngine(this)))
  62. return FALSE;
  63. return TRUE;
  64. }
  65. BOOL KInlinePicSink::UnInit()
  66. {
  67. if (!m_pRepShell)
  68. return FALSE;
  69. if (FAILED(m_pRepShell->UnAdviseRepresent(this)))
  70. return FALSE;
  71. if (FAILED(UnAdviseEngine(this)))
  72. return FALSE;
  73. return TRUE;
  74. }
  75. long KInlinePicSink::GetPicSize(unsigned short wIndex, int& cx, int& cy)
  76. {
  77. _ASSERT(m_Images.size() == m_ImageParams.size() &&
  78. m_CustomImages.size() == m_CustomImageParams.size());
  79. if (!m_pRepShell ||
  80. wIndex < MAX_SYSTEM_INLINE_PICTURES && wIndex >= m_Images.size() ||
  81. wIndex >= MAX_SYSTEM_INLINE_PICTURES &&
  82. (wIndex - MAX_SYSTEM_INLINE_PICTURES >= m_CustomImages.size() ||
  83. !m_CustomImages[wIndex - MAX_SYSTEM_INLINE_PICTURES].szImage[0]))
  84. return E_FAIL;
  85. if (wIndex < MAX_SYSTEM_INLINE_PICTURES)
  86. {
  87. cx = m_ImageParams[wIndex].nWidth;
  88. cy = m_ImageParams[wIndex].nHeight;
  89. }
  90. else
  91. {
  92. cx = m_CustomImageParams[wIndex - MAX_SYSTEM_INLINE_PICTURES].nWidth;
  93. cy = m_CustomImageParams[wIndex - MAX_SYSTEM_INLINE_PICTURES].nHeight;
  94. }
  95. return S_OK;
  96. }
  97. long KInlinePicSink::DrawPic(unsigned short wIndex, int x, int y)
  98. {
  99. _ASSERT(m_Images.size() == m_ImageParams.size() &&
  100. m_CustomImages.size() == m_CustomImageParams.size());
  101. if (!m_pRepShell ||
  102. wIndex < MAX_SYSTEM_INLINE_PICTURES && wIndex >= m_Images.size() ||
  103. wIndex >= MAX_SYSTEM_INLINE_PICTURES &&
  104. (wIndex - MAX_SYSTEM_INLINE_PICTURES >= m_CustomImages.size() ||
  105. !m_CustomImages[wIndex - MAX_SYSTEM_INLINE_PICTURES].szImage[0]))
  106. return E_FAIL;
  107. KUiImageRef* pPic = NULL;
  108. if (wIndex < MAX_SYSTEM_INLINE_PICTURES)
  109. pPic = &(m_Images[wIndex]);
  110. else
  111. pPic = &(m_CustomImages[wIndex - MAX_SYSTEM_INLINE_PICTURES]);
  112. pPic->oPosition.nX = x;
  113. pPic->oPosition.nY = y;
  114. m_pRepShell->DrawPrimitives(1, pPic, RU_T_IMAGE, true);
  115. IR_NextFrame(*pPic);
  116. return S_OK;
  117. }
  118. //动态加载图片,获取一个WORD,即图片的索引
  119. long KInlinePicSink::AddCustomInlinePic(unsigned short& rwIndex, const char* szSprPathName)
  120. {
  121. KUiImageRef CurrentImg;
  122. KImageParam Param;
  123. int i = 0, nSize = 0;
  124. rwIndex = -1;
  125. if (!szSprPathName || !szSprPathName[0])
  126. return E_FAIL;
  127. IR_InitUiImageRef(CurrentImg);
  128. CurrentImg.nFlipTime = 0;
  129. CurrentImg.nInterval = 0;
  130. CurrentImg.nNumFrames = 0;
  131. strncpy(CurrentImg.szImage, szSprPathName, sizeof(CurrentImg.szImage));
  132. CurrentImg.szImage[sizeof(CurrentImg.szImage) - 1] = 0;
  133. CurrentImg.bRenderFlag = RUIMAGE_RENDER_FLAG_REF_SPOT;
  134. CurrentImg.nType = ISI_T_SPR;
  135. memset(&Param, 0, sizeof(Param));
  136. if (!m_pRepShell->GetImageParam(CurrentImg.szImage, &Param, CurrentImg.nType))
  137. return E_FAIL;
  138. for (i = 0, nSize = (int)m_CustomImages.size(); i < nSize; i++)
  139. {
  140. if (0 == m_CustomImages[i].szImage[0])
  141. {
  142. m_CustomImages[i] = CurrentImg;
  143. m_CustomImageParams[i] = Param;
  144. break;
  145. }
  146. }
  147. if (i >= nSize)
  148. {
  149. m_CustomImages.push_back(CurrentImg);
  150. m_CustomImageParams.push_back(Param);
  151. }
  152. rwIndex = i + MAX_SYSTEM_INLINE_PICTURES;
  153. return S_OK;
  154. }
  155. //动态卸载图片
  156. long KInlinePicSink::RemoveCustomInlinePic(unsigned short wIndex)
  157. {
  158. if (wIndex < MAX_SYSTEM_INLINE_PICTURES ||
  159. wIndex >= MAX_SYSTEM_INLINE_PICTURES &&
  160. (wIndex - MAX_SYSTEM_INLINE_PICTURES >= m_CustomImages.size() ||
  161. !m_CustomImages[wIndex - MAX_SYSTEM_INLINE_PICTURES].szImage[0]))
  162. return E_FAIL;
  163. m_CustomImages[wIndex - MAX_SYSTEM_INLINE_PICTURES].szImage[0] = 0;
  164. return S_OK;
  165. }