cook-c100/src/app/pagetest3.c
2024-08-22 22:13:20 +08:00

160 lines
5.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 调用头文件
//这是一段时钟功能+图标按钮的桌面页面,包括左右两个切换按钮
//时钟位于上方,图标按钮有十个排列在下半部分,左右两侧分别为切换按钮
//时钟的固定大小为340*70像素时钟可以通过wjh_GetClockControl(main_window, 150, 100);创建150100为时钟左上角距离窗口x150y100像素
#include "stdint.h"
#include "stddef.h"
#include "stdio.h"
#include "gdd.h"
#include "gdd_button.h"
#include "wjh_window.h"
#include "wjh_Graph.h"
#include "page.h"
u8 iconname3[][20] = {"address", "camera", "cart", "controller", "location", "music", "picture", "search", "time", "wifi", "table", "barchart"};
u32 iconflag3 = 0;
// Button click and paint handlers
static bool_t left_page_button_paint(struct WindowMsg *pMsg);
static bool_t right_page_button_paint(struct WindowMsg *pMsg);
static bool_t page_button_paint(struct WindowMsg *pMsg);
static bool_t main_window_paint(struct WindowMsg *pMsg);
static bool_t left_page_button_click(struct WindowMsg *pMsg);
static bool_t right_page_button_click(struct WindowMsg *pMsg);
// Implementation of the temperature graph page with side icon buttons
HWND enter_to_page3() {
// Create the main window (1024x600)
HWND main_window = wjh_createWindow(
"temperature_page_window", 0, 0, 1024, 600, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY,
RGB(255, 255, 255), GDD_GetDesktopWindow(NULL), main_window_paint, NULL
);
// Create the left page button (50x50)
wjh_createButton("left_page_button", BS_NORMAL | WS_UNFILL, 20, 275, 50, 50, main_window, left_page_button_paint, left_page_button_click);
// Create the right page button (50x50)
wjh_createButton("right_page_button", BS_NORMAL | WS_UNFILL, 954, 275, 50, 50, main_window, right_page_button_paint, right_page_button_click);
// Generate temperature data for 10 days
u8 x_labels[10][GRAPH_DATA_LEN_MAX];
u32 temp_values[10];
for (int i = 0; i < 10; ++i) {
temp_values[i] = rand() % 30 + 15; // Random temperatures between 15 and 45 degrees
sprintf(x_labels[i], "D.%d", i + 1);
}
// Create the graph window to display temperature data (600x400), centered horizontally
HWND graph_window = wjh_Graph_Initialize(
212, 100, 600, 400, 10, x_labels, temp_values, main_window
);
//
// // Set the title of the graph
wjh_Graph_SetTitle(graph_window, "10-Day Temperature Forecast");
//
// // Set the graph to be a line chart
wjh_Graph_SetShowMode(graph_window, GRAPH_LINE_CHART);
// Adjusted positions for icon buttons (aligned to the sides of the graph)
int icon_size = 90; // Button size adjusted to 90x90
int spacing_y = 40; // Vertical spacing between buttons
int left_x = 100; // Left side for the left icon buttons
int right_x = 824; // Right side for the right icon buttons
int y_start = 130; // Position aligned to the graph's vertical position
// Create 3 icon buttons on the left side of the graph
for (int i = 0; i < 3; ++i) {
char button_name[20];
sprintf(button_name, "left_icon_button_%d", i);
wjh_createButton(button_name, BS_NORMAL | WS_UNFILL, left_x, y_start + i * (icon_size + spacing_y),
icon_size, icon_size, main_window, page_button_paint, NULL);
}
// Create 3 icon buttons on the right side of the graph
for (int i = 0; i < 3; ++i) {
char button_name[20];
sprintf(button_name, "right_icon_button_%d", i);
wjh_createButton(button_name, BS_NORMAL | WS_UNFILL, right_x, y_start + i * (icon_size + spacing_y),
icon_size, icon_size, main_window, page_button_paint, NULL);
}
return main_window;
}
// Paint handlers for the main window
static bool_t main_window_paint(struct WindowMsg *pMsg) {
HWND hwnd = pMsg->hwnd;
if(hwnd == NULL)
return false;
HDC hdc = GDD_BeginPaint(hwnd);
if(hdc == NULL)
return false;
wjh_setBackBmp(pMsg->hwnd, wjh_Search_BMP("background1"));
//通过画圆来记录当前页面
GDD_SetDrawColor(hdc, RGB(200, 200, 200));
GDD_FillCircle(hdc, 527, 570, 5);
GDD_SetDrawColor(hdc, RGB(125, 125, 125));
GDD_FillCircle(hdc, 507, 570, 5);
GDD_FillCircle(hdc, 487, 570, 5);
GDD_EndPaint(hwnd, hdc);
return true;
}
// Paint handlers for the left page button
static bool_t left_page_button_paint(struct WindowMsg *pMsg) {
HWND hwnd = pMsg->hwnd;
HDC hdc = GDD_BeginPaint(hwnd);
if (hdc == NULL) return false;
wjh_setBackBmp(hwnd, wjh_Search_BMP("turn_left"));
GDD_EndPaint(hwnd, hdc);
return true;
}
// Paint handlers for the right page button
static bool_t right_page_button_paint(struct WindowMsg *pMsg) {
HWND hwnd = pMsg->hwnd;
HDC hdc = GDD_BeginPaint(hwnd);
if (hdc == NULL) return false;
wjh_setBackBmp(hwnd, wjh_Search_BMP("turn_right"));
GDD_EndPaint(hwnd, hdc);
return true;
}
// Paint handlers for the icon buttons
static bool_t page_button_paint(struct WindowMsg *pMsg) {
HWND hwnd = pMsg->hwnd;
HDC hdc = GDD_BeginPaint(hwnd);
if (hdc == NULL) return false;
wjh_setBackBmp(hwnd, wjh_Search_BMP("button1_background"));
wjh_setBackBmpHyaline(hwnd, wjh_Search_ICONBMP(iconname3[(iconflag3++)%12]));
GDD_EndPaint(hwnd, hdc);
return true;
}
// Click handlers for the left page button
static bool_t left_page_button_click(struct WindowMsg *pMsg) {
// Navigate to the previous page
wjh_deleteWindow(GDD_GetWindowParent(pMsg->hwnd));
enter_to_page2(); // Example of navigating to page1
return true;
}
// Click handlers for the right page button
static bool_t right_page_button_click(struct WindowMsg *pMsg) {
// Navigate to the next page
wjh_deleteWindow(GDD_GetWindowParent(pMsg->hwnd));
enter_to_page1(); // Example of navigating to page3
return true;
}