home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Venus 3.5 / FlightWindow.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-10  |  4.6 KB  |  123 lines  |  [TEXT/CWIE]

  1. /*
  2.  ***********************************************************************
  3.  *
  4.  *                                FlightWindow
  5.  * a live (animated) window that displays the FlightView and tells it to move on
  6.  * 
  7.  ***********************************************************************
  8.  */
  9.  
  10. #pragma once
  11.  
  12. #include "ImageViews.h"
  13.  
  14.                             // A more optimized version of a generic ThreeDView
  15. class ThreeDProjector_PeriodicMap;
  16. class FlightView : public ThreeDView<ThreeDProjector_PeriodicMap>
  17. {
  18.   virtual void prepaint(void);            // Draw the sky (as a background image)
  19. public:
  20.   FlightView(const ElevationMap& elev_map, const ViewerPosition& viewer_pos,
  21.                const ProjectionParameters& projection_parms)
  22.       : ThreeDView<ThreeDProjector_PeriodicMap>(elev_map,viewer_pos,projection_parms) {}
  23. };
  24.  
  25.  
  26.                             // An utility class to help us count frames
  27. class StopWatch
  28. {
  29.   int mark_counter;                // Counts marks (say, drawn frames)
  30.   int time_started;                // Tick counter when the StopWatch was last started
  31.   int time_stopped;                // Tick counter when the StopWatch was stopped, or 0 if it is running
  32. public:
  33.   StopWatch(void) : mark_counter(0), time_started(0), time_stopped(0) {}
  34.   int operator ++ (void)        { return mark_counter++; }
  35.   void start(void)                { mark_counter = 0; time_started = TickCount(); time_stopped = 0;}
  36.   void stop(void)                { time_stopped = TickCount(); }
  37.   int marks_per_sec(void) const;
  38. };
  39.                             // A window that displays FlightView and does some
  40.                             // animation and key/mouse handling
  41. class FlightWindow : public ScreenWindow
  42. {
  43.   class ViewerAnim: public ViewerPosition
  44.   {
  45.     const int sup_xe;
  46.     const int sup_ye;
  47.     int clip(const int x, const int sup_x) { return x < 0 ? x + sup_x : x >=sup_x ? x-sup_x: x; }
  48.   public:
  49.     ViewerAnim(const ScreenRect& rect);
  50.     void move_hor(const int incr)    { xe = clip(xe+incr, sup_xe); }
  51.     void move_ver(const int incr)    { ye = clip(ye+incr, sup_ye); }
  52.     void stir(void);            // move things a little
  53.   };
  54.   ViewerAnim viewer;
  55.   
  56.   class ProjAnim : public ProjectionParameters
  57.   {
  58.     Boolean clip(int& var, const int var_min, const int var_max)
  59.         { if( var > var_max ) return var = var_max, FALSE;
  60.           else if( var < var_min ) return var = var_min, FALSE;
  61.           else return TRUE; }
  62.   public:
  63.     ProjAnim(const ScreenRect& rect)
  64.       : ProjectionParameters(rect,226,83) { Ov = 75; }
  65.     void climb(const int incr) { ze += incr; clip(ze,64,512); }
  66.     void zoom(const int incr) { beta += incr; clip(beta,32,128); }
  67.     void move_horizon(const int incr) { Ov += incr; clip(Ov,1,v_sup-1); }
  68.   };
  69.   
  70.   ProjAnim proj_parameters;
  71.   
  72.   FlightView view_buffer;
  73.  
  74.   Boolean is_flying;
  75.   StopWatch frame_counter;            // Counts frames drawn
  76.   
  77.   virtual void draw(void);            // It is this function that really draws smth
  78.  
  79. protected:
  80.  
  81.                                 // Commencing and terminating the flight
  82.   void start_flight(void);
  83.   void stop_flight(void);
  84.   void animate(void);            // Usually called within draw()
  85.  
  86.   Boolean handle_mouse_down(const EventRecord& the_event, WindowPtr where_window, short window_part);
  87.   Boolean handle_key_down(const EventRecord& the_event);    // Handles key_down & auto_key events
  88.                                         // Track the mouse clicked in content
  89.                                         // and move the plane as the mouse (still down) moves
  90.   Boolean  track_mouse(Point mouse_down_pt);
  91.  
  92.   const PixMapHandle get_pixmap(void) const        { return view_buffer.get_pixmap(); }
  93. //  virtual void destroy_it(void);        // A virtual window destructor
  94.   virtual void setup_color_env(OffScreenBuffer& offscreen_buffer);
  95.   Boolean was_QD_optimized;        // Just an informational flag to see how sucessful my color
  96.                                   // worlds negotiations were
  97.  
  98. public:
  99.   FlightWindow(const ElevationMap& elev_map, const int wind_id);
  100.   
  101.                             // This constructor is similar to the one above, but works
  102.                             // in cases when the view_buffer dimensions aren't the same
  103.                             // as those of the on-screen window (and differ by a factor
  104.                             // of two, say). This is the case when the onscreen window
  105.                             // is way to big to buffer it offscreen (and some blockiness
  106.                             // due to blow-up during the blitting can be tolerated)
  107.   FlightWindow(const ElevationMap& elev_map, const int wind_id,ScreenRect buffer_rect);
  108.  
  109.   virtual Boolean handle_null_event(const long event_time);
  110.   void init(void);                    // post-constructor
  111. };
  112.  
  113.                             // A flight window for the whole screen
  114. class FullFlightWindow : public FlightWindow
  115. {
  116.   const int normal_menu_bar_height;        // saved while flying
  117.   virtual void destroy_it(void);        // A virtual window destructor
  118.   virtual void draw(void);            // It is this function that really draws smth
  119.   virtual void setup_color_env(OffScreenBuffer& offscreen_buffer);
  120. public:
  121.   FullFlightWindow(const ElevationMap& image_map, const int wind_id);
  122. };
  123.