📄 nativegui.c
字号:
} FindClose(fileHandle); SetCurrentDirectory(cdir); return NULL;}#endifstatic intstrcasecmp(const char *a, const char *b){ while (*a && *b) { int d = tolower(*a) - tolower(*b); if (d) return d; ++a; ++b; } return tolower(*a) - tolower(*b);}static void CreateEmulatorWindow(){ HINSTANCE hInstance = GetModuleHandle(NULL); static char szAppName[] = "Kauai"; WNDCLASSEX wndclass ; HWND hwnd; HDC hdc; HMENU hMenu = NULL; char *s; char *DB_ENV = getInternalProp("system.display.double_buffered"); char *DEPTH_ENV = getInternalProp("system.display.screen_depth"); static WORD graybits[] = {0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555}; unsigned int width = EMULATOR_WIDTH, height = EMULATOR_HEIGHT; if (initialized) { return; } else { initialized = 1; } if (DB_ENV != NULL) { doubleBuffer = !strcasecmp(DB_ENV, "true"); } if (DEPTH_ENV == NULL) numColors = 4; else if (!strcmp(DEPTH_ENV, "1")) numColors = 2; else if (!strcmp(DEPTH_ENV, "2")) numColors = 4; else if (!strcmp(DEPTH_ENV, "4")) numColors = 16; else if (!strcmp(DEPTH_ENV, "8")) { numColors = 256; } wndclass.cbSize = sizeof (wndclass) ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) BACKGROUND_BRUSH; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ; RegisterClassEx (&wndclass) ;#ifdef SKINS_MENU_SUPPORTED hMenu = buildSkinsMenu(); if (hMenu != NULL) height += 24;#endif hwnd = CreateWindow (szAppName, /* window class name */ "MIDP", /* window caption */ WS_OVERLAPPEDWINDOW & /* window style; disable */ (~WS_MAXIMIZEBOX), /* the 'maximize' button */ CW_USEDEFAULT, /* initial x position */ CW_USEDEFAULT, /* initial y position */ width, /* initial x size */ height, /* initial y size */ NULL, /* parent window handle */ hMenu, /* window menu handle */ hInstance, /* program instance handle */ NULL); /* creation parameters */ hMainWindow = hwnd; /* colors chosen to match those used in topbar.h */ whitePixel = 0xffffff; blackPixel = 0x000000; lightGrayPixel = RGB(182, 182, 170); darkGrayPixel = RGB(109, 109, 85); foregroundColor = blackPixel; backgroundColor = lightGrayPixel; /* brushes for borders and menu hilights */ darkGrayBrush = CreateSolidBrush(darkGrayPixel); darkGrayPen = CreatePen(PS_SOLID, 1, darkGrayPixel); whiteBrush = CreateSolidBrush(whitePixel); whitePen = CreatePen(PS_SOLID, 1, whitePixel); BACKGROUND_BRUSH = CreateSolidBrush(backgroundColor); BACKGROUND_PEN = CreatePen(PS_SOLID, 1, backgroundColor); FOREGROUND_BRUSH = CreateSolidBrush(foregroundColor); FOREGROUND_PEN = CreatePen(PS_SOLID, 1, foregroundColor); hdc = GetDC(hwnd); CreateScreenBitmap(hdc); ReleaseDC(hwnd, hdc); ShowWindow(hwnd, SW_SHOWNORMAL); UpdateWindow(hwnd); /* printf("Hello\n"); */}#if USE_KVMvoidGetAndStoreNextKVMEvent(bool_t forever, ulong64 waitUntil) { MSG msg; gotEvent = KNI_FALSE; if (forever) { while (GetMessage(&msg, NULL, 0, 0)) { if (msg.message == WM_QUIT) { break; } TranslateMessage (&msg) ; DispatchMessage (&msg) ; if (gotEvent) { StoreMIDPEvent(&kvmEvent); return; } } return; } else { HANDLE h; for (;;) { /* see if backlight is on */ drawBackLight(isBklite_on); /* see if we should toggle the network indicator LED */ if ((netIndicatorCount != latestNICount) || isLED_on == KNI_TRUE) { updateNetIndicator(); } while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { return; } TranslateMessage(&msg); DispatchMessage(&msg); if (gotEvent) { StoreMIDPEvent(&kvmEvent); return; } } if (waitUntil == 0) { return; } else { int ret, timeout, alt; if ((timeout = waitUntil - midp_getCurrentTime()) <= 0) { return; }#ifdef LATER /* use an alternative timeout if a timer is pending, */ /* in order to ensure that the timer is not made late */ /* by a long waitUntil value. */ alt = timerPending - midp_getCurrentTime(); if ((alt > 0) && (alt < timeout)) { timeout = alt; }#endif ret = MsgWaitForMultipleObjects(0, &h, KNI_FALSE, timeout, QS_ALLEVENTS); if (ret == WAIT_TIMEOUT) { return; } else if (ret == -1) { fprintf(stderr, "MsgWaitForMultipleObjects failed\n"); } } } }}#endif /* USE_KVM */voidDrawBitmap(HDC hdc, HBITMAP hBitmap, int x, int y, int rop){ BITMAP bm; HDC hdcMem; POINT ptSize, ptOrg; HBITMAP tmp; hdcMem = CreateCompatibleDC(hdc); CHECK_RETURN(tmp = SelectObject(hdcMem, hBitmap)); SetMapMode(hdcMem, GetMapMode(hdc)); GetObject(hBitmap, sizeof(BITMAP), (LPVOID)&bm); ptSize.x = bm.bmWidth; ptSize.y = bm.bmHeight; DPtoLP(hdc, &ptSize, 1); ptOrg.x = 0; ptOrg.y = 0; DPtoLP(hdcMem, &ptOrg, 1); BitBlt(hdc, x, y, ptSize.x, ptSize.y, hdcMem, ptOrg.x, ptOrg.y, rop); SelectObject(hdcMem, tmp); DeleteDC(hdcMem);}static voidpaintHorizontalScroll(HDC hdc, int scrollPosition, int scrollProportion){ /* arrow images; all are 7x7 */ static BYTE left_bits[] = {0xF7,0, 0xE7,0, 0xC1,0, 0x81,0, 0xC1,0, 0xE7,0, 0xF7,0}; static BYTE right_bits[] = {0xDF,0, 0xCF,0, 0x07,0, 0x03,0, 0x07,0, 0xCF,0, 0xDF,0};#define HORIZ_Y (y_offset + paintHeight + 5)#define LEFT_X (x_offset + (PAINT_WIDTH/2) - 10)#define RIGHT_X (x_offset + (PAINT_WIDTH/2) + 4) HBITMAP hb; CHECK_RETURN(SelectObject(hdc, BACKGROUND_PEN)); CHECK_RETURN(SelectObject(hdc, BACKGROUND_BRUSH)); /* If the scrollable is 100% the proportion of the viewport, */ /* there's no need for any scrolling, clear the arrows and */ /* return. */ if (scrollProportion >= 100 || scrollProportion == 0) { Rectangle(hdc, LEFT_X, HORIZ_Y, LEFT_X + 7, HORIZ_Y + 7); Rectangle(hdc, RIGHT_X, HORIZ_Y, RIGHT_X + 7, HORIZ_Y + 7); return; } /* If we're somewhere between the left and right, */ /* add both scroll arrows */ if (scrollPosition > 0 && scrollPosition < 100) { /* WEST */ hb = CreateBitmap(7, 7, 1, 1, left_bits); DrawBitmap(hdc, hb, LEFT_X, HORIZ_Y, MERGECOPY); DeleteObject(hb); /* EAST */ hb = CreateBitmap(7, 7, 1, 1, right_bits); DrawBitmap(hdc, hb, RIGHT_X, HORIZ_Y, MERGECOPY); DeleteObject(hb); /* If we're at the left, add the right arrow, clear the */ /* left arrow */ } else if (scrollPosition == 0) { /* EAST */ hb = CreateBitmap(7, 7, 1, 1, right_bits); DrawBitmap(hdc, hb, RIGHT_X, HORIZ_Y, MERGECOPY); DeleteObject(hb); Rectangle(hdc, LEFT_X, HORIZ_Y, LEFT_X + 7, HORIZ_Y + 7); /* We're at the right, add the left arrow, clear the */ /* right arrow */ } else { /* WEST */ hb = CreateBitmap(7, 7, 1, 1, left_bits); DrawBitmap(hdc, hb, LEFT_X, HORIZ_Y, MERGECOPY); DeleteObject(hb); Rectangle(hdc, RIGHT_X, HORIZ_Y, RIGHT_X + 7, HORIZ_Y + 7); }}static voidpaintVerticalScroll(HDC hdc, int scrollPosition, int scrollProportion){ /* arrow images; all are 7x7 */ static BYTE up_bits[] = {0xEF,0, 0xC7,0, 0x83,0, 0x01,0, 0xC7,0, 0xC7,0, 0xFF,0}; static BYTE down_bits[] = {0xFF,0, 0xC7,0, 0xC7,0, 0x01,0, 0x83,0, 0xC7,0, 0xEF,0};#define VERT_X (x_offset + (PAINT_WIDTH/2) - 4) #define UP_Y (y_offset + paintHeight + MENUBAR_BORDER_HEIGHT) #define DOWN_Y (y_offset + paintHeight + 11) HBITMAP hb; CHECK_RETURN(SelectObject(hdc, BACKGROUND_PEN)); CHECK_RETURN(SelectObject(hdc, BACKGROUND_BRUSH)); if (KNI_TRUE == inFullScreenMode) { return; } /* clear the arrow area */ Rectangle(hdc, VERT_X, UP_Y, VERT_X + 8, UP_Y + BOTTOM_BAR_HEIGHT - 1); /* If the scrollable is 100% the proportion of the viewport, */ /* there's no need for any scrolling, clear the arrows and */ /* return. */ if (scrollProportion >= 100 || scrollProportion == 0) { return; } /* If we're somewhere between the top and bottom, */ /* add both scroll arrows */ if (scrollPosition > 0 && scrollPosition < 100) { /* NORTH */ hb = CreateBitmap(7, 7, 1, 1, up_bits); DrawBitmap(hdc, hb, VERT_X, UP_Y, MERGECOPY); DeleteObject(hb); /* SOUTH */ hb = CreateBitmap(7, 7, 1, 1, down_bits); DrawBitmap(hdc, hb, VERT_X, DOWN_Y, MERGECOPY); DeleteObject(hb); /* If we're at the top, add the down arrow, clear the */ /* up arrow */ } else if (scrollPosition == 0) { /* SOUTH */ hb = CreateBitmap(7, 7, 1, 1, down_bits); DrawBitmap(hdc, hb, VERT_X, DOWN_Y, MERGECOPY); DeleteObject(hb); Rectangle(hdc, VERT_X, UP_Y, VERT_X + 7, UP_Y + 7); /* We're at the bottom, add the up arrow, clear the */ /* down arrow */ } else { /* NORTH */ hb = CreateBitmap(7, 7, 1, 1, up_bits); DrawBitmap(hdc, hb, VERT_X, UP_Y, MERGECOPY); DeleteObject(hb); Rectangle(hdc, VERT_X, DOWN_Y, VERT_X + 7, DOWN_Y + 7); }}HWND midpGetWindowHandle() { return hMainWindow;}void InitializeWindowSystem(){ int x, y; HDC hdc, hdcMem; /* set up the offsets for non-full screen mode*/ setUpOffsets(KNI_FALSE); inFullScreenMode = KNI_FALSE; requestedFullScreenMode = KNI_FALSE; drawTrustedMIDletIcon = KNI_FALSE; CreateEmulatorWindow(); LCDUIinitMenus(); LCDUIinitPopupMenu();}voidFinalizeWindowSystem() { if (initialized) { /* Clean up thread local data */ void* ptr = (void*) TlsGetValue(tlsId); if (ptr != NULL) { /* Must free TLS data before freeing the TLS ID */ midpFree(ptr); TlsFree(tlsId); } LCDUIfinalizeMenus(); LCDUIfinalizePopupMenu(); }}/* * Return the key code corresponding to the given abstract game action. */int LCDUIgetKeyCode(int gameAction){ switch (gameAction) { case 1: return KEY_UP; case 6: return KEY_DOWN; case 2: return KEY_LEFT; case 5: return KEY_RIGHT; case 8: return KEY_SELECT; case 9: return KEY_1; case 10: return KEY_3; case 11: return KEY_7; case 12: return KEY_9; default: return 0; }}/* * Return the abstract game action corresponding to the given key code. */int LCDUIgetGameAction(int keyCode){ switch (keyCode) { case KEY_UP: case KEY_2: return 1; case KEY_DOWN: case KEY_8: return 6; case KEY_LEFT: case KEY_4: return 2; case KEY_RIGHT: case KEY_6: return 5; case KEY_SELECT: case KEY_5: return 8; case KEY_1: return 9; case KEY_3: return 10; case KEY_7: return 11; case KEY_9: return 12; case KEY_SOFT1: case KEY_SOFT2: case KEY_0: case KEY_ASTERISK: case KEY_POUND:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -