Adding GUI support for OLED screens 6: progress bar control

Source: Internet
Author: User

Adding GUI support for OLED screens 6: progress bar control


this blog link: http://blog.csdn.net/jdh99 , Author: jdh, reprint please specify.

Environment:

Host: WIN10

Development environment: MDK5.13

mcu:stm32f103



Source:

Gui_widget_progbar.h

/*** Copyright (c), 2015-2025* @file gui_widget_progbar.h* @brief Text Control header file * @author jdh* @date 2015/11/22*/#ifndef _gui_wid Get_progbar_h_#define _gui_widget_progbar_h_/****************************************************************** Header file **********************************************************************/#include "gui_interface.h"/****** Macro Definition ******************************************** @brief text length. Units: Bytes */#define len_widget_text32/************************************ Data Structure **********************************************************************//* * * @brief progress bar data structure */typedef struct _widget_progbar{//x axis position uint16_t x;//y axis position uint16_t y;//horizontal dimension uint16_t xsize;//Vertical Size UInt16 _t Ysize;} *widget_progbar_handle;/********************************************************************** function ************** @brief Create the control * @param x:Upper-Left x-coordinate * @param y: Upper-Left y-coordinate * @param xsize: Horizontal Dimension * @param ysize: Vertical dimension * @retval control handle */widget_progbar_handle Gui_widget_progbar_ Create (uint16_t x,uint16_t y,uint16_t xsize,uint16_t ysize);/*** @brief Set Progress * @param value: percent, 0-100*/void gui_widget_ Progbar_set_value (widget_progbar_handle handle,uint8_t value); #endif

Gui_widget_progbar.c

/*** Copyright (c), 2015-2025* @file gui_widget_progbar.c* @brief progress bar control Master file * @author jdh* @date 2015/11/22*//************* Header file *************************************************** /#include "gui_widget_progbar.h" #include "gui_2d_lib.h" #include "stdlib.h"/******************* Static variable ******************************************************** @brief percent */static uint8_t Percent = 0;/******************************************************** static function **********************************************************************//*** @brief control display * @param Handle: Control handle */static void Show (Widget_progbar_handle handle);/**************************************************** function **********************************************************************//*** @brief Create control * @ param x: Upper-Left x-coordinate * @param y: Upper-Left y-coordinate * @param xsize: Horizontal Dimension * @param ysize: Vertical dimension * @retval control handle */widget_progbar_handle gui_widget_progbar_create (uint16_t x,uint16_t y,uint16_t xsize,uint16_t ysize) {Widget_Progbar_ Handle handle;//Control Initialization Handle = malloc (sizeof (*handle)); handle->x = X;handle->y = Y;handle->xsize = Xsize; Handle->ysize = ysize;//shows show (handle); return handle;} /*** @brief Set Progress * @param value: Percent, 0-100*/void gui_widget_progbar_set_value (Widget_progbar_handle handle,uint8_t Value) {if (Percent = = value) {return;} if (value < Percent) {//Clear area Gui_fill_rect (handle->x,handle->y,handle->x + handle->xsize,handle->y + handle->ysize,0);//Display Gui_draw_rect (handle->x,handle->y,handle->x + handle->xsize,handle->y + handle->ysize);}  Show Gui_fill_rect (handle->x + handle->xsize * percent/100,handle->y, handle->x + handle->xsize * Value/ 100,handle->y + handle->ysize,1); Percent = value;} /*** @brief control displays * @param handle: Control handle */static void Show (Widget_progbar_handle handle) {//Clear area gui_fill_rect (handle->x , handle->y,handle->x+ handle->xsize,handle->y + handle->ysize,0);//Display Gui_draw_rect (Handle->x,handle->y,handle->x + Handle->xsize,handle->y + handle->ysize); Percent = 0;}

Test code:

progress bar static Widget_progbar_handle Widget_progbar; Widget_progbar = Gui_widget_progbar_create (9,39,111,8); Gui_widget_progbar_set_value (Widget_Progbar,50);




Adding GUI support for OLED screens 6: progress bar control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.