Adonthell  0.4
drawable.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 1999/2000/2001 Alexandre Courbot
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 /**
21  * @file drawable.h
22  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
23  *
24  * @brief Declares the drawable class.
25  *
26  */
27 
28 
29 #ifndef DRAWABLE_H_
30 #define DRAWABLE_H_
31 
32 #include "drawing_area.h"
33 
34 class surface;
35 
36 /**
37  * Abstract class for drawable %objects manipulation.
38  *
39  * This class is designed to allow flexibility in
40  * drawable %objects manipulation. It also serves as
41  * a template when creating your own classes.
42  *
43  * It defines the basic virtual methods every drawable
44  * object is required to have. When you design such drawable
45  * object, make it inherit from this class and overload the virtual
46  * functions you wish to use.
47  *
48  * The main advantage of this class is that it allows you to manipulate
49  * any drawable object (image, animation, mapview...) without caring
50  * about it's type, at the little cost of having to use virtual methods.
51  *
52  * There are a few methods that are required to be overloaded
53  * in your class. The draw method is a must-have. Your object must also
54  * take care to set the size of the drawable correctly (the best thing
55  * being that it should use the drawable's size as it's own and don't
56  * overload the length () and height () methods).
57  *
58  */
59 class drawable
60 {
61 public:
62 
63  /**
64  * Default constructor.
65  *
66  */
67  drawable ();
68 
69  /**
70  * Destructor.
71  */
72  virtual ~drawable ();
73 
74  /**
75  * Returns the length of the drawable.
76  *
77  *
78  * @return length of the drawable.
79  */
80  u_int16 length () const
81  {
82  return length_;
83  }
84 
85  /**
86  * Returns the height of the drawable.
87  *
88  *
89  * @return height of the drawable.
90  */
91  u_int16 height () const
92  {
93  return height_;
94  }
95 
96  /**
97  * Virtual update function, provided for %objects which
98  * doesn't need one.
99  *
100  */
101  virtual bool update ();
102 
103  /**
104  * Virtual input update function, provided for %objects which
105  * doesn't need one.
106  *
107  */
108  virtual bool input_update ();
109 
110  /**
111  * Draw the object on the %screen.
112  *
113  * @param x X position where to draw.
114  * @param y Y position where to draw.
115  * @param da_opt optional drawing_area to use during the drawing operation.
116  * @param target pointer to the surface where to draw the drawable. If NULL,
117  * draw on the screen.
118  */
119  virtual void draw (s_int16 x, s_int16 y, const drawing_area * da_opt = NULL,
120  surface * target = NULL) const = 0;
121 
122 protected:
123 
124  /**
125  * Sets the length of the drawable.
126  *
127  * @param l new length.
128  */
130  {
131  length_ = l;
132  }
133 
134  /**
135  * Sets the height of the drawable.
136  *
137  * @param h new height.
138  */
140  {
141  height_ = h;
142  }
143 
144 private:
145  u_int16 length_;
146  u_int16 height_;
147 };
148 
149 #endif
void set_length(u_int16 l)
Sets the length of the drawable.
Definition: drawable.h:129
u_int16 height() const
Returns the height of the drawable.
Definition: drawable.h:91
#define u_int16
16 bits long unsigned integer
Definition: types.h:38
void set_height(u_int16 h)
Sets the height of the drawable.
Definition: drawable.h:139
u_int16 length() const
Returns the length of the drawable.
Definition: drawable.h:80
Class where drawables can actually be drawn to.
Definition: surface.h:85
virtual bool input_update()
Virtual input update function, provided for objects which doesn&#39;t need one.
Definition: drawable.cc:49
drawable()
Default constructor.
Definition: drawable.cc:34
Implements "drawing zones" for drawing operations.
Definition: drawing_area.h:54
#define s_int16
16 bits long signed integer
Definition: types.h:47
virtual void draw(s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const =0
Draw the object on the screen.
virtual bool update()
Virtual update function, provided for objects which doesn&#39;t need one.
Definition: drawable.cc:44
Abstract class for drawable objects manipulation.
Definition: drawable.h:59
Declares the drawing_area class.
virtual ~drawable()
Destructor.
Definition: drawable.cc:40