2008-08-13 15:00:17 -07:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 2008 Freddie Witherden
|
|
|
|
Copyright (C) 2008 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
#ifndef WIDGET_H_
|
|
|
|
#define WIDGET_H_
|
|
|
|
|
2008-05-06 09:34:34 -07:00
|
|
|
// TODO: Make this cross platform (MSVC)
|
|
|
|
#include <stdint.h>
|
2008-07-02 16:18:32 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
2008-05-06 09:34:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
#include <cairo.h>
|
|
|
|
|
2008-08-31 03:17:09 -07:00
|
|
|
#if __APPLE__
|
2008-07-31 12:30:36 -07:00
|
|
|
# include <OpenGL/gl.h>
|
|
|
|
# include <OpenGL/glu.h>
|
|
|
|
#else
|
|
|
|
# include <GL/gl.h>
|
|
|
|
# include <GL/glu.h>
|
|
|
|
#endif
|
2008-07-18 15:21:54 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
#include "vector.h"
|
|
|
|
#include "geom.h"
|
|
|
|
|
2008-07-09 08:46:46 -07:00
|
|
|
#include "keycode.h"
|
2008-08-25 10:30:09 -07:00
|
|
|
#include "clipboard.h"
|
2008-08-20 06:05:44 -07:00
|
|
|
#include "font.h"
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
2008-06-22 16:28:34 -07:00
|
|
|
* Forward declarations
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
2008-06-23 05:18:19 -07:00
|
|
|
typedef struct _classInfo classInfo;
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
typedef struct _widget widget;
|
|
|
|
typedef struct _widgetVtbl widgetVtbl;
|
|
|
|
|
2008-06-22 16:28:34 -07:00
|
|
|
typedef struct _event event;
|
|
|
|
typedef struct _eventMouse eventMouse;
|
|
|
|
typedef struct _eventMouseBtn eventMouseBtn;
|
|
|
|
typedef struct _eventKey eventKey;
|
2008-07-09 08:46:46 -07:00
|
|
|
typedef struct _eventText eventText;
|
2008-07-15 03:12:03 -07:00
|
|
|
typedef struct _eventTimer eventTimer;
|
2008-08-25 08:56:58 -07:00
|
|
|
typedef struct _eventToolTip eventToolTip;
|
2008-09-05 10:05:56 -07:00
|
|
|
typedef struct _eventReposition eventReposition;
|
|
|
|
typedef struct _eventResize eventResize;
|
2008-06-22 16:28:34 -07:00
|
|
|
typedef struct _eventMisc eventMisc;
|
2008-04-24 11:07:47 -07:00
|
|
|
|
2008-08-11 12:03:48 -07:00
|
|
|
/**
|
|
|
|
* Function signature for event handler callbacks. All callback functions must
|
|
|
|
* be of this form.
|
|
|
|
*
|
|
|
|
* @param self The widget that received/handled the event.
|
|
|
|
* @param evt A pointer to the event structure. Depending on the value of
|
|
|
|
* evt->type it may be necessary to cast this to derived event
|
|
|
|
* structure (e.g., evtMouse or evtMisc).
|
|
|
|
* @param handlerId The (unique) id of this event handler. This can be used to:
|
|
|
|
* - Remove the event handler from the widgets event table;
|
2008-09-03 12:02:39 -07:00
|
|
|
* which can be done by calling widgetRemoveEventHandler.
|
|
|
|
* This will result in the event handlers destruct method
|
|
|
|
* being called, so long as such a method exists.
|
2008-08-11 12:03:48 -07:00
|
|
|
* - Set the *userData pointer by using
|
|
|
|
* widgetSetEventHandlerUserData.
|
|
|
|
* @param userData The user-data associated with the callback; this is stored
|
|
|
|
* and passed verbatim.
|
|
|
|
* @return True if the callback executed without error, otherwise false.
|
|
|
|
*/
|
|
|
|
typedef bool (*callback) (widget *self, const event *evt, int handlerId,
|
2008-07-13 08:40:58 -07:00
|
|
|
void *userData);
|
2008-04-24 11:07:47 -07:00
|
|
|
|
|
|
|
typedef struct _eventTableEntry eventTableEntry;
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-06-23 05:18:19 -07:00
|
|
|
* Information about the `type' (class) of a widget
|
|
|
|
*/
|
|
|
|
struct _classInfo
|
|
|
|
{
|
2008-06-24 03:11:03 -07:00
|
|
|
const struct _classInfo *parentType;
|
2008-06-23 05:18:19 -07:00
|
|
|
const char *ourType;
|
|
|
|
};
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-04-24 11:07:47 -07:00
|
|
|
* The valid event types
|
|
|
|
*/
|
2008-08-01 02:15:43 -07:00
|
|
|
typedef enum
|
2008-04-24 11:07:47 -07:00
|
|
|
{
|
|
|
|
// Mouse events
|
|
|
|
EVT_MOUSE_DOWN,
|
|
|
|
EVT_MOUSE_UP,
|
|
|
|
EVT_MOUSE_CLICK,
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
EVT_MOUSE_ENTER,
|
|
|
|
EVT_MOUSE_MOVE,
|
|
|
|
EVT_MOUSE_LEAVE,
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
// Keyboard events
|
|
|
|
EVT_KEY_DOWN,
|
|
|
|
EVT_KEY_UP,
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-09 08:46:46 -07:00
|
|
|
// Text input events
|
|
|
|
EVT_TEXT,
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-08-12 06:00:40 -07:00
|
|
|
// Drag events
|
|
|
|
EVT_DRAG_BEGIN,
|
|
|
|
EVT_DRAG_TRACK,
|
|
|
|
EVT_DRAG_END,
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-07-15 03:12:03 -07:00
|
|
|
// Timer events
|
|
|
|
EVT_TIMER,
|
|
|
|
EVT_TIMER_SINGLE_SHOT,
|
|
|
|
EVT_TIMER_PERSISTENT,
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-08-25 08:56:58 -07:00
|
|
|
// Tool-tip events
|
|
|
|
EVT_TOOL_TIP_SHOW,
|
|
|
|
EVT_TOOL_TIP_HIDE,
|
2008-09-05 10:05:56 -07:00
|
|
|
|
|
|
|
// Resize and reposition
|
|
|
|
EVT_RESIZE,
|
|
|
|
EVT_REPOSITION,
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
// Misc
|
|
|
|
EVT_FOCUS,
|
2008-08-02 15:56:14 -07:00
|
|
|
EVT_BLUR,
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-25 08:56:58 -07:00
|
|
|
// Destroy
|
2008-08-02 15:56:14 -07:00
|
|
|
EVT_DESTRUCT
|
2008-08-01 02:15:43 -07:00
|
|
|
} eventType;
|
2008-04-24 11:07:47 -07:00
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-04-24 11:07:47 -07:00
|
|
|
* The possible mouse states as understood by the events system
|
|
|
|
*/
|
2008-08-01 02:15:43 -07:00
|
|
|
typedef enum
|
2008-04-24 11:07:47 -07:00
|
|
|
{
|
|
|
|
BUTTON_LEFT,
|
|
|
|
BUTTON_RIGHT,
|
2008-04-25 16:20:16 -07:00
|
|
|
BUTTON_WHEEL_UP,
|
2008-04-26 03:52:41 -07:00
|
|
|
BUTTON_WHEEL_DOWN,
|
2008-04-24 11:07:47 -07:00
|
|
|
BUTTON_OTHER
|
2008-08-01 02:15:43 -07:00
|
|
|
} mouseButton;
|
2008-04-24 11:07:47 -07:00
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-08-12 06:00:40 -07:00
|
|
|
* Possible drag states
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
/// No active drag
|
|
|
|
DRAG_NONE,
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-12 06:00:40 -07:00
|
|
|
/// Drag offer pending acceptance/declination
|
|
|
|
DRAG_PENDING,
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-12 06:00:40 -07:00
|
|
|
/// Offer was accepted
|
|
|
|
DRAG_ACCEPTED,
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-12 06:00:40 -07:00
|
|
|
/// Offer was declined
|
|
|
|
DRAG_DECLINED,
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-12 06:00:40 -07:00
|
|
|
/// Drag is currently active
|
|
|
|
DRAG_ACTIVE
|
|
|
|
} dragStates;
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
|
|
|
* Event structures
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-04-24 11:07:47 -07:00
|
|
|
* The 'base' event structure. All events can be cast to this
|
|
|
|
*/
|
|
|
|
struct _event
|
|
|
|
{
|
|
|
|
// The time at which the event took place
|
|
|
|
int time;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
// The type of the event
|
|
|
|
eventType type;
|
|
|
|
};
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-04-24 11:07:47 -07:00
|
|
|
* The event structure used for mouse motion events
|
|
|
|
*/
|
|
|
|
struct _eventMouse
|
|
|
|
{
|
|
|
|
event event;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/// Location of the mouse
|
2008-04-24 11:07:47 -07:00
|
|
|
point loc;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/// Previous location of the mouse
|
2008-08-11 10:18:26 -07:00
|
|
|
point previousLoc;
|
2008-04-24 11:07:47 -07:00
|
|
|
};
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-04-24 11:07:47 -07:00
|
|
|
* The event structure used for mouse button events
|
|
|
|
*/
|
|
|
|
struct _eventMouseBtn
|
|
|
|
{
|
|
|
|
event event;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/// Location
|
2008-04-24 11:07:47 -07:00
|
|
|
point loc;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/// Button pressed
|
2008-04-24 11:07:47 -07:00
|
|
|
mouseButton button;
|
|
|
|
};
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-04-24 11:07:47 -07:00
|
|
|
* The event structure used for keyboard events
|
|
|
|
*/
|
|
|
|
struct _eventKey
|
|
|
|
{
|
|
|
|
event event;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/// The keycode of the key which was pressed
|
2008-07-09 08:46:46 -07:00
|
|
|
eventKeycode keycode;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/// Active modifier keys
|
2008-04-24 11:07:47 -07:00
|
|
|
bool ctrl;
|
|
|
|
bool shift;
|
|
|
|
bool alt;
|
|
|
|
};
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-07-09 08:46:46 -07:00
|
|
|
* The event structure for text input events
|
|
|
|
*/
|
|
|
|
struct _eventText
|
|
|
|
{
|
|
|
|
event event;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/// The text that was typed, UTF-8 encoded
|
2008-07-09 08:46:46 -07:00
|
|
|
const char *utf8;
|
|
|
|
};
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-07-15 03:12:03 -07:00
|
|
|
* The event structure for timer events
|
|
|
|
*/
|
|
|
|
struct _eventTimer
|
|
|
|
{
|
|
|
|
event event;
|
|
|
|
};
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-08-25 08:56:58 -07:00
|
|
|
* The event structure for tool-tip events
|
|
|
|
*/
|
|
|
|
struct _eventToolTip
|
|
|
|
{
|
|
|
|
event event;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-25 08:56:58 -07:00
|
|
|
widget *target;
|
|
|
|
};
|
|
|
|
|
2008-09-05 10:05:56 -07:00
|
|
|
/**
|
|
|
|
* The event structure for resize events
|
|
|
|
*/
|
|
|
|
struct _eventResize
|
|
|
|
{
|
|
|
|
event event;
|
|
|
|
|
|
|
|
/// The previous size of the widget
|
|
|
|
size oldSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The event structure for reposition events
|
|
|
|
*/
|
|
|
|
struct _eventReposition
|
|
|
|
{
|
|
|
|
event event;
|
|
|
|
|
|
|
|
/// The previous position of the widget relative to its parent
|
|
|
|
point oldPosition;
|
|
|
|
|
|
|
|
/// The previous position of the widget relative to the screen
|
|
|
|
point oldAbsolutePosition;
|
|
|
|
};
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
|
|
|
* The event structure for miscellaneous events
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
struct _eventMisc
|
|
|
|
{
|
|
|
|
event event;
|
|
|
|
};
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-04-24 11:07:47 -07:00
|
|
|
* Event table structure
|
|
|
|
*/
|
|
|
|
struct _eventTableEntry
|
|
|
|
{
|
2008-07-14 16:41:53 -07:00
|
|
|
/// The unique id of the event handler
|
|
|
|
int id;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-14 16:41:53 -07:00
|
|
|
/// The event for which the handler is registered for
|
2008-04-24 11:07:47 -07:00
|
|
|
eventType type;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-14 16:41:53 -07:00
|
|
|
/// The method to call
|
2008-04-24 11:07:47 -07:00
|
|
|
callback callback;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-24 09:58:27 -07:00
|
|
|
/// The method to call when removing the event handler
|
|
|
|
callback destructor;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-14 16:41:53 -07:00
|
|
|
/// Pointer to user supplied data to pass to callback
|
2008-04-25 16:20:16 -07:00
|
|
|
void *userData;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-15 03:12:03 -07:00
|
|
|
/// The time when the event was last called (for debugging and timer events)
|
|
|
|
int lastCalled;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-15 03:12:03 -07:00
|
|
|
/// For timer events only; how often the event should fire; in ms
|
|
|
|
int interval;
|
2008-04-24 11:07:47 -07:00
|
|
|
};
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-08-15 02:59:11 -07:00
|
|
|
* Possible types of widget animation
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
ANI_TYPE_TRANSLATE,
|
|
|
|
ANI_TYPE_ROTATE,
|
|
|
|
ANI_TYPE_SCALE,
|
|
|
|
ANI_TYPE_ALPHA,
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/// Must be the last member
|
|
|
|
ANI_TYPE_COUNT
|
|
|
|
} animationType;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/// The animation type represented by this keyframe
|
|
|
|
animationType type;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/// The time this keyframe represents in ms
|
|
|
|
int time;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/// Animation specific information
|
|
|
|
union
|
|
|
|
{
|
|
|
|
/// Where to translate ourself to, relative to our parent
|
|
|
|
point translate;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/// Number of degrees to rotate the widget by
|
|
|
|
float rotate;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/// Scale factor to scale the widget by
|
|
|
|
size scale;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/// Alpha value to use
|
|
|
|
float alpha;
|
|
|
|
} data;
|
|
|
|
} animationFrame;
|
|
|
|
|
2008-09-03 12:02:39 -07:00
|
|
|
/**
|
2008-05-06 09:34:34 -07:00
|
|
|
* The widget classes virtual method table
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
struct _widgetVtbl
|
|
|
|
{
|
2008-08-11 03:27:11 -07:00
|
|
|
bool (*handleEvent) (widget *self, const event *evt);
|
2008-06-22 16:28:34 -07:00
|
|
|
|
|
|
|
bool (*addChild) (widget *self, widget *child);
|
|
|
|
void (*removeChild) (widget *self, widget *child);
|
|
|
|
|
2008-08-11 03:27:11 -07:00
|
|
|
bool (*fireCallbacks) (widget *self, const event *evt);
|
|
|
|
bool (*fireTimerCallbacks) (widget *self, const event *evt);
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-06-22 16:28:34 -07:00
|
|
|
int (*addEventHandler) (widget *self, eventType type,
|
2008-08-24 09:58:27 -07:00
|
|
|
callback handler,
|
|
|
|
callback destructor,
|
|
|
|
void *userData);
|
2008-07-15 03:12:03 -07:00
|
|
|
int (*addTimerEventHandler) (widget *self, eventType type,
|
2008-08-02 08:47:41 -07:00
|
|
|
int interval, callback handler,
|
2008-08-24 09:58:27 -07:00
|
|
|
callback destructor,
|
2008-08-02 08:47:41 -07:00
|
|
|
void *userData);
|
2008-06-22 16:28:34 -07:00
|
|
|
void (*removeEventHandler) (widget *self, int id);
|
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
point (*animationInterpolateTranslate) (widget *self,
|
|
|
|
animationFrame k1,
|
|
|
|
animationFrame k2,
|
|
|
|
int time);
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
float (*animationInterpolateRotate) (widget *self,
|
|
|
|
animationFrame k1,
|
|
|
|
animationFrame k2,
|
|
|
|
int time);
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
point (*animationInterpolateScale) (widget *self,
|
|
|
|
animationFrame k1,
|
|
|
|
animationFrame k2,
|
|
|
|
int time);
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
float (*animationInterpolateAlpha) (widget *self,
|
|
|
|
animationFrame k1,
|
|
|
|
animationFrame k2,
|
|
|
|
int time);
|
|
|
|
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-06-22 16:28:34 -07:00
|
|
|
void (*focus) (widget *self);
|
|
|
|
void (*blur) (widget *self);
|
|
|
|
|
2008-08-12 06:00:40 -07:00
|
|
|
void (*acceptDrag) (widget *self);
|
|
|
|
void (*declineDrag) (widget *self);
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-06-22 16:28:34 -07:00
|
|
|
void (*enable) (widget *self);
|
|
|
|
void (*disable) (widget *self);
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-08-01 14:24:19 -07:00
|
|
|
void (*show) (widget *self);
|
|
|
|
void (*hide) (widget *self);
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-07-02 16:18:32 -07:00
|
|
|
size (*getMinSize) (widget *self);
|
|
|
|
size (*getMaxSize) (widget *self);
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-08-13 04:21:58 -07:00
|
|
|
void (*resize) (widget *self, int w, int h);
|
|
|
|
void (*reposition) (widget *self, int x, int y);
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-18 15:21:54 -07:00
|
|
|
void (*composite) (widget *self);
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-07-02 16:18:32 -07:00
|
|
|
void (*doDraw) (widget *self);
|
2008-07-07 12:10:23 -07:00
|
|
|
void (*doDrawMask) (widget *self);
|
2008-06-22 16:28:34 -07:00
|
|
|
bool (*doLayout) (widget *self);
|
|
|
|
|
|
|
|
void (*destroy) (widget *self);
|
2008-04-24 11:07:47 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
struct _widget
|
|
|
|
{
|
|
|
|
//--------------------------------------
|
|
|
|
// Private/protected members
|
|
|
|
//--------------------------------------
|
|
|
|
widgetVtbl *vtbl;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
2008-06-22 05:03:42 -07:00
|
|
|
* The list of registered event handlers
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
vector *eventVtbl;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
2008-06-22 05:03:42 -07:00
|
|
|
* The child widgets of ourself
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
vector *children;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
2008-06-22 05:03:42 -07:00
|
|
|
* The widgets parent widget
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
widget *parent;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-06-22 10:53:08 -07:00
|
|
|
/*
|
|
|
|
* If a mouse button is currently depressed on the widget
|
|
|
|
*/
|
|
|
|
bool hasMouseDown;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-25 08:56:58 -07:00
|
|
|
/*
|
|
|
|
* The tool-tip of the widget
|
|
|
|
*/
|
|
|
|
const char *toolTip;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-25 08:56:58 -07:00
|
|
|
/*
|
|
|
|
* If the widgets tool-tip is currently visible
|
|
|
|
*/
|
|
|
|
bool toolTipVisible;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-12 06:00:40 -07:00
|
|
|
/*
|
|
|
|
* Current drag state
|
|
|
|
*/
|
|
|
|
dragStates dragState;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-02 16:18:32 -07:00
|
|
|
/*
|
|
|
|
* The widgets cairo drawing context
|
|
|
|
*/
|
|
|
|
cairo_t *cr;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-18 15:21:54 -07:00
|
|
|
/*
|
|
|
|
* The id of the OpenGL texture to which self->cr is mapped
|
|
|
|
*/
|
|
|
|
GLuint textureId;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-07 12:10:23 -07:00
|
|
|
/*
|
|
|
|
* The widgets mouse-event mask
|
|
|
|
*/
|
|
|
|
cairo_t *maskCr;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
//--------------------------------------
|
|
|
|
// Public members
|
|
|
|
//--------------------------------------
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
|
|
|
* The id of the widget
|
|
|
|
*/
|
2008-08-17 13:51:59 -07:00
|
|
|
const char *id;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-06-23 05:18:19 -07:00
|
|
|
/*
|
|
|
|
* The class (or subclass) that widget is (used for type checking)
|
|
|
|
*/
|
2008-06-24 03:11:03 -07:00
|
|
|
const classInfo *classInfo;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
2008-08-02 08:47:41 -07:00
|
|
|
* Arbitrary user-defined data
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
void *pUserData;
|
2008-05-06 09:34:34 -07:00
|
|
|
int32_t userData;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
2008-04-27 08:14:42 -07:00
|
|
|
* The offset of the widget relative to its parent
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
2008-04-27 08:14:42 -07:00
|
|
|
point offset;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/*
|
|
|
|
* How many degrees to rotate the widget about the z-axis
|
|
|
|
*/
|
|
|
|
float rotate;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/*
|
|
|
|
* How much to scale the widget by in the x- and y-axis; the deformation is
|
|
|
|
* non vector
|
|
|
|
*/
|
|
|
|
point scale;
|
2008-08-25 13:37:41 -07:00
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/*
|
|
|
|
* Alpha value to multiply the cairo context by when compositing
|
|
|
|
*/
|
|
|
|
float alpha;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-27 08:14:42 -07:00
|
|
|
/*
|
|
|
|
* The size of the widget
|
|
|
|
*/
|
2008-07-02 16:18:32 -07:00
|
|
|
size size;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
|
|
|
* If the widget currently has keyboard focus
|
|
|
|
*/
|
|
|
|
bool hasFocus;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
|
|
|
* If the mouse is currently over the widget
|
|
|
|
*/
|
|
|
|
bool hasMouse;
|
2008-06-22 16:28:34 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
|
|
|
* If the widget is currently enabled or not
|
|
|
|
*/
|
|
|
|
bool isEnabled;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-08-01 14:24:19 -07:00
|
|
|
/*
|
|
|
|
* If the widget is visible or not
|
|
|
|
*/
|
|
|
|
bool isVisible;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-02 16:18:32 -07:00
|
|
|
/*
|
|
|
|
* If the widget is dirty (i.e., needs to be re-drawn)
|
|
|
|
*/
|
|
|
|
bool needsRedraw;
|
2008-08-02 08:47:41 -07:00
|
|
|
|
2008-07-07 12:10:23 -07:00
|
|
|
/*
|
|
|
|
* If the widget uses an mouse event mask
|
|
|
|
*/
|
|
|
|
bool maskEnabled;
|
2008-04-24 11:07:47 -07:00
|
|
|
};
|
|
|
|
|
2008-06-23 05:18:19 -07:00
|
|
|
/*
|
|
|
|
* Type information
|
|
|
|
*/
|
2008-07-02 16:18:32 -07:00
|
|
|
extern const classInfo widgetClassInfo;
|
2008-06-23 05:18:19 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
|
|
|
* Helper macros
|
|
|
|
*/
|
|
|
|
#define WIDGET(self) ((widget *) (self))
|
|
|
|
#define WIDGET_GET_VTBL(self) ((WIDGET(self))->vtbl)
|
2008-05-06 09:34:34 -07:00
|
|
|
#define WIDGET_CHECK_METHOD(self, method) (assert(WIDGET_GET_VTBL(self)->method))
|
2008-04-24 11:07:47 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Protected methods
|
|
|
|
*/
|
|
|
|
void widgetInit(widget *instance, const char *id);
|
|
|
|
void widgetDestroyImpl(widget *instance);
|
|
|
|
bool widgetAddChildImpl(widget *self, widget *child);
|
|
|
|
void widgetRemoveChildImpl(widget *self, widget *child);
|
2008-08-11 03:27:11 -07:00
|
|
|
bool widgetFireCallbacksImpl(widget *self, const event *evt);
|
|
|
|
bool widgetFireTimerCallbacksImpl(widget *self, const event *evt);
|
2008-04-25 16:20:16 -07:00
|
|
|
int widgetAddEventHandlerImpl(widget *self, eventType type,
|
2008-08-24 09:58:27 -07:00
|
|
|
callback handler, callback destructor,
|
|
|
|
void *userData);
|
2008-07-15 03:12:03 -07:00
|
|
|
int widgetAddTimerEventHandlerImpl(widget *self, eventType type, int interval,
|
2008-08-24 09:58:27 -07:00
|
|
|
callback handler, callback destructor,
|
|
|
|
void *userData);
|
2008-04-24 11:07:47 -07:00
|
|
|
void widgetRemoveEventHandlerImpl(widget *self, int id);
|
2008-08-15 02:59:11 -07:00
|
|
|
point widgetAnimationInterpolateTranslateImpl(widget *self, animationFrame k1,
|
|
|
|
animationFrame k2, int time);
|
|
|
|
float widgetAnimationInterpolateRotateImpl(widget *self, animationFrame k1,
|
|
|
|
animationFrame k2, int time);
|
|
|
|
point widgetAnimationInterpolateScaleImpl(widget *self, animationFrame k1,
|
|
|
|
animationFrame k2, int time);
|
|
|
|
float widgetAnimationInterpolateAlphaImpl(widget *self, animationFrame k1,
|
|
|
|
animationFrame k2, int time);
|
2008-08-12 06:00:40 -07:00
|
|
|
void widgetAcceptDragImpl(widget *self);
|
|
|
|
void widgetDeclineDragImpl(widget *self);
|
2008-04-24 11:07:47 -07:00
|
|
|
void widgetEnableImpl(widget *self);
|
|
|
|
void widgetDisableImpl(widget *self);
|
2008-08-01 14:24:19 -07:00
|
|
|
void widgetShowImpl(widget *self);
|
|
|
|
void widgetHideImpl(widget *self);
|
2008-04-24 11:07:47 -07:00
|
|
|
void widgetFocusImpl(widget *self);
|
|
|
|
void widgetBlurImpl(widget *self);
|
2008-07-02 16:18:32 -07:00
|
|
|
void widgetResizeImpl(widget *self, int w, int h);
|
2008-08-13 04:21:58 -07:00
|
|
|
void widgetRepositionImpl(widget *self, int x, int y);
|
2008-08-11 03:27:11 -07:00
|
|
|
bool widgetHandleEventImpl(widget *self, const event *evt);
|
2008-07-18 15:21:54 -07:00
|
|
|
void widgetCompositeImpl(widget *self);
|
2008-04-24 11:07:47 -07:00
|
|
|
|
2008-06-23 05:18:19 -07:00
|
|
|
/*
|
|
|
|
* Public static methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if it is legal to cast self to instanceOf. Or, put in OO terms
|
|
|
|
* checks if self `is a' instanceOf instance.
|
2008-08-02 08:47:41 -07:00
|
|
|
*
|
2008-06-23 05:18:19 -07:00
|
|
|
* @param self The widget to check the class of.
|
|
|
|
* @param instanceOf The class we are interested in.
|
|
|
|
* @return True if it is legal to cast, false otherwise.
|
|
|
|
*/
|
2008-08-10 15:51:12 -07:00
|
|
|
bool widgetIsA(const widget *self, const classInfo *instanceOf);
|
2008-06-23 05:18:19 -07:00
|
|
|
|
2008-09-05 08:03:21 -07:00
|
|
|
/**
|
|
|
|
* Creates and fills out a new event structure using the information provided.
|
|
|
|
* This is strictly a convenience method to make it easier to generate new
|
|
|
|
* events.
|
|
|
|
*
|
|
|
|
* The event structure returned is the building block of all other, more complex
|
|
|
|
* events (such as mouse and keyboard events).
|
|
|
|
*
|
|
|
|
* @param type The type of the newly created event.
|
|
|
|
* @return A complete event structure.
|
|
|
|
*/
|
|
|
|
event widgetCreateEvent(eventType type);
|
|
|
|
|
2008-08-10 05:43:45 -07:00
|
|
|
/*
|
|
|
|
* Public static, implementation defined methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method should return the number of milliseconds since an undefined
|
|
|
|
* epoch.
|
|
|
|
*
|
|
|
|
* @return The number of milliseconds since the epoch.
|
|
|
|
*/
|
|
|
|
int widgetGetTime(void);
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
|
|
|
* Public methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the widget along with its child widgets.
|
2008-04-25 16:20:16 -07:00
|
|
|
*
|
2008-06-22 16:28:34 -07:00
|
|
|
* @param self The widget to be drawn.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
2008-07-02 16:18:32 -07:00
|
|
|
void widgetDraw(widget *self);
|
|
|
|
|
|
|
|
/**
|
2008-08-10 04:12:42 -07:00
|
|
|
* Composites the widget self onto the frame-buffer. In addition this method is
|
|
|
|
* also responsible for transforming the widget for the purposes of animation.
|
|
|
|
* Finally this method will loop over the child widgets of self and call
|
|
|
|
* widgetComposite on each one.
|
|
|
|
*
|
|
|
|
* @param self The widget (along with its children to composite.
|
2008-07-02 16:18:32 -07:00
|
|
|
*/
|
2008-07-18 15:21:54 -07:00
|
|
|
void widgetComposite(widget *self);
|
2008-04-24 11:07:47 -07:00
|
|
|
|
2008-07-07 12:10:23 -07:00
|
|
|
/**
|
|
|
|
* Enables the widgets mask.
|
2008-08-02 08:47:41 -07:00
|
|
|
*
|
2008-07-07 12:10:23 -07:00
|
|
|
* @param self The widget whose mask to enable.
|
|
|
|
*/
|
|
|
|
void widgetEnableMask(widget *self);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables the widgets mouse-event mask.
|
2008-08-02 08:47:41 -07:00
|
|
|
*
|
2008-07-07 12:10:23 -07:00
|
|
|
* @param self The widget whose mask to disable.
|
|
|
|
*/
|
|
|
|
void widgetDisableMask(widget *self);
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/**
|
|
|
|
* Recursively searches the child widgets of self for a widget whose ->id is
|
|
|
|
* id. If no widget with such an id exists NULL is returned.
|
2008-04-25 16:20:16 -07:00
|
|
|
*
|
2008-06-22 16:28:34 -07:00
|
|
|
* @param self The widget to start the search from.
|
|
|
|
* @param id The id of the desired widget.
|
2008-04-25 16:20:16 -07:00
|
|
|
* @return A pointer to the widget if found, NULL otherwise.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
widget *widgetFindById(widget *self, const char *id);
|
|
|
|
|
2008-04-27 08:14:42 -07:00
|
|
|
/**
|
|
|
|
* Returns the absolute position of the widget (ie, a position that is not
|
|
|
|
* relative to any other widget.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
|
|
|
* @param self The widget to get the position of.
|
2008-04-27 08:14:42 -07:00
|
|
|
* @return The absolute position of self.
|
|
|
|
*/
|
2008-08-10 15:51:12 -07:00
|
|
|
point widgetAbsolutePosition(const widget *self);
|
2008-04-27 08:14:42 -07:00
|
|
|
|
2008-06-21 10:23:00 -07:00
|
|
|
/**
|
|
|
|
* Returns the absolute bounding rectangle of the widget.
|
|
|
|
*
|
2008-06-22 16:28:34 -07:00
|
|
|
* @param self The widget to get the bounds of.
|
2008-06-21 10:23:00 -07:00
|
|
|
* @return The absolute bounds of self.
|
|
|
|
*/
|
2008-08-10 15:51:12 -07:00
|
|
|
rect widgetAbsoluteBounds(const widget *self);
|
2008-06-21 10:23:00 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/**
|
|
|
|
* Transverses up the hierarchy until it finds parent-less widget (known as
|
|
|
|
* the root widget). A pointer to this widget is returned.
|
2008-04-25 16:20:16 -07:00
|
|
|
*
|
2008-06-22 16:28:34 -07:00
|
|
|
* @param self The widget to find the root widget of.
|
2008-04-25 16:20:16 -07:00
|
|
|
* @return A pointer to the root widget.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
2008-06-22 05:03:42 -07:00
|
|
|
widget *widgetGetRoot(widget *self);
|
2008-04-24 11:07:47 -07:00
|
|
|
|
|
|
|
/**
|
2008-04-25 16:20:16 -07:00
|
|
|
* Attempts to add child as a child widget of self. The exact location of the
|
2008-05-06 09:34:34 -07:00
|
|
|
* widget (as well as its dimensions) are decided based off of the min & max
|
|
|
|
* sizes of the child.
|
2008-04-24 11:07:47 -07:00
|
|
|
*
|
2008-06-22 16:28:34 -07:00
|
|
|
* @param self The widget to add the child widget to.
|
|
|
|
* @param child The widget to be added.
|
2008-04-25 16:20:16 -07:00
|
|
|
* @return true if child was successfully added, false otherwise.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
bool widgetAddChild(widget *self, widget *child);
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:20:16 -07:00
|
|
|
* Attempts to remove child from the list of child widgets. If the child widget
|
|
|
|
* is found anywhere in the hierarchy it is removed and its destructor called.
|
2008-04-24 11:07:47 -07:00
|
|
|
*
|
2008-08-25 13:37:41 -07:00
|
|
|
* A convenient way of using this method is as follows:
|
2008-04-25 16:20:16 -07:00
|
|
|
* widgetRemoveChild(self, widgetFindById(self, "id_to_remove"));
|
|
|
|
*
|
2008-06-22 16:28:34 -07:00
|
|
|
* @param self The widget to remove child from.
|
|
|
|
* @param child The child widget to remove.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
void widgetRemoveChild(widget *self, widget *child);
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:20:16 -07:00
|
|
|
* Adds handler to self's event handler table, registering it to respond to
|
|
|
|
* events of type. An unique id is assigned to the event when it is added. This
|
|
|
|
* id can be used at a later date to widgetRemoveEventHandler to remove the
|
|
|
|
* event.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
2008-04-25 16:20:16 -07:00
|
|
|
* The userData pointer is passed verbatim to handler via the userData
|
|
|
|
* parameter. If no user data is required then NULL can be passed.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
2008-04-25 16:20:16 -07:00
|
|
|
* It is perfectly legal for there to be multiple event handlers installed for
|
|
|
|
* a single event type. When this is the case the event handlers are fired in
|
|
|
|
* the order in which they were added.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
|
|
|
* @param self The widget to add the event handler to.
|
|
|
|
* @param type The type of event that handler should respond to.
|
|
|
|
* @param handler The function to call when the event type fires.
|
2008-08-24 09:58:27 -07:00
|
|
|
* @param destructor The function to call when the event handler is removed.
|
2008-07-18 05:10:47 -07:00
|
|
|
* @param userData User specified data pointer to pass to handler.
|
2008-04-25 16:20:16 -07:00
|
|
|
* @return The id of the newly added event.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
2008-08-24 09:58:27 -07:00
|
|
|
int widgetAddEventHandler(widget *self, eventType type, callback handler,
|
|
|
|
callback destructor, void *userData);
|
2008-04-24 11:07:47 -07:00
|
|
|
|
2008-07-18 05:10:47 -07:00
|
|
|
/**
|
|
|
|
* Similar to widgetAddEventHandler in many respects, except that it is designed
|
|
|
|
* to add timer event handlers (EVT_TIMER_ONE_SHOT and EVT_TIMER_PERSISTENT).
|
2008-08-02 08:47:41 -07:00
|
|
|
*
|
2008-07-18 05:10:47 -07:00
|
|
|
* @param self The widget to add the timer event handler to.
|
2008-08-20 06:05:44 -07:00
|
|
|
* @param type The type of the timer to register the handler for.
|
2008-07-18 05:10:47 -07:00
|
|
|
* @param interval The duration in ms to wait.
|
|
|
|
* @param handler The function to call when the event fires.
|
2008-08-24 09:58:27 -07:00
|
|
|
* @param destructor The function to call when the event handler is removed.
|
2008-07-18 05:10:47 -07:00
|
|
|
* @param userData User specified data pointer to pass to handler.
|
|
|
|
* @return The id of the newly added event.
|
|
|
|
*/
|
|
|
|
int widgetAddTimerEventHandler(widget *self, eventType type, int interval,
|
2008-08-24 09:58:27 -07:00
|
|
|
callback handler, callback destructor,
|
|
|
|
void *userData);
|
2008-07-18 05:10:47 -07:00
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/**
|
2008-04-25 16:20:16 -07:00
|
|
|
* Removes the event from the events table at offset id.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
|
|
|
* @param self The widget to remove the event handler from.
|
|
|
|
* @param id The id of the event to be removed.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
void widgetRemoveEventHandler(widget *self, int id);
|
|
|
|
|
2008-08-21 09:19:51 -07:00
|
|
|
/**
|
|
|
|
* Returns if id is that of a valid event handler.
|
|
|
|
*
|
|
|
|
* @param self The widget to check if id is a valid event handler for.
|
|
|
|
* @param id The id in question.
|
|
|
|
*/
|
|
|
|
bool widgetIsEventHandler(const widget *self, int id);
|
|
|
|
|
2008-08-08 11:15:50 -07:00
|
|
|
/**
|
|
|
|
* Returns the user-data for the event whose id is id.
|
|
|
|
*
|
|
|
|
* @param self The widget to whom the event handler is registered to.
|
|
|
|
* @param id The id of the event handler to fetch the user-data for.
|
2008-08-25 13:37:41 -07:00
|
|
|
* @return The user-data for the event handler, or NULL if the eventId is
|
2008-08-08 11:15:50 -07:00
|
|
|
* invalid.
|
|
|
|
*/
|
2008-08-10 15:51:12 -07:00
|
|
|
void *widgetGetEventHandlerUserData(const widget *self, int id);
|
2008-08-08 11:15:50 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the user-data for the event handler with an id of id registered to self
|
|
|
|
* to userData.
|
|
|
|
*
|
|
|
|
* @param self The widget to whom the event handler is registered to.
|
|
|
|
* @param id The id of the widget to set the user-data for.
|
|
|
|
* @param userData The new user-data for the event handler
|
|
|
|
*/
|
|
|
|
void widgetSetEventHandlerUserData(widget *self, int id, void *userData);
|
|
|
|
|
2008-08-12 06:00:40 -07:00
|
|
|
/**
|
|
|
|
* Accepts the current drag offer, if any. Should no drag offer be on the table
|
|
|
|
* then the results are undefined.
|
|
|
|
*
|
|
|
|
* @param self The widget to accept the drag offer for.
|
|
|
|
*/
|
|
|
|
void widgetAcceptDrag(widget *self);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declines the current drag offer. Like with widgetAcceptDrag the results are
|
|
|
|
* undefined if there is no drag offer .
|
|
|
|
*
|
|
|
|
* @param self The widget to decline the drag offer for.
|
|
|
|
*/
|
|
|
|
void widgetDeclineDrag(widget *self);
|
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/**
|
|
|
|
* TODO
|
|
|
|
*/
|
|
|
|
int widgetAddAnimation(widget *self, int nframes,
|
|
|
|
const animationFrame *frames);
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/**
|
|
|
|
* Enables the current widget along with all of its child widgets. If the
|
|
|
|
* widget is currently enabled but one or more of its child widgets are not
|
|
|
|
* then they will also be enabled.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
2008-04-24 11:07:47 -07:00
|
|
|
* If, however, the parent widget is disabled then this method is effectively
|
|
|
|
* a no-op.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
|
|
|
* @param self The widget to enable.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
void widgetEnable(widget *self);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables the current widget along with all of its child widgets. If the
|
|
|
|
* widget is currently disabled then this method is a no-op.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
|
|
|
* @param self The widget to disable.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
void widgetDisable(widget *self);
|
|
|
|
|
2008-08-01 14:24:19 -07:00
|
|
|
/**
|
|
|
|
* Shows the current widget (makes it visible). This is a no-op if the widget is
|
|
|
|
* already shown.
|
|
|
|
*
|
|
|
|
* @param self The widget to show.
|
|
|
|
*/
|
|
|
|
void widgetShow(widget *self);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the current widget. Again, this is a no-op if the widget is already
|
|
|
|
* hidden.
|
|
|
|
*
|
|
|
|
* @param self The widget to hide.
|
|
|
|
*/
|
|
|
|
void widgetHide(widget *self);
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/**
|
|
|
|
* Destroys the widget and frees *all* memory associated with it.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
|
|
|
* @param self The widget to destroy.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
void widgetDestroy(widget *self);
|
|
|
|
|
|
|
|
/**
|
2008-08-25 13:37:41 -07:00
|
|
|
* Returns a pointer to the widget farthest down the hierarchy which currently
|
2008-04-24 11:07:47 -07:00
|
|
|
* has focus. If self does not currently have focus then NULL is returned.
|
|
|
|
* Should none of self's child widgets have focus (but it does) then self is
|
|
|
|
* returned.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
2008-08-25 13:37:41 -07:00
|
|
|
* @param self The widget to get the farthest down focused child of.
|
2008-04-25 16:20:16 -07:00
|
|
|
* @return A pointer to the widget, or NULL if self is not focused.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
widget *widgetGetCurrentlyFocused(widget *self);
|
|
|
|
|
2008-08-17 11:22:38 -07:00
|
|
|
/**
|
|
|
|
* Very much the same as widgetGetCurrentlyFocused except that it returns a
|
2008-08-25 13:37:41 -07:00
|
|
|
* pointer to the widget farthest down the hierarchy which currently has the
|
2008-08-17 11:22:38 -07:00
|
|
|
* mouse over it. Like with widgetGetCurrentlyFocused should self not have the
|
|
|
|
* mouse over it, NULL is returned.
|
|
|
|
*
|
2008-08-25 13:37:41 -07:00
|
|
|
* @param self The widget to get the farthest down moused-over child of.
|
2008-08-17 11:22:38 -07:00
|
|
|
* @param A pointer to the widget, or NULL if self does not have the mouse.
|
|
|
|
*/
|
|
|
|
widget *widgetGetCurrentlyMousedOver(widget *self);
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/**
|
|
|
|
* If the widget is capable of holding keyboard focus and does not currently
|
2008-04-25 16:20:16 -07:00
|
|
|
* hold it then this method will bring it into focus. Should ->parent not be
|
|
|
|
* focused then widgetFocus(self->parent) will be called to focus it.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
2008-04-25 16:20:16 -07:00
|
|
|
* This method will also blur any widgets which will no longer be in focus as a
|
2008-08-25 13:37:41 -07:00
|
|
|
* result of self being focused. In addition it takes responsibility for firing
|
2008-04-25 16:20:16 -07:00
|
|
|
* the EVT_FOCUS callbacks for self.
|
2008-04-24 11:07:47 -07:00
|
|
|
*
|
2008-06-22 16:28:34 -07:00
|
|
|
* @param self The widget to focus.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
void widgetFocus(widget *self);
|
|
|
|
|
|
|
|
/**
|
2008-05-06 09:34:34 -07:00
|
|
|
* Blurs the current widget (removes keyboard focus from it). Before self is
|
2008-04-25 16:20:16 -07:00
|
|
|
* blurred any child widget with focus is blurred first. Finally the EVT_BLUR
|
|
|
|
* event handlers for self are fired.
|
|
|
|
*
|
2008-06-22 16:28:34 -07:00
|
|
|
* @param self The widget to blur.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
|
|
|
void widgetBlur(widget *self);
|
|
|
|
|
2008-05-06 09:34:34 -07:00
|
|
|
/**
|
|
|
|
* Returns the minimum size that the widget can be.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
2008-08-25 13:37:41 -07:00
|
|
|
* @param self The widget to return the minimum size of.
|
|
|
|
* @return The minimum (x,y) size of the widget.
|
2008-05-06 09:34:34 -07:00
|
|
|
*/
|
2008-07-02 16:18:32 -07:00
|
|
|
size widgetGetMinSize(widget *self);
|
2008-05-06 09:34:34 -07:00
|
|
|
|
|
|
|
/**
|
2008-08-25 13:37:41 -07:00
|
|
|
* Returns the maximum size that the widget can be.
|
2008-05-06 09:34:34 -07:00
|
|
|
*
|
2008-06-22 16:28:34 -07:00
|
|
|
* @param self The widget to return the maximum size of.
|
2008-05-06 09:34:34 -07:00
|
|
|
* @return The maximum (x,y) size of the widget.
|
|
|
|
*/
|
2008-07-02 16:18:32 -07:00
|
|
|
size widgetGetMaxSize(widget *self);
|
2008-05-06 09:34:34 -07:00
|
|
|
|
|
|
|
/**
|
2008-07-02 16:18:32 -07:00
|
|
|
* Sets the size of the widget to (x,y). x and y are subject to the following
|
|
|
|
* conditions:
|
|
|
|
* widgetGetMinSize().x <= x <= widgetGetMaxSize().x and
|
|
|
|
* widgetGetMinSize().y <= y <= widgetGetMaxSize().y.
|
2008-08-02 08:47:41 -07:00
|
|
|
*
|
2008-09-03 12:02:39 -07:00
|
|
|
* This method should not be invoked directly on non-root widget; setting the
|
|
|
|
* dimensions of a widget remains the exclusive responsibility of the parent.
|
|
|
|
*
|
2008-07-02 16:18:32 -07:00
|
|
|
* @param self The widget to resize.
|
|
|
|
* @param w The new size of the widget in the x-axis.
|
|
|
|
* @param h The new size of the widget in the y-axis.
|
2008-05-06 09:34:34 -07:00
|
|
|
*/
|
2008-07-02 16:18:32 -07:00
|
|
|
void widgetResize(widget *self, int w, int h);
|
2008-05-06 09:34:34 -07:00
|
|
|
|
2008-08-13 04:21:58 -07:00
|
|
|
/**
|
|
|
|
* Sets the offset of the widget, relative to its parent widget to (x,y).
|
|
|
|
*
|
|
|
|
* @param self The widget to reposition.
|
|
|
|
* @param w The new x-offset of the widget.
|
|
|
|
* @param h The new y-offset of the widget.
|
|
|
|
*/
|
|
|
|
void widgetReposition(widget *self, int x, int y);
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/**
|
2008-08-10 04:12:42 -07:00
|
|
|
* This is the main event dispatching function. Its purpose is to take an event,
|
|
|
|
* evt and decide what course of action needs to be taken (if any). It is
|
|
|
|
* responsible for setting widget-states such as hasMouse and hasFocus and for
|
|
|
|
* deciding if evt is relevant to any child widgets of self.
|
|
|
|
*
|
|
|
|
* @param self The widget to handle the event.
|
|
|
|
* @param evt The event itself.
|
|
|
|
* @param True if the event was `handled', false otherwise.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
2008-08-11 03:27:11 -07:00
|
|
|
bool widgetHandleEvent(widget *self, const event *evt);
|
2008-04-24 11:07:47 -07:00
|
|
|
|
2008-08-25 08:56:58 -07:00
|
|
|
/**
|
|
|
|
* Sets the tool-tip for the widget to tip. Since this method makes a copy of
|
|
|
|
* tip there is no need for the caller to retain it. Should one wish to disable
|
|
|
|
* tool-tips for this widget NULL should be passed in-place of tip.
|
|
|
|
*
|
|
|
|
* @param self The widget to set the tool-tip for.
|
|
|
|
* @param tip The tool-tip to set for the widget.
|
|
|
|
*/
|
|
|
|
void widgetSetToolTip(widget *self, const char *tip);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a pointer to the widgets tool-tip text. Should the widget not have a
|
|
|
|
* tool-tip, NULL is returned.
|
|
|
|
*
|
|
|
|
* @param self The widget to get the tool-tip for.
|
|
|
|
* @return A pointer to the widgets tool-tip.
|
|
|
|
*/
|
|
|
|
const char *widgetGetToolTip(widget *self);
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
/*
|
|
|
|
* Protected methods
|
|
|
|
*/
|
|
|
|
|
2008-06-22 05:03:42 -07:00
|
|
|
/**
|
2008-07-02 16:18:32 -07:00
|
|
|
* A protected `pure virtual' method which is called to draw the widget.
|
2008-06-22 16:28:34 -07:00
|
|
|
*
|
|
|
|
* @param self The widget that should draw itself.
|
2008-04-24 11:07:47 -07:00
|
|
|
*/
|
2008-07-02 16:18:32 -07:00
|
|
|
void widgetDoDraw(widget *self);
|
2008-04-24 11:07:47 -07:00
|
|
|
|
2008-07-07 12:10:23 -07:00
|
|
|
/**
|
|
|
|
* Configures the mask context (self->maskCr) for drawing and then delegates the
|
|
|
|
* drawing to widgetDoDrawMask. This method is required as the mask context
|
|
|
|
* requires some additional initialisation to a regular Cairo context.
|
2008-08-02 08:47:41 -07:00
|
|
|
*
|
2008-07-07 12:10:23 -07:00
|
|
|
* @param self The widget whose mask to draw.
|
|
|
|
*/
|
|
|
|
void widgetDrawMask(widget *self);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A protected `pure virtual` method which is called to draw the widgets mouse-
|
|
|
|
* event mask.
|
2008-08-02 08:47:41 -07:00
|
|
|
*
|
2008-07-07 12:10:23 -07:00
|
|
|
* @param self The widget that should draw its mask.
|
|
|
|
*/
|
|
|
|
void widgetDoDrawMask(widget *self);
|
|
|
|
|
2008-05-06 09:34:34 -07:00
|
|
|
/**
|
2008-08-16 10:49:52 -07:00
|
|
|
* A protected `pure virtual' method which is called to lay out any child
|
|
|
|
* widgets of self.
|
2008-05-06 09:34:34 -07:00
|
|
|
*
|
2008-08-16 10:49:52 -07:00
|
|
|
* This method may fail (return false) if self is not large enough to hold all
|
|
|
|
* of its children.
|
|
|
|
*
|
|
|
|
* @param self The widget whose children should be layed out.
|
|
|
|
* @return True if the widgets children were successfully layed out, false
|
|
|
|
* otherwise.
|
2008-05-06 09:34:34 -07:00
|
|
|
*/
|
|
|
|
bool widgetDoLayout(widget *self);
|
|
|
|
|
2008-04-25 16:20:16 -07:00
|
|
|
/**
|
2008-08-25 13:37:41 -07:00
|
|
|
* Fires all of the event handlers registered for evt->type on the widget self.
|
2008-04-25 16:20:16 -07:00
|
|
|
*
|
2008-06-22 16:28:34 -07:00
|
|
|
* @param self The widget to fire the callbacks on.
|
|
|
|
* @param evt The event to fire the callbacks for.
|
2008-04-25 16:20:16 -07:00
|
|
|
*/
|
2008-08-11 03:27:11 -07:00
|
|
|
bool widgetFireCallbacks(widget *self, const event *evt);
|
2008-04-25 16:20:16 -07:00
|
|
|
|
2008-07-15 03:12:03 -07:00
|
|
|
/**
|
2008-08-16 10:49:52 -07:00
|
|
|
* Fires all of the timer event handles for the widget self.
|
2008-08-02 08:47:41 -07:00
|
|
|
*
|
2008-08-16 10:49:52 -07:00
|
|
|
* @param self The widget to fire the timer callbacks on.
|
|
|
|
* @param evt The event to fire the callbacks for.
|
2008-07-15 03:12:03 -07:00
|
|
|
*/
|
2008-08-11 03:27:11 -07:00
|
|
|
bool widgetFireTimerCallbacks(widget *self, const event *evt);
|
2008-07-15 03:12:03 -07:00
|
|
|
|
2008-07-07 12:10:23 -07:00
|
|
|
/**
|
|
|
|
* Checks to see if the point loc is masked or not by the widgets mouse-event
|
|
|
|
* mask.
|
2008-08-02 08:47:41 -07:00
|
|
|
*
|
2008-07-07 12:10:23 -07:00
|
|
|
* @param self The widget to check the mask of.
|
|
|
|
* @param loc The point (x,y) to check the mask status of.
|
|
|
|
* @return true if loc is masked; false otherwise;
|
|
|
|
*/
|
2008-08-10 15:51:12 -07:00
|
|
|
bool widgetPointMasked(const widget *self, point loc);
|
2008-07-07 12:10:23 -07:00
|
|
|
|
2008-08-25 08:56:58 -07:00
|
|
|
/**
|
|
|
|
* Asks the root widget to show the tool-tip of self.
|
|
|
|
*
|
|
|
|
* @param self The widget to show the tool-tip for.
|
|
|
|
*/
|
|
|
|
void widgetShowToolTip(widget *self);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asks the root widget to hide the tool-tip of self.
|
|
|
|
*
|
|
|
|
* @param self The widget to hide the tool-tip for.
|
|
|
|
*/
|
|
|
|
void widgetHideToolTip(widget *self);
|
|
|
|
|
2008-08-15 02:59:11 -07:00
|
|
|
/**
|
|
|
|
* TODO
|
|
|
|
*/
|
|
|
|
point widgetAnimationInterpolateTranslate(widget *self,
|
2008-08-25 13:37:41 -07:00
|
|
|
animationFrame k1, animationFrame k2,
|
2008-08-15 02:59:11 -07:00
|
|
|
int time);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO
|
|
|
|
*/
|
|
|
|
float widgetAnimationInterpolateRotate(widget *self,
|
|
|
|
animationFrame k1, animationFrame k2,
|
|
|
|
int time);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO
|
|
|
|
*/
|
|
|
|
point widgetAnimationInterpolateScale(widget *self,
|
|
|
|
animationFrame k1, animationFrame k2,
|
|
|
|
int time);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO
|
|
|
|
*/
|
|
|
|
float widgetAnimationInterpolateAlpha(widget *self,
|
|
|
|
animationFrame k1, animationFrame k2,
|
|
|
|
int time);
|
|
|
|
|
2008-04-24 11:07:47 -07:00
|
|
|
#endif /*WIDGET_H_*/
|