Adonthell 0.4

drawing_area.cc

Go to the documentation of this file.
00001 /*
00002    $Id: drawing_area.cc,v 1.2 2001/07/02 22:18:55 gnurou 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  * @file   drawing_area.cc
00017  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
00018  * 
00019  * @brief  Defines the drawing_area class.
00020  * 
00021  * 
00022  */
00023 
00024 #include "drawing_area.h"
00025 
00026 
00027 using namespace std;
00028 
00029 
00030 drawing_area::drawing_area ()
00031 {
00032     move (0, 0);
00033     resize (0, 0);
00034     draw_to = NULL; 
00035 }
00036 
00037 drawing_area::drawing_area (s_int16 px, s_int16 py, u_int16 pw, u_int16 ph)
00038 {
00039     move (px, py);
00040     resize (pw, ph); 
00041     draw_to = NULL; 
00042 }
00043 
00044 drawing_area& drawing_area::operator = (SDL_Rect& r) 
00045 {
00046     rect = r;
00047     draw_to = NULL;
00048     return (*this); 
00049 }
00050 
00051 SDL_Rect drawing_area::setup_rects () const
00052 {
00053     if (draw_to)
00054     {
00055         SDL_Rect ret;
00056         SDL_Rect temp = draw_to->setup_rects ();
00057         
00058         ret.x = temp.x > x ()? temp.x : x (); 
00059         ret.y = temp.y > y ()? temp.y : y ();
00060 
00061         // Precalculated for faster operation.
00062         s_int32 xpl = x () + length (); 
00063         s_int32 txw = temp.x + temp.w;
00064         s_int32 txwmrx = txw - ret.x;
00065         s_int32 xplmrx = xpl - ret.x;  
00066         s_int32 yph = y () + height (); 
00067         s_int32 tyh = temp.y + temp.h;
00068         s_int32 tyhmry = tyh - ret.y;
00069         s_int32 yphmry = yph - ret.y; 
00070         
00071         
00072         ret.w = txw < xpl ? txwmrx > 0 ? txwmrx : 0 : xplmrx > 0 ? xplmrx : 0;
00073         ret.h = tyh < yph ? tyhmry > 0 ? tyhmry : 0 : yphmry > 0 ? yphmry : 0;
00074         
00075         return ret;
00076     }
00077     else return rect;
00078 
00079 }