00001 #ifndef PAINTABLE_CLASS 00002 #define PAINTABLE_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : paintable * 00007 * Author : Chris Koeritz * 00008 * * 00009 * Purpose: * 00010 * * 00011 * Represents an object that can be painted onto a canvas. * 00012 * * 00013 ******************************************************************************* 00014 * Copyright (c) 1991-$now By Author. This program is free software; you can * 00015 * redistribute it and/or modify it under the terms of the GNU General Public * 00016 * License as published by the Free Software Foundation; either version 2 of * 00017 * the License or (at your option) any later version. This is online at: * 00018 * http://www.fsf.org/copyleft/gpl.html * 00019 * Please send any updates to: fred@gruntose.com * 00020 \*****************************************************************************/ 00021 00022 #include "canvas.h" 00023 #include "drawable.h" 00024 00025 class WP_PASSIVE_CLASS_STYLE paintable : public drawable 00026 { 00027 public: 00028 paintable(canvas &to_draw_on, const c_point &origin, 00029 const color &foreground = colors::WHITE, bool attach = true); 00030 // the paintable object is created with the color "foreground". it is 00031 // added to the canvas "to_draw_on" if "attach" is true. if "attach" is 00032 // false, calls to draw() will show the object, but the object will 00033 // disappear when the canvas is redrawn. paintables are intentionally 00034 // quite dumb; they should not draw or erase themselves unless 00035 // specifically ordered to. 00036 00037 virtual ~paintable(); 00038 00039 canvas &target() const; 00040 // The paintable object will perform its draws and erases on the canvas 00041 // returned by target. 00042 00043 void draw(); 00044 void erase(); 00045 // Each of these two methods uses plot to draw the paintable object on its 00046 // canvas in the canvas foreground and background colors respectively. 00047 00048 virtual c_rectangle dimensions() const = 0; 00049 // This must be provided by all derived paintable objects. It should 00050 // return a rectangle that bounds the extent of the paintable on the screen 00051 // in terms of the world coordinate system (see canvas.h). 00052 00053 virtual void plot(const color &to_draw_in) = 0; 00054 // Draws the object on its target canvas using the color specified in 00055 // "to_draw_in". 00056 00057 bool filled() const; 00058 // if this is true, then the object should be drawn filled in, if that 00059 // is possible. 00060 virtual void set_filled(bool i_am_to_be_filled = true); 00061 // tells the paintable to be filled (or not), if that is supported. 00062 00063 color foreground() const; 00064 virtual void foreground(const color &new_foreground); 00065 // The foreground here is used for the primary color that the paintable 00066 // will have when draw() is called. 00067 00068 virtual void set_origin(const c_point &new_origin); 00069 // Resets the attachment point for the paintable on the canvas. 00070 00071 private: 00072 bool _filled; // true if the object is to be filled when drawn. 00073 bool _attach; // true if the object is to be attached to the canvas. 00074 canvas &_canvas; // the canvas that the object will be drawn on. 00075 00076 void attach(); 00077 void detach(); 00078 }; 00079 00080 #endif 00081
1.5.1