From ae80afb6ae93b1876c86afccefa8f4362bc184b9 Mon Sep 17 00:00:00 2001 From: SSYYL <1032789891@qq.com> Date: Mon, 17 Oct 2022 19:42:35 +0800 Subject: [PATCH] The GUI supports displaying the number '0' and decimals. --- STM32/STM32-F103ZET6/User/GUI/GUI_Paint.c | 63 ++++++++++++++++++++++- STM32/STM32-F103ZET6/User/GUI/GUI_Paint.h | 1 + 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/STM32/STM32-F103ZET6/User/GUI/GUI_Paint.c b/STM32/STM32-F103ZET6/User/GUI/GUI_Paint.c index e7e562b..f8ab27e 100644 --- a/STM32/STM32-F103ZET6/User/GUI/GUI_Paint.c +++ b/STM32/STM32-F103ZET6/User/GUI/GUI_Paint.c @@ -718,12 +718,73 @@ void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, } //Converts a number to a string - while (Nummber) { + do { Num_Array[Num_Bit] = Nummber % 10 + '0'; Num_Bit++; Nummber /= 10; + } while(Nummber); + + + //The string is inverted + while (Num_Bit > 0) { + Str_Array[Str_Bit] = Num_Array[Num_Bit - 1]; + Str_Bit ++; + Num_Bit --; } + //show + Paint_DrawString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground); +} + +/****************************************************************************** +function: Display nummber (Able to display decimals) +parameter: + Xstart :X coordinate + Ystart : Y coordinate + Nummber : The number displayed + Font :A structure pointer that displays a character size + Digit : Fractional width + Color_Foreground : Select the foreground color + Color_Background : Select the background color +******************************************************************************/ +void Paint_DrawNumDecimals(UWORD Xpoint, UWORD Ypoint, double Nummber, + sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background) +{ + int16_t Num_Bit = 0, Str_Bit = 0; + uint8_t Str_Array[ARRAY_LEN] = {0}, Num_Array[ARRAY_LEN] = {0}; + uint8_t *pStr = Str_Array; + int temp = Nummber; + float decimals; + uint8_t i; + if (Xpoint > Paint.Width || Ypoint > Paint.Height) { + Debug("Paint_DisNum Input exceeds the normal display range\r\n"); + return; + } + + if(Digit > 0) { + decimals = Nummber - temp; + for(i=Digit; i > 0; i--) { + decimals*=10; + } + temp = decimals; + //Converts a number to a string + for(i=Digit; i>0; i--) { + Num_Array[Num_Bit] = temp % 10 + '0'; + Num_Bit++; + temp /= 10; + } + Num_Array[Num_Bit] = '.'; + Num_Bit++; + } + + temp = Nummber; + //Converts a number to a string + do { + Num_Array[Num_Bit] = temp % 10 + '0'; + Num_Bit++; + temp /= 10; + } while(temp); + //The string is inverted while (Num_Bit > 0) { Str_Array[Str_Bit] = Num_Array[Num_Bit - 1]; diff --git a/STM32/STM32-F103ZET6/User/GUI/GUI_Paint.h b/STM32/STM32-F103ZET6/User/GUI/GUI_Paint.h index 6578d7c..67d2291 100644 --- a/STM32/STM32-F103ZET6/User/GUI/GUI_Paint.h +++ b/STM32/STM32-F103ZET6/User/GUI/GUI_Paint.h @@ -200,6 +200,7 @@ void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Acsii_Char, sFONT* Fo void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background); void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background); void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background); +void Paint_DrawNumDecimals(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background); // Able to display decimals void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background); //pic