swatchButtons.ed.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Common functionality for GuiSwatchButtonCtrls.
  23. //
  24. // Note that for the mouse-event related functionality, "useMouseEvents" must be set
  25. // to true.
  26. //---------------------------------------------------------------------------------------------
  27. function GuiSwatchButtonCtrl::onMouseDragged( %this )
  28. {
  29. %payload = new GuiSwatchButtonCtrl();
  30. %payload.assignFieldsFrom( %this );
  31. %payload.position = "0 0 ";
  32. %payload.dragSourceControl = %this;
  33. %xOffset = getWord( %payload.extent, 0 ) / 2;
  34. %yOffset = getWord( %payload.extent, 1 ) / 2;
  35. %cursorpos = Canvas.getCursorPos();
  36. %xPos = getWord( %cursorpos, 0 ) - %xOffset;
  37. %yPos = getWord( %cursorpos, 1 ) - %yOffset;
  38. // Create the drag control.
  39. %ctrl = new GuiDragAndDropControl()
  40. {
  41. canSaveDynamicFields = "0";
  42. Profile = "ToolsGuiSolidDefaultProfile";
  43. HorizSizing = "right";
  44. VertSizing = "bottom";
  45. Position = %xPos SPC %yPos;
  46. extent = %payload.extent;
  47. MinExtent = "4 4";
  48. canSave = "1";
  49. Visible = "1";
  50. hovertime = "1000";
  51. deleteOnMouseUp = true;
  52. class = "GuiDragAndDropControlType_ColorSwatch";
  53. };
  54. %ctrl.add( %payload );
  55. // Start drag.
  56. Canvas.getContent().add( %ctrl );
  57. %ctrl.startDragging( %xOffset, %yOffset );
  58. }
  59. //---------------------------------------------------------------------------------------------
  60. function GuiSwatchButtonCtrl::onControlDropped( %this, %payload, %position )
  61. {
  62. if( !%payload.parentGroup.isInNamespaceHierarchy( "GuiDragAndDropControlType_ColorSwatch" ) )
  63. return;
  64. // If dropped on same button whence we came from,
  65. // do nothing.
  66. if( %payload.dragSourceControl == %this )
  67. return;
  68. // If a swatch button control is dropped onto this control,
  69. // copy it's color.
  70. if( %payload.isMemberOfClass( "GuiSwatchButtonCtrl" ) )
  71. {
  72. // If the swatch button is part of a color-type inspector field,
  73. // remember the inspector field so we can later set the color
  74. // through it.
  75. if( %this.parentGroup.isMemberOfClass( "GuiInspectorTypeColorI" ) )
  76. %this.parentGroup.apply( ColorFloatToInt( %payload.color ) );
  77. else if( %this.parentGroup.isMemberOfClass( "GuiInspectorTypeColorF" ) )
  78. %this.parentGroup.apply( %payload.color );
  79. else
  80. %this.setColor( %payload.color );
  81. }
  82. }