KrWidget Class Reference

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

#include <widget.h>

Inheritance diagram for KrWidget:

KrImNode IKrWidgetListener grinliz::Listener< IKrWidgetListener > KrButton KrConsole KrImageListBox KrListBox KrProgress KrTextWidget KrPushButton KrToggleButton List of all members.

Public Member Functions

virtual KrWidgetToWidget ()
 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.
KrWidgetParentWidget ()
 Find the parent of the widget that is also a widget.

Public Attributes

grinliz::Publisher< IKrWidgetListenerwidgetPublish
 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:

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:


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:
Generated on Thu Jul 20 20:45:33 2006 for Kyra by  doxygen 1.4.7