2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 1998 - 2000 , Matthes Bender
* Copyright ( c ) 2001 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2009 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
/* Handles viewport editing in console mode */
# ifndef INC_C4EditCursor
# define INC_C4EditCursor
2016-04-03 18:07:56 +00:00
# include "control/C4Control.h"
# include "lib/C4Rect.h"
2016-04-03 19:06:32 +00:00
# include "object/C4DefGraphics.h"
2017-04-30 08:49:09 +00:00
# include "object/C4ObjectList.h"
# include "script/C4Value.h"
2009-05-08 13:28:41 +00:00
2016-02-18 05:11:35 +00:00
// Currently selected elements in editcursor. May be objects and other prop lists.
class C4EditCursorSelection : public std : : list < C4Value >
{
public :
StdStrBuf GetDataString ( ) const ; // Return a string like "n objects".
C4Object * GetObject ( int32_t index = 0 ) const ; // Get indexed C4Object * in list
C4Object * GetLastObject ( ) const ;
2016-11-02 23:58:02 +00:00
void ConsolidateEmpty ( ) ; // remove nullptred entries that may happen because objects got deleted
2016-02-18 05:11:35 +00:00
bool ClearPointers ( C4Object * obj ) ;
bool IsContained ( C4PropList * obj ) const ;
int32_t ObjectCount ( ) const ; // count only C4Object *
} ;
2009-05-08 13:28:41 +00:00
class C4EditCursor
2010-03-28 17:58:21 +00:00
{
public :
C4EditCursor ( ) ;
~ C4EditCursor ( ) ;
2016-02-18 05:11:35 +00:00
2010-03-28 17:58:21 +00:00
protected :
bool fAltWasDown ;
2012-04-22 20:09:06 +00:00
bool fShiftWasDown ;
2016-03-18 03:18:29 +00:00
bool has_mouse_hover ;
2016-05-23 23:22:05 +00:00
bool selection_invalid ; // if true, the property list should be updated on next execution
2010-03-28 17:58:21 +00:00
int32_t Mode ;
2016-06-17 04:07:49 +00:00
float X , Y , X2 , Y2 , Zoom ;
bool Hold , DragFrame , DragLine , DragShape , DragTransform ;
int32_t DragRot0 , DragCon0 , DragRotLast , DragConLast ;
2010-03-28 17:58:21 +00:00
C4Object * Target , * DropTarget ;
2016-06-16 20:15:15 +00:00
C4Value highlighted_object ;
2016-03-06 18:06:29 +00:00
class C4Def * creator_def ;
2016-03-19 18:39:37 +00:00
std : : unique_ptr < C4GraphicsOverlay > creator_overlay ;
2012-03-15 12:58:56 +00:00
struct ObjselItemDt {
2012-03-20 15:38:45 +00:00
C4EditCursor * EditCursor ;
2012-03-15 12:58:56 +00:00
C4Object * Object ;
2015-01-03 22:21:36 +00:00
StdCopyStrBuf Command ;
2012-03-23 21:53:56 +00:00
# if defined(USE_WIN32_WINDOWS)
2012-03-20 16:30:41 +00:00
UINT_PTR ItemId ;
# endif
2012-03-15 12:58:56 +00:00
} ;
std : : vector < ObjselItemDt > itemsObjselect ;
2012-03-23 21:53:56 +00:00
# ifdef USE_WIN32_WINDOWS
2012-03-20 15:38:45 +00:00
HMENU hMenu ;
2009-05-08 13:28:41 +00:00
# endif
2016-02-12 04:37:13 +00:00
// Selection may either be any number of objects or a single non-object prop list
2016-02-18 05:11:35 +00:00
C4EditCursorSelection selection ;
2016-04-25 20:17:10 +00:00
# ifdef WITH_QT_EDITOR
std : : unique_ptr < class C4ConsoleQtShapes > shapes ;
# endif
2010-03-28 17:58:21 +00:00
public :
void Default ( ) ;
void Clear ( ) ;
void Execute ( ) ;
void ClearPointers ( C4Object * pObj ) ;
bool ToggleMode ( ) ;
2010-09-24 17:51:34 +00:00
void Draw ( C4TargetFacet & cgo ) ;
2010-03-28 17:58:21 +00:00
int32_t GetMode ( ) ;
C4Object * GetTarget ( ) ;
bool SetMode ( int32_t iMode ) ;
bool In ( const char * szText ) ;
bool Duplicate ( ) ;
bool OpenPropTools ( ) ;
bool Delete ( ) ;
2010-12-13 22:29:14 +00:00
void GrabContents ( ) ;
2012-04-22 20:09:06 +00:00
bool LeftButtonUp ( DWORD dwKeyState ) ;
bool LeftButtonDown ( DWORD dwKeyState ) ;
bool RightButtonUp ( DWORD dwKeyState ) ;
bool RightButtonDown ( DWORD dwKeyState ) ;
bool KeyDown ( C4KeyCode KeyCode , DWORD dwKeyState ) ;
bool KeyUp ( C4KeyCode KeyCode , DWORD dwKeyState ) ;
2016-06-17 04:07:49 +00:00
bool Move ( float iX , float iY , float zoom , DWORD dwKeyState ) ;
2016-11-02 13:24:14 +00:00
bool Move ( DWORD new_key_state ) ;
2010-03-28 17:58:21 +00:00
bool Init ( ) ;
2016-03-18 03:18:29 +00:00
bool EditingOK ( bool for_landscape_drawing = false ) ;
2016-02-18 05:11:35 +00:00
C4EditCursorSelection & GetSelection ( ) { return selection ; }
2010-03-28 17:58:21 +00:00
void SetHold ( bool fToState ) { Hold = fToState ; }
2016-02-18 05:11:35 +00:00
void OnSelectionChanged ( bool by_objectlist = false ) ;
2010-03-28 17:58:21 +00:00
bool AltDown ( ) ;
bool AltUp ( ) ;
2016-03-18 03:18:29 +00:00
void SetMouseHover ( bool h ) { has_mouse_hover = h ; }
2016-06-18 14:33:08 +00:00
# ifdef WITH_QT_EDITOR
2016-04-25 20:17:10 +00:00
class C4ConsoleQtShapes * GetShapes ( ) const { return shapes . get ( ) ; }
2016-06-18 14:33:08 +00:00
# endif
2016-06-17 04:07:49 +00:00
bool HasTransformCursor ( ) const { return DragTransform | | IsHoveringTransformMarker ( ) ; }
bool IsHoveringTransformMarker ( ) const ;
2010-03-28 17:58:21 +00:00
protected :
2010-12-14 01:06:23 +00:00
void UpdateStatusBar ( ) ;
2016-03-06 18:06:29 +00:00
void ApplyCreateObject ( bool contained ) ;
2010-03-28 17:58:21 +00:00
void ApplyToolPicker ( ) ;
void ToolFailure ( ) ;
void PutContents ( ) ;
2012-04-22 20:09:06 +00:00
void UpdateDropTarget ( DWORD dwKeyState ) ;
bool DoContextMenu ( DWORD dwKeyState ) ;
2016-06-19 22:19:43 +00:00
void AppendMenuItem ( int num , const StdStrBuf & label ) ;
2010-03-28 17:58:21 +00:00
void ApplyToolFill ( ) ;
void ApplyToolRect ( ) ;
void ApplyToolLine ( ) ;
void ApplyToolBrush ( ) ;
2016-06-17 04:07:49 +00:00
void DrawObject ( C4TargetFacet & cgo , C4Object * cobj , uint32_t select_mark_color , bool highlight , bool draw_transform_marker ) ;
2016-06-16 20:15:15 +00:00
void DrawSelectMark ( C4Facet & cgo , FLOAT_RECT r , float width , uint32_t color = 0xffffffff ) ;
2016-06-17 04:07:49 +00:00
bool HasTransformMarker ( float * x , float * y , float zoom ) const ;
2010-03-28 17:58:21 +00:00
void FrameSelection ( ) ;
2016-11-20 16:39:17 +00:00
void MoveSelection ( C4Real iXOff , C4Real iYOff , bool drag_finished ) ;
void EMMoveObject ( enum C4ControlEMObjectAction eAction , C4Real tx , C4Real ty , C4Object * pTargetObj , const C4EditCursorSelection * pObjs = nullptr , const char * szScript = nullptr , bool drag_finished = false ) ;
2015-01-03 22:21:36 +00:00
void DoContextObjCommand ( C4Object * , const char * cmd ) ;
2012-03-15 12:58:56 +00:00
void ObjselectDelItems ( ) ;
2009-05-08 13:28:41 +00:00
2016-06-19 22:19:43 +00:00
public :
void DoContextObjsel ( C4Object * , bool clear ) ;
2016-06-20 05:41:15 +00:00
void PerformDuplication ( int32_t * object_numbers , int32_t object_count , bool local_call ) ;
void PerformDuplicationLegacy ( int32_t * pObjects , int32_t iObjectNum , bool fLocalCall ) ;
2016-06-19 22:19:43 +00:00
protected :
2016-02-18 05:11:35 +00:00
public :
void AddToSelection ( C4PropList * add_obj ) ; // add object to selection and do script callback. Doesn't do OnSelectionChanged().
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().
2016-11-02 23:58:02 +00:00
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().
2016-03-06 18:06:29 +00:00
// Type of object to create in object creation mode
2016-11-02 23:58:02 +00:00
void SetCreatorDef ( C4Def * new_def ) { creator_def = new_def ; creator_overlay . reset ( nullptr ) ; }
2016-03-06 18:06:29 +00:00
C4Def * GetCreatorDef ( ) { return creator_def ; }
2016-05-23 23:22:05 +00:00
void EMControl ( enum C4PacketType eCtrlType , class C4ControlPacket * pCtrl ) ;
void InvalidateSelection ( ) { selection_invalid = true ; }
void ValidateSelection ( ) { selection_invalid = false ; }
bool IsSelectionInvalidated ( ) const { return selection_invalid ; }
2016-06-16 18:59:04 +00:00
bool GetCurrentSelectionPosition ( int32_t * x , int32_t * y ) ; // return center of first selected object
2016-06-16 20:15:15 +00:00
void SetHighlightedObject ( C4Object * new_highlight ) ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
# endif