1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef R2_TOOL_MAINTAINED_ACTION_H
18 #define R2_TOOL_MAINTAINED_ACTION_H
27 /** This class contained common behaviour for tools that follow the following mechanism :
28 * - when the left bouton if maintained, an action if performerd on highlighted instance
29 * if the instance wasn't the selection then it becomes the selection
30 * - when the right button is pushed down while an action is performed then the action
31 * is canceled. The mouse is then captured until both right and left buttons are released
32 * - when right button is pushed down outside of action then the context menu for current selected
33 * instance is shown. If the mouse was over an highlighted instance that is not the selection then
34 * it become the selection
35 * - when right or left button are pushed then maintained and the mouse wasn't on an entity then
36 * the camera handling begins.
38 class CToolMaintainedAction
: public CTool
42 enum TState
{ Idle
, Action
, ActionNotPossible
, Canceling
};
43 CToolMaintainedAction();
44 virtual ~CToolMaintainedAction();
46 // when another tool finishes with a (double) click, it may switch to the default select move tool
47 // so the last click may be interpreted as a click "in scene", which does an unselect.
48 // Call this after switching to prevent this behavior
49 void markPreviousToolClickEnd() { _PreviousToolClickEnd
= true; }
51 virtual bool getPreviousToolClickEndFlag(bool clear
= true);
56 ///////////////////////////
57 // INTERFACE TO DERIVERS //
58 ///////////////////////////
60 virtual void beginAction(CInstance
&instance
) = 0;
61 virtual void cancelAction(CInstance
&instance
) = 0;
62 virtual void commitAction(CInstance
&instance
) = 0;
63 virtual void updateAction(CInstance
&instance
) = 0;
64 virtual const char *getCursorForPossibleAction() const = 0;
65 virtual const char *getDefaultCursor() const;
66 virtual const char *getPickCursor() const;
67 virtual bool isActionPossibleOn(const CInstance
&instance
) const = 0;
73 virtual void onFocusGained();
74 virtual bool onMouseMove();
75 virtual bool onMouseLeftButtonDown();
76 virtual bool onMouseRightButtonDown();
77 virtual bool onMouseLeftButtonUp();
78 virtual bool onMouseRightButtonUp();
79 virtual bool onMouseLeftButtonClicked();
80 virtual void updateBeforeRender();
81 virtual void updateAfterRender();
82 virtual void cancel();
87 CInstance::TRefPtr _TargetInstance
;
89 bool _RightButtonDown
;
90 bool _PreviousToolClickEnd
;
91 bool _LostFocusRecover
;
93 void updateFocusedInstance();