Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

255 wiersze
6.8 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. #include "richedit.h"
  37. namespace AssimpView {
  38. /* extern */ CLogWindow CLogWindow::s_cInstance;
  39. extern HKEY g_hRegistry;
  40. // header for the RTF log file
  41. static const char* AI_VIEW_RTF_LOG_HEADER =
  42. "{\\rtf1"
  43. "\\ansi"
  44. "\\deff0"
  45. "{"
  46. "\\fonttbl{\\f0 Courier New;}"
  47. "}"
  48. "{\\colortbl;"
  49. "\\red255\\green0\\blue0;" // red for errors
  50. "\\red255\\green120\\blue0;" // orange for warnings
  51. "\\red0\\green150\\blue0;" // green for infos
  52. "\\red0\\green0\\blue180;" // blue for debug messages
  53. "\\red0\\green0\\blue0;" // black for everything else
  54. "}}";
  55. //-------------------------------------------------------------------------------
  56. // Message procedure for the log window
  57. //-------------------------------------------------------------------------------
  58. INT_PTR CALLBACK LogDialogProc(HWND hwndDlg,UINT uMsg,
  59. WPARAM wParam,LPARAM lParam)
  60. {
  61. (void)lParam;
  62. switch (uMsg)
  63. {
  64. case WM_INITDIALOG:
  65. {
  66. return TRUE;
  67. }
  68. case WM_SIZE:
  69. {
  70. int x = LOWORD(lParam);
  71. int y = HIWORD(lParam);
  72. SetWindowPos(GetDlgItem(hwndDlg,IDC_EDIT1),NULL,0,0,
  73. x-10,y-12,SWP_NOMOVE|SWP_NOZORDER);
  74. return TRUE;
  75. }
  76. case WM_CLOSE:
  77. EndDialog(hwndDlg,0);
  78. CLogWindow::Instance().bIsVisible = false;
  79. return TRUE;
  80. };
  81. return FALSE;
  82. }
  83. //-------------------------------------------------------------------------------
  84. void CLogWindow::Init ()
  85. {
  86. this->hwnd = ::CreateDialog(g_hInstance,MAKEINTRESOURCE(IDD_LOGVIEW),
  87. NULL,&LogDialogProc);
  88. if (!this->hwnd)
  89. {
  90. CLogDisplay::Instance().AddEntry("[ERROR] Unable to create logger window",
  91. D3DCOLOR_ARGB(0xFF,0,0xFF,0));
  92. }
  93. // setup the log text
  94. this->szText = AI_VIEW_RTF_LOG_HEADER;;
  95. this->szPlainText = "";
  96. }
  97. //-------------------------------------------------------------------------------
  98. void CLogWindow::Show()
  99. {
  100. if (this->hwnd)
  101. {
  102. ShowWindow(this->hwnd,SW_SHOW);
  103. this->bIsVisible = true;
  104. // contents aren't updated while the logger isn't displayed
  105. this->Update();
  106. }
  107. }
  108. //-------------------------------------------------------------------------------
  109. void CMyLogStream::write(const char* message)
  110. {
  111. CLogWindow::Instance().WriteLine(message);
  112. }
  113. //-------------------------------------------------------------------------------
  114. void CLogWindow::Clear()
  115. {
  116. this->szText = AI_VIEW_RTF_LOG_HEADER;;
  117. this->szPlainText = "";
  118. this->Update();
  119. }
  120. //-------------------------------------------------------------------------------
  121. void CLogWindow::Update()
  122. {
  123. if (this->bIsVisible)
  124. {
  125. SETTEXTEX sInfo;
  126. sInfo.flags = ST_DEFAULT;
  127. sInfo.codepage = CP_ACP;
  128. SendDlgItemMessage(this->hwnd,IDC_EDIT1,
  129. EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM)this->szText.c_str());
  130. }
  131. }
  132. //-------------------------------------------------------------------------------
  133. void CLogWindow::Save()
  134. {
  135. char szFileName[MAX_PATH];
  136. DWORD dwTemp = MAX_PATH;
  137. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LogDestination",NULL,NULL,
  138. (BYTE*)szFileName,&dwTemp))
  139. {
  140. // Key was not found. Use C:
  141. strcpy(szFileName,"");
  142. }
  143. else
  144. {
  145. // need to remove the file name
  146. char* sz = strrchr(szFileName,'\\');
  147. if (!sz)sz = strrchr(szFileName,'/');
  148. if (!sz)*sz = 0;
  149. }
  150. OPENFILENAME sFilename1 = {
  151. sizeof(OPENFILENAME),
  152. g_hDlg,GetModuleHandle(NULL),
  153. "Log files\0*.txt", NULL, 0, 1,
  154. szFileName, MAX_PATH, NULL, 0, NULL,
  155. "Save log to file",
  156. OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
  157. 0, 1, ".txt", 0, NULL, NULL
  158. };
  159. if(GetSaveFileName(&sFilename1) == 0) return;
  160. // Now store the file in the registry
  161. RegSetValueExA(g_hRegistry,"LogDestination",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
  162. FILE* pFile = fopen(szFileName,"wt");
  163. fprintf(pFile,this->szPlainText.c_str());
  164. fclose(pFile);
  165. CLogDisplay::Instance().AddEntry("[INFO] The log file has been saved",
  166. D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
  167. }
  168. //-------------------------------------------------------------------------------
  169. void CLogWindow::WriteLine(const char* message)
  170. {
  171. this->szPlainText.append(message);
  172. this->szPlainText.append("\r\n");
  173. if (0 != this->szText.length())
  174. {
  175. this->szText.resize(this->szText.length()-1);
  176. }
  177. switch (message[0])
  178. {
  179. case 'e':
  180. case 'E':
  181. this->szText.append("{\\pard \\cf1 \\b \\fs18 ");
  182. break;
  183. case 'w':
  184. case 'W':
  185. this->szText.append("{\\pard \\cf2 \\b \\fs18 ");
  186. break;
  187. case 'i':
  188. case 'I':
  189. this->szText.append("{\\pard \\cf3 \\b \\fs18 ");
  190. break;
  191. case 'd':
  192. case 'D':
  193. this->szText.append("{\\pard \\cf4 \\b \\fs18 ");
  194. break;
  195. default:
  196. this->szText.append("{\\pard \\cf5 \\b \\fs18 ");
  197. break;
  198. }
  199. std::string _message = message;
  200. for (unsigned int i = 0; i < _message.length();++i)
  201. {
  202. if ('\\' == _message[i] ||
  203. '}' == _message[i] ||
  204. '{' == _message[i])
  205. {
  206. _message.insert(i++,"\\");
  207. }
  208. }
  209. this->szText.append(_message);
  210. this->szText.append("\\par}}");
  211. if (this->bIsVisible && this->bUpdate)
  212. {
  213. SETTEXTEX sInfo;
  214. sInfo.flags = ST_DEFAULT;
  215. sInfo.codepage = CP_ACP;
  216. SendDlgItemMessage(this->hwnd,IDC_EDIT1,
  217. EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM)this->szText.c_str());
  218. }
  219. return;
  220. }
  221. }; //! AssimpView