ArenaWindow.h

Go to the documentation of this file.
00001 /*
00002 RealTimeBattle, a robot programming game for Unix
00003 Copyright (C) 1998-2000  Erik Ouchterlony and Ragnar Ouchterlony
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software Foundation,
00017 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef __ARENA_WINDOW__
00021 #define __ARENA_WINDOW__
00022 
00023 #ifdef HAVE_CONFIG_H
00024 # include <config.h>
00025 #endif
00026 
00027 #ifndef NO_GRAPHICS
00028 
00029 #include "Vector2D.h"
00030 
00031 struct _GtkWidget;
00032 typedef struct _GtkWidget GtkWidget;
00033 union _GdkEvent;
00034 typedef union _GdkEvent GdkEvent;
00035 struct _GdkEventKey;
00036 typedef struct _GdkEventKey GdkEventKey;
00037 struct _GdkEventExpose;
00038 typedef struct _GdkEventExpose GdkEventExpose;
00039 struct _GdkColor;
00040 typedef struct _GdkColor GdkColor;
00041 typedef void* gpointer;
00042 typedef int gint;
00043 
00044 
00045 class ArenaWindow
00046 {
00047 public:
00048   ArenaWindow                      ( const int default_width  = -1,
00049                                      const int default_height = -1,
00050                                      const int default_x_pos  = -1,
00051                                      const int default_y_pos  = -1 );
00052   ~ArenaWindow                     ();
00053 
00054   void set_window_title            ();
00055 
00056   static gboolean hide_window          ( GtkWidget* widget, GdkEvent* event,
00057                                      class ArenaWindow* arenawindow_p );
00058   static void show_window          ( GtkWidget* widget,
00059                                      class ArenaWindow* arenawindow_p );
00060   static void no_zoom              ( GtkWidget* widget,
00061                                      class ArenaWindow* arenawindow_p );
00062   static void zoom_in              ( GtkWidget* widget,
00063                                      class ArenaWindow* arenawindow_p );
00064   static void zoom_out             ( GtkWidget* widget,
00065                                      class ArenaWindow* arenawindow_p );
00066   static gint redraw               ( GtkWidget* widget,
00067                                      GdkEventExpose* event,
00068                                      class ArenaWindow* arenawindow_p );
00069   static gint keyboard_handler     ( GtkWidget *widget, GdkEventKey *event,
00070                                      class ArenaWindow* arenawindow_p );
00071 
00072 
00073   inline int boundary2pixel_x      ( const double x );
00074   inline int boundary2pixel_y      ( const double y );
00075 
00076 
00077   void clear_area                  ();
00078   void draw_everything             ();
00079   void draw_moving_objects         ( const bool clear_objects_first );
00080   void drawing_area_scale_changed  ( const bool change_da_value = false );
00081   void draw_circle                 ( const Vector2D& center,
00082                                      const double radius,
00083                                      GdkColor& colour,
00084                                      const bool filled );
00085   void draw_arc                    ( const Vector2D& center, 
00086                                      const double inner_radius, const double outer_radius,
00087                                      const double angle1, const double angle2,
00088                                      GdkColor& colour );
00089   void draw_line                   ( const Vector2D& start,
00090                                      const Vector2D& direction,
00091                                      const double length, 
00092                                      const double thickness,
00093                                      GdkColor& colour );
00094   void draw_line                   ( const Vector2D& start,
00095                                      const Vector2D& direction,
00096                                      const double length, 
00097                                      GdkColor& colour );
00098   void draw_rectangle              ( const Vector2D& start,
00099                                      const Vector2D& end,
00100                                      GdkColor& colour,
00101                                      const bool filled );
00102 
00103   GtkWidget* get_drawing_area      () { return drawing_area; }
00104   GtkWidget* get_scrolled_window   () { return scrolled_window; }
00105   GtkWidget* get_window_p          () { return window_p; }
00106   bool is_window_shown             () { return window_shown; }
00107   void set_window_shown            ( bool win_shown );
00108   int get_zoom                     () { return zoom; }
00109   void set_zoom                    ( int z ) { zoom = z; }
00110   double get_drawing_area_scale    () { return drawing_area_scale; }
00111 
00112 private:
00113 
00114   GtkWidget* window_p;
00115   GtkWidget* scrolled_window;
00116   GtkWidget* drawing_area;
00117 
00118   Vector2D scrolled_window_size;
00119   int zoom; // The zoom when pressed on one of the zoombuttons
00120   double drawing_area_scale;
00121 
00122   bool window_shown;
00123 };
00124 
00125 #include "ArenaController.h"
00126 
00127 inline int
00128 ArenaWindow::boundary2pixel_x( const double x )
00129 {
00130   return (int)( ( x - the_arena.get_boundary()[0][0] ) * 
00131                 drawing_area_scale + 0.5 );
00132 }
00133 
00134 inline int
00135 ArenaWindow::boundary2pixel_y( const double y )
00136 {
00137   return (int)( ( the_arena.get_boundary()[1][1] - y ) * 
00138                 drawing_area_scale + 0.5 );
00139 }
00140 
00141 #endif 
00142 
00143 #endif

Generated on Fri Oct 15 15:47:36 2004 for Real Time Battle by  doxygen 1.3.9.1