#include <Drawing.h>
Inheritance diagram for Drawing:
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. | |
Group * | get_contents () const |
Return the group holding all the elements. | |
SimpleWindow * | get_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 | |
Contents * | contents |
Canvas * | canvas |
ToolWindow * | tool_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 |
CannedInput * | canned_input |
Static Private Attributes | |
Drawing::Factory | factory |
Factory to create drawings. | |
Friends | |
class | Drawing::Canvas |
class | Drawing::Contents |
class | Drawing::ToolWindow |
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.
|
|
|
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 {} |
|
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 } |
|
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 } |
|
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 } |
|
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 } |
|
Return an iterator into the current selected elements.
00140 { 00141 return selected.begin(); 00142 } |
|
Unselect all elements.
|
|
Simulate a mouse click.
00179 { 00180 if (in_tool_window) { 00181 tool_window->MouseClickEvent(pos); 00182 } else { 00183 canvas->MouseClickEvent(pos); 00184 } 00185 } |
|
Return the current default color.
00150 { 00151 return the_current_color; 00152 } |
|
Return the iterator after end of current selected elements.
00145 { 00146 return selected.end(); 00147 } |
|
Execute events from this canned input file.
00173 { 00174 canned_input = c; 00175 canvas->TimerEvent(); 00176 } |
|
Return the window into which everything is drawn.
00163 { 00164 return canvas; 00165 } |
|
Return the group holding all the elements.
00159 { 00160 return contents; 00161 } |
|
Record the fact that things have changed and that we need to update the window.
00168 { 00169 needs_refreshing = true; 00170 } |
|
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 } |
|
Repaint the window if some change has some in since the last time we painted it.
00188 { 00189 if (needs_refreshing) canvas->RefreshEvent(); 00190 } |
|
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 } |
|
Set the default color.
00155 { 00156 the_current_color = c; 00157 } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Factory to create drawings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|