/test/src/mouse/MouseTests.hx

http://github.com/silexlabs/Cocktail · Haxe · 109 lines · 66 code · 25 blank · 18 comment · 0 complexity · 110d5e6601762625161378f8ebdfb82f MD5 · raw file

  1. /*
  2. This file is part of Silex - see http://projects.silexlabs.org/?/silex
  3. Silex is Š 2010-2011 Silex Labs and is released under the GPL License:
  4. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  5. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  7. */
  8. package mouse;
  9. /**
  10. * Units tests for mouse events
  11. * @author Yannick DOMINGUEZ
  12. */
  13. import haxe.Log;
  14. import cocktail.domElement.abstract.AbstractDOMElement;
  15. import cocktail.domElement.DOMElement;
  16. import cocktail.domElement.ImageDOMElement;
  17. import cocktail.resource.ResourceLoaderManager;
  18. import utest.Assert;
  19. import utest.Runner;
  20. import utest.ui.Report;
  21. import utest.ui.common.HeaderDisplayMode;
  22. import cocktail.domElement.DOMElementData;
  23. import cocktail.domElement.GraphicDOMElement;
  24. import cocktail.mouse.Mouse;
  25. import cocktail.nativeElement.NativeElementManager;
  26. import cocktail.nativeElement.NativeElementData;
  27. import cocktail.mouse.MouseData;
  28. class MouseTests
  29. {
  30. public static function main()
  31. {
  32. new MouseTests();
  33. }
  34. public function new()
  35. {
  36. var stageDOMElement:DOMElement = new DOMElement(NativeElementManager.getRoot());
  37. var graphicDOMElement:GraphicDOMElement = new GraphicDOMElement(NativeElementManager.createNativeElement(graphic));
  38. graphicDOMElement.width = 200;
  39. graphicDOMElement.height = 200;
  40. graphicDOMElement.x = 50;
  41. graphicDOMElement.y = 50;
  42. graphicDOMElement.beginFill(monochrome( { color:0x00FF00, alpha:100 } ), LineStyleValue.none);
  43. graphicDOMElement.drawRect(0, 0, 200, 200);
  44. graphicDOMElement.endFill();
  45. stageDOMElement.addChild(graphicDOMElement);
  46. graphicDOMElement.onMouseDown = onDOMElementPress;
  47. graphicDOMElement.onMouseUp = onDOMElementRelease;
  48. graphicDOMElement.onMouseOver = onDOMElementRollOver;
  49. graphicDOMElement.onMouseOut = onDOMElementRollOut;
  50. graphicDOMElement.onMouseMove = onDOMElementMouseMove;
  51. graphicDOMElement.onMouseDoubleClick = onDOMElementDoubleClick;
  52. }
  53. /////////////////////////////////////////////////////////////////////////////////////
  54. // DOMElement mouse events callbacks
  55. ////////////////////////////////////////////////////////////////////////////////////
  56. private function onDOMElementPress(mouseEventData:MouseEventData):Void
  57. {
  58. Log.trace("mouse down");
  59. }
  60. private function onDOMElementDoubleClick(mouseEventData:MouseEventData):Void
  61. {
  62. Log.trace("mouse double click");
  63. }
  64. private function onDOMElementRelease(mouseEventData:MouseEventData):Void
  65. {
  66. Log.trace("mouse release");
  67. }
  68. private function onDOMElementRollOver(mouseEventData:MouseEventData):Void
  69. {
  70. Log.trace("mouse roll over");
  71. }
  72. private function onDOMElementRollOut(mouseEventData:MouseEventData):Void
  73. {
  74. Log.trace("mouse roll out");
  75. }
  76. private function onDOMElementMouseMove(mouseEventData:MouseEventData):Void
  77. {
  78. Log.trace("mouse move");
  79. }
  80. }