Counter Strike : Global Offensive Source Code
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.

186 lines
5.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implementation of IEditorTexture interface for placeholder textures.
  4. // Placeholder textures are used for textures that are referenced in
  5. // the map file but not found in storage.
  6. //
  7. //=============================================================================//
  8. #include "stdafx.h"
  9. #include <process.h>
  10. #include <afxtempl.h>
  11. #include <io.h>
  12. #include <sys\stat.h>
  13. #include <fcntl.h>
  14. #include "DummyTexture.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include <tier0/memdbgon.h>
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Constructor.
  19. //-----------------------------------------------------------------------------
  20. CDummyTexture::CDummyTexture(const char *pszName, TEXTUREFORMAT eFormat)
  21. {
  22. if (pszName != NULL)
  23. {
  24. strcpy(m_szName, pszName);
  25. }
  26. else
  27. {
  28. strcpy(m_szName, "Missing texture");
  29. }
  30. m_eTextureFormat = eFormat;
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Purpose: Destructor.
  34. //-----------------------------------------------------------------------------
  35. CDummyTexture::~CDummyTexture()
  36. {
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose: Returns an empty string, since we have no source file.
  40. //-----------------------------------------------------------------------------
  41. const char *CDummyTexture::GetFileName() const
  42. {
  43. static char *pszEmpty = "";
  44. return(pszEmpty);
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose: Returns a string of comma delimited keywords associated with this
  48. // material.
  49. // Input : pszKeywords - Buffer to receive keywords, NULL to query string length.
  50. // Output : Returns the number of characters in the keyword string.
  51. //-----------------------------------------------------------------------------
  52. int CDummyTexture::GetKeywords(char *pszKeywords) const
  53. {
  54. if (pszKeywords != NULL)
  55. {
  56. *pszKeywords = '\0';
  57. }
  58. return(0);
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. // Input : *pszName -
  63. // Output :
  64. //-----------------------------------------------------------------------------
  65. // dvs: move into a common place for CWADTexture & CDummyTexture
  66. int CDummyTexture::GetShortName(char *pszName) const
  67. {
  68. char szBuf[MAX_PATH];
  69. if (pszName == NULL)
  70. {
  71. pszName = szBuf;
  72. }
  73. if (m_eTextureFormat == tfWAL)
  74. {
  75. const char *psz = strstr(m_szName, "textures");
  76. if (psz == NULL)
  77. {
  78. psz = m_szName;
  79. }
  80. else
  81. {
  82. psz += strlen("textures\\");
  83. }
  84. strcpy(pszName, psz);
  85. // remove extension
  86. char *pszExtension = strstr(pszName, ".wal");
  87. if (pszExtension)
  88. {
  89. *pszExtension = 0;
  90. }
  91. }
  92. else
  93. {
  94. strcpy(pszName, m_szName);
  95. }
  96. return(strlen(pszName));
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Purpose: If the buffer pointer passed in is not NULL, copies the image data
  100. // in RGB format to the buffer
  101. // Input : pImageRGB - Pointer to buffer that receives the image data. If the
  102. // pointer is NULL, no data is copied, only the data size is returned.
  103. // Output : Returns a the size of the RGB image in bytes.
  104. //-----------------------------------------------------------------------------
  105. int CDummyTexture::GetImageDataRGB( void *pImageRGB )
  106. {
  107. return(0);
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose: If the buffer pointer passed in is not NULL, copies the image data
  111. // in RGBA format to the buffer
  112. // Input : pImageRGBA - Pointer to buffer that receives the image data. If the
  113. // pointer is NULL, no data is copied, only the data size is returned.
  114. // Output : Returns a the size of the RGBA image in bytes.
  115. //-----------------------------------------------------------------------------
  116. int CDummyTexture::GetImageDataRGBA( void *pImageRGBA )
  117. {
  118. return(0);
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose:
  122. // Input : size -
  123. //-----------------------------------------------------------------------------
  124. void CDummyTexture::GetSize( SIZE &size ) const
  125. {
  126. size.cx = 0;
  127. size.cy = 0;
  128. }
  129. //-----------------------------------------------------------------------------
  130. // Purpose: Renders "No Image" into a device context as a placeholder for the
  131. // missing texture.
  132. // Input : pDC -
  133. // rect -
  134. // iFontHeight -
  135. // dwFlags -
  136. //-----------------------------------------------------------------------------
  137. void CDummyTexture::Draw(CDC *pDC, RECT &rect, int iFontHeight, int iIconHeight, DrawTexData_t &DrawTexData)
  138. {
  139. CFont *pOldFont = (CFont *)pDC->SelectStockObject(ANSI_VAR_FONT);
  140. COLORREF crText = pDC->SetTextColor(RGB(0xff, 0xff, 0xff));
  141. COLORREF crBack = pDC->SetBkColor(RGB(0, 0, 0));
  142. pDC->FillRect(&rect, CBrush::FromHandle(HBRUSH(GetStockObject(BLACK_BRUSH))));
  143. pDC->TextOut(rect.left + 2, rect.top + 2, "No Image", 8);
  144. pDC->SelectObject(pOldFont);
  145. pDC->SetTextColor(crText);
  146. pDC->SetBkColor(crBack);
  147. }
  148. //-----------------------------------------------------------------------------
  149. // Purpose: Loads this texture from disk if it is not already loaded.
  150. // Output : Returns true on success, false on failure.
  151. //-----------------------------------------------------------------------------
  152. bool CDummyTexture::Load( void )
  153. {
  154. return(true);
  155. }