#include <widget.h>
Inheritance diagram for KrWidget::
Public Methods | |
virtual KrWidget * | ToWidget () |
Return a pointer if this is a widget. | |
void | AddListener (IKrWidgetListener *) |
Add a pointer to a class that listens to this widget. More... | |
void | RemoveListener (IKrWidgetListener *) |
Remove a listener. Can be called at any time, even during a callback. | |
virtual int | IsMouseListener () |
IsMouseListener returns whether this is a mouse listener or not, and which buttons are listened to. More... | |
virtual void | MouseIn (bool down, bool in) |
| |
virtual void | MouseMove (bool down, int x, int y) |
| |
virtual void | MouseClick (int click, int x, int y) |
| |
virtual bool | HandleWidgetEvent (KrWidget *source, U32 event, U32 data, const SDL_Event *sdlEvent, const char *command, const char *arg) |
Handle SDL events, return true if handled, false if not ours. | |
KrWidget * | ParentWidget () |
Find the parent of the widget that is also a 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:
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:
|
Add a pointer to a class that listens to this widget. It can be added at any time (even a callback.) It should not be deleted without calling RemoveListener. |
|
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. |