Adonthell  0.4
drawing_area.cc
Go to the documentation of this file.
1 /*
2  $Id: drawing_area.cc,v 1.2 2001/07/02 22:18:55 gnurou Exp $
3 
4  Copyright (C) 1999/2000/2001 The Adonthell Project
5  Part of the Adonthell Project http://adonthell.linuxgames.com
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file drawing_area.cc
17  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
18  *
19  * @brief Defines the drawing_area class.
20  *
21  *
22  */
23 
24 #include "drawing_area.h"
25 
26 
27 using namespace std;
28 
29 
31 {
32  move (0, 0);
33  resize (0, 0);
34  draw_to = NULL;
35 }
36 
38 {
39  move (px, py);
40  resize (pw, ph);
41  draw_to = NULL;
42 }
43 
45 {
46  rect = r;
47  draw_to = NULL;
48  return (*this);
49 }
50 
51 SDL_Rect drawing_area::setup_rects () const
52 {
53  if (draw_to)
54  {
55  SDL_Rect ret;
56  SDL_Rect temp = draw_to->setup_rects ();
57 
58  ret.x = temp.x > x ()? temp.x : x ();
59  ret.y = temp.y > y ()? temp.y : y ();
60 
61  // Precalculated for faster operation.
62  s_int32 xpl = x () + length ();
63  s_int32 txw = temp.x + temp.w;
64  s_int32 txwmrx = txw - ret.x;
65  s_int32 xplmrx = xpl - ret.x;
66  s_int32 yph = y () + height ();
67  s_int32 tyh = temp.y + temp.h;
68  s_int32 tyhmry = tyh - ret.y;
69  s_int32 yphmry = yph - ret.y;
70 
71 
72  ret.w = txw < xpl ? txwmrx > 0 ? txwmrx : 0 : xplmrx > 0 ? xplmrx : 0;
73  ret.h = tyh < yph ? tyhmry > 0 ? tyhmry : 0 : yphmry > 0 ? yphmry : 0;
74 
75  return ret;
76  }
77  else return rect;
78 
79 }
#define s_int32
32 bits long signed integer
Definition: types.h:44
drawing_area()
Default constructor.
Definition: drawing_area.cc:30
#define u_int16
16 bits long unsigned integer
Definition: types.h:32
Definition: str_hash.h:36
drawing_area & operator=(SDL_Rect &r)
Convert an SDL_Rect into a drawing_area.
Definition: drawing_area.cc:44
SDL_Rect setup_rects() const
Gets the real parameters of this drawing_area.
Definition: drawing_area.cc:51
Implements "drawing zones" for drawing operations.
Definition: drawing_area.h:50
#define s_int16
16 bits long signed integer
Definition: types.h:41
Declares the drawing_area class.