diff options
author | inmarket <andrewh@inmarket.com.au> | 2013-06-10 17:18:01 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2013-06-10 17:18:01 +1000 |
commit | 2cb35d6815a0a12035f4792c266b688c77085620 (patch) | |
tree | 292ebc4760767d67b41f7f0e0022185afcf05067 /include | |
parent | 777ec6af7c1b594f7b7a9cbaaf7ead90d8fb7e8f (diff) | |
download | uGFX-2cb35d6815a0a12035f4792c266b688c77085620.tar.gz uGFX-2cb35d6815a0a12035f4792c266b688c77085620.tar.bz2 uGFX-2cb35d6815a0a12035f4792c266b688c77085620.zip |
Clean up GWIN Event assignment. Optimise event efficiency.
Diffstat (limited to 'include')
-rw-r--r-- | include/gfx_rules.h | 43 | ||||
-rw-r--r-- | include/ginput/dial.h | 1 | ||||
-rw-r--r-- | include/gqueue/gqueue.h | 44 | ||||
-rw-r--r-- | include/gwin/button.h | 6 | ||||
-rw-r--r-- | include/gwin/checkbox.h | 15 | ||||
-rw-r--r-- | include/gwin/class_gwin.h | 61 | ||||
-rw-r--r-- | include/gwin/gwidget.h | 14 | ||||
-rw-r--r-- | include/gwin/gwin.h | 1 | ||||
-rw-r--r-- | include/gwin/options.h | 4 | ||||
-rw-r--r-- | include/gwin/slider.h | 24 |
10 files changed, 154 insertions, 59 deletions
diff --git a/include/gfx_rules.h b/include/gfx_rules.h index 7e14ef9d..6c0dc756 100644 --- a/include/gfx_rules.h +++ b/include/gfx_rules.h @@ -46,24 +46,6 @@ #warning "GWIN: Drawing can occur outside the defined windows as GDISP_NEED_CLIP is FALSE" #endif #endif - #if GWIN_NEED_WINDOWMANAGER - #if !GFX_USE_GQUEUE || !GQUEUE_NEED_ASYNC - #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GFX_USE_GQUEUE and GQUEUE_NEED_ASYNC is required if GWIN_NEED_WINDOWMANAGER is TRUE. It has been turned on for you." - #endif - #undef GFX_USE_GQUEUE - #undef GQUEUE_NEED_ASYNC - #define GFX_USE_GQUEUE TRUE - #define GQUEUE_NEED_ASYNC TRUE - #endif - #endif - #if GWIN_NEED_CONSOLE - #if !GDISP_NEED_TEXT - #error "GWIN: GDISP_NEED_TEXT is required if GWIN_NEED_CONSOLE is TRUE." - #endif - #endif - #if GWIN_NEED_GRAPH - #endif #if GWIN_NEED_BUTTON || GWIN_NEED_SLIDER || GWIN_NEED_CHECKBOX #if !GWIN_NEED_WIDGET #if GFX_DISPLAY_RULE_WARNINGS @@ -81,6 +63,13 @@ // This test also ensures that GFX_USE_GEVENT is set #error "GWIN: GFX_USE_GINPUT (and one or more input sources) is required if GWIN_NEED_WIDGET is TRUE" #endif + #if !GWIN_NEED_WINDOWMANAGER + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: GWIN_NEED_WINDOWMANAGER is required if GWIN_NEED_WIDGET is TRUE. It has been turned on for you." + #endif + #undef GWIN_NEED_WINDOWMANAGER + #define GWIN_NEED_WINDOWMANAGER TRUE + #endif #if !GDISP_NEED_MULTITHREAD && !GDISP_NEED_ASYNC #if GFX_DISPLAY_RULE_WARNINGS #warning "GWIN: Either GDISP_NEED_MULTITHREAD or GDISP_NEED_ASYNC is required if GWIN_NEED_WIDGET is TRUE." @@ -90,6 +79,24 @@ #define GDISP_NEED_MULTITHREAD TRUE #endif #endif + #if GWIN_NEED_WINDOWMANAGER + #if !GFX_USE_GQUEUE || !GQUEUE_NEED_ASYNC + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: GFX_USE_GQUEUE and GQUEUE_NEED_ASYNC is required if GWIN_NEED_WINDOWMANAGER is TRUE. It has been turned on for you." + #endif + #undef GFX_USE_GQUEUE + #undef GQUEUE_NEED_ASYNC + #define GFX_USE_GQUEUE TRUE + #define GQUEUE_NEED_ASYNC TRUE + #endif + #endif + #if GWIN_NEED_CONSOLE + #if !GDISP_NEED_TEXT + #error "GWIN: GDISP_NEED_TEXT is required if GWIN_NEED_CONSOLE is TRUE." + #endif + #endif + #if GWIN_NEED_GRAPH + #endif #endif #if GFX_USE_GINPUT diff --git a/include/ginput/dial.h b/include/ginput/dial.h index af54952a..8b4f9d3c 100644 --- a/include/ginput/dial.h +++ b/include/ginput/dial.h @@ -36,6 +36,7 @@ typedef struct GEventDial_t { GEventType type; // The type of this event (GEVENT_DIAL) uint16_t instance; // The dial instance uint16_t value; // The dial value + uint16_t maxvalue; // The maximum dial value } GEventDial; /*===========================================================================*/ diff --git a/include/gqueue/gqueue.h b/include/gqueue/gqueue.h index 38c1908d..399042d9 100644 --- a/include/gqueue/gqueue.h +++ b/include/gqueue/gqueue.h @@ -103,7 +103,7 @@ void gfxQueueFSyncInit(gfxQueueFSync *pqueue); /* @} */ /** - * @brief Get an item from the head of the queue. + * @brief Get an item from the head of the queue (and remove it from the queue). * @return NULL if the timeout expires before an item is available * * @param[in] pqueue A pointer to the queue @@ -139,7 +139,7 @@ bool_t gfxQueueFSyncPut(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem, delayti /* @} */ /** - * @brief Pop an item from the head of the queue. + * @brief Pop an item from the head of the queue (and remove it from the queue). * @detail This is exactly the same as the Get operation above. * * @api @@ -220,6 +220,46 @@ bool_t gfxQueueGSyncIsIn(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem); bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem); /* @} */ +/** + * @brief Get the first item from the head of the queue but do not remove it from the queue. + * @return NULL if no item is available. + * + * @param[in] pqueue A pointer to the queue + * + * @note This call does not block. + * @note This can be used as the first call to iterate all the elements in the queue. + * @note As that item is still on the queue, it should be treated as read-only. It could + * also be removed from the queue at any time by another thread (thereby altering the + * queue item). + * + * @api + * @{ + */ +#define gfxQueueASyncPeek(pqueue) ((const gfxQueueASyncItem *)((pqueue)->head)) +#define gfxQueueGSyncPeek(pqueue) ((const gfxQueueGSyncItem *)((pqueue)->head)) +#define gfxQueueFSyncPeek(pqueue) ((const gfxQueueFSyncItem *)((pqueue)->head)) +/* @} */ + +/** + * @brief Get the next item in the queue (but do not remove it from the queue). + * @return NULL if no item is available. + * + * @param[in] pitem The previous item in the queue + * + * @note This call does not block. + * @note This can be used as subsequent calls to iterate all the elements in the queue. + * @note As that item is still on the queue, it should be treated as read-only. It could + * also be removed from the queue at any time by another thread (thereby altering the + * queue item). + * + * @api + * @{ + */ +#define gfxQueueASyncNext(pitem) ((const gfxQueueASyncItem *)((pitem)->next)) +#define gfxQueueGSyncNext(pitem) ((const gfxQueueGSyncItem *)((pitem)->next)) +#define gfxQueueFSyncNext(pitem) ((const gfxQueueFSyncItem *)((pitem)->next)) +/* @} */ + #ifdef __cplusplus } #endif diff --git a/include/gwin/button.h b/include/gwin/button.h index 53096ea3..20fd6df7 100644 --- a/include/gwin/button.h +++ b/include/gwin/button.h @@ -55,6 +55,7 @@ typedef struct GButtonColors { */ typedef struct GButtonObject_t { GWidgetObject w; + uint16_t toggle; GButtonColors c_up; GButtonColors c_dn; GButtonColors c_dis; @@ -78,10 +79,13 @@ extern "C" { * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there * is no default font and text drawing operations will no nothing. * @note The dimensions and position may be changed to fit on the real screen. - * @note A button remembers its normal button state. If there is a window manager then it is automatically + * @note A button remembers its normal drawing state. If there is a window manager then it is automatically * redrawn if the window is moved or its visibility state is changed. * @note The button is initially marked as invisible so that more properties can be set before display. * Call @p gwinSetVisible() to display it when ready. + * @note A button supports mouse and a toggle input. + * @note When assigning a toggle, only one toggle is supported. If you try to assign more than one toggle it will + * forget the previous toggle. When assigning a toggle the role parameter must be 0. * * @api */ diff --git a/include/gwin/checkbox.h b/include/gwin/checkbox.h index de49fa01..6f151218 100644 --- a/include/gwin/checkbox.h +++ b/include/gwin/checkbox.h @@ -50,6 +50,7 @@ typedef struct GCheckboxColors { /* A Checkbox window */ typedef struct GCheckboxObject_t { GWidgetObject w; + uint16_t toggle; GCheckboxColors c; } GCheckboxObject; @@ -62,10 +63,18 @@ typedef struct GCheckboxObject_t { * @param[in] width The width of the window * @param[in] height The height of the window * - * @note The drawing color gets set to White and the background drawing color to Black. - * @note Don't forget to set the font using @p gwinSetFont() or @p gwinSetDefaultFont() + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. * @note The dimensions and position may be changed to fit on the real screen. - * @note The checkbox is not automatically drawn. Call gwinDraw() to draw it. + * @note A checkbox remembers its normal drawing state. If there is a window manager then it is automatically + * redrawn if the window is moved or its visibility state is changed. + * @note The checkbox is initially marked as invisible so that more properties can be set before display. + * Call @p gwinSetVisible() to display it when ready. + * @note A checkbox supports mouse and a toggle input. + * @note When assigning a toggle, only one toggle is supported. If you try to assign more than one toggle it will + * forget the previous toggle. When assigning a toggle the role parameter must be 0. * * @api */ diff --git a/include/gwin/class_gwin.h b/include/gwin/class_gwin.h index 5e3cb01f..1c640c0c 100644 --- a/include/gwin/class_gwin.h +++ b/include/gwin/class_gwin.h @@ -52,37 +52,58 @@ typedef struct gwinVMT { /* @} */ #if GWIN_NEED_WIDGET || defined(__DOXYGEN__) + + /** + * @brief An toggle/dial instance is not being used + */ + #define GWIDGET_NO_INSTANCE ((uint16_t)-1) + + /** + * @brief The source handle that widgets use when sending events + */ + #define GWIDGET_SOURCE ((GSourceHandle)(void *)_gwidgetCreate) + /** * @brief The Virtual Method Table for a widget * @note A widget must have a destroy function. Either use @p _gwidgetDestroy() or use your own function * which internally calls @p _gwidgetDestroy(). * @note A widget must have a redraw function. Use @p _gwidgetRedraw(). - * @note If no MouseDown(), MouseUp() or MouseMove() function is provided, the widget will not accept being attached to a mouse input source. - * @note If no ToggleOn() or ToggleOff() function is provided, the widget will not accept being attached to a toggle input source. - * @note If no DialMove() function is provided, the widget will not accept being attached to a dial input source. - * @note AssignToggle() and AssignDial() enable a widget to handle more than one toggle/dial device attached to the widget. - * For example, a slider might accept two toggles, one for slider-down and one for slider-up. - * The function enables the widget to record that a particular device instance performs each particular role. - * (eg toggle0 = slider-down, toggle1 = slider-up). + * @note If toggleroles != 0, ToggleAssign(), ToggleGet() and one or both of ToggleOff() and ToggleOn() must be specified. + * @note If dialroles != 0, DialAssign(), DialGet() and DialMove() must be specified. * @{ */ typedef struct gwidgetVMT { - struct gwinVMT g; // @< This is still a GWIN - void (*DefaultDraw) (GWidgetObject *gw, void *param); // @< The default drawing routine (mandatory) - void (*MouseDown) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse down events (optional) - void (*MouseUp) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse up events (optional) - void (*MouseMove) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse move events (optional) - void (*ToggleOff) (GWidgetObject *gw, uint16_t instance); // @< Process toggle off events (optional) - void (*ToggleOn) (GWidgetObject *gw, uint16_t instance); // @< Process toggle on events (optional) - void (*DialMove) (GWidgetObject *gw, uint16_t instance, uint16_t value); // @< Process dial move events (optional) - void (*AllEvents) (GWidgetObject *gw, GEvent *pe); // @< Process all events (optional) - bool_t (*AssignToggle) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Test the role and save the toggle instance handle (optional) - bool_t (*AssignDial) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Test the role and save the dial instance handle (optional) + struct gwinVMT g; // @< This is still a GWIN + void (*DefaultDraw) (GWidgetObject *gw, void *param); // @< The default drawing routine (mandatory) + struct { + void (*MouseDown) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse down events (optional) + void (*MouseUp) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse up events (optional) + void (*MouseMove) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse move events (optional) + }; + struct { + uint16_t toggleroles; // @< The roles supported for toggles (0->toggleroles-1) + void (*ToggleAssign) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Assign a toggle to a role (optional) + uint16_t (*ToggleGet) (GWidgetObject *gw, uint16_t role); // @< Return the instance for a particular role (optional) + void (*ToggleOff) (GWidgetObject *gw, uint16_t role); // @< Process toggle off events (optional) + void (*ToggleOn) (GWidgetObject *gw, uint16_t role); // @< Process toggle on events (optional) + }; + struct { + uint16_t dialroles; // @< The roles supported for dials (0->dialroles-1) + void (*DialAssign) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Test the role and save the dial instance handle (optional) + uint16_t (*DialGet) (GWidgetObject *gw, uint16_t role); // @< Return the instance for a particular role (optional) + void (*DialMove) (GWidgetObject *gw, uint16_t role, uint16_t value, uint16_t max); // @< Process dial move events (optional) + }; } gwidgetVMT; /* @} */ #endif #if GWIN_NEED_WINDOWMANAGER || defined(__DOXYGEN__) + #if 1 // When we know that wmq is the first element of the GWindowObject structure + #define QItem2GWindow(qi) ((GHandle)qi) + #else + #define QItem2GWindow(qi) ((GHandle)(((char *)(qi)) - (size_t)(&(((GWindowObject *)0)->wmq)))) + #endif + // @note There is only ever one instance of each GWindowManager type typedef struct GWindowManager { const struct gwmVMT *vmt; @@ -126,7 +147,7 @@ extern "C" { * * @notapi */ -GHandle _gwindowInit(GWindowObject *pgw, coord_t x, coord_t y, coord_t w, coord_t h, size_t size, const gwinVMT *vmt, uint16_t flags); +GHandle _gwindowCreate(GWindowObject *pgw, coord_t x, coord_t y, coord_t w, coord_t h, size_t size, const gwinVMT *vmt, uint16_t flags); #if GWIN_NEED_WIDGET || defined(__DOXYGEN__) /** @@ -140,7 +161,7 @@ GHandle _gwindowInit(GWindowObject *pgw, coord_t x, coord_t y, coord_t w, coord_ * * @notapi */ - GHandle _gwidgetInit(GWidgetObject *pgw, coord_t x, coord_t y, coord_t w, coord_t h, size_t size, const gwidgetVMT *vmt); + GHandle _gwidgetCreate(GWidgetObject *pgw, coord_t x, coord_t y, coord_t w, coord_t h, size_t size, const gwidgetVMT *vmt); /** * @brief Destroy the Widget object diff --git a/include/gwin/gwidget.h b/include/gwin/gwidget.h index 21cfd4ac..a022ab13 100644 --- a/include/gwin/gwidget.h +++ b/include/gwin/gwidget.h @@ -46,7 +46,6 @@ typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param); */ typedef struct GWidgetObject { GWindowObject g; // @< This is still a GWIN - GListener listener; // @< The widget listener const char * txt; // @< The widget text CustomWidgetDrawFunction fnDraw; // @< The current draw function void * fnParam; // @< A parameter for the current draw function @@ -120,28 +119,27 @@ const char *gwinGetText(GHandle gh); void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void *param); /** - * @brief Attach a Listener to this widget + * @brief Attach a Listener to listen for widget events * @return TRUE on success * - * @param[in] gh The widget handle * @param[in] pl The listener - * @param[in] flags Flags to use for listening. For most widgets this should be 0. * * @api */ -bool_t gwinAttachListener(GHandle gh, GListener *pl, unsigned flags); +bool_t gwinAttachListener(GListener *pl); #if GFX_USE_GINPUT && GINPUT_NEED_MOUSE /** - * @brief Attach a mouse to a widget + * @brief Set the mouse to be used to control the widgets * @return TRUE on success * - * @param[in] gh The widget handle * @param[in] instance The mouse instance * + * @note Every widget uses the same mouse. + * * @api */ - bool_t gwinAttachMouse(GHandle gh, uint16_t instance); + bool_t gwinAttachMouse(uint16_t instance); #endif #if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE diff --git a/include/gwin/gwin.h b/include/gwin/gwin.h index d915a4f0..96d7be97 100644 --- a/include/gwin/gwin.h +++ b/include/gwin/gwin.h @@ -35,6 +35,7 @@ */ typedef struct GWindowObject { #if GWIN_NEED_WINDOWMANAGER + // This MUST be the first member of the struct gfxQueueASyncItem wmq; // @< The next window (for the window manager) #endif const struct gwinVMT *vmt; // @< The VMT for this GWIN diff --git a/include/gwin/options.h b/include/gwin/options.h index 3619e075..db4ae69b 100644 --- a/include/gwin/options.h +++ b/include/gwin/options.h @@ -21,11 +21,11 @@ * @{ */ /** - * @brief Should a window manager be used. + * @brief Should window manager support be included * @details Defaults to FALSE */ #ifndef GWIN_NEED_WINDOWMANAGER - #define GWIN_NEED_WINDOWMANAGER FALSE + #define GWIN_NEED_WIDGET FALSE #endif /** * @brief Should widget functions be included. Needed for any widget (eg Buttons, Sliders etc) diff --git a/include/gwin/slider.h b/include/gwin/slider.h index 41894305..45618114 100644 --- a/include/gwin/slider.h +++ b/include/gwin/slider.h @@ -45,11 +45,14 @@ typedef struct GSliderColors { // A slider window typedef struct GSliderObject_t { GWidgetObject w; - GSliderColors c; + uint16_t t_dn; + uint16_t t_up; + uint16_t dial; coord_t dpos; int min; int max; int pos; + GSliderColors c; } GSliderObject; #ifdef __cplusplus @@ -65,11 +68,22 @@ extern "C" { * @param[in] width The width of the window * @param[in] height The height of the window * - * @note The drawing color gets set to White and the background drawing color to Black. - * @note Don't forget to set the font using @p gwinSetFont() or @p gwinSetDefaultFont() + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. * @note The dimensions and position may be changed to fit on the real screen. - * @note The slider is not automatically drawn. Call gwinDraw() to draw it. - * @note Sets the slider range from 0 to 100 with an initial position of 0 + * @note A slider remembers its normal drawing state. If there is a window manager then it is automatically + * redrawn if the window is moved or its visibility state is changed. + * @note The slider is initially marked as invisible so that more properties can be set before display. + * Call @p gwinSetVisible() to display it when ready. + * @note The initial slider range is from 0 to 100 with an initial position of 0. + * @note A slider supports mouse, toggle and dial input. + * @note When assigning a toggle, only one toggle is supported per role. If you try to assign more than + * one toggle to a role it will forget the previous toggle. Two roles are supported: + * Role 0 = toggle for down, Role 1 = toggle for up. + * @note When assigning a dial, only one dial is supported. If you try to assign more than one dial + * it will forget the previous dial. Only dial role 0 is supported. * * @api */ |