Main Page   Class Hierarchy   Compound List   File List   Compound Members  

KrWidget Class Reference

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

#include <widget.h>

Inheritance diagram for KrWidget::

KrImNode IKrWidgetListener KrButton KrConsole KrImageListBox KrListBox KrProgress KrTextWidget KrPushButton KrToggleButton List of all members.

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)
 
See also:
IsMouseListener.


virtual void MouseMove (bool down, int x, int y)
 
See also:
IsMouseListener.


virtual void MouseClick (int click, int x, int y)
 
See also:
IsMouseListener.


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.


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

void KrWidget::AddListener IKrWidgetListener  
 

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.

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.


The documentation for this class was generated from the following file:
Generated on Mon Sep 15 12:01:12 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001