You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

236 lines
7.2 KiB

  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. #include "stdafx.h"
  35. #include "assimp_view.h"
  36. namespace AssimpView {
  37. /* extern */ CLogDisplay CLogDisplay::s_cInstance;
  38. //-------------------------------------------------------------------------------
  39. void CLogDisplay::AddEntry(const std::string& szText,
  40. const D3DCOLOR clrColor)
  41. {
  42. SEntry sNew;
  43. sNew.clrColor = clrColor;
  44. sNew.szText = szText;
  45. sNew.dwStartTicks = (DWORD)GetTickCount();
  46. this->asEntries.push_back(sNew);
  47. }
  48. //-------------------------------------------------------------------------------
  49. void CLogDisplay::ReleaseNativeResource()
  50. {
  51. if (this->piFont)
  52. {
  53. this->piFont->Release();
  54. this->piFont = NULL;
  55. }
  56. }
  57. //-------------------------------------------------------------------------------
  58. void CLogDisplay::RecreateNativeResource()
  59. {
  60. if (!this->piFont)
  61. {
  62. if (FAILED(D3DXCreateFont(g_piDevice,
  63. 16, //Font height
  64. 0, //Font width
  65. FW_BOLD, //Font Weight
  66. 1, //MipLevels
  67. false, //Italic
  68. DEFAULT_CHARSET, //CharSet
  69. OUT_DEFAULT_PRECIS, //OutputPrecision
  70. //CLEARTYPE_QUALITY, //Quality
  71. 5, //Quality
  72. DEFAULT_PITCH|FF_DONTCARE, //PitchAndFamily
  73. "Verdana", //pFacename,
  74. &this->piFont)))
  75. {
  76. CLogDisplay::Instance().AddEntry("Unable to load font",D3DCOLOR_ARGB(0xFF,0xFF,0,0));
  77. this->piFont = NULL;
  78. return;
  79. }
  80. }
  81. return;
  82. }
  83. //-------------------------------------------------------------------------------
  84. void CLogDisplay::OnRender()
  85. {
  86. DWORD dwTick = (DWORD) GetTickCount();
  87. DWORD dwLimit = dwTick - 8000;
  88. DWORD dwLimit2 = dwLimit + 3000;
  89. unsigned int iCnt = 0;
  90. RECT sRect;
  91. sRect.left = 10;
  92. sRect.top = 10;
  93. RECT sWndRect;
  94. GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sWndRect);
  95. sWndRect.right -= sWndRect.left;
  96. sWndRect.bottom -= sWndRect.top;
  97. sWndRect.left = sWndRect.top = 0;
  98. sRect.right = sWndRect.right - 30;
  99. sRect.bottom = sWndRect.bottom;
  100. // if no asset is loaded draw a "no asset loaded" text in the center
  101. if (!g_pcAsset)
  102. {
  103. const char* szText = "Nothing to display ... \r\nTry [Viewer | Open asset] to load an asset";
  104. // shadow
  105. RECT sCopy;
  106. sCopy.left = sWndRect.left+1;
  107. sCopy.top = sWndRect.top+1;
  108. sCopy.bottom = sWndRect.bottom+1;
  109. sCopy.right = sWndRect.right+1;
  110. this->piFont->DrawText(NULL,szText ,
  111. -1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
  112. sCopy.left = sWndRect.left+1;
  113. sCopy.top = sWndRect.top+1;
  114. sCopy.bottom = sWndRect.bottom-1;
  115. sCopy.right = sWndRect.right-1;
  116. this->piFont->DrawText(NULL,szText ,
  117. -1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
  118. sCopy.left = sWndRect.left-1;
  119. sCopy.top = sWndRect.top-1;
  120. sCopy.bottom = sWndRect.bottom+1;
  121. sCopy.right = sWndRect.right+1;
  122. this->piFont->DrawText(NULL,szText ,
  123. -1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
  124. sCopy.left = sWndRect.left-1;
  125. sCopy.top = sWndRect.top-1;
  126. sCopy.bottom = sWndRect.bottom-1;
  127. sCopy.right = sWndRect.right-1;
  128. this->piFont->DrawText(NULL,szText ,
  129. -1,&sCopy,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(100,0x0,0x0,0x0));
  130. // text
  131. this->piFont->DrawText(NULL,szText ,
  132. -1,&sWndRect,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF));
  133. }
  134. // update all elements in the queue and render them
  135. for (std::list<SEntry>::iterator
  136. i = this->asEntries.begin();
  137. i != this->asEntries.end();++i,++iCnt)
  138. {
  139. if ((*i).dwStartTicks < dwLimit)
  140. {
  141. i = this->asEntries.erase(i);
  142. if(i == this->asEntries.end())break;
  143. }
  144. else if (NULL != this->piFont)
  145. {
  146. float fAlpha = 1.0f;
  147. if ((*i).dwStartTicks <= dwLimit2)
  148. {
  149. // linearly interpolate to create the fade out effect
  150. fAlpha = 1.0f - (float)(dwLimit2 - (*i).dwStartTicks) / 3000.0f;
  151. }
  152. D3DCOLOR& clrColor = (*i).clrColor;
  153. clrColor &= ~(0xFFu << 24);
  154. clrColor |= (((unsigned char)(fAlpha * 255.0f)) & 0xFFu) << 24;
  155. const char* szText = (*i).szText.c_str();
  156. if (sRect.top + 30 > sWndRect.bottom)
  157. {
  158. // end of window. send a special message
  159. szText = "... too many errors";
  160. clrColor = D3DCOLOR_ARGB(0xFF,0xFF,100,0x0);
  161. }
  162. // draw the black shadow
  163. RECT sCopy;
  164. sCopy.left = sRect.left+1;
  165. sCopy.top = sRect.top+1;
  166. sCopy.bottom = sRect.bottom+1;
  167. sCopy.right = sRect.right+1;
  168. this->piFont->DrawText(NULL,szText,
  169. -1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
  170. (unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
  171. sCopy.left = sRect.left-1;
  172. sCopy.top = sRect.top-1;
  173. sCopy.bottom = sRect.bottom-1;
  174. sCopy.right = sRect.right-1;
  175. this->piFont->DrawText(NULL,szText,
  176. -1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
  177. (unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
  178. sCopy.left = sRect.left-1;
  179. sCopy.top = sRect.top-1;
  180. sCopy.bottom = sRect.bottom+1;
  181. sCopy.right = sRect.right+1;
  182. this->piFont->DrawText(NULL,szText,
  183. -1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
  184. (unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
  185. sCopy.left = sRect.left+1;
  186. sCopy.top = sRect.top+1;
  187. sCopy.bottom = sRect.bottom-1;
  188. sCopy.right = sRect.right-1;
  189. this->piFont->DrawText(NULL,szText,
  190. -1,&sCopy,DT_RIGHT | DT_TOP,D3DCOLOR_ARGB(
  191. (unsigned char)(fAlpha * 100.0f),0x0,0x0,0x0));
  192. // draw the text itself
  193. int iPX = this->piFont->DrawText(NULL,szText,
  194. -1,&sRect,DT_RIGHT | DT_TOP,clrColor);
  195. sRect.top += iPX;
  196. sRect.bottom += iPX;
  197. if (szText != (*i).szText.c_str())break;
  198. }
  199. }
  200. return;
  201. }
  202. };