Added progressbar widget (demos still to do)
This commit is contained in:
parent
3c3b6967d1
commit
560f946cd9
91
demos/modules/gwin/progressbar/gfxconf.h
Normal file
91
demos/modules/gwin/progressbar/gfxconf.h
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||
* Copyright (c) 2012, 2013, Andrew Hannam aka inmarket
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the <organization> nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _GFXCONF_H
|
||||
#define _GFXCONF_H
|
||||
|
||||
//#define GFX_USE_OS_CHIBIOS TRUE
|
||||
//#define GFX_USE_OS_WIN32 TRUE
|
||||
//#define GFX_USE_OS_LINUX TRUE
|
||||
|
||||
/* GFX sub-systems to turn on */
|
||||
#define GFX_USE_GDISP TRUE
|
||||
#define GFX_USE_GWIN TRUE
|
||||
#define GFX_USE_GEVENT TRUE
|
||||
#define GFX_USE_GTIMER TRUE
|
||||
#define GFX_USE_GINPUT TRUE
|
||||
|
||||
/* Features for the GDISP sub-system. */
|
||||
#define GDISP_NEED_VALIDATION TRUE
|
||||
#define GDISP_NEED_CLIP TRUE
|
||||
#define GDISP_NEED_TEXT TRUE
|
||||
#define GDISP_NEED_CIRCLE TRUE
|
||||
#define GDISP_NEED_ELLIPSE FALSE
|
||||
#define GDISP_NEED_ARC FALSE
|
||||
#define GDISP_NEED_CONVEX_POLYGON TRUE
|
||||
#define GDISP_NEED_SCROLL TRUE
|
||||
#define GDISP_NEED_PIXELREAD FALSE
|
||||
#define GDISP_NEED_CONTROL FALSE
|
||||
#define GDISP_NEED_IMAGE TRUE
|
||||
#define GDISP_NEED_MULTITHREAD TRUE
|
||||
#define GDISP_NEED_ASYNC FALSE
|
||||
#define GDISP_NEED_MSGAPI FALSE
|
||||
|
||||
/* Builtin Fonts */
|
||||
#define GDISP_INCLUDE_FONT_UI2 TRUE
|
||||
#define GDISP_NEED_ANTIALIAS FALSE
|
||||
|
||||
/* GDISP image decoders */
|
||||
#define GDISP_NEED_IMAGE_NATIVE FALSE
|
||||
#define GDISP_NEED_IMAGE_GIF TRUE
|
||||
#define GDISP_NEED_IMAGE_BMP FALSE
|
||||
#define GDISP_NEED_IMAGE_JPG FALSE
|
||||
#define GDISP_NEED_IMAGE_PNG FALSE
|
||||
|
||||
/* Features for the GWIN sub-system. */
|
||||
#define GWIN_NEED_WINDOWMANAGER TRUE
|
||||
#define GWIN_NEED_CONSOLE FALSE
|
||||
#define GWIN_NEED_GRAPH FALSE
|
||||
#define GWIN_NEED_WIDGET TRUE
|
||||
#define GWIN_NEED_BUTTON FALSE
|
||||
#define GWIN_NEED_SLIDER FALSE
|
||||
#define GWIN_NEED_CHECKBOX FALSE
|
||||
#define GWIN_NEED_LABEL FALSE
|
||||
#define GWIN_NEED_IMAGE FALSE
|
||||
#define GWIN_NEED_RADIO FALSE
|
||||
#define GWIN_NEED_LIST FALSE
|
||||
#define GWIN_NEED_IMAGE_ANIMATION FALSE
|
||||
#define GWIN_NEED_LIST_IMAGES FALSE
|
||||
#define GWIN_NEED_PROGRESSBAR TRUE
|
||||
|
||||
/* Features for the GINPUT sub-system. */
|
||||
#define GINPUT_NEED_MOUSE TRUE
|
||||
#define GINPUT_NEED_TOGGLE FALSE
|
||||
#define GINPUT_NEED_DIAL FALSE
|
||||
|
||||
#endif /* _GFXCONF_H */
|
39
demos/modules/gwin/progressbar/main.c
Normal file
39
demos/modules/gwin/progressbar/main.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include "gfx.h"
|
||||
|
||||
GHandle ghProgressbar;
|
||||
|
||||
static void _createWidget(void) {
|
||||
GWidgetInit wi;
|
||||
|
||||
wi.customDraw = 0;
|
||||
wi.customParam = 0;
|
||||
wi.customStyle = 0;
|
||||
wi.g.show = TRUE;
|
||||
|
||||
wi.g.y = 10; wi.g.x = 10; wi.g.width = 200; wi.g.height = 20; wi.text = "Progress 1";
|
||||
ghProgressbar = gwinProgressbarCreate(NULL, &wi);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
gfxInit();
|
||||
|
||||
gwinSetDefaultFont(gdispOpenFont("UI2"));
|
||||
gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
|
||||
gdispClear(White);
|
||||
|
||||
_createWidget();
|
||||
|
||||
gwinProgressbarSetResolution(ghProgressbar, 10);
|
||||
gwinProgressbarStart(ghProgressbar, 500);
|
||||
|
||||
//gwinProgressbarSetPosition(ghProgressbar, 42);
|
||||
//gwinProgressbarIncrement(ghProgressbar);
|
||||
//gwinProgressbarDecrement(ghProgressbar);
|
||||
|
||||
while (1) {
|
||||
gfxSleepMilliseconds(500);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -111,6 +111,7 @@
|
||||
#define GWIN_NEED_IMAGE FALSE
|
||||
#define GWIN_NEED_RADIO FALSE
|
||||
#define GWIN_NEED_LIST FALSE
|
||||
#define GWIN_NEED_PROGRESSBAR FALSE
|
||||
|
||||
/* Features for the GEVENT subsystem. */
|
||||
#define GEVENT_ASSERT_NO_RESOURCE FALSE
|
||||
|
@ -300,5 +300,9 @@ bool_t gwinAttachListener(GListener *pl);
|
||||
#include "gwin/list.h"
|
||||
#endif
|
||||
|
||||
#if GWIN_NEED_PROGRESSBAR || defined(__DOXYGEN__)
|
||||
#include "gwin/progressbar.h"
|
||||
#endif
|
||||
|
||||
#endif /* _GWIDGET_H */
|
||||
/** @} */
|
||||
|
188
include/gwin/progressbar.h
Normal file
188
include/gwin/progressbar.h
Normal file
@ -0,0 +1,188 @@
|
||||
/*
|
||||
* This file is subject to the terms of the GFX License. If a copy of
|
||||
* the license was not distributed with this file, you can obtain one at:
|
||||
*
|
||||
* http://ugfx.org/license.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file include/gwin/progressbar.h
|
||||
* @brief GWIN Graphic window subsystem header file.
|
||||
*
|
||||
* @defgroup Progressbar Progressbar
|
||||
* @ingroup GWIN
|
||||
*
|
||||
* @details Create progressbars with different styles
|
||||
*
|
||||
* @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h
|
||||
* @pre GWIN_NEED_PROGRESSBAR must be set to TRUE in your gfxconf.h
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _GWIN_PROGRESSBAR_H
|
||||
#define _GWIN_PROGRESSBAR_H
|
||||
|
||||
// A progressbar window
|
||||
typedef struct GProgressbarObject {
|
||||
GWidgetObject w;
|
||||
coord_t dpos;
|
||||
int min;
|
||||
int max;
|
||||
int res;
|
||||
int pos;
|
||||
#if GFX_USE_GTIMER
|
||||
GTimer gt;
|
||||
delaytime_t delay;
|
||||
#endif
|
||||
} GProgressbarObject;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Create a progressbar window.
|
||||
* @return NULL if there is no resultant drawing area, otherwise a window handle.
|
||||
*
|
||||
* @param[in] g The GDisplay to display this window on
|
||||
* @param[in] gb The GProgressbarObject structure to initialise. If this is NULL the structure is dynamically allocated.
|
||||
* @param[in] pInit The initialization parameters to use
|
||||
*
|
||||
* @note The drawing color and the background color get set to the current defaults. If you haven't called
|
||||
* @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively.
|
||||
* @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there
|
||||
* is no default font and text drawing operations will no nothing.
|
||||
* @note A progressbar remembers its normal drawing state. If there is a window manager then it is automatically
|
||||
* redrawn if the window is moved or its visibility state is changed.
|
||||
* @note The initial progressbar range is from 0 to 100 with an initial position of 0.
|
||||
* @note A progressbar does not take any GINPUT inputs.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
GHandle gwinGProgressbarCreate(GDisplay *g, GProgressbarObject *gb, const GWidgetInit *pInit);
|
||||
#define gwinProgressbarCreate(w, pInit) gwinGProgressbarCreate(GDISP, w, pInit)
|
||||
|
||||
/**
|
||||
* @brief Set the progressbar range.
|
||||
*
|
||||
* @param[in] gh The window handle (must be a progressbar window)
|
||||
* @param[in] min The minimum value
|
||||
* @param[in] max The maximum value
|
||||
*
|
||||
* @note The defaults are 0 and 100
|
||||
* @note Sets the position to the minimum value.
|
||||
* @note The progressbar is not automatically drawn. Call gwinProgressbarDraw() after changing the range.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void gwinProgressbarSetRange(GHandle gh, int min, int max);
|
||||
|
||||
/**
|
||||
* @brief Set the progressbar position.
|
||||
*
|
||||
* @param[in] gh The window handle (must be a progressbar window)
|
||||
* @param[in] pos The new position
|
||||
*
|
||||
* @note If the new position is outside the progressbar range then the position
|
||||
* is set to the closest end of the range.
|
||||
* @note The progressbar is not automatically drawn. Call gwinProgressbarDraw() after changing the position.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void gwinProgressbarSetPosition(GHandle gh, int pos);
|
||||
|
||||
/**
|
||||
* @brief Set the resolution for the incrementation and decrementation of the progressbar
|
||||
*
|
||||
* @note Default is set to 1
|
||||
*
|
||||
* @param[in] gh The window handle (must be a progressbar window)
|
||||
* @param[in] res The resolution to be set
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void gwinProgressbarSetResolution(GHandle gh, int res);
|
||||
|
||||
/**
|
||||
* @brief Increment the progressbar value
|
||||
*
|
||||
* @details Increments by the resolution set through gwinProgressbarSetResolution()
|
||||
*
|
||||
* @param[in] gh The window handle (must be a progressbar window)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void gwinProgressbarIncrement(GHandle gh);
|
||||
|
||||
/**
|
||||
* @brief Decrement the progressbar value
|
||||
*
|
||||
* @details Decrements by the resolution set through gwinProgressbarSetResolution()
|
||||
*
|
||||
* @param[in] gh The window handle (must be a progressbar window)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void gwinProgressbarDecrement(GHandle gh);
|
||||
|
||||
/**
|
||||
* @brief Get the current progressbar position.
|
||||
* @return The progressbar position
|
||||
*
|
||||
* @param[in] gh The window handle (must be a progressbar window)
|
||||
*
|
||||
* @note The use of a listener to get the progressbar position is recommended if you
|
||||
* want continuous updates on the progressbar position.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
#define gwinProgressbarGetPosition(gh) (((GProgressbarObject *)(gh))->pos)
|
||||
|
||||
/**
|
||||
* @brief Automatically increments the progress bar
|
||||
*
|
||||
* @note The delay is generated using the GTIMER module which is based on software/virtual timer.
|
||||
* Therefore, the delay is totally unprecise.
|
||||
*
|
||||
* @note An even is generated once the maximum value has been reached (ToDo)
|
||||
*
|
||||
* @param[in] gh The window handle (must be a progressbar window)
|
||||
* @param[in] delay The incrementation delay (in milliseconds)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void gwinProgressbarStart(GHandle gh, delaytime_t delay);
|
||||
|
||||
/**
|
||||
* @brief Some custom progressbar drawing routines
|
||||
* @details These function may be passed to @p gwinSetCustomDraw() to get different progressbar drawing styles
|
||||
*
|
||||
* @param[in] gw The widget (which must be a progressbar)
|
||||
* @param[in] param A parameter passed in from the user
|
||||
*
|
||||
* @note In your custom progressbar drawing function you may optionally call this
|
||||
* standard functions and then draw your extra details on top.
|
||||
* @note The standard functions below ignore the param parameter except for @p gwinProgressbarDraw_Image().
|
||||
* @note The image custom draw function @p gwinProgressbarDraw_Image() uses param to pass in the gdispImage pointer.
|
||||
* The image must be already opened before calling @p gwinSetCustomDraw(). The image is tiled to fill
|
||||
* the active area of the progressbar. The normal colors apply to the border and inactive area and the dividing line
|
||||
* between the active and inactive areas.
|
||||
* No checking is done to compare the dimensions of the progressbar 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 gwinProgressbarDraw_Std(GWidgetObject *gw, void *param);
|
||||
void gwinProgressbarDraw_Image(GWidgetObject *gw, void *param);
|
||||
/* @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _GWIN_PROGRESSBAR_H */
|
||||
/** @} */
|
||||
|
@ -10,4 +10,5 @@ GFXSRC += $(GFXLIB)/src/gwin/gwin.c \
|
||||
$(GFXLIB)/src/gwin/label.c \
|
||||
$(GFXLIB)/src/gwin/radio.c \
|
||||
$(GFXLIB)/src/gwin/list.c \
|
||||
$(GFXLIB)/src/gwin/progressbar.c \
|
||||
|
||||
|
294
src/gwin/progressbar.c
Normal file
294
src/gwin/progressbar.c
Normal file
@ -0,0 +1,294 @@
|
||||
/*
|
||||
* This file is subject to the terms of the GFX License. If a copy of
|
||||
* the license was not distributed with this file, you can obtain one at:
|
||||
*
|
||||
* http://ugfx.org/license.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file src/gwin/progressbar.c
|
||||
* @brief GWIN sub-system progressbar code.
|
||||
*
|
||||
* @defgroup Progressbar Progressbar
|
||||
* @ingroup GWIN
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "gfx.h"
|
||||
|
||||
#if (GFX_USE_GWIN && GWIN_NEED_PROGRESSBAR) || defined(__DOXYGEN__)
|
||||
|
||||
#include "gwin/class_gwin.h"
|
||||
|
||||
// Reset the display position back to the value predicted by the saved progressbar position
|
||||
static void ResetDisplayPos(GProgressbarObject *gsw) {
|
||||
if (gsw->w.g.width < gsw->w.g.height)
|
||||
gsw->dpos = gsw->w.g.height-1-((gsw->w.g.height-1)*(gsw->pos-gsw->min))/(gsw->max-gsw->min);
|
||||
else
|
||||
gsw->dpos = ((gsw->w.g.width-1)*(gsw->pos-gsw->min))/(gsw->max-gsw->min);
|
||||
}
|
||||
|
||||
// The progressbar VMT table
|
||||
static const gwidgetVMT progressbarVMT = {
|
||||
{
|
||||
"Progressbar", // The classname
|
||||
sizeof(GProgressbarObject), // The object size
|
||||
_gwidgetDestroy, // The destroy routine
|
||||
_gwidgetRedraw, // The redraw routine
|
||||
0, // The after-clear routine
|
||||
},
|
||||
gwinProgressbarDraw_Std, // The default drawing routine
|
||||
#if GINPUT_NEED_MOUSE
|
||||
{
|
||||
0, // Process mouse down events (NOT USED)
|
||||
0, // Process mouse up events
|
||||
0, // Process mouse move events
|
||||
},
|
||||
#endif
|
||||
#if GINPUT_NEED_TOGGLE
|
||||
{
|
||||
0, // 1 toggle role
|
||||
0, // Assign Toggles
|
||||
0, // Get Toggles
|
||||
0, // Process toggle off events (NOT USED)
|
||||
0, // Process toggle on events
|
||||
},
|
||||
#endif
|
||||
#if GINPUT_NEED_DIAL
|
||||
{
|
||||
0, // 1 dial roles
|
||||
0, // Assign Dials
|
||||
0, // Get Dials
|
||||
0, // Process dial move events
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
GHandle gwinGProgressbarCreate(GDisplay *g, GProgressbarObject *gs, const GWidgetInit *pInit) {
|
||||
if (!(gs = (GProgressbarObject *)_gwidgetCreate(g, &gs->w, pInit, &progressbarVMT)))
|
||||
return 0;
|
||||
|
||||
gs->min = 0;
|
||||
gs->max = 100;
|
||||
gs->res = 1;
|
||||
gs->pos = 0;
|
||||
gs->delay = 0;
|
||||
|
||||
ResetDisplayPos(gs);
|
||||
gwinSetVisible((GHandle)gs, pInit->g.show);
|
||||
|
||||
return (GHandle)gs;
|
||||
}
|
||||
|
||||
void gwinProgressbarSetRange(GHandle gh, int min, int max) {
|
||||
#define gsw ((GProgressbarObject *)gh)
|
||||
|
||||
if (gh->vmt != (gwinVMT *)&progressbarVMT)
|
||||
return;
|
||||
|
||||
if (min == max) // prevent divide by 0 errors.
|
||||
max++;
|
||||
gsw->min = min;
|
||||
gsw->max = max;
|
||||
gsw->pos = min;
|
||||
|
||||
ResetDisplayPos(gsw);
|
||||
|
||||
#undef gsw
|
||||
}
|
||||
|
||||
void gwinProgressbarSetPosition(GHandle gh, int pos) {
|
||||
#define gsw ((GProgressbarObject *)gh)
|
||||
|
||||
if (gh->vmt != (gwinVMT *)&progressbarVMT)
|
||||
return;
|
||||
|
||||
if (gsw->min <= gsw->max) {
|
||||
if (pos < gsw->min) gsw->pos = gsw->min;
|
||||
else if (pos > gsw->max) gsw->pos = gsw->max;
|
||||
else gsw->pos = pos;
|
||||
} else {
|
||||
if (pos > gsw->min) gsw->pos = gsw->min;
|
||||
else if (pos < gsw->max) gsw->pos = gsw->max;
|
||||
else gsw->pos = pos;
|
||||
}
|
||||
|
||||
ResetDisplayPos(gsw);
|
||||
_gwidgetRedraw(gh);
|
||||
|
||||
#undef gsw
|
||||
}
|
||||
|
||||
void gwinProgressbarSetResolution(GHandle gh, int resolution) {
|
||||
#define gsw ((GProgressbarObject *)gh)
|
||||
|
||||
if (gh->vmt != (gwinVMT *)&progressbarVMT)
|
||||
return;
|
||||
|
||||
if (resolution <= 0)
|
||||
resolution = 1;
|
||||
|
||||
gsw->res = resolution;
|
||||
|
||||
#undef gsw
|
||||
}
|
||||
|
||||
void gwinProgressbarIncrement(GHandle gh) {
|
||||
#define gsw ((GProgressbarObject *)gh)
|
||||
|
||||
if (gh->vmt != (gwinVMT *)&progressbarVMT)
|
||||
return;
|
||||
|
||||
if (gsw->max - gsw->pos > gsw->res)
|
||||
gsw->pos += gsw->res;
|
||||
else
|
||||
gsw->pos = gsw->max;
|
||||
|
||||
ResetDisplayPos(gsw);
|
||||
_gwidgetRedraw(gh);
|
||||
|
||||
#undef gsw
|
||||
}
|
||||
|
||||
void gwinProgressbarDecrement(GHandle gh) {
|
||||
#define gsw ((GProgressbarObject *)gh)
|
||||
|
||||
if (gh->vmt != (gwinVMT *)&progressbarVMT)
|
||||
return;
|
||||
|
||||
if (gsw->pos > gsw->res)
|
||||
gsw->pos -= gsw->min;
|
||||
else
|
||||
gsw->pos = gsw->min;
|
||||
|
||||
gsw->pos -= gsw->res;
|
||||
|
||||
ResetDisplayPos(gsw);
|
||||
_gwidgetRedraw(gh);
|
||||
|
||||
#undef gsw
|
||||
}
|
||||
|
||||
// used by gwinProgressbarStart();
|
||||
static void _progressbarCallback(GHandle gh) {
|
||||
#define gsw ((GProgressbarObject *)gh)
|
||||
|
||||
if (gh->vmt != (gwinVMT *)&progressbarVMT)
|
||||
return;
|
||||
|
||||
gwinProgressbarIncrement(gh);
|
||||
|
||||
if (gsw->pos < gsw->max)
|
||||
gtimerStart(&(gsw->gt), _progressbarCallback, gh, FALSE, gsw->delay);
|
||||
|
||||
#undef gsw
|
||||
}
|
||||
|
||||
void gwinProgressbarStart(GHandle gh, delaytime_t delay) {
|
||||
#define gsw ((GProgressbarObject *)gh)
|
||||
|
||||
if (gh->vmt != (gwinVMT *)&progressbarVMT)
|
||||
return;
|
||||
|
||||
gsw->delay = delay;
|
||||
|
||||
gtimerInit(&(gsw->gt));
|
||||
gtimerStart(&(gsw->gt), _progressbarCallback, gh, FALSE, gsw->delay);
|
||||
|
||||
#undef gsw
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------
|
||||
* Custom Draw Routines
|
||||
*----------------------------------------------------------*/
|
||||
|
||||
void gwinProgressbarDraw_Std(GWidgetObject *gw, void *param) {
|
||||
#define gsw ((GProgressbarObject *)gw)
|
||||
const GColorSet * pcol;
|
||||
(void) param;
|
||||
|
||||
if (gw->g.vmt != (gwinVMT *)&progressbarVMT)
|
||||
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 progressbar
|
||||
if (gsw->dpos != gw->g.height-1)
|
||||
gdispGFillArea(gw->g.display, gw->g.x, gw->g.y+gsw->dpos, gw->g.width, gw->g.height - gsw->dpos, pcol->progress); // Active Area
|
||||
if (gsw->dpos != 0)
|
||||
gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gsw->dpos, gw->pstyle->enabled.progress); // Inactive area
|
||||
gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge
|
||||
gdispGDrawLine(gw->g.display, gw->g.x, gw->g.y+gsw->dpos, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos, pcol->edge); // Thumb
|
||||
|
||||
// Horizontal progressbar
|
||||
} else {
|
||||
if (gsw->dpos != gw->g.width-1)
|
||||
gdispGFillArea(gw->g.display, 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)
|
||||
gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, gsw->dpos, gw->g.height, pcol->progress); // Active Area
|
||||
gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge
|
||||
gdispGDrawLine(gw->g.display, gw->g.x+gsw->dpos, gw->g.y, gw->g.x+gsw->dpos, gw->g.y+gw->g.height-1, pcol->edge); // Thumb
|
||||
}
|
||||
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, justifyCenter);
|
||||
|
||||
#undef gsw
|
||||
}
|
||||
|
||||
#if GDISP_NEED_IMAGE
|
||||
void gwinProgressbarDraw_Image(GWidgetObject *gw, void *param) {
|
||||
#define gsw ((GProgressbarObject *)gw)
|
||||
#define gi ((gdispImage *)param)
|
||||
const GColorSet * pcol;
|
||||
coord_t z, v;
|
||||
|
||||
if (gw->g.vmt != (gwinVMT *)&progressbarVMT)
|
||||
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 progressbar
|
||||
if (gsw->dpos != 0) // The unfilled area
|
||||
gdispGFillArea(gw->g.display, 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;
|
||||
if (z < gsw->dpos) {
|
||||
v -= gsw->dpos - z;
|
||||
z = gsw->dpos;
|
||||
}
|
||||
gdispGImageDraw(gw->g.display, gi, gw->g.x, gw->g.y+z, gw->g.width, v, 0, gi->height-v);
|
||||
}
|
||||
}
|
||||
gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge
|
||||
gdispGDrawLine(gw->g.display, gw->g.x, gw->g.y+gsw->dpos, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos, pcol->edge); // Thumb
|
||||
|
||||
// Horizontal progressbar
|
||||
} else {
|
||||
if (gsw->dpos != gw->g.width-1) // The unfilled area
|
||||
gdispGFillArea(gw->g.display, 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)
|
||||
v -= z+v - gsw->dpos;
|
||||
gdispGImageDraw(gw->g.display, gi, gw->g.x+z, gw->g.y, v, gw->g.height, 0, 0);
|
||||
}
|
||||
}
|
||||
gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge
|
||||
gdispGDrawLine(gw->g.display, gw->g.x+gsw->dpos, gw->g.y, gw->g.x+gsw->dpos, gw->g.y+gw->g.height-1, pcol->edge); // Thumb
|
||||
}
|
||||
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, justifyCenter);
|
||||
|
||||
#undef gsw
|
||||
}
|
||||
#endif /* GDISP_NEED_IMAGE */
|
||||
|
||||
#endif /* GFX_USE_GWIN && GWIN_NEED_BUTTON */
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user