LogDisplay.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //-------------------------------------------------------------------------------
  2. /**
  3. * This program is distributed under the terms of the GNU Lesser General
  4. * Public License (LGPL).
  5. *
  6. * ASSIMP Viewer Utility
  7. *
  8. */
  9. //-------------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "assimp_view.h"
  12. namespace AssimpView {
  13. /* extern */ CLogDisplay CLogDisplay::s_cInstance;
  14. //-------------------------------------------------------------------------------
  15. void CLogDisplay::AddEntry(const std::string& szText,
  16. const D3DCOLOR clrColor)
  17. {
  18. SEntry sNew;
  19. sNew.clrColor = clrColor;
  20. sNew.szText = szText;
  21. sNew.dwStartTicks = (DWORD)GetTickCount();
  22. this->asEntries.push_back(sNew);
  23. }
  24. //-------------------------------------------------------------------------------
  25. void CLogDisplay::ReleaseNativeResource()
  26. {
  27. if (this->piFont)
  28. {
  29. this->piFont->Release();
  30. this->piFont = NULL;
  31. }
  32. }
  33. //-------------------------------------------------------------------------------
  34. void CLogDisplay::RecreateNativeResource()
  35. {
  36. if (!this->piFont)
  37. {
  38. if (FAILED(D3DXCreateFont(g_piDevice,
  39. 16, //Font height
  40. 0, //Font width
  41. FW_BOLD, //Font Weight
  42. 1, //MipLevels
  43. false, //Italic
  44. DEFAULT_CHARSET, //CharSet
  45. OUT_DEFAULT_PRECIS, //OutputPrecision
  46. CLEARTYPE_QUALITY, //Quality
  47. DEFAULT_PITCH|FF_DONTCARE, //PitchAndFamily
  48. "Verdana", //pFacename,
  49. &this->piFont)))
  50. {
  51. CLogDisplay::Instance().AddEntry("Unable to load font",D3DCOLOR_ARGB(0xFF,0xFF,0,0));
  52. this->piFont = NULL;
  53. return;
  54. }
  55. }
  56. return;
  57. }
  58. //-------------------------------------------------------------------------------
  59. void CLogDisplay::OnRender()
  60. {
  61. DWORD dwTick = (DWORD) GetTickCount();
  62. DWORD dwLimit = dwTick - 8000;
  63. DWORD dwLimit2 = dwLimit + 3000;
  64. unsigned int iCnt = 0;
  65. RECT sRect;
  66. sRect.left = 0;
  67. sRect.top = 10;
  68. RECT sWndRect;
  69. GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sWndRect);
  70. sWndRect.right -= sWndRect.left;
  71. sWndRect.bottom -= sWndRect.top;
  72. sWndRect.left = sWndRect.top = 0;
  73. // if no asset is loaded draw a "no asset loaded" text in the center
  74. if (!g_pcAsset)
  75. {
  76. const char* szText = "No asset loaded\r\nUse [Viewer | Open asset] to load one";
  77. // shadow
  78. RECT sCopy;
  79. sCopy.left = sWndRect.left+1;
  80. sCopy.top = sWndRect.top+1;
  81. sCopy.bottom = sWndRect.bottom+1;
  82. sCopy.right = sWndRect.right+1;
  83. this->piFont->DrawText(NULL,szText ,
  84. -1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
  85. sCopy.left = sWndRect.left+1;
  86. sCopy.top = sWndRect.top+1;
  87. sCopy.bottom = sWndRect.bottom-1;
  88. sCopy.right = sWndRect.right-1;
  89. this->piFont->DrawText(NULL,szText ,
  90. -1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
  91. sCopy.left = sWndRect.left-1;
  92. sCopy.top = sWndRect.top-1;
  93. sCopy.bottom = sWndRect.bottom+1;
  94. sCopy.right = sWndRect.right+1;
  95. this->piFont->DrawText(NULL,szText ,
  96. -1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
  97. sCopy.left = sWndRect.left-1;
  98. sCopy.top = sWndRect.top-1;
  99. sCopy.bottom = sWndRect.bottom-1;
  100. sCopy.right = sWndRect.right-1;
  101. this->piFont->DrawText(NULL,szText ,
  102. -1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
  103. // text
  104. this->piFont->DrawText(NULL,szText ,
  105. -1,&sWndRect,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF));
  106. }
  107. sRect.right = sWndRect.right - 30;
  108. sRect.bottom = sWndRect.bottom;
  109. // update all elements in the queue and render them
  110. for (std::list<SEntry>::iterator
  111. i = this->asEntries.begin();
  112. i != this->asEntries.end();++i,++iCnt)
  113. {
  114. if ((*i).dwStartTicks < dwLimit)
  115. {
  116. i = this->asEntries.erase(i);
  117. if(i == this->asEntries.end())break;
  118. }
  119. else if (NULL != this->piFont)
  120. {
  121. float fAlpha = 1.0f;
  122. if ((*i).dwStartTicks <= dwLimit2)
  123. {
  124. // linearly interpolate to create the fade out effect
  125. fAlpha = 1.0f - (float)(dwLimit2 - (*i).dwStartTicks) / 3000.0f;
  126. }
  127. D3DCOLOR& clrColor = (*i).clrColor;
  128. clrColor &= ~(0xFFu << 24);
  129. clrColor |= (((unsigned char)(fAlpha * 255.0f)) & 0xFFu) << 24;
  130. const char* szText = (*i).szText.c_str();
  131. if (sRect.top + 30 > sWndRect.bottom)
  132. {
  133. // end of window. send a special message
  134. szText = "... too many errors";
  135. clrColor = D3DCOLOR_ARGB(0xFF,0xFF,100,0x0);
  136. }
  137. // draw the black shadow
  138. RECT sCopy;
  139. sCopy.left = sRect.left+1;
  140. sCopy.top = sRect.top+1;
  141. sCopy.bottom = sRect.bottom+1;
  142. sCopy.right = sRect.right+1;
  143. this->piFont->DrawText(NULL,szText,
  144. -1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
  145. (unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
  146. sCopy.left = sRect.left-1;
  147. sCopy.top = sRect.top-1;
  148. sCopy.bottom = sRect.bottom-1;
  149. sCopy.right = sRect.right-1;
  150. this->piFont->DrawText(NULL,szText,
  151. -1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
  152. (unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
  153. sCopy.left = sRect.left-1;
  154. sCopy.top = sRect.top-1;
  155. sCopy.bottom = sRect.bottom+1;
  156. sCopy.right = sRect.right+1;
  157. this->piFont->DrawText(NULL,szText,
  158. -1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
  159. (unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
  160. sCopy.left = sRect.left+1;
  161. sCopy.top = sRect.top+1;
  162. sCopy.bottom = sRect.bottom-1;
  163. sCopy.right = sRect.right-1;
  164. this->piFont->DrawText(NULL,szText,
  165. -1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
  166. (unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
  167. // draw the text itself
  168. int iPX = this->piFont->DrawText(NULL,szText,
  169. -1,&sRect,DT_RIGHT | DT_TOP,clrColor);
  170. sRect.top += iPX;
  171. sRect.bottom += iPX;
  172. if (szText != (*i).szText.c_str())break;
  173. }
  174. }
  175. return;
  176. }
  177. };