Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

DrawElement Class Reference

A part of the drawing. More...

#include <DrawElement.h>

Inheritance diagram for DrawElement:

Object Circle Group Rectangle Drawing::Contents List of all members.

Public Methods

 DrawElement (const Position &=Position(0.0, 0.0), color=Black)
 Create something at the given position with the given fill color.

virtual ~DrawElement ()
virtual void add_feature (std::string, std::string)
 Permit color to be specified.

virtual void add_feature (std::string, Position)
 Permit the center to be specified.

Position get_center () const
 Return the center of the thing.

virtual void move (const Position &new_center)
 Move the thing to a new place.

color get_color () const
 Return the fill color of the thing.

virtual void set_color (color)
 Set the fill color.

virtual bool is_hit (const Position &)=0
 Determine whether the given position is inside the shape.

bool is_selected () const
 Is this element selected? If selected, it is drawn with a border.

virtual void set_selected (bool)
 Set whether selected.

virtual int mutate (const Position &new_position)
 Change the shape in some way given a position.

virtual void render (SimpleWindow *)=0
 Draw the thing in the window.

bool set_location (Group *)
 Set the group for an orphaned element.

bool reset_location (Group *)
 Remove a draw element from the group.

bool check_location (Group *)
 Returns true if this element indeed has this group.


Protected Methods

void inform_location ()
 Called to let the group know that this thing has changed in some way.

Groupget_location () const
 Return the group of this element.


Private Attributes

Position center
color the_color
bool selected
Grouplocation

Detailed Description

A part of the drawing.

Each draw element supports a generic set of operations. Each element is located inside some Group (except for the outermost group).


Constructor & Destructor Documentation

DrawElement::DrawElement const Position &    = Position(0.0, 0.0),
color    = Black
 

Create something at the given position with the given fill color.

00006   : center(pos), the_color(c), selected(false), location(0) {}

DrawElement::~DrawElement   [virtual]
 

00008 {}


Member Function Documentation

void DrawElement::add_feature std::string   ,
Position   
[virtual]
 

Permit the center to be specified.

Reimplemented from Object.

00020 {
00021   if (key == "center") {
00022     move(pos);
00023   } else {
00024     Object::add_feature(key,pos);
00025   }
00026 }

void DrawElement::add_feature std::string   ,
std::string   
[virtual]
 

Permit color to be specified.

Reimplemented from Object.

00011 {
00012   if (key == "color") {
00013     if (!Utilities::from_string(value,the_color))
00014       throw unknown_feature("unknown color name " + value);
00015   } else {
00016     Object::add_feature(key,value);
00017   }
00018 }

bool DrawElement::check_location Group  
 

Returns true if this element indeed has this group.

00085 {
00086   return (location == loc);
00087 }

Position DrawElement::get_center   const
 

Return the center of the thing.

00029 {
00030   return center;
00031 }

color DrawElement::get_color   const
 

Return the fill color of the thing.

00041 {
00042   return the_color;
00043 }

Group * DrawElement::get_location   const [protected]
 

Return the group of this element.

This function is made protected because normally the group of an element should be either irrelevant or else known already.

00095 {
00096   return location;
00097 }

void DrawElement::inform_location   [protected]
 

Called to let the group know that this thing has changed in some way.

00090 {
00091   location->set_changed(this);
00092 }

virtual bool DrawElement::is_hit const Position &    [pure virtual]
 

Determine whether the given position is inside the shape.

May record where it hit for a mutate operation.

Returns :
true if inside.

Implemented in Circle, Group, and Rectangle.

bool DrawElement::is_selected   const
 

Is this element selected? If selected, it is drawn with a border.

00053 {
00054   return selected;
00055 }

void DrawElement::move const Position &    new_center [virtual]
 

Move the thing to a new place.

Reimplemented in Group.

00035 {
00036   center = new_center;
00037   if (location) location->set_changed(this);
00038 }

int DrawElement::mutate const Position &    new_position [virtual]
 

Change the shape in some way given a position.

The type of mutation depends on the shape, and also (perhaps) on the previous hit.

Returns :
1 if successful

Reimplemented in Circle, Group, and Rectangle.

00065 {
00066   move(new_position);
00067   return 1;
00068 }

virtual void DrawElement::render SimpleWindow   [pure virtual]
 

Draw the thing in the window.

Implemented in Circle, Group, and Rectangle.

bool DrawElement::reset_location Group  
 

Remove a draw element from the group.

Returns :
false is already orphaned.

00078 {
00079   if (location != loc) return false;
00080   location = 0;
00081   return true;
00082 }

void DrawElement::set_color color    c [virtual]
 

Set the fill color.

Reimplemented in Group.

00047 {
00048   the_color = c;
00049   if (location) location->set_changed(this);
00050 }

bool DrawElement::set_location Group  
 

Set the group for an orphaned element.

Returns :
false if the element already has a group.

00071 {
00072   if (location) return false;
00073   location = loc;
00074   return true;
00075 }

void DrawElement::set_selected bool    [virtual]
 

Set whether selected.

This function should only be called by the group in which this element resides, or (for the outermost grpup) by the drawing object itself.

Reimplemented in Group.

00059 {
00060   selected = s;
00061   if (location) location->set_changed(this);
00062 }


Member Data Documentation

Position DrawElement::center [private]
 

Group* DrawElement::location [private]
 

bool DrawElement::selected [private]
 

color DrawElement::the_color [private]
 


The documentation for this class was generated from the following files:
Generated on Fri Nov 8 10:52:29 2002 for Draw by doxygen1.2.17