/*
 * This file is subject to the terms of the GFX License, v1.0. If a copy of
 * the license was not distributed with this file, you can obtain one at:
 *
 *              http://chibios-gfx.com/license.html
 */

/**
 * @file    include/gwin/button.h
 * @brief   GWIN Graphic window subsystem header file.
 *
 * @defgroup Button Button
 * @ingroup GWIN
 *
 * @details		GWIN allows it to easily create buttons with different styles
 *				and check for different meta states such as: PRESSED, CLICKED,
 *				RELEASED etc.
 *
 * @pre			GFX_USE_GWIN must be set to TRUE in your gfxconf.h
 * @pre			GWIN_NEED_BUTTON must be set to TRUE in your gfxconf.h
 * @{
 */

#ifndef _GWIN_BUTTON_H
#define _GWIN_BUTTON_H

/* This file is included within "gwin/gwidget.h" */

/**
 * @brief	The Event Type for a Button Event
 */
#define GEVENT_GWIN_BUTTON		(GEVENT_GWIN_FIRST+0)

/**
 * @brief	A Button Event
 * @note	There are currently no GEventGWinButton listening flags - use 0 as the flags to @p gwinAttachListener()
 */
typedef struct GEventGWinButton {
	GEventType		type;				// The type of this event (GEVENT_GWIN_BUTTON)
	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 {
	GWidgetObject		w;
	GButtonColors		c_up;
	GButtonColors		c_dn;
	GButtonColors		c_dis;
} GButtonObject;

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief   Create a button widget.
 * @return  NULL if there is no resultant drawing area, otherwise a window handle.
 *
 * @param[in] gb		The GButtonObject structure to initialise. If this is NULL the structure is dynamically allocated.
 * @param[in] x,y		The screen co-ordinates for the top left corner of the window
 * @param[in] width		The width of the window
 * @param[in] height	The height of the window
 *
 * @note				The drawing color gets set to White and the background drawing color to Black.
 * @note				Don't forget to set the font using @p gwinSetFont() or @p gwinSetDefaultFont()
 * @note				The dimensions and position may be changed to fit on the real screen.
 * @note				The button is not automatically drawn. Call gwinDraw() to draw it.
 *
 * @api
 */	
GHandle gwinCreateButton(GButtonObject *gb, coord_t x, coord_t y, coord_t width, coord_t height);

/**
 * @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);

/**
 * @brief	Is the button current pressed
 * @return	TRUE if the button is depressed
 *
 * @param[in] gh	The window handle (must be a button widget)
 *
 * @api
 */
bool_t gwinIsButtonPressed(GHandle gh);

/**
 * @brief	Some custom button drawing routines
 * @details	These function may be passed to @p gwinSetCustomDraw() to get different button drawing styles
 *
 * @param[in] gw		The widget object (in this case a button)
 * @param[in] param		A parameter passed in from the user
 *
 * @note				In your custom button drawing function you may optionally call these
 * 						standard functions and then draw your extra details on top.
 * @note				The standard functions below ignore the param parameter except for @p gwinButtonDraw_Image().
 * @note				The image custom draw function  @p gwinButtonDraw_Image() uses param to pass in the gdispImage pointer.
 * 						The image must be already opened before calling  @p gwinSetCustomDraw(). The image should be 3
 * 						times the height of the button. The button image is repeated 3 times vertically, the first (top) for
 * 						the "up" image, the 2nd for the "down" image, and the third (bottom) image for the disabled state. If
 * 						the disabled state is never going to be used then the image can be just 2 times the button height.
 * 						No checking is done to compare the size of the button to the size of the image.
 * 						Note text is drawn on top of the image.
 * @note				These custom drawing routines don't have to worry about setting clipping as the framework
 * 						sets clipping to the object window prior to calling these routines.
 *
 * @api
 * @{
 */
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
#if GDISP_NEED_ELLIPSE || defined(__DOXYGEN__)
	void gwinButtonDraw_Ellipse(GWidgetObject *gw, void *param);		// @< A circular button
#endif
#if GDISP_NEED_CONVEX_POLYGON || defined(__DOXYGEN__)
	void gwinButtonDraw_ArrowUp(GWidgetObject *gw, void *param);		// @< An up arrow button
	void gwinButtonDraw_ArrowDown(GWidgetObject *gw, void *param);		// @< A down arrow button
	void gwinButtonDraw_ArrowLeft(GWidgetObject *gw, void *param);		// @< A left arrow button
	void gwinButtonDraw_ArrowRight(GWidgetObject *gw, void *param);		// @< A right arrow button
#endif
#if GDISP_NEED_IMAGE || defined(__DOXYGEN__)
	void gwinButtonDraw_Image(GWidgetObject *gw, void *param);			// @< An image button - see the notes above on the param.
#endif
/** @} */

#ifdef __cplusplus
}
#endif

#endif /* _GWIN_BUTTON_H */
/** @} */