mirror of
https://github.com/jam422470459/EPD-nRF52-hema213.git
synced 2025-12-06 08:32:54 +08:00
show mode for emulator
This commit is contained in:
55
emulator.c
55
emulator.c
@@ -11,7 +11,6 @@
|
||||
#define BITMAP_HEIGHT 300
|
||||
#define WINDOW_WIDTH 450
|
||||
#define WINDOW_HEIGHT 380
|
||||
#define WINDOW_TITLE TEXT("Emurator")
|
||||
|
||||
// Global variables
|
||||
HINSTANCE g_hInstance;
|
||||
@@ -23,9 +22,6 @@ uint8_t g_week_start = 0; // Default week start (0=Sunday, 1=Monday, etc.)
|
||||
time_t g_display_time;
|
||||
struct tm g_tm_time;
|
||||
|
||||
// Help text for hotkeys
|
||||
static const wchar_t helpText[] = L"空格 - 切换时钟 | R - 切换颜色 | W - 星期起点 | 方向键 - 调整日期/月份";
|
||||
|
||||
// Implementation of the buffer_callback function
|
||||
void DrawBitmap(uint8_t *black, uint8_t *color, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||
HDC hdc = g_paintHDC;
|
||||
@@ -184,20 +180,43 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
SelectObject(hdc, oldBrush);
|
||||
DeleteObject(borderPen);
|
||||
|
||||
// Display current mode at the top of the bitmap
|
||||
const wchar_t* modeText = (g_display_mode == MODE_CLOCK) ? L"时钟模式" : L"日历模式";
|
||||
int modeTextY = drawY - 20; // Above the bitmap
|
||||
SetTextColor(hdc, RGB(50, 50, 50));
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
|
||||
// Create a font for mode text
|
||||
HFONT modeFont = CreateFont(
|
||||
16, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
|
||||
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
|
||||
DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial"
|
||||
);
|
||||
HFONT oldFont = SelectObject(hdc, modeFont);
|
||||
|
||||
// Calculate text width for centering mode text
|
||||
SIZE modeTextSize;
|
||||
GetTextExtentPoint32W(hdc, modeText, wcslen(modeText), &modeTextSize);
|
||||
int modeCenteredX = drawX + (BITMAP_WIDTH - modeTextSize.cx) / 2;
|
||||
|
||||
TextOutW(hdc, modeCenteredX, modeTextY, modeText, wcslen(modeText));
|
||||
|
||||
// Draw help text below the bitmap
|
||||
const wchar_t helpText[] = L"空格 - 切换模式 | R - 切换颜色 | W - 星期起点 | 方向键 - 调整日期/月份";
|
||||
int helpTextY = drawY + BITMAP_HEIGHT * scale + 5;
|
||||
SetTextColor(hdc, RGB(80, 80, 80));
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
|
||||
// Create a smaller font for help text
|
||||
HFONT helpFont = CreateFont(
|
||||
14, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
||||
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
|
||||
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
|
||||
DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial"
|
||||
);
|
||||
HFONT oldFont = SelectObject(hdc, helpFont);
|
||||
SelectObject(hdc, modeFont);
|
||||
DeleteObject(modeFont);
|
||||
SelectObject(hdc, helpFont);
|
||||
|
||||
// Calculate text width for centering
|
||||
// Calculate text width for centering help text
|
||||
SIZE textSize;
|
||||
GetTextExtentPoint32W(hdc, helpText, wcslen(helpText), &textSize);
|
||||
int centeredX = drawX + (BITMAP_WIDTH - textSize.cx) / 2;
|
||||
@@ -292,7 +311,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return DefWindowProc(hwnd, message, wParam, lParam);
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,23 +320,23 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
g_hInstance = hInstance;
|
||||
|
||||
// Register window class
|
||||
WNDCLASSA wc = {0}; // Using WNDCLASSA for ANSI version
|
||||
WNDCLASSW wc = {0};
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.hInstance = hInstance;
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wc.lpszClassName = "BitmapDemo"; // No L prefix - using ANSI strings
|
||||
wc.lpszClassName = L"Emurator";
|
||||
|
||||
if (!RegisterClassA(&wc)) {
|
||||
MessageBoxA(NULL, "Window Registration Failed!", "Error", MB_ICONEXCLAMATION | MB_OK);
|
||||
if (!RegisterClassW(&wc)) {
|
||||
MessageBoxW(NULL, L"Window Registration Failed!", L"Error", MB_ICONEXCLAMATION | MB_OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create the window - explicit use of CreateWindowA for ANSI version
|
||||
g_hwnd = CreateWindowA(
|
||||
"BitmapDemo",
|
||||
"Emurator", // Using simple title
|
||||
// Create the window
|
||||
g_hwnd = CreateWindowW(
|
||||
L"Emurator",
|
||||
L"模拟器",
|
||||
WS_POPUPWINDOW | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
WINDOW_WIDTH, WINDOW_HEIGHT,
|
||||
@@ -325,7 +344,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
);
|
||||
|
||||
if (!g_hwnd) {
|
||||
MessageBoxA(NULL, "Window Creation Failed!", "Error", MB_ICONEXCLAMATION | MB_OK);
|
||||
MessageBoxW(NULL, L"Window Creation Failed!", L"Error", MB_ICONEXCLAMATION | MB_OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user