Adonthell 0.4
drawing_area.h
Go to the documentation of this file.
00001 /*
00002    $Id: drawing_area.h,v 1.10 2006/05/07 10:16:18 ksterker Exp $
00003 
00004    Copyright (C) 1999/2000/2001   The Adonthell Project
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 
00016 
00017 /**
00018  * @file   drawing_area.h
00019  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
00020  * 
00021  * @brief  Declares the drawing_area class.
00022  * 
00023  * 
00024  */
00025 
00026 #ifndef DRAWING_AREA_H_
00027 #define DRAWING_AREA_H_
00028 
00029 #include "types.h"
00030 
00031 
00032 /**
00033  * Implements "drawing zones" for drawing operations.
00034  * An object which is drawn into a drawing_area will only appear in
00035  * the rectangular zone it covers.
00036  * During some drawing operations, you may want to limit the blits to a limited
00037  * area of the %screen. For example, if you want to draw an image into a
00038  * window, and that image is larger than this window, you don't want the
00039  * entire image to appear, only the part that fits into the window. This is
00040  * exactly what drawing areas are for. A drawing area is a square that can be
00041  * any size and located anywhere on the %screen. If you assign a drawing area
00042  * to a drawable object (for example, an image), and then draw the image on
00043  * the %screen, the part of the image that doesn't fit the drawing area limits
00044  * isn't displayed. A drawing area can be assigned to any drawable, but also
00045  * to another drawing area, in which case the result of blitting operations
00046  * from objects that are assigned to the second drawing area will be limited
00047  * to the intersection of the two drawing areas. Recursively, you can use as many
00048  * drawing_areas as you wish for drawing operations.
00049  */ 
00050 class drawing_area
00051 { 
00052 public:
00053     /** Default constructor.
00054      *  The drawing_area is then located at (0, 0) and is (0, 0) sized.
00055      */  
00056     drawing_area ();
00057  
00058 #ifndef SWIG
00059     /** Builds a drawing_area from the parameters.
00060      *  @param px X position.
00061      *  @param py Y position.
00062      *  @param pw Length.
00063      *  @param ph Height.
00064      *
00065      *  @note Not available from Python.
00066      */  
00067     drawing_area (s_int16 px, s_int16 py, u_int16 pw, u_int16 ph); 
00068 #endif
00069     
00070     /** Returns the horizontal position of the drawing_area.
00071      *  @return horizontal position of the drawing_area.
00072      */  
00073     s_int16 x () const
00074     {
00075         return rect.x; 
00076     }
00077 
00078     /** Returns the vertical position of the drawing_area.
00079      *  @return vertical position of the drawing_area.
00080      */  
00081     s_int16 y () const
00082     {
00083         return rect.y; 
00084     }
00085 
00086     /** Returns the length of the drawing_area.
00087      *  @return length of the drawing_area.
00088      */  
00089     u_int16 length () const
00090     {
00091         return rect.w; 
00092     }
00093 
00094     /** Returns the height of the drawing_area.
00095      *  @return height of the drawing_area.
00096      */  
00097     u_int16 height () const
00098     {
00099         return rect.h; 
00100     }
00101 
00102     /** Move the drawing_area.
00103      *  @param nx new horizontal position.
00104      *  @param ny new vertical position.
00105      */  
00106     void move (s_int16 nx, s_int16 ny) 
00107     {
00108         rect.x = nx;
00109         rect.y = ny;
00110     }
00111 
00112     /** Resize the drawing_area.
00113      *  @param nl new length.
00114      *  @param nl new height.
00115      */ 
00116     void resize (u_int16 nl, u_int16 nh) 
00117     {
00118         rect.w = nl;
00119         rect.h = nh; 
00120     }
00121 
00122     /** Assign a drawing_area to this drawing_area.
00123      *  If a drawing area is assigned to another one, the zone covered
00124      *  by the drawing_area is the intersection of the two.
00125      *  @param da the drawing_area to assign.
00126      */  
00127     void assign_drawing_area (const drawing_area * da) 
00128     {
00129         draw_to = (drawing_area *) da; 
00130     }
00131 
00132     /** 
00133      * Returns a pointer to the drawing_area assigned to this one.
00134      * 
00135      * 
00136      * @return pointer to the assigned drawing_area, NULL if none.
00137      */
00138     drawing_area * assigned_drawing_area () const
00139     {
00140         return draw_to; 
00141     }
00142     
00143     /** Detach (if needed) the drawing_area which was attached to this
00144      *  one.
00145      */ 
00146     void detach_drawing_area () 
00147     {
00148         draw_to = NULL;
00149     }
00150      
00151 #ifndef SWIG
00152     /** 
00153      * Convert an SDL_Rect into a drawing_area.
00154      * 
00155      * @param r SDL_rect to convert.
00156      * 
00157      * @return drawing_area which has the same dimensions and location as r.
00158      */
00159     drawing_area& operator = (SDL_Rect& r); 
00160 #endif
00161     
00162     /** 
00163      * Gets the real parameters of this drawing_area.
00164      * 
00165      * 
00166      * @return SDL_Rect which is the intersection of this drawing area and
00167      * all the drawing areas assigned to it.
00168      */
00169     SDL_Rect setup_rects () const; 
00170     
00171 private:
00172     /// drawing_area location and size.
00173     SDL_Rect rect;
00174 
00175     /// Attached drawing_area.
00176     drawing_area *draw_to; 
00177 
00178 }; 
00179 
00180 
00181 #endif