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

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 界面窗口体系结构--图形窗口
  3. // Copyright : Kingsoft 2002
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2002-7-25
  6. *****************************************************************************************/
  7. #include "KWin32.h"
  8. #include "KIniFile.h"
  9. #include "WndImage.h"
  10. #include "../../../Represent/iRepresent/iRepresentShell.h"
  11. extern iRepresentShell* g_pRepresentShell;
  12. //--------------------------------------------------------------------------
  13. // 功能:构造函数
  14. //--------------------------------------------------------------------------
  15. KWndImage::KWndImage()
  16. {
  17. IR_InitUiImageRef(m_Image);
  18. }
  19. void KWndImage::Clone(KWndImage* pCopy)
  20. {
  21. if (pCopy)
  22. {
  23. KWndWindow::Clone(pCopy);
  24. pCopy->m_Image = m_Image;
  25. }
  26. }
  27. //--------------------------------------------------------------------------
  28. // 功能:初始化窗口
  29. //--------------------------------------------------------------------------
  30. int KWndImage::Init(KIniFile* pIniFile, const char* pSection)
  31. {
  32. if (KWndWindow::Init(pIniFile, pSection))
  33. {
  34. int nValue = 0;
  35. pIniFile->GetInteger(pSection, "Trans", 0, &nValue);
  36. if (nValue)
  37. m_Style |= WNDIMG_ES_EXCLUDE_TRANS;
  38. else
  39. m_Style &= ~WNDIMG_ES_EXCLUDE_TRANS;
  40. m_Image.nFlipTime = 0;
  41. m_Image.nInterval = 0;
  42. m_Image.nNumFrames = 0;
  43. pIniFile->GetInteger(pSection, "ImgType", 0, &nValue);
  44. if (nValue == 1)
  45. {
  46. m_Image.nType = ISI_T_BITMAP16;
  47. m_Image.bRenderStyle = IMAGE_RENDER_STYLE_OPACITY;
  48. m_Style &= ~WNDIMG_ES_EXCLUDE_TRANS;
  49. }
  50. else
  51. {
  52. m_Image.nType = ISI_T_SPR;
  53. m_Image.bRenderStyle = IMAGE_RENDER_STYLE_ALPHA;
  54. m_Image.Color.Color_b.a = 255;
  55. }
  56. m_Image.uImage = 0;
  57. m_Image.nISPosition = IMAGE_IS_POSITION_INIT;
  58. pIniFile->GetString(pSection, "Image", "" , m_Image.szImage, sizeof(m_Image.szImage));
  59. if (pIniFile->GetInteger(pSection, "Frame", -1, &nValue) && nValue != -1)
  60. m_Image.nFrame = nValue;
  61. if ((m_Width == 0 || m_Height == 0) && g_pRepresentShell)
  62. {
  63. KImageParam Param = { 0 };
  64. if (g_pRepresentShell->GetImageParam(m_Image.szImage, &Param, m_Image.nType))
  65. {
  66. if (m_Width == 0)
  67. m_Width = Param.nWidth;
  68. if (m_Height == 0)
  69. m_Height = Param.nHeight;
  70. }
  71. }
  72. return true;
  73. }
  74. return false;
  75. }
  76. //--------------------------------------------------------------------------
  77. // 功能:判断一个点是否在窗口范围内,传入的是绝对坐标
  78. //--------------------------------------------------------------------------
  79. int KWndImage::PtInWindow(int x, int y)
  80. {
  81. int bIn = KWndWindow::PtInWindow(x, y);
  82. if ((bIn &&
  83. (m_Style & WND_S_SIZE_WITH_ALL_CHILD) == 0) || 
  84. ((m_Style & WND_S_VISIBLE) &&
  85. bIn == false &&
  86. (m_Style & WND_S_SIZE_WITH_ALL_CHILD)))
  87. {
  88. if ((m_Style & WNDIMG_ES_EXCLUDE_TRANS) && g_pRepresentShell)
  89. bIn =  g_pRepresentShell->GetImagePixelAlpha(m_Image.szImage, m_Image.nFrame, x - m_nAbsoluteLeft, y - m_nAbsoluteTop, m_Image.nType);
  90. }
  91. return bIn;
  92. }
  93. //--------------------------------------------------------------------------
  94. // 功能:设置图形帧
  95. //--------------------------------------------------------------------------
  96. void KWndImage::SetFrame(int nFrame)
  97. {
  98. m_Image.nFrame = nFrame;
  99. }
  100. void KWndImage::SetImage(short nType, const char* pszImgName, bool bAdjustWndSize)
  101. {
  102. m_Image.nType = nType;
  103. strncpy(m_Image.szImage, pszImgName, sizeof(m_Image.szImage));
  104. m_Image.szImage[sizeof(m_Image.szImage) - 1] = 0;
  105. m_Image.nNumFrames = 0;
  106. m_Image.uImage = 0;
  107. m_Image.nFlipTime = IR_GetCurrentTime();
  108. if (bAdjustWndSize && g_pRepresentShell)
  109. {
  110. KImageParam Param;
  111. if (g_pRepresentShell->GetImageParam(m_Image.szImage, &Param, nType))
  112. SetSize(Param.nWidth, Param.nHeight);
  113. }
  114. }
  115. void KWndImage::UpdateTimer()
  116. {
  117. m_Image.nFlipTime = IR_GetCurrentTime();
  118. }
  119. //--------------------------------------------------------------------------
  120. // 功能:图形换帧
  121. //--------------------------------------------------------------------------
  122. int KWndImage::NextFrame()
  123. {
  124. return IR_NextFrame(m_Image);
  125. }
  126. //--------------------------------------------------------------------------
  127. // 功能:窗体绘制
  128. //--------------------------------------------------------------------------
  129. void KWndImage::PaintWindow()
  130. {
  131. KWndWindow::PaintWindow();
  132. if (g_pRepresentShell)
  133. {
  134. m_Image.oPosition.nX = m_nAbsoluteLeft;
  135. m_Image.oPosition.nY = m_nAbsoluteTop;
  136. g_pRepresentShell->DrawPrimitives(1, &m_Image, RU_T_IMAGE, true);
  137. }
  138. }