00001 #ifndef PICTURE_CLASS 00002 #define PICTURE_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : picture * 00007 * Author : Chris Koeritz * 00008 * * 00009 * Purpose: * 00010 * * 00011 * A collection of drawables that can be drawn or erased as a group and * 00012 * that share a common origin as their reference point. * 00013 * * 00014 ******************************************************************************* 00015 * Copyright (c) 1991-$now By Author. This program is free software; you can * 00016 * redistribute it and/or modify it under the terms of the GNU General Public * 00017 * License as published by the Free Software Foundation; either version 2 of * 00018 * the License or (at your option) any later version. This is online at: * 00019 * http://www.fsf.org/copyleft/gpl.html * 00020 * Please send any updates to: fred@gruntose.com * 00021 \*****************************************************************************/ 00022 00023 #include "drawable.h" 00024 00025 #include <data_struct/amorph.h> 00026 #include <geometric/cartesian_objects.h> 00027 00028 class picture_part; 00029 00030 class WP_PASSIVE_CLASS_STYLE picture 00031 : public drawable, private amorph<picture_part> 00032 { 00033 public: 00034 picture(const c_point &origin); 00035 virtual ~picture(); 00036 00037 void add(drawable *to_add); 00038 // Adds a drawable object to the picture. The origin of the object (at 00039 // the time of add) is used as the object's relationship with the 00040 // origin of the picture. That is, if a drawable is added with an 00041 // origin of (0, 0), then it has the same origin as the picture, 00042 // whereas if a drawable is added with origin(20, -30), then it is 00043 // located at 20 pixels to the right and 30 pixels below the picture's 00044 // origin. The relative origin is updated appropriately when the 00045 // picture is moved. 00046 00047 bool remove(drawable *to_remove); 00048 bool remove(int index); 00049 // Eliminates a member from the picture, if it is present. true is 00050 // returned if it was found and removed. The size of the picture shrinks 00051 // after the element is removed. The drawable object (which was until 00052 // recently an element in the picture) is not deleted; this must be done 00053 // by the real parent of the drawable. 00054 00055 virtual c_rectangle dimensions() const; 00056 // Returns a rectangle bounding the whole picture. 00057 00058 virtual void draw(); 00059 virtual void erase(); 00060 00061 void draw_intersecting(const c_rectangle ®ion); 00062 void erase_intersecting(const c_rectangle ®ion); 00063 00064 amorph<picture_part>::elements; 00065 00066 const drawable *get(int index) const; 00067 drawable *acquire(int index); 00068 // returns the drawable at the "index", or NIL if the index is invalid. 00069 // get retains the drawable in question, acquire removes it from the 00070 // picture. 00071 00072 virtual void set_origin(const c_point &new_origin); 00073 // changes the origin for the picture within the frame of reference where 00074 // the picture is to be drawn. each of the drawables maintain their 00075 // relationship with the relative origin. 00076 00077 void update(); 00078 // reorders the list of drawables with correct layering. this accounts 00079 // for an object's layer changing after it has been added to the picture. 00080 // all of the objects are erased and then redrawn in the correct order, 00081 // currently. 00082 00083 private: 00084 c_point _origin; 00085 }; 00086 00087 class WP_PASSIVE_CLASS_STYLE picture_part : private c_point 00088 { 00089 private: 00090 picture_part(const c_point &origin) : c_point(origin) {} 00091 drawable *stored; 00092 friend class picture; 00093 }; 00094 00095 #endif
1.5.1