Adonthell  0.4
drawing_area.cc
Go to the documentation of this file.
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 
32 {
33  move (0, 0);
34  resize (0, 0);
35  draw_to = NULL;
36 }
37 
39 {
40  move (px, py);
41  resize (pw, ph);
42  draw_to = NULL;
43 }
44 
46 {
47  rect = r;
48  draw_to = NULL;
49  return (*this);
50 }
51 
52 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 }
#define s_int32
32 bits long signed integer
Definition: types.h:50
s_int16 y() const
Returns the vertical position of the drawing_area.
Definition: drawing_area.h:85
drawing_area()
Default constructor.
Definition: drawing_area.cc:31
#define u_int16
16 bits long unsigned integer
Definition: types.h:38
u_int16 length() const
Returns the length of the drawing_area.
Definition: drawing_area.h:93
void resize(u_int16 nl, u_int16 nh)
Resize the drawing_area.
Definition: drawing_area.h:120
s_int16 x() const
Returns the horizontal position of the drawing_area.
Definition: drawing_area.h:77
drawing_area & operator=(SDL_Rect &r)
Convert an SDL_Rect into a drawing_area.
Definition: drawing_area.cc:45
Implements "drawing zones" for drawing operations.
Definition: drawing_area.h:54
#define s_int16
16 bits long signed integer
Definition: types.h:47
SDL_Rect setup_rects() const
Gets the real parameters of this drawing_area.
Definition: drawing_area.cc:52
void move(s_int16 nx, s_int16 ny)
Move the drawing_area.
Definition: drawing_area.h:110
Declares the drawing_area class.
u_int16 height() const
Returns the height of the drawing_area.
Definition: drawing_area.h:101