Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Tool used for picking entities for filling out entity properties and
  4. // I/O connections. Anywhere you see an entity name field there should
  5. // be an eyedropper button next to it for picking the entity.
  6. //
  7. // TODO: make the entity field / picker button a single control?
  8. // TODO: combine the face picker with the entity picker?
  9. //
  10. //=============================================================================//
  11. #ifndef TOOLPICKENTITY_H
  12. #define TOOLPICKENTITY_H
  13. #ifdef _WIN32
  14. #pragma once
  15. #endif
  16. #include "MapEntity.h"
  17. #include "ToolInterface.h"
  18. class CMapView3D;
  19. class CMapViewLogical;
  20. class CToolPickEntity;
  21. //
  22. // Selection states for entries in our list of selected faces.
  23. //
  24. enum EntityState_t
  25. {
  26. EntityState_Select = 0, //
  27. EntityState_Partial, // Used for multiselect; the face is in at least one of the face lists being edited.
  28. EntityState_None, // Used for multiselect; to deselect partially selected faces. Otherwise they are removed from the list.
  29. };
  30. //
  31. // An entry in our list of selected entities.
  32. //
  33. struct SelectedEntity_t
  34. {
  35. CMapEntity *pEntity; // Pointer to the entity.
  36. EntityState_t eState; // The current selection state of this entity.
  37. EntityState_t eOriginalState; // The original selection state of this entity.
  38. };
  39. //
  40. // Interface for notification by the entity picking tool. Inherit from this if you
  41. // are a client of the entity picker.
  42. //
  43. class IPickEntityTarget
  44. {
  45. public:
  46. virtual void OnNotifyPickEntity(CToolPickEntity *pTool) = 0;
  47. };
  48. class CToolPickEntity : public CBaseTool
  49. {
  50. public:
  51. //
  52. // Constructor/Destructor
  53. //
  54. CToolPickEntity();
  55. ~CToolPickEntity();
  56. //
  57. // CBaseTool virtual implementations
  58. //
  59. virtual void OnDeactivate();
  60. virtual ToolID_t GetToolID(void) { return TOOL_PICK_ENTITY; }
  61. virtual bool OnLMouseUp3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint);
  62. virtual bool OnLMouseDown3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint);
  63. virtual bool OnLMouseDblClk3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint);
  64. virtual bool OnRMouseUp3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint);
  65. virtual bool OnRMouseDown3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint);
  66. virtual bool OnMouseMove3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint);
  67. virtual bool OnLMouseUpLogical(CMapViewLogical *pView, UINT nFlags, const Vector2D &vPoint) { return true; }
  68. virtual bool OnLMouseDownLogical(CMapViewLogical *pView, UINT nFlags, const Vector2D &vPoint);
  69. virtual bool OnLMouseDblClkLogical(CMapViewLogical *pView, UINT nFlags, const Vector2D &vPoint) { return true; }
  70. virtual bool OnRMouseUpLogical(CMapViewLogical *pView, UINT nFlags, const Vector2D &vPoint) { return true; }
  71. virtual bool OnRMouseDownLogical(CMapViewLogical *pView, UINT nFlags, const Vector2D &vPoint) { return true; }
  72. virtual bool OnMouseMoveLogical(CMapViewLogical *pView, UINT nFlags, const Vector2D &vPoint);
  73. //
  74. // Functions specific to this tool.
  75. //
  76. inline void Attach(IPickEntityTarget *pTarget);
  77. void AllowMultiSelect(bool bAllow);
  78. void GetSelectedEntities(CMapEntityList &EntityListFull, CMapEntityList &EntityListPartial);
  79. void SetSelectedEntities(CMapEntityList &EntityListFull, CMapEntityList &EntityListPartial);
  80. protected:
  81. void CycleSelectEntity(CMapEntity *pEntity);
  82. void DeselectAll(void);
  83. void DeselectEntity(int nIndex);
  84. void DeselectEntity(CMapEntity *pEntity);
  85. int FindEntity(CMapEntity *pEntity);
  86. void SelectEntity(CMapEntity *pEntity);
  87. void AddToList(CMapEntity *pEntity, EntityState_t eState);
  88. void RemoveFromList(int nIndex);
  89. void SetEyedropperCursor(void);
  90. IPickEntityTarget *m_pNotifyTarget; // Object to notify when selection events occur.
  91. bool m_bAllowMultiSelect; // If false, only one entity can be selected at a time.
  92. CUtlVector <SelectedEntity_t> m_Entities; // Picked entities and their selection state (partial or full).
  93. };
  94. //-----------------------------------------------------------------------------
  95. // Purpose: Attaches the given notification target to this tool. That object
  96. // will be used for all future notifications and updates by the tool.
  97. //-----------------------------------------------------------------------------
  98. void CToolPickEntity::Attach(IPickEntityTarget *pNotifyTarget)
  99. {
  100. m_pNotifyTarget = pNotifyTarget;
  101. }
  102. #endif // TOOLPICKENTITY_H