GWIN renaming, tidy up, color styles

ugfx_release_2.6
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;
#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.
*
@ -65,9 +87,30 @@ typedef struct GWidgetObject {
typedef struct GWidgetInit {
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.
@ -356,8 +356,23 @@ extern "C" {
*/
void gwinResize(GHandle gh, coord_t width, coord_t height);
/**
* @brief Redraw a window
*
* @param[in] gh The 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 gwinRedraw(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
@ -378,6 +393,7 @@ extern "C" {
/**
* @brief Get the Minimized/Maximized state of a window
* @pre GWIN_NEED_WINDOWMANAGER must be TRUE
*
* @param[in] gh The window
*
@ -387,16 +403,17 @@ extern "C" {
/**
* @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. If there is no
* window manager this call simple tries to redraw the window. See the comments
* @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,72 +158,63 @@ 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) {
const GColorSet * pcol;
(void) param;
GButtonColors * pcol;
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) {
const GColorSet * pcol;
(void) param;
GButtonColors * pcol;
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) {
const GColorSet * pcol;
(void) param;
GButtonColors * pcol;
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) {
const GColorSet * pcol;
(void) param;
GButtonColors * pcol;
point arw[7];
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
@ -266,14 +228,15 @@ 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) {
const GColorSet * pcol;
(void) param;
GButtonColors * pcol;
point arw[7];
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
@ -287,14 +250,15 @@ 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) {
const GColorSet * pcol;
(void) param;
GButtonColors * pcol;
point arw[7];
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
@ -308,14 +272,15 @@ 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) {
const GColorSet * pcol;
(void) param;
GButtonColors * pcol;
point arw[7];
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
@ -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;
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;
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;
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

View File

@ -165,7 +165,7 @@ static void lineto(GGraphObject *gg, coord_t x0, coord_t y0, coord_t x1, coord_t
}
}
GHandle gwinCreateGraph(GGraphObject *gg, const GWindowInit *pInit) {
GHandle gwinGraphCreate(GGraphObject *gg, const GWindowInit *pInit) {
if (!(gg = (GGraphObject *)_gwindowCreate(&gg->g, pInit, &graphVMT, 0)))
return 0;
gg->xorigin = gg->yorigin = 0;

View File

@ -16,6 +16,66 @@
/* Our listener for events for widgets */
static GListener gl;
/* Our default style - a white background theme */
const GWidgetStyle WhiteWidgetStyle = {
HTML2COLOR(0xFFFFFF), // window background
// enabled color set
{
HTML2COLOR(0x000000), // text
HTML2COLOR(0x404040), // edge
HTML2COLOR(0xE0E0E0), // fill
HTML2COLOR(0xE0E0E0), // progress - inactive area
},
// disabled color set
{
HTML2COLOR(0xC0C0C0), // text
HTML2COLOR(0x808080), // edge
HTML2COLOR(0xE0E0E0), // fill
HTML2COLOR(0xC0E0C0), // progress - active area
},
// pressed color set
{
HTML2COLOR(0x404040), // text
HTML2COLOR(0x404040), // edge
HTML2COLOR(0x808080), // fill
HTML2COLOR(0x00E000), // progress - active area
},
};
/* Our black style */
const GWidgetStyle BlackWidgetStyle = {
HTML2COLOR(0x000000), // window background
// enabled color set
{
HTML2COLOR(0xC0C0C0), // text
HTML2COLOR(0xC0C0C0), // edge
HTML2COLOR(0x606060), // fill
HTML2COLOR(0x404040), // progress - inactive area
},
// disabled color set
{
HTML2COLOR(0x808080), // text
HTML2COLOR(0x404040), // edge
HTML2COLOR(0x404040), // fill
HTML2COLOR(0x004000), // progress - active area
},
// pressed color set
{
HTML2COLOR(0xFFFFFF), // text
HTML2COLOR(0xC0C0C0), // edge
HTML2COLOR(0xE0E0E0), // fill
HTML2COLOR(0x008000), // progress - active area
},
};
static const GWidgetStyle * defaultStyle = &BlackWidgetStyle;
/* We use these everywhere in this file */
#define gw ((GWidgetObject *)gh)
#define wvmt ((gwidgetVMT *)gh->vmt)
@ -169,9 +229,10 @@ GHandle _gwidgetCreate(GWidgetObject *pgw, const GWidgetInit *pInit, const gwidg
if (!(pgw = (GWidgetObject *)_gwindowCreate(&pgw->g, &pInit->g, &vmt->g, GWIN_FLG_WIDGET|GWIN_FLG_ENABLED)))
return 0;
pgw->txt = pInit->text ? pInit->text : "";
pgw->fnDraw = vmt->DefaultDraw;
pgw->fnParam = 0;
pgw->text = pInit->text ? pInit->text : "";
pgw->fnDraw = pInit->customDraw ? pInit->customDraw : vmt->DefaultDraw;
pgw->fnParam = pInit->customParam;
pgw->pstyle = pInit->customStyle ? pInit->customStyle : defaultStyle;
return &pgw->g;
}
@ -184,7 +245,7 @@ void _gwidgetDestroy(GHandle gh) {
// Deallocate the text (if necessary)
if ((gh->flags & GWIN_FLG_ALLOCTXT)) {
gh->flags &= ~GWIN_FLG_ALLOCTXT;
gfxFree((void *)gw->txt);
gfxFree((void *)gw->text);
}
#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE
@ -226,32 +287,60 @@ void _gwidgetRedraw(GHandle gh) {
gw->fnDraw(gw, gw->fnParam);
}
void gwinSetText(GHandle gh, const char *txt, bool_t useAlloc) {
void gwinSetDefaultStyle(const GWidgetStyle *pstyle, bool_t updateAll) {
if (!pstyle)
pstyle = &BlackWidgetStyle;
if (updateAll) {
const gfxQueueASyncItem * qi;
GHandle gh;
for(qi = gfxQueueASyncPeek(&_GWINList); qi; qi = gfxQueueASyncNext(qi)) {
gh = QItem2GWindow(qi);
if ((gh->flags & GWIN_FLG_WIDGET) && ((GWidgetObject *)gh)->pstyle == defaultStyle)
gwinSetStyle(gh, pstyle);
}
}
gwinSetDefaultBgColor(pstyle->background);
defaultStyle = pstyle;
}
/**
* @brief Get the current default style.
*
* @api
*/
const GWidgetStyle *gwinGetDefaultStyle(void) {
return defaultStyle;
}
void gwinSetText(GHandle gh, const char *text, bool_t useAlloc) {
if (!(gh->flags & GWIN_FLG_WIDGET))
return;
// Dispose of the old string
if ((gh->flags & GWIN_FLG_ALLOCTXT)) {
gh->flags &= ~GWIN_FLG_ALLOCTXT;
if (gw->txt) {
gfxFree((void *)gw->txt);
gw->txt = "";
if (gw->text) {
gfxFree((void *)gw->text);
gw->text = "";
}
}
// Alloc the new text if required
if (txt && !*txt) txt = 0;
if (txt && useAlloc) {
if (!text || !*text)
gw->text = "";
else if (useAlloc) {
char *str;
if ((str = (char *)gfxAlloc(strlen(txt)+1))) {
if ((str = (char *)gfxAlloc(strlen(text)+1))) {
gh->flags |= GWIN_FLG_ALLOCTXT;
strcpy(str, txt);
strcpy(str, text);
}
txt = (const char *)str;
}
gw->txt = txt ? txt : "";
gw->text = (const char *)str;
} else
gw->text = text;
_gwidgetRedraw(gh);
}
@ -259,7 +348,20 @@ const char *gwinGetText(GHandle gh) {
if (!(gh->flags & GWIN_FLG_WIDGET))
return 0;
return gw->txt;
return gw->text;
}
void gwinSetStyle(GHandle gh, const GWidgetStyle *pstyle) {
if (!(gh->flags & GWIN_FLG_WIDGET))
return;
gw->pstyle = pstyle ? pstyle : defaultStyle;
gh->bgcolor = pstyle->background;
gh->color = pstyle->enabled.text;
_gwidgetRedraw(gh);
}
const GWidgetStyle *gwinGetStyle(GHandle gh) {
return gw->pstyle;
}
void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void *param) {

View File

@ -32,11 +32,6 @@ static color_t defaultBgColor = Black;
#if GDISP_NEED_TEXT
static font_t defaultFont;
#endif
#if GWIN_NEED_WINDOWMANAGER
gfxQueueASync _GWINList;
extern GWindowManager GNullWindowManager;
static GWindowManager * cwm;
#endif
/*-----------------------------------------------
* Helper Routines
@ -52,9 +47,9 @@ static color_t defaultBgColor = Black;
} else
gwinClear(gh);
}
static void _gwm_redim(GHandle gh, const GWindowInit *pInit) {
gh->x = pInit->x; gh->y = pInit->y;
gh->width = pInit->width; gh->height = pInit->height;
static void _gwm_redim(GHandle gh, coord_t x, coord_t y, coord_t width, coord_t height) {
gh->x = x; gh->y = y;
gh->width = width; gh->height = height;
if (gh->x < 0) { gh->width += gh->x; gh->x = 0; }
if (gh->y < 0) { gh->height += gh->y; gh->y = 0; }
if (gh->x > gdispGetWidth()-MIN_WIN_WIDTH) gh->x = gdispGetWidth()-MIN_WIN_WIDTH;
@ -87,9 +82,9 @@ void _gwinInit(void) {
_gwidgetInit();
#endif
#if GWIN_NEED_WINDOWMANAGER
gfxQueueASyncInit(&_GWINList);
cwm = &GNullWindowManager;
cwm->vmt->Init();
extern void _gwmInit(void);
_gwmInit();
#endif
}
@ -113,7 +108,7 @@ GHandle _gwindowCreate(GWindowObject *pgw, const GWindowInit *pInit, const gwinV
#endif
#if GWIN_NEED_WINDOWMANAGER
if (!cwm->vmt->Add(pgw, pInit)) {
if (!_GWINwm->vmt->Add(pgw, pInit)) {
if ((pgw->flags & GWIN_FLG_DYNAMIC))
gfxFree(pgw);
return 0;
@ -129,18 +124,6 @@ GHandle _gwindowCreate(GWindowObject *pgw, const GWindowInit *pInit, const gwinV
* Routines that affect all windows
*-----------------------------------------------*/
#if GWIN_NEED_WINDOWMANAGER
void gwinSetWindowManager(struct GWindowManager *gwm) {
if (!gwm)
gwm = &GNullWindowManager;
if (cwm != gwm) {
cwm->vmt->DeInit();
cwm = gwm;
cwm->vmt->Init();
}
}
#endif
void gwinSetDefaultColor(color_t clr) {
defaultFgColor = clr;
}
@ -171,7 +154,7 @@ color_t gwinGetDefaultBgColor(void) {
* The GWindow Routines
*-----------------------------------------------*/
GHandle gwinCreateWindow(GWindowObject *pgw, const GWindowInit *pInit) {
GHandle gwinWindowCreate(GWindowObject *pgw, const GWindowInit *pInit) {
if (!(pgw = _gwindowCreate(pgw, pInit, &basegwinVMT, 0)))
return 0;
gwinSetVisible(pgw, pInit->show);
@ -181,7 +164,7 @@ GHandle gwinCreateWindow(GWindowObject *pgw, const GWindowInit *pInit) {
void gwinDestroy(GHandle gh) {
// Remove from the window manager
#if GWIN_NEED_WINDOWMANAGER
cwm->vmt->Delete(gh);
_GWINwm->vmt->Delete(gh);
#endif
// Class destroy routine
@ -204,7 +187,7 @@ void gwinSetVisible(GHandle gh, bool_t visible) {
if (!(gh->flags & GWIN_FLG_VISIBLE)) {
gh->flags |= GWIN_FLG_VISIBLE;
#if GWIN_NEED_WINDOWMANAGER
cwm->vmt->Visible(gh);
_GWINwm->vmt->Visible(gh);
#else
_gwm_vis(gh);
#endif
@ -213,7 +196,7 @@ void gwinSetVisible(GHandle gh, bool_t visible) {
if ((gh->flags & GWIN_FLG_VISIBLE)) {
gh->flags &= ~GWIN_FLG_VISIBLE;
#if GWIN_NEED_WINDOWMANAGER
cwm->vmt->Visible(gh);
_GWINwm->vmt->Visible(gh);
#endif
}
}
@ -253,7 +236,7 @@ bool_t gwinGetEnabled(GHandle gh) {
void gwinMove(GHandle gh, coord_t x, coord_t y) {
#if GWIN_NEED_WINDOWMANAGER
cwm->vmt->Redim(gh, x, y, gh->width, gh->height);
_GWINwm->vmt->Redim(gh, x, y, gh->width, gh->height);
#else
_gwm_redim(gh, x, y, gh->width, gh->height);
#endif
@ -261,44 +244,21 @@ void gwinMove(GHandle gh, coord_t x, coord_t y) {
void gwinResize(GHandle gh, coord_t width, coord_t height) {
#if GWIN_NEED_WINDOWMANAGER
cwm->vmt->Redim(gh, gh->x, gh->y, width, height);
_GWINwm->vmt->Redim(gh, gh->x, gh->y, width, height);
#else
_gwm_redim(gh, gh->x, gh->y, width, height);
#endif
}
void gwinSetMinMax(GHandle gh, GWindowMinMax minmax) {
void gwinRedraw(GHandle gh) {
#if GWIN_NEED_WINDOWMANAGER
cwm->vmt->MinMax(gh, minmax);
gwinRaise(gh);
#else
(void) gh;
(void) minmax;
if ((gh->flags & GWIN_FLG_VISIBLE))
_gwm_vis(gh);
#endif
}
void gwinRaise(GHandle gh) {
#if GWIN_NEED_WINDOWMANAGER
cwm->vmt->Raise(gh);
#else
if ((gh->flags & GWIN_FLG_VISIBLE)) {
if (gh->vmt->Redraw) {
#if GDISP_NEED_CLIP
gdispSetClip(gh->x, gh->y, gh->width, gh->height);
#endif
gh->vmt->Redraw(gh);
}
}
#endif
}
GWindowMinMax gwinGetMinMax(GHandle gh) {
if (gh->flags & GWIN_FLG_MINIMIZED)
return GWIN_MINIMIZE;
if (gh->flags & GWIN_FLG_MAXIMIZED)
return GWIN_MAXIMIZE;
return GWIN_NORMAL;
}
#if GDISP_NEED_TEXT
void gwinSetFont(GHandle gh, font_t font) {
gh->font = font;

View File

@ -43,10 +43,49 @@ static const gwmVMT GNullWindowManagerVMT = {
WM_MinMax,
};
const GWindowManager GNullWindowManager = {
static const GWindowManager GNullWindowManager = {
&GNullWindowManagerVMT,
};
gfxQueueASync _GWINList;
GWindowManager * _GWINwm;
/*-----------------------------------------------
* Window Routines
*-----------------------------------------------*/
void _gwmInit(void) {
gfxQueueASyncInit(&_GWINList);
_GWINwm = (GWindowManager *)&GNullWindowManager;
_GWINwm->vmt->Init();
}
void gwinSetWindowManager(struct GWindowManager *gwm) {
if (!gwm)
gwm = (GWindowManager *)&GNullWindowManager;
if (_GWINwm != gwm) {
_GWINwm->vmt->DeInit();
_GWINwm = gwm;
_GWINwm->vmt->Init();
}
}
void gwinSetMinMax(GHandle gh, GWindowMinMax minmax) {
_GWINwm->vmt->MinMax(gh, minmax);
}
void gwinRaise(GHandle gh) {
_GWINwm->vmt->Raise(gh);
}
GWindowMinMax gwinGetMinMax(GHandle gh) {
if (gh->flags & GWIN_FLG_MINIMIZED)
return GWIN_MINIMIZE;
if (gh->flags & GWIN_FLG_MAXIMIZED)
return GWIN_MAXIMIZE;
return GWIN_NORMAL;
}
/*-----------------------------------------------
* Window Manager Routines
*-----------------------------------------------*/

View File

@ -25,38 +25,40 @@
#define GLABEL_FLG_HAUTO (GWIN_FIRST_CONTROL_FLAG<<1)
// Simple: single line with no wrapping
static coord_t getwidth(const char *txt, font_t font, coord_t maxwidth) {
static coord_t getwidth(const char *text, font_t font, coord_t maxwidth) {
(void) maxwidth;
return gdispGetStringWidth(txt, font)+2; // Allow one pixel of padding on each side
return gdispGetStringWidth(text, font)+2; // Allow one pixel of padding on each side
}
// Simple: single line with no wrapping
static coord_t getheight(const char *txt, font_t font, coord_t maxwidth) {
(void) txt;
static coord_t getheight(const char *text, font_t font, coord_t maxwidth) {
(void) text;
(void) maxwidth;
return gdispGetFontMetric(font, fontHeight);
}
static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) {
(void) param;
coord_t w, h;
(void) param;
w = (gw->g.flags & GLABEL_FLG_WAUTO) ? getwidth(gw->txt, gw->g.font, gdispGetWidth() - gw->g.x) : gw->g.width;
h = (gw->g.flags & GLABEL_FLG_HAUTO) ? getheight(gw->txt, gw->g.font, gdispGetWidth() - gw->g.x) : gw->g.height;
w = (gw->g.flags & GLABEL_FLG_WAUTO) ? getwidth(gw->text, gw->g.font, gdispGetWidth() - gw->g.x) : gw->g.width;
h = (gw->g.flags & GLABEL_FLG_HAUTO) ? getheight(gw->text, gw->g.font, gdispGetWidth() - gw->g.x) : gw->g.height;
if (gw->g.width != w || gw->g.height != h) {
gwinResize(&gw->g, w, h);
return;
}
gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->txt, gw->g.font, gw->g.color, gw->g.bgcolor, justifyLeft);
gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font,
(gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background,
justifyLeft);
}
static const gwidgetVMT labelVMT = {
{
"Label", // The class name
sizeof(GLabelWidget), // The object size
sizeof(GLabelObject), // The object size
_gwidgetDestroy, // The destroy routine
_gwidgetRedraw, // The redraw routine
0, // The after-clear routine
@ -88,7 +90,7 @@ static const gwidgetVMT labelVMT = {
#endif
};
GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit) {
GHandle gwinLabelCreate(GLabelObject *widget, GWidgetInit *pInit) {
uint16_t flags = 0;
// auto assign width
@ -103,7 +105,7 @@ GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit) {
pInit->g.height = getheight(pInit->text, gwinGetDefaultFont(), gdispGetWidth() - pInit->g.x);
}
if (!(widget = (GLabelWidget *)_gwidgetCreate(&widget->w, pInit, &labelVMT)))
if (!(widget = (GLabelObject *)_gwidgetCreate(&widget->w, pInit, &labelVMT)))
return 0;
widget->w.g.flags |= flags;

View File

@ -24,25 +24,8 @@
// Our pressed state
#define GRADIO_FLG_PRESSED (GWIN_FIRST_CONTROL_FLAG<<0)
// Default color scheme
static const GRadioColors GRadioDefaultColorsUp = {
HTML2COLOR(0x404040), // color_up_edge;
HTML2COLOR(0xE0E0E0), // color_up_fill;
HTML2COLOR(0x000000), // color_up_txt;
};
static const GRadioColors GRadioDefaultColorsDown = {
HTML2COLOR(0x404040), // color_dn_edge;
HTML2COLOR(0x808080), // color_dn_fill;
HTML2COLOR(0x404040), // color_dn_txt;
};
static const GRadioColors GRadioDefaultColorsDisabled = {
HTML2COLOR(0x808080), // color_dis_edge;
HTML2COLOR(0xE0E0E0), // color_dis_fill;
HTML2COLOR(0xC0C0C0), // color_dis_txt;
};
// Send the button event
static void SendButtonEvent(GWidgetObject *gw) {
static void SendRadioEvent(GWidgetObject *gw) {
GSourceListener * psl;
GEvent * pe;
#define pbe ((GEventGWinRadio *)pe)
@ -66,7 +49,7 @@ static void SendButtonEvent(GWidgetObject *gw) {
static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) {
(void) x; (void) y;
gwinPressRadio((GHandle)gw);
gwinRadioPress((GHandle)gw);
}
#endif
@ -75,7 +58,7 @@ static void SendButtonEvent(GWidgetObject *gw) {
static void ToggleOn(GWidgetObject *gw, uint16_t role) {
(void) role;
gwinPressRadio((GHandle)gw);
gwinRadioPress((GHandle)gw);
}
static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) {
@ -125,7 +108,7 @@ static const gwidgetVMT radioVMT = {
#endif
};
GHandle gwinCreateRadio(GRadioObject *gw, const GWidgetInit *pInit, uint16_t group) {
GHandle gwinRadioCreate(GRadioObject *gw, const GWidgetInit *pInit, uint16_t group) {
if (!(gw = (GRadioObject *)_gwidgetCreate(&gw->w, pInit, &radioVMT)))
return 0;
@ -133,53 +116,33 @@ GHandle gwinCreateRadio(GRadioObject *gw, const GWidgetInit *pInit, uint16_t gro
gw->toggle = GWIDGET_NO_INSTANCE;
#endif
gw->group = group;
gw->c_up = GRadioDefaultColorsUp;
gw->c_dn = GRadioDefaultColorsDown;
gw->c_dis = GRadioDefaultColorsDisabled;
gwinSetVisible((GHandle)gw, pInit->g.show);
return (GHandle)gw;
}
void gwinSetRadioColors(GHandle gh, const GRadioColors *pUp, const GRadioColors *pDown, const GRadioColors *pDisabled) {
if (gh->vmt != (gwinVMT *)&radioVMT)
return;
if (pUp) ((GRadioObject *)gh)->c_up = *pUp;
if (pDown) ((GRadioObject *)gh)->c_dn = *pDown;
if (pDisabled) ((GRadioObject *)gh)->c_dis = *pDisabled;
}
void gwinPressRadio(GHandle gh) {
void gwinRadioPress(GHandle gh) {
GHandle gx;
if (gh->vmt != (gwinVMT *)&radioVMT || (gh->flags & GRADIO_FLG_PRESSED))
return;
if ((gx = gwinActiveRadio(((GRadioObject *)gh)->group))) {
if ((gx = gwinRadioGetActive(((GRadioObject *)gh)->group))) {
gx->flags &= ~GRADIO_FLG_PRESSED;
_gwidgetRedraw(gx);
}
gh->flags |= GRADIO_FLG_PRESSED;
_gwidgetRedraw(gh);
SendButtonEvent((GWidgetObject *)gh);
SendRadioEvent((GWidgetObject *)gh);
}
bool_t gwinIsRadioPressed(GHandle gh) {
bool_t gwinRadioIsPressed(GHandle gh) {
if (gh->vmt != (gwinVMT *)&radioVMT)
return FALSE;
return (gh->flags & GRADIO_FLG_PRESSED) ? TRUE : FALSE;
}
/**
* @brief Find the currently pressed radio button in the specified group
* @return The handle of the pressed radio button or NULL if none are pressed
*
* @param[in] gh The window handle (must be a radio widget)
*
* @api
*/
GHandle gwinActiveRadio(uint16_t group) {
GHandle gwinRadioGetActive(uint16_t group) {
const gfxQueueASyncItem * qi;
GHandle gh;
@ -195,16 +158,16 @@ GHandle gwinActiveRadio(uint16_t group) {
* Custom Draw Routines
*----------------------------------------------------------*/
static GRadioColors *getDrawColors(GWidgetObject *gw) {
if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &((GRadioObject *)gw)->c_dis;
if ((gw->g.flags & GRADIO_FLG_PRESSED)) return &((GRadioObject *)gw)->c_dn;
return &((GRadioObject *)gw)->c_up;
static const GColorSet *getDrawColors(GWidgetObject *gw) {
if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &gw->pstyle->disabled;
if ((gw->g.flags & GRADIO_FLG_PRESSED)) return &gw->pstyle->pressed;
return &gw->pstyle->enabled;
}
void gwinRadioDraw_Radio(GWidgetObject *gw, void *param) {
#define gcw ((GRadioObject *)gw)
coord_t ld, df;
GRadioColors * pcol;
const GColorSet * pcol;
(void) param;
if (gw->g.vmt != (gwinVMT *)&radioVMT) return;
@ -213,46 +176,52 @@ void gwinRadioDraw_Radio(GWidgetObject *gw, void *param) {
ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height;
#if GDISP_NEED_CIRCLE
df = ld/2;
gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->g.bgcolor);
gdispDrawCircle(gw->g.x+df, gw->g.y+df, df, pcol->color_edge);
df = (ld-1)/2;
gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background);
gdispDrawCircle(gw->g.x+df, gw->g.y+df, df, pcol->edge);
if (gw->g.flags & GRADIO_FLG_PRESSED)
gdispFillCircle(gw->g.x+df, gw->g.y+df, df <= 2 ? 1 : (df-2), pcol->color_fill);
gdispFillCircle(gw->g.x+df, gw->g.y+df, df <= 2 ? 1 : (df-2), pcol->fill);
#else
gdispFillArea(gw->g.x+1, gw->g.y+1, ld, ld-2, gw->g.bgcolor);
gdispDrawBox(gw->g.x, gw->g.y, ld, ld, pcol->color_edge);
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 & GRADIO_FLG_PRESSED)
gdispFillArea(gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->color_fill);
gdispFillArea(gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill);
#endif
gdispFillStringBox(gw->g.x+ld+1, gw->g.y, gw->g.width-ld-1, gw->g.height, gw->txt, gw->g.font, pcol->color_txt, gw->g.bgcolor, 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 gwinRadioDraw_Button(GWidgetObject *gw, void *param) {
const GColorSet * pcol;
(void) param;
GRadioColors * pcol;
if (gw->g.vmt != (gwinVMT *)&radioVMT) 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);
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);
}
void gwinRadioDraw_Tab(GWidgetObject *gw, void *param) {
const GColorSet * pcol;
(void) param;
GRadioColors * pcol;
if (gw->g.vmt != (gwinVMT *)&radioVMT) 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);
if ((gw->g.flags & GRADIO_FLG_PRESSED)) {
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge);
gdispFillStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-1, gw->text, gw->g.font, pcol->text, pcol->fill, justifyCenter);
} else {
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);
}
}
#endif /* GFX_USE_GWIN && GWIN_NEED_BUTTON */

View File

@ -29,14 +29,6 @@
#define GWIN_SLIDER_TOGGLE_INC 20 // How many toggles to go from minimum to maximum
#endif
static const GSliderColors GSliderDefaultColors = {
HTML2COLOR(0x404040), // color_edge
HTML2COLOR(0x000000), // color_thumb
HTML2COLOR(0x00E000), // color_active
HTML2COLOR(0xE0E0E0), // color_inactive
HTML2COLOR(0xFFFFFF), // color_txt
};
// Send the slider event
static void SendSliderEvent(GWidgetObject *gw) {
GSourceListener * psl;
@ -146,10 +138,10 @@ static void ResetDisplayPos(GSliderObject *gsw) {
#define gsw ((GSliderObject *)gw)
if (role) {
gwinSetSliderPosition((GHandle)gw, gsw->pos+(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC);
gwinSliderSetPosition((GHandle)gw, gsw->pos+(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC);
SendSliderEvent(gw);
} else {
gwinSetSliderPosition((GHandle)gw, gsw->pos-(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC);
gwinSliderSetPosition((GHandle)gw, gsw->pos-(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC);
SendSliderEvent(gw);
}
#undef gsw
@ -231,7 +223,7 @@ static const gwidgetVMT sliderVMT = {
#endif
};
GHandle gwinCreateSlider(GSliderObject *gs, const GWidgetInit *pInit) {
GHandle gwinSliderCreate(GSliderObject *gs, const GWidgetInit *pInit) {
if (!(gs = (GSliderObject *)_gwidgetCreate(&gs->w, pInit, &sliderVMT)))
return 0;
#if GINPUT_NEED_TOGGLE
@ -241,7 +233,6 @@ GHandle gwinCreateSlider(GSliderObject *gs, const GWidgetInit *pInit) {
#if GINPUT_NEED_DIAL
gs->dial = GWIDGET_NO_INSTANCE;
#endif
gs->c = GSliderDefaultColors;
gs->min = 0;
gs->max = 100;
gs->pos = 0;
@ -250,7 +241,7 @@ GHandle gwinCreateSlider(GSliderObject *gs, const GWidgetInit *pInit) {
return (GHandle)gs;
}
void gwinSetSliderRange(GHandle gh, int min, int max) {
void gwinSliderSetRange(GHandle gh, int min, int max) {
#define gsw ((GSliderObject *)gh)
if (gh->vmt != (gwinVMT *)&sliderVMT)
@ -265,7 +256,7 @@ void gwinSetSliderRange(GHandle gh, int min, int max) {
#undef gsw
}
void gwinSetSliderPosition(GHandle gh, int pos) {
void gwinSliderSetPosition(GHandle gh, int pos) {
#define gsw ((GSliderObject *)gh)
if (gh->vmt != (gwinVMT *)&sliderVMT)
@ -284,46 +275,49 @@ void gwinSetSliderPosition(GHandle gh, int pos) {
#undef gsw
}
void gwinSetSliderColors(GHandle gh, const GSliderColors *pColors) {
if (gh->vmt != (gwinVMT *)&sliderVMT)
return;
((GSliderObject *)gh)->c = *pColors;
}
/*----------------------------------------------------------
* Custom Draw Routines
*----------------------------------------------------------*/
void gwinSliderDraw_Std(GWidgetObject *gw, void *param) {
#define gsw ((GSliderObject *)gw)
const GColorSet * pcol;
(void) param;
if (gw->g.vmt != (gwinVMT *)&sliderVMT)
return;
if ((gw->g.flags & GWIN_FLG_ENABLED))
pcol = &gw->pstyle->pressed;
else
pcol = &gw->pstyle->disabled;
if (gw->g.width < gw->g.height) { // Vertical slider
if (gsw->dpos != gw->g.height-1)
gdispFillArea(gw->g.x, gw->g.y+gsw->dpos, gw->g.width, gw->g.height - gsw->dpos, gsw->c.color_active);
gdispFillArea(gw->g.x, gw->g.y+gsw->dpos, gw->g.width, gw->g.height - gsw->dpos, pcol->progress); // Active Area
if (gsw->dpos != 0)
gdispFillArea(gw->g.x, gw->g.y, gw->g.width, gsw->dpos, gsw->c.color_inactive);
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gsw->c.color_edge);
gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos, gsw->c.color_thumb);
gdispFillArea(gw->g.x, gw->g.y, gw->g.width, gsw->dpos, gw->pstyle->enabled.progress); // Inactive area
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge
gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos, pcol->edge); // Thumb
if (gsw->dpos >= 2)
gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos-2, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos-2, gsw->c.color_thumb);
gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos-2, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos-2, pcol->edge); // Thumb
if (gsw->dpos <= gw->g.height-2)
gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos+2, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos+2, gsw->c.color_thumb);
gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos+2, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos+2, pcol->edge); // Thumb
// Horizontal slider
} else {
if (gsw->dpos != gw->g.width-1)
gdispFillArea(gw->g.x+gsw->dpos, gw->g.y, gw->g.width-gsw->dpos, gw->g.height, gsw->c.color_inactive);
gdispFillArea(gw->g.x+gsw->dpos, gw->g.y, gw->g.width-gsw->dpos, gw->g.height, gw->pstyle->enabled.progress); // Inactive area
if (gsw->dpos != 0)
gdispFillArea(gw->g.x, gw->g.y, gsw->dpos, gw->g.height, gsw->c.color_active);
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gsw->c.color_edge);
gdispDrawLine(gw->g.x+gsw->dpos, gw->g.y, gw->g.x+gsw->dpos, gw->g.y+gw->g.height-1, gsw->c.color_thumb);
gdispFillArea(gw->g.x, gw->g.y, gsw->dpos, gw->g.height, pcol->progress); // Active Area
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge
gdispDrawLine(gw->g.x+gsw->dpos, gw->g.y, gw->g.x+gsw->dpos, gw->g.y+gw->g.height-1, pcol->edge); // Thumb
if (gsw->dpos >= 2)
gdispDrawLine(gw->g.x+gsw->dpos-2, gw->g.y, gw->g.x+gsw->dpos-2, gw->g.y+gw->g.height-1, gsw->c.color_thumb);
gdispDrawLine(gw->g.x+gsw->dpos-2, gw->g.y, gw->g.x+gsw->dpos-2, gw->g.y+gw->g.height-1, pcol->edge); // Thumb
if (gsw->dpos <= gw->g.width-2)
gdispDrawLine(gw->g.x+gsw->dpos+2, gw->g.y, gw->g.x+gsw->dpos+2, gw->g.y+gw->g.height-1, gsw->c.color_thumb);
gdispDrawLine(gw->g.x+gsw->dpos+2, gw->g.y, gw->g.x+gsw->dpos+2, gw->g.y+gw->g.height-1, pcol->edge); // Thumb
}
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, gsw->c.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);
#undef gsw
}
@ -331,14 +325,20 @@ void gwinSliderDraw_Std(GWidgetObject *gw, void *param) {
void gwinSliderDraw_Image(GWidgetObject *gw, void *param) {
#define gsw ((GSliderObject *)gw)
#define gi ((gdispImage *)param)
const GColorSet * pcol;
coord_t z, v;
if (gw->g.vmt != (gwinVMT *)&sliderVMT)
return;
if ((gw->g.flags & GWIN_FLG_ENABLED))
pcol = &gw->pstyle->pressed;
else
pcol = &gw->pstyle->disabled;
if (gw->g.width < gw->g.height) { // Vertical slider
if (gsw->dpos != 0) // The unfilled area
gdispFillArea(gw->g.x, gw->g.y, gw->g.width, gsw->dpos, gsw->c.color_inactive);
gdispFillArea(gw->g.x, gw->g.y, gw->g.width, gsw->dpos, gw->pstyle->enabled.progress); // Inactive area
if (gsw->dpos != gw->g.height-1) { // The filled area
for(z=gw->g.height, v=gi->height; z > gsw->dpos;) {
z -= v;
@ -349,13 +349,13 @@ void gwinSliderDraw_Image(GWidgetObject *gw, void *param) {
gdispImageDraw(gi, gw->g.x, gw->g.y+z, gw->g.width, v, 0, gi->height-v);
}
}
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gsw->c.color_edge);
gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos, gsw->c.color_thumb);
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge
gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos, pcol->edge); // Thumb
// Horizontal slider
} else {
if (gsw->dpos != gw->g.width-1) // The unfilled area
gdispFillArea(gw->g.x+gsw->dpos, gw->g.y, gw->g.width-gsw->dpos, gw->g.height, gsw->c.color_inactive);
gdispFillArea(gw->g.x+gsw->dpos, gw->g.y, gw->g.width-gsw->dpos, gw->g.height, gw->pstyle->enabled.progress); // Inactive area
if (gsw->dpos != 0) { // The filled area
for(z=0, v=gi->width; z < gsw->dpos; z += v) {
if (z+v > gsw->dpos)
@ -363,10 +363,10 @@ void gwinSliderDraw_Image(GWidgetObject *gw, void *param) {
gdispImageDraw(gi, gw->g.x+z, gw->g.y, v, gw->g.height, 0, 0);
}
}
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gsw->c.color_edge);
gdispDrawLine(gw->g.x+gsw->dpos, gw->g.y, gw->g.x+gsw->dpos, gw->g.y+gw->g.height-1, gsw->c.color_thumb);
gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge
gdispDrawLine(gw->g.x+gsw->dpos, gw->g.y, gw->g.x+gsw->dpos, gw->g.y+gw->g.height-1, pcol->edge); // Thumb
}
gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, gsw->c.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);
#undef gsw
}