diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gfile/sys_defs.h | 135 | ||||
-rw-r--r-- | src/gwin/list.c | 20 | ||||
-rw-r--r-- | src/gwin/list.h | 14 | ||||
-rw-r--r-- | src/gwin/progressbar.c | 34 |
4 files changed, 194 insertions, 9 deletions
diff --git a/src/gfile/sys_defs.h b/src/gfile/sys_defs.h index 675bc4b1..1e53b439 100644 --- a/src/gfile/sys_defs.h +++ b/src/gfile/sys_defs.h @@ -49,17 +49,152 @@ extern GFILE *gfileStdOut; extern "C" { #endif + /** + * @brief Check if file exists + * + * @param[in] fname The file name + * + * @return TRUE if file exists, FALSE otherwise + * + * @api + */ bool_t gfileExists(const char *fname); + + /** + * @brief Delete file + * + * @param[in] fname The file name + * + * @return TRUE on success, FALSE otherwise + * + * @api + */ bool_t gfileDelete(const char *fname); + + /** + * @brief Get the size of a file + * @note Please use @p gfileGetSize() if the file is not opened + * + * @param[in] fname The file name + * + * @return File size on success, -1 on error + * + * @api + */ long int gfileGetFilesize(const char *fname); + + /** + * @brief Rename file + * + * @param[in] oldname The current file name + * @param[in] newname The new name of the file + * + * @return TRUE on success, FALSE otherwise + * + * @api + */ bool_t gfileRename(const char *oldname, const char *newname); + + /** + * @brief Open file + * @details A file must be opened before it can be accessed + * @details ToDo (document possible modes) + * @details The resulting GFILE will be used for all functions that access the file. + * + * @param[in] fname The file name + * @param[in] mode The mode + * + * @return Valid GFILE on success, 0 otherwise + * + * @api + */ GFILE * gfileOpen(const char *fname, const char *mode); + + /** + * @brief Close file + * @details Closes a file after is has been opened using @p gfileOpen() + * + * @param[in] f The file + * + * @api + */ void gfileClose(GFILE *f); + + /** + * @brief Read from file + * @details Reads a given amount of bytes from the file + * @details The read/write cursor will not be reset when calling this function + * + * @param[in] f The file + * @param[out] buf The buffer in which to save the content that has been read from the file + * @param[in] len Amount of bytes to read + * + * @return Amount of bytes read + * + * @api + */ size_t gfileRead(GFILE *f, void *buf, size_t len); + + /** + * @brief Write to file + * @details Write a given amount of bytes to the file + * @details The read/write cursor will not be reset when calling this function + * + * @param[in] f The file + * @param[in] buf The buffer which contains the content that will be written to the file + * @param[in] len Amount of bytes to write + * + * @return Amount of bytes written + * + * @api + */ size_t gfileWrite(GFILE *f, const void *buf, size_t len); + + /** + * @brief Get the current position of the read/write cursor + * + * @param[in] f The file + * + * @return The current position in the file + * + * @api + */ long int gfileGetPos(GFILE *f); + + /** + * @brief Set the position of the read/write cursor + * + * @param[in] f The file + * @param[in] pos The position to which the cursor will be set + * + * @return TRUE on success, FALSE otherwise + * + * @api + */ bool_t gfileSetPos(GFILE *f, long int pos); + + /** + * @brief Get the size of file + * @note Please use @p gfileGetFilesize() if the file is not opened + * + * @param[in] f The file + * + * @return The size of the file + * + * @api + */ long int gfileGetSize(GFILE *f); + + /** + * @brief Check for EOF + * @details Checks if the cursor is at the end of the file + * + * @param[in] f The file + * + * @return TRUE if EOF, FALSE otherwise + * + * @api + */ bool_t gfileEOF(GFILE *f); #if GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS diff --git a/src/gwin/list.c b/src/gwin/list.c index 8374ff39..50c669f0 100644 --- a/src/gwin/list.c +++ b/src/gwin/list.c @@ -41,6 +41,7 @@ #define GLIST_FLG_HASIMAGES (GWIN_FIRST_CONTROL_FLAG << 1) #define GLIST_FLG_SCROLLALWAYS (GWIN_FIRST_CONTROL_FLAG << 2) #define GLIST_FLG_SCROLLSMOOTH (GWIN_FIRST_CONTROL_FLAG << 3) +#define GLIST_FLG_ENABLERENDER (GWIN_FIRST_CONTROL_FLAG << 4) // Flags on a ListItem. #define GLIST_FLG_SELECTED 0x0001 @@ -92,6 +93,11 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { coord_t sy; #endif + // dont render if render has been disabled + if (!(gw->g.flags & GLIST_FLG_ENABLERENDER)) { + return; + } + ps = (gw->g.flags & GWIN_FLG_ENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; x = 1; @@ -401,12 +407,26 @@ GHandle gwinGListCreate(GDisplay *g, GListObject* gobj, GWidgetInit* pInit, bool if (multiselect) gobj->w.g.flags |= GLIST_FLG_MULTISELECT; gobj->w.g.flags |= GLIST_FLG_SCROLLALWAYS; + gobj->w.g.flags |= GLIST_FLG_ENABLERENDER; gwinSetVisible(&gobj->w.g, pInit->g.show); return (GHandle)gobj; } +void gwinListEnableRender(GHandle gh, bool_t ena) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&listVMT) + return; + + if (ena) { + gh->flags |= GLIST_FLG_ENABLERENDER; + gwinRedraw(gh); + } else { + gh->flags &=~ GLIST_FLG_ENABLERENDER; + } +} + void gwinListSetScroll(GHandle gh, scroll_t flag) { // is it a valid handle? if (gh->vmt != (gwinVMT *)&listVMT) diff --git a/src/gwin/list.h b/src/gwin/list.h index eb800439..2cc525a2 100644 --- a/src/gwin/list.h +++ b/src/gwin/list.h @@ -103,6 +103,20 @@ GHandle gwinGListCreate(GDisplay *g, GListObject *widget, GWidgetInit *pInit, bo #define gwinListCreate(w, pInit, m) gwinGListCreate(GDISP, w, pInit, m) /** + * @brief Enable or disable the rendering of the list + * + * @details Usually the list is being re-rendered when an item is added to the list. This can cause + * flickering and performance issues when many items are added at once. This can be prevented + * by temporarely disabling the render using this function. + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] ena TRUE or FALSE + * + * @api + */ +void gwinListEnableRender(GHandle gh, bool_t ena); + +/** * @brief Change the behaviour of the scroll bar * * @note Current possible values: @p scrollAlways, @p scrollAuto and @p scrollSmooth diff --git a/src/gwin/progressbar.c b/src/gwin/progressbar.c index a7acc0ed..7c34607f 100644 --- a/src/gwin/progressbar.c +++ b/src/gwin/progressbar.c @@ -206,6 +206,12 @@ void gwinProgressbarStart(GHandle gh, delaytime_t delay) { gtimerInit(&(gsw->gt)); gtimerStart(&(gsw->gt), _progressbarCallback, gh, FALSE, gsw->delay); + // if this is not made, the progressbar will not start when the it's already visible + if (gsw->w.g.flags & GWIN_FLG_VISIBLE) { + gwinSetVisible(gh, FALSE); + gwinSetVisible(gh, TRUE); + } + #undef gsw } @@ -226,33 +232,43 @@ void gwinProgressbarStop(GHandle gh) { 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)) + // disable the auto-update timer if any + #if GFX_USE_GTIMER + if (gtimerIsActive(&(gsw->gt)) && !(gw->g.flags & GWIN_FLG_ENABLED)) { + gtimerStop(&(gsw->gt)); + } + #endif + + // get the colors right + 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 + // Vertical progressbar + if (gw->g.width < gw->g.height) { 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 + 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 + 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 + 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); |