1 /*
2    Copyright (C) 1999/2000/2001   The Adonthell Project
3    Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5    Adonthell is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9 
10    Adonthell is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with Adonthell.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * @file   drawing_area.cc
21  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
22  *
23  * @brief  Defines the drawing_area class.
24  *
25  *
26  */
27 
28 #include "drawing_area.h"
29 
30 
drawing_area()31 drawing_area::drawing_area ()
32 {
33     move (0, 0);
34     resize (0, 0);
35     draw_to = NULL;
36 }
37 
drawing_area(s_int16 px,s_int16 py,u_int16 pw,u_int16 ph)38 drawing_area::drawing_area (s_int16 px, s_int16 py, u_int16 pw, u_int16 ph)
39 {
40     move (px, py);
41     resize (pw, ph);
42     draw_to = NULL;
43 }
44 
operator =(SDL_Rect & r)45 drawing_area& drawing_area::operator = (SDL_Rect& r)
46 {
47     rect = r;
48     draw_to = NULL;
49     return (*this);
50 }
51 
setup_rects() const52 SDL_Rect drawing_area::setup_rects () const
53 {
54     if (draw_to)
55     {
56         SDL_Rect ret;
57         SDL_Rect temp = draw_to->setup_rects ();
58 
59         ret.x = temp.x > x ()? temp.x : x ();
60         ret.y = temp.y > y ()? temp.y : y ();
61 
62         // Precalculated for faster operation.
63         s_int32 xpl = x () + length ();
64         s_int32 txw = temp.x + temp.w;
65         s_int32 txwmrx = txw - ret.x;
66         s_int32 xplmrx = xpl - ret.x;
67         s_int32 yph = y () + height ();
68         s_int32 tyh = temp.y + temp.h;
69         s_int32 tyhmry = tyh - ret.y;
70         s_int32 yphmry = yph - ret.y;
71 
72 
73         ret.w = txw < xpl ? txwmrx > 0 ? txwmrx : 0 : xplmrx > 0 ? xplmrx : 0;
74         ret.h = tyh < yph ? tyhmry > 0 ? tyhmry : 0 : yphmry > 0 ? yphmry : 0;
75 
76         return ret;
77     }
78     else return rect;
79 
80 }
81