Gui.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ==Gui Subsystem==
  2. -------------------------------------------------------------------------------
  3. - Description
  4. The Gui subsystem provides an easy way to create in-game windows and populate
  5. them with widgets.
  6. - The basic Widget:
  7. Each widget, wether a simple button or a whole complex window, inherit from a
  8. generic Widget. This class provides the skeleton for the Gui subsystem. It re
  9. presents a generic 'Gui object' that has a dimension and can be displayed on
  10. screen. Its functionalities are common to all the derived types and are:
  11. - Children handling and displaying:
  12. Each widget contains a list of children widgets, representing a tree as a w
  13. hole. A widgets belongs to his parent, that can be specified only in the wi
  14. dget's constructor or by attaching later the widget to a parent if null was
  15. specified in the constructor, and once set it can't change.
  16. If no custom method is specified, the drawing of children is performed auto
  17. matically, otherwise DrawChildren must be called when defining the OnDraw()
  18. method (usually at the end).
  19. - Mouse interaction:
  20. Mouse events are received through the On[Preview]Mouse???() method (where
  21. ??? varies depending on the event being notified). Each mouse event is rece
  22. ived only if the corresponding action was done inside the widget or one of
  23. its children. An exception to this is when the widget explicitly captures t
  24. he mouse: in this case, the widget will receive the mouse events regadrless
  25. of the fact that they occoured inside or outside the widget itself or one o
  26. f its children. Of course in this case MouseIn and MouseOut occour only whe
  27. n the mouse enters or exits the widget that captures the mouse, otherwise t
  28. hey would not make sense.
  29. - Position and dimension:
  30. Size and position of widgets can be selected using SetDesiredSize() and Set
  31. DesiredPosition() methods. Actual values may vary depending on the layout b
  32. eing used. If values of -1 are specified for the desired size, the layout s
  33. ystem will interpret it as 'i don't care, you choose', which for default la
  34. yout means expand the widget as much as possible. Margins, Horizontal and V
  35. ertical alignment provide a convenient way to handle how widgets are displa
  36. yed.
  37. - Events:
  38. Each interaction with the Gui can create an event for the application to resp
  39. ond.
  40. There are two kinds of events: OnEvents, and Signals.
  41. - OnEvents:
  42. The OnEvents are used by the Gui elements to handle specific behaviours o
  43. f the elements themselves: for example, a ListView can use the OnPreviewM
  44. ouseUp (covered later) to detect the selection of a child item. The Progr
  45. ammer should use these events only when defining custom widgets.
  46. Some(All?) OnEvents follow the Tunneling-Bubbling pattern:
  47. When an OnEvent fires, for example an OnMouseMove event, the following pr
  48. ocedure is followed:
  49. 1) The element on which the event occours is determined (called Target).
  50. 2) From the Root Ancestor of the Target, traversing the Widget Tree down
  51. the branch that leads to the Target, OnPreviewMouseMove is called on e
  52. ach widget encountered until some of them sets stopPropagation or the
  53. Target is reached.
  54. 3) The same procedure is followed, from the Target to the Root Ancestor,
  55. but this time calling OnMouseMove.
  56. This mechanism allows parent widgets to be notified of events before the
  57. Target can know it, allowing them to react accordingly: for example, a Li
  58. stViewItems listen for OnPreviewMouseUp to detect when they are selected.
  59. Note: Stopping a Preview event via stopPropagation does not block the cor
  60. responding Bubbling event to be performed.
  61. - Signals:
  62. Signals expose a set of events that a Programmer can hook onto to detect
  63. when a particular User action occours. Each widget has its signals: a Lis
  64. tView for example, has the SelectionChangedSignal that fires whenever the
  65. selection changes to another item.
  66. To attach to a signal, simply define a Slot with the same signature and a
  67. n handler method and connect it to the desidered signal.
  68. - Layout:
  69. Its purpose is to give widgets a size and position. It's performed automati
  70. cally when needed, by means of the OnUpdateLayout event.
  71. By default, widgets accomodate desired sizes and position requested by the
  72. children. If a different placement is desired, custom Layout widgets must b
  73. e used. For example to place a series of button vertically, it's sufficient
  74. to create a StackLayout widget as child of the container widget, and put th
  75. e buttons inside it.
  76. - WindowsManager
  77. The WindowsManager offers an interface between the Crown Entity model and win
  78. dows. It is the container of all the windows, and is responsible of receiving
  79. keyboard and mouse events and propagate them in the windows hierarchy.
  80. Usually the user doesn't need to interface to it except for creation and wind
  81. dows assignment.
  82. - Window
  83. It's a specialized Widget that has a title bar, a close button and a client a
  84. rea where children Widgets are displayed. It is the basic host of all the wid
  85. gets. This means that non-Window widgets can only exist inside the Widget tre
  86. e of a Window.
  87. To insert a widget in the Window client area, just pass them as parent the wi
  88. dget returned by calling GetClientArea() on the window.