2013-03-02 12:20:57 +00:00
|
|
|
/*
|
2013-06-15 11:09:02 +00:00
|
|
|
* This file is subject to the terms of the GFX License. If a copy of
|
2013-05-03 14:36:17 +00:00
|
|
|
* the license was not distributed with this file, you can obtain one at:
|
2013-03-02 12:20:57 +00:00
|
|
|
*
|
2018-10-01 15:32:39 +00:00
|
|
|
* http://ugfx.io/license.html
|
2013-03-02 12:20:57 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-06 04:44:47 +00:00
|
|
|
/**
|
2014-08-20 07:42:53 +00:00
|
|
|
* @file src/gwin/gwin_button.c
|
2014-05-20 16:05:38 +00:00
|
|
|
* @brief GWIN sub-system button code
|
2013-05-06 04:44:47 +00:00
|
|
|
*/
|
|
|
|
|
2015-11-21 09:27:08 +00:00
|
|
|
#include "../../gfx.h"
|
2013-03-02 12:20:57 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
#if GFX_USE_GWIN && GWIN_NEED_BUTTON
|
2013-03-02 12:20:57 +00:00
|
|
|
|
2014-08-20 07:42:53 +00:00
|
|
|
#include "gwin_class.h"
|
2013-06-06 04:33:32 +00:00
|
|
|
|
|
|
|
// Parameters for various shapes
|
2015-06-08 04:14:40 +00:00
|
|
|
#define BTN_CNR_SIZE 5 // Rounded corner size for rounded buttons
|
|
|
|
#define BTN_ARROWHEAD_DIV 0 // What fraction of the length for the arrow head. Use 0 for 45 degree arrow head.
|
|
|
|
#define BTN_ARROWBODY_DIV 2 // What fraction of the width for the arrow body
|
|
|
|
#define BTN_TOP_FADE 50 // (BTN_TOP_FADE/255)% fade to white for top of button
|
|
|
|
#define BTN_BOTTOM_FADE 25 // (BTN_BOTTOM_FADE/255)% fade to black for bottom of button
|
2013-03-10 06:15:49 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
#if GINPUT_NEED_MOUSE
|
|
|
|
// A mouse down has occurred over the button
|
2018-07-08 00:54:19 +00:00
|
|
|
static void ButtonMouseDown(GWidgetObject *gw, gCoord x, gCoord y) {
|
2013-07-05 15:45:24 +00:00
|
|
|
(void) x; (void) y;
|
|
|
|
gw->g.flags |= GBUTTON_FLG_PRESSED;
|
2014-05-21 03:02:00 +00:00
|
|
|
_gwinUpdate((GHandle)gw);
|
2013-07-05 15:45:24 +00:00
|
|
|
}
|
2013-03-02 12:20:57 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
// A mouse up has occurred (it may or may not be over the button)
|
2018-07-08 00:54:19 +00:00
|
|
|
static void ButtonMouseUp(GWidgetObject *gw, gCoord x, gCoord y) {
|
2013-07-05 15:45:24 +00:00
|
|
|
(void) x; (void) y;
|
|
|
|
gw->g.flags &= ~GBUTTON_FLG_PRESSED;
|
2014-05-21 03:02:00 +00:00
|
|
|
_gwinUpdate((GHandle)gw);
|
2013-03-02 12:20:57 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
#if !GWIN_BUTTON_LAZY_RELEASE
|
|
|
|
// If the mouse up was not over the button then cancel the event
|
|
|
|
if (x < 0 || y < 0 || x >= gw->g.width || y >= gw->g.height)
|
|
|
|
return;
|
|
|
|
#endif
|
2013-03-02 12:20:57 +00:00
|
|
|
|
2014-08-20 02:18:27 +00:00
|
|
|
_gwinSendEvent(&gw->g, GEVENT_GWIN_BUTTON);
|
2013-07-05 15:45:24 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-16 14:18:54 +00:00
|
|
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
2015-08-16 04:30:25 +00:00
|
|
|
static void ButtonKeyboard(GWidgetObject* gw, GEventKeyboard* pke)
|
2015-08-15 23:36:33 +00:00
|
|
|
{
|
|
|
|
// ENTER and SPACE keys to press the button
|
|
|
|
if (pke->c[0] == GKEY_ENTER || pke->c[0] == GKEY_SPACE) {
|
|
|
|
|
2016-08-24 07:48:41 +00:00
|
|
|
// Some keyboards (eg the virtual keyboard) can't send keyup events.
|
|
|
|
// Even for those that do we may not be listening for them.
|
|
|
|
// We should really process on a keydown and then set a timer to display
|
|
|
|
// the button release but that requires an extra timer and lots of
|
|
|
|
// complication. Instead we cheat by not providing user feedback of the keypress.
|
|
|
|
if (!(pke->keystate & GKEYSTATE_KEYUP))
|
|
|
|
_gwinSendEvent(&gw->g, GEVENT_GWIN_BUTTON);
|
2015-08-15 23:36:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
#if GINPUT_NEED_TOGGLE
|
|
|
|
// A toggle off has occurred
|
2018-11-03 00:51:23 +00:00
|
|
|
static void ButtonToggleOff(GWidgetObject *gw, gU16 role) {
|
2013-07-05 15:45:24 +00:00
|
|
|
(void) role;
|
|
|
|
gw->g.flags &= ~GBUTTON_FLG_PRESSED;
|
2014-05-21 03:02:00 +00:00
|
|
|
_gwinUpdate((GHandle)gw);
|
2013-07-05 15:45:24 +00:00
|
|
|
}
|
2013-03-02 12:20:57 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
// A toggle on has occurred
|
2018-11-03 00:51:23 +00:00
|
|
|
static void ButtonToggleOn(GWidgetObject *gw, gU16 role) {
|
2013-07-05 15:45:24 +00:00
|
|
|
(void) role;
|
|
|
|
gw->g.flags |= GBUTTON_FLG_PRESSED;
|
2014-05-21 03:02:00 +00:00
|
|
|
_gwinUpdate((GHandle)gw);
|
2013-07-05 15:45:24 +00:00
|
|
|
// Trigger the event on button down (different than for mouse/touch)
|
2014-08-20 02:18:27 +00:00
|
|
|
_gwinSendEvent(&gw->g, GEVENT_GWIN_BUTTON);
|
2013-07-05 15:45:24 +00:00
|
|
|
}
|
2013-03-02 12:20:57 +00:00
|
|
|
|
2018-11-03 00:51:23 +00:00
|
|
|
static void ButtonToggleAssign(GWidgetObject *gw, gU16 role, gU16 instance) {
|
2013-07-05 15:45:24 +00:00
|
|
|
(void) role;
|
|
|
|
((GButtonObject *)gw)->toggle = instance;
|
|
|
|
}
|
2013-03-10 06:15:49 +00:00
|
|
|
|
2018-11-03 00:51:23 +00:00
|
|
|
static gU16 ButtonToggleGet(GWidgetObject *gw, gU16 role) {
|
2013-07-05 15:45:24 +00:00
|
|
|
(void) role;
|
|
|
|
return ((GButtonObject *)gw)->toggle;
|
|
|
|
}
|
|
|
|
#endif
|
2013-06-10 07:18:01 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
// The button VMT table
|
|
|
|
static const gwidgetVMT buttonVMT = {
|
|
|
|
{
|
|
|
|
"Button", // The classname
|
|
|
|
sizeof(GButtonObject), // The object size
|
|
|
|
_gwidgetDestroy, // The destroy routine
|
|
|
|
_gwidgetRedraw, // The redraw routine
|
|
|
|
0, // The after-clear routine
|
|
|
|
},
|
2014-05-01 03:57:44 +00:00
|
|
|
gwinButtonDraw_Normal, // The default drawing routine
|
2013-07-05 15:45:24 +00:00
|
|
|
#if GINPUT_NEED_MOUSE
|
|
|
|
{
|
2015-06-08 04:14:40 +00:00
|
|
|
ButtonMouseDown, // Process mouse down events
|
|
|
|
ButtonMouseUp, // Process mouse up events
|
2013-07-05 15:45:24 +00:00
|
|
|
0, // Process mouse move events (NOT USED)
|
|
|
|
},
|
|
|
|
#endif
|
2015-08-16 14:18:54 +00:00
|
|
|
#if GINPUT_NEED_KEYBOARD || GWIN_NEED_KEYBOARD
|
2015-08-12 15:32:38 +00:00
|
|
|
{
|
2015-08-16 04:30:25 +00:00
|
|
|
ButtonKeyboard // Process keyboard events
|
2015-08-12 15:32:38 +00:00
|
|
|
},
|
|
|
|
#endif
|
2013-07-05 15:45:24 +00:00
|
|
|
#if GINPUT_NEED_TOGGLE
|
|
|
|
{
|
|
|
|
1, // 1 toggle role
|
2015-06-08 04:14:40 +00:00
|
|
|
ButtonToggleAssign, // Assign Toggles
|
|
|
|
ButtonToggleGet, // Get Toggles
|
|
|
|
ButtonToggleOff, // Process toggle off events
|
|
|
|
ButtonToggleOn, // Process toggle on events
|
2013-07-05 15:45:24 +00:00
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#if GINPUT_NEED_DIAL
|
|
|
|
{
|
|
|
|
0, // No dial roles
|
|
|
|
0, // Assign Dials (NOT USED)
|
|
|
|
0, // Get Dials (NOT USED)
|
|
|
|
0, // Process dial move events (NOT USED)
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
};
|
2013-06-10 07:18:01 +00:00
|
|
|
|
2013-10-24 08:36:11 +00:00
|
|
|
GHandle gwinGButtonCreate(GDisplay *g, GButtonObject *gw, const GWidgetInit *pInit) {
|
|
|
|
if (!(gw = (GButtonObject *)_gwidgetCreate(g, &gw->w, pInit, &buttonVMT)))
|
2013-06-06 04:33:32 +00:00
|
|
|
return 0;
|
2013-03-10 06:15:49 +00:00
|
|
|
|
2013-07-05 15:45:24 +00:00
|
|
|
#if GINPUT_NEED_TOGGLE
|
|
|
|
gw->toggle = GWIDGET_NO_INSTANCE;
|
|
|
|
#endif
|
2013-06-24 12:58:37 +00:00
|
|
|
gwinSetVisible((GHandle)gw, pInit->g.show);
|
2013-06-06 04:33:32 +00:00
|
|
|
return (GHandle)gw;
|
2013-03-10 06:15:49 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
gBool gwinButtonIsPressed(GHandle gh) {
|
2013-06-06 04:33:32 +00:00
|
|
|
if (gh->vmt != (gwinVMT *)&buttonVMT)
|
2018-06-23 03:02:07 +00:00
|
|
|
return gFalse;
|
2013-03-10 06:15:49 +00:00
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
return (gh->flags & GBUTTON_FLG_PRESSED) ? gTrue : gFalse;
|
2013-03-10 06:15:49 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
/*----------------------------------------------------------
|
|
|
|
* Custom Draw Routines
|
|
|
|
*----------------------------------------------------------*/
|
2013-05-20 05:01:20 +00:00
|
|
|
|
2015-06-08 04:14:40 +00:00
|
|
|
static const GColorSet *getButtonColors(GWidgetObject *gw) {
|
2014-05-09 15:11:30 +00:00
|
|
|
if (!(gw->g.flags & GWIN_FLG_SYSENABLED)) return &gw->pstyle->disabled;
|
2013-07-07 09:40:37 +00:00
|
|
|
if ((gw->g.flags & GBUTTON_FLG_PRESSED)) return &gw->pstyle->pressed;
|
|
|
|
return &gw->pstyle->enabled;
|
2013-05-20 05:01:20 +00:00
|
|
|
}
|
|
|
|
|
2014-05-01 03:57:44 +00:00
|
|
|
#if GWIN_FLAT_STYLING
|
|
|
|
void gwinButtonDraw_Normal(GWidgetObject *gw, void *param) {
|
|
|
|
const GColorSet * pcol;
|
2015-11-08 21:36:59 +00:00
|
|
|
|
2014-05-01 03:57:44 +00:00
|
|
|
(void) param;
|
2013-03-10 06:15:49 +00:00
|
|
|
|
2014-05-01 03:57:44 +00:00
|
|
|
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
|
2015-06-08 04:14:40 +00:00
|
|
|
pcol = getButtonColors(gw);
|
2014-05-01 03:57:44 +00:00
|
|
|
|
2018-07-08 02:19:30 +00:00
|
|
|
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->text, gw->g.font, pcol->text, pcol->fill, gJustifyCenter);
|
2014-05-01 03:57:44 +00:00
|
|
|
gdispGDrawLine(gw->g.display, 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);
|
|
|
|
gdispGDrawLine(gw->g.display, 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);
|
2015-10-19 05:19:42 +00:00
|
|
|
|
|
|
|
// Render highlighted border if focused
|
|
|
|
_gwidgetDrawFocusRect(gw, 1, 1, gw->g.width-2, gw->g.height-2);
|
2014-05-01 03:57:44 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
void gwinButtonDraw_Normal(GWidgetObject *gw, void *param) {
|
|
|
|
const GColorSet * pcol;
|
|
|
|
fixed alpha;
|
|
|
|
fixed dalpha;
|
2018-07-08 00:54:19 +00:00
|
|
|
gCoord i;
|
2018-07-08 01:19:43 +00:00
|
|
|
gColor tcol, bcol;
|
2015-11-08 21:36:59 +00:00
|
|
|
|
2014-05-01 03:57:44 +00:00
|
|
|
(void) param;
|
|
|
|
|
|
|
|
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
|
2015-06-08 04:14:40 +00:00
|
|
|
pcol = getButtonColors(gw);
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2014-05-01 03:57:44 +00:00
|
|
|
/* Fill the box blended from variants of the fill color */
|
2018-03-10 10:36:12 +00:00
|
|
|
tcol = gdispBlendColor(GFX_WHITE, pcol->fill, BTN_TOP_FADE);
|
|
|
|
bcol = gdispBlendColor(GFX_BLACK, pcol->fill, BTN_BOTTOM_FADE);
|
2014-05-01 03:57:44 +00:00
|
|
|
dalpha = FIXED(255)/gw->g.height;
|
|
|
|
for(alpha = 0, i = 0; i < gw->g.height; i++, alpha += dalpha)
|
|
|
|
gdispGDrawLine(gw->g.display, gw->g.x, gw->g.y+i, gw->g.x+gw->g.width-2, gw->g.y+i, gdispBlendColor(bcol, tcol, NONFIXED(alpha)));
|
|
|
|
|
2018-07-08 02:19:30 +00:00
|
|
|
gdispGDrawStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->text, gw->g.font, pcol->text, gJustifyCenter);
|
2014-05-01 03:57:44 +00:00
|
|
|
gdispGDrawLine(gw->g.display, 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);
|
|
|
|
gdispGDrawLine(gw->g.display, 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);
|
2015-10-19 05:19:42 +00:00
|
|
|
|
|
|
|
// Render highlighted border if focused
|
|
|
|
_gwidgetDrawFocusRect(gw, 0, 0, gw->g.width-1, gw->g.height-1);
|
2014-05-01 03:57:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-03-10 06:15:49 +00:00
|
|
|
|
2013-03-02 12:20:57 +00:00
|
|
|
#if GDISP_NEED_ARC
|
2013-06-06 04:33:32 +00:00
|
|
|
void gwinButtonDraw_Rounded(GWidgetObject *gw, void *param) {
|
2013-07-07 09:40:37 +00:00
|
|
|
const GColorSet * pcol;
|
2015-11-08 21:36:59 +00:00
|
|
|
|
2013-07-07 09:40:37 +00:00
|
|
|
(void) param;
|
2013-06-06 04:33:32 +00:00
|
|
|
|
|
|
|
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
|
2015-06-08 04:14:40 +00:00
|
|
|
pcol = getButtonColors(gw);
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2013-10-24 08:36:11 +00:00
|
|
|
gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->background);
|
2015-06-08 04:14:40 +00:00
|
|
|
if (gw->g.width >= 2*BTN_CNR_SIZE+10) {
|
|
|
|
gdispGFillRoundedBox(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, BTN_CNR_SIZE-1, pcol->fill);
|
2018-07-08 02:19:30 +00:00
|
|
|
gdispGDrawStringBox(gw->g.display, gw->g.x+1, gw->g.y+BTN_CNR_SIZE, gw->g.width-2, gw->g.height-(2*BTN_CNR_SIZE), gw->text, gw->g.font, pcol->text, gJustifyCenter);
|
2015-06-08 04:14:40 +00:00
|
|
|
gdispGDrawRoundedBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, BTN_CNR_SIZE, pcol->edge);
|
2013-03-10 06:15:49 +00:00
|
|
|
} else {
|
2018-07-08 02:19:30 +00:00
|
|
|
gdispGFillStringBox(gw->g.display, 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, gJustifyCenter);
|
2013-10-24 08:36:11 +00:00
|
|
|
gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge);
|
2013-03-02 12:20:57 +00:00
|
|
|
}
|
2013-03-10 06:15:49 +00:00
|
|
|
}
|
2013-03-02 12:20:57 +00:00
|
|
|
#endif
|
2013-03-10 06:15:49 +00:00
|
|
|
|
2013-03-02 12:20:57 +00:00
|
|
|
#if GDISP_NEED_ELLIPSE
|
2013-06-06 04:33:32 +00:00
|
|
|
void gwinButtonDraw_Ellipse(GWidgetObject *gw, void *param) {
|
2013-07-07 09:40:37 +00:00
|
|
|
const GColorSet * pcol;
|
2015-11-08 21:36:59 +00:00
|
|
|
|
2013-07-07 09:40:37 +00:00
|
|
|
(void) param;
|
2013-06-06 04:33:32 +00:00
|
|
|
|
|
|
|
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
|
2015-06-08 04:14:40 +00:00
|
|
|
pcol = getButtonColors(gw);
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2013-10-24 08:36:11 +00:00
|
|
|
gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->background);
|
2016-07-13 23:26:44 +00:00
|
|
|
gdispGFillEllipse(gw->g.display, gw->g.x+gw->g.width/2, gw->g.y+gw->g.height/2, gw->g.width/2-2, gw->g.height/2-2, pcol->fill);
|
2018-07-08 02:19:30 +00:00
|
|
|
gdispGDrawStringBox(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, gJustifyCenter);
|
2016-07-13 23:26:44 +00:00
|
|
|
gdispGDrawEllipse(gw->g.display, gw->g.x+gw->g.width/2, gw->g.y+gw->g.height/2, gw->g.width/2-1, gw->g.height/2-1, pcol->edge);
|
2013-03-10 06:15:49 +00:00
|
|
|
}
|
2013-03-02 12:20:57 +00:00
|
|
|
#endif
|
2013-03-10 06:15:49 +00:00
|
|
|
|
|
|
|
#if GDISP_NEED_CONVEX_POLYGON
|
2013-06-06 04:33:32 +00:00
|
|
|
void gwinButtonDraw_ArrowUp(GWidgetObject *gw, void *param) {
|
2013-07-07 09:40:37 +00:00
|
|
|
const GColorSet * pcol;
|
2018-07-08 00:43:30 +00:00
|
|
|
gPoint arw[7];
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-11-08 21:36:59 +00:00
|
|
|
(void) param;
|
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
|
2015-06-08 04:14:40 +00:00
|
|
|
pcol = getButtonColors(gw);
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-02-14 04:20:45 +00:00
|
|
|
// Create the arrow polygon
|
|
|
|
arw[0].x = (gw->g.width-1)/2; // Point center
|
|
|
|
arw[0].y = 0; // Arrow start
|
|
|
|
arw[3].y = gw->g.height-1; // Arrow end
|
2015-06-08 04:14:40 +00:00
|
|
|
#if BTN_ARROWHEAD_DIV == 0
|
2015-02-14 04:20:45 +00:00
|
|
|
if (gw->g.height <= arw[0].x) {
|
|
|
|
arw[1].y = arw[3].y; // End of head
|
|
|
|
arw[1].x = arw[0].x+arw[3].y; // Width of head (side 1)
|
|
|
|
arw[2].x = arw[1].x; // Width of shaft (side 1)
|
|
|
|
arw[4].x = arw[0].x-arw[3].y; // Width of head (side 2)
|
|
|
|
arw[6].x = arw[4].x; // Width of shaft (side 2)
|
|
|
|
} else {
|
|
|
|
arw[1].y = arw[0].x;
|
|
|
|
arw[1].x = arw[0].x << 1;
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[2].x = arw[0].x + arw[0].x/BTN_ARROWBODY_DIV;
|
|
|
|
arw[4].x = arw[0].x - arw[0].x/BTN_ARROWBODY_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[6].x = 0;
|
|
|
|
}
|
|
|
|
#else
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[1].y = gw->g.height/BTN_ARROWHEAD_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[1].x = arw[0].x << 1;
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[2].x = arw[0].x + arw[0].x/BTN_ARROWBODY_DIV;
|
|
|
|
arw[4].x = arw[0].x - arw[0].x/BTN_ARROWBODY_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[6].x = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Fill in the rest from the special points
|
|
|
|
/* arw[0].x set */ /* arw[0].y set */
|
|
|
|
/* arw[1].x set */ /* arw[1].y set */
|
|
|
|
/* arw[2].x set */ arw[2].y = arw[1].y;
|
|
|
|
arw[3].x = arw[2].x; /* arw[3].y set */
|
|
|
|
/* arw[4].x set */ arw[4].y = arw[3].y;
|
|
|
|
arw[5].x = arw[4].x; arw[5].y = arw[1].y;
|
|
|
|
/* arw[6].x set */ arw[6].y = arw[1].y;
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-02-14 04:20:45 +00:00
|
|
|
// Draw
|
2013-10-24 08:36:11 +00:00
|
|
|
gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->background);
|
|
|
|
gdispGFillConvexPoly(gw->g.display, gw->g.x, gw->g.y, arw, 7, pcol->fill);
|
|
|
|
gdispGDrawPoly(gw->g.display, gw->g.x, gw->g.y, arw, 7, pcol->edge);
|
2018-07-08 02:19:30 +00:00
|
|
|
gdispGDrawStringBox(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, gJustifyCenter);
|
2013-03-02 12:20:57 +00:00
|
|
|
}
|
2013-03-10 06:15:49 +00:00
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
void gwinButtonDraw_ArrowDown(GWidgetObject *gw, void *param) {
|
2013-07-07 09:40:37 +00:00
|
|
|
const GColorSet * pcol;
|
2018-07-08 00:43:30 +00:00
|
|
|
gPoint arw[7];
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-11-08 21:36:59 +00:00
|
|
|
(void) param;
|
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
|
2015-06-08 04:14:40 +00:00
|
|
|
pcol = getButtonColors(gw);
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-02-14 04:20:45 +00:00
|
|
|
// Create the arrow polygon
|
|
|
|
arw[0].x = (gw->g.width-1)/2; // Point center
|
|
|
|
arw[0].y = gw->g.height-1; // Arrow start
|
|
|
|
arw[3].y = 0; // Arrow end
|
2015-06-08 04:14:40 +00:00
|
|
|
#if BTN_ARROWHEAD_DIV == 0
|
2015-02-14 04:20:45 +00:00
|
|
|
if (gw->g.height <= arw[0].x) {
|
|
|
|
arw[1].y = arw[3].y; // End of head
|
|
|
|
arw[1].x = arw[0].x+arw[0].y; // Width of head (side 1)
|
|
|
|
arw[2].x = arw[1].x; // Width of shaft (side 1)
|
|
|
|
arw[4].x = arw[0].x-arw[0].y; // Width of head (side 2)
|
|
|
|
arw[6].x = arw[4].x; // Width of shaft (side 2)
|
|
|
|
} else {
|
|
|
|
arw[1].y = arw[0].y - arw[0].x;
|
|
|
|
arw[1].x = arw[0].x << 1;
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[2].x = arw[0].x + arw[0].x/BTN_ARROWBODY_DIV;
|
|
|
|
arw[4].x = arw[0].x - arw[0].x/BTN_ARROWBODY_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[6].x = 0;
|
|
|
|
}
|
|
|
|
#else
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[1].y = arw[0].y - gw->g.height/BTN_ARROWHEAD_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[1].x = arw[0].x << 1;
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[2].x = arw[0].x + arw[0].x/BTN_ARROWBODY_DIV;
|
|
|
|
arw[4].x = arw[0].x - arw[0].x/BTN_ARROWBODY_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[6].x = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Fill in the rest from the special points
|
|
|
|
/* arw[0].x set */ /* arw[0].y set */
|
|
|
|
/* arw[1].x set */ /* arw[1].y set */
|
|
|
|
/* arw[2].x set */ arw[2].y = arw[1].y;
|
|
|
|
arw[3].x = arw[2].x; /* arw[3].y set */
|
|
|
|
/* arw[4].x set */ arw[4].y = arw[3].y;
|
|
|
|
arw[5].x = arw[4].x; arw[5].y = arw[1].y;
|
|
|
|
/* arw[6].x set */ arw[6].y = arw[1].y;
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-02-14 04:20:45 +00:00
|
|
|
// Draw
|
2013-10-24 08:36:11 +00:00
|
|
|
gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->background);
|
|
|
|
gdispGFillConvexPoly(gw->g.display, gw->g.x, gw->g.y, arw, 7, pcol->fill);
|
|
|
|
gdispGDrawPoly(gw->g.display, gw->g.x, gw->g.y, arw, 7, pcol->edge);
|
2018-07-08 02:19:30 +00:00
|
|
|
gdispGDrawStringBox(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, gJustifyCenter);
|
2013-03-10 06:15:49 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
void gwinButtonDraw_ArrowLeft(GWidgetObject *gw, void *param) {
|
2013-07-07 09:40:37 +00:00
|
|
|
const GColorSet * pcol;
|
2018-07-08 00:43:30 +00:00
|
|
|
gPoint arw[7];
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-11-08 21:36:59 +00:00
|
|
|
(void) param;
|
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
|
2015-06-08 04:14:40 +00:00
|
|
|
pcol = getButtonColors(gw);
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-02-14 04:20:45 +00:00
|
|
|
// Create the arrow polygon
|
|
|
|
arw[0].y = (gw->g.height-1)/2; // Point center
|
|
|
|
arw[0].x = 0; // Arrow start
|
|
|
|
arw[3].x = gw->g.width-1; // Arrow end
|
2015-06-08 04:14:40 +00:00
|
|
|
#if BTN_ARROWHEAD_DIV == 0
|
2015-02-14 04:20:45 +00:00
|
|
|
if (gw->g.width <= arw[0].y) {
|
|
|
|
arw[1].x = arw[3].x; // End of head
|
|
|
|
arw[1].y = arw[0].y+arw[3].x; // Width of head (side 1)
|
|
|
|
arw[2].y = arw[1].y; // Width of shaft (side 1)
|
|
|
|
arw[4].y = arw[0].y-arw[3].x; // Width of head (side 2)
|
|
|
|
arw[6].y = arw[4].y; // Width of shaft (side 2)
|
|
|
|
} else {
|
|
|
|
arw[1].x = arw[0].y;
|
|
|
|
arw[1].y = arw[0].y << 1;
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[2].y = arw[0].y + arw[0].y/BTN_ARROWBODY_DIV;
|
|
|
|
arw[4].y = arw[0].y - arw[0].y/BTN_ARROWBODY_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[6].y = 0;
|
|
|
|
}
|
|
|
|
#else
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[1].x = gw->g.width/BTN_ARROWHEAD_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[1].y = arw[0].y << 1;
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[2].y = arw[0].y + arw[0].y/BTN_ARROWBODY_DIV;
|
|
|
|
arw[4].y = arw[0].y - arw[0].y/BTN_ARROWBODY_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[6].y = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Fill in the rest from the special points
|
|
|
|
/* arw[0].x set */ /* arw[0].y set */
|
|
|
|
/* arw[1].x set */ /* arw[1].y set */
|
|
|
|
arw[2].x = arw[1].x; /* arw[2].y set */
|
|
|
|
/* arw[3].y set */ arw[3].y = arw[2].y;
|
|
|
|
arw[4].x = arw[3].x; /* arw[4].y set */
|
|
|
|
arw[5].x = arw[1].x; arw[5].y = arw[4].y;
|
|
|
|
arw[6].x = arw[1].x; /* arw[6].y set */
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-02-14 04:20:45 +00:00
|
|
|
// Draw
|
2013-10-24 08:36:11 +00:00
|
|
|
gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->background);
|
|
|
|
gdispGFillConvexPoly(gw->g.display, gw->g.x, gw->g.y, arw, 7, pcol->fill);
|
|
|
|
gdispGDrawPoly(gw->g.display, gw->g.x, gw->g.y, arw, 7, pcol->edge);
|
2018-07-08 02:19:30 +00:00
|
|
|
gdispGDrawStringBox(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, gJustifyCenter);
|
2013-03-10 06:15:49 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
void gwinButtonDraw_ArrowRight(GWidgetObject *gw, void *param) {
|
2013-07-07 09:40:37 +00:00
|
|
|
const GColorSet * pcol;
|
2018-07-08 00:43:30 +00:00
|
|
|
gPoint arw[7];
|
2015-11-08 21:36:59 +00:00
|
|
|
|
|
|
|
(void) param;
|
2013-06-06 04:33:32 +00:00
|
|
|
|
|
|
|
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
|
2015-06-08 04:14:40 +00:00
|
|
|
pcol = getButtonColors(gw);
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-02-14 04:20:45 +00:00
|
|
|
// Create the arrow polygon
|
|
|
|
arw[0].y = (gw->g.height-1)/2; // Point center
|
|
|
|
arw[0].x = gw->g.width-1; // Arrow start
|
|
|
|
arw[3].x = 0; // Arrow end
|
2015-06-08 04:14:40 +00:00
|
|
|
#if BTN_ARROWHEAD_DIV == 0
|
2015-02-14 04:20:45 +00:00
|
|
|
if (gw->g.width <= arw[0].y) {
|
|
|
|
arw[1].x = arw[3].x; // End of head
|
|
|
|
arw[1].y = arw[0].y+arw[0].x; // Width of head (side 1)
|
|
|
|
arw[2].y = arw[1].y; // Width of shaft (side 1)
|
|
|
|
arw[4].y = arw[0].y-arw[0].x; // Width of head (side 2)
|
|
|
|
arw[6].y = arw[4].y; // Width of shaft (side 2)
|
|
|
|
} else {
|
|
|
|
arw[1].x = arw[0].x - arw[0].y;
|
|
|
|
arw[1].y = arw[0].y << 1;
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[2].y = arw[0].y + arw[0].y/BTN_ARROWBODY_DIV;
|
|
|
|
arw[4].y = arw[0].y - arw[0].y/BTN_ARROWBODY_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[6].y = 0;
|
|
|
|
}
|
|
|
|
#else
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[1].x = arw[0].x - gw->g.width/BTN_ARROWHEAD_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[1].y = arw[0].y << 1;
|
2015-06-08 04:14:40 +00:00
|
|
|
arw[2].y = arw[0].y + arw[0].y/BTN_ARROWBODY_DIV;
|
|
|
|
arw[4].y = arw[0].y - arw[0].y/BTN_ARROWBODY_DIV;
|
2015-02-14 04:20:45 +00:00
|
|
|
arw[6].y = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Fill in the rest from the special points
|
|
|
|
/* arw[0].x set */ /* arw[0].y set */
|
|
|
|
/* arw[1].x set */ /* arw[1].y set */
|
|
|
|
arw[2].x = arw[1].x; /* arw[2].y set */
|
|
|
|
/* arw[3].y set */ arw[3].y = arw[2].y;
|
|
|
|
arw[4].x = arw[3].x; /* arw[4].y set */
|
|
|
|
arw[5].x = arw[1].x; arw[5].y = arw[4].y;
|
|
|
|
arw[6].x = arw[1].x; /* arw[6].y set */
|
2013-06-06 04:33:32 +00:00
|
|
|
|
2015-02-14 04:20:45 +00:00
|
|
|
// Draw
|
2013-10-24 08:36:11 +00:00
|
|
|
gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->pstyle->background);
|
|
|
|
gdispGFillConvexPoly(gw->g.display, gw->g.x, gw->g.y, arw, 7, pcol->fill);
|
|
|
|
gdispGDrawPoly(gw->g.display, gw->g.x, gw->g.y, arw, 7, pcol->edge);
|
2018-07-08 02:19:30 +00:00
|
|
|
gdispGDrawStringBox(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, gJustifyCenter);
|
2013-03-10 06:15:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-03-02 12:20:57 +00:00
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
#if GDISP_NEED_IMAGE || defined(__DOXYGEN__)
|
|
|
|
void gwinButtonDraw_Image(GWidgetObject *gw, void *param) {
|
2013-07-07 09:40:37 +00:00
|
|
|
const GColorSet * pcol;
|
2018-07-08 00:54:19 +00:00
|
|
|
gCoord sy;
|
2013-04-07 06:02:10 +00:00
|
|
|
|
2013-06-06 04:33:32 +00:00
|
|
|
if (gw->g.vmt != (gwinVMT *)&buttonVMT) return;
|
2015-06-08 04:14:40 +00:00
|
|
|
pcol = getButtonColors(gw);
|
2013-03-02 12:20:57 +00:00
|
|
|
|
2014-05-09 15:11:30 +00:00
|
|
|
if (!(gw->g.flags & GWIN_FLG_SYSENABLED)) {
|
2013-06-06 04:33:32 +00:00
|
|
|
sy = 2 * gw->g.height;
|
|
|
|
} else if ((gw->g.flags & GBUTTON_FLG_PRESSED)) {
|
|
|
|
sy = gw->g.height;
|
|
|
|
} else {
|
|
|
|
sy = 0;
|
|
|
|
}
|
2013-03-02 12:20:57 +00:00
|
|
|
|
2019-04-10 15:33:15 +00:00
|
|
|
gdispGImageDraw(gw->g.display, (gImage *)param, gw->g.x, gw->g.y, gw->g.width, gw->g.height, 0, sy);
|
2018-07-08 02:19:30 +00:00
|
|
|
gdispGDrawStringBox(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, gJustifyCenter);
|
2013-03-02 12:20:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* GFX_USE_GWIN && GWIN_NEED_BUTTON */
|