home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 3.ddi / BGICLA.ZIP / DISPLAY.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-24  |  3.5 KB  |  89 lines

  1. /*************************************************************************
  2.     Listing 1 - DISPLAY.HPP
  3.  
  4.     Written by: Kevin D. Weeks, April 17, 1990
  5.     Released to the Public Domain.
  6.  
  7.     Description:
  8.         This is the display control class. There can be ONLY ONE declared
  9.     and that it must be declared globally! The classes that use the
  10.     Graphics_Display object expect that it will be named "theDisplay".
  11.     This class also provides the support attributes for the virtual
  12.     world. There are a number of methods not included here for the sake
  13.     of brevity that should be included, for instance: set_mode() and
  14.     get_mode(), get_ and set_default_fill_pattern(), etc.
  15. */
  16.  
  17. #if !defined(DISPLAY_HPP)
  18. #define DISPLAY_HPP
  19.  
  20. #include <graphics.h>
  21.  
  22. double  round(double value);
  23.  
  24. class Graphics_Display
  25. {
  26.   public:
  27. // Constructors and destructor
  28.     Graphics_Display(char *path,const int world_size = 1000.0);
  29.     ~Graphics_Display(void)
  30.     { closegraph(); };
  31.  
  32. // GET attribute methods.
  33.     float       get_aspect_ratio(void)      // the value returned assumes
  34.                 { return aspect_ratio; };   //     that Y equals 1 and that
  35.                                             //     X is a fraction of Y.
  36.                                             //     the value value actually
  37.                                             //     returned is the X com-
  38.                                             //     ponent of the ratio.
  39.     float       get_virtual_size(void)
  40.                 { return virtual_size; };
  41.     int         get_max_x(void)
  42.                 { return max_x; };
  43.     int         get_max_y(void)
  44.                 { return max_y; };
  45.     int         get_driver(void)
  46.                 { return driver; };
  47.     // the next two methods return the scaling factors to be used in
  48.     // converting to and from virtual world co-ordinates and actual screen
  49.     // co-ordinates.
  50.     float       get_x_scale(void)
  51.                 { return x_scale; };
  52.     float       get_y_scale(void)
  53.                 { return y_scale; };
  54.  
  55. // SET attribute methods.
  56.     // the first two methods SHOULD NOT be used after the creation of
  57.     // ANY Graphics_Object!
  58.     void        set_aspect_ratio(const double ratio);
  59.     void        set_virtual_size(const double size);
  60.     void        set_default_bk_color(const COLORS new_color)
  61.                 { setbkcolor(new_color); };
  62.     void        set_default_fg_color(const COLORS new_color)
  63.                 { setcolor(new_color); };
  64.  
  65.     // conversion methods.
  66.     double      x_to_virtual(int x)
  67.                 { return round( ((float)x / x_scale) * aspect_ratio); };
  68.     double      y_to_virtual(int y)
  69.                 { return round( (float)y / y_scale); };
  70.     int         x_to_real(float x)
  71.                 { return (int)(round(x * x_scale)); };
  72.     int         y_to_real(float y)
  73.                 { return (int)(round(y * y_scale)); };
  74.  
  75.   private:
  76.     int         driver;                 // display driver to use. defined
  77.                                         //     in include\graphics.h
  78.     float       aspect_ratio;           // see get_aspect_ratio() above
  79.     float       virtual_size;           // virtual world size.
  80.                                         //     default = 1000.0 x 1000.0
  81.     float       x_scale;                // see get_x_scale() and
  82.     float       y_scale;                //     get_y_scale() above.
  83.     int         max_x;                  // horizontal display size in pixels
  84.     int         max_y;                  // vertical display size in pixels
  85.  
  86. };
  87.  
  88. #endif
  89.