]> git.tdb.fi Git - r2c2.git/blob - source/designer/objectselecttool.cpp
Add a dialog to display telemetry data from the driver
[r2c2.git] / source / designer / objectselecttool.cpp
1 #include <msp/input/keys.h>
2 #include <msp/strings/format.h>
3 #include "designer.h"
4 #include "objectselecttool.h"
5
6 using namespace std;
7 using namespace Msp;
8 using namespace R2C2;
9
10 ObjectSelectTool::ObjectSelectTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, Selection &s):
11         Tool(d, k, m),
12         selection(s)
13 {
14         update_status();
15 }
16
17 void ObjectSelectTool::key_press(unsigned key)
18 {
19         if(key==Input::KEY_ESC)
20                 selection.clear();
21         else if(key==Msp::Input::KEY_PLUS)
22                 selection.select_more();
23         else if(key==Msp::Input::KEY_L && shift_held)
24                 selection.select_blocks();
25         else if(key==Msp::Input::KEY_L)
26                 selection.select_linked();
27         else
28                 return Tool::key_press(key);
29
30         update_status();
31 }
32
33 void ObjectSelectTool::button_press(unsigned btn)
34 {
35         if(btn==1)
36         {
37                 Ray ray = designer.get_view().create_ray(pointer.x, pointer.y);
38                 Object *obj = designer.get_layout().pick<Object>(ray);
39                 if(obj)
40                 {
41                         if(!shift_held)
42                                 selection.clear();
43                         selection.toggle_object(obj);
44
45                         update_status();
46                 }
47         }
48 }
49
50 void ObjectSelectTool::update_status()
51 {
52         const set<Object *> &objects = selection.get_objects();
53         float track_length = 0;
54         unsigned other_count = 0;
55         for(set<Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
56         {
57                 if(Track *track = dynamic_cast<Track *>(*i))
58                         track_length += track->get_type().get_total_length();
59                 else
60                         ++other_count;
61         }
62
63         if(!track_length && !other_count)
64                 set_status(string());
65         else
66         {
67                 string s;
68                 if(track_length)
69                 {
70                         s += format("%.2fm of track", track_length);
71                         if(other_count)
72                                 s += " and ";
73                 }
74                 if(other_count)
75                 {
76                         s += lexical_cast<string>(other_count);
77                         if(track_length)
78                                 s += " other";
79                         s += " object";
80                         if(other_count>1)
81                                 s += 's';
82                 }
83                 s += " selected";
84                 set_status(s);
85         }
86 }