GUIToggle.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. public sealed class GUIToggle : GUIElement
  6. {
  7. public delegate void OnClickDelegate();
  8. public delegate void OnHoverDelegate();
  9. public delegate void OnOutDelegate();
  10. public delegate void OnToggleDelegate(bool toggled);
  11. public delegate void OnDoubleClickDelegate();
  12. public event OnClickDelegate OnClick;
  13. public event OnHoverDelegate OnHover;
  14. public event OnOutDelegate OnOut;
  15. public event OnToggleDelegate OnToggled;
  16. public event OnDoubleClickDelegate OnDoubleClick;
  17. public bool Value
  18. {
  19. get { return Internal_GetValue(mCachedPtr); }
  20. set { Internal_SetValue(mCachedPtr, value); }
  21. }
  22. public GUIToggle(GUIContent content, GUIToggleGroup toggleGroup, string style, params GUIOption[] options)
  23. {
  24. Internal_CreateInstance(this, content, toggleGroup, style, options);
  25. }
  26. public GUIToggle(GUIContent content, string style, params GUIOption[] options)
  27. {
  28. Internal_CreateInstance(this, content, null, style, options);
  29. }
  30. public GUIToggle(GUIContent content, string style)
  31. {
  32. Internal_CreateInstance(this, content, null, style, new GUIOption[0]);
  33. }
  34. public GUIToggle(GUIContent content, params GUIOption[] options)
  35. {
  36. Internal_CreateInstance(this, content, null, "", options);
  37. }
  38. public GUIToggle(GUIContent content, GUIToggleGroup toggleGroup, string style)
  39. {
  40. Internal_CreateInstance(this, content, toggleGroup, style, new GUIOption[0]);
  41. }
  42. public GUIToggle(GUIContent content, GUIToggleGroup toggleGroup, params GUIOption[] options)
  43. {
  44. Internal_CreateInstance(this, content, toggleGroup, "", options);
  45. }
  46. public void SetContent(GUIContent content)
  47. {
  48. Internal_SetContent(mCachedPtr, content);
  49. }
  50. public void SetTint(Color color)
  51. {
  52. Internal_SetTint(mCachedPtr, color);
  53. }
  54. private void DoOnClick()
  55. {
  56. if (OnClick != null)
  57. OnClick();
  58. }
  59. private void DoOnHover()
  60. {
  61. if (OnHover != null)
  62. OnHover();
  63. }
  64. private void DoOnOut()
  65. {
  66. if (OnOut != null)
  67. OnOut();
  68. }
  69. private void DoOnToggled(bool toggled)
  70. {
  71. if (OnToggled != null)
  72. OnToggled(toggled);
  73. }
  74. private void DoOnDoubleClick()
  75. {
  76. if (OnDoubleClick != null)
  77. OnDoubleClick();
  78. }
  79. [MethodImpl(MethodImplOptions.InternalCall)]
  80. private static extern void Internal_CreateInstance(GUIToggle instance, GUIContent content,
  81. GUIToggleGroup toggleGroup, string style, GUIOption[] options);
  82. [MethodImpl(MethodImplOptions.InternalCall)]
  83. private static extern void Internal_SetContent(IntPtr nativeInstance, GUIContent content);
  84. [MethodImpl(MethodImplOptions.InternalCall)]
  85. private static extern bool Internal_GetValue(IntPtr nativeInstance);
  86. [MethodImpl(MethodImplOptions.InternalCall)]
  87. private static extern void Internal_SetValue(IntPtr nativeInstance, bool value);
  88. [MethodImpl(MethodImplOptions.InternalCall)]
  89. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  90. }
  91. }