Browse Source

Updated GuiDragAndDropCtrl

Updated this control by moving its console function to a script binding file. Also added some defaults in the constructor. Most importantly changed the end of the name from "Control" -> "Ctrl" to be consistent with the other controls.
Peter Robinson 4 years ago
parent
commit
8b9439c64f

+ 1 - 0
engine/compilers/VisualStudio 2017/Torque 2D.vcxproj

@@ -1144,6 +1144,7 @@
     <ClInclude Include="..\..\source\gui\buttons\guiCheckBoxCtrl_ScriptBinding.h" />
     <ClInclude Include="..\..\source\gui\buttons\guiCheckBoxCtrl_ScriptBinding.h" />
     <ClInclude Include="..\..\source\gui\containers\guiChainCtrl.h" />
     <ClInclude Include="..\..\source\gui\containers\guiChainCtrl.h" />
     <ClInclude Include="..\..\source\gui\containers\guiChainCtrl_ScriptBinding.h" />
     <ClInclude Include="..\..\source\gui\containers\guiChainCtrl_ScriptBinding.h" />
+    <ClInclude Include="..\..\source\gui\containers\guiDragAndDropCtrl_ScriptBinding.h" />
     <ClInclude Include="..\..\source\gui\containers\guiExpandCtrl.h" />
     <ClInclude Include="..\..\source\gui\containers\guiExpandCtrl.h" />
     <ClInclude Include="..\..\source\gui\containers\guiExpandCtrl_ScriptBinding.h" />
     <ClInclude Include="..\..\source\gui\containers\guiExpandCtrl_ScriptBinding.h" />
     <ClInclude Include="..\..\source\gui\containers\guiGridCtrl.h" />
     <ClInclude Include="..\..\source\gui\containers\guiGridCtrl.h" />

+ 3 - 0
engine/compilers/VisualStudio 2017/Torque 2D.vcxproj.filters

@@ -3325,6 +3325,9 @@
     <ClInclude Include="..\..\source\gui\guiListBoxCtrl_ScriptBinding.h">
     <ClInclude Include="..\..\source\gui\guiListBoxCtrl_ScriptBinding.h">
       <Filter>gui</Filter>
       <Filter>gui</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="..\..\source\gui\containers\guiDragAndDropCtrl_ScriptBinding.h">
+      <Filter>gui\containers</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="Torque 2D.rc" />
     <ResourceCompile Include="Torque 2D.rc" />

+ 16 - 21
engine/source/gui/containers/guiDragAndDropCtrl.cc

@@ -23,29 +23,24 @@
 #include "gui/containers/guiDragAndDropCtrl.h"
 #include "gui/containers/guiDragAndDropCtrl.h"
 #include "gui/guiCanvas.h"
 #include "gui/guiCanvas.h"
 
 
-IMPLEMENT_CONOBJECT(GuiDragAndDropControl);
+#include "guiDragAndDropCtrl_ScriptBinding.h"
 
 
-void GuiDragAndDropControl::initPersistFields()
+IMPLEMENT_CONOBJECT(GuiDragAndDropCtrl);
+
+GuiDragAndDropCtrl::GuiDragAndDropCtrl()
 {
 {
-   Parent::initPersistFields();
-   addField("deleteOnMouseUp", TypeBool, Offset(mDeleteOnMouseUp, GuiDragAndDropControl));
+	mDeleteOnMouseUp = false;
+
+	setField("profile", "GuiDefaultProfile");
 }
 }
 
 
-ConsoleMethod(GuiDragAndDropControl, startDragging, void, 2, 4, "( int x, int y ) "
-			  "@param x X coordinate relative to the point on the object on which you are clicking\n"
-			  "@param y Y coordinate relative to the point on the object on which you are clicking\n"
-			  "@note If no point is passed, or only one coordinate is passed, the method defaults to (0,0)")
+void GuiDragAndDropCtrl::initPersistFields()
 {
 {
-   Point2I offset = Point2I(0, 0);
-   if (argc > 3)
-   {
-      offset.x = dAtoi(argv[2]);
-      offset.y = dAtoi(argv[3]);
-   }
-   object->startDragging(offset);
+   Parent::initPersistFields();
+   addField("deleteOnMouseUp", TypeBool, Offset(mDeleteOnMouseUp, GuiDragAndDropCtrl));
 }
 }
 
 
-void GuiDragAndDropControl::startDragging(Point2I offset)
+void GuiDragAndDropCtrl::startDragging(Point2I offset)
 {
 {
    GuiCanvas* canvas = getRoot();
    GuiCanvas* canvas = getRoot();
    AssertFatal(canvas, "DragAndDropControl wasn't added to the gui before the drag started.");
    AssertFatal(canvas, "DragAndDropControl wasn't added to the gui before the drag started.");
@@ -61,12 +56,12 @@ void GuiDragAndDropControl::startDragging(Point2I offset)
    mLastTarget=NULL;
    mLastTarget=NULL;
 }
 }
 
 
-void GuiDragAndDropControl::onTouchDown(const GuiEvent& event)
+void GuiDragAndDropCtrl::onTouchDown(const GuiEvent& event)
 {
 {
    startDragging(event.mousePoint - mBounds.point);
    startDragging(event.mousePoint - mBounds.point);
 }
 }
 
 
-void GuiDragAndDropControl::onTouchDragged(const GuiEvent& event)
+void GuiDragAndDropCtrl::onTouchDragged(const GuiEvent& event)
 {
 {
    mBounds.point = event.mousePoint - mOffset;
    mBounds.point = event.mousePoint - mOffset;
 
 
@@ -83,7 +78,7 @@ void GuiDragAndDropControl::onTouchDragged(const GuiEvent& event)
    sendDragEvent(dragTarget, "onControlDragged");
    sendDragEvent(dragTarget, "onControlDragged");
 }
 }
 
 
-void GuiDragAndDropControl::onTouchUp(const GuiEvent& event)
+void GuiDragAndDropCtrl::onTouchUp(const GuiEvent& event)
 {
 {
    mouseUnlock();
    mouseUnlock();
 
 
@@ -94,7 +89,7 @@ void GuiDragAndDropControl::onTouchUp(const GuiEvent& event)
       deleteObject();
       deleteObject();
 }
 }
 
 
-void GuiDragAndDropControl::sendDragEvent(GuiControl* target, const char* event)
+void GuiDragAndDropCtrl::sendDragEvent(GuiControl* target, const char* event)
 {
 {
    if(!target || !target->isMethod(event))
    if(!target || !target->isMethod(event))
       return;
       return;
@@ -105,7 +100,7 @@ void GuiDragAndDropControl::sendDragEvent(GuiControl* target, const char* event)
    Con::executef(target, 3, event, Con::getIntArg(at(0)->getId()), position);
    Con::executef(target, 3, event, Con::getIntArg(at(0)->getId()), position);
 }
 }
 
 
-GuiControl* GuiDragAndDropControl::findDragTarget(Point2I mousePoint, const char* method)
+GuiControl* GuiDragAndDropCtrl::findDragTarget(Point2I mousePoint, const char* method)
 {
 {
    // If there are any children and we have a parent.
    // If there are any children and we have a parent.
    GuiControl* parent = getParent();
    GuiControl* parent = getParent();

+ 4 - 3
engine/source/gui/containers/guiDragAndDropCtrl.h

@@ -31,11 +31,12 @@
 #include "console/console.h"
 #include "console/console.h"
 #include "console/consoleTypes.h"
 #include "console/consoleTypes.h"
 
 
-class GuiDragAndDropControl : public GuiControl
+class GuiDragAndDropCtrl : public GuiControl
 {
 {
 private:
 private:
    typedef GuiControl Parent;
    typedef GuiControl Parent;
 
 
+
    // The mouse down offset from the upper left of the control.
    // The mouse down offset from the upper left of the control.
    Point2I mOffset;
    Point2I mOffset;
    bool mDeleteOnMouseUp;
    bool mDeleteOnMouseUp;
@@ -48,7 +49,7 @@ private:
    GuiControl* findDragTarget(Point2I mousePoint, const char* method);
    GuiControl* findDragTarget(Point2I mousePoint, const char* method);
 
 
 public:
 public:
-   GuiDragAndDropControl() { }
+   GuiDragAndDropCtrl();
 
 
    void startDragging(Point2I offset = Point2I(0, 0));
    void startDragging(Point2I offset = Point2I(0, 0));
 
 
@@ -58,7 +59,7 @@ public:
 
 
    static void initPersistFields();
    static void initPersistFields();
 
 
-   DECLARE_CONOBJECT(GuiDragAndDropControl);
+   DECLARE_CONOBJECT(GuiDragAndDropCtrl);
 };
 };
 
 
 #endif
 #endif

+ 44 - 0
engine/source/gui/containers/guiDragAndDropCtrl_ScriptBinding.h

@@ -0,0 +1,44 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2013 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+ConsoleMethodGroupBeginWithDocs(GuiDragAndDropCtrl, GuiControl)
+
+/*! Simulates a cursor down event on the control with an optional offset to be used when tracking the cursor.
+	@param x The horizontal offset from the top left corner of the control. Defaults to 0.
+	@param y The vertical offset from the top left corner of the control. Defaults to 0.
+	@return No return value.
+*/
+ConsoleMethodWithDocs(GuiDragAndDropCtrl, startDragging, ConsoleVoid, 2, 4, "( [S32 x], [S32 y] )")
+{
+	Point2I offset = Point2I(0, 0);
+	if (argc > 2)
+	{
+		offset.x = dAtoi(argv[2]);
+	}
+	if (argc > 3)
+	{
+		offset.y = dAtoi(argv[3]);
+	}
+	object->startDragging(offset);
+}
+
+ConsoleMethodGroupEndWithDocs(GuiDragAndDropCtrl)

+ 3 - 2
toybox/GuiEditorToy/1/main.cs

@@ -202,9 +202,9 @@ function GuiEditorToolboxDrag::onTouchDragged(%this, %index, %text)
 	%xPos = getWord(%cursorpos, 0) - %xOffset;
 	%xPos = getWord(%cursorpos, 0) - %xOffset;
 	%yPos = getWord(%cursorpos, 1) - %yOffset;
 	%yPos = getWord(%cursorpos, 1) - %yOffset;
 
 
-	%dragCtrl = new GuiDragAndDropControl() {
+	%dragCtrl = new GuiDragAndDropCtrl() {
 		canSaveDynamicFields = "0";
 		canSaveDynamicFields = "0";
-		Profile = "GuiDefaultProfile";
+		Profile = "GuiDragAndDropProfile";
 		HorizSizing = "right";
 		HorizSizing = "right";
 		VertSizing = "bottom";
 		VertSizing = "bottom";
 		Position = %xPos SPC %yPos;
 		Position = %xPos SPC %yPos;
@@ -213,6 +213,7 @@ function GuiEditorToolboxDrag::onTouchDragged(%this, %index, %text)
 		canSave = "1";
 		canSave = "1";
 		Visible = "1";
 		Visible = "1";
 		hovertime = "1000";
 		hovertime = "1000";
+		Text = %text;
 		deleteOnMouseUp = true;
 		deleteOnMouseUp = true;
 	};
 	};
 
 

+ 6 - 0
toybox/Sandbox/1/gui/guiProfiles.cs

@@ -731,3 +731,9 @@ if (!isObject(GuiLabelProfile)) new GuiControlProfile (GuiLabelProfile : GuiDefa
 	fontSize = $platformFontSize;
 	fontSize = $platformFontSize;
 	align = "left";
 	align = "left";
 };
 };
+
+if(!isObject(GuiDragAndDropProfile)) new GuiControlProfile (GuiDragAndDropProfile : GuiDefaultProfile)
+{
+   fillColor = SetColorAlpha($color4, 50);
+   fontColor = $color5;
+};