📄 graphicobject.c
字号:
/**
******************************************************************************
* @file graphicObject.c
* @author MCD Application Team
* @version V2.0.0
* @date 11-July-2011
* @brief This file contains the methods to create the objects that
* can be printed on the LCD.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "graphicObject.h"
#include "images.h"
#include "touchscreen.h"
#include "TscHal.h"
#include "JoyHal.h"
#include "LcdHal.h"
#include "cursor.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/** @addtogroup Embedded_GUI_Library
* @{
*/
/** @defgroup graphicObject
* @brief graphicObject functions
* @{
*/
/* External variables --------------------------------------------------------*/
extern __IO uint16_t GL_TextColor;
extern __IO uint32_t u32_TSXCoordinate;
extern __IO uint32_t u32_TSYCoordinate;
/* Private typedef -----------------------------------------------------------*/
/* Private defines -----------------------------------------------------------*/
/** @defgroup graphicObject_Private_Defines
* @{
*/
#define FONT_LENGTH 8
#define BUTTON_SLICE_LENGTH 8
#define SLIDEBAR_CURSOR_LENGTH 6
#define SLIDEBAR_CENTRAL_LENGTH 27
#define SLIDEBAR_OFFSET_LENGTH 4
#define SLIDEBAR_PIECE_LENGTH 4
#define SLIDEBAR_HEIGHT 18
#define BUTTON_HEIGHT 26
#define BUTTON_PIECE_LENGTH 8
#define RBUTTON_OPT_SIZE 20
#define RADIO_BUTTON_RADIUS 9
#define COMBOBOX_SIZE 22
#define CHECKBOX_SIZE 20
#define PAGE_MAX_NUM 50
#define TIMEOUT 1000000
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/** @defgroup graphicObject_Private_Macros
* @{
*/
#define min(x,y) ((x<y)? x:y)
#define p_strncpy(oBuf, iBuf, Len) strncpy((char*)oBuf, (char*)iBuf, (int)Len)
#define p_strlen(iBuf) strlen((char*)iBuf)
#define p_strcmp(str1,str2) strcmp((char*)str1,(char*)str2)
#define p_strcpy(str1,str2) strcpy((char*)str1,(char*)str2)
/**
* @}
*/
/* Private variables ---------------------------------------------------------*/
/** @defgroup graphicObject_Private_Variables
* @{
*/
GL_Page_TypeDef* PagesList[PAGE_MAX_NUM];
/*Header and bitmap image of cursor's symbol*/
static uint32_t SlidebarCursorPointer[] =
{
0x14, /*Height of cursor symbol*/
0x06, /*Width of cursor symbol*/
0x0D, /*Count of pixels of cursor symbol*/
0x80001, 0x80001, 0x80001, 0x80001, 0x80001, 0x80001, 0x80001
};
static uint16_t PageCount = 0;
static __IO uint32_t TimingDelay;
__IO uint32_t vu32_gTimeOutCount = 0;
__IO uint8_t vu8_gTouchEnable = 1;
__IO uint8_t vu8_gSleepState = 0;
uint8_t ValidTouchDetected = 0;
/* Set to 0 to disable The Automatic Backlight Switch Off */
__IO uint8_t vu8_gPowerSaveOption = 1;
/* touch_done global variable is used to handle the Touch event/interrupt.
touch_done must be defined as external variable in main application using this library */
__IO uint8_t touch_done = 0;
__IO uint8_t joy_done = 0;
__IO uint8_t calibration_done = 0;
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/** @defgroup graphicObject_Private_FunctionPrototypes
* @{
*/
static void GL_SetStringFieldValue(uint8_t * dBuf, uint8_t * sBuf, uint32_t MaxLength) ;
static void CallPreEvents(GL_PageControls_TypeDef* pControl);
static void CallEvent(GL_PageControls_TypeDef* pControl);
static GL_ErrStatus Create_Label (GL_Label_TypeDef* );
static GL_ErrStatus Create_Button (GL_Button_TypeDef* );
static GL_ErrStatus Create_RadioButtonGrp (GL_RadioButtonGrp_TypeDef* );
static GL_ErrStatus Create_RadioButtonOption (GL_RadioOption_TypeDef* );
static GL_ErrStatus Create_ComboBoxGrp (GL_ComboBoxGrp_TypeDef* );
static GL_ErrStatus Create_ComboBoxOption (GL_ComboOption_TypeDef* );
static GL_ErrStatus Create_Checkbox (GL_Checkbox_TypeDef* );
static GL_ErrStatus Create_Switch (GL_Switch_TypeDef* );
static GL_ErrStatus Create_Icon (GL_Icon_TypeDef* );
static GL_ErrStatus Create_Slidebar (GL_Slidebar_TypeDef* );
static GL_ErrStatus Create_Histogram (GL_Histogram_TypeDef* );
static GL_ErrStatus Create_GraphChart (GL_GraphChart_TypeDef* );
static GL_ErrStatus SetLabelVisible(GL_PageControls_TypeDef* , GL_Coordinate_TypeDef );
static GL_ErrStatus SetCheckboxVisible(GL_PageControls_TypeDef* , GL_Coordinate_TypeDef );
static GL_ErrStatus SetSwitchVisible(GL_PageControls_TypeDef* , GL_Coordinate_TypeDef );
static GL_ErrStatus SetButtonVisible(GL_PageControls_TypeDef* , GL_Coordinate_TypeDef );
static GL_ErrStatus SetRadioButtonVisible(GL_PageControls_TypeDef* , GL_Coordinate_TypeDef );
static GL_ErrStatus SetComboBoxVisible(GL_PageControls_TypeDef* , GL_Coordinate_TypeDef );
static GL_ErrStatus SetIconVisible(GL_PageControls_TypeDef* , GL_Coordinate_TypeDef );
static GL_ErrStatus SetSlidebarVisible(GL_PageControls_TypeDef* , GL_Coordinate_TypeDef );
static GL_ErrStatus SetHistogramVisible( GL_PageControls_TypeDef* , GL_Coordinate_TypeDef );
static GL_ErrStatus SetGraphChartVisible( GL_PageControls_TypeDef* , GL_Coordinate_TypeDef );
static void SlidebarCursorPreDraw(GL_PageControls_TypeDef* pControl, GL_bool);
static GL_ObjDimensions_TypeDef GetObjSize(GL_PageControls_TypeDef* pPageControl);
static GL_Coordinate_TypeDef GetObjCoordinates(GL_Page_TypeDef* pPage, uint16_t ID);
static GL_ErrStatus SetPage(GL_Page_TypeDef* pThis, GL_bool bVal);
static void GL_DrawRectangle(uint16_t maxX, uint16_t minX, uint8_t maxY, uint8_t minY);
/**
* @}
*/
/* Private functions ---------------------------------------------------------*/
/** @defgroup graphicObject_Private_Functions
* @{
*/
/**
* @brief Displays a Rectangle.
* @param maxX - Maximum X coordinate
* @param minX - Minimum X coordinate
* @param maxY - Maximum Y coordinate
* @param minY - Minimum Y coordinate
* @retval None
*/
static void GL_DrawRectangle(uint16_t maxX, uint16_t minX, uint8_t maxY, uint8_t minY)
{
GL_DrawLine(minY, maxX, maxX - minX, GL_Horizontal);
GL_DrawLine((minY + maxY - minY), maxX, maxX - minX, GL_Horizontal);
GL_DrawLine(minY, maxX, maxY - minY, GL_Vertical);
GL_DrawLine(minY, (maxX - (maxX - minX) + 1), maxY - minY, GL_Vertical);
}
/**
* @brief Displays a filled Rectangle.
* @param maxX: Maximum X coordinate
* @param minX: Minimum X coordinate
* @param maxY: Maximum Y coordinate
* @param minY: Minimum Y coordinate
* @param Color: The filling color
* @retval None
*/
static void GL_DrawFilledRectangle(uint16_t maxX, uint16_t minX, uint8_t maxY, uint8_t minY, uint16_t Color)
{
uint32_t counter = 0;
if ( (maxX > minX + 1) && (maxY > minY - 1) )
{
GL_DrawLine(minY, maxX, maxX - minX, GL_Horizontal);
GL_DrawLine((minY + maxY - minY), maxX, maxX - minX, GL_Horizontal);
GL_DrawLine(minY, maxX, maxY - minY, GL_Vertical);
GL_DrawLine(minY, (maxX - (maxX - minX) + 1), maxY - minY, GL_Vertical);
}
GL_SetTextColor(Color);
for (counter = 1; counter < (maxY - minY); counter++)
{
GL_DrawLine(minY + counter, maxX - 1, maxX - minX - 2, GL_Horizontal);
}
}
/**
* @brief Displays a circle.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Radius: specifies the circle radius.
* @param Color: specifies the filling color.
* @retval None
*/
void GL_DrawFilledCircle(uint16_t Xpos, uint8_t Ypos, uint16_t Radius, uint16_t Color)
{
uint32_t n = 2;
GL_LCD_DrawCircle( Ypos - Radius, Xpos - Radius, Radius);
GL_LCD_DrawCircle( Ypos - Radius, Xpos - Radius, Radius - 1);
GL_SetTextColor(Color);
for (; n < Radius; n++)
{
GL_LCD_DrawCircle( Ypos - Radius, Xpos - Radius, Radius - n);
}
}
/**
* @brief Displays a line using Bresenham line algorithm.
* @param Xpos1: specifies the first point X position
* @param Ypos1: specifies the first point Y position
* @param Xpos2: specifies the second point X position
* @param Ypos2: specifies the second point Y position
* @param Color: RGB color of line.
* @retval None
*/
static void GL_DrawObliqueLine(uint16_t Ypos1, uint16_t Xpos1, uint16_t Ypos2, uint16_t Xpos2, uint16_t Color)
{
uint8_t steep = 0; /* Steepness of line,0 - non-steep (angle 45
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -