2017-05-29 07:54:57 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Copyright. **/
|
2017-10-08 16:03:05 +00:00
|
|
|
/** FileName: SGUI_List.c **/
|
2017-05-29 07:54:57 +00:00
|
|
|
/** Author: XuYulin **/
|
|
|
|
/** Description: Draw list interface. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
//=======================================================================//
|
|
|
|
//= Include files. =//
|
|
|
|
//=======================================================================//
|
2017-08-02 14:24:26 +00:00
|
|
|
#include "SGUI_List.h"
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
//=======================================================================//
|
2017-06-02 12:33:13 +00:00
|
|
|
//= User Macro definition. =//
|
2017-05-29 07:54:57 +00:00
|
|
|
//=======================================================================//
|
2017-08-02 14:24:26 +00:00
|
|
|
// User settings
|
2019-01-11 14:03:38 +00:00
|
|
|
#define LIST_SCROLLBAR_WIDTH (5)
|
2017-08-02 14:24:26 +00:00
|
|
|
// Automatic calculation
|
2019-02-02 14:04:14 +00:00
|
|
|
#define LIST_EDGE_SIZE 1
|
2019-12-09 14:11:37 +00:00
|
|
|
#define LIST_TITLE_HEIGHT(FONT) ((FONT)->iHeight+2)
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= Static function declaration. =//
|
|
|
|
//=======================================================================//
|
|
|
|
|
|
|
|
//=======================================================================//
|
2017-12-27 12:03:30 +00:00
|
|
|
//= Function define. =//
|
2017-05-29 07:54:57 +00:00
|
|
|
//=======================================================================//
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
2018-08-15 14:51:24 +00:00
|
|
|
/** Function Name: SGUI_List_InitializeListData **/
|
2017-08-02 14:24:26 +00:00
|
|
|
/** Purpose: Initialize a list control data. **/
|
|
|
|
/** Params: **/
|
2019-12-09 14:11:37 +00:00
|
|
|
/** @ pstObj[in]: Pointer of list data will be initialized. **/
|
|
|
|
/** @ pstFontRes[in]: Font resource object pointer. **/
|
2017-08-02 14:24:26 +00:00
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: None. **/
|
|
|
|
/*************************************************************************/
|
2019-12-12 14:28:32 +00:00
|
|
|
void SGUI_List_Initialize(SGUI_LIST_STRUCT* pstObj, const SGUI_FONT_RES* pstFontRes)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2019-12-09 14:11:37 +00:00
|
|
|
if((NULL != pstObj) && (NULL != pstFontRes))
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
// Initialize member object pointer.
|
2019-12-09 14:11:37 +00:00
|
|
|
pstObj->pstFontRes = pstFontRes;
|
|
|
|
pstObj->stItems.pstItems = NULL;
|
|
|
|
pstObj->stItems.stLayout.iPosX = pstObj->stLayout.iPosX+2;
|
2019-12-11 13:14:27 +00:00
|
|
|
pstObj->stItems.stLayout.iWidth = pstObj->stLayout.iWidth-4-LIST_SCROLLBAR_WIDTH;
|
2019-12-09 14:11:37 +00:00
|
|
|
if(NULL == pstObj->szTitle)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
2019-12-09 14:11:37 +00:00
|
|
|
pstObj->stItems.stLayout.iPosY = pstObj->stLayout.iPosY+2;
|
|
|
|
pstObj->stItems.stLayout.iHeight = pstObj->stLayout.iHeight-4;
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
2019-12-09 14:11:37 +00:00
|
|
|
else
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
2019-12-09 14:11:37 +00:00
|
|
|
pstObj->stItems.stLayout.iPosY = pstObj->stLayout.iPosY+LIST_TITLE_HEIGHT(pstObj->pstFontRes)+2;
|
|
|
|
pstObj->stItems.stLayout.iHeight = pstObj->stLayout.iHeight-LIST_TITLE_HEIGHT(pstObj->pstFontRes)-3;
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
2019-12-09 14:11:37 +00:00
|
|
|
SGUI_ItemsBase_Initialize(&(pstObj->stItems), pstObj->pstFontRes);
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
2019-12-09 14:11:37 +00:00
|
|
|
/** Function Name: SGUI_List_BindItemsData **/
|
|
|
|
/** Purpose: Bind list item data to object. **/
|
2017-08-02 14:24:26 +00:00
|
|
|
/** Params: **/
|
2019-12-09 14:11:37 +00:00
|
|
|
/** @ pstObj[in]: Pointer of list object. **/
|
|
|
|
/** @ pstItemsData[in]: List items data array. **/
|
|
|
|
/** @ iItemsCount[in]: Number of list item data. **/
|
2017-08-02 14:24:26 +00:00
|
|
|
/** Return: None. **/
|
2019-12-09 14:11:37 +00:00
|
|
|
/** Notice: None. **/
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
2019-12-12 14:28:32 +00:00
|
|
|
void SGUI_List_BindItemsData(SGUI_LIST_STRUCT* pstObj, SGUI_ITEMS_ITEM* pstItemsData, SGUI_INT iItemsCount)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2019-12-09 14:11:37 +00:00
|
|
|
if((NULL != pstObj) && (NULL != pstItemsData) && (iItemsCount > 0))
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
2019-12-10 15:04:51 +00:00
|
|
|
SGUI_ItemsBase_BindItemsData(&(pstObj->stItems), pstItemsData, iItemsCount);
|
2019-12-09 14:11:37 +00:00
|
|
|
// Initialize scroll bar.
|
2019-12-10 15:04:51 +00:00
|
|
|
pstObj->stScrollBar.eDirection = SGUI_SCROLLBAR_VERTICAL;
|
2019-12-11 13:14:27 +00:00
|
|
|
pstObj->stScrollBar.iPosX = pstObj->stItems.stLayout.iPosX+pstObj->stItems.stLayout.iWidth+1;
|
2019-12-10 15:04:51 +00:00
|
|
|
pstObj->stScrollBar.iPosY = pstObj->stItems.stLayout.iPosY;
|
|
|
|
pstObj->stScrollBar.iWidth = LIST_SCROLLBAR_WIDTH;
|
|
|
|
pstObj->stScrollBar.iHeight = pstObj->stItems.stLayout.iHeight;
|
|
|
|
pstObj->stScrollBar.sMaxIndex = (pstObj->stItems.iCount > pstObj->stItems.iVisibleItems)?(pstObj->stItems.iCount - pstObj->stItems.iVisibleItems):0;
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
2019-12-09 14:11:37 +00:00
|
|
|
/** Function Name: SGUI_List_Repaint **/
|
2017-08-02 14:24:26 +00:00
|
|
|
/** Purpose: Refresh list display. **/
|
|
|
|
/** Params: **/
|
2019-12-09 14:11:37 +00:00
|
|
|
/** @ pstDeviceIF[in]: Device driver object pointer. **/
|
|
|
|
/** @ pstObj[in]: Pointer of list data will be refreshed. **/
|
2017-08-02 14:24:26 +00:00
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: This function will refresh all list display on **/
|
|
|
|
/** screen, include edge, items, title and scrollbar. **/
|
|
|
|
/*************************************************************************/
|
2019-12-12 14:28:32 +00:00
|
|
|
void SGUI_List_Repaint(SGUI_SCR_DEV* pstDeviceIF, SGUI_LIST_STRUCT* pstObj)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2019-02-02 14:04:14 +00:00
|
|
|
SGUI_RECT_AREA stTitleTextDisplayArea;
|
2019-12-09 14:11:37 +00:00
|
|
|
SGUI_POINT stInnerPos;
|
2017-07-31 13:29:09 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2019-12-09 14:11:37 +00:00
|
|
|
if(NULL != pstObj)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
2019-12-09 14:11:37 +00:00
|
|
|
// Clear list item display area.
|
|
|
|
SGUI_Basic_DrawRectangle(pstDeviceIF, pstObj->stLayout.iPosX, pstObj->stLayout.iPosY, pstObj->stLayout.iWidth, pstObj->stLayout.iHeight, SGUI_COLOR_FRGCLR, SGUI_COLOR_BKGCLR);
|
|
|
|
// Paint title.
|
|
|
|
if(NULL != pstObj->szTitle)
|
2017-07-31 13:29:09 +00:00
|
|
|
{
|
2019-12-09 14:11:37 +00:00
|
|
|
stTitleTextDisplayArea.iPosX = pstObj->stLayout.iPosX+2;
|
|
|
|
stTitleTextDisplayArea.iPosY = pstObj->stLayout.iPosY+2;
|
|
|
|
stTitleTextDisplayArea.iWidth = pstObj->stLayout.iWidth-4;
|
|
|
|
stTitleTextDisplayArea.iHeight = pstObj->pstFontRes->iHeight;
|
|
|
|
stInnerPos.iPosX = 0;
|
|
|
|
stInnerPos.iPosY = 0;
|
|
|
|
SGUI_Text_DrawText(pstDeviceIF, pstObj->szTitle, pstObj->pstFontRes, &stTitleTextDisplayArea, &stInnerPos, SGUI_DRAW_NORMAL);
|
|
|
|
SGUI_Basic_DrawLine(pstDeviceIF, pstObj->stLayout.iPosX, pstObj->stLayout.iPosY+pstObj->pstFontRes->iHeight+3, pstObj->stLayout.iPosX+pstObj->stLayout.iWidth-1, pstObj->stLayout.iPosY+pstObj->pstFontRes->iHeight+3, SGUI_COLOR_FRGCLR);
|
2017-07-31 13:29:09 +00:00
|
|
|
}
|
2019-12-09 14:11:37 +00:00
|
|
|
// Paint items.
|
|
|
|
SGUI_ItemsBase_Repaint(pstDeviceIF, &(pstObj->stItems));
|
|
|
|
// Paint scroll bar.
|
2019-12-10 15:04:51 +00:00
|
|
|
pstObj->stScrollBar.sIndex = pstObj->stItems.iPageStartIndex;
|
|
|
|
SGUI_ScrollBar_Repaint(pstDeviceIF, &(pstObj->stScrollBar));
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
}
|