home *** CD-ROM | disk | FTP | other *** search
/ Learn 3D Graphics Programming on the PC / Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso / rwwin / gdi3d.c_ / gdi3d.bin
Text File  |  1995-11-14  |  4KB  |  134 lines

  1. /**********************************************************************
  2.  *
  3.  * File :     gdi3d.c
  4.  *
  5.  * Abstract : RenderWare Shop demo. GDI utility functions for drawing 
  6.  *            3D shapes.
  7.  *
  8.  **********************************************************************
  9.  *
  10.  * This file is a product of Criterion Software Ltd.
  11.  *
  12.  * This file is provided as is with no warranties of any kind and is
  13.  * provided without any obligation on Criterion Software Ltd. or
  14.  * Canon Inc. to assist in its use or modification.
  15.  *
  16.  * Criterion Software Ltd. will not, under any
  17.  * circumstances, be liable for any lost revenue or other damages arising
  18.  * from the use of this file.
  19.  *
  20.  * Copyright (c) 1995 Criterion Software Ltd.
  21.  * All Rights Reserved.
  22.  *
  23.  * RenderWare is a trademark of Canon Inc.
  24.  *
  25.  ************************************************************************/
  26. /**********************************************************************
  27.  *
  28.  * Include files.
  29.  *
  30.  **********************************************************************/
  31.  
  32. #include <windows.h>
  33.  
  34. /**********************************************************************
  35.  *
  36.  * Draw a 3D rectangle.
  37.  *
  38.  **********************************************************************/
  39.  
  40. BOOL
  41. Rectangle3D(HDC hdc, int left, int top, int right, int bottom, BOOL out)
  42. {
  43.     HPEN oldPen;
  44.     HPEN topLeftPen;
  45.     HPEN bottomRightPen;
  46.     HBRUSH oldBrush;
  47.     HBRUSH faceBrush;
  48.  
  49.     topLeftPen = CreatePen(PS_SOLID, 1, GetSysColor((out ? COLOR_BTNHIGHLIGHT : COLOR_BTNSHADOW)));
  50.     if (!topLeftPen)
  51.         return FALSE;
  52.  
  53.     bottomRightPen = CreatePen(PS_SOLID, 1, GetSysColor((out ? COLOR_BTNSHADOW : COLOR_BTNHIGHLIGHT)));
  54.     if (!bottomRightPen)
  55.     {
  56.         DeleteObject(topLeftPen);
  57.         return FALSE;
  58.     }
  59.  
  60.     faceBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  61.     if (!faceBrush)
  62.     {
  63.         DeleteObject(bottomRightPen);
  64.         DeleteObject(topLeftPen);
  65.         return FALSE;
  66.     }
  67.  
  68.     oldPen = SelectObject(hdc, topLeftPen);
  69.     MoveToEx(hdc, left, bottom - 1, NULL);
  70.     LineTo(hdc, left, top);
  71.     LineTo(hdc, right - 1, top);
  72.     SelectObject(hdc, bottomRightPen);
  73.     MoveToEx(hdc, right - 1, top, NULL);
  74.     LineTo(hdc, right - 1, bottom - 1);
  75.     LineTo(hdc, left, bottom - 1);
  76.     SelectObject(hdc, GetStockObject(NULL_PEN));
  77.     oldBrush = SelectObject(hdc, faceBrush);
  78.     Rectangle(hdc, left + 1, top + 1, right, bottom);
  79.     SelectObject(hdc, oldBrush);
  80.     SelectObject(hdc, oldPen);
  81.  
  82.     DeleteObject(faceBrush);
  83.     DeleteObject(bottomRightPen);
  84.     DeleteObject(topLeftPen);
  85.  
  86.     return TRUE;
  87. }
  88.  
  89. /**********************************************************************
  90.  *
  91.  * Draw a framed 3D rectangle.
  92.  *
  93.  **********************************************************************/
  94.  
  95. BOOL
  96. FrameRect3D(HDC hdc, int left, int top, int right, int bottom, BOOL out)
  97. {
  98.     HPEN oldPen;
  99.     HPEN topLeftPen;
  100.     HPEN bottomRightPen;
  101.  
  102.     topLeftPen = CreatePen(PS_SOLID, 1, GetSysColor((out ? COLOR_BTNHIGHLIGHT : COLOR_BTNSHADOW)));
  103.     if (!topLeftPen)
  104.         return FALSE;
  105.  
  106.     bottomRightPen = CreatePen(PS_SOLID, 1, GetSysColor((out ? COLOR_BTNSHADOW : COLOR_BTNHIGHLIGHT)));
  107.     if (!bottomRightPen)
  108.     {
  109.         DeleteObject(topLeftPen);
  110.         return FALSE;
  111.     }
  112.  
  113.     oldPen = SelectObject(hdc, topLeftPen);
  114.     MoveToEx(hdc, left, bottom - 1, NULL);
  115.     LineTo(hdc, left, top);
  116.     LineTo(hdc, right - 1, top);
  117.     SelectObject(hdc, bottomRightPen);
  118.     MoveToEx(hdc, right - 1, top, NULL);
  119.     LineTo(hdc, right - 1, bottom - 1);
  120.     LineTo(hdc, left, bottom - 1);
  121.     SelectObject(hdc, oldPen);
  122.  
  123.     DeleteObject(bottomRightPen);
  124.     DeleteObject(topLeftPen);
  125.  
  126.     return TRUE;
  127. }
  128.  
  129. /**********************************************************************
  130.  *
  131.  * End of file.
  132.  *
  133.  **********************************************************************/
  134.