Inheritance diagram for Drawing::ToolWindow:
Public Methods | |
ToolWindow (Drawing *drawing, int across, int down) | |
Create a tool window. | |
virtual int | MouseClickEvent (const Position &) |
Calls the function associated with mouse clicks. | |
virtual int | RefreshEvent () |
Calls the function assoicated with the window being exposed. | |
Tool * | current_tool () |
Return the currently selected tool (if any). | |
virtual void | highlight (color c=Red) |
Highlight currently selected tool with color. | |
Private Attributes | |
Drawing *const | drawing |
int | current_index |
Static Private Attributes | |
const float | TOOL_WIDTH = 1.2 |
The following parameters indicate how big we want space in the tool bar for buttons. | |
const float | TOOL_HEIGHT = 1.2 |
|
Create a tool window.
00241 : 00242 SimpleWindow("Toolbar",TOOL_WIDTH*a, TOOL_HEIGHT*down, 00243 d->canvas->GetCenter()+ 00244 Position(d->canvas->GetWidth()/2+0.1, 00245 -d->canvas->GetHeight()/2)), 00246 drawing(d), 00247 current_index(-1) 00248 { 00249 Open(); 00250 // the callback is unused, but if we don't set it 00251 // we don't get any events: 00252 SetMouseClickCallback(bogus1); 00253 SetRefreshCallback(bogus2); 00254 00255 RefreshEvent(); 00256 } |
|
Return the currently selected tool (if any).
00330 { 00331 if (current_index == -1) return 0; 00332 return drawing->tools[current_index]; 00333 } |
|
Highlight currently selected tool with color.
00336 { 00337 int i = current_index%drawing->across; 00338 int j = current_index/drawing->across; 00339 Position tl(i*TOOL_WIDTH,j*TOOL_HEIGHT); 00340 Position bl(i*TOOL_WIDTH,(j+1)*TOOL_HEIGHT); 00341 Position br((i+1)*TOOL_WIDTH,(j+1)*TOOL_HEIGHT); 00342 Position tr((i+1)*TOOL_WIDTH,j*TOOL_HEIGHT); 00343 00344 RenderLine(tl,bl,c,0.1); 00345 RenderLine(bl,br,c,0.1); 00346 RenderLine(br,tr,c,0.1); 00347 RenderLine(tr,tl,c,0.1); 00348 } |
|
Calls the function associated with mouse clicks.
Reimplemented from SimpleWindow.
00259 { 00260 int i = int(pos.GetXDistance()/TOOL_WIDTH); 00261 int j = int(pos.GetYDistance()/TOOL_HEIGHT); 00262 int index = j*drawing->across + i; 00263 // cout << "Clicked on tool " << index << endl; 00264 Tool *current = current_tool(); 00265 if (current) { 00266 current->stop(); 00267 highlight(White); 00268 } 00269 if (i >= 0 && i < drawing->across && 00270 index >= 0 && index < int(drawing->tools.size())) { 00271 current_index = index; 00272 current = current_tool(); 00273 highlight(Red); 00274 current->start(); 00275 } else { 00276 current_index = -1; 00277 } 00278 drawing->refresh_if_needed(); 00279 return 1; 00280 } |
|
Calls the function assoicated with the window being exposed.
Reimplemented from SimpleWindow.
00296 { 00297 int across = int(GetWidth()/TOOL_WIDTH+0.5); 00298 int down = int(GetHeight()/TOOL_HEIGHT+0.5); 00299 00300 if (across == 0) across = 1; 00301 if (down == 0) down = 1; 00302 00303 drawing->across = across; 00304 drawing->down = down; 00305 00306 // cout << "Toolbar: " << across << "X" << down << endl; 00307 00308 vector<Tool*> tools = drawing->tools; 00309 00310 // Erase(Position(0,0),GetWidth(),GetHeight()); 00311 00312 for (unsigned index=0; index < tools.size(); ++index) { 00313 BitMap b(this); 00314 if (!load_bitmap(b,tools[index]->get_bitmap_name())) { 00315 cerr << "Cannot load bitmap" << endl; 00316 continue; 00317 } 00318 float width = b.GetWidth(); 00319 float height = b.GetHeight(); 00320 int i = index % across; 00321 int j = index / across; 00322 b.SetPosition(Position((i+0.5)*TOOL_WIDTH-width/2.0, 00323 (j+0.5)*TOOL_HEIGHT-height/2.0)); 00324 b.Draw(); 00325 } 00326 00327 return 1; 00328 } |
|
|
|
|
|
|
|
The following parameters indicate how big we want space in the tool bar for buttons. In this case we expect buttons to be 1x1, so we leave 1mm around each button for highlighting: |