main.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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. function ShapeVectorToy::create( %this )
  23. {
  24. // Set the sandbox drag mode availability.
  25. Sandbox.allowManipulation(pan);
  26. // Set the manipulation mode.
  27. Sandbox.useManipulation(pan);
  28. // Set the toy properties
  29. // Shape determines the number of vertices for the ShapeVector
  30. ShapeVectorToy.shape = 4;
  31. // Default shape is a polygon instead of a circle
  32. ShapeVectorToy.circle = false;
  33. // Toggles filling the shape with color or leaving as an outline
  34. ShapeVectorToy.fillMode = true;
  35. // Color of the filling
  36. ShapeVectorToy.fillColor = "0.5 1 1 0.5";
  37. // Color of the border lines
  38. ShapeVectorToy.lineColor = "0.5 1 1 1";
  39. // Add custom controls for toy
  40. addNumericOption("Vertices Count", 3, 20, 1, "setShape", ShapeVectorToy.shape, true, "Selects the shape to add to the scene based on the number of vertices");
  41. addFlagOption("Make a Circle", "setCircle", ShapeVectorToy.circle, true, "Override the number of vertices to make a circle");
  42. addFlagOption("Fill mode", "setFillMode", ShapeVectorToy.fillMode, true, "Whether new shapes are filled in or not");
  43. // Reset the toy.
  44. ShapeVectorToy.reset();
  45. }
  46. //-----------------------------------------------------------------------------
  47. function ShapeVectorToy::destroy( %this )
  48. {
  49. }
  50. //-----------------------------------------------------------------------------
  51. function ShapeVectorToy::reset( %this )
  52. {
  53. // Clear the scene.
  54. SandboxScene.clear();
  55. // Add a single shape
  56. %this.addShape();
  57. }
  58. //-----------------------------------------------------------------------------
  59. function ShapeVectorToy::setShape( %this, %value )
  60. {
  61. %this.shape = %value;
  62. }
  63. //-----------------------------------------------------------------------------
  64. function ShapeVectorToy::setCircle(%this, %value)
  65. {
  66. %this.circle = %value;
  67. }
  68. //-----------------------------------------------------------------------------
  69. function ShapeVectorToy::setFillMode( %this, %value)
  70. {
  71. %this.fillMode = %value;
  72. }
  73. //-----------------------------------------------------------------------------
  74. function ShapeVectorToy::generateShape( %this )
  75. {
  76. // Create the shape vector
  77. %shape = new ShapeVector();
  78. %shape.setPosition("0 0");
  79. %shape.setSize(20);
  80. %shape.setLineColor(%this.lineColor);
  81. %shape.setFillColor(%this.fillColor);
  82. %shape.setFillMode(%this.fillMode);
  83. // Check if circle, if not make an equiangular convex polygon with n number of sides
  84. if (%this.circle)
  85. {
  86. %shape.setIsCircle(true);
  87. %shape.setCircleRadius(20);
  88. }else
  89. {
  90. %shape.setPolyPrimitive(%this.shape);
  91. }
  92. // Return the shape to be added to the scene
  93. return %shape;
  94. }
  95. //-----------------------------------------------------------------------------
  96. function ShapeVectorToy::addShape( %this )
  97. {
  98. // Create the shape.
  99. %object = %this.generateShape();
  100. // Add the sprite to the scene.
  101. SandboxScene.add( %object );
  102. }