Adonthell 0.4

drawable.h

Go to the documentation of this file.
00001 /*
00002    $Id: drawable.h,v 1.6 2001/07/28 20:34:49 gnurou Exp $
00003 
00004    Copyright (C) 1999/2000/2001   Alexandre Courbot
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 /**
00017  * @file   drawable.h
00018  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
00019  * 
00020  * @brief  Declares the drawable class.
00021  *  
00022  */
00023 
00024 
00025 #ifndef DRAWABLE_H_
00026 #define DRAWABLE_H_
00027 
00028 #include "drawing_area.h"
00029 
00030 class surface; 
00031 
00032 /**
00033  * Abstract class for drawable %objects manipulation.
00034  *
00035  * This class is designed to allow flexibility in
00036  * drawable %objects manipulation. It also serves as
00037  * a template when creating your own classes.
00038  *
00039  * It defines the basic virtual methods every drawable
00040  * object is required to have. When you design such drawable
00041  * object, make it inherit from this class and overload the virtual
00042  * functions you wish to use.
00043  *
00044  * The main advantage of this class is that it allows you to manipulate
00045  * any drawable object (image, animation, mapview...) without caring
00046  * about it's type, at the little cost of having to use virtual methods.
00047  *
00048  * There are a few methods that are required to be overloaded
00049  * in your class. The draw method is a must-have. Your object must also
00050  * take care to set the size of the drawable correctly (the best thing
00051  * being that it should use the drawable's size as it's own and don't
00052  * overload the length () and height () methods).
00053  * 
00054  */
00055 class drawable
00056 {
00057 public:
00058     
00059     /** 
00060      * Default constructor.
00061      * 
00062      */
00063     drawable ();
00064     
00065     /**
00066      * Destructor.
00067      */ 
00068     virtual ~drawable ();
00069 
00070     /** 
00071      * Returns the length of the drawable.
00072      * 
00073      * 
00074      * @return length of the drawable.
00075      */
00076     u_int16 length () const
00077     {
00078         return length_; 
00079     }
00080 
00081     /** 
00082      * Returns the height of the drawable.
00083      * 
00084      * 
00085      * @return height of the drawable.
00086      */
00087     u_int16 height () const
00088     {
00089         return height_; 
00090     }
00091 
00092     /** 
00093      * Virtual update function, provided for %objects which
00094      * doesn't need one.
00095      * 
00096      */
00097     virtual bool update ();
00098 
00099     /** 
00100      * Virtual input update function, provided for %objects which
00101      * doesn't need one.
00102      * 
00103      */
00104     virtual bool input_update ();
00105 
00106     /** 
00107      * Draw the object on the %screen.
00108      * 
00109      * @param x X position where to draw.
00110      * @param y Y position where to draw.
00111      * @param da_opt optional drawing_area to use during the drawing operation.
00112      * @param target pointer to the surface where to draw the drawable. If NULL,
00113      *               draw on the screen.
00114      */
00115     virtual void draw (s_int16 x, s_int16 y, const drawing_area * da_opt = NULL,
00116                        surface * target = NULL) const = 0;
00117 
00118 protected:
00119     
00120     /** 
00121      * Sets the length of the drawable.
00122      * 
00123      * @param l new length.
00124      */
00125     void set_length (u_int16 l)
00126     {
00127         length_ = l; 
00128     }
00129 
00130     /**
00131      * Sets the height of the drawable.
00132      *
00133      * @param h new height.
00134      */ 
00135     void set_height (u_int16 h)
00136     {
00137         height_ = h; 
00138     }
00139     
00140 private:
00141     u_int16 length_; 
00142     u_int16 height_; 
00143 };
00144 
00145 #endif