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.

291 lines
8.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <color.h>
  8. #include <vgui/IPanel.h>
  9. #include <vgui/ISurface.h>
  10. #include <vgui_controls/Image.h>
  11. #include <vgui_controls/Controls.h>
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. using namespace vgui;
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Conctructor. Start with default position and default color.
  17. //-----------------------------------------------------------------------------
  18. Image::Image()
  19. {
  20. SetPos(0,0);
  21. SetSize(0,0);
  22. SetColor(Color(255,255,255,255));
  23. }
  24. //-----------------------------------------------------------------------------
  25. // Purpose: Destructor
  26. //-----------------------------------------------------------------------------
  27. Image::~Image()
  28. {
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Set the position of the image, you need to reset this every time you
  32. // call Paint()
  33. //-----------------------------------------------------------------------------
  34. void Image::SetPos(int x,int y)
  35. {
  36. _pos[0]=x;
  37. _pos[1]=y;
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose: Get the position of the image
  41. //-----------------------------------------------------------------------------
  42. void Image::GetPos(int& x,int& y)
  43. {
  44. x=_pos[0];
  45. y=_pos[1];
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Purpose: Get the size of the image
  49. //-----------------------------------------------------------------------------
  50. void Image::GetSize(int &wide, int &tall)
  51. {
  52. wide = _size[0];
  53. tall = _size[1];
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose: Gets the size of the image contents (by default the set size)
  57. //-----------------------------------------------------------------------------
  58. void Image::GetContentSize(int &wide, int &tall)
  59. {
  60. GetSize(wide, tall);
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose: Set the size of the image
  64. //-----------------------------------------------------------------------------
  65. void Image::SetSize(int wide, int tall)
  66. {
  67. _size[0]=wide;
  68. _size[1]=tall;
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Purpose: Set the draw color using a Color struct.
  72. //-----------------------------------------------------------------------------
  73. void Image::DrawSetColor(Color col)
  74. {
  75. surface()->DrawSetColor(col[0], col[1], col[2], col[3]);
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose: Set the draw color using RGBA ints
  79. //-----------------------------------------------------------------------------
  80. void Image::DrawSetColor(int r,int g,int b,int a)
  81. {
  82. surface()->DrawSetColor(r,g,b,a);
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Purpose: Draw a filled rectangle
  86. //-----------------------------------------------------------------------------
  87. void Image::DrawFilledRect(int x0,int y0,int x1,int y1)
  88. {
  89. x0+=_pos[0];
  90. y0+=_pos[1];
  91. x1+=_pos[0];
  92. y1+=_pos[1];
  93. surface()->DrawFilledRect(x0,y0,x1,y1);
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Draw an outlined rectangle
  97. //-----------------------------------------------------------------------------
  98. void Image::DrawOutlinedRect(int x0,int y0,int x1,int y1)
  99. {
  100. x0+=_pos[0];
  101. y0+=_pos[1];
  102. x1+=_pos[0];
  103. y1+=_pos[1];
  104. surface()->DrawOutlinedRect(x0,y0,x1,y1);
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Purpose: Draw a line between two points
  108. //-----------------------------------------------------------------------------
  109. void Image::DrawLine(int x0,int y0,int x1,int y1)
  110. {
  111. x0+=_pos[0];
  112. y0+=_pos[1];
  113. x1+=_pos[0];
  114. y1+=_pos[1];
  115. surface()->DrawLine(x0,y0,x1,y1);
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Purpose: Draw a line between a list of 'numPoints' points
  119. //-----------------------------------------------------------------------------
  120. void Image::DrawPolyLine(int *px, int *py, int numPoints)
  121. {
  122. // update the positions to be relative to this panel
  123. for(int i=0;i<numPoints;i++)
  124. {
  125. px[i] += _pos[0];
  126. py[i] += _pos[1];
  127. }
  128. surface()->DrawPolyLine(px, py, numPoints);
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose: Set the font
  132. //-----------------------------------------------------------------------------
  133. void Image::DrawSetTextFont(HFont font)
  134. {
  135. surface()->DrawSetTextFont(font);
  136. }
  137. //-----------------------------------------------------------------------------
  138. // Purpose: Set the text color using a color struct
  139. //-----------------------------------------------------------------------------
  140. void Image::DrawSetTextColor(Color sc)
  141. {
  142. surface()->DrawSetTextColor(sc[0], sc[1], sc[2], sc[3]);
  143. }
  144. //-----------------------------------------------------------------------------
  145. // Purpose: Set the text color useing RGBA ints
  146. //-----------------------------------------------------------------------------
  147. void Image::DrawSetTextColor(int r,int g,int b,int a)
  148. {
  149. surface()->DrawSetTextColor(r,g,b,a);
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Purpose: Set the text position
  153. //-----------------------------------------------------------------------------
  154. void Image::DrawSetTextPos(int x,int y)
  155. {
  156. x+=_pos[0];
  157. y+=_pos[1];
  158. surface()->DrawSetTextPos(x,y);
  159. }
  160. //-----------------------------------------------------------------------------
  161. // Purpose: Draw a text string
  162. //-----------------------------------------------------------------------------
  163. void Image::DrawPrintText(const wchar_t *str,int strlen)
  164. {
  165. surface()->DrawPrintText(str, strlen);
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Purpose: Draw a text string at the given coords.
  169. //-----------------------------------------------------------------------------
  170. void Image::DrawPrintText(int x, int y, const wchar_t *str, int strlen)
  171. {
  172. x += _pos[0];
  173. y += _pos[1];
  174. surface()->DrawSetTextPos(x, y);
  175. surface()->DrawPrintText(str, strlen);
  176. }
  177. //-----------------------------------------------------------------------------
  178. // Purpose: Draw a character
  179. //-----------------------------------------------------------------------------
  180. void Image::DrawPrintChar(wchar_t ch)
  181. {
  182. surface()->DrawUnicodeChar(ch);
  183. }
  184. //-----------------------------------------------------------------------------
  185. // Purpose: Draw a character at the given coords
  186. //-----------------------------------------------------------------------------
  187. void Image::DrawPrintChar(int x, int y, wchar_t ch)
  188. {
  189. x+=_pos[0];
  190. y+=_pos[1];
  191. surface()->DrawSetTextPos(x, y);
  192. surface()->DrawUnicodeChar(ch);
  193. }
  194. //-----------------------------------------------------------------------------
  195. // Purpose: Set a texture
  196. //-----------------------------------------------------------------------------
  197. void Image::DrawSetTexture(int id)
  198. {
  199. surface()->DrawSetTexture(id);
  200. }
  201. //-----------------------------------------------------------------------------
  202. // Purpose: Draw a rectangle filled with the current texture
  203. //-----------------------------------------------------------------------------
  204. void Image::DrawTexturedRect(int x0,int y0,int x1,int y1)
  205. {
  206. surface()->DrawTexturedRect(x0,y0,x1,y1);
  207. }
  208. //-----------------------------------------------------------------------------
  209. // Purpose: Paint the contents of the image on screen.
  210. // You must call this explicitly each frame.
  211. //-----------------------------------------------------------------------------
  212. void Image::Paint()
  213. {
  214. }
  215. //-----------------------------------------------------------------------------
  216. // Purpose: Set the current color using a color struct
  217. //-----------------------------------------------------------------------------
  218. void Image::SetColor(Color color)
  219. {
  220. _color=color;
  221. DrawSetTextColor(color); // now update the device context underneath us :)
  222. }
  223. //-----------------------------------------------------------------------------
  224. // Purpose: Get the current color as a color struct
  225. //-----------------------------------------------------------------------------
  226. Color Image::GetColor()
  227. {
  228. return _color;
  229. }
  230. bool Image::Evict()
  231. {
  232. return false;
  233. }
  234. int Image::GetNumFrames()
  235. {
  236. return 0;
  237. }
  238. void Image::SetFrame( int nFrame )
  239. {
  240. }
  241. HTexture Image::GetID()
  242. {
  243. return 0;
  244. }
  245. int Image::GetTall()
  246. {
  247. return _size[1];
  248. }
  249. int Image::GetWide()
  250. {
  251. return _size[0];
  252. }