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

  1. /**********************************************************************
  2.  *
  3.  * File :     status.c
  4.  *
  5.  * Abstract : Add a status bar to the bottom of a RenderWare window
  6.  *
  7.  **********************************************************************
  8.  *
  9.  * This file is a product of Criterion Software Ltd.
  10.  *
  11.  * This file is provided as is with no warranties of any kind and is
  12.  * provided without any obligation on Criterion Software Ltd. or
  13.  * Canon Inc. to assist in its use or modification.
  14.  *
  15.  * Criterion Software Ltd. will not, under any
  16.  * circumstances, be liable for any lost revenue or other damages arising
  17.  * from the use of this file.
  18.  *
  19.  * Copyright (c) 1995 Criterion Software Ltd.
  20.  * All Rights Reserved.
  21.  *
  22.  * RenderWare is a trademark of Canon Inc.
  23.  *
  24.  ************************************************************************/
  25.  
  26. #define INCLUDE_SHELLAPI_H
  27.  
  28. #include <windows.h>
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32.  
  33. #include <rwlib.h>
  34.  
  35. /* Structure and Enum definitions */
  36.  
  37. typedef enum {
  38.     B_IN,
  39.     B_OUT
  40. } EnBox;
  41.  
  42. /* Constant definitions */
  43.  
  44. #define STATUS_HEIGHT 20        /* height of the status bar */
  45.  
  46. /************************************************************************
  47.  *
  48.  *      Function:       Box3D()
  49.  *                      
  50.  *      Description:    Draws a 3D box on the output DC.
  51.  *
  52.  *      Parameters:     hdc - output DC
  53.  *                      type - a sunken or raised box
  54.  *                      left - x co-ordinate for left of box
  55.  *                      top  - y co-ordinate for top  of box
  56.  *                      right - x co-ordinate for left of box
  57.  *                      bottom - y co-ordinate for left of box
  58.  *
  59.  ************************************************************************/
  60. static void Box3d(HDC hdc, EnBox type, int left, int top, int right, int bottom)
  61. {
  62.     LOGPEN lp;
  63.     HPEN pen, oldpen;
  64.  
  65.     /* Create a grey pen */
  66.  
  67.     lp.lopnStyle = PS_SOLID;
  68.     lp.lopnWidth.x = 0;
  69.     lp.lopnWidth.y = 0;
  70.     lp.lopnColor = RGB(128, 128, 128);
  71.  
  72.     pen = CreatePenIndirect(&lp);
  73.  
  74.     if (type == B_IN)
  75.     {
  76.         /* Use the grey pen for the left and top of the box */
  77.         oldpen = SelectObject(hdc, pen);
  78.     }
  79.     else
  80.     {
  81.         /* Use the white pen for the left and top of the box */
  82.         oldpen = SelectObject(hdc, GetStockObject(WHITE_PEN));
  83.     }
  84.  
  85.     /* draw the left and top of the box */
  86.  
  87.     MoveToEx(hdc, left, bottom, NULL);
  88.     LineTo(hdc, left, top);
  89.     LineTo(hdc, right, top);
  90.  
  91.     if (type == B_IN)
  92.     {
  93.         /* Use the white pen for the right and bottom of the box */
  94.         SelectObject(hdc, GetStockObject(WHITE_PEN));
  95.     }
  96.     else
  97.     {
  98.         /* Use the grey pen for the right and bottom of the box */
  99.         SelectObject(hdc, pen);
  100.     }
  101.  
  102.     /* draw the right and bottom of the box */
  103.     LineTo(hdc, right, bottom);
  104.     LineTo(hdc, left, bottom);
  105.  
  106.     SelectObject(hdc, oldpen);
  107.     DeleteObject(pen);
  108. }
  109.  
  110. /************************************************************************
  111.  *
  112.  *      Function:       ShowAppLeftStatus()
  113.  *                      
  114.  *      Description:    Display the left status bar below the RenderWare
  115.  *                      camera.
  116.  *
  117.  *      Parameters:     window - window containing status bar
  118.  *                      Camera - RenderWare camera
  119.  *                      string - string to display in status bar
  120.  *
  121.  ************************************************************************/
  122. void ShowAppLeftStatus(HWND Window, RwCamera *Camera, char *string)
  123. {
  124.     RwInt32 height, width;
  125.     HDC        dc;
  126.     RECT        r;
  127.  
  128.     /* Don't include the status bar in minimised windows */
  129.     
  130.     if (IsIconic(Window))
  131.         return;
  132.  
  133.     /* Find out where the bottom of the camera is */
  134.  
  135.     RwGetCameraViewport(Camera, NULL, NULL, &width, &height);
  136.  
  137.     dc = GetDC(Window);
  138.  
  139.     /* Define the dimensions of the area of the status bar that will
  140.        contain text */
  141.      SetRect(&r, 2, (int)height + 2, (int)width/2 - 3, (int)height + STATUS_HEIGHT - 2);
  142.  
  143.     /* clear the status bar to grey */
  144.     SelectObject(dc, GetStockObject(LTGRAY_BRUSH));
  145.     Rectangle(dc, r.left - 2, r.top - 2, r.right + 3, r.bottom + 3);
  146.  
  147.     /* draw the 3D effect lines */
  148.     Box3d(dc, B_OUT, r.left - 2, r.top - 2, r.right + 2, r.bottom + 2); 
  149.     Box3d(dc, B_IN, r.left, r.top, r.right, r.bottom); 
  150.  
  151.     SetBkMode(dc, TRANSPARENT);
  152.     SetTextColor(dc, RGB(0,0,0));
  153.     SelectObject(dc, GetStockObject(ANSI_VAR_FONT));
  154.  
  155.     /* Draw the text */
  156.     ExtTextOut(dc, r.left + 4, r.top + 3, ETO_CLIPPED, &r, string, strlen(string), NULL);
  157.     ReleaseDC(Window, dc);
  158. }
  159.  
  160. /************************************************************************
  161.  *
  162.  *      Function:       ShowAppRightStatus()
  163.  *                      
  164.  *      Description:    Display the right status bar below the RenderWare
  165.  *                      camera.
  166.  *
  167.  *      Parameters:     window - window containing status bar
  168.  *                      Camera - RenderWare camera
  169.  *                      string - string to display in status bar
  170.  *
  171.  ************************************************************************/
  172. void ShowAppRightStatus(HWND Window, RwCamera *Camera, char *string)
  173. {
  174.     RwInt32 height, width;
  175.     HDC        dc;
  176.     RECT        r;
  177.  
  178.     /* Don't include the status bar in minimised windows */
  179.  
  180.     if (IsIconic(Window))
  181.         return;
  182.    
  183.     /* Find out where the bottom of the camera is */
  184.    
  185.     RwGetCameraViewport(Camera, NULL, NULL, &width, &height);
  186.  
  187.     dc = GetDC(Window);
  188.  
  189.     /* Define the dimensions of the area of the status bar that will
  190.        contain text */
  191.      SetRect(&r, (int)width/2 + 2, (int)height + 2, (int)width - 2, (int)height + STATUS_HEIGHT - 2);
  192.  
  193.     /* clear the status bar to grey */
  194.     SelectObject(dc, GetStockObject(LTGRAY_BRUSH));
  195.     Rectangle(dc, r.left - 2, r.top - 2, r.right + 3, r.bottom + 3);
  196.  
  197.     /* draw the 3D effect lines */
  198.     Box3d(dc, B_OUT, r.left - 2, r.top - 2, r.right + 2, r.bottom + 2); 
  199.     Box3d(dc, B_IN, r.left, r.top, r.right, r.bottom); 
  200.  
  201.     SetBkMode(dc, TRANSPARENT);
  202.     SetTextColor(dc, RGB(0,0,0));
  203.     SelectObject(dc, GetStockObject(ANSI_VAR_FONT));
  204.  
  205.     /* Draw the text */
  206.  
  207.     ExtTextOut(dc, r.left + 2, r.top + 1, ETO_CLIPPED, &r, string, strlen(string), NULL);
  208.     ReleaseDC(Window, dc);
  209. }
  210.  
  211. /************************************************************************
  212.  *
  213.  *      Function:       StatusAdjustHeight()
  214.  *                      
  215.  *      Description:    If the status bar is currently displayed, then 
  216.  *                      adjust the supplied height to account for this
  217.  *
  218.  *      Parameters:     window - window containing status bar
  219.  *                      height - Current height
  220.  *
  221.  *      Return Value:   new height.
  222.  *
  223.  ************************************************************************/
  224. int StatusAdjustHeight(HWND Window, int height)
  225. {
  226.     if (IsIconic(Window))
  227.         return (height);
  228.     else
  229.         return (height - STATUS_HEIGHT);
  230. }
  231.