spin-on-click.vwf.yaml 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  2. # Secretary of Defense (Personnel & Readiness).
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  5. # in compliance with the License. You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software distributed under the License
  10. # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  11. # or implied. See the License for the specific language governing permissions and limitations under
  12. # the License.
  13. ## The component representation of a spin behavior (on click)
  14. ##
  15. ## @name spin-on-click.vwf
  16. ## @namespace
  17. ---
  18. extends:
  19. http://vwf.example.com/node3.vwf
  20. properties:
  21. ## Whether the component is spinning
  22. ##
  23. ## @name spin-on-click.vwf#spin-spinning
  24. ## @property
  25. spin-spinning:
  26. set: |
  27. if ( value && ! this["spin-spinning"] ) { // starting
  28. this["spin-spinning"] = true; // set the internal value
  29. this.spin(); // run the first step and schedule the next one
  30. } else if ( ! value && this["spin-spinning"] ) { // stopping
  31. this["spin-spinning"] = false; // set the internal value
  32. }
  33. value: false
  34. ## Spin rate
  35. ##
  36. ## @name spin-on-click.vwf#spin-rate
  37. ## @property
  38. spin-rate: 1
  39. ## Spin axis
  40. ##
  41. ## @name spin-on-click.vwf#spin-axis
  42. ## @property
  43. spin-axis: [ 0, 1, 0 ]
  44. methods:
  45. ## Spin function. Updates component rotations and calls future spin
  46. ##
  47. ## @name spin-on-click.vwf#spin
  48. ## @function
  49. ##
  50. ## @returns undefined
  51. spin: |
  52. if ( this["spin-spinning"] ) { // if enabled
  53. var axis = this["spin-axis"];
  54. this.rotateBy( [ axis[0], axis[1], axis[2], this["spin-rate"], 0 ] );
  55. this.future( 0.05 ).spin(); // schedule the next step
  56. }
  57. scripts:
  58. - |
  59. this.pointerClick = function( pointerInfo ) {
  60. if ( pointerInfo.button == "left" ) {
  61. this["spin-spinning"] = ! this["spin-spinning"]; // ... toggle the enabled flag
  62. }
  63. }