StdGrfx.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /* ==========================================================================
  2. File : StdGrfx.cpp
  3. Class : CStdGrfx
  4. Author : Johan Rosengren, Abstrakt Mekanik AB
  5. Date : 2004-03-31
  6. Purpose : Static graphics helper class. Will return pens and
  7. brushes in the current Windows colors. Will also draw
  8. some different kind of boxes, as they seem not to
  9. scale well. Neither does these, but better than
  10. Draw3dFrame et. al.
  11. Description :
  12. Usage :
  13. ========================================================================*/
  14. #include "stdafx.h"
  15. #include "stdgrfx.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. CPen CStdGrfx::s_shadowPen;
  22. CPen CStdGrfx::s_darkshadowPen;
  23. CPen CStdGrfx::s_lightPen;
  24. CPen CStdGrfx::s_highlightPen;
  25. CPen CStdGrfx::s_dialogPen;
  26. CPen CStdGrfx::s_windowPen;
  27. CPen CStdGrfx::s_scrollPen;
  28. CBrush CStdGrfx::s_dialogBrush;
  29. CBrush CStdGrfx::s_backgroundBrush;
  30. CBrush CStdGrfx::s_windowBrush;
  31. CBrush CStdGrfx::s_scrollBrush;
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CStdGrfx
  34. //
  35. CPen* CStdGrfx::shadowPen()
  36. /* ============================================================
  37. Function : CStdGrfx::shadowPen
  38. Description : Returns a pen with the current 3d shadow
  39. color (dark gray).
  40. Access : Public
  41. Return : CPen* - The pen
  42. Parameters : none
  43. Usage : Static function.
  44. ============================================================*/
  45. {
  46. if( CStdGrfx::s_shadowPen.m_hObject == NULL )
  47. CStdGrfx::s_shadowPen.CreatePen( PS_SOLID, 0, ::GetSysColor( COLOR_3DSHADOW ) );
  48. return &CStdGrfx::s_shadowPen;
  49. }
  50. CPen* CStdGrfx::darkshadowPen()
  51. /* ============================================================
  52. Function : CStdGrfx::darkshadowPen
  53. Description : Returns a pen with the current 3d dark
  54. shadow color (black).
  55. Access : Public
  56. Return : CPen* - The pen
  57. Parameters : none
  58. Usage : Static function.
  59. ============================================================*/
  60. {
  61. if( CStdGrfx::s_darkshadowPen.m_hObject == NULL )
  62. CStdGrfx::s_darkshadowPen.CreatePen( PS_SOLID, 0, ::GetSysColor( COLOR_3DDKSHADOW ) );
  63. return &CStdGrfx::s_darkshadowPen;
  64. }
  65. CPen* CStdGrfx::lightPen()
  66. /* ============================================================
  67. Function : CStdGrfx::lightPen
  68. Description : Returns a pen with the current 3d light
  69. color (light gray).
  70. Access : Public
  71. Return : CPen* - The pen
  72. Parameters : none
  73. Usage : Static function.
  74. ============================================================*/
  75. {
  76. if( CStdGrfx::s_lightPen.m_hObject == NULL )
  77. CStdGrfx::s_lightPen.CreatePen( PS_SOLID, 0, ::GetSysColor( COLOR_3DLIGHT ) );
  78. return &CStdGrfx::s_lightPen;
  79. }
  80. CPen* CStdGrfx::highlightPen()
  81. /* ============================================================
  82. Function : CStdGrfx::highlightPen
  83. Description : Returns a pen with the current 3d highligh
  84. color (white).
  85. Access : Public
  86. Return : CPen* - The pen
  87. Parameters : none
  88. Usage : Static function.
  89. ============================================================*/
  90. {
  91. if( CStdGrfx::s_highlightPen.m_hObject == NULL )
  92. CStdGrfx::s_highlightPen.CreatePen( PS_SOLID, 0, ::GetSysColor( COLOR_3DHILIGHT ) );
  93. return &CStdGrfx::s_highlightPen;
  94. }
  95. CPen* CStdGrfx::dialogPen()
  96. /* ============================================================
  97. Function : CStdGrfx::dialogPen
  98. Description : Returns a pen with the current dialog
  99. background color
  100. Access : Public
  101. Return : CPen* - The pen
  102. Parameters : none
  103. Usage : Static function.
  104. ============================================================*/
  105. {
  106. if( CStdGrfx::s_dialogPen.m_hObject == NULL )
  107. CStdGrfx::s_dialogPen.CreatePen( PS_SOLID, 0, ::GetSysColor( COLOR_3DFACE ) );
  108. return &CStdGrfx::s_dialogPen;
  109. }
  110. CPen* CStdGrfx::windowPen()
  111. /* ============================================================
  112. Function : CStdGrfx::windowPen
  113. Description : Returns a pen with the current window
  114. background color
  115. Access : Public
  116. Return : CPen* - The pen
  117. Parameters : none
  118. Usage : Static function.
  119. ============================================================*/
  120. {
  121. if( CStdGrfx::s_windowPen.m_hObject == NULL )
  122. CStdGrfx::s_windowPen.CreatePen( PS_SOLID, 0, ::GetSysColor( COLOR_WINDOW ) );
  123. return &CStdGrfx::s_windowPen;
  124. }
  125. CPen* CStdGrfx::scrollPen()
  126. /* ============================================================
  127. Function : CStdGrfx::scrollPen
  128. Description : Returns a pen with the current scrollbar
  129. background color
  130. Access : Public
  131. Return : CPen* - The pen
  132. Parameters : none
  133. Usage : Static function.
  134. ============================================================*/
  135. {
  136. if( CStdGrfx::s_scrollPen.m_hObject == NULL )
  137. CStdGrfx::s_scrollPen.CreatePen( PS_SOLID, 0, ::GetSysColor( COLOR_SCROLLBAR ) );
  138. return &CStdGrfx::s_scrollPen;
  139. }
  140. CBrush* CStdGrfx::dialogBrush()
  141. /* ============================================================
  142. Function : CStdGrfx::dialogBrush
  143. Description : Returns a brush with the current dialog
  144. color.
  145. Access : Public
  146. Return : CBrush* - The brush
  147. Parameters : none
  148. Usage : Static function.
  149. ============================================================*/
  150. {
  151. if( CStdGrfx::s_dialogBrush.m_hObject == NULL )
  152. CStdGrfx::s_dialogBrush.CreateSolidBrush( ::GetSysColor( COLOR_3DFACE ) );
  153. return &CStdGrfx::s_dialogBrush;
  154. }
  155. CBrush* CStdGrfx::windowBrush()
  156. /* ============================================================
  157. Function : CStdGrfx::windowBrush
  158. Description : Returns a brush with the current window
  159. color.
  160. Access : Public
  161. Return : CBrush* - The brush
  162. Parameters : none
  163. Usage : Static function.
  164. ============================================================*/
  165. {
  166. if( CStdGrfx::s_windowBrush.m_hObject == NULL )
  167. CStdGrfx::s_windowBrush.CreateSolidBrush( ::GetSysColor( COLOR_WINDOW ) );
  168. return &CStdGrfx::s_windowBrush;
  169. }
  170. CBrush* CStdGrfx::scrollBrush()
  171. /* ============================================================
  172. Function : CStdGrfx::scrollBrush
  173. Description : Returns a brush with the current scrollbar
  174. color.
  175. Access : Public
  176. Return : CBrush* - The brush
  177. Parameters : none
  178. Usage : Static function.
  179. ============================================================*/
  180. {
  181. if( CStdGrfx::s_scrollBrush.m_hObject == NULL )
  182. CStdGrfx::s_scrollBrush.CreateSolidBrush( ::GetSysColor( COLOR_SCROLLBAR ) );
  183. return &CStdGrfx::s_scrollBrush;
  184. }
  185. void CStdGrfx::drawframed3dBox( CDC* dc, CRect rect )
  186. /* ============================================================
  187. Function : CStdGrfx::drawframed3dBox
  188. Description : Draws a 3d rect with a black frame.
  189. Access : Public
  190. Return : void
  191. Parameters : CDC* dc - The "CDC" to draw to
  192. CRect rect - The rectangle to draw
  193. Usage : Static function.
  194. ============================================================*/
  195. {
  196. dc->SelectObject( CStdGrfx::darkshadowPen() );
  197. dc->SelectObject( CStdGrfx::dialogBrush() );
  198. dc->Rectangle( rect );
  199. rect.InflateRect( -1, -1 );
  200. CStdGrfx::draw3dFrame( dc, rect );
  201. dc->SelectStockObject( BLACK_PEN );
  202. dc->SelectStockObject( WHITE_BRUSH );
  203. }
  204. void CStdGrfx::drawsunkenframed3dWindow( CDC* dc, CRect rect )
  205. /* ============================================================
  206. Function : CStdGrfx::drawsunkenframed3dWindow
  207. Description : Draws a sunken 3d rect with a black frame.
  208. Access : Public
  209. Return : void
  210. Parameters : CDC* dc - The "CDC" to draw to
  211. CRect rect - The rectangle to draw
  212. Usage : Static function.
  213. ============================================================*/
  214. {
  215. dc->SelectObject( CStdGrfx::windowPen() );
  216. dc->SelectObject( CStdGrfx::windowBrush() );
  217. dc->Rectangle( rect );
  218. CStdGrfx::drawdoublesunken3dFrame( dc, rect );
  219. dc->SelectStockObject( BLACK_PEN );
  220. dc->SelectStockObject( WHITE_BRUSH );
  221. }
  222. void CStdGrfx::draw3dFrame( CDC* dc, CRect rect )
  223. /* ============================================================
  224. Function : CStdGrfx::draw3dFrame
  225. Description : Draws a 3d rect.
  226. Access : Public
  227. Return : void
  228. Parameters : CDC* dc - The "CDC" to draw to
  229. CRect rect - The rectangle to draw
  230. Usage : Static function.
  231. ============================================================*/
  232. {
  233. rect.InflateRect( 0, 0, -1, -1 );
  234. dc->SelectObject( CStdGrfx::highlightPen() );
  235. dc->MoveTo( rect.left, rect.bottom );
  236. dc->LineTo( rect.left, rect.top );
  237. dc->LineTo( rect.right , rect.top );
  238. dc->SelectObject( CStdGrfx::shadowPen() );
  239. dc->LineTo( rect.right , rect.bottom );
  240. dc->LineTo( rect.left, rect.bottom );
  241. dc->SelectStockObject( BLACK_PEN );
  242. }
  243. void CStdGrfx::drawsunken3dFrame( CDC* dc, CRect rect )
  244. /* ============================================================
  245. Function : CStdGrfx::drawsunken3dFrame
  246. Description : Draws a sunken 3d rect.
  247. Access : Public
  248. Return : void
  249. Parameters : CDC* dc - The "CDC" to draw to
  250. CRect rect - The rectangle to draw
  251. Usage : Static function.
  252. ============================================================*/
  253. {
  254. rect.InflateRect( 0, 0, -1, -1 );
  255. dc->SelectObject( CStdGrfx::shadowPen() );
  256. dc->MoveTo( rect.left, rect.bottom );
  257. dc->LineTo( rect.left, rect.top );
  258. dc->LineTo( rect.right , rect.top );
  259. dc->SelectObject( CStdGrfx::highlightPen() );
  260. dc->LineTo( rect.right , rect.bottom );
  261. dc->LineTo( rect.left, rect.bottom );
  262. dc->SelectStockObject( BLACK_PEN );
  263. }
  264. void CStdGrfx::drawdoublesunken3dFrame( CDC* dc, CRect rect )
  265. /* ============================================================
  266. Function : CStdGrfx::drawdoublesunken3dFrame
  267. Description : Draws a double sunken 3d rect.
  268. Access : Public
  269. Return : void
  270. Parameters : CDC* dc - The "CDC" to draw to
  271. CRect rect - The rectangle to draw
  272. Usage : Static function.
  273. ============================================================*/
  274. {
  275. rect.InflateRect( 0, 0, -1, -1 );
  276. dc->SelectObject( CStdGrfx::shadowPen() );
  277. dc->MoveTo( rect.left, rect.bottom );
  278. dc->LineTo( rect.left, rect.top );
  279. dc->LineTo( rect.right , rect.top );
  280. dc->SelectObject( CStdGrfx::highlightPen() );
  281. dc->LineTo( rect.right , rect.bottom );
  282. dc->LineTo( rect.left, rect.bottom );
  283. rect.InflateRect( -1, -1 );
  284. dc->SelectObject( CStdGrfx::darkshadowPen() );
  285. dc->MoveTo( rect.left, rect.bottom );
  286. dc->LineTo( rect.left, rect.top );
  287. dc->LineTo( rect.right , rect.top );
  288. dc->SelectObject( CStdGrfx::lightPen() );
  289. dc->LineTo( rect.right , rect.bottom );
  290. dc->LineTo( rect.left, rect.bottom );
  291. dc->SelectStockObject( BLACK_PEN );
  292. }