Source code of Windows XP (NT5)
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.

395 lines
12 KiB

  1. /******************************************************************************
  2. Source File: setdrw.c
  3. This file contains the code to draw the test bitmap
  4. Copyright (c) 1997-1998 by Microsoft Corporation
  5. Change History:
  6. Original version - ChrisW
  7. 12-01-97 AndreVa - Created It
  8. ******************************************************************************/
  9. #include "deskadp.h"
  10. /****************************************************************************
  11. FUNCTION: MakeRect
  12. PURPOSE: Fill in RECT structure given contents.
  13. ****************************************************************************/
  14. VOID MakeRect( PRECT pRect, INT xmin, INT ymin, INT xmax, INT ymax )
  15. {
  16. pRect->left= xmin;
  17. pRect->right= xmax;
  18. pRect->bottom= ymin;
  19. pRect->top= ymax;
  20. }
  21. // type constants for DrawArrow
  22. #define AW_TOP 1 // top
  23. #define AW_BOTTOM 2 // bottom
  24. #define AW_LEFT 3 // left
  25. #define AW_RIGHT 4 // right
  26. /****************************************************************************
  27. FUNCTION: DrawArrow
  28. PURPOSE: Draw one arrow in a given color.
  29. ****************************************************************************/
  30. static
  31. VOID DrawArrow( HDC hDC, INT type, INT xPos, INT yPos, COLORREF crPenColor )
  32. {
  33. INT shaftlen=30; // length of arrow shaft
  34. INT headlen=15; // height or width of arrow head (not length)
  35. HGDIOBJ hPen, hPrevPen = NULL; // pens
  36. INT x,y;
  37. INT xdir, ydir; // directions of x and y (1,-1)
  38. hPen= CreatePen( PS_SOLID, 1, crPenColor );
  39. if( hPen )
  40. hPrevPen= SelectObject( hDC, hPen );
  41. MoveToEx( hDC, xPos, yPos, NULL );
  42. xdir= ydir= 1; // defaults
  43. switch( type )
  44. {
  45. case AW_BOTTOM:
  46. ydir= -1;
  47. case AW_TOP:
  48. LineTo(hDC, xPos, yPos+ydir*shaftlen);
  49. for( x=0; x<3; x++ )
  50. {
  51. MoveToEx( hDC, xPos, yPos+ydir*x, NULL );
  52. LineTo( hDC, xPos-(headlen-x), yPos+ydir*headlen );
  53. MoveToEx( hDC, xPos, yPos+ydir*x, NULL );
  54. LineTo( hDC, xPos+(headlen-x), yPos+ydir*headlen );
  55. }
  56. break;
  57. case AW_RIGHT:
  58. xdir= -1;
  59. case AW_LEFT:
  60. LineTo( hDC, xPos + xdir*shaftlen, yPos );
  61. for( y=0; y<3; y++ )
  62. {
  63. MoveToEx( hDC, xPos + xdir*y, yPos, NULL );
  64. LineTo( hDC, xPos + xdir*headlen, yPos+(headlen-y));
  65. MoveToEx( hDC, xPos + xdir*y, yPos, NULL );
  66. LineTo( hDC, xPos + xdir*headlen, yPos-(headlen-y));
  67. }
  68. break;
  69. }
  70. if( hPrevPen )
  71. SelectObject( hDC, hPrevPen );
  72. if (hPen)
  73. DeleteObject(hPen);
  74. }
  75. /****************************************************************************
  76. FUNCTION: LabelRect
  77. PURPOSE: Label a rectangle with centered text given resource ID.
  78. ****************************************************************************/
  79. static
  80. VOID LabelRect(HDC hDC, PRECT pRect, UINT idString )
  81. {
  82. UINT iStatus;
  83. INT xStart, yStart;
  84. SIZE Size; // for size of string
  85. TCHAR szMsg[256];
  86. if( idString == 0 ) // make it easy to ignore call
  87. return;
  88. SetBkMode( hDC, OPAQUE );
  89. SetBkColor( hDC, RGB(0,0,0) );
  90. SetTextColor( hDC, RGB(255,255,255) );
  91. // center
  92. xStart= (pRect->left+pRect->right) /2;
  93. yStart= (pRect->top+pRect->bottom) /2;
  94. iStatus= LoadString( g_hInst, idString, szMsg, ARRAYSIZE(szMsg) );
  95. if( !iStatus )
  96. {
  97. return; // can't find string - print nothing
  98. }
  99. GetTextExtentPoint32( hDC, szMsg, lstrlen(szMsg), &Size );
  100. TextOut( hDC, xStart-Size.cx/2, yStart-Size.cy/2, szMsg, lstrlen(szMsg) );
  101. }
  102. /****************************************************************************
  103. FUNCTION: PaintRect
  104. PURPOSE: Color in a rectangle and label it.
  105. ****************************************************************************/
  106. static
  107. VOID PaintRect(
  108. HDC hDC, // DC to paint
  109. INT lowx, // coordinates describing rectangle to fill
  110. INT lowy, //
  111. INT highx, //
  112. INT highy, //
  113. COLORREF rgb, // color to fill in rectangle with
  114. UINT idString ) // resource ID to use to label or 0 is none
  115. {
  116. RECT rct;
  117. HBRUSH hBrush;
  118. MakeRect( &rct, lowx, lowy, highx, highy );
  119. hBrush = CreateSolidBrush( rgb );
  120. if (hBrush)
  121. {
  122. FillRect( hDC, &rct, hBrush );
  123. DeleteObject( hBrush );
  124. }
  125. LabelRect( hDC, &rct, idString );
  126. }
  127. /****************************************************************************
  128. FUNCTION: DrawArrows
  129. PURPOSE: Draw all the arrows showing edges of resolution.
  130. ****************************************************************************/
  131. VOID DrawArrows( HDC hDC, INT xRes, INT yRes )
  132. {
  133. INT dx,dy;
  134. INT x,y;
  135. COLORREF color= RGB(0,0,0); // color of arrow
  136. dx= xRes/8;
  137. dy= yRes/8;
  138. for( x=0; x<xRes; x += dx )
  139. {
  140. DrawArrow( hDC, AW_TOP, dx/2+x, 0, color );
  141. DrawArrow( hDC, AW_BOTTOM, dx/2+x, yRes-1, color );
  142. }
  143. for( y=0; y<yRes; y += dy )
  144. {
  145. DrawArrow( hDC, AW_LEFT, 0, dy/2+y, color );
  146. DrawArrow( hDC, AW_RIGHT, xRes-1, dy/2+y, color );
  147. }
  148. }
  149. /****************************************************************************
  150. FUNCTION: LabelResolution
  151. PURPOSE: Labels the resolution in a form a user may understand.
  152. FEATURE: We could label vertically too.
  153. ****************************************************************************/
  154. VOID LabelResolution( HDC hDC, INT xmin, INT ymin, INT xmax, INT ymax )
  155. {
  156. TCHAR szRes[120]; // text for resolution
  157. TCHAR szFmt[256]; // format string
  158. SIZE Size;
  159. INT iStatus;
  160. iStatus= LoadString( g_hInst, IDS_RESOLUTION_FMT, szFmt, ARRAYSIZE(szFmt) );
  161. if( !iStatus || iStatus==ARRAYSIZE(szFmt) )
  162. {
  163. lstrcpy(szFmt,TEXT("%d x %d")); // make sure we get something
  164. }
  165. wsprintf( szRes, szFmt, xmax, ymax );
  166. SetBkMode( hDC, TRANSPARENT );
  167. SetTextColor( hDC, RGB(0,0,0) );
  168. GetTextExtentPoint32( hDC, szRes, lstrlen(szRes), &Size );
  169. // Text near bottom of screen ~10 pixels from bottom
  170. TextOut( hDC, xmax/2 - Size.cx/2, ymax - 10-Size.cy, szRes, lstrlen(szRes) );
  171. }
  172. // table of resolutions that we show off.
  173. // if the resolution is larger, then we show that one too.
  174. typedef struct tagRESTAB {
  175. INT xRes;
  176. INT yRes;
  177. COLORREF crColor; // color to paint this resolution
  178. } RESTAB;
  179. RESTAB ResTab[] ={
  180. { 1600, 1200, RGB(255,0,0)},
  181. { 1280, 1024, RGB(0,255,0)},
  182. { 1152, 900, RGB(0,0,255)},
  183. { 1024, 768, RGB(255,0,0)},
  184. { 800, 600, RGB(0,255,0)},
  185. // 640x480 or 640x400 handled specially
  186. { 0, 0, 0} // end of table
  187. };
  188. /****************************************************************************
  189. FUNCTION: Set1152Mode
  190. PURPOSE: Set the height of the 1152 mode since it varies from card to
  191. card.
  192. ****************************************************************************/
  193. VOID Set1152Mode(int height)
  194. {
  195. ResTab[2].yRes = height;
  196. }
  197. /****************************************************************************
  198. FUNCTION: DrawBmp
  199. PURPOSE: Show off a fancy screen so the user has some idea
  200. of what will be seen given this resolution, colour
  201. depth and vertical refresh rate. Note that we do not
  202. try to simulate the font sizes.
  203. ****************************************************************************/
  204. VOID DrawBmp(HDC hDC)
  205. {
  206. INT nBpp; // bits per pixel
  207. INT nWidth; // width of screen in pixels
  208. INT nHeight; // height of screen in pixels
  209. INT xUsed,yUsed; // amount of x and y to use for dense bitmap
  210. INT dx,dy; // delta x and y for color bars
  211. RECT rct; // rectangle for passing bounds
  212. // HFONT hFont; // stock font for logfont
  213. // LOGFONT lf; // for creating new font
  214. HGDIOBJ hPrevFont=0; // previous font in DC
  215. HGDIOBJ hNewFont; // new font if possible
  216. HGDIOBJ hPrevPen; // previous pen handle
  217. INT x,y,i;
  218. INT off; // offset in dx units
  219. // try to use bigger better looking font
  220. //hFont= GetStockObject( DEVICE_DEFAULT_FONT );
  221. //GetObject( hFont, sizeof(LOGFONT), &lf );
  222. //lf.lfHeight= 30;
  223. //hNewFont= CreateFontIndirect( &lf );
  224. hNewFont = (HFONT)NULL;
  225. if( hNewFont ) // if no font, use old
  226. hPrevFont= SelectObject( hDC, hNewFont );
  227. // get surface information
  228. nBpp= GetDeviceCaps( hDC, BITSPIXEL ) * GetDeviceCaps( hDC, PLANES );
  229. nWidth= GetDeviceCaps( hDC, HORZRES );
  230. nHeight= GetDeviceCaps( hDC, VERTRES );
  231. // background for everything is yellow.
  232. PaintRect( hDC, 0,0,nWidth, nHeight, RGB(255,255,0),0 );
  233. LabelResolution( hDC, 0,0,nWidth, nHeight );
  234. // Background for various resolutions
  235. // biggest ones first
  236. for( i=0; ResTab[i].xRes !=0; i++ )
  237. {
  238. // Only draw if it will show
  239. if( ( nWidth>=ResTab[i].xRes ) | ( nHeight>=ResTab[i].yRes ) )
  240. {
  241. PaintRect(hDC,0,0,ResTab[i].xRes,ResTab[i].yRes,ResTab[i].crColor,0);
  242. LabelResolution( hDC, 0, 0, ResTab[i].xRes, ResTab[i].yRes);
  243. }
  244. }
  245. // color bars - only in standard vga area
  246. xUsed= min( nWidth, 640 ); // only use vga width
  247. yUsed= min( nHeight, 480 ); // could be 400 on some boards
  248. dx= xUsed/2;
  249. dy= yUsed/6;
  250. PaintRect( hDC, 0, 0, dx, dy*1, RGB(255,0,0), IDS_COLOR_RED );
  251. PaintRect( hDC, 0,dy*1, dx, dy*2, RGB(0,255,0), IDS_COLOR_GREEN );
  252. PaintRect( hDC, 0,dy*2, dx, dy*3, RGB(0,0,255), IDS_COLOR_BLUE );
  253. PaintRect( hDC, 0,dy*3, dx, dy*4, RGB(255,255,0 ),IDS_COLOR_YELLOW );
  254. PaintRect( hDC, 0,dy*4, dx, dy*5, RGB(255,0,255), IDS_COLOR_MAGENTA );
  255. PaintRect( hDC, 0,dy*5, dx, yUsed, RGB(0,255,255), IDS_COLOR_CYAN );
  256. // gradations of colors for true color detection
  257. for( x=dx; x<xUsed; x++ )
  258. {
  259. INT level;
  260. level= 255- ( 256*(x-dx) ) / dx;
  261. PaintRect( hDC, x, dy*0, x+1, dy*1, RGB( level,0,0 ),0 );
  262. PaintRect( hDC, x, dy*1, x+1, dy*2, RGB( 0,level,0 ),0 );
  263. PaintRect( hDC, x, dy*2, x+1, dy*3, RGB( 0,0,level ),0 );
  264. PaintRect( hDC, x, dy*5, x+1, dy*6, RGB( level,level,level), 0 );
  265. }
  266. MakeRect( &rct, dx,0,dx*2,dy*1 );
  267. LabelRect( hDC, &rct, IDS_RED_SHADES );
  268. MakeRect( &rct, dx,dy,dx*2,dy*2);
  269. LabelRect( hDC, &rct, IDS_GREEN_SHADES );
  270. MakeRect( &rct, dx,2*dy,dx*2,dy*3);
  271. LabelRect( hDC, &rct, IDS_BLUE_SHADES );
  272. MakeRect( &rct, dx,5*dy,dx*2,dy*6);
  273. LabelRect( hDC, &rct, IDS_GRAY_SHADES );
  274. // horizontal lines for interlace detection
  275. off= 3;
  276. PaintRect(hDC, dx,dy*off, xUsed, dy*(off+1),RGB(255,255,255),0 );// white
  277. hPrevPen= SelectObject( hDC, GetStockObject(BLACK_PEN) );
  278. for( y=dy*off; y<dy*(off+1); y= y+2 )
  279. {
  280. MoveToEx( hDC, dx, y, NULL );
  281. LineTo( hDC, dx*2, y );
  282. }
  283. SelectObject( hDC, hPrevPen );
  284. MakeRect( &rct, dx, dy*off, dx*2, dy*(off+1) );
  285. LabelRect( hDC, &rct, IDS_PATTERN_HORZ );
  286. // vertical lines for bad dac detection
  287. off= 4;
  288. PaintRect(hDC, dx,dy*off, xUsed,dy*(off+1), RGB(255,255,255),0 ); // white
  289. hPrevPen= SelectObject( hDC, GetStockObject(BLACK_PEN) );
  290. for( x=dx; x<xUsed; x= x+2 )
  291. {
  292. MoveToEx( hDC, x, dy*off, NULL );
  293. LineTo( hDC, x, dy*(off+1) );
  294. }
  295. SelectObject( hDC, hPrevPen );
  296. MakeRect( &rct, dx, dy*off, dx*2, dy*(off+1) );
  297. LabelRect( hDC, &rct, IDS_PATTERN_VERT );
  298. DrawArrows( hDC, nWidth, nHeight );
  299. LabelResolution(hDC, 0,0, xUsed, yUsed );
  300. // delete created font if one was created
  301. if( hPrevFont )
  302. {
  303. hPrevFont= SelectObject( hDC, hPrevFont );
  304. DeleteObject( hPrevFont );
  305. }
  306. }