From ba26732f7a7a31f24ebd29baa8e2fa58d33f99a9 Mon Sep 17 00:00:00 2001 From: wujiahao17 <315776852@qq.com> Date: Tue, 20 Aug 2024 20:06:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/Demo/BiaoGe/TableControl.c | 738 ------------------------------------- src/app/Demo/BiaoGe/TableControl.h | 63 ---- src/app/Demo/TimeEdit/TimeEdit.c | 437 ---------------------- src/app/Demo/TimeEdit/TimeEdit.h | 36 -- src/app/Module/TableControl.c | 738 +++++++++++++++++++++++++++++++++++++ src/app/Module/TableControl.h | 63 ++++ src/app/Module/TimeEdit.c | 437 ++++++++++++++++++++++ src/app/Module/TimeEdit.h | 36 ++ src/app/Module/wjh_ClockControl.c | 185 ++++++++++ src/app/Module/wjh_ClockControl.h | 23 ++ 10 files changed, 1482 insertions(+), 1274 deletions(-) delete mode 100644 src/app/Demo/BiaoGe/TableControl.c delete mode 100644 src/app/Demo/BiaoGe/TableControl.h delete mode 100644 src/app/Demo/TimeEdit/TimeEdit.c delete mode 100644 src/app/Demo/TimeEdit/TimeEdit.h create mode 100644 src/app/Module/TableControl.c create mode 100644 src/app/Module/TableControl.h create mode 100644 src/app/Module/TimeEdit.c create mode 100644 src/app/Module/TimeEdit.h create mode 100644 src/app/Module/wjh_ClockControl.c create mode 100644 src/app/Module/wjh_ClockControl.h diff --git a/src/app/Demo/BiaoGe/TableControl.c b/src/app/Demo/BiaoGe/TableControl.c deleted file mode 100644 index ee13603..0000000 --- a/src/app/Demo/BiaoGe/TableControl.c +++ /dev/null @@ -1,738 +0,0 @@ -/* - * TableControl.c - * - * Created on: 2024年6月14日 - * Author: wu - */ - -#include "TableControl.h" -static bool_t Table_Draw(u32 TableId); -struct TableHistorInfo -{ - HWND hwnd; - u32 x,y; - u32 bgColor;//表格背景颜色 - u32 frontColor;//表格字体颜色 - u32 high;//表格总高度 - u32 rows;//一页显示的行数,不包括表头 - u32 pages;//当前显示的页数 - s32 nowNums;//当前从第几个开始显示 - u32 headerHigh;//表头的高度,记录的高度((总高度-表头高度)/一页显示行数) - u32 columns;//列数 - struct TableHeader tableHeader[COLUMNS_MAX]; - u32 dataLenght;//数据的长度,每一个格子代表一个长度 - u8 data[DATA_MAX][DATA_LEN_MAX];//表格的数据,下一行的数据紧挨着上一行的下一位数组 -}; - -//历史表格信息 -struct TableHistorInfo tableHistorInfo[TABLE_NUM_MAX] = {0}; - -static struct TableInfo TableHistorInfo_To_TableInfo(u32 TableId){ - struct TableInfo tableInfo = {0}; - if(TableId > TABLE_NUM_MAX - 1){ - return tableInfo; - } - - tableInfo.x = tableHistorInfo[TableId].x; - tableInfo.y = tableHistorInfo[TableId].y; - tableInfo.bgColor = tableHistorInfo[TableId].bgColor; - tableInfo.frontColor = tableHistorInfo[TableId].frontColor; - tableInfo.high = tableHistorInfo[TableId].high; - tableInfo.rows = tableHistorInfo[TableId].rows; - tableInfo.headerHigh = tableHistorInfo[TableId].headerHigh; - tableInfo.columns = tableHistorInfo[TableId].columns; - tableInfo.dataLenght = tableHistorInfo[TableId].dataLenght; - memcpy(tableInfo.tableHeader,tableHistorInfo[TableId].tableHeader,sizeof(struct TableHeader) * COLUMNS_MAX); - for(u32 i = 0;i < tableHistorInfo[TableId].dataLenght;i ++){ - strcpy(tableInfo.data[i],tableHistorInfo[TableId].data[i]); - } - - return tableInfo; -} - -static bool_t TableInfo_To_TableHistorInfo(u32 TableId,struct TableInfo *tableInfo){ - if(TableId > TABLE_NUM_MAX - 1){ - return false; - } - tableHistorInfo[TableId].x = tableInfo->x; - tableHistorInfo[TableId].y = tableInfo->y; - tableHistorInfo[TableId].bgColor = tableInfo->bgColor; - tableHistorInfo[TableId].frontColor = tableInfo->frontColor; - tableHistorInfo[TableId].high = tableInfo->high; - tableHistorInfo[TableId].rows = tableInfo->rows; - tableHistorInfo[TableId].headerHigh = tableInfo->headerHigh; - tableHistorInfo[TableId].columns = tableInfo->columns; - memcpy(tableHistorInfo[TableId].tableHeader,tableInfo->tableHeader,sizeof(struct TableHeader) * COLUMNS_MAX); - tableHistorInfo[TableId].dataLenght = tableInfo->dataLenght; - for(u32 i = 0;i < tableHistorInfo[TableId].dataLenght;i ++){ -// memcpy(tableHistorInfo[TableId].data[i],tableInfo->data[i],sizeof(u8) * DATA_LEN_MAX); - strcpy(tableHistorInfo[TableId].data[i],tableInfo->data[i]); - } - - return true; -} - -// ============================================================================= -// 功能:寻找表格,并返回历史信息地址(这个由于是直接返回历史表格指针,所以最好不要随意调用) -// 参数:TableId:所要搜索的窗口信息ID -// 返回:tableHistorInfo[i]:寻找到的目标表格结构体指针,NULL:没有找到目标表格 -// ============================================================================= -//static struct TableHistorInfo* Table_Search_Info(u32 TableId){ -// if(TableId > TABLE_NUM_MAX - 1){ -// return NULL; -// } -// if(tableHistorInfo[TableId].hwnd == NULL){ -// return NULL; -// } -// return &tableHistorInfo[TableId]; -//} - -// ============================================================================= -// 功能:寻找表格,并返回复制的信息(可以用来统一修改表格)//先别用 -// 参数:TableId:所要搜索的窗口Id -// 返回:tableHistorInfo:寻找到的目标表格结构体的复制,NULL:没有找到目标表格 -// ============================================================================= -//struct TableInfo Table_Search_Info_Copy(u32 TableId){ -// struct TableInfo tableInfo = {0}; -// if(TableId > TABLE_NUM_MAX - 1){ -// return tableInfo; -// } -// if(tableHistorInfo[TableId].hwnd == NULL){ -// return tableInfo; -// } -// tableInfo = TableHistorInfo_To_TableInfo(TableId); -// -// return tableInfo; -//} - -// ============================================================================= -// 功能:搜索一个空的表格位置,用来存储历史表格信息 -// 参数:无 -// 返回:i:返回的目标表格的下标,TABLE_NULL:表格控件满了需要增大TABLENUMMAX数量 -// ============================================================================= -//static u32 Table_Search_NULL(void){ -// for(u32 i = 0;i < TABLE_NUM_MAX;i ++){ -// if(tableHistorInfo[i] == NULL||tableHistorInfo == 0){ -// return i; -// } -// } -// return TABLE_NULL; -//} - -static POINT first_pt = {0}; -static POINT old_pt = {0}; -//bool_t MoveStatus = false; - -static bool_t down(struct WindowMsg *pMsg) -{ - u8* data; - HWND hwnd; - HDC hdc; - if(pMsg==NULL) - return false; - hwnd = pMsg -> hwnd; - if(hwnd ==NULL) return false; - first_pt.x = (u16)(pMsg->Param2 & 0xFFFF); - first_pt.y = (u16)((pMsg->Param2 >> 16) & 0xFFFF); - old_pt.y = first_pt.y; -// // 屏幕坐标转窗口坐标 -// GDD_ScreenToWindow(hwnd,&first_pt,1); - - return true; -} - -static bool_t move(struct WindowMsg *pMsg) -{ - u8* data; - HWND hwnd; - HDC hdc; - if(pMsg==NULL) - return false; - hwnd = pMsg -> hwnd; - POINT new_pt = {0}; - // 算出触摸点坐标 - new_pt.x = (u16)(pMsg->Param2 & 0xFFFF); - new_pt.y = (u16)((pMsg->Param2 >> 16) & 0xFFFF); - u32 tableId = GDD_GetWindowPrivateData(hwnd); - //如果有往相反的方向滑动,则重置按下的坐标 - if((new_pt.y < old_pt.y&&first_pt.y < new_pt.y)||(new_pt.y < first_pt.y&&old_pt.y < new_pt.y)){ - first_pt.y = old_pt.y; - } - old_pt.y = new_pt.y; - new_pt.y = first_pt.y - new_pt.y; -// // 屏幕坐标转窗口坐标 -// GDD_ScreenToWindow(hwnd, &new_pt, 1); - - Table_slide_grid_Y(tableId,new_pt.y); - - return true; -} - - -struct MsgProcTable homeMsg[] = - { - {.MsgCode = MSG_TOUCH_MOVE + MSG_ADOPT_NONE, .MsgProc = move}, - {.MsgCode = MSG_TOUCH_DOWN + MSG_ADOPT_NONE, .MsgProc = down }, - {.MsgCode = MSG_TOUCH_UP + MSG_ADOPT_NONE, .MsgProc = NULL}, - {.MsgCode = MSG_PAINT , .MsgProc = NULL }, -}; -// 用户定义的消息链表(登录按钮相关的) -struct MsgTableLink homeMsgTab = - { - .MsgNum = sizeof(homeMsg) / sizeof(struct MsgProcTable), - .myTable = (struct MsgProcTable *)&homeMsg, -}; - -// ============================================================================= -// 功能:创建表格,并进行绘制(如果后续需要通过代码对目标表格进行修改才需要创建) -// 参数:TableId:表格的ID(当做历史表格数组的下标,以0开始,头文件可以修改表格的最大数量),tableInfo:表格信息 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Create(u32 TableId,HWND hParent,struct TableInfo *tableInfo) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(hParent == NULL){ - return false;//窗口没有定义 - } - if(tableInfo->columns > COLUMNS_MAX||tableInfo->dataLenght > DATA_MAX){ - return false;//定义的列数超过了列数最大值,或者数据长度大于定义的最大支持数据长度 - } - if(tableHistorInfo[TableId].hwnd != NULL){ - return false;//该窗口已经创建过表格 - } - - u32 width = 0; - - //把每一列的宽度加起来,如果该列的宽度为<=的话,则设置为默认宽度 - for(u32 i = 0;i < tableInfo->columns;i ++){ - width += tableInfo->tableHeader[i].width?tableInfo->tableHeader[i].width:DEFAULT_WIDTH; - } - - //以表格的下标、高度和宽度来命名表格,防止重名 - u8 tableName[100]; - sprintf(tableName,"table_Window%d%d%d",TableId,tableInfo->high,width); - tableHistorInfo[TableId].hwnd = GDD_CreateWindow(tableName,&homeMsgTab,tableInfo->x,tableInfo->y, width, tableInfo->high, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY, RGB(200, 200, 200), 0, TableId,hParent); - TableInfo_To_TableHistorInfo(TableId,tableInfo); - - Table_Draw(TableId); - return true; -} - -// ============================================================================= -// 功能:删除表格 -// 参数:TableId:目标表格Id -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Delete(u32 TableId) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - GDD_DestroyWindow(tableHistorInfo[TableId].hwnd); - tableHistorInfo[TableId].hwnd = NULL; - - return true; -} - -// ============================================================================= -// 功能:修改表格全部数据 -// 参数:tableInfo:表格信息 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Edit_All(u32 TableId,struct TableInfo *tableInfo) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - //更新全部信息 - TableInfo_To_TableHistorInfo(TableId,tableInfo); - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:修改表头文字,textNum还会修改表格列数 -// 参数:TalbeId:目标表格窗口Id。textNum:表头文本个数(表格的列数是依据表头个数来定,因此这里传参会修改表格的列数)。text:表头文本 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Edit_Header_And_column(u32 TableId,u32 textNum,u8 *text[]) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - //复制数据 - tableHistorInfo[TableId].columns = textNum; - for(u32 i = 0;i < tableHistorInfo[TableId].columns;i ++){ - strcpy(tableHistorInfo[TableId].tableHeader[i].attribute,text[i]); - } - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:修改表格数据,并将页数变为第一页 -// 参数:TableId:目标表格窗口Id dataNum:数据个数 data:数据数组 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Edit_Data(u32 TableId,u32 dataNum,u8 *data[]) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - //复制数据 - tableHistorInfo[TableId].columns = dataNum; - for(u32 i = 0;i < tableHistorInfo[TableId].columns;i ++){ - strcpy(tableHistorInfo[TableId].tableHeader[i].attribute,data[i]); - } - - //页面初始化为第一页 - tableHistorInfo[TableId].pages = 0; - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:修改表头高度 -// 参数:tableId:目标表格窗口Id high:修改表格高度 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Edit_Header_High(u32 TableId,u32 high) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - //修改表格高度 - tableHistorInfo[TableId].headerHigh = high; - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:修改表格总高度(表格除去表头的其他行的高度计算公式为:(总高度-表头高度)/一页显示行数 -// 参数:hwnd:目标表格窗口 high:修改表格高度 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Edit_High(u32 TableId,u32 high) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - //修改表格高度 - tableHistorInfo[TableId].high = high; - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:修改表格的背景颜色 -// 参数:hwnd:目标表格窗口 bgColor:背景颜色 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Edit_Background_Color(u32 TableId,u32 bgColor) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - //修改表格高度 - tableHistorInfo[TableId].bgColor = bgColor; - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:修改表格的文本颜色 -// 参数:hwnd:目标表格窗口 frontColor:文本颜色 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Edit_Front_Color(u32 TableId,u32 frontColor) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - //修改表格高度 - tableHistorInfo[TableId].frontColor = frontColor; - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:跳转表格至上一页 -// 参数:hwnd:目标表格窗口 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Last_Page(u32 TableId) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - if(tableHistorInfo[TableId].pages == 0){ - if(tableHistorInfo[TableId].nowNums != 0){ - tableHistorInfo[TableId].nowNums = 0; - Table_Draw(TableId); - } - return false;//这是第一页,不能再进入上一页了 - } - - //如果是页面循环才需要算总的页面数 -// u32 onePageData = tableHistorInfo[xb].rows * tableHistorInfo[xb].columns;//一页的数据 -// u32 jw = (tableHistorInfo[xb].dataLenght % onePageData)?1:0; -// u32 pageNums = tableHistorInfo[xb].dataLenght / onePageData + jw;//如果整除不尽就加一 - tableHistorInfo[TableId].pages --; - tableHistorInfo[TableId].nowNums = tableHistorInfo[TableId].pages * (tableHistorInfo[TableId].rows * tableHistorInfo[TableId].columns);//当前显示的初始数据变成目标页数的第一个 - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:跳转表格至下一页 -// 参数:hwnd:目标表格窗口 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Next_Page(u32 TableId) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - u32 onePageData = tableHistorInfo[TableId].rows * tableHistorInfo[TableId].columns;//一页的数据 - u32 jw = (tableHistorInfo[TableId].dataLenght % onePageData)?1:0; - u32 pageNums = tableHistorInfo[TableId].dataLenght / onePageData + jw;//如果整除不尽就加一 - if(tableHistorInfo[TableId].pages + 1 == pageNums){ -// if()//这里要加 - return false;//这是最后一页,不能进入下一页了 - } -// tableHistorInfo[xb].pages = (tableHistorInfo[xb].pages + 1) % pageNums;//这是循环的方法 - tableHistorInfo[TableId].pages ++; - tableHistorInfo[TableId].nowNums = tableHistorInfo[TableId].pages * (tableHistorInfo[TableId].rows * tableHistorInfo[TableId].columns);//当前显示的初始数据变成目标页数的第一个 - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:传入一个数值,图表根据数值滑动,每次变动都是按照格子来滑动,不会显示一半之类的 -// 参数:hwnd:目标表格窗口 Y_Len:Y轴滑动距离 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_slide_grid_Y(u32 TableId,s32 Y_Len) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - s32 dataHigh = (tableHistorInfo[TableId].high - tableHistorInfo[TableId].headerHigh) / tableHistorInfo[TableId].rows; - s32 slideNum = Y_Len / dataHigh; - tableHistorInfo[TableId].nowNums += slideNum * tableHistorInfo[TableId].columns; - - //处理越界 - if(tableHistorInfo[TableId].nowNums < 0){ - tableHistorInfo[TableId].nowNums = 0; - } - if(tableHistorInfo[TableId].nowNums >= tableHistorInfo[TableId].dataLenght - tableHistorInfo[TableId].columns){ - tableHistorInfo[TableId].nowNums = tableHistorInfo[TableId].dataLenght - tableHistorInfo[TableId].columns; - } - - - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:跳转至目标页数(如果页数不存在会失败) -// 参数:hwnd:目标表格窗口 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_To_Page(u32 TableId,u32 num) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - u32 onePageData = tableHistorInfo[TableId].rows * tableHistorInfo[TableId].columns;//一页的数据 - u32 jw = (tableHistorInfo[TableId].dataLenght % onePageData)?1:0; - u32 pageNums = tableHistorInfo[TableId].dataLenght / onePageData + jw;//如果整除不尽就加一 - if(num >= pageNums||num < 0){ - return false;//输入页数超出范围 - } - tableHistorInfo[TableId].pages = num; - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:修改表格列宽(修改后的总列宽以创建时的为基准 -// 参数:hwnd:目标表格窗口。num:要修改的数字。width[]:表格宽度数组 -// 返回:true:成功,false:失败 -// ============================================================================= -bool_t Table_Edit_Width(u32 TableId,u32 num,u32 width[]) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } - - if(num > tableHistorInfo[TableId].columns){ - return false;//如果num大于表格列数,则返回false - } - //修改宽度,只从头到尾修改num个 - for(u32 i = 0;i < num;i ++){ - tableHistorInfo[TableId].tableHeader[i].width = width[i]; - } - - Table_Draw(TableId); - - return true; -} - -// ============================================================================= -// 功能:根据表格信息绘制表格(如果是一次性表格无需修改可以直接调用,因为这个函数的表格信息不能存到历史表格中,后续如需要通过代码或操控修改表格则通过Table_Create函数创建) -// 参数:TableId:要绘制的表格ID -// 返回:true:成功,false:失败 -// ============================================================================= -static bool_t Table_Draw(u32 TableId) -{ - if(TableId > TABLE_NUM_MAX - 1){ - return false;//传入的表格ID超出了范围 - } - if(tableHistorInfo[TableId].hwnd == NULL){ - return false; - } -// if(!Table_Search_Num(tableInfo->hwnd) == TABLE_NULL){ -// return false;//该窗口没有表格 -// } - -// u32 beginData = tableInfo->rows * tableInfo->columns * tableInfo->pages;//当前页的起始数据 - u32 dq_height = 0;//记录当前绘制高度 - u32 dq_width = 0;//记录当前绘制的宽度 - HDC hdc = GDD_BeginPaint(tableHistorInfo[TableId].hwnd); - GDD_CleanClient(hdc);//清空表格 - GDD_SetTextColor(hdc,tableHistorInfo[TableId].frontColor);//设置表格文本字体颜色 - //先绘制表头 - for(u32 i = 0;i < tableHistorInfo[TableId].columns;i++){ - if(tableHistorInfo[TableId].tableHeader[i].width == 0){ - tableHistorInfo[TableId].tableHeader[i].width = DEFAULT_WIDTH; - } - //画背景颜色 - GDD_FillRectEx(hdc,&(RECT){dq_width + 2,dq_height + 2,dq_width + tableHistorInfo[TableId].tableHeader[i].width - 2,dq_height + tableHistorInfo[TableId].headerHigh - 2},tableHistorInfo[TableId].bgColor); - //画线 - GDD_DrawRect(hdc,&(RECT){dq_width,dq_height,dq_width + tableHistorInfo[TableId].tableHeader[i].width,dq_height + tableHistorInfo[TableId].headerHigh}); - //画表头内文字 - GDD_DrawText(hdc,tableHistorInfo[TableId].tableHeader[i].attribute,-1,&(RECT){dq_width,dq_height,dq_width + tableHistorInfo[TableId].tableHeader[i].width,dq_height + tableHistorInfo[TableId].headerHigh},DT_VCENTER); - dq_width += tableHistorInfo[TableId].tableHeader[i].width; - } - dq_height += tableHistorInfo[TableId].headerHigh;//表头画完之后,需要把当前最下面的坐标做个记录 - - u32 rowHigh = (tableHistorInfo[TableId].high - tableHistorInfo[TableId].headerHigh) / tableHistorInfo[TableId].rows; - //绘制该页数据 - for(u32 i = 0;i < tableHistorInfo[TableId].rows;i ++){ - dq_width = 0; - for(u32 j = 0;j < tableHistorInfo[TableId].columns;j ++){ - //画背景颜色 - GDD_FillRectEx(hdc,&(RECT){dq_width + 2,dq_height + 2,dq_width + tableHistorInfo[TableId].tableHeader[j].width - 2,dq_height + rowHigh - 2},tableHistorInfo[TableId].bgColor); - //画线 - GDD_DrawRect(hdc,&(RECT){dq_width,dq_height,dq_width + tableHistorInfo[TableId].tableHeader[j].width,dq_height + rowHigh}); - //画表头内文字 - if((tableHistorInfo[TableId].nowNums + i * tableHistorInfo[TableId].columns + j) < tableHistorInfo[TableId].dataLenght){ - GDD_DrawText(hdc,tableHistorInfo[TableId].data[tableHistorInfo[TableId].nowNums + i * tableHistorInfo[TableId].columns + j],-1,&(RECT){dq_width,dq_height,dq_width + tableHistorInfo[TableId].tableHeader[j].width,dq_height + rowHigh},DT_VCENTER); - } - dq_width += tableHistorInfo[TableId].tableHeader[j].width; - } - dq_height += rowHigh; - } - GDD_EndPaint(tableHistorInfo[TableId].hwnd,hdc); - return true; -} - - -////以下都是Demo部分,可以任意更改 -struct TableInfo tableInfo = {0}; - -void Table_Demo(void) -{ - //先创建一个窗口来放置表格 - HWND father_Page = GDD_CreateWindow("father_Window", NULL, 0, 0, 1024, 600, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY, RGB(200, 200, 200), 0, 0, GDD_GetDesktopWindow(NULL)); - - //设置表格信息 - tableInfo.x = 200; - tableInfo.y = 10; - tableInfo.bgColor = RGB(121,133,235);//设置表格背景颜色 - tableInfo.frontColor = RGB(200,200,200);//设置表格字体颜色 - tableInfo.high = 400;//设置表格总高度 - tableInfo.rows = 5;//设置表格一页显示的行数 - tableInfo.headerHigh = 50;//设置表格表头高度 - tableInfo.columns = 3;//设置表格列数 - - //设计表头信息 - tableInfo.tableHeader[0].width = 100; - tableInfo.tableHeader[1].width = 200; - tableInfo.tableHeader[2].width = 400; - strcpy(tableInfo.tableHeader[0].attribute,"姓名"); - strcpy(tableInfo.tableHeader[1].attribute,"班级"); - strcpy(tableInfo.tableHeader[2].attribute,"学号"); - //设置表格内部数据信息 - tableInfo.dataLenght = 27;//表格数据的总长度,表格的数据长度一定要是columns的倍数 - strcpy(tableInfo.data[0],"吴家豪"); - strcpy(tableInfo.data[1],"软件2232"); - strcpy(tableInfo.data[2],"2205223213"); - strcpy(tableInfo.data[3],"吴家豪1"); - strcpy(tableInfo.data[4],"软件2231"); - strcpy(tableInfo.data[5],"2205223212"); - strcpy(tableInfo.data[6],"吴家豪2"); - strcpy(tableInfo.data[7],"软件2230"); - strcpy(tableInfo.data[8],"2205223211"); - strcpy(tableInfo.data[9],"吴家豪"); - strcpy(tableInfo.data[10],"软件2232"); - strcpy(tableInfo.data[12],"2205223213"); - strcpy(tableInfo.data[12],"吴家豪1"); - strcpy(tableInfo.data[13],"软件2231"); - strcpy(tableInfo.data[14],"2205223212"); - strcpy(tableInfo.data[15],"吴家豪2"); - strcpy(tableInfo.data[16],"软件2230"); - strcpy(tableInfo.data[17],"2205223211"); - strcpy(tableInfo.data[18],"吴家豪"); - strcpy(tableInfo.data[19],"软件2232"); - strcpy(tableInfo.data[20],"2205223213"); - strcpy(tableInfo.data[21],"吴家豪1"); - strcpy(tableInfo.data[22],"软件2231"); - strcpy(tableInfo.data[23],"2205223212"); - strcpy(tableInfo.data[24],"吴家豪2"); - strcpy(tableInfo.data[25],"软件2230"); - strcpy(tableInfo.data[26],"2205223211"); - - Table_Create(1,father_Page,&tableInfo); - - DJY_EventDelay(3000 * 1000); - - //修改表格高度 -// Table_Edit_High(1,600); -// Table_Edit_Background_Color(1,RGB(255,255,255)); -// Table_Edit_Front_Color(1,RGB(121,133,235)); -// -// DJY_EventDelay(3000 * 1000); - -// Table_Edit_All(1,&tableInfo); - -// //测试修改表格宽度函数 -// u32 width[4] = {200,300,400}; -// Table_Edit_Width(Home_Page,3,width); -// -// DJY_EventDelay(3000 * 1000); -// -// //测试删除函数 -// Table_Delete(1); -// -// DJY_EventDelay(3000 * 1000); -// -// Table_Create(&tableInfo); -// -// DJY_EventDelay(3000 * 1000); -// -// //测试下一页函数 -// Table_Next_Page(Home_Page); -// -// DJY_EventDelay(3000 * 1000); -// -// //测试上一页函数 -// Table_Last_Page(Home_Page); -// -// DJY_EventDelay(3000 * 1000); -// -// //测试修改数据 -// u8 *new_data[10]; -// new_data[0] = "1"; -// new_data[1] = "2"; -// new_data[2] = "3"; -// new_data[3] = "4"; -// new_data[4] = "5"; -// new_data[5] = "6"; -// new_data[6] = "7"; -// new_data[7] = "8"; -// new_data[8] = "9"; -// new_data[9] = "10"; -// new_data[10] = "11"; -// Table_Edit_Data(Home_Page,11,new_data); -// -// DJY_EventDelay(3000 * 1000); -// -// //测试修改表头和列数 -// u8 *new_head[4]; -// new_head[0] = "姓名"; -// new_head[1] = "班级"; -// new_head[2] = "学号"; -// new_head[3] = "座位号"; -// Table_Edit_Header_And_column(Home_Page,4,new_head); -// while(1){ -// Table_Next_Page(Home_Page); -// DJY_EventDelay(2000 * 1000); -// } -} diff --git a/src/app/Demo/BiaoGe/TableControl.h b/src/app/Demo/BiaoGe/TableControl.h deleted file mode 100644 index c47df90..0000000 --- a/src/app/Demo/BiaoGe/TableControl.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * TableControl.h - * - * Created on: 2024年6月14日 - * Author: wu - */ - -#ifndef APP_DEMO_BIAOGE_TABLECONTROL_H_ -#define APP_DEMO_BIAOGE_TABLECONTROL_H_ - -#include "gdd.h" - -#define TABLE_NULL -99 - -enum -{ - TABLE_NUM_MAX = 5,//可以创建的最大表格数量 - COLUMNS_MAX = 10,//列数的最大值 - ATTRIBUTE_LEN_MAX = 30,//表头的信息最大长度 - DATA_MAX = 100,//记录的最大条数 - DATA_LEN_MAX = 100,//每个格子里数据的最大长度 - DEFAULT_WIDTH = 80,//控件的默认列宽 -}; - -//存储每一个表头的信息 -struct TableHeader -{ - u8 attribute[ATTRIBUTE_LEN_MAX];//表头的文字信息 - u32 width;//该列的宽度,如果没设置(数值为0),系统会设置为默认宽度 -}; - -struct TableInfo -{ - u32 x,y; - u32 bgColor;//表格背景颜色 - u32 frontColor;//表格字体颜色 - u32 high;//表格总高度 - u32 rows;//一页显示的行数,不包括表头 - u32 headerHigh;//表头的高度,记录的高度((总高度-表头高度)/一页显示行数) - u32 columns;//列数 - struct TableHeader tableHeader[COLUMNS_MAX]; - u32 dataLenght;//数据的长度,每一个格子代表一个长度 - u8 data[DATA_MAX][DATA_LEN_MAX];//表格的数据,下一行的数据紧挨着上一行的下一位数组 -}; - -void Table_Demo(void); -bool_t Table_Create(u32 TableId,HWND hParent,struct TableInfo *tableInfo); -bool_t Table_Delete(u32 TableId); -bool_t Table_Last_Page(u32 TableId); -bool_t Table_Next_Page(u32 TableId); -bool_t Table_To_Page(u32 TableId,u32 num); -bool_t Table_slide_grid_Y(u32 TalbeId,s32 Y_Len); -bool_t Table_Edit_All(u32 TableId,struct TableInfo *tableInfo); -bool_t Table_Edit_Header_And_column(u32 TableId,u32 textNum,u8 *text[]); -bool_t Table_Edit_Data(u32 TableId,u32 dataNum,u8 *data[]); -bool_t Table_Edit_Width(u32 TableId,u32 num,u32 width[]); -bool_t Table_Edit_Header_High(u32 tableId,u32 high); -bool_t Table_Edit_High(u32 TableId,u32 high); -bool_t Table_Edit_Background_Color(u32 TableId,u32 bgColor); -bool_t Table_Edit_Front_Color(u32 TableId,u32 frontColor); -//struct TableInfo Table_Search_Info_Copy(u32 TableId); - -#endif /* APP_DEMO_BIAOGE_TABLECONTROL_H_ */ diff --git a/src/app/Demo/TimeEdit/TimeEdit.c b/src/app/Demo/TimeEdit/TimeEdit.c deleted file mode 100644 index f8e1036..0000000 --- a/src/app/Demo/TimeEdit/TimeEdit.c +++ /dev/null @@ -1,437 +0,0 @@ -/* - * TimeEdit.c - * - * Created on: 2024年6月20日 - * Author: wu - */ -#include "gdd_button.h" -#include "TimeEdit.h" - -HWND homePage = NULL; -HWND dayPage = NULL; -HWND lastDayPage = NULL; -struct Time historyTime; -u32 dq_Day_Num = 0;//用来记录当前月的天数 -u32 dq_week = 0;//用来记录当前对应星期 -struct Time reporttime; -HWND timebutton; -enum{ - ButtonInfoNum = 4, - TimeInfoNum = 2, - - Nian = 0, - Yue = 1, - - DayButtonHight = 35, - DayButtonWidht = 35, - DayAllButton = 42,//天的个数,5 * 7 = 35(有35个预留按钮位) - - DayPageY = 113,//天的页面距离控件的y轴位置 - DayPageX = 5,//天的页面距离控件的x轴位置 -}; - -static void TimeEdit_Nian_Sub(void); -static void TimeEdit_Nian_Add(void); -static void TimeEdit_Yue_Sub(void); -static void TimeEdit_Yue_Add(void); -static void TimeEdit_Confirm(void); -static void TimeEdit_Cancel(void); -static u32 Calculate_Week(u32 nian,u32 yue,u32 ri); -static void Draw_Day(void); - -struct TimeEdit_Page_Info time_Info[ButtonInfoNum + TimeInfoNum] = { - { - .Name = "年的<", - .Text = "<", - .x = 5, - .y = 35, - .w = 35, - .h = 35, - .fun_callback = TimeEdit_Nian_Sub, - }, - { - .Name = "月的<", - .Text = "<", - .x = 221, - .y = 35, - .w = 35, - .h = 35, - .fun_callback = TimeEdit_Yue_Sub, - }, - { - .Name = "年的>", - .Text = ">", - .x = 143, - .y = 35, - .w = 35, - .h = 35, - .fun_callback = TimeEdit_Nian_Add, - }, - { - .Name = "月的>", - .Text = ">", - .x = 360, - .y = 35, - .w = 35, - .h = 35, - .fun_callback = TimeEdit_Yue_Add, - }, -// { -// .Name = "日期选择确认", -// .Text = "确认", -// .x = 63, -// .y = 379, -// .w = 76, -// .h = 35, -// .fun_callback = TimeEdit_Confirm, -// }, -// { -// .Name = "日期选择取消", -// .Text = "取消", -// .x = 250, -// .y = 379, -// .w = 76, -// .h = 35, -// .fun_callback = TimeEdit_Cancel, -// }, - { - .Name = "年显示", - .Text = NULL, - .x = 40, - .y = 35, - .w = 104, - .h = 35, - }, - { - .Name = "月显示", - .Text = NULL, - .x = 256, - .y = 35, - .w = 104, - .h = 35, - }, -}; - -//天按下的动作 -static bool_t Button_Day_Change(struct WindowMsg *pMsg) -{ - HWND hwnd; - HDC hdc; - if(pMsg==NULL) - return false; - hwnd = pMsg -> hwnd; - if(hwnd ==NULL) return false; - - - u32 dayNum = 0; - if(historyTime.Yue == 1||historyTime.Yue == 3||historyTime.Yue == 5||historyTime.Yue == 7||historyTime.Yue == 8||historyTime.Yue == 10||historyTime.Yue == 12){ - dayNum = 31; - }else if(historyTime.Yue == 4||historyTime.Yue == 6||historyTime.Yue == 9||historyTime.Yue == 11){ - dayNum = 30; - }else{ - if((historyTime.Nian % 4 == 0 && historyTime.Nian % 100 != 0) || historyTime.Nian % 400 == 0){ - dayNum = 29; - }else{ - dayNum = 28; - } - } - - s16 x = LO16(pMsg->Param2) - historyTime.x - DayPageX; - s16 y = HI16(pMsg->Param2) - historyTime.y - DayPageY; - for(u32 i = 0;i < DayAllButton;i ++){ - if(x <= (59 * (i % 7) + 35)&&x >= (59 * (i % 7))&&y >= (44 * (i / 7))&& y <= (44 * (i / 7) + 35)){ - if((i - dq_week + 1) > 0&&(i - dq_week + 1) <= dayNum){ - historyTime.Ri = i - dq_week + 1; - } - } - } - Draw_Day(); - return true; -} - -//画天的窗口 -static void Draw_Day(){ - u32 dayNum = 0; - if(historyTime.Yue == 1||historyTime.Yue == 3||historyTime.Yue == 5||historyTime.Yue == 7||historyTime.Yue == 8||historyTime.Yue == 10||historyTime.Yue == 12){ - dayNum = 31; - }else if(historyTime.Yue == 4||historyTime.Yue == 6||historyTime.Yue == 9||historyTime.Yue == 11){ - dayNum = 30; - }else{ - if((historyTime.Nian % 4 == 0 && historyTime.Nian % 100 != 0) || historyTime.Nian % 400 == 0){ - dayNum = 29; - }else{ - dayNum = 28; - } - } - HDC hdc = GDD_BeginPaint(dayPage); - GDD_SetBackGroundColor(hdc, RGB(50, 50, 60)); - GDD_CleanClient(hdc); - for(u32 i = 0;i < DayAllButton;i++){ - //如果i在要画的日期间的话才开始画数字 - if(i >= dq_week&& i < dq_week + dayNum){ - if((i - dq_week + 1) == historyTime.Ri){ - GDD_FillRectEx(hdc,&(RECT){59 * (i % 7),44 * (i / 7),59 * (i % 7) + 35,44 * (i / 7) + 35},CN_COLOR_BLUE); - } - u8 zfc[5]; - sprintf(zfc,"%d",i - dq_week + 1); - GDD_DrawText(hdc,zfc,-1,&(RECT){59 * (i % 7),44 * (i / 7),59 * (i % 7) + 35,44 * (i / 7) + 35},DT_VCENTER); - } - } - GDD_EndPaint(dayPage,hdc); -} - -//天按键对应的消息链表 -struct MsgProcTable TimeEditDayMsg[] = - { - {.MsgCode = MSG_TOUCH_DOWN + MSG_ADOPT_NONE, .MsgProc = Button_Day_Change }, // 替换掉按钮的down消息不然up消息出发后会触发按钮自带的down消息 - {.MsgCode = MSG_TOUCH_UP + MSG_ADOPT_NONE, .MsgProc = NULL}, - {.MsgCode = MSG_PAINT , .MsgProc = NULL }, // 这里不选择继承是因为按钮上面肯定会有图片的,继承的意义不大反正最后也会被覆盖所以干脆不画MSG_CLOSE -}; -struct MsgTableLink TimeEditDayMsgTab = - { - .MsgNum = sizeof(TimeEditDayMsg) / sizeof(struct MsgProcTable), - .myTable = (struct MsgProcTable *)&TimeEditDayMsg, -}; - -//画年和月 -static void Draw_Time(u32 flag){ - HDC hdc = GDD_BeginPaint(homePage); - - u32 time; - switch(flag){ - case Nian:time = historyTime.Nian;break; - case Yue:time = historyTime.Yue;break; - } - u8 time_zfc[80]; - u32 ws = 0; - while(time){ - time_zfc[ws ++] = time % 10 + '0'; - time /= 10; - } - time_zfc[ws] = '\0'; - for(u32 i = 0;i < ws / 2;i ++){ - u8 ls = time_zfc[i]; - time_zfc[i] = time_zfc[ws - i - 1]; - time_zfc[ws - i - 1] = ls; - } - u32 dq_ys = GDD_GetBackGroundColor(hdc); - GDD_FillRectEx(hdc,&(RECT){time_Info[ButtonInfoNum + flag].x,time_Info[ButtonInfoNum + flag].y,time_Info[ButtonInfoNum + flag].x + time_Info[ButtonInfoNum + flag].w,time_Info[ButtonInfoNum + flag].y + time_Info[ButtonInfoNum + flag].h},dq_ys); - GDD_DrawText(hdc,time_zfc,-1,&(RECT){time_Info[ButtonInfoNum + flag].x,time_Info[ButtonInfoNum + flag].y,time_Info[ButtonInfoNum + flag].x + time_Info[ButtonInfoNum + flag].w,time_Info[ButtonInfoNum + flag].y + time_Info[ButtonInfoNum + flag].h},DT_VCENTER); - GDD_EndPaint(homePage, hdc); -} - -//确认函数 -void TimeEdit_Confirm(void){ - if(homePage != NULL){ - //执行回调函数(修改目标时间) - historyTime.fun_callback(historyTime.Nian,historyTime.Yue,historyTime.Ri); - GDD_DestroyWindow(homePage); - homePage = NULL; - } -} - -//取消函数 -void TimeEdit_Cancel(void){ - if(homePage != NULL){ - GDD_DestroyWindow(homePage); - homePage = NULL; - } -} - -//年减一 -void TimeEdit_Nian_Sub(void){ - historyTime.Nian --; - Draw_Time(Nian); - historyTime.Ri = 1; - //计算当前月的第一天对应的星期 - dq_week = Calculate_Week(historyTime.Nian,historyTime.Yue,1); - //画日期 - Draw_Day(); -} - -//年加一 -void TimeEdit_Nian_Add(void){ - historyTime.Nian ++; - Draw_Time(Nian); - historyTime.Ri = 1; - //计算当前月的第一天对应的星期 - dq_week = Calculate_Week(historyTime.Nian,historyTime.Yue,1); - - //画日期 - Draw_Day(); -} - -//月减一 -void TimeEdit_Yue_Sub(void){ - historyTime.Ri = 1; - if(historyTime.Yue > 1){ - historyTime.Yue --; - //计算当前月的第一天对应的星期 - dq_week = Calculate_Week(historyTime.Nian,historyTime.Yue,1); - } - else{ - historyTime.Yue = 12; - TimeEdit_Nian_Sub(); - } - Draw_Time(Yue); - //画日期 - Draw_Day(); -} - -//月加一 -void TimeEdit_Yue_Add(void){ - historyTime.Ri = 1; - if(historyTime.Yue < 12){ - historyTime.Yue ++; - //计算当前月的第一天对应的星期 - dq_week = Calculate_Week(historyTime.Nian,historyTime.Yue,1); - } - else{ - historyTime.Yue = 1; - TimeEdit_Nian_Add(); - } - - Draw_Time(Yue); - //画日期 - Draw_Day(); -} - -static u32 Calculate_Week(u32 nian,u32 yue,u32 ri){ - u32 totalDay = 0; - for(u32 i = 1;i < nian;i ++){ - if((i % 4 == 0 && i % 100 != 0) || i % 400 == 0){ - totalDay += 366; - }else{ - totalDay += 365; - } - } - //计算月转化成天 - for(int j = 1; j < yue ; j++){ - if(j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 ){ - totalDay += 31; - }else if( j == 2 ){ - if((nian % 4 == 0 && nian % 100 != 0) || nian % 400 == 0){ - totalDay += 29; - }else{ - totalDay += 28; - } - }else{ - totalDay += 30; - } - } - //计算天 - totalDay += ri; - return totalDay % 7; -} - -static bool_t Button_Down(struct WindowMsg *pMsg) -{ - HWND hwnd; - HDC hdc; - if(pMsg==NULL) - return false; - hwnd = pMsg -> hwnd; - if(hwnd ==NULL) return false; - struct TimeEdit_Page_Info *data = GDD_GetWindowPrivateData(hwnd); - data->fun_callback(); - return true; -} - -static bool_t Button_Paint(struct WindowMsg *pMsg) -{ - HWND hwnd; - HDC hdc; - if(pMsg==NULL) - return false; - hwnd = pMsg -> hwnd; - if(hwnd ==NULL) return false; - struct TimeEdit_Page_Info *data = GDD_GetWindowPrivateData(hwnd); - if(data != NULL){ - hdc = GDD_BeginPaint(hwnd); - GDD_DrawText(hdc,data->Text,-1,&(RECT){0,0,data->w,data->h},DT_VCENTER); - GDD_EndPaint(hwnd, hdc); - } - return true; -} - -struct MsgProcTable TimeEditMsg[] = - { - {.MsgCode = MSG_TOUCH_DOWN + MSG_ADOPT_NONE, .MsgProc = Button_Down }, // 替换掉按钮的down消息不然up消息出发后会触发按钮自带的down消息 - {.MsgCode = MSG_TOUCH_UP + MSG_ADOPT_NONE, .MsgProc = NULL}, - {.MsgCode = MSG_PAINT , .MsgProc = Button_Paint }, // 这里不选择继承是因为按钮上面肯定会有图片的,继承的意义不大反正最后也会被覆盖所以干脆不画MSG_CLOSE -}; -struct MsgTableLink TimeEditMsgTab = - { - .MsgNum = sizeof(TimeEditMsg) / sizeof(struct MsgProcTable), - .myTable = (struct MsgProcTable *)&TimeEditMsg, -}; - -void TimeEdit_Create(HWND hParent,struct Time time){ - //把信息都置入全局变量保存 - historyTime.Nian = time.Nian; - historyTime.Yue = time.Yue; - historyTime.Ri = time.Ri; - historyTime.bgColor = time.bgColor; - historyTime.x = time.x; - historyTime.y = time.y; - historyTime.fun_callback = time.fun_callback; - - homePage = GDD_CreateWindow("TimeEdit_Page", NULL, historyTime.x, historyTime.y, 400, 380, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY, historyTime.bgColor, 0, 0, hParent); - HDC hdc = GDD_BeginPaint(homePage); - GDD_SetBackGroundColor(hdc, historyTime.bgColor); - GDD_CleanClient(hdc); - GDD_TextOut(hdc,74,0,"年",-1); - GDD_TextOut(hdc,301,0,"月",-1); - Draw_Time(Nian); - Draw_Time(Yue); - //把日对应的星期打印出来 - u8 ls_text[7][3] = {"日","一","二","三","四","五","六"}; - for(u32 i = 0;i < 7;i ++){ - GDD_TextOut(hdc,5 + (59 * i),76,ls_text[i],-1); - } - GDD_EndPaint(homePage,hdc); - - for(u32 i = 0;i < ButtonInfoNum;i ++){ - Widget_CreateButton(time_Info[i].Name,BS_NORMAL | WS_UNFILL,time_Info[i].x,time_Info[i].y,time_Info[i].w,time_Info[i].h,homePage,0,&time_Info[i],&TimeEditMsgTab); - } - - //计算当前月的第一天对应的星期 - dq_week = Calculate_Week(historyTime.Nian,historyTime.Yue,1); - - //天的画图 - dayPage = GDD_CreateWindow("TimeEdit_Day_Page", &TimeEditDayMsgTab, DayPageX, DayPageY, 390, 259, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY, historyTime.bgColor, 0, 0, homePage); - - Draw_Day(); -} - -void TimeEditbutton_Create(HWND hParent,RECT rect){ -// timebutton = Widget_CreateButton("curvereportTime", BS_NORMAL | WS_UNFILL, rect.left, rect.top, GDD_RectW(&rect), GDD_RectH(&rect), hParent, 0, 0, &timeEDITbuttonTab); - - reporttime.Nian = 2024; - reporttime.Yue = 6; - reporttime.Ri = 26; - reporttime.x = rect.left; - reporttime.y = rect.top; - reporttime.bgColor = RGB(50,50,60); - TimeEdit_Create(hParent,reporttime); - -// reporttime.fun_callback = my_fun; -} -//下面的是demo -//当控件按下确定键后,将会调用如下内容,并返回年、月、日 -//void my_fun(u32 Nian,u32 Yue,u32 Ri) -//{ -// printf("%d %d %d\r\n",Nian,Yue,Ri); -//} -// -//void TimeEdit_Demo(void){ -// struct Time time; -// time.Nian = 2019; -// time.Yue = 1; -// time.Ri = 1; -// time.x = 200; -// time.y = 50; -// time.bgColor = RGB(100,100,100); -// time.fun_callback = my_fun; -// TimeEdit_Create(GDD_GetDesktopWindow(NULL),time); -//} diff --git a/src/app/Demo/TimeEdit/TimeEdit.h b/src/app/Demo/TimeEdit/TimeEdit.h deleted file mode 100644 index 5c66312..0000000 --- a/src/app/Demo/TimeEdit/TimeEdit.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * TimeEdit.h - * - * Created on: 2024年6月20日 - * Author: wu - */ - -#ifndef APP_DEMO_TIMEEDIT_TIMEEDIT_H_ -#define APP_DEMO_TIMEEDIT_TIMEEDIT_H_ - -#include "gdd.h" - -typedef void (*fun_callback_time)(u32 Nian,u32 Yue,u32 Ri); -typedef void (*fun_callback_button)(void); - -struct Time{ - u32 Nian; - u32 Yue; - u32 Ri; - u32 bgColor;//时间控件的背景颜色 - u32 x,y;//时间控件生成的横纵坐标轴 - fun_callback_time fun_callback;//设置一个回调函数,当控件点击确认时,通过这个函数来获取所设置的时间 -}; - -struct TimeEdit_Page_Info{ - u8 *Name; - u8 *Text; - u32 x,y,w,h; - fun_callback_button fun_callback; -}; - -void TimeEdit_Demo(void); -void TimeEditbutton_Create(HWND hParent,RECT rect); - - -#endif /* APP_DEMO_TIMEEDIT_TIMEEDIT_H_ */ diff --git a/src/app/Module/TableControl.c b/src/app/Module/TableControl.c new file mode 100644 index 0000000..ee13603 --- /dev/null +++ b/src/app/Module/TableControl.c @@ -0,0 +1,738 @@ +/* + * TableControl.c + * + * Created on: 2024年6月14日 + * Author: wu + */ + +#include "TableControl.h" +static bool_t Table_Draw(u32 TableId); +struct TableHistorInfo +{ + HWND hwnd; + u32 x,y; + u32 bgColor;//表格背景颜色 + u32 frontColor;//表格字体颜色 + u32 high;//表格总高度 + u32 rows;//一页显示的行数,不包括表头 + u32 pages;//当前显示的页数 + s32 nowNums;//当前从第几个开始显示 + u32 headerHigh;//表头的高度,记录的高度((总高度-表头高度)/一页显示行数) + u32 columns;//列数 + struct TableHeader tableHeader[COLUMNS_MAX]; + u32 dataLenght;//数据的长度,每一个格子代表一个长度 + u8 data[DATA_MAX][DATA_LEN_MAX];//表格的数据,下一行的数据紧挨着上一行的下一位数组 +}; + +//历史表格信息 +struct TableHistorInfo tableHistorInfo[TABLE_NUM_MAX] = {0}; + +static struct TableInfo TableHistorInfo_To_TableInfo(u32 TableId){ + struct TableInfo tableInfo = {0}; + if(TableId > TABLE_NUM_MAX - 1){ + return tableInfo; + } + + tableInfo.x = tableHistorInfo[TableId].x; + tableInfo.y = tableHistorInfo[TableId].y; + tableInfo.bgColor = tableHistorInfo[TableId].bgColor; + tableInfo.frontColor = tableHistorInfo[TableId].frontColor; + tableInfo.high = tableHistorInfo[TableId].high; + tableInfo.rows = tableHistorInfo[TableId].rows; + tableInfo.headerHigh = tableHistorInfo[TableId].headerHigh; + tableInfo.columns = tableHistorInfo[TableId].columns; + tableInfo.dataLenght = tableHistorInfo[TableId].dataLenght; + memcpy(tableInfo.tableHeader,tableHistorInfo[TableId].tableHeader,sizeof(struct TableHeader) * COLUMNS_MAX); + for(u32 i = 0;i < tableHistorInfo[TableId].dataLenght;i ++){ + strcpy(tableInfo.data[i],tableHistorInfo[TableId].data[i]); + } + + return tableInfo; +} + +static bool_t TableInfo_To_TableHistorInfo(u32 TableId,struct TableInfo *tableInfo){ + if(TableId > TABLE_NUM_MAX - 1){ + return false; + } + tableHistorInfo[TableId].x = tableInfo->x; + tableHistorInfo[TableId].y = tableInfo->y; + tableHistorInfo[TableId].bgColor = tableInfo->bgColor; + tableHistorInfo[TableId].frontColor = tableInfo->frontColor; + tableHistorInfo[TableId].high = tableInfo->high; + tableHistorInfo[TableId].rows = tableInfo->rows; + tableHistorInfo[TableId].headerHigh = tableInfo->headerHigh; + tableHistorInfo[TableId].columns = tableInfo->columns; + memcpy(tableHistorInfo[TableId].tableHeader,tableInfo->tableHeader,sizeof(struct TableHeader) * COLUMNS_MAX); + tableHistorInfo[TableId].dataLenght = tableInfo->dataLenght; + for(u32 i = 0;i < tableHistorInfo[TableId].dataLenght;i ++){ +// memcpy(tableHistorInfo[TableId].data[i],tableInfo->data[i],sizeof(u8) * DATA_LEN_MAX); + strcpy(tableHistorInfo[TableId].data[i],tableInfo->data[i]); + } + + return true; +} + +// ============================================================================= +// 功能:寻找表格,并返回历史信息地址(这个由于是直接返回历史表格指针,所以最好不要随意调用) +// 参数:TableId:所要搜索的窗口信息ID +// 返回:tableHistorInfo[i]:寻找到的目标表格结构体指针,NULL:没有找到目标表格 +// ============================================================================= +//static struct TableHistorInfo* Table_Search_Info(u32 TableId){ +// if(TableId > TABLE_NUM_MAX - 1){ +// return NULL; +// } +// if(tableHistorInfo[TableId].hwnd == NULL){ +// return NULL; +// } +// return &tableHistorInfo[TableId]; +//} + +// ============================================================================= +// 功能:寻找表格,并返回复制的信息(可以用来统一修改表格)//先别用 +// 参数:TableId:所要搜索的窗口Id +// 返回:tableHistorInfo:寻找到的目标表格结构体的复制,NULL:没有找到目标表格 +// ============================================================================= +//struct TableInfo Table_Search_Info_Copy(u32 TableId){ +// struct TableInfo tableInfo = {0}; +// if(TableId > TABLE_NUM_MAX - 1){ +// return tableInfo; +// } +// if(tableHistorInfo[TableId].hwnd == NULL){ +// return tableInfo; +// } +// tableInfo = TableHistorInfo_To_TableInfo(TableId); +// +// return tableInfo; +//} + +// ============================================================================= +// 功能:搜索一个空的表格位置,用来存储历史表格信息 +// 参数:无 +// 返回:i:返回的目标表格的下标,TABLE_NULL:表格控件满了需要增大TABLENUMMAX数量 +// ============================================================================= +//static u32 Table_Search_NULL(void){ +// for(u32 i = 0;i < TABLE_NUM_MAX;i ++){ +// if(tableHistorInfo[i] == NULL||tableHistorInfo == 0){ +// return i; +// } +// } +// return TABLE_NULL; +//} + +static POINT first_pt = {0}; +static POINT old_pt = {0}; +//bool_t MoveStatus = false; + +static bool_t down(struct WindowMsg *pMsg) +{ + u8* data; + HWND hwnd; + HDC hdc; + if(pMsg==NULL) + return false; + hwnd = pMsg -> hwnd; + if(hwnd ==NULL) return false; + first_pt.x = (u16)(pMsg->Param2 & 0xFFFF); + first_pt.y = (u16)((pMsg->Param2 >> 16) & 0xFFFF); + old_pt.y = first_pt.y; +// // 屏幕坐标转窗口坐标 +// GDD_ScreenToWindow(hwnd,&first_pt,1); + + return true; +} + +static bool_t move(struct WindowMsg *pMsg) +{ + u8* data; + HWND hwnd; + HDC hdc; + if(pMsg==NULL) + return false; + hwnd = pMsg -> hwnd; + POINT new_pt = {0}; + // 算出触摸点坐标 + new_pt.x = (u16)(pMsg->Param2 & 0xFFFF); + new_pt.y = (u16)((pMsg->Param2 >> 16) & 0xFFFF); + u32 tableId = GDD_GetWindowPrivateData(hwnd); + //如果有往相反的方向滑动,则重置按下的坐标 + if((new_pt.y < old_pt.y&&first_pt.y < new_pt.y)||(new_pt.y < first_pt.y&&old_pt.y < new_pt.y)){ + first_pt.y = old_pt.y; + } + old_pt.y = new_pt.y; + new_pt.y = first_pt.y - new_pt.y; +// // 屏幕坐标转窗口坐标 +// GDD_ScreenToWindow(hwnd, &new_pt, 1); + + Table_slide_grid_Y(tableId,new_pt.y); + + return true; +} + + +struct MsgProcTable homeMsg[] = + { + {.MsgCode = MSG_TOUCH_MOVE + MSG_ADOPT_NONE, .MsgProc = move}, + {.MsgCode = MSG_TOUCH_DOWN + MSG_ADOPT_NONE, .MsgProc = down }, + {.MsgCode = MSG_TOUCH_UP + MSG_ADOPT_NONE, .MsgProc = NULL}, + {.MsgCode = MSG_PAINT , .MsgProc = NULL }, +}; +// 用户定义的消息链表(登录按钮相关的) +struct MsgTableLink homeMsgTab = + { + .MsgNum = sizeof(homeMsg) / sizeof(struct MsgProcTable), + .myTable = (struct MsgProcTable *)&homeMsg, +}; + +// ============================================================================= +// 功能:创建表格,并进行绘制(如果后续需要通过代码对目标表格进行修改才需要创建) +// 参数:TableId:表格的ID(当做历史表格数组的下标,以0开始,头文件可以修改表格的最大数量),tableInfo:表格信息 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Create(u32 TableId,HWND hParent,struct TableInfo *tableInfo) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(hParent == NULL){ + return false;//窗口没有定义 + } + if(tableInfo->columns > COLUMNS_MAX||tableInfo->dataLenght > DATA_MAX){ + return false;//定义的列数超过了列数最大值,或者数据长度大于定义的最大支持数据长度 + } + if(tableHistorInfo[TableId].hwnd != NULL){ + return false;//该窗口已经创建过表格 + } + + u32 width = 0; + + //把每一列的宽度加起来,如果该列的宽度为<=的话,则设置为默认宽度 + for(u32 i = 0;i < tableInfo->columns;i ++){ + width += tableInfo->tableHeader[i].width?tableInfo->tableHeader[i].width:DEFAULT_WIDTH; + } + + //以表格的下标、高度和宽度来命名表格,防止重名 + u8 tableName[100]; + sprintf(tableName,"table_Window%d%d%d",TableId,tableInfo->high,width); + tableHistorInfo[TableId].hwnd = GDD_CreateWindow(tableName,&homeMsgTab,tableInfo->x,tableInfo->y, width, tableInfo->high, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY, RGB(200, 200, 200), 0, TableId,hParent); + TableInfo_To_TableHistorInfo(TableId,tableInfo); + + Table_Draw(TableId); + return true; +} + +// ============================================================================= +// 功能:删除表格 +// 参数:TableId:目标表格Id +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Delete(u32 TableId) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + GDD_DestroyWindow(tableHistorInfo[TableId].hwnd); + tableHistorInfo[TableId].hwnd = NULL; + + return true; +} + +// ============================================================================= +// 功能:修改表格全部数据 +// 参数:tableInfo:表格信息 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Edit_All(u32 TableId,struct TableInfo *tableInfo) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + //更新全部信息 + TableInfo_To_TableHistorInfo(TableId,tableInfo); + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:修改表头文字,textNum还会修改表格列数 +// 参数:TalbeId:目标表格窗口Id。textNum:表头文本个数(表格的列数是依据表头个数来定,因此这里传参会修改表格的列数)。text:表头文本 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Edit_Header_And_column(u32 TableId,u32 textNum,u8 *text[]) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + //复制数据 + tableHistorInfo[TableId].columns = textNum; + for(u32 i = 0;i < tableHistorInfo[TableId].columns;i ++){ + strcpy(tableHistorInfo[TableId].tableHeader[i].attribute,text[i]); + } + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:修改表格数据,并将页数变为第一页 +// 参数:TableId:目标表格窗口Id dataNum:数据个数 data:数据数组 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Edit_Data(u32 TableId,u32 dataNum,u8 *data[]) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + //复制数据 + tableHistorInfo[TableId].columns = dataNum; + for(u32 i = 0;i < tableHistorInfo[TableId].columns;i ++){ + strcpy(tableHistorInfo[TableId].tableHeader[i].attribute,data[i]); + } + + //页面初始化为第一页 + tableHistorInfo[TableId].pages = 0; + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:修改表头高度 +// 参数:tableId:目标表格窗口Id high:修改表格高度 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Edit_Header_High(u32 TableId,u32 high) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + //修改表格高度 + tableHistorInfo[TableId].headerHigh = high; + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:修改表格总高度(表格除去表头的其他行的高度计算公式为:(总高度-表头高度)/一页显示行数 +// 参数:hwnd:目标表格窗口 high:修改表格高度 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Edit_High(u32 TableId,u32 high) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + //修改表格高度 + tableHistorInfo[TableId].high = high; + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:修改表格的背景颜色 +// 参数:hwnd:目标表格窗口 bgColor:背景颜色 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Edit_Background_Color(u32 TableId,u32 bgColor) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + //修改表格高度 + tableHistorInfo[TableId].bgColor = bgColor; + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:修改表格的文本颜色 +// 参数:hwnd:目标表格窗口 frontColor:文本颜色 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Edit_Front_Color(u32 TableId,u32 frontColor) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + //修改表格高度 + tableHistorInfo[TableId].frontColor = frontColor; + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:跳转表格至上一页 +// 参数:hwnd:目标表格窗口 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Last_Page(u32 TableId) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + if(tableHistorInfo[TableId].pages == 0){ + if(tableHistorInfo[TableId].nowNums != 0){ + tableHistorInfo[TableId].nowNums = 0; + Table_Draw(TableId); + } + return false;//这是第一页,不能再进入上一页了 + } + + //如果是页面循环才需要算总的页面数 +// u32 onePageData = tableHistorInfo[xb].rows * tableHistorInfo[xb].columns;//一页的数据 +// u32 jw = (tableHistorInfo[xb].dataLenght % onePageData)?1:0; +// u32 pageNums = tableHistorInfo[xb].dataLenght / onePageData + jw;//如果整除不尽就加一 + tableHistorInfo[TableId].pages --; + tableHistorInfo[TableId].nowNums = tableHistorInfo[TableId].pages * (tableHistorInfo[TableId].rows * tableHistorInfo[TableId].columns);//当前显示的初始数据变成目标页数的第一个 + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:跳转表格至下一页 +// 参数:hwnd:目标表格窗口 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Next_Page(u32 TableId) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + u32 onePageData = tableHistorInfo[TableId].rows * tableHistorInfo[TableId].columns;//一页的数据 + u32 jw = (tableHistorInfo[TableId].dataLenght % onePageData)?1:0; + u32 pageNums = tableHistorInfo[TableId].dataLenght / onePageData + jw;//如果整除不尽就加一 + if(tableHistorInfo[TableId].pages + 1 == pageNums){ +// if()//这里要加 + return false;//这是最后一页,不能进入下一页了 + } +// tableHistorInfo[xb].pages = (tableHistorInfo[xb].pages + 1) % pageNums;//这是循环的方法 + tableHistorInfo[TableId].pages ++; + tableHistorInfo[TableId].nowNums = tableHistorInfo[TableId].pages * (tableHistorInfo[TableId].rows * tableHistorInfo[TableId].columns);//当前显示的初始数据变成目标页数的第一个 + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:传入一个数值,图表根据数值滑动,每次变动都是按照格子来滑动,不会显示一半之类的 +// 参数:hwnd:目标表格窗口 Y_Len:Y轴滑动距离 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_slide_grid_Y(u32 TableId,s32 Y_Len) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + s32 dataHigh = (tableHistorInfo[TableId].high - tableHistorInfo[TableId].headerHigh) / tableHistorInfo[TableId].rows; + s32 slideNum = Y_Len / dataHigh; + tableHistorInfo[TableId].nowNums += slideNum * tableHistorInfo[TableId].columns; + + //处理越界 + if(tableHistorInfo[TableId].nowNums < 0){ + tableHistorInfo[TableId].nowNums = 0; + } + if(tableHistorInfo[TableId].nowNums >= tableHistorInfo[TableId].dataLenght - tableHistorInfo[TableId].columns){ + tableHistorInfo[TableId].nowNums = tableHistorInfo[TableId].dataLenght - tableHistorInfo[TableId].columns; + } + + + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:跳转至目标页数(如果页数不存在会失败) +// 参数:hwnd:目标表格窗口 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_To_Page(u32 TableId,u32 num) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + u32 onePageData = tableHistorInfo[TableId].rows * tableHistorInfo[TableId].columns;//一页的数据 + u32 jw = (tableHistorInfo[TableId].dataLenght % onePageData)?1:0; + u32 pageNums = tableHistorInfo[TableId].dataLenght / onePageData + jw;//如果整除不尽就加一 + if(num >= pageNums||num < 0){ + return false;//输入页数超出范围 + } + tableHistorInfo[TableId].pages = num; + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:修改表格列宽(修改后的总列宽以创建时的为基准 +// 参数:hwnd:目标表格窗口。num:要修改的数字。width[]:表格宽度数组 +// 返回:true:成功,false:失败 +// ============================================================================= +bool_t Table_Edit_Width(u32 TableId,u32 num,u32 width[]) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } + + if(num > tableHistorInfo[TableId].columns){ + return false;//如果num大于表格列数,则返回false + } + //修改宽度,只从头到尾修改num个 + for(u32 i = 0;i < num;i ++){ + tableHistorInfo[TableId].tableHeader[i].width = width[i]; + } + + Table_Draw(TableId); + + return true; +} + +// ============================================================================= +// 功能:根据表格信息绘制表格(如果是一次性表格无需修改可以直接调用,因为这个函数的表格信息不能存到历史表格中,后续如需要通过代码或操控修改表格则通过Table_Create函数创建) +// 参数:TableId:要绘制的表格ID +// 返回:true:成功,false:失败 +// ============================================================================= +static bool_t Table_Draw(u32 TableId) +{ + if(TableId > TABLE_NUM_MAX - 1){ + return false;//传入的表格ID超出了范围 + } + if(tableHistorInfo[TableId].hwnd == NULL){ + return false; + } +// if(!Table_Search_Num(tableInfo->hwnd) == TABLE_NULL){ +// return false;//该窗口没有表格 +// } + +// u32 beginData = tableInfo->rows * tableInfo->columns * tableInfo->pages;//当前页的起始数据 + u32 dq_height = 0;//记录当前绘制高度 + u32 dq_width = 0;//记录当前绘制的宽度 + HDC hdc = GDD_BeginPaint(tableHistorInfo[TableId].hwnd); + GDD_CleanClient(hdc);//清空表格 + GDD_SetTextColor(hdc,tableHistorInfo[TableId].frontColor);//设置表格文本字体颜色 + //先绘制表头 + for(u32 i = 0;i < tableHistorInfo[TableId].columns;i++){ + if(tableHistorInfo[TableId].tableHeader[i].width == 0){ + tableHistorInfo[TableId].tableHeader[i].width = DEFAULT_WIDTH; + } + //画背景颜色 + GDD_FillRectEx(hdc,&(RECT){dq_width + 2,dq_height + 2,dq_width + tableHistorInfo[TableId].tableHeader[i].width - 2,dq_height + tableHistorInfo[TableId].headerHigh - 2},tableHistorInfo[TableId].bgColor); + //画线 + GDD_DrawRect(hdc,&(RECT){dq_width,dq_height,dq_width + tableHistorInfo[TableId].tableHeader[i].width,dq_height + tableHistorInfo[TableId].headerHigh}); + //画表头内文字 + GDD_DrawText(hdc,tableHistorInfo[TableId].tableHeader[i].attribute,-1,&(RECT){dq_width,dq_height,dq_width + tableHistorInfo[TableId].tableHeader[i].width,dq_height + tableHistorInfo[TableId].headerHigh},DT_VCENTER); + dq_width += tableHistorInfo[TableId].tableHeader[i].width; + } + dq_height += tableHistorInfo[TableId].headerHigh;//表头画完之后,需要把当前最下面的坐标做个记录 + + u32 rowHigh = (tableHistorInfo[TableId].high - tableHistorInfo[TableId].headerHigh) / tableHistorInfo[TableId].rows; + //绘制该页数据 + for(u32 i = 0;i < tableHistorInfo[TableId].rows;i ++){ + dq_width = 0; + for(u32 j = 0;j < tableHistorInfo[TableId].columns;j ++){ + //画背景颜色 + GDD_FillRectEx(hdc,&(RECT){dq_width + 2,dq_height + 2,dq_width + tableHistorInfo[TableId].tableHeader[j].width - 2,dq_height + rowHigh - 2},tableHistorInfo[TableId].bgColor); + //画线 + GDD_DrawRect(hdc,&(RECT){dq_width,dq_height,dq_width + tableHistorInfo[TableId].tableHeader[j].width,dq_height + rowHigh}); + //画表头内文字 + if((tableHistorInfo[TableId].nowNums + i * tableHistorInfo[TableId].columns + j) < tableHistorInfo[TableId].dataLenght){ + GDD_DrawText(hdc,tableHistorInfo[TableId].data[tableHistorInfo[TableId].nowNums + i * tableHistorInfo[TableId].columns + j],-1,&(RECT){dq_width,dq_height,dq_width + tableHistorInfo[TableId].tableHeader[j].width,dq_height + rowHigh},DT_VCENTER); + } + dq_width += tableHistorInfo[TableId].tableHeader[j].width; + } + dq_height += rowHigh; + } + GDD_EndPaint(tableHistorInfo[TableId].hwnd,hdc); + return true; +} + + +////以下都是Demo部分,可以任意更改 +struct TableInfo tableInfo = {0}; + +void Table_Demo(void) +{ + //先创建一个窗口来放置表格 + HWND father_Page = GDD_CreateWindow("father_Window", NULL, 0, 0, 1024, 600, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY, RGB(200, 200, 200), 0, 0, GDD_GetDesktopWindow(NULL)); + + //设置表格信息 + tableInfo.x = 200; + tableInfo.y = 10; + tableInfo.bgColor = RGB(121,133,235);//设置表格背景颜色 + tableInfo.frontColor = RGB(200,200,200);//设置表格字体颜色 + tableInfo.high = 400;//设置表格总高度 + tableInfo.rows = 5;//设置表格一页显示的行数 + tableInfo.headerHigh = 50;//设置表格表头高度 + tableInfo.columns = 3;//设置表格列数 + + //设计表头信息 + tableInfo.tableHeader[0].width = 100; + tableInfo.tableHeader[1].width = 200; + tableInfo.tableHeader[2].width = 400; + strcpy(tableInfo.tableHeader[0].attribute,"姓名"); + strcpy(tableInfo.tableHeader[1].attribute,"班级"); + strcpy(tableInfo.tableHeader[2].attribute,"学号"); + //设置表格内部数据信息 + tableInfo.dataLenght = 27;//表格数据的总长度,表格的数据长度一定要是columns的倍数 + strcpy(tableInfo.data[0],"吴家豪"); + strcpy(tableInfo.data[1],"软件2232"); + strcpy(tableInfo.data[2],"2205223213"); + strcpy(tableInfo.data[3],"吴家豪1"); + strcpy(tableInfo.data[4],"软件2231"); + strcpy(tableInfo.data[5],"2205223212"); + strcpy(tableInfo.data[6],"吴家豪2"); + strcpy(tableInfo.data[7],"软件2230"); + strcpy(tableInfo.data[8],"2205223211"); + strcpy(tableInfo.data[9],"吴家豪"); + strcpy(tableInfo.data[10],"软件2232"); + strcpy(tableInfo.data[12],"2205223213"); + strcpy(tableInfo.data[12],"吴家豪1"); + strcpy(tableInfo.data[13],"软件2231"); + strcpy(tableInfo.data[14],"2205223212"); + strcpy(tableInfo.data[15],"吴家豪2"); + strcpy(tableInfo.data[16],"软件2230"); + strcpy(tableInfo.data[17],"2205223211"); + strcpy(tableInfo.data[18],"吴家豪"); + strcpy(tableInfo.data[19],"软件2232"); + strcpy(tableInfo.data[20],"2205223213"); + strcpy(tableInfo.data[21],"吴家豪1"); + strcpy(tableInfo.data[22],"软件2231"); + strcpy(tableInfo.data[23],"2205223212"); + strcpy(tableInfo.data[24],"吴家豪2"); + strcpy(tableInfo.data[25],"软件2230"); + strcpy(tableInfo.data[26],"2205223211"); + + Table_Create(1,father_Page,&tableInfo); + + DJY_EventDelay(3000 * 1000); + + //修改表格高度 +// Table_Edit_High(1,600); +// Table_Edit_Background_Color(1,RGB(255,255,255)); +// Table_Edit_Front_Color(1,RGB(121,133,235)); +// +// DJY_EventDelay(3000 * 1000); + +// Table_Edit_All(1,&tableInfo); + +// //测试修改表格宽度函数 +// u32 width[4] = {200,300,400}; +// Table_Edit_Width(Home_Page,3,width); +// +// DJY_EventDelay(3000 * 1000); +// +// //测试删除函数 +// Table_Delete(1); +// +// DJY_EventDelay(3000 * 1000); +// +// Table_Create(&tableInfo); +// +// DJY_EventDelay(3000 * 1000); +// +// //测试下一页函数 +// Table_Next_Page(Home_Page); +// +// DJY_EventDelay(3000 * 1000); +// +// //测试上一页函数 +// Table_Last_Page(Home_Page); +// +// DJY_EventDelay(3000 * 1000); +// +// //测试修改数据 +// u8 *new_data[10]; +// new_data[0] = "1"; +// new_data[1] = "2"; +// new_data[2] = "3"; +// new_data[3] = "4"; +// new_data[4] = "5"; +// new_data[5] = "6"; +// new_data[6] = "7"; +// new_data[7] = "8"; +// new_data[8] = "9"; +// new_data[9] = "10"; +// new_data[10] = "11"; +// Table_Edit_Data(Home_Page,11,new_data); +// +// DJY_EventDelay(3000 * 1000); +// +// //测试修改表头和列数 +// u8 *new_head[4]; +// new_head[0] = "姓名"; +// new_head[1] = "班级"; +// new_head[2] = "学号"; +// new_head[3] = "座位号"; +// Table_Edit_Header_And_column(Home_Page,4,new_head); +// while(1){ +// Table_Next_Page(Home_Page); +// DJY_EventDelay(2000 * 1000); +// } +} diff --git a/src/app/Module/TableControl.h b/src/app/Module/TableControl.h new file mode 100644 index 0000000..c47df90 --- /dev/null +++ b/src/app/Module/TableControl.h @@ -0,0 +1,63 @@ +/* + * TableControl.h + * + * Created on: 2024年6月14日 + * Author: wu + */ + +#ifndef APP_DEMO_BIAOGE_TABLECONTROL_H_ +#define APP_DEMO_BIAOGE_TABLECONTROL_H_ + +#include "gdd.h" + +#define TABLE_NULL -99 + +enum +{ + TABLE_NUM_MAX = 5,//可以创建的最大表格数量 + COLUMNS_MAX = 10,//列数的最大值 + ATTRIBUTE_LEN_MAX = 30,//表头的信息最大长度 + DATA_MAX = 100,//记录的最大条数 + DATA_LEN_MAX = 100,//每个格子里数据的最大长度 + DEFAULT_WIDTH = 80,//控件的默认列宽 +}; + +//存储每一个表头的信息 +struct TableHeader +{ + u8 attribute[ATTRIBUTE_LEN_MAX];//表头的文字信息 + u32 width;//该列的宽度,如果没设置(数值为0),系统会设置为默认宽度 +}; + +struct TableInfo +{ + u32 x,y; + u32 bgColor;//表格背景颜色 + u32 frontColor;//表格字体颜色 + u32 high;//表格总高度 + u32 rows;//一页显示的行数,不包括表头 + u32 headerHigh;//表头的高度,记录的高度((总高度-表头高度)/一页显示行数) + u32 columns;//列数 + struct TableHeader tableHeader[COLUMNS_MAX]; + u32 dataLenght;//数据的长度,每一个格子代表一个长度 + u8 data[DATA_MAX][DATA_LEN_MAX];//表格的数据,下一行的数据紧挨着上一行的下一位数组 +}; + +void Table_Demo(void); +bool_t Table_Create(u32 TableId,HWND hParent,struct TableInfo *tableInfo); +bool_t Table_Delete(u32 TableId); +bool_t Table_Last_Page(u32 TableId); +bool_t Table_Next_Page(u32 TableId); +bool_t Table_To_Page(u32 TableId,u32 num); +bool_t Table_slide_grid_Y(u32 TalbeId,s32 Y_Len); +bool_t Table_Edit_All(u32 TableId,struct TableInfo *tableInfo); +bool_t Table_Edit_Header_And_column(u32 TableId,u32 textNum,u8 *text[]); +bool_t Table_Edit_Data(u32 TableId,u32 dataNum,u8 *data[]); +bool_t Table_Edit_Width(u32 TableId,u32 num,u32 width[]); +bool_t Table_Edit_Header_High(u32 tableId,u32 high); +bool_t Table_Edit_High(u32 TableId,u32 high); +bool_t Table_Edit_Background_Color(u32 TableId,u32 bgColor); +bool_t Table_Edit_Front_Color(u32 TableId,u32 frontColor); +//struct TableInfo Table_Search_Info_Copy(u32 TableId); + +#endif /* APP_DEMO_BIAOGE_TABLECONTROL_H_ */ diff --git a/src/app/Module/TimeEdit.c b/src/app/Module/TimeEdit.c new file mode 100644 index 0000000..f8e1036 --- /dev/null +++ b/src/app/Module/TimeEdit.c @@ -0,0 +1,437 @@ +/* + * TimeEdit.c + * + * Created on: 2024年6月20日 + * Author: wu + */ +#include "gdd_button.h" +#include "TimeEdit.h" + +HWND homePage = NULL; +HWND dayPage = NULL; +HWND lastDayPage = NULL; +struct Time historyTime; +u32 dq_Day_Num = 0;//用来记录当前月的天数 +u32 dq_week = 0;//用来记录当前对应星期 +struct Time reporttime; +HWND timebutton; +enum{ + ButtonInfoNum = 4, + TimeInfoNum = 2, + + Nian = 0, + Yue = 1, + + DayButtonHight = 35, + DayButtonWidht = 35, + DayAllButton = 42,//天的个数,5 * 7 = 35(有35个预留按钮位) + + DayPageY = 113,//天的页面距离控件的y轴位置 + DayPageX = 5,//天的页面距离控件的x轴位置 +}; + +static void TimeEdit_Nian_Sub(void); +static void TimeEdit_Nian_Add(void); +static void TimeEdit_Yue_Sub(void); +static void TimeEdit_Yue_Add(void); +static void TimeEdit_Confirm(void); +static void TimeEdit_Cancel(void); +static u32 Calculate_Week(u32 nian,u32 yue,u32 ri); +static void Draw_Day(void); + +struct TimeEdit_Page_Info time_Info[ButtonInfoNum + TimeInfoNum] = { + { + .Name = "年的<", + .Text = "<", + .x = 5, + .y = 35, + .w = 35, + .h = 35, + .fun_callback = TimeEdit_Nian_Sub, + }, + { + .Name = "月的<", + .Text = "<", + .x = 221, + .y = 35, + .w = 35, + .h = 35, + .fun_callback = TimeEdit_Yue_Sub, + }, + { + .Name = "年的>", + .Text = ">", + .x = 143, + .y = 35, + .w = 35, + .h = 35, + .fun_callback = TimeEdit_Nian_Add, + }, + { + .Name = "月的>", + .Text = ">", + .x = 360, + .y = 35, + .w = 35, + .h = 35, + .fun_callback = TimeEdit_Yue_Add, + }, +// { +// .Name = "日期选择确认", +// .Text = "确认", +// .x = 63, +// .y = 379, +// .w = 76, +// .h = 35, +// .fun_callback = TimeEdit_Confirm, +// }, +// { +// .Name = "日期选择取消", +// .Text = "取消", +// .x = 250, +// .y = 379, +// .w = 76, +// .h = 35, +// .fun_callback = TimeEdit_Cancel, +// }, + { + .Name = "年显示", + .Text = NULL, + .x = 40, + .y = 35, + .w = 104, + .h = 35, + }, + { + .Name = "月显示", + .Text = NULL, + .x = 256, + .y = 35, + .w = 104, + .h = 35, + }, +}; + +//天按下的动作 +static bool_t Button_Day_Change(struct WindowMsg *pMsg) +{ + HWND hwnd; + HDC hdc; + if(pMsg==NULL) + return false; + hwnd = pMsg -> hwnd; + if(hwnd ==NULL) return false; + + + u32 dayNum = 0; + if(historyTime.Yue == 1||historyTime.Yue == 3||historyTime.Yue == 5||historyTime.Yue == 7||historyTime.Yue == 8||historyTime.Yue == 10||historyTime.Yue == 12){ + dayNum = 31; + }else if(historyTime.Yue == 4||historyTime.Yue == 6||historyTime.Yue == 9||historyTime.Yue == 11){ + dayNum = 30; + }else{ + if((historyTime.Nian % 4 == 0 && historyTime.Nian % 100 != 0) || historyTime.Nian % 400 == 0){ + dayNum = 29; + }else{ + dayNum = 28; + } + } + + s16 x = LO16(pMsg->Param2) - historyTime.x - DayPageX; + s16 y = HI16(pMsg->Param2) - historyTime.y - DayPageY; + for(u32 i = 0;i < DayAllButton;i ++){ + if(x <= (59 * (i % 7) + 35)&&x >= (59 * (i % 7))&&y >= (44 * (i / 7))&& y <= (44 * (i / 7) + 35)){ + if((i - dq_week + 1) > 0&&(i - dq_week + 1) <= dayNum){ + historyTime.Ri = i - dq_week + 1; + } + } + } + Draw_Day(); + return true; +} + +//画天的窗口 +static void Draw_Day(){ + u32 dayNum = 0; + if(historyTime.Yue == 1||historyTime.Yue == 3||historyTime.Yue == 5||historyTime.Yue == 7||historyTime.Yue == 8||historyTime.Yue == 10||historyTime.Yue == 12){ + dayNum = 31; + }else if(historyTime.Yue == 4||historyTime.Yue == 6||historyTime.Yue == 9||historyTime.Yue == 11){ + dayNum = 30; + }else{ + if((historyTime.Nian % 4 == 0 && historyTime.Nian % 100 != 0) || historyTime.Nian % 400 == 0){ + dayNum = 29; + }else{ + dayNum = 28; + } + } + HDC hdc = GDD_BeginPaint(dayPage); + GDD_SetBackGroundColor(hdc, RGB(50, 50, 60)); + GDD_CleanClient(hdc); + for(u32 i = 0;i < DayAllButton;i++){ + //如果i在要画的日期间的话才开始画数字 + if(i >= dq_week&& i < dq_week + dayNum){ + if((i - dq_week + 1) == historyTime.Ri){ + GDD_FillRectEx(hdc,&(RECT){59 * (i % 7),44 * (i / 7),59 * (i % 7) + 35,44 * (i / 7) + 35},CN_COLOR_BLUE); + } + u8 zfc[5]; + sprintf(zfc,"%d",i - dq_week + 1); + GDD_DrawText(hdc,zfc,-1,&(RECT){59 * (i % 7),44 * (i / 7),59 * (i % 7) + 35,44 * (i / 7) + 35},DT_VCENTER); + } + } + GDD_EndPaint(dayPage,hdc); +} + +//天按键对应的消息链表 +struct MsgProcTable TimeEditDayMsg[] = + { + {.MsgCode = MSG_TOUCH_DOWN + MSG_ADOPT_NONE, .MsgProc = Button_Day_Change }, // 替换掉按钮的down消息不然up消息出发后会触发按钮自带的down消息 + {.MsgCode = MSG_TOUCH_UP + MSG_ADOPT_NONE, .MsgProc = NULL}, + {.MsgCode = MSG_PAINT , .MsgProc = NULL }, // 这里不选择继承是因为按钮上面肯定会有图片的,继承的意义不大反正最后也会被覆盖所以干脆不画MSG_CLOSE +}; +struct MsgTableLink TimeEditDayMsgTab = + { + .MsgNum = sizeof(TimeEditDayMsg) / sizeof(struct MsgProcTable), + .myTable = (struct MsgProcTable *)&TimeEditDayMsg, +}; + +//画年和月 +static void Draw_Time(u32 flag){ + HDC hdc = GDD_BeginPaint(homePage); + + u32 time; + switch(flag){ + case Nian:time = historyTime.Nian;break; + case Yue:time = historyTime.Yue;break; + } + u8 time_zfc[80]; + u32 ws = 0; + while(time){ + time_zfc[ws ++] = time % 10 + '0'; + time /= 10; + } + time_zfc[ws] = '\0'; + for(u32 i = 0;i < ws / 2;i ++){ + u8 ls = time_zfc[i]; + time_zfc[i] = time_zfc[ws - i - 1]; + time_zfc[ws - i - 1] = ls; + } + u32 dq_ys = GDD_GetBackGroundColor(hdc); + GDD_FillRectEx(hdc,&(RECT){time_Info[ButtonInfoNum + flag].x,time_Info[ButtonInfoNum + flag].y,time_Info[ButtonInfoNum + flag].x + time_Info[ButtonInfoNum + flag].w,time_Info[ButtonInfoNum + flag].y + time_Info[ButtonInfoNum + flag].h},dq_ys); + GDD_DrawText(hdc,time_zfc,-1,&(RECT){time_Info[ButtonInfoNum + flag].x,time_Info[ButtonInfoNum + flag].y,time_Info[ButtonInfoNum + flag].x + time_Info[ButtonInfoNum + flag].w,time_Info[ButtonInfoNum + flag].y + time_Info[ButtonInfoNum + flag].h},DT_VCENTER); + GDD_EndPaint(homePage, hdc); +} + +//确认函数 +void TimeEdit_Confirm(void){ + if(homePage != NULL){ + //执行回调函数(修改目标时间) + historyTime.fun_callback(historyTime.Nian,historyTime.Yue,historyTime.Ri); + GDD_DestroyWindow(homePage); + homePage = NULL; + } +} + +//取消函数 +void TimeEdit_Cancel(void){ + if(homePage != NULL){ + GDD_DestroyWindow(homePage); + homePage = NULL; + } +} + +//年减一 +void TimeEdit_Nian_Sub(void){ + historyTime.Nian --; + Draw_Time(Nian); + historyTime.Ri = 1; + //计算当前月的第一天对应的星期 + dq_week = Calculate_Week(historyTime.Nian,historyTime.Yue,1); + //画日期 + Draw_Day(); +} + +//年加一 +void TimeEdit_Nian_Add(void){ + historyTime.Nian ++; + Draw_Time(Nian); + historyTime.Ri = 1; + //计算当前月的第一天对应的星期 + dq_week = Calculate_Week(historyTime.Nian,historyTime.Yue,1); + + //画日期 + Draw_Day(); +} + +//月减一 +void TimeEdit_Yue_Sub(void){ + historyTime.Ri = 1; + if(historyTime.Yue > 1){ + historyTime.Yue --; + //计算当前月的第一天对应的星期 + dq_week = Calculate_Week(historyTime.Nian,historyTime.Yue,1); + } + else{ + historyTime.Yue = 12; + TimeEdit_Nian_Sub(); + } + Draw_Time(Yue); + //画日期 + Draw_Day(); +} + +//月加一 +void TimeEdit_Yue_Add(void){ + historyTime.Ri = 1; + if(historyTime.Yue < 12){ + historyTime.Yue ++; + //计算当前月的第一天对应的星期 + dq_week = Calculate_Week(historyTime.Nian,historyTime.Yue,1); + } + else{ + historyTime.Yue = 1; + TimeEdit_Nian_Add(); + } + + Draw_Time(Yue); + //画日期 + Draw_Day(); +} + +static u32 Calculate_Week(u32 nian,u32 yue,u32 ri){ + u32 totalDay = 0; + for(u32 i = 1;i < nian;i ++){ + if((i % 4 == 0 && i % 100 != 0) || i % 400 == 0){ + totalDay += 366; + }else{ + totalDay += 365; + } + } + //计算月转化成天 + for(int j = 1; j < yue ; j++){ + if(j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 ){ + totalDay += 31; + }else if( j == 2 ){ + if((nian % 4 == 0 && nian % 100 != 0) || nian % 400 == 0){ + totalDay += 29; + }else{ + totalDay += 28; + } + }else{ + totalDay += 30; + } + } + //计算天 + totalDay += ri; + return totalDay % 7; +} + +static bool_t Button_Down(struct WindowMsg *pMsg) +{ + HWND hwnd; + HDC hdc; + if(pMsg==NULL) + return false; + hwnd = pMsg -> hwnd; + if(hwnd ==NULL) return false; + struct TimeEdit_Page_Info *data = GDD_GetWindowPrivateData(hwnd); + data->fun_callback(); + return true; +} + +static bool_t Button_Paint(struct WindowMsg *pMsg) +{ + HWND hwnd; + HDC hdc; + if(pMsg==NULL) + return false; + hwnd = pMsg -> hwnd; + if(hwnd ==NULL) return false; + struct TimeEdit_Page_Info *data = GDD_GetWindowPrivateData(hwnd); + if(data != NULL){ + hdc = GDD_BeginPaint(hwnd); + GDD_DrawText(hdc,data->Text,-1,&(RECT){0,0,data->w,data->h},DT_VCENTER); + GDD_EndPaint(hwnd, hdc); + } + return true; +} + +struct MsgProcTable TimeEditMsg[] = + { + {.MsgCode = MSG_TOUCH_DOWN + MSG_ADOPT_NONE, .MsgProc = Button_Down }, // 替换掉按钮的down消息不然up消息出发后会触发按钮自带的down消息 + {.MsgCode = MSG_TOUCH_UP + MSG_ADOPT_NONE, .MsgProc = NULL}, + {.MsgCode = MSG_PAINT , .MsgProc = Button_Paint }, // 这里不选择继承是因为按钮上面肯定会有图片的,继承的意义不大反正最后也会被覆盖所以干脆不画MSG_CLOSE +}; +struct MsgTableLink TimeEditMsgTab = + { + .MsgNum = sizeof(TimeEditMsg) / sizeof(struct MsgProcTable), + .myTable = (struct MsgProcTable *)&TimeEditMsg, +}; + +void TimeEdit_Create(HWND hParent,struct Time time){ + //把信息都置入全局变量保存 + historyTime.Nian = time.Nian; + historyTime.Yue = time.Yue; + historyTime.Ri = time.Ri; + historyTime.bgColor = time.bgColor; + historyTime.x = time.x; + historyTime.y = time.y; + historyTime.fun_callback = time.fun_callback; + + homePage = GDD_CreateWindow("TimeEdit_Page", NULL, historyTime.x, historyTime.y, 400, 380, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY, historyTime.bgColor, 0, 0, hParent); + HDC hdc = GDD_BeginPaint(homePage); + GDD_SetBackGroundColor(hdc, historyTime.bgColor); + GDD_CleanClient(hdc); + GDD_TextOut(hdc,74,0,"年",-1); + GDD_TextOut(hdc,301,0,"月",-1); + Draw_Time(Nian); + Draw_Time(Yue); + //把日对应的星期打印出来 + u8 ls_text[7][3] = {"日","一","二","三","四","五","六"}; + for(u32 i = 0;i < 7;i ++){ + GDD_TextOut(hdc,5 + (59 * i),76,ls_text[i],-1); + } + GDD_EndPaint(homePage,hdc); + + for(u32 i = 0;i < ButtonInfoNum;i ++){ + Widget_CreateButton(time_Info[i].Name,BS_NORMAL | WS_UNFILL,time_Info[i].x,time_Info[i].y,time_Info[i].w,time_Info[i].h,homePage,0,&time_Info[i],&TimeEditMsgTab); + } + + //计算当前月的第一天对应的星期 + dq_week = Calculate_Week(historyTime.Nian,historyTime.Yue,1); + + //天的画图 + dayPage = GDD_CreateWindow("TimeEdit_Day_Page", &TimeEditDayMsgTab, DayPageX, DayPageY, 390, 259, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY, historyTime.bgColor, 0, 0, homePage); + + Draw_Day(); +} + +void TimeEditbutton_Create(HWND hParent,RECT rect){ +// timebutton = Widget_CreateButton("curvereportTime", BS_NORMAL | WS_UNFILL, rect.left, rect.top, GDD_RectW(&rect), GDD_RectH(&rect), hParent, 0, 0, &timeEDITbuttonTab); + + reporttime.Nian = 2024; + reporttime.Yue = 6; + reporttime.Ri = 26; + reporttime.x = rect.left; + reporttime.y = rect.top; + reporttime.bgColor = RGB(50,50,60); + TimeEdit_Create(hParent,reporttime); + +// reporttime.fun_callback = my_fun; +} +//下面的是demo +//当控件按下确定键后,将会调用如下内容,并返回年、月、日 +//void my_fun(u32 Nian,u32 Yue,u32 Ri) +//{ +// printf("%d %d %d\r\n",Nian,Yue,Ri); +//} +// +//void TimeEdit_Demo(void){ +// struct Time time; +// time.Nian = 2019; +// time.Yue = 1; +// time.Ri = 1; +// time.x = 200; +// time.y = 50; +// time.bgColor = RGB(100,100,100); +// time.fun_callback = my_fun; +// TimeEdit_Create(GDD_GetDesktopWindow(NULL),time); +//} diff --git a/src/app/Module/TimeEdit.h b/src/app/Module/TimeEdit.h new file mode 100644 index 0000000..5c66312 --- /dev/null +++ b/src/app/Module/TimeEdit.h @@ -0,0 +1,36 @@ +/* + * TimeEdit.h + * + * Created on: 2024年6月20日 + * Author: wu + */ + +#ifndef APP_DEMO_TIMEEDIT_TIMEEDIT_H_ +#define APP_DEMO_TIMEEDIT_TIMEEDIT_H_ + +#include "gdd.h" + +typedef void (*fun_callback_time)(u32 Nian,u32 Yue,u32 Ri); +typedef void (*fun_callback_button)(void); + +struct Time{ + u32 Nian; + u32 Yue; + u32 Ri; + u32 bgColor;//时间控件的背景颜色 + u32 x,y;//时间控件生成的横纵坐标轴 + fun_callback_time fun_callback;//设置一个回调函数,当控件点击确认时,通过这个函数来获取所设置的时间 +}; + +struct TimeEdit_Page_Info{ + u8 *Name; + u8 *Text; + u32 x,y,w,h; + fun_callback_button fun_callback; +}; + +void TimeEdit_Demo(void); +void TimeEditbutton_Create(HWND hParent,RECT rect); + + +#endif /* APP_DEMO_TIMEEDIT_TIMEEDIT_H_ */ diff --git a/src/app/Module/wjh_ClockControl.c b/src/app/Module/wjh_ClockControl.c new file mode 100644 index 0000000..1ae9e59 --- /dev/null +++ b/src/app/Module/wjh_ClockControl.c @@ -0,0 +1,185 @@ +//这段程序是一个时钟 +// +// +#include "stdint.h" +#include "stddef.h" +#include "stdio.h" +#include "gdd.h" +#include "gdd_button.h" +#include "wjh_window.h" +// 用于存放按钮hwnd +HWND timeclock[8]; +HWND clock_window = NULL; +//定义按钮名字 +u8 buttontime[8][20] = {"hour1", "hour2", "colon1", "minute1", "minute2", "colon2", "second1", "second2"}; +//图片名称,不可更改 +u8 timename[10][20] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; +//初始化时间 +u32 hour_t = 0; +u32 minute_t = 59; +u32 second_t = 50; + +u32 C_flag = 0; +struct WinTimer* c_timer; +enum { + C_Clock, + C_Timer, +}; +static bool_t main_window_paint(struct WindowMsg *pMsg) { + HWND hwnd = pMsg->hwnd; + if (hwnd == NULL) return false; + + HDC hdc = GDD_BeginPaint(hwnd); + + GDD_SetBackGroundColor(hdc, RGB(8,24,58)); + GDD_CleanClient(hdc); + + GDD_EndPaint(hwnd, hdc); // 结束绘制并刷新 + + return true; +} +static bool_t button_paint(struct WindowMsg *pMsg) { + u8* data; + HWND hwnd; + HDC hdc; + if(pMsg==NULL) + return false; + hwnd = pMsg -> hwnd; + if(hwnd ==NULL) return false; + hdc = GDD_BeginPaint(hwnd); +// struct RopGroup ropgroup = GDD_GetRopCode(hdc); +// ropgroup.HyalineEn = 1; +// GDD_SetRopCode(hwnd, ropgroup); +// GDD_SetWindowHyalineColor(hwnd, RGB(8,24,58)); +// Set the background image for the window + wjh_setBackBmp(hwnd, wjh_Search_ClockBMP("colon")); + + GDD_EndPaint(hwnd, hdc); // 结束绘制并刷新 + + return true; + } + +static bool_t timer_paint(struct WindowMsg *pMsg) { + u8* data; + HWND hwnd; + HDC hdc; + if(pMsg==NULL) + return false; + hwnd = pMsg -> hwnd; + if(hwnd ==NULL) return false; + hdc = GDD_BeginPaint(hwnd); + //根据时间调整图片 + wjh_setBackBmp(timeclock[0], wjh_Search_ClockBMP(timename[hour_t/10])); + wjh_setBackBmp(timeclock[1], wjh_Search_ClockBMP(timename[hour_t%10])); + wjh_setBackBmp(timeclock[3], wjh_Search_ClockBMP(timename[minute_t/10])); + wjh_setBackBmp(timeclock[4], wjh_Search_ClockBMP(timename[minute_t%10])); + wjh_setBackBmp(timeclock[6], wjh_Search_ClockBMP(timename[second_t/10])); + wjh_setBackBmp(timeclock[7], wjh_Search_ClockBMP(timename[second_t%10])); + if(C_flag == C_Clock){ + second_t = second_t + 1; + if(second_t==60){ + second_t = 0; + minute_t = minute_t + 1; + } + if(minute_t==60){ + minute_t = 0; + hour_t = hour_t + 1; + } + if(hour_t==24){ + hour_t = 0; + } + }else if(C_flag == C_Timer){ + if(second_t==0&&minute_t == 0&&hour_t==0){ + GDD_StopTimer(c_timer); + } + if(second_t==0&&!(minute_t == 0&&hour_t == 0)){ + second_t = 60; + if(minute_t == 0 && hour_t != 0){ + minute_t = 60; + hour_t -= 1; + } + minute_t -= 1; + + } + second_t -= 1; + + } + + + GDD_EndPaint(hwnd, hdc); // 结束绘制并刷新 + + return true; +} +void create_TimerControl(){ + if(clock_window!=NULL){ + hour_t = 1; + minute_t = 1; + second_t = 0; + C_flag = C_Timer; + GDD_PostMessage(clock_window, MSG_TIMER, 0, NULL); + } +} + +void start_timer(){ + if(clock_window!=NULL) + GDD_StartTimer(c_timer); + +} +void pause_timer(){ + if(clock_window!=NULL) + GDD_StopTimer(c_timer); + +} +void Del_ClockControl(){ + if(clock_window!=NULL){ + GDD_DestroyWindow(clock_window); + clock_window = NULL; + u32 hour_t = 0; + u32 minute_t = 59; + u32 second_t = 50; + } +} +void correct_ClockControl(){ + hour_t = 0; + minute_t = 59; + second_t = 50; + GDD_StartTimer(c_timer); + +} + +// Main function +HWND wjh_GetClockControl(HWND hwnd, u32 x, u32 y) +{ + // Enable the screen backlight +// Lcd_BackLight_OnOff(1); + // Create the navigation bar window +// if(clock_window == NULL){ + C_flag = C_Clock; + clock_window = wjh_createWindow( + "clock_window", x, y, 340, 70, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY, + RGB(1, 1, 1), hwnd, main_window_paint, NULL + ); + + //创建按钮 + for(int i = 0; i < 8; i++){ + timeclock[i] = wjh_createButton(buttontime[i], BS_NORMAL | WS_UNFILL, 12+i*40, 5, 40, 60, clock_window, button_paint, NULL); +// HDC hdc = GDD_BeginPaint(timeclock[i]); +// struct RopGroup ropgroup = GDD_GetRopCode(hdc); +// ropgroup.HyalineEn = 1; +// GDD_SetRopCode(timeclock[i], ropgroup); +// GDD_SetWindowHyalineColor(hwnd, RGB(8,24,58)); +// GDD_EndPaint(timeclock[i], hdc); + } + //给main窗口创建一个计时器的timer事件 + wjh_setTimer(clock_window,timer_paint); + //创建计时器 + c_timer = GDD_CreateTimer(clock_window,0,1000); + //计时器开始执行 + GDD_StartTimer(c_timer); + return clock_window; +// }else{ +// correct_ClockControl(); +// } +// return NULL; +} + diff --git a/src/app/Module/wjh_ClockControl.h b/src/app/Module/wjh_ClockControl.h new file mode 100644 index 0000000..6b5d083 --- /dev/null +++ b/src/app/Module/wjh_ClockControl.h @@ -0,0 +1,23 @@ +/* + * wjh_ClockControl.h + * + * Created on: 2024年8月6日 + * Author: LENOVO + */ + +#ifndef APP_MODULE_WJH_CLOCKCONTROL_H_ +#define APP_MODULE_WJH_CLOCKCONTROL_H_ +#include "gdd.h" + +HWND wjh_GetClockControl(HWND hwnd, u32 x, u32 y); +void Del_ClockControl(); +void correct_ClockControl(); +void pause_timer(); +void start_timer(); +void create_TimerControl(); + + + + + +#endif /* APP_MODULE_WJH_CLOCKCONTROL_H_ */