IBrowserUI.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. namespace ZenFulcrum.EmbeddedBrowser {
  6. [Flags]
  7. public enum MouseButton {
  8. Left = 0x1,
  9. Middle = 0x2,
  10. Right = 0x4,
  11. }
  12. public class BrowserInputSettings {
  13. /**
  14. * How fast do we scroll?
  15. */
  16. public int scrollSpeed = 120;
  17. /**
  18. * How far can the cursor wander from its position before won't consider another click as a double/triple click?
  19. * Value is number of pixels in browser space.
  20. */
  21. public float multiclickTolerance = 6;
  22. /**
  23. * How long must we wait between clicks before we don't consider it a double/triple/etc. click?
  24. * Measured in seconds.
  25. */
  26. public float multiclickSpeed = .7f;
  27. }
  28. /**
  29. * Proxy for browser input (and current mouse cursor).
  30. * You can create your own implementation to take input however you'd like. To use your implementation,
  31. * create a new instance and assign it to browser.UIHandler just after creating the browser.
  32. */
  33. public interface IBrowserUI {
  34. /** Called once per frame by the browser before fetching properties. */
  35. void InputUpdate();
  36. /**
  37. * Returns true if the browser will be getting mouse events. Typically this is true when the mouse if over the browser.
  38. *
  39. * If this is false, the Mouse* properties will be ignored.
  40. */
  41. bool MouseHasFocus { get; }
  42. /**
  43. * Current mouse position.
  44. *
  45. * Returns the current position of the mouse with (0, 0) in the bottom-left corner and (1, 1) in the
  46. * top-right corner.
  47. */
  48. Vector2 MousePosition { get; }
  49. /** Bitmask of currently depressed mouse buttons */
  50. MouseButton MouseButtons { get; }
  51. /**
  52. * Delta X and Y scroll values since the last time InputUpdate() was called.
  53. *
  54. * Return 1 for every "click" of the scroll wheel, or smaller numbers for more incremental scrolling.
  55. */
  56. Vector2 MouseScroll { get; }
  57. /**
  58. * Returns true when the browser will receive keyboard events.
  59. *
  60. * In the simplest case, return the same value as MouseHasFocus, but you can track focus yourself if desired.
  61. *
  62. * If this is false, the Key* properties will be ignored.
  63. */
  64. bool KeyboardHasFocus { get; }
  65. /**
  66. * List of key up/down events that have happened since the last InputUpdate() call.
  67. *
  68. * The returned list is not to be altered or retained.
  69. */
  70. List<Event> KeyEvents { get; }
  71. /**
  72. * Returns a BrowserCursor instance. The Browser will update the current cursor to reflect the
  73. * mouse's position on the page.
  74. *
  75. * The IBrowserUI is responsible for changing the actual cursor, be it the mouse cursor or some in-game display.
  76. */
  77. BrowserCursor BrowserCursor { get; }
  78. /**
  79. * These settings are used to interpret the input data.
  80. */
  81. BrowserInputSettings InputSettings { get; }
  82. }
  83. }