- Main Page
- Classes
- Files
- Directories
- Related Pages

- Class List
- Class Hierarchy
- Class Members

# KrWidget Class Reference

This is the base of any Kyra widget. More...

`#include <widget.h>`

Inheritance diagram for KrWidget:

List of all members.

## Public Member Functions
virtual KrWidget * | ToWidget ()
| Return a pointer if this is a widget.
virtual int | IsMouseListener ()
| IsMouseListener returns whether this is a mouse listener or not, and which buttons are listened to.
virtual void | MouseIn (bool down, bool in)
virtual void | MouseMove (bool down, int x, int y)
virtual bool | MouseClick (int click, int x, int y)
virtual bool | HandleWidgetEvent (KrWidget *source, const KrWidgetEvent &event)
| Handle widget events, return true if handled, false if not ours.
KrWidget * | ParentWidget ()
| Find the parent of the widget that is also a widget.
## Public Attributes
grinliz::Publisher< IKrWidgetListener > | widgetPublish
| All widgets publish events through this member.

## Detailed Description

This is the base of any Kyra widget.

A widget is much like any other Kyra image object. You new it, add it to the KrImageTree, and it is drawn as part of the Draw() pass.

Widgets don't have resources, but do use schemes which are similar.

Widgets get their events from an event manager. If you use widgets, you must therefore send events to the KrEventManager class. Widgets generally need SDL_EnableUNICODE( true ) to function correctly.

Widgets broadcast their events to "listeners." To register a class as a listener, call AddListener(). The class will then receive notification of events. The event each widget broadcast is documented on a per-widget basis.

A widget subclass can implement any of the following properties:

- MouseListeners receieve and can respond to mouse events.
- KeyListeners get keyboard focus and key messages. They grab key focus with the "tab" key or if clicked on.
- Selectable widgets have state. They can be on/off, up/down, or whatever. A KrToggleButton is a selectable widget.
- Groupable widgets are in a group, and are aware of other widgets in that group. Radio Buttons are groupable.
- Some widgets can respond to accelerator keys. Use SetAccelerator to specify a hotkey to pass to the widget.

Widgets can be nested and you can query for parents. However, Kyra regards the widget model as flat and doesn't pay attention to the nesting, with one important exception: a key event that isn't handled by a widget will be passed through its parent chain. For example, a KrConsole uses a KrTextWidget. If the KrTextWidget doesn't handle a particular key, it will get passed up to the KrConsole.

WARNING: You may want to use Widgets in window 0, if you are using multiple Kyra windows. They are not fully tested in higher window numbers. You may see placement or bounding errors in higher window numbers.

Notes for implementing your own widgets:

- All Widgets are of the type ToWidget(). To get a particular flavor, the ToExtended() method can be used.
- Widgets should initialize themselves in the AddedtoTree() method. When the engine calls your AddedtoTree() method, you can add children because you are already in the Tree(). Be sure to call the parent KrWidget::AddedtoTree() as well!
- If you have been added to the Tree(), your Engine() pointer will be non-null.

## Member Function Documentation

virtual int KrWidget::IsMouseListener | ( |  | ) | `[inline, virtual]`

IsMouseListener returns whether this is a mouse listener or not, and which buttons are listened to.

A return value of 0 is no listening. Else it can return an OR mask of the buttons ( LEFT_MOUSE, RIGHT_MOUSE, MIDDLE_MOUSE ) it wants to listen for mouse clicks.

The simple case is to only listen to the left mouse, in which case return LEFT_MOUSE (1). The click messages can then be treated like a boolean for the left mouse (1 is down, 0 is up.)

Currently, with version 2.0, only the LEFT_MOUSE is supported.

MouseIn is called when a mouse moves in to the widget. The 'down' parameter reflects the state of the left mouse button. The 'in' reflects whether it is moving to the widget (true) or away from the widget (false).

MouseMove reports when the mouse moves over this widget.

MouseClick is called when the mouse is clicked on this widget. The 'click' param will have a single value (not OR mask) of LEFT_UP, LEFT_DOWN, RIGHT_UP, etc. with x and y coordinates of the action.

In the simple case that you are only listening to the left mouse, the parameter will be essentially a boolean: 1 for the left mouse down, 0 for the left mouse up.

Reimplemented in KrPushButton, KrToggleButton, KrTextWidget, and KrImageListBox.

virtual bool KrWidget::MouseClick | ( | int | click,
|  | int | x,
|  | int | y |
| ) |  |  | `[inline, virtual]`

See also:
  IsMouseListener

Reimplemented in KrPushButton, KrToggleButton, KrTextWidget, and KrImageListBox.

virtual void KrWidget::MouseIn | ( | bool | down,
|  | bool | in |
| ) |  |  | `[inline, virtual]`

See also:
  IsMouseListener

Reimplemented in KrPushButton, KrToggleButton, KrTextWidget, and KrImageListBox.

virtual void KrWidget::MouseMove | ( | bool | down,
|  | int | x,
|  | int | y |
| ) |  |  | `[inline, virtual]`

See also:
  IsMouseListener

Reimplemented in KrPushButton, KrToggleButton, KrTextWidget, and KrImageListBox.

The documentation for this class was generated from the following file:

- widget.h