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

Drawing Class Reference

A complete drawing for the draw project. More...

#include <Drawing.h>

Inheritance diagram for Drawing:

Object List of all members.

Public Types

typedef std::list< DrawElement
* >::const_iterator 
Selection

Public Methods

 Drawing ()
 Create a drawing and its subparts.

void add_feature (std::string, float)
void add_feature (std::string, std::string)
 This variation of add_feature is the only one that doesn't always throw an exception when it reaches Object.

void add_feature (std::string, Object *)
void open ()
 Start up: open windows and go.

void clear_selection ()
 Unselect all elements.

void add_selection (DrawElement *)
 Add an element to the selection.

void remove_selection (DrawElement *)
 Remove an element from the selection.

Selection begin_selection () const
 Return an iterator into the current selected elements.

Selection end_selection () const
 Return the iterator after end of current selected elements.

color current_color () const
 Return the current default color.

void set_current_color (color)
 Set the default color.

Groupget_contents () const
 Return the group holding all the elements.

SimpleWindowget_canvas () const
 Return the window into which everything is drawn.

void needs_refresh ()
 Record the fact that things have changed and that we need to update the window.

void execute_canned_input (CannedInput *)
 Execute events from this canned input file.

void click (const Position &, bool in_tool_window=false)
 Simulate a mouse click.


Protected Methods

void refresh_if_needed ()
 Repaint the window if some change has some in since the last time we painted it.


Private Attributes

Contentscontents
Canvascanvas
ToolWindowtool_window
std::string title
color the_current_color
std::list< DrawElement * > selected
std::vector< Tool * > tools
float width
float height
int across
int down
bool needs_refreshing
CannedInputcanned_input

Static Private Attributes

Drawing::Factory factory
 Factory to create drawings.


Friends

class Drawing::Canvas
class Drawing::Contents
class Drawing::ToolWindow

Detailed Description

A complete drawing for the draw project.

We only expect one instance of this class to be created. Each drawing has its own window and own tool window. A drawing has a Group in which all the elements are placed. Mouse clicks in the window are delegated to the tools. Timer events are taken as times to provide canned input and refresh events are used to redraw the canvas.


Member Typedef Documentation

typedef std::list<DrawElement*>::const_iterator Drawing::Selection
 


Constructor & Destructor Documentation

Drawing::Drawing  
 

Create a drawing and its subparts.

00027   : Object(),
00028     contents(new Contents(this)),
00029     canvas(0), tool_window(0),
00030     title(DRAW_VERSION),
00031     the_current_color(Black),
00032     selected(), tools(),
00033     width(8.0), height(8.0),
00034     across(0), down(0),
00035     needs_refreshing(false),
00036     canned_input(0)
00037 {}


Member Function Documentation

void Drawing::add_feature std::string   ,
Object  
[virtual]
 

Reimplemented from Object.

00064 {
00065   if (key == "tool") {
00066     if (Tool* tool = dynamic_cast<Tool*>(value)) {
00067       if (tool->drawing != 0) {
00068         throw runtime_error("tool already allocated to a drawing");
00069       } else {
00070         tool->drawing = this;
00071         tools.push_back(tool);
00072       }
00073     } else {
00074       throw unknown_feature("tool attribute must be tool");
00075     }
00076   } else if (key == "element") {
00077     if (DrawElement* e = dynamic_cast<DrawElement*>(value)) {
00078       contents->add_element(e);
00079     } else {
00080       throw unknown_feature("element attribute must be a drawing element");
00081     }
00082   } else {
00083     Object::add_feature(key,value);
00084   }
00085 }

void Drawing::add_feature std::string    key,
std::string    value
[virtual]
 

This variation of add_feature is the only one that doesn't always throw an exception when it reaches Object.

If the feature to add is "text", then it sets the text private variable to equal value.

Reimplemented from Object.

00055 {
00056   if (key == "title") {
00057     title = key;
00058   } else {
00059     Object::add_feature(key,value);
00060   }
00061 } 

void Drawing::add_feature std::string   ,
float   
[virtual]
 

Reimplemented from Object.

00040 {
00041   if (key == "width") {
00042     width = value;
00043   } else if (key == "height") {
00044     height = value;
00045   } else if (key == "toolbar:across") {
00046     across = int(value);
00047   } else if (key == "toolbar:down") {
00048     down = int(value);
00049   } else {
00050     Object::add_feature(key,value);
00051   }
00052 }

void Drawing::add_selection DrawElement  
 

Add an element to the selection.

00116 {
00117   if (e->check_location(this->get_contents())) {
00118     if (e->is_selected())
00119       selected.remove(e); // just in case
00120     e->set_selected(true);
00121     selected.push_back(e);
00122     needs_refresh();
00123   } else {
00124     throw invalid_argument("not located here");
00125   }
00126 }

Drawing::Selection Drawing::begin_selection   const
 

Return an iterator into the current selected elements.

00140 {
00141   return selected.begin();
00142 }

void Drawing::clear_selection  
 

Unselect all elements.

00107 {
00108   for (Selection i=selected.begin(); i != selected.end(); ++i) {
00109     (*i)->set_selected(false);
00110   }
00111   selected.erase(selected.begin(),selected.end());
00112   needs_refresh();
00113 }

void Drawing::click const Position &   ,
bool    in_tool_window = false
 

Simulate a mouse click.

00179 {
00180   if (in_tool_window) {
00181     tool_window->MouseClickEvent(pos);
00182   } else {
00183     canvas->MouseClickEvent(pos);
00184   }
00185 }

color Drawing::current_color   const
 

Return the current default color.

00150 {
00151   return the_current_color;
00152 }

Drawing::Selection Drawing::end_selection   const
 

Return the iterator after end of current selected elements.

00145 {
00146   return selected.end();
00147 }

void Drawing::execute_canned_input CannedInput  
 

Execute events from this canned input file.

00173 {
00174   canned_input = c;
00175   canvas->TimerEvent();
00176 }

SimpleWindow * Drawing::get_canvas   const
 

Return the window into which everything is drawn.

00163                                         {
00164   return canvas;
00165 }

Group * Drawing::get_contents   const
 

Return the group holding all the elements.

00159                                    {
00160   return contents;
00161 }

void Drawing::needs_refresh  
 

Record the fact that things have changed and that we need to update the window.

00168 {
00169   needs_refreshing = true;
00170 }

void Drawing::open  
 

Start up: open windows and go.

00088 {
00089   // first get the drawing window open:
00090   canvas = new Canvas(title,width,height,this);
00091   
00092   // set across and down to defaults:
00093   if (across == 0) {
00094     if (down == 0) {
00095       down = 2;
00096     }
00097     across = (tools.size()+down-1)/down;
00098   } else if (down == 0) {
00099     down = (tools.size()+across-1)/across;
00100   }
00101 
00102   // open tool window:
00103   tool_window = new ToolWindow(this,across,down);
00104 }

void Drawing::refresh_if_needed   [protected]
 

Repaint the window if some change has some in since the last time we painted it.

00188 {
00189   if (needs_refreshing) canvas->RefreshEvent();
00190 }

void Drawing::remove_selection DrawElement  
 

Remove an element from the selection.

00129 {
00130   if (e->check_location(get_contents())) {
00131     selected.remove(e);
00132     e->set_selected(false);
00133     needs_refresh();
00134   } else {
00135     throw invalid_argument("not located here");
00136   }
00137 }

void Drawing::set_current_color color   
 

Set the default color.

00155 {
00156   the_current_color = c;
00157 }


Friends And Related Function Documentation

friend class Drawing::Canvas [friend]
 

friend class Drawing::Contents [friend]
 

friend class Drawing::ToolWindow [friend]
 


Member Data Documentation

int Drawing::across [private]
 

CannedInput* Drawing::canned_input [private]
 

Canvas* Drawing::canvas [private]
 

Contents* Drawing::contents [private]
 

int Drawing::down [private]
 

Drawing::Factory Drawing::factory [static, private]
 

Factory to create drawings.

float Drawing::height [private]
 

bool Drawing::needs_refreshing [private]
 

std::list<DrawElement*> Drawing::selected [private]
 

color Drawing::the_current_color [private]
 

std::string Drawing::title [private]
 

ToolWindow* Drawing::tool_window [private]
 

std::vector<Tool*> Drawing::tools [private]
 

float Drawing::width [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