| 1 | /* |
|---|
| 2 | ================================================================================= |
|---|
| 3 | This file is part of Cafu, the open-source game engine and graphics engine |
|---|
| 4 | for multiplayer, cross-platform, real-time 3D action. |
|---|
| 5 | Copyright (C) 2002-2012 Carsten Fuchs Software. |
|---|
| 6 | |
|---|
| 7 | Cafu is free software: you can redistribute it and/or modify it under the terms |
|---|
| 8 | of the GNU General Public License as published by the Free Software Foundation, |
|---|
| 9 | either version 3 of the License, or (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 12 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|---|
| 13 | PURPOSE. See the GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with Cafu. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | |
|---|
| 18 | For support and more information about Cafu, visit us at <http://www.cafu.de>. |
|---|
| 19 | ================================================================================= |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #ifndef CAFU_TOOL_SELECTION_HPP_INCLUDED |
|---|
| 23 | #define CAFU_TOOL_SELECTION_HPP_INCLUDED |
|---|
| 24 | |
|---|
| 25 | #include "Tool.hpp" |
|---|
| 26 | #include "TrafoBox.hpp" |
|---|
| 27 | #include "Templates/Array.hpp" |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | class OptionsBar_SelectionToolT; |
|---|
| 31 | class Renderer2DT; |
|---|
| 32 | class ViewWindowT; |
|---|
| 33 | class ToolSelectionT; |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | class CycleHitsTimerT : public wxTimer |
|---|
| 37 | { |
|---|
| 38 | public: |
|---|
| 39 | |
|---|
| 40 | CycleHitsTimerT(ToolSelectionT& SelectionTool); |
|---|
| 41 | |
|---|
| 42 | void Notify(); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | private: |
|---|
| 46 | |
|---|
| 47 | ToolSelectionT& m_SelectionTool; |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | class ToolSelectionT : public ToolT, public ObserverT |
|---|
| 52 | { |
|---|
| 53 | public: |
|---|
| 54 | |
|---|
| 55 | ToolSelectionT(MapDocumentT& MapDoc, ToolManagerT& ToolMan, wxWindow* ParentOptionsBar); |
|---|
| 56 | ~ToolSelectionT(); |
|---|
| 57 | |
|---|
| 58 | // Implementations/overrides of ToolT methods. |
|---|
| 59 | int GetWxEventID() const { return ChildFrameT::ID_MENU_TOOLS_TOOL_SELECTION; } |
|---|
| 60 | wxWindow* GetOptionsBar(); |
|---|
| 61 | void OnActivate(ToolT* OldTool); |
|---|
| 62 | void OnDeactivate(ToolT* NewTool); |
|---|
| 63 | |
|---|
| 64 | bool OnKeyDown2D (ViewWindow2DT& ViewWindow, wxKeyEvent& KE); |
|---|
| 65 | bool OnKeyUp2D (ViewWindow2DT& ViewWindow, wxKeyEvent& KE); |
|---|
| 66 | bool OnLMouseDown2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME); |
|---|
| 67 | bool OnLMouseUp2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME); |
|---|
| 68 | bool OnMouseMove2D (ViewWindow2DT& ViewWindow, wxMouseEvent& ME); |
|---|
| 69 | int OnContextMenu2D(ViewWindow2DT& ViewWindow, wxContextMenuEvent& CE, wxMenu& Menu); |
|---|
| 70 | |
|---|
| 71 | bool OnKeyDown3D (ViewWindow3DT& ViewWindow, wxKeyEvent& KE); |
|---|
| 72 | bool OnLMouseDown3D (ViewWindow3DT& ViewWindow, wxMouseEvent& ME); |
|---|
| 73 | bool OnLMouseUp3D (ViewWindow3DT& ViewWindow, wxMouseEvent& ME); |
|---|
| 74 | bool OnMouseMove3D (ViewWindow3DT& ViewWindow, wxMouseEvent& ME); |
|---|
| 75 | int OnContextMenu3D(ViewWindow3DT& ViewWindow, wxContextMenuEvent& CE, wxMenu& Menu); |
|---|
| 76 | |
|---|
| 77 | void RenderTool2D(Renderer2DT& Renderer) const; |
|---|
| 78 | void RenderTool3D(Renderer3DT& Renderer) const; |
|---|
| 79 | bool UpdateStatusBar(ChildFrameT* ChildFrame) const; |
|---|
| 80 | |
|---|
| 81 | // ObserverT implementation. |
|---|
| 82 | void NotifySubjectChanged_Selection(SubjectT* Subject, const ArrayT<MapElementT*>& OldSelection, const ArrayT<MapElementT*>& NewSelection); |
|---|
| 83 | void NotifySubjectChanged_Deleted(SubjectT* Subject, const ArrayT<MapElementT*>& MapElements); |
|---|
| 84 | void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<MapElementT*>& MapElements, MapElemModDetailE Detail); |
|---|
| 85 | void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<MapElementT*>& MapElements, MapElemModDetailE Detail, const ArrayT<BoundingBox3fT>& OldBounds); |
|---|
| 86 | void NotifySubjectChanged_Modified(SubjectT* Subject, const ArrayT<MapElementT*>& MapElements, MapElemModDetailE Detail, const wxString& Key); |
|---|
| 87 | void NotifySubjectDies(SubjectT* dyingSubject); |
|---|
| 88 | |
|---|
| 89 | // The TypeSys related declarations for this class. |
|---|
| 90 | virtual const cf::TypeSys::TypeInfoT* GetType() const { return &TypeInfo; } |
|---|
| 91 | static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params); |
|---|
| 92 | static const cf::TypeSys::TypeInfoT TypeInfo; |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | private: |
|---|
| 96 | |
|---|
| 97 | /// This enumeration defines the essential states of this tool. |
|---|
| 98 | /// Note that in each tool state, the selection can contain any number of map elements. |
|---|
| 99 | enum ToolStateT |
|---|
| 100 | { |
|---|
| 101 | /// The LMB is up and nothing is currently happening. |
|---|
| 102 | /// The mouse cursor however is updated to indicate a likely next state if the button is pressed at the current position. |
|---|
| 103 | TS_IDLE, |
|---|
| 104 | |
|---|
| 105 | /// The LMB went down in a place where further input is required (e.g. mouse move or button release) |
|---|
| 106 | /// for deciding the action and the next state. |
|---|
| 107 | TS_UNDECIDED, |
|---|
| 108 | |
|---|
| 109 | /// There was a one-click selection, and the button is still down. |
|---|
| 110 | /// We cycle through subsets of the selected objects (each one separately, and their union) until the button is released. |
|---|
| 111 | TS_POINT_SEL, |
|---|
| 112 | |
|---|
| 113 | /// The user is dragging a box frame for map element selection. |
|---|
| 114 | TS_DRAG_SEL, |
|---|
| 115 | |
|---|
| 116 | /// The box around the selected objects is currently being transformed, that is, translated, scaled, rotated or sheared. |
|---|
| 117 | TS_BOX_TRAFO |
|---|
| 118 | }; |
|---|
| 119 | |
|---|
| 120 | /// IDs used for the items in our RMB context menus. |
|---|
| 121 | enum |
|---|
| 122 | { |
|---|
| 123 | ID_CREATE_MODEL=wxID_HIGHEST+1000, |
|---|
| 124 | ID_CREATE_PLANT |
|---|
| 125 | }; |
|---|
| 126 | |
|---|
| 127 | friend class CycleHitsTimerT; |
|---|
| 128 | |
|---|
| 129 | void OnEscape(ViewWindowT& ViewWindow); ///< Handles the ESC key event in the 2D and 3D views. |
|---|
| 130 | void UpdateTrafoBox(); |
|---|
| 131 | void CreateModel(const Vector3fT& WorldPos); |
|---|
| 132 | void CreatePlant(const Vector3fT& WorldPos); |
|---|
| 133 | void NudgeSelection(const AxesInfoT& AxesInfo, const wxKeyEvent& KE); |
|---|
| 134 | void GetToggleEffects(MapElementT* Elem, ArrayT<MapElementT*>& RemoveFromSel, ArrayT<MapElementT*>& AddToSel) const; |
|---|
| 135 | void SetHitList(const ArrayT<MapElementT*>& NewHits, bool IsControlDown); |
|---|
| 136 | void StepCurHitNr(int Step); |
|---|
| 137 | void ToggleCurHitNr(); |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | ToolStateT m_ToolState; ///< The main state of this tool. |
|---|
| 141 | TrafoBoxT m_TrafoBox; ///< The transformation box around the current selection (only dependent on the selection, not the tool state). Depending on its own state, the trafo box can show scale, rotate or shear handles. |
|---|
| 142 | |
|---|
| 143 | wxPoint m_LDownPosWin; ///< The point where the LMB went down, in window coordinates. Set for all tool states. |
|---|
| 144 | Vector3fT m_LDownPosWorld; ///< The point where the LMB went down, in world space. Set for all tool states. |
|---|
| 145 | Vector3fT m_LDragPosWorld; ///< In state TS_DRAG_SEL, this is the current point in world space of the drag (second corner of the dragging rectangle). |
|---|
| 146 | |
|---|
| 147 | CycleHitsTimerT m_CycleHitsTimer; |
|---|
| 148 | ArrayT<MapElementT*> m_HitList; ///< The list of map elements that were hit by the last LMB click in a 2D or 3D view (along the ray through the pixel). |
|---|
| 149 | int m_CurHitNr; ///< As we're cycling through the m_HitList, this is the number of the currently considered (and selected) list element. |
|---|
| 150 | |
|---|
| 151 | OptionsBar_SelectionToolT* m_OptionsBar; ///< The options bar for this tool. |
|---|
| 152 | }; |
|---|
| 153 | |
|---|
| 154 | #endif |
|---|