OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4EditCursor.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Handles viewport editing in console mode */
19 
20 #ifndef INC_C4EditCursor
21 #define INC_C4EditCursor
22 
23 #include "control/C4Control.h"
24 #include "lib/C4Rect.h"
25 #include "object/C4DefGraphics.h"
26 #include "object/C4ObjectList.h"
27 #include "script/C4Value.h"
28 
29 
30 // Currently selected elements in editcursor. May be objects and other prop lists.
31 class C4EditCursorSelection : public std::list<C4Value>
32 {
33 public:
34  StdStrBuf GetDataString() const; // Return a string like "n objects".
35  C4Object *GetObject(int32_t index=0) const; // Get indexed C4Object * in list
36  C4Object *GetLastObject() const;
37  void ConsolidateEmpty(); // remove nullptred entries that may happen because objects got deleted
38  bool ClearPointers(C4Object *obj);
39  bool IsContained(C4PropList *obj) const;
40  int32_t ObjectCount() const; // count only C4Object *
41 };
42 
44 {
45 public:
46  C4EditCursor();
47  ~C4EditCursor();
48 
49 protected:
53  bool selection_invalid; // if true, the property list should be updated on next execution
54  int32_t Mode;
55  float X,Y,X2,Y2,Zoom;
61  std::unique_ptr<C4GraphicsOverlay> creator_overlay;
62  struct ObjselItemDt {
66 #if defined(USE_WIN32_WINDOWS)
67  UINT_PTR ItemId;
68 #endif
69  };
70  std::vector<ObjselItemDt> itemsObjselect;
71 #ifdef USE_WIN32_WINDOWS
72  HMENU hMenu;
73 #endif
74  // Selection may either be any number of objects or a single non-object prop list
76 #ifdef WITH_QT_EDITOR
77  std::unique_ptr<class C4ConsoleQtShapes> shapes;
78 #endif
79 public:
80  void Default();
81  void Clear();
82  void Execute();
83  void ClearPointers(C4Object *pObj);
84  bool ToggleMode();
85  void Draw(C4TargetFacet &cgo);
86  int32_t GetMode();
88  bool SetMode(int32_t iMode);
89  bool In(const char *szText);
90  bool Duplicate();
91  bool OpenPropTools();
92  bool Delete();
93  void GrabContents();
94  bool LeftButtonUp(DWORD dwKeyState);
95  bool LeftButtonDown(DWORD dwKeyState);
96  bool RightButtonUp(DWORD dwKeyState);
97  bool RightButtonDown(DWORD dwKeyState);
98  bool KeyDown(C4KeyCode KeyCode, DWORD dwKeyState);
99  bool KeyUp(C4KeyCode KeyCode, DWORD dwKeyState);
100  bool Move(float iX, float iY, float zoom, DWORD dwKeyState);
101  bool Move(DWORD new_key_state);
102  bool Init();
103  bool EditingOK(bool for_landscape_drawing=false);
105  void SetHold(bool fToState) { Hold = fToState; }
106  void OnSelectionChanged(bool by_objectlist=false);
107  bool AltDown();
108  bool AltUp();
109  void SetMouseHover(bool h) { has_mouse_hover = h; }
110 #ifdef WITH_QT_EDITOR
111  class C4ConsoleQtShapes *GetShapes() const { return shapes.get(); }
112 #endif
113  bool HasTransformCursor() const { return DragTransform || IsHoveringTransformMarker(); }
114  bool IsHoveringTransformMarker() const;
115 protected:
116  void UpdateStatusBar();
117  void ApplyCreateObject(bool contained);
118  void ApplyToolPicker();
119  void ToolFailure();
120  void PutContents();
121  void UpdateDropTarget(DWORD dwKeyState);
122  bool DoContextMenu(DWORD dwKeyState);
123  void AppendMenuItem(int num, const StdStrBuf & label);
124  void ApplyToolFill();
125  void ApplyToolRect();
126  void ApplyToolLine();
127  void ApplyToolBrush();
128  void DrawObject(C4TargetFacet &cgo, C4Object *cobj, uint32_t select_mark_color, bool highlight, bool draw_transform_marker);
129  void DrawSelectMark(C4Facet &cgo, FLOAT_RECT r, float width, uint32_t color = 0xffffffff);
130  bool HasTransformMarker(float *x, float *y, float zoom) const;
131  void FrameSelection();
132  void MoveSelection(C4Real iXOff, C4Real iYOff, bool drag_finished);
133  void EMMoveObject(enum C4ControlEMObjectAction eAction, C4Real tx, C4Real ty, C4Object *pTargetObj, const C4EditCursorSelection *pObjs = nullptr, const char *szScript = nullptr, bool drag_finished = false);
134  void DoContextObjCommand(C4Object *, const char *cmd);
135  void ObjselectDelItems();
136 
137 public:
138  void DoContextObjsel(C4Object *, bool clear);
139  void PerformDuplication(int32_t *object_numbers, int32_t object_count, bool local_call);
140  void PerformDuplicationLegacy(int32_t *pObjects, int32_t iObjectNum, bool fLocalCall);
141 
142 protected:
143 public:
144  void AddToSelection(C4PropList *add_obj); // add object to selection and do script callback. Doesn't do OnSelectionChanged().
145  bool RemoveFromSelection(C4PropList *remove_obj); // remove object from selection and do script callback. return true if object was in selection before. Doesn't do OnSelectionChanged().
146  void ClearSelection(C4PropList *next_selection=nullptr); // remove all objects from selection and do script callback. if next_selection is non-null, passes that to the deselection callbacks. Doesn't do OnSelectionChanged().
147  // Type of object to create in object creation mode
148  void SetCreatorDef(C4Def *new_def) { creator_def = new_def; creator_overlay.reset(nullptr); }
150 
151  void EMControl(enum C4PacketType eCtrlType, class C4ControlPacket *pCtrl);
152  void InvalidateSelection() { selection_invalid = true; }
153  void ValidateSelection() { selection_invalid = false; }
154  bool IsSelectionInvalidated() const { return selection_invalid; }
155  bool GetCurrentSelectionPosition(int32_t *x, int32_t *y); // return center of first selected object
156  void SetHighlightedObject(C4Object *new_highlight);
157 };
158 
159 #endif
int32_t ObjectCount() const
int32_t DragCon0
Definition: C4EditCursor.h:57
void DoContextObjCommand(C4Object *, const char *cmd)
bool SetMode(int32_t iMode)
void ApplyToolPicker()
bool In(const char *szText)
void UpdateDropTarget(DWORD dwKeyState)
bool IsContained(C4PropList *obj) const
bool DragTransform
Definition: C4EditCursor.h:56
void UpdateStatusBar()
bool OpenPropTools()
void PerformDuplication(int32_t *object_numbers, int32_t object_count, bool local_call)
void PerformDuplicationLegacy(int32_t *pObjects, int32_t iObjectNum, bool fLocalCall)
C4Object * Target
Definition: C4EditCursor.h:58
std::unique_ptr< C4GraphicsOverlay > creator_overlay
Definition: C4EditCursor.h:61
void ApplyToolLine()
void FrameSelection()
void EMMoveObject(enum C4ControlEMObjectAction eAction, C4Real tx, C4Real ty, C4Object *pTargetObj, const C4EditCursorSelection *pObjs=nullptr, const char *szScript=nullptr, bool drag_finished=false)
int32_t DragRot0
Definition: C4EditCursor.h:57
C4PacketType
Definition: C4PacketBase.h:76
bool selection_invalid
Definition: C4EditCursor.h:53
C4EditCursorSelection & GetSelection()
Definition: C4EditCursor.h:104
void DrawSelectMark(C4Facet &cgo, FLOAT_RECT r, float width, uint32_t color=0xffffffff)
void ApplyToolRect()
void ObjselectDelItems()
bool ClearPointers(C4Object *obj)
bool HasTransformCursor() const
Definition: C4EditCursor.h:113
void DoContextObjsel(C4Object *, bool clear)
bool KeyDown(C4KeyCode KeyCode, DWORD dwKeyState)
C4Object * GetLastObject() const
bool IsSelectionInvalidated() const
Definition: C4EditCursor.h:154
Definition: C4Real.h:58
void ClearSelection(C4PropList *next_selection=nullptr)
C4Object * GetObject(int32_t index=0) const
void ApplyToolBrush()
C4Def * GetCreatorDef()
Definition: C4EditCursor.h:149
void EMControl(enum C4PacketType eCtrlType, class C4ControlPacket *pCtrl)
bool DoContextMenu(DWORD dwKeyState)
bool fAltWasDown
Definition: C4EditCursor.h:50
void OnSelectionChanged(bool by_objectlist=false)
void SetMouseHover(bool h)
Definition: C4EditCursor.h:109
bool LeftButtonUp(DWORD dwKeyState)
void AppendMenuItem(int num, const StdStrBuf &label)
C4ControlEMObjectAction
Definition: C4Control.h:440
Definition: C4Def.h:98
class C4Def * creator_def
Definition: C4EditCursor.h:60
void ClearPointers(C4Object *pObj)
bool LeftButtonDown(DWORD dwKeyState)
bool KeyUp(C4KeyCode KeyCode, DWORD dwKeyState)
bool IsHoveringTransformMarker() const
std::vector< ObjselItemDt > itemsObjselect
Definition: C4EditCursor.h:70
void ApplyCreateObject(bool contained)
bool Move(float iX, float iY, float zoom, DWORD dwKeyState)
int32_t DragConLast
Definition: C4EditCursor.h:57
bool RemoveFromSelection(C4PropList *remove_obj)
bool GetCurrentSelectionPosition(int32_t *x, int32_t *y)
void Draw(C4TargetFacet &cgo)
void MoveSelection(C4Real iXOff, C4Real iYOff, bool drag_finished)
C4Object * DropTarget
Definition: C4EditCursor.h:58
void SetHighlightedObject(C4Object *new_highlight)
bool fShiftWasDown
Definition: C4EditCursor.h:51
void DrawObject(C4TargetFacet &cgo, C4Object *cobj, uint32_t select_mark_color, bool highlight, bool draw_transform_marker)
bool RightButtonDown(DWORD dwKeyState)
int32_t Mode
Definition: C4EditCursor.h:54
void AddToSelection(C4PropList *add_obj)
C4EditCursorSelection selection
Definition: C4EditCursor.h:75
void SetHold(bool fToState)
Definition: C4EditCursor.h:105
int32_t DragRotLast
Definition: C4EditCursor.h:57
void InvalidateSelection()
Definition: C4EditCursor.h:152
bool RightButtonUp(DWORD dwKeyState)
void SetCreatorDef(C4Def *new_def)
Definition: C4EditCursor.h:148
uint32_t DWORD
bool EditingOK(bool for_landscape_drawing=false)
C4Object * GetTarget()
void ApplyToolFill()
C4Value highlighted_object
Definition: C4EditCursor.h:59
unsigned long C4KeyCode
StdStrBuf GetDataString() const
void ValidateSelection()
Definition: C4EditCursor.h:153
int32_t GetMode()
bool has_mouse_hover
Definition: C4EditCursor.h:52
C4EditCursor * EditCursor
Definition: C4EditCursor.h:63
bool HasTransformMarker(float *x, float *y, float zoom) const