GWIN renaming, tidy up, color styles

This commit is contained in:
inmarket 2013-07-07 19:40:37 +10:00
parent de28112a7d
commit 3957505ab1
22 changed files with 594 additions and 533 deletions

View File

@ -40,27 +40,15 @@ typedef struct GEventGWinButton {
GHandle button; // The button that has been depressed (actually triggered on release)
} GEventGWinButton;
/**
* @brief Button colors
*/
typedef struct GButtonColors {
color_t color_edge;
color_t color_fill;
color_t color_txt;
} GButtonColors;
/**
* @brief The button widget structure
* @note Do not use the members directly - treat it as a black-box.
*/
typedef struct GButtonObject_t {
typedef struct GButtonObject {
GWidgetObject w;
#if GINPUT_NEED_TOGGLE
uint16_t toggle;
uint16_t toggle;
#endif
GButtonColors c_up;
GButtonColors c_dn;
GButtonColors c_dis;
} GButtonObject;
#ifdef __cplusplus
@ -86,26 +74,7 @@ extern "C" {
*
* @api
*/
GHandle gwinCreateButton(GButtonObject *gb, const GWidgetInit *pInit);
/**
* @brief Set the colors of a button.
*
* @param[in] gh The window handle (must be a button widget)
* @param[in] pUp The colors for the button when in the up state.
* @param[in] pDown The colors for the button when in the down state.
* @param[in] pDisabled The colors for the button when it is disabled.
*
* @note The button is not automatically redrawn. Call gwinButtonDraw() after changing the button style
* @note The button style is copied into the internal button structure - there is no need to
* maintain static style structures (they can be temporary structures on the stack).
* @note The pUp, pDown and pDisabled parameters can be NULL. If they are then the existing color styles
* are not changed for that button state.
* @note Some custom drawn buttons will ignore he specified colors
*
* @api
*/
void gwinSetButtonColors(GHandle gh, const GButtonColors *pUp, const GButtonColors *pDown, const GButtonColors *pDisabled);
GHandle gwinButtonCreate(GButtonObject *gb, const GWidgetInit *pInit);
/**
* @brief Is the button current pressed
@ -115,7 +84,7 @@ void gwinSetButtonColors(GHandle gh, const GButtonColors *pUp, const GButtonColo
*
* @api
*/
bool_t gwinIsButtonPressed(GHandle gh);
bool_t gwinButtonIsPressed(GHandle gh);
/**
* @brief Some custom button drawing routines
@ -141,7 +110,6 @@ bool_t gwinIsButtonPressed(GHandle gh);
* @{
*/
void gwinButtonDraw_3D(GWidgetObject *gw, void *param); // @< A standard 3D button
void gwinButtonDraw_Box(GWidgetObject *gw, void *param); // @< A very simple box style button
#if GDISP_NEED_ARC || defined(__DOXYGEN__)
void gwinButtonDraw_Rounded(GWidgetObject *gw, void *param); // @< A rounded rectangle button
#endif

View File

@ -34,26 +34,18 @@
/* Type definitions */
/*===========================================================================*/
typedef struct GEventGWinCheckbox_t {
typedef struct GEventGWinCheckbox {
GEventType type; // The type of this event (GEVENT_GWIN_CHECKBOX)
GHandle checkbox; // The checkbox that has been depressed (actually triggered on release)
bool_t isChecked; // Is the checkbox currently checked or unchecked?
} GEventGWinCheckbox;
typedef struct GCheckboxColors {
color_t color_border;
color_t color_checked;
color_t color_bg;
color_t color_txt;
} GCheckboxColors;
/* A Checkbox window */
typedef struct GCheckboxObject_t {
typedef struct GCheckboxObject {
GWidgetObject w;
#if GINPUT_NEED_TOGGLE
uint16_t toggle;
#endif
GCheckboxColors c;
} GCheckboxObject;
/**
@ -75,7 +67,17 @@ typedef struct GCheckboxObject_t {
*
* @api
*/
GHandle gwinCreateCheckbox(GCheckboxObject *gb, const GWidgetInit *pInit);
GHandle gwinCheckboxCreate(GCheckboxObject *gb, const GWidgetInit *pInit);
/**
* @brief Set the state of a checkbox
*
* @param[in] gh The window handle (must be a checkbox window)
* @param[in] isChecked TRUE to set the check, FALSE to uncheck.
*
* @api
*/
void gwinCheckboxCheck(GHandle gh, bool_t isChecked);
/**
* @brief Get the state of a checkbox
@ -85,17 +87,7 @@ GHandle gwinCreateCheckbox(GCheckboxObject *gb, const GWidgetInit *pInit);
*
* @api
*/
bool_t gwinIsCheckboxChecked(GHandle gh);
/**
* @brief Set the colors used to draw the checkbox
*
* @param[in] gh The window handle (must be a checkbox window)
* @param[in] pColors The colors to use
*
* @api
*/
void gwinCheckboxSetColors(GHandle gh, GCheckboxColors *pColors);
bool_t gwinCheckboxIsChecked(GHandle gh);
/**
* @brief Some custom checkbox drawing routines

View File

@ -136,6 +136,11 @@ typedef struct gwinVMT {
* @brief The list of all windows in the system
*/
extern gfxQueueASync _GWINList;
/**
* @brief The current window manager
*/
extern GWindowManager * _GWINwm;
#endif
#ifdef __cplusplus

View File

@ -27,7 +27,7 @@
/* This file is included within "gwin/gwin.h" */
// A console window. Supports wrapped text writing and a cursor.
typedef struct GConsoleObject_t {
typedef struct GConsoleObject {
GWindowObject g;
coord_t cx, cy; // Cursor position
@ -46,8 +46,8 @@ extern "C" {
/**
* @brief Create a console window.
* @details A console window allows text to be written using chprintf() (and the console functions defined here).
* @brief Text in a console window supports newlines and will wrap text as required.
* @details A console window allows text to be written.
* @note Text in a console window supports newlines and will wrap text as required.
* @return NULL if there is no resultant drawing area, otherwise a window handle.
*
* @param[in] gc The GConsoleObject structure to initialise. If this is NULL the structure is dynamically allocated.
@ -64,7 +64,7 @@ extern "C" {
*
* @api
*/
GHandle gwinCreateConsole(GConsoleObject *gc, const GWindowInit *pInit);
GHandle gwinConsoleCreate(GConsoleObject *gc, const GWindowInit *pInit);
#if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM
/**
@ -77,7 +77,7 @@ GHandle gwinCreateConsole(GConsoleObject *gc, const GWindowInit *pInit);
*
* @api
*/
BaseSequentialStream *gwinGetConsoleStream(GHandle gh);
BaseSequentialStream *gwinConsoleGetStream(GHandle gh);
#endif
/**

View File

@ -71,7 +71,7 @@ typedef struct GGraphStyle_t {
} GGraphStyle;
// A graph window
typedef struct GGraphObject_t {
typedef struct GGraphObject {
GWindowObject g;
GGraphStyle style;
coord_t xorigin, yorigin;
@ -107,7 +107,7 @@ extern "C" {
*
* @api
*/
GHandle gwinCreateGraph(GGraphObject *gg, const GWindowInit *pInit);
GHandle gwinGraphCreate(GGraphObject *gg, const GWindowInit *pInit);
/**
* @brief Set the style of the graphing operations.

View File

@ -30,28 +30,50 @@
// Forward definition
struct GWidgetObject;
/**
* @brief The GColorSet structure
* @{
*/
typedef struct GColorSet {
color_t text; // @< The text color
color_t edge; // @< The edge color
color_t fill; // @< The fill color
color_t progress; // @< The color of progress bars
} GColorSet;
/* @} */
/**
* @brief The GWidgetStyle structure
* @details A GWidgetStyle is a set of colors that together form a "style".
* These colors should not be confused with the GWindow foreground
* and background colors which are used for drawing operations.
* @{
*/
typedef struct GWidgetStyle {
color_t background; // @< The window background color
GColorSet enabled; // @< The colors when enabled
GColorSet disabled; // @< The colors when disabled
GColorSet pressed; // @< The colors when pressed
} GWidgetStyle;
/* @} */
/**
* @brief We define a couple of GWidgetStyle's that you can use in your
* application. The Black style is the default style if you don't
* specify one.
* @note BlackWidgetStyle means that it is designed for a Black background.
* Similarly WhiteWidgetStyle is designed for a White background.
* @{
*/
extern const GWidgetStyle BlackWidgetStyle;
extern const GWidgetStyle WhiteWidgetStyle;
/* @} */
/**
* @brief Defines a custom drawing function for a widget
*/
typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param);
/**
* @brief The GWIN Widget structure
* @note A widget is a GWIN window that accepts user input.
* It also has a number of other properties such as its ability
* to redraw itself (a widget maintains drawing state).
* @note Do not access the members directly. Treat it as a black-box and use the method functions.
*
* @{
*/
typedef struct GWidgetObject {
GWindowObject g; // @< This is still a GWIN
const char * txt; // @< The widget text
CustomWidgetDrawFunction fnDraw; // @< The current draw function
void * fnParam; // @< A parameter for the current draw function
} GWidgetObject;
/* @} */
/**
* @brief The structure to initialise a widget.
*
@ -63,11 +85,32 @@ typedef struct GWidgetObject {
* @{
*/
typedef struct GWidgetInit {
GWindowInit g; // @< The GWIN initializer
const char * text; // @< The initial text
GWindowInit g; // @< The GWIN initializer
const char * text; // @< The initial text
CustomWidgetDrawFunction customDraw; // @< A custom draw function - use NULL for the standard
void * customParam; // @< A parameter for the custom draw function (default = NULL)
const GWidgetStyle * customStyle; // @< A custom style to use - use NULL for the default style
} GWidgetInit;
/* @} */
/**
* @brief The GWIN Widget structure
* @note A widget is a GWIN window that accepts user input.
* It also has a number of other properties such as its ability
* to redraw itself (a widget maintains drawing state).
* @note Do not access the members directly. Treat it as a black-box and use the method functions.
*
* @{
*/
typedef struct GWidgetObject {
GWindowObject g; // @< This is still a GWIN
const char * text; // @< The widget text
CustomWidgetDrawFunction fnDraw; // @< The current draw function
void * fnParam; // @< A parameter for the current draw function
const GWidgetStyle * pstyle; // @< The current widget style colors
} GWidgetObject;
/* @} */
/**
* A comment/rant on the above structure:
* We would really like the GWindowObject member to be anonymous. While this is
@ -83,11 +126,32 @@ typedef struct GWidgetInit {
extern "C" {
#endif
/**
* @brief Set the default style for widgets created hereafter.
*
* @param[in] pstyle The default style. Passing NULL uses the system compiled style.
* @param[in] updateAll If TRUE then all existing widgets that are using the current default style
* will be updated to use this new style. Widgets that have custom styles different
* from the default style will not be updated.
*
* @note The style must be allocated statically (not on the stack) as only the pointer is stored.
*
* @api
*/
void gwinSetDefaultStyle(const GWidgetStyle *pstyle, bool_t updateAll);
/**
* @brief Get the current default style.
*
* @api
*/
const GWidgetStyle *gwinGetDefaultStyle(void);
/**
* @brief Set the text of a widget.
*
* @param[in] gh The widget handle
* @param[in] txt The text to set. This must be a constant string unless useAlloc is set.
* @param[in] text The text to set. This must be a constant string unless useAlloc is set.
* @param[in] useAlloc If TRUE the string specified will be copied into dynamically allocated memory.
*
* @note The widget is automatically redrawn
@ -95,7 +159,7 @@ extern "C" {
*
* @api
*/
void gwinSetText(GHandle gh, const char *txt, bool_t useAlloc);
void gwinSetText(GHandle gh, const char *text, bool_t useAlloc);
/**
* @brief Get the text of a widget.
@ -107,6 +171,30 @@ void gwinSetText(GHandle gh, const char *txt, bool_t useAlloc);
*/
const char *gwinGetText(GHandle gh);
/**
* @brief Set the style of a widget.
*
* @param[in] gh The widget handle
* @param[in] pstyle The style to set. This must be a static structure (not allocated on a transient stack).
* Use NULL to reset to the default style.
*
* @note The widget is automatically redrawn
* @note Non-widgets will ignore this call.
*
* @api
*/
void gwinSetStyle(GHandle gh, const GWidgetStyle *pstyle);
/**
* @brief Get the style of a widget.
* @return The widget style or NULL if it isn't a widget
*
* @param[in] gh The widget handle
*
* @api
*/
const GWidgetStyle *gwinGetStyle(GHandle gh);
/**
* @brief Set the routine to perform a custom widget drawing.
*

View File

@ -174,7 +174,7 @@ extern "C" {
*
* @api
*/
GHandle gwinCreateWindow(GWindowObject *pgw, const GWindowInit *pInit);
GHandle gwinWindowCreate(GWindowObject *pgw, const GWindowInit *pInit);
/**
* @brief Destroy a window (of any type). Releases any dynamically allocated memory.
@ -357,46 +357,63 @@ extern "C" {
void gwinResize(GHandle gh, coord_t width, coord_t height);
/**
* @brief Minimize, Maximize or Restore a window
* @brief Redraw a window
*
* @param[in] gh The window
* @param[in] minmax The new minimized/maximized state
*
* @note The final window state may not be the requested state. Window Managers
* do not need to implement changing the minmax state. If there is no
* window manager this call is ignored.
* @note The window is redrawn if it is changed. See the comments in @p gwinSetVisible()
* with regard to what can be redrawn and what can't.
* @note It is up to the window manager to determine what happens with any screen area
* uncovered by resizing the window.
* @note When a window is minimised it may be asked to draw the window or the window
* manager may draw the minimised window.
* @note This is normally never required as windows and widgets will redraw as required.
* Note that some windows are incapable of redrawing themselves as they don't save
* their drawing state.
*
* @api
*/
void gwinSetMinMax(GHandle gh, GWindowMinMax minmax);
void gwinRedraw(GHandle gh);
/**
* @brief Get the Minimized/Maximized state of a window
*
* @param[in] gh The window
*
* @api
*/
GWindowMinMax gwinGetMinMax(GHandle gh);
#if GWIN_NEED_WINDOWMANAGER
/**
* @brief Minimize, Maximize or Restore a window
* @pre GWIN_NEED_WINDOWMANAGER must be TRUE
*
* @param[in] gh The window
* @param[in] minmax The new minimized/maximized state
*
* @note The final window state may not be the requested state. Window Managers
* do not need to implement changing the minmax state. If there is no
* window manager this call is ignored.
* @note The window is redrawn if it is changed. See the comments in @p gwinSetVisible()
* with regard to what can be redrawn and what can't.
* @note It is up to the window manager to determine what happens with any screen area
* uncovered by resizing the window.
* @note When a window is minimised it may be asked to draw the window or the window
* manager may draw the minimised window.
*
* @api
*/
void gwinSetMinMax(GHandle gh, GWindowMinMax minmax);
/**
* @brief Raise a window to the top of the z-order
*
* @param[in] gh The window
*
* @note The window z-order is only supported by some window managers. If there is no
* window manager this call simple tries to redraw the window. See the comments
* in @p gwinSetVisible() with regard to what can be redrawn and what can't.
*
* @api
*/
void gwinRaise(GHandle gh);
/**
* @brief Get the Minimized/Maximized state of a window
* @pre GWIN_NEED_WINDOWMANAGER must be TRUE
*
* @param[in] gh The window
*
* @api
*/
GWindowMinMax gwinGetMinMax(GHandle gh);
/**
* @brief Raise a window to the top of the z-order
* @pre GWIN_NEED_WINDOWMANAGER must be TRUE
*
* @param[in] gh The window
*
* @note The window z-order is only supported by some window managers. See the comments
* in @p gwinSetVisible() with regard to what can be redrawn and what can't.
*
* @api
*/
void gwinRaise(GHandle gh);
#endif
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**

View File

@ -30,10 +30,10 @@
// This file is included within "gwin/gwin.h"
// An image window
typedef struct GImageWidget_t {
typedef struct GImageObject {
GWindowObject g;
gdispImage image;
} GImageWidget;
} GImageObject;
#ifdef __cplusplus
extern "C" {
@ -41,7 +41,7 @@ extern "C" {
/**
* @brief Create an image widget.
* @details A console widget allows to display a picture.
* @details Display's a picture.
* @return NULL if there is no resultant drawing area, otherwise the widget handle.
*
* @param[in] widget The image widget structure to initialise. If this is NULL, the structure is dynamically allocated.
@ -52,10 +52,10 @@ extern "C" {
*
* @api
*/
GHandle gwinImageCreate(GImageWidget *widget, GWindowInit *pInit);
GHandle gwinImageCreate(GImageObject *widget, GWindowInit *pInit);
/**
* @brief Sets the sets the io fields in the image structure to routines that support reading from an image stored
* @brief Sets the input routines that support reading the image from memory
* in RAM or flash.
* @return TRUE if the IO open function succeeds
*
@ -68,8 +68,7 @@ bool_t gwinImageOpenMemory(GHandle gh, const void* memory);
#if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_POSIX || defined(__DOXYGEN__)
/**
* @brief Sets the sets the io fields in the image structure to routines that support reading from an image stored
* in a simulators native file system.
* @brief Sets the input routines that support reading the image from a file
* @return TRUE if the IO open function succeeds
*
* @param[in] gh The widget (must be an image widget)
@ -82,8 +81,7 @@ bool_t gwinImageOpenMemory(GHandle gh, const void* memory);
#if GFX_USE_OS_CHIBIOS || defined(__DOXYGEN__)
/**
* @brief Sets the sets the io fields in the image structure to routines that support reading from an image stored
* on a BaseFileStream (eg. an SD-Card).
* @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card).
* @return TRUE if the IO open function succeeds
*
* @param[in] gh The widget (must be an image widget)

View File

@ -30,9 +30,9 @@
// This file is included within "gwin/gwin.h"
// An label window
typedef struct GLabelWidget_t {
typedef struct GLabelObject {
GWidgetObject w;
} GLabelWidget;
} GLabelObject;
#ifdef __cplusplus
extern "C" {
@ -49,7 +49,7 @@ extern "C" {
*
* @api
*/
GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit);
GHandle gwinLabelCreate(GLabelObject *widget, GWidgetInit *pInit);
#ifdef __cplusplus
}

View File

@ -39,28 +39,16 @@ typedef struct GEventGWinRadio {
uint16_t group; // The group for this radio button
} GEventGWinRadio;
/**
* @brief Button colors
*/
typedef struct GRadioColors {
color_t color_edge;
color_t color_fill;
color_t color_txt;
} GRadioColors;
/**
* @brief The radio button widget structure
* @note Do not use the members directly - treat it as a black-box.
*/
typedef struct GRadioObject_t {
typedef struct GRadioObject {
GWidgetObject w;
#if GINPUT_NEED_TOGGLE
uint16_t toggle;
#endif
uint16_t group;
GRadioColors c_up;
GRadioColors c_dn;
GRadioColors c_dis;
} GRadioObject;
#ifdef __cplusplus
@ -89,26 +77,7 @@ extern "C" {
*
* @api
*/
GHandle gwinCreateRadio(GRadioObject *gb, const GWidgetInit *pInit, uint16_t group);
/**
* @brief Set the colors of a button.
*
* @param[in] gh The window handle (must be a radio widget)
* @param[in] pUp The colors for the button when in the up state.
* @param[in] pDown The colors for the button when in the down state.
* @param[in] pDisabled The colors for the button when it is disabled.
*
* @note The button is not automatically redrawn. Call gwinButtonDraw() after changing the button style
* @note The button style is copied into the internal button structure - there is no need to
* maintain static style structures (they can be temporary structures on the stack).
* @note The pUp, pDown and pDisabled parameters can be NULL. If they are then the existing color styles
* are not changed for that button state.
* @note Some custom drawn buttons will ignore he specified colors
*
* @api
*/
void gwinSetRadioColors(GHandle gh, const GRadioColors *pUp, const GRadioColors *pDown, const GRadioColors *pDisabled);
GHandle gwinRadioCreate(GRadioObject *gb, const GWidgetInit *pInit, uint16_t group);
/**
* @brief Press this radio button (and by definition unset any others in the group)
@ -117,7 +86,7 @@ void gwinSetRadioColors(GHandle gh, const GRadioColors *pUp, const GRadioColors
*
* @api
*/
void gwinPressRadio(GHandle gh);
void gwinRadioPress(GHandle gh);
/**
* @brief Is the radio button currently pressed
@ -127,7 +96,7 @@ void gwinPressRadio(GHandle gh);
*
* @api
*/
bool_t gwinIsRadioPressed(GHandle gh);
bool_t gwinRadioIsPressed(GHandle gh);
/**
* @brief Find the currently pressed radio button in the specified group
@ -137,7 +106,7 @@ bool_t gwinIsRadioPressed(GHandle gh);
*
* @api
*/
GHandle gwinActiveRadio(uint16_t group);
GHandle gwinRadioGetActive(uint16_t group);
/**
* @brief Some custom radio button drawing routines

View File

@ -26,7 +26,7 @@
#define GEVENT_GWIN_SLIDER (GEVENT_GWIN_FIRST+1)
typedef struct GEventGWinSlider_t {
typedef struct GEventGWinSlider {
GEventType type; // The type of this event (GEVENT_GWIN_BUTTON)
GHandle slider; // The slider that is returning results
int position;
@ -34,16 +34,8 @@ typedef struct GEventGWinSlider_t {
// There are currently no GEventGWinSlider listening flags - use 0
typedef struct GSliderColors {
color_t color_edge;
color_t color_thumb;
color_t color_active;
color_t color_inactive;
color_t color_txt;
} GSliderColors;
// A slider window
typedef struct GSliderObject_t {
typedef struct GSliderObject {
GWidgetObject w;
#if GINPUT_NEED_TOGGLE
uint16_t t_dn;
@ -56,7 +48,6 @@ typedef struct GSliderObject_t {
int min;
int max;
int pos;
GSliderColors c;
} GSliderObject;
#ifdef __cplusplus
@ -86,7 +77,7 @@ extern "C" {
*
* @api
*/
GHandle gwinCreateSlider(GSliderObject *gb, const GWidgetInit *pInit);
GHandle gwinSliderCreate(GSliderObject *gb, const GWidgetInit *pInit);
/**
* @brief Set the slider range.
@ -99,7 +90,7 @@ GHandle gwinCreateSlider(GSliderObject *gb, const GWidgetInit *pInit);
*
* @api
*/
void gwinSetSliderRange(GHandle gh, int min, int max);
void gwinSliderSetRange(GHandle gh, int min, int max);
/**
* @brief Set the slider position.
@ -112,22 +103,7 @@ void gwinSetSliderRange(GHandle gh, int min, int max);
*
* @api
*/
void gwinSetSliderPosition(GHandle gh, int pos);
/**
* @brief Set the style of a slider.
* @details The slider style is defined by its colours.
*
* @param[in] gh The window handle (must be a slider window)
* @param[in] pStyle The styling for the slider.
*
* @note The slider is not automatically redrawn. Call gwinSliderDraw() after changing the slider style
* @note The slider style is copied into the internal slider structure - there is no need to
* maintain a static style structure.
*
* @api
*/
void gwinSetSliderColors(GHandle gh, const GSliderColors *pStyle);
void gwinSliderSetPosition(GHandle gh, int pos);
/**
* @brief Get the current slider position.
@ -140,7 +116,7 @@ void gwinSetSliderColors(GHandle gh, const GSliderColors *pStyle);
*
* @api
*/
#define gwinGetSliderPosition(gh) (((GSliderObject *)(gh))->pos)
#define gwinSliderGetPosition(gh) (((GSliderObject *)(gh))->pos)
/**
* @brief Some custom slider drawing routines

View File

@ -29,23 +29,6 @@
// Our pressed state
#define GBUTTON_FLG_PRESSED (GWIN_FIRST_CONTROL_FLAG<<0)
// Default color scheme
static const GButtonColors GButtonDefaultColorsUp = {
HTML2COLOR(0x404040), // color_up_edge;
HTML2COLOR(0xE0E0E0), // color_up_fill;
HTML2COLOR(0x000000), // color_up_txt;
};
static const GButtonColors GButtonDefaultColorsDown = {
HTML2COLOR(0x404040), // color_dn_edge;
HTML2COLOR(0x808080), // color_dn_fill;
HTML2COLOR(0x404040), // color_dn_txt;
};
static const GButtonColors GButtonDefaultColorsDisabled = {
HTML2COLOR(0x808080), // color_dis_edge;
HTML2COLOR(0xE0E0E0), // color_dis_fill;
HTML2COLOR(0xC0C0C0), // color_dis_txt;
};
// Send the button event
static void SendButtonEvent(GWidgetObject *gw) {
GSourceListener * psl;
@ -153,30 +136,18 @@ static const gwidgetVMT buttonVMT = {
#endif
};
GHandle gwinCreateButton(GButtonObject *gw, const GWidgetInit *pInit) {
GHandle gwinButtonCreate(GButtonObject *gw, const GWidgetInit *pInit) {
if (!(gw = (GButtonObject *)_gwidgetCreate(&gw->w, pInit, &buttonVMT)))
return 0;
#if GINPUT_NEED_TOGGLE
gw->toggle = GWIDGET_NO_INSTANCE;
#endif
gw->c_up = GButtonDefaultColorsUp;
gw->c_dn = GButtonDefaultColorsDown;
gw->c_dis = GButtonDefaultColorsDisabled;
gwinSetVisible((GHandle)gw, pInit->g.show);
return (GHandle)gw;
}
void gwinSetButtonColors(GHandle gh, const GButtonColors *pUp, const GButtonColors *pDown, const GButtonColors *pDisabled) {
if (gh->vmt != (gwinVMT *)&buttonVMT)
return;
if (pUp) ((GButtonObject *)gh)->c_up = *pUp;
if (pDown) ((GButtonObject *)gh)->c_dn = *pDown;
if (pDisabled) ((GButtonObject *)gh)->c_dis = *pDisabled;
}
bool_t gwinIsButtonPressed(GHandle gh) {
bool_t gwinButtonIsPressed(GHandle gh) {
if (gh->vmt != (gwinVMT *)&buttonVMT)
return FALSE;
@ -187,73 +158,64 @@ bool_t gwinIsButtonPressed(GHandle gh) {
* Custom Draw Routines
*----------------------------------------------------------*/
static GButtonColors *getDrawColors(GWidgetObject *gw) {
if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &((GButtonObject *)gw)->c_dis;
if ((gw->g.flags & GBUTTON_FLG_PRESSED)) return &((GButtonObject *)gw)->c_dn;
return &((GButtonObject *)gw)->c_up;
static const GColorSet *getDrawColors(GWidgetObject *gw) {
if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &gw->pstyle->disabled;
if ((gw->g.flags & GBUTTON_FLG_PRESSED)) return &gw->pstyle->pressed;
return &gw->pstyle->enabled;
}
void gwinButtonDraw_3D(GWidgetObject *gw, void *param) {
(void) param;
GButtonColors * pcol;
const GColorSet * pcol;
(void) param;
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
pcol = getDrawColors(gw);
gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->txt, gw->g.font, pcol->color_txt, pcol->color_fill, justifyCenter);
gdispDrawLine(gw->g.x+gw->g.width-1, gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, pcol->color_edge);
gdispDrawLine(gw->g.x, gw->g.y+gw->g.height-1, gw->g.x+gw->g.width-2, gw->g.y+gw->g.height-1, pcol->color_edge);
}
void gwinButtonDraw_Box(GWidgetObject *gw, void *param) {
(void) param;
GButtonColors * pcol;
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
pcol = getDrawColors(gw);
gdispFillStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, pcol->color_fill, justifyCenter);
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->color_edge);
gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->text, gw->g.font, pcol->text, pcol->fill, justifyCenter);
gdispDrawLine(gw->g.x+gw->g.width-1, gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, pcol->edge);
gdispDrawLine(gw->g.x, gw->g.y+gw->g.height-1, gw->g.x+gw->g.width-2, gw->g.y+gw->g.height-1, pcol->edge);
}
#if GDISP_NEED_ARC
void gwinButtonDraw_Rounded(GWidgetObject *gw, void *param) {
(void) param;
GButtonColors * pcol;
const GColorSet * pcol;
(void) param;
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
pcol = getDrawColors(gw);
gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background);
if (gw->g.width >= 2*RND_CNR_SIZE+10) {
gdispFillRoundedBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, RND_CNR_SIZE-1, pcol->color_fill);
gdispDrawStringBox(gw->g.x+1, gw->g.y+RND_CNR_SIZE, gw->g.width-2, gw->g.height-(2*RND_CNR_SIZE), gw->txt, gw->g.font, pcol->color_txt, justifyCenter);
gdispDrawRoundedBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, RND_CNR_SIZE, pcol->color_edge);
gdispFillRoundedBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, RND_CNR_SIZE-1, pcol->fill);
gdispDrawStringBox(gw->g.x+1, gw->g.y+RND_CNR_SIZE, gw->g.width-2, gw->g.height-(2*RND_CNR_SIZE), gw->text, gw->g.font, pcol->text, justifyCenter);
gdispDrawRoundedBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, RND_CNR_SIZE, pcol->edge);
} else {
gdispFillStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, pcol->color_fill, justifyCenter);
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->color_edge);
gdispFillStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, pcol->fill, justifyCenter);
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge);
}
}
#endif
#if GDISP_NEED_ELLIPSE
void gwinButtonDraw_Ellipse(GWidgetObject *gw, void *param) {
(void) param;
GButtonColors * pcol;
const GColorSet * pcol;
(void) param;
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
pcol = getDrawColors(gw);
gdispFillEllipse(gw->g.x+1, gw->g.y+1, gw->g.width/2-1, gw->g.height/2-1, pcol->color_fill);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter);
gdispDrawEllipse(gw->g.x, gw->g.y, gw->g.width/2, gw->g.height/2, pcol->color_edge);
gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background);
gdispFillEllipse(gw->g.x+1, gw->g.y+1, gw->g.width/2-1, gw->g.height/2-1, pcol->fill);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter);
gdispDrawEllipse(gw->g.x, gw->g.y, gw->g.width/2, gw->g.height/2, pcol->edge);
}
#endif
#if GDISP_NEED_CONVEX_POLYGON
void gwinButtonDraw_ArrowUp(GWidgetObject *gw, void *param) {
(void) param;
GButtonColors * pcol;
point arw[7];
const GColorSet * pcol;
(void) param;
point arw[7];
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
pcol = getDrawColors(gw);
@ -266,15 +228,16 @@ void gwinButtonDraw_Box(GWidgetObject *gw, void *param) {
arw[5].x = (gw->g.width - gw->g.width/ARROWBODY_DIVIDER)/2; arw[5].y = gw->g.height/ARROWHEAD_DIVIDER;
arw[6].x = 0; arw[6].y = gw->g.height/ARROWHEAD_DIVIDER;
gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_fill);
gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_edge);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter);
gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background);
gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->fill);
gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->edge);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter);
}
void gwinButtonDraw_ArrowDown(GWidgetObject *gw, void *param) {
(void) param;
GButtonColors * pcol;
point arw[7];
const GColorSet * pcol;
(void) param;
point arw[7];
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
pcol = getDrawColors(gw);
@ -287,15 +250,16 @@ void gwinButtonDraw_Box(GWidgetObject *gw, void *param) {
arw[5].x = (gw->g.width - gw->g.width/ARROWBODY_DIVIDER)/2; arw[5].y = gw->g.height-1-gw->g.height/ARROWHEAD_DIVIDER;
arw[6].x = 0; arw[6].y = gw->g.height-1-gw->g.height/ARROWHEAD_DIVIDER;
gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_fill);
gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_edge);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter);
gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background);
gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->fill);
gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->edge);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter);
}
void gwinButtonDraw_ArrowLeft(GWidgetObject *gw, void *param) {
(void) param;
GButtonColors * pcol;
point arw[7];
const GColorSet * pcol;
(void) param;
point arw[7];
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
pcol = getDrawColors(gw);
@ -308,15 +272,16 @@ void gwinButtonDraw_Box(GWidgetObject *gw, void *param) {
arw[5].x = gw->g.width/ARROWHEAD_DIVIDER; arw[5].y = (gw->g.height + gw->g.height/ARROWBODY_DIVIDER)/2;
arw[6].x = gw->g.width/ARROWHEAD_DIVIDER; arw[6].y = gw->g.height-1;
gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_fill);
gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_edge);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter);
gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background);
gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->fill);
gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->edge);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter);
}
void gwinButtonDraw_ArrowRight(GWidgetObject *gw, void *param) {
(void) param;
GButtonColors * pcol;
point arw[7];
const GColorSet * pcol;
(void) param;
point arw[7];
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
pcol = getDrawColors(gw);
@ -329,32 +294,31 @@ void gwinButtonDraw_Box(GWidgetObject *gw, void *param) {
arw[5].x = gw->g.width-1-gw->g.width/ARROWHEAD_DIVIDER; arw[5].y = (gw->g.height + gw->g.height/ARROWBODY_DIVIDER)/2;
arw[6].x = gw->g.width-1-gw->g.width/ARROWHEAD_DIVIDER; arw[6].y = gw->g.height-1;
gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_fill);
gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_edge);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter);
gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background);
gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->fill);
gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->edge);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter);
}
#endif
#if GDISP_NEED_IMAGE || defined(__DOXYGEN__)
void gwinButtonDraw_Image(GWidgetObject *gw, void *param) {
GButtonColors * pcol;
coord_t sy;
const GColorSet * pcol;
coord_t sy;
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
pcol = getDrawColors(gw);
if (!(gw->g.flags & GWIN_FLG_ENABLED)) {
pcol = &((GButtonObject *)gw)->c_dis;
sy = 2 * gw->g.height;
} else if ((gw->g.flags & GBUTTON_FLG_PRESSED)) {
pcol = &((GButtonObject *)gw)->c_dn;
sy = gw->g.height;
} else {
pcol = &((GButtonObject *)gw)->c_up;
sy = 0;
}
gdispImageDraw((gdispImage *)param, gw->g.x, gw->g.y, gw->g.width, gw->g.height, 0, sy);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter);
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter);
}
#endif

View File

@ -24,13 +24,6 @@
// Our checked state
#define GCHECKBOX_FLG_CHECKED (GWIN_FIRST_CONTROL_FLAG<<0)
static const GCheckboxColors defaultColors = {
Black, // border
Grey, // selected
White, // background
Black, // text
};
// Send the checkbox event
static void SendCheckboxEvent(GWidgetObject *gw) {
GSourceListener * psl;
@ -115,70 +108,89 @@ static const gwidgetVMT checkboxVMT = {
#endif
};
GHandle gwinCreateCheckbox(GCheckboxObject *gb, const GWidgetInit *pInit) {
GHandle gwinCheckboxCreate(GCheckboxObject *gb, const GWidgetInit *pInit) {
if (!(gb = (GCheckboxObject *)_gwidgetCreate(&gb->w, pInit, &checkboxVMT)))
return 0;
#if GINPUT_NEED_TOGGLE
gb->toggle = GWIDGET_NO_INSTANCE;
#endif
gb->c = defaultColors; // assign the default colors
gwinSetVisible((GHandle)gb, pInit->g.show);
return (GHandle)gb;
}
bool_t gwinIsCheckboxChecked(GHandle gh) {
void gwinCheckboxCheck(GHandle gh, bool_t isChecked) {
if (gh->vmt != (gwinVMT *)&checkboxVMT)
return;
if (isChecked) {
if ((gh->flags & GCHECKBOX_FLG_CHECKED)) return;
gh->flags |= GCHECKBOX_FLG_CHECKED;
} else {
if (!(gh->flags & GCHECKBOX_FLG_CHECKED)) return;
gh->flags &= ~GCHECKBOX_FLG_CHECKED;
}
_gwidgetRedraw(gh);
SendCheckboxEvent((GWidgetObject *)gh);
}
bool_t gwinCheckboxIsChecked(GHandle gh) {
if (gh->vmt != (gwinVMT *)&checkboxVMT)
return FALSE;
return (gh->flags & GCHECKBOX_FLG_CHECKED) ? TRUE : FALSE;
}
void gwinCheckboxSetColors(GHandle gh, GCheckboxColors *pColors) {
if (gh->vmt != (gwinVMT *)&checkboxVMT)
return;
/*----------------------------------------------------------
* Custom Draw Routines
*----------------------------------------------------------*/
((GCheckboxObject *)gh)->c = *pColors;
static const GColorSet *getDrawColors(GWidgetObject *gw) {
if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &gw->pstyle->disabled;
if ((gw->g.flags & GCHECKBOX_FLG_CHECKED)) return &gw->pstyle->pressed;
return &gw->pstyle->enabled;
}
void gwinCheckboxDraw_CheckOnLeft(GWidgetObject *gw, void *param) {
#define gcw ((GCheckboxObject *)gw)
coord_t ld, df;
(void) param;
#define gcw ((GCheckboxObject *)gw)
coord_t ld, df;
const GColorSet * pcol;
(void) param;
if (gw->g.vmt != (gwinVMT *)&checkboxVMT)
return;
if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return;
pcol = getDrawColors(gw);
ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height;
gdispFillArea(gw->g.x+1, gw->g.y+1, ld, ld-2, gcw->c.color_bg);
gdispDrawBox(gw->g.x, gw->g.y, ld, ld, gcw->c.color_border);
gdispFillArea(gw->g.x+1, gw->g.y+1, ld, ld-2, gw->pstyle->background);
gdispDrawBox(gw->g.x, gw->g.y, ld, ld, pcol->edge);
df = ld < 4 ? 1 : 2;
if (gw->g.flags & GCHECKBOX_FLG_CHECKED)
gdispFillArea(gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, gcw->c.color_checked);
gdispFillArea(gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill);
gdispFillStringBox(gw->g.x+ld+1, gw->g.y, gw->g.width-ld-1, gw->g.height, gw->txt, gw->g.font, gcw->c.color_txt, gcw->c.color_bg, justifyLeft);
gdispFillStringBox(gw->g.x+ld+1, gw->g.y, gw->g.width-ld-1, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyLeft);
#undef gcw
}
void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param) {
#define gcw ((GCheckboxObject *)gw)
coord_t ep, ld, df;
(void) param;
#define gcw ((GCheckboxObject *)gw)
coord_t ep, ld, df;
const GColorSet * pcol;
(void) param;
if (gw->g.vmt != (gwinVMT *)&checkboxVMT)
return;
if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return;
pcol = getDrawColors(gw);
ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height;
ep = gw->g.width-ld-1;
gdispFillArea(gw->g.x+ep-1, gw->g.y+1, ld, ld-2, gcw->c.color_bg);
gdispDrawBox(gw->g.x+ep, gw->g.y, ld, ld, gcw->c.color_border);
gdispFillArea(gw->g.x+ep-1, gw->g.y+1, ld, ld-2, gw->pstyle->background);
gdispDrawBox(gw->g.x+ep, gw->g.y, ld, ld, pcol->edge);
df = ld < 4 ? 1 : 2;
if (gw->g.flags & GCHECKBOX_FLG_CHECKED)
gdispFillArea(gw->g.x+ep+df, gw->g.y+df, ld-2*df, ld-2*df, gcw->c.color_checked);
gdispFillArea(gw->g.x+ep+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill);
gdispFillStringBox(gw->g.x, gw->g.y, ep, gw->g.height, gw->txt, gw->g.font, gcw->c.color_txt, gcw->c.color_bg, justifyRight);
gdispFillStringBox(gw->g.x, gw->g.y, ep, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyRight);
#undef gcw
}

View File

@ -66,7 +66,7 @@ static const gwinVMT consoleVMT = {
AfterClear, // The after-clear routine
};
GHandle gwinCreateConsole(GConsoleObject *gc, const GWindowInit *pInit) {
GHandle gwinConsoleCreate(GConsoleObject *gc, const GWindowInit *pInit) {
if (!(gc = (GConsoleObject *)_gwindowCreate(&gc->g, pInit, &consoleVMT, 0)))
return 0;
#if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM
@ -79,7 +79,7 @@ GHandle gwinCreateConsole(GConsoleObject *gc, const GWindowInit *pInit) {
}
#if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM
BaseSequentialStream *gwinGetConsoleStream(GHandle gh) {
BaseSequentialStream *gwinConsoleGetStream(GHandle gh) {
if (gh->vmt != &consoleVMT)
return 0;
return (BaseSequentialStream *)&(((GConsoleObject *)(gh))->stream);

View File

@ -16,7 +16,7 @@
#include "gwin/class_gwin.h"
#define widget(gh) ((GImageWidget*)gh)
#define widget(gh) ((GImageObject *)gh)
static void _destroy(GWindowObject *gh) {
if (gdispImageIsOpen(&widget(gh)->image))
@ -80,14 +80,14 @@ static void _redraw(GHandle gh) {
static const gwinVMT imageVMT = {
"Image", // The class name
sizeof(GImageWidget), // The object size
sizeof(GImageObject), // The object size
_destroy, // The destroy routine
_redraw, // The redraw routine
0, // The after-clear routine
};
GHandle gwinImageCreate(GImageWidget *gobj, GWindowInit *pInit) {
if (!(gobj = (GImageWidget *)_gwindowCreate(&gobj->g, pInit, &imageVMT, 0)))
GHandle gwinImageCreate(GImageObject *gobj, GWindowInit *pInit) {
if (!(gobj = (GImageObject *)_gwindowCreate(&gobj->g, pInit, &imageVMT, 0)))
return 0;
// Ensure the gdispImageIsOpen() gives valid results