use_tool_with_selected_objects<ElevateTool>();
else if(key==Msp::Input::KEY_ESC)
{
- if(cur_tool)
- {
- delete cur_tool;
- cur_tool = 0;
- }
- else if(mode==CATALOGUE)
+ if(mode==CATALOGUE)
mode = SELECT;
- else
+ else if(mode==SELECT)
selection.clear();
}
else if(key==Msp::Input::KEY_X)
template<typename T>
T *Designer::use_tool_with_selected_objects()
{
- T *tool = new T(*this, mouse, selection.get_objects());
+ T *tool = new T(*this, keyboard, mouse, selection.get_objects());
use_tool(tool);
return tool;
}
template<typename T>
T *Designer::use_tool()
{
- T *tool = new T(*this, mouse);
+ T *tool = new T(*this, keyboard, mouse);
use_tool(tool);
return tool;
}
using namespace Msp;
using namespace R2C2;
-ElevateTool::ElevateTool(Designer &d, Input::Mouse &m, const set<Object *> &o):
- Manipulator(d, m, o)
+ElevateTool::ElevateTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &o):
+ Manipulator(d, k, m, o)
{
origin = pointer.y;
}
float origin;
public:
- ElevateTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+ ElevateTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
virtual void axis_motion(unsigned, float, float);
};
using namespace Msp;
using namespace R2C2;
-ExtendTool::ExtendTool(Designer &d, Input::Mouse &m, const set<Object *> &objects):
- Tool(d, m)
+ExtendTool::ExtendTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &objects):
+ Tool(d, k, m)
{
for(set<Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
if(Track *t = dynamic_cast<Track *>(*i))
std::vector<R2C2::Track *> extend_tracks;
public:
- ExtendTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+ ExtendTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
virtual ~ExtendTool();
void connect();
using namespace R2C2;
using namespace Msp;
-Manipulator::Manipulator(Designer &d, Input::Mouse &m, const set<Object *> &objs):
- Tool(d, m)
+Manipulator::Manipulator(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &objs):
+ Tool(d, k, m)
{
set<Object *> pending = objs;
while(!pending.empty())
R2C2::Vector center;
public:
- Manipulator(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+ Manipulator(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
virtual ~Manipulator();
private:
#include <cmath>
#include <msp/gl/meshbuilder.h>
#include <msp/gl/renderer.h>
+#include <msp/input/keys.h>
#include <msp/strings/format.h>
#include "designer.h"
#include "3d/layout.h"
using namespace R2C2;
using namespace Msp;
-Measure::Measure(Designer &d, Input::Mouse &m):
- Tool(d, m),
+Measure::Measure(Designer &d, Input::Keyboard &k, Input::Mouse &m):
+ Tool(d, k, m),
start_pinned(false),
mesh((GL::COLOR4_UBYTE, GL::VERTEX3))
{
designer.get_layout_3d().get_scene().remove(*this);
}
+void Measure::back()
+{
+ if(start_pinned)
+ {
+ start_pinned = false;
+ update_mesh();
+ }
+ else
+ set_done(true);
+}
+
+void Measure::key_press(unsigned key)
+{
+ if(key==Input::KEY_ESC)
+ back();
+ else
+ Tool::key_press(key);
+}
+
void Measure::button_press(unsigned btn)
{
if(btn==1)
start_pinned = true;
}
else if(btn==3)
- {
- if(start_pinned)
- {
- start_pinned = false;
- update_mesh();
- }
- else
- set_done(true);
- }
+ back();
}
void Measure::pointer_motion()
Msp::GL::Mesh mesh;
public:
- Measure(Designer &, Msp::Input::Mouse &);
+ Measure(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &);
virtual ~Measure();
float get_parallel_distance() const { return par_dist; }
const R2C2::Angle &get_angle_difference() const { return adiff; }
private:
+ void back();
+ virtual void key_press(unsigned);
virtual void button_press(unsigned);
virtual void pointer_motion();
using namespace Msp;
using namespace R2C2;
-MoveTool::MoveTool(Designer &d, Input::Mouse &m, const set<Object *> &o):
- Manipulator(d, m, o),
+MoveTool::MoveTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &o):
+ Manipulator(d, k, m, o),
origin(ground_pointer)
{
for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
R2C2::Vector origin;
public:
- MoveTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+ MoveTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
virtual void pointer_motion();
};
using namespace Msp;
using namespace R2C2;
-RotateTool::RotateTool(Designer &d, Input::Mouse &m, const set<Object *> &o):
- Manipulator(d, m, o),
+RotateTool::RotateTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &o):
+ Manipulator(d, k, m, o),
origin(Geometry::atan2(ground_pointer.y-center.y, ground_pointer.x-center.x))
{ }
R2C2::Angle angle;
public:
- RotateTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+ RotateTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
virtual void pointer_motion();
};
using namespace Msp;
using namespace R2C2;
-SlopeTool::SlopeTool(Designer &d, Input::Mouse &m, const set<Object *> &objects):
- Tool(d, m),
+SlopeTool::SlopeTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &objects):
+ Tool(d, k, m),
total_length(0)
{
for(set<Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
float total_length;
public:
- SlopeTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+ SlopeTool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
void even_slope(bool =false);
void flatten();
#include <sigc++/bind.h>
+#include <msp/input/keys.h>
#include "designer.h"
#include "tool.h"
using namespace Msp;
-Tool::Tool(Designer &d, Input::Mouse &mouse):
+Tool::Tool(Designer &d, Input::Keyboard &keyboard, Input::Mouse &mouse):
designer(d),
done(false),
accepted(false)
{
+ keyboard.signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Tool::key_press), false));
+ keyboard.signal_button_release.connect(sigc::bind_return(sigc::mem_fun(this, &Tool::key_release), false));
mouse.signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Tool::button_press), false));
mouse.signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Tool::axis_motion), false));
signal_done.emit();
}
+void Tool::key_press(unsigned key)
+{
+ if(key==Input::KEY_ESC)
+ set_done(false);
+ else if(key==Input::KEY_SHIFT_L || key==Input::KEY_SHIFT_R)
+ shift_held = true;
+ else if(key==Input::KEY_CTRL_L || key==Input::KEY_CTRL_R)
+ ctrl_held = true;
+}
+
+void Tool::key_release(unsigned key)
+{
+ if(key==Input::KEY_SHIFT_L || key==Input::KEY_SHIFT_R)
+ shift_held = false;
+ else if(key==Input::KEY_CTRL_L || key==Input::KEY_CTRL_R)
+ ctrl_held = false;
+}
+
void Tool::button_press(unsigned btn)
{
if(btn==1)
#include <string>
#include <sigc++/signal.h>
#include <sigc++/trackable.h>
+#include <msp/input/keyboard.h>
#include <msp/input/mouse.h>
#include "libr2c2/geometry.h"
Designer &designer;
R2C2::Vector pointer;
R2C2::Vector ground_pointer;
+ bool shift_held;
+ bool ctrl_held;
std::string status;
bool done;
bool accepted;
- Tool(Designer &, Msp::Input::Mouse &);
+ Tool(Designer &, Msp::Input::Keyboard &, Msp::Input::Mouse &);
public:
virtual ~Tool() { }
bool is_done() const { return done; }
protected:
+ virtual void key_press(unsigned);
+ virtual void key_release(unsigned);
virtual void button_press(unsigned);
virtual void axis_motion(unsigned, float, float);
virtual void pointer_motion() { }