| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <string> |
| 4 |
#include <memory> |
| 5 |
#include <list> |
| 6 |
#include "imousetoolevent.h" |
| 7 |
|
| 8 |
class RenderSystem; |
| 9 |
class IRenderableCollector; |
| 10 |
class VolumeTest; |
| 11 |
|
| 12 |
namespace ui |
| 13 |
{ |
| 14 |
|
| 15 |
/** |
| 16 |
* A Tool class represents an operator which can be "used" |
| 17 |
* in DarkRadiant's Ortho- and Camera views by using the mouse. |
| 18 |
*/ |
| 19 |
class MouseTool |
| 20 |
{ |
| 21 |
public: |
| 22 |
typedef MouseToolEvent Event; |
| 23 |
|
| 24 |
enum class Result |
| 25 |
{ |
| 26 |
Ignored, // event does not apply for this tool |
| 27 |
Activated, // event handled, tool is now active |
| 28 |
Continued, // event handled, tool continues to be active |
| 29 |
Finished, // event handled, tool no longer active |
| 30 |
}; |
| 31 |
|
| 32 |
// Returns the name of this operation. This name is only used |
| 33 |
// internally and should be unique. |
| 34 |
virtual const std::string& getName() = 0; |
| 35 |
|
| 36 |
// The display name, which is also used in the status bar |
| 37 |
virtual const std::string& getDisplayName() = 0; |
| 38 |
|
| 39 |
virtual Result onMouseDown(Event& ev) = 0; |
| 40 |
virtual Result onMouseMove(Event& ev) = 0; |
| 41 |
virtual Result onMouseUp(Event& ev) = 0; |
| 42 |
|
| 43 |
// During an active operation the user may hit ESC, |
| 44 |
// in which case the onCancel event will be fired. |
| 45 |
// This should not be ignored by the tool, which should |
| 46 |
// seek to shut down any ongoing operation safely, unless it actually |
| 47 |
// wants to pass the key through and stay active (e.g. FreeMoveTool). |
| 48 |
// Classes returning Finished to this call will have the tool cleared. |
| 49 |
virtual Result onCancel(IInteractiveView&) |
| 50 |
{ |
| 51 |
// Default behaviour is to remove this tool once ESC is encountered |
| 52 |
return Result::Finished; |
| 53 |
} |
| 54 |
|
| 55 |
// A tool using pointer mode Capture might want to get notified |
| 56 |
// when the mouse capture of the window has been lost due to |
| 57 |
// the user alt-tabbing out of the app or something else. |
| 58 |
// Any tools using PointerMode::Capture must watch out for this event. |
| 59 |
virtual void onMouseCaptureLost(IInteractiveView& view) |
| 60 |
{} |
| 61 |
|
| 62 |
// Some tools might want to receive mouseMove events even when they |
| 63 |
// are not active, to send feedback to the user before the buttons |
| 64 |
// are pressed. The Clipper tool uses this to change the mouse cursor |
| 65 |
// to a crosshair when moved over a manipulatable clip point. |
| 66 |
virtual bool alwaysReceivesMoveEvents() |
| 67 |
{ |
| 68 |
return false; |
| 69 |
} |
| 70 |
|
| 71 |
// By default, when the user is dragging the mouse to the borders of |
| 72 |
// the view, the viewport will be moved along. For some tools this might |
| 73 |
// not be desirable, in which case they need to override this method to |
| 74 |
// return false. |
| 75 |
virtual bool allowChaseMouse() |
| 76 |
{ |
| 77 |
return true; |
| 78 |
} |
| 79 |
|
| 80 |
// A tool can request special mouse capture modes during its active phase |
| 81 |
// All flags can be combined, use Normal to indicate that no capturing is needed. |
| 82 |
struct PointerMode |
| 83 |
{ |
| 84 |
enum Flags |
| 85 |
{ |
| 86 |
Normal = 0, // no capturing, absolute coordinates are sent to onMouseMove, pointer will be shown |
| 87 |
Capture = 1, // capture mouse (tools should implement onMouseCaptureLost), see also MotionDeltas |
| 88 |
Freeze = 2, // pointer will be frozen and kept at the same position |
| 89 |
Hidden = 4, // pointer will be hidden |
| 90 |
MotionDeltas = 8, // onMouseMove will receive delta values relative to the capture position |
| 91 |
}; |
| 92 |
}; |
| 93 |
|
| 94 |
// Some tools might want to capture the pointer after onMouseDown |
| 95 |
// Override this method to return "Capture" instead of "Normal". |
| 96 |
virtual unsigned int getPointerMode() |
| 97 |
{ |
| 98 |
return PointerMode::Normal; |
| 99 |
} |
| 100 |
|
| 101 |
// Bitmask determining which view are refreshed in which way |
| 102 |
// after each click and mouse pointer movement event |
| 103 |
struct RefreshMode |
| 104 |
{ |
| 105 |
enum Flags |
| 106 |
{ |
| 107 |
NoRefresh = 0, // don't refresh anything |
| 108 |
Queue = 1 << 0, // queue a redraw (will be painted as soon as the app is idle) |
| 109 |
Force = 1 << 1, // force a redraw |
| 110 |
ActiveView = 1 << 2, // refresh the active view only (the one the mouse tool has been activated on) |
| 111 |
AllViews = 1 << 3, // refresh all available views |
| 112 |
}; |
| 113 |
}; |
| 114 |
|
| 115 |
virtual unsigned int getRefreshMode() |
| 116 |
{ |
| 117 |
// By default, force a refresh of the view the tool is active on |
| 118 |
return RefreshMode::Force | RefreshMode::ActiveView; |
| 119 |
} |
| 120 |
|
| 121 |
// Optional render routine that is invoked after the scene |
| 122 |
// has been drawn on the interactive window. The projection |
| 123 |
// and modelview matrix have already been set up for |
| 124 |
// overlay rendering (glOrtho). |
| 125 |
virtual void renderOverlay() |
| 126 |
{} |
| 127 |
|
| 128 |
// For in-scene rendering of active mousetools they need implement this method. |
| 129 |
// Any needed shaders should be acquired on-demand from the attached rendersystem. |
| 130 |
// Renderable objects need to be submitted to the given RenderableCollector. |
| 131 |
virtual void render(RenderSystem& renderSystem, IRenderableCollector& collector, const VolumeTest& volume) |
| 132 |
{} |
| 133 |
}; |
| 134 |
typedef std::shared_ptr<MouseTool> MouseToolPtr; |
| 135 |
|
| 136 |
} // namespace |