| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "i18n.h" |
| 4 |
#include "imousetool.h" |
| 5 |
#include "imousetoolevent.h" |
| 6 |
#include "iorthoview.h" |
| 7 |
|
| 8 |
namespace ui |
| 9 |
{ |
| 10 |
|
| 11 |
/** |
| 12 |
* The MoveViewTool implements the drag view functionality used in |
| 13 |
* the orthoviews. The mouse pointer is captured during its active |
| 14 |
* phase and only the move deltas are processed to translate the view origin. |
| 15 |
*/ |
| 16 |
class MoveViewTool : |
| 17 |
public MouseTool |
| 18 |
{ |
| 19 |
public: |
| 20 |
const std::string& getName() override |
| 21 |
{ |
| 22 |
static std::string name("MoveViewTool"); |
| 23 |
return name; |
| 24 |
} |
| 25 |
|
| 26 |
const std::string& getDisplayName() override |
| 27 |
{ |
| 28 |
static std::string displayName(_("Drag View")); |
| 29 |
return displayName; |
| 30 |
} |
| 31 |
|
| 32 |
unsigned int getPointerMode() override |
| 33 |
{ |
| 34 |
return PointerMode::Capture | PointerMode::Freeze | |
| 35 |
PointerMode::Hidden | PointerMode::MotionDeltas; |
| 36 |
} |
| 37 |
|
| 38 |
Result onMouseDown(Event& ev) override |
| 39 |
{ |
| 40 |
try |
| 41 |
{ |
| 42 |
dynamic_cast<OrthoViewMouseToolEvent&>(ev).getOrthoView(); |
| 43 |
return Result::Activated; |
| 44 |
} |
| 45 |
catch (std::bad_cast&) |
| 46 |
{ |
| 47 |
} |
| 48 |
|
| 49 |
return Result::Ignored; // not handled |
| 50 |
} |
| 51 |
|
| 52 |
Result onMouseMove(Event& ev) override |
| 53 |
{ |
| 54 |
try |
| 55 |
{ |
| 56 |
// We use capture mode, so orthoview event will contain the delta only |
| 57 |
auto& xyEvent = dynamic_cast<OrthoViewMouseToolEvent&>(ev); |
| 58 |
|
| 59 |
// Scroll the view |
| 60 |
xyEvent.getOrthoView().scrollByPixels(xyEvent.getDeviceDelta().x(), xyEvent.getDeviceDelta().y()); |
| 61 |
|
| 62 |
return Result::Continued; |
| 63 |
} |
| 64 |
catch (std::bad_cast&) |
| 65 |
{ |
| 66 |
} |
| 67 |
|
| 68 |
return Result::Ignored; |
| 69 |
} |
| 70 |
|
| 71 |
Result onMouseUp(Event& ev) override |
| 72 |
{ |
| 73 |
try |
| 74 |
{ |
| 75 |
// We only operate on orthoview events, so attempt to cast |
| 76 |
dynamic_cast<OrthoViewMouseToolEvent&>(ev).getOrthoView(); |
| 77 |
return Result::Finished; |
| 78 |
} |
| 79 |
catch (std::bad_cast&) |
| 80 |
{ |
| 81 |
} |
| 82 |
|
| 83 |
return Result::Ignored; |
| 84 |
} |
| 85 |
}; |
| 86 |
|
| 87 |
} |