📄 nativegui.c
字号:
if (KNI_FALSE == fullscreen) { HDC hdc; hdc = getBitmapDC(UNTRANSLATED_SCREEN_BITMAP); CHECK_RETURN(SelectObject(hdc, BACKGROUND_BRUSH)); CHECK_RETURN(SelectObject(hdc, BACKGROUND_PEN)); Rectangle(hdc, x_offset, Y_SCREEN_OFFSET, x_offset + PAINT_WIDTH, y_offset); DrawBitmap(hdc, topbar_Image, x_offset, Y_SCREEN_OFFSET, SRCCOPY); if (drawTrustedMIDletIcon == KNI_TRUE) { DrawBitmap(hdc, TrustIcon_Image, TrustIcon_xposition, TrustIcon_yposition, SRCCOPY); } REFRESHTOPBAR(); /* draw top border of menu */ DrawMenuBarBorder(hdc);#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) CHECK_RETURN(SelectObject(hdc, BACKGROUND_PEN)); CHECK_RETURN(SelectObject(hdc, BACKGROUND_BRUSH)); /* clear the arrow area */ Rectangle(hdc, VERT_X, UP_Y, VERT_X + 8, UP_Y + BOTTOM_BAR_HEIGHT - 1); REFRESHBOTTOMBAR(); releaseBitmapDC(hdc); LCDUIsetSoftButton(1, rlabel.label, rlabel.num); } REFRESHBOTTOMBAR();}/* Sets the top bar to display a trusted MIDlet icon, * then calls drawEmulatorScreen to cause an invalidate of * the top bar */void LCDUIdrawTrustedIcon(jboolean trusted) { drawTrustedMIDletIcon = trusted; drawEmulatorScreen(inFullScreenMode);}/* draws the top border of the menu: a one pixel thick dark gray * line on top of a one pixel thick white line */void DrawMenuBarBorder(HDC myhdc){ CHECK_RETURN(SelectObject(myhdc, darkGrayBrush)); CHECK_RETURN(SelectObject(myhdc, darkGrayPen)); MoveToEx(myhdc, x_offset, y_offset + paintHeight, NULL); LineTo(myhdc, x_offset + PAINT_WIDTH, y_offset + paintHeight); CHECK_RETURN(SelectObject(myhdc, whiteBrush)); CHECK_RETURN(SelectObject(myhdc, whitePen)); MoveToEx(myhdc, x_offset, y_offset + paintHeight + 1, NULL); LineTo(myhdc, x_offset + PAINT_WIDTH, y_offset + paintHeight + 1);}void setEmulatorScreenMode(jboolean fullscreen) { setUpOffsets(fullscreen); drawEmulatorScreen(fullscreen); /* defined as static in defaultLCDUI.c */ inFullScreenMode = fullscreen;}void restoreEmulatorScreenMode() { if (inFullScreenMode != requestedFullScreenMode) { setEmulatorScreenMode(requestedFullScreenMode); }}void LCDUISetEmulatorFullScreenMode(jboolean mode) { /* defined as static in defaultLCDUI.c */ requestedFullScreenMode = mode; setCommandsFullScreenMode(mode); setEmulatorScreenMode(mode);}/* * Returns a DC for the graphics code to draw into. * * In the current implementation, this returns a DC of an off-screen * bitmap. All drawings will be first drawn into the bitmap and later * BLT'ed to the simulator window. */HDC getBitmapDC(void *imageData){ HDC hdc, hdcMem; HANDLE *mutex = (HANDLE*) TlsGetValue(tlsId); if (mutex == NULL) { mutex = midpMalloc(sizeof(HANDLE)); if (mutex == NULL) { return NULL; } TlsSetValue(tlsId, mutex); *mutex = CreateMutex(0, KNI_FALSE, "hScreenBitmapMutex"); } hdc = GetDC(hMainWindow); hdcMem = CreateCompatibleDC(hdc); ReleaseDC(hMainWindow, hdc); WaitForSingleObject(*mutex, INFINITE); if (imageData == NULL) { CHECK_RETURN(getBitmapDCtmp = SelectObject(hdcMem, hScreenBitmap)); SetWindowOrgEx(hdcMem, -x_offset, -y_offset, NULL); } else if (imageData == UNTRANSLATED_SCREEN_BITMAP) { CHECK_RETURN(getBitmapDCtmp = SelectObject(hdcMem, hScreenBitmap)); } else { myBitmapStruct *bmp = (myBitmapStruct *)imageData; if (bmp->mutable) { getBitmapDCtmp = SelectObject(hdcMem, bmp->bitmap); } } return hdcMem;}void releaseBitmapDC(HDC hdcMem){ HANDLE *mutex = (HANDLE*) TlsGetValue(tlsId); SelectObject(hdcMem, getBitmapDCtmp); getBitmapDCtmp = NULL; DeleteDC(hdcMem); ReleaseMutex(*mutex);}void setupClip(HDC hdc, void *imageData, short *clip){ HRGN rgn; RECT r; myBitmapStruct *b = (myBitmapStruct*) imageData; r.left = 0; r.right = b ? b->width : PAINT_WIDTH; r.top = 0; r.bottom = b ? b->height : paintHeight; if (clip) { if (r.left < clip[0]) r.left = clip[0]; if (r.top < clip[1]) r.top = clip[1]; if (r.right > clip[0] + clip[2]) r.right = clip[0] + clip[2]; if (r.bottom > clip[1] + clip[3]) r.bottom = clip[1] + clip[3]; } rgn = CreateRectRgnIndirect(&r); SelectClipRgn(hdc, rgn); if (imageData == NULL) OffsetClipRgn(hdc, x_offset, y_offset); DeleteObject(rgn); /* it's been copied */}voidrefreshPaintWindow(int x1, int y1, int x2, int y2) { RECT r; if (x1 < x2) { r.left = x1 + x_offset; r.right = x2 + x_offset; } else { r.left = x2 + x_offset; r.right = x1 + x_offset; } if (y1 < y2) { r.top = y1 + y_offset; r.bottom = y2 + y_offset; } else { r.top = y2 + y_offset; r.bottom = y1 + y_offset; } ++r.bottom; ++r.right; InvalidateRect(hMainWindow, &r, KNI_TRUE); }void refreshWholePaintWindow(){ refreshPaintWindow(0, 0, PAINT_WIDTH, paintHeight);}/* static int/* makePixel(int rgb, int gray, int isGray) { */int LCDUIgetPixel(int rgb, int gray, int isGray) { if (numColors == 2) { return (gray > 127) ? grayTable4[3] : grayTable4[0]; } else if (numColors == 4) { return grayTable4[gray >> 6]; } else if (numColors == 16) { return grayTable16[gray >> 4]; } else if (numColors == 256) { int red = (rgb >> 16) & 0xff; int grn = (rgb >> 8) & 0xff; int blu = (rgb >> 0) & 0xff; red = rgtable[red >> 5]; grn = rgtable[grn >> 5]; blu = btable[blu >> 6]; return RGB(red, grn, blu); } else { fprintf(stderr, "unsupported color format\n"); return 0; }}static voidCreateScreenBitmap(HDC hdc) { int i; HDC hdcMem = CreateCompatibleDC(hdc); BITMAPINFOHEADER* b = phone_dib; HBITMAP img, tmp; int cmapLen; HANDLE *mutex; BITMAPINFOHEADER* grayLEDInfo = grayLED_dib; BITMAPINFOHEADER* greenLEDInfo = greenLED_dib; BITMAPINFOHEADER* topbarInfo = topbar_dib; BITMAPINFOHEADER* trustIconInfo = trustedIcon_dib; backgroundColor = lightGrayPixel; foregroundColor = blackPixel; tlsId = TlsAlloc(); mutex = midpMalloc(sizeof(HANDLE)); if (mutex == NULL) { return; } TlsSetValue(tlsId, mutex); *mutex = CreateMutex(0, KNI_FALSE, "hScreenBitmapMutex"); WaitForSingleObject(*mutex, INFINITE); hScreenBitmap = CreateCompatibleBitmap(hdc, EMULATOR_WIDTH, EMULATOR_HEIGHT); CHECK_RETURN(tmp = SelectObject(hdcMem, hScreenBitmap)); cmapLen = (b->biBitCount > 8) ? 0 : (b->biClrUsed ? b->biClrUsed : (1 << b->biBitCount)); img = CreateDIBitmap(hdc, b, CBM_INIT, ((char*)b) + b->biSize + 4*cmapLen, (BITMAPINFO*)b, DIB_RGB_COLORS); DrawBitmap(hdcMem, img, 0, 0, SRCCOPY); CHECK_RETURN(SelectObject(hdcMem, BACKGROUND_PEN)); CHECK_RETURN(SelectObject(hdcMem, BACKGROUND_BRUSH)); Rectangle(hdcMem, x_offset - 1, y_offset - topBarHeight - 1, x_offset + DISPLAY_WIDTH + 1, y_offset - topBarHeight + DISPLAY_HEIGHT + 1); DeleteObject(img); cmapLen = (topbarInfo->biBitCount > 8) ? 0 : (topbarInfo->biClrUsed ? topbarInfo->biClrUsed : (1 << topbarInfo->biBitCount)); topbar_Image = CreateDIBitmap(hdc, topbarInfo, CBM_INIT, ((char*)topbarInfo) + topbarInfo->biSize + 4*cmapLen, (BITMAPINFO*)topbarInfo, DIB_RGB_COLORS); DrawBitmap(hdcMem, topbar_Image, X_SCREEN_OFFSET, Y_SCREEN_OFFSET, SRCCOPY); /* Create dim (default) network indicator and draw it */ cmapLen = (grayLEDInfo->biBitCount > 8) ? 0 : (grayLEDInfo->biClrUsed ? grayLEDInfo->biClrUsed : (1 << grayLEDInfo->biBitCount)); LED_off_Image = CreateDIBitmap(hdc, grayLEDInfo, CBM_INIT, ((char*)grayLEDInfo) + grayLEDInfo->biSize + 4*cmapLen, (BITMAPINFO*)grayLEDInfo, DIB_RGB_COLORS); DrawBitmap(hdcMem, LED_off_Image, LED_xposition, LED_yposition, SRCCOPY); /* Create bright network indicator */ cmapLen = (greenLEDInfo->biBitCount > 8) ? 0 : (greenLEDInfo->biClrUsed ? greenLEDInfo->biClrUsed : (1 << greenLEDInfo->biBitCount)); LED_on_Image = CreateDIBitmap(hdc, greenLEDInfo, CBM_INIT, ((char*)greenLEDInfo) + greenLEDInfo->biSize + 4 * cmapLen, (BITMAPINFO*)greenLEDInfo, DIB_RGB_COLORS); /* Create trusted icon */ cmapLen = (trustIconInfo->biBitCount > 8) ? 0 : (trustIconInfo->biClrUsed ? trustIconInfo->biClrUsed : (1 << trustIconInfo->biBitCount)); TrustIcon_Image = CreateDIBitmap(hdc, trustIconInfo, CBM_INIT, ((char*)trustIconInfo) + trustIconInfo->biSize + 4 * cmapLen, (BITMAPINFO*)trustIconInfo, DIB_RGB_COLORS); /* SetTextColor(hdcMem, RGB(255,255,255)); */ /* SetTextAlign(hdcMem, TA_TOP | TA_LEFT); */ /* SetBkMode(hdcMem, TRANSPARENT); */ /* TextOut(hdcMem, 8, 8, "kvm", 3); */ /* SetBkMode(hdcMem, OPAQUE); */ SelectObject(hdcMem, tmp); DeleteDC(hdcMem); ReleaseMutex(*mutex);}voidCreateBacklight(HDC hdc) { if (KNI_FALSE == bkliteImageCreated) { int cmapLen; BITMAPINFOHEADER* bkliteTopInfo = bkliteTop_dib; BITMAPINFOHEADER* bkliteBottomInfo = bkliteBottom_dib; BITMAPINFOHEADER* bkliteLeftInfo = bkliteLeft_dib; BITMAPINFOHEADER* bkliteRightInfo = bkliteRight_dib; /* Create top backlight bar */ cmapLen = (bkliteTopInfo->biBitCount > 8) ? 0 : (bkliteTopInfo->biClrUsed ? bkliteTopInfo->biClrUsed : (1 << bkliteTopInfo->biBitCount)); bklite_Top_Image = CreateDIBitmap(hdc, bkliteTopInfo, CBM_INIT, ((char*)bkliteTopInfo) + bkliteTopInfo->biSize + 4 * cmapLen, (BITMAPINFO*)bkliteTopInfo, DIB_RGB_COLORS); /* Create bottom backlight bar */ cmapLen = (bkliteBottomInfo->biBitCount > 8) ? 0 : (bkliteBottomInfo->biClrUsed ? bkliteBottomInfo->biClrUsed : (1 << bkliteBottomInfo->biBitCount)); bklite_Bottom_Image = CreateDIBitmap(hdc, bkliteBottomInfo, CBM_INIT, ((char*)bkliteBottomInfo) + bkliteBottomInfo->biSize + 4 * cmapLen, (BITMAPINFO*)bkliteBottomInfo, DIB_RGB_COLORS); /* Create left backlight bar */ cmapLen = (bkliteLeftInfo->biBitCount > 8) ? 0 : (bkliteLeftInfo->biClrUsed ? bkliteLeftInfo->biClrUsed : (1 << bkliteLeftInfo->biBitCount)); bklite_Left_Image = CreateDIBitmap(hdc, bkliteLeftInfo, CBM_INIT, ((char*)bkliteLeftInfo) + bkliteLeftInfo->biSize + 4 * cmapLen, (BITMAPINFO*)bkliteLeftInfo, DIB_RGB_COLORS); /* Create right backlight bar */ cmapLen = (bkliteRightInfo->biBitCount > 8) ? 0 : (bkliteRightInfo->biClrUsed ? bkliteRightInfo->biClrUsed : (1 << bkliteRightInfo->biBitCount)); bklite_Right_Image = CreateDIBitmap(hdc, bkliteRightInfo, CBM_INIT, ((char*)bkliteRightInfo) + bkliteRightInfo->biSize + 4 * cmapLen, (BITMAPINFO*)bkliteRightInfo, DIB_RGB_COLORS); bkliteImageCreated = KNI_TRUE; }}#ifdef SKINS_MENU_SUPPORTEDstatic HMENUbuildSkinsMenu(){ /* first step: find directory which contains skins */ char cdir[256], cur[256]; char *dir = getInternalProp("system.display.kh_skins"); HANDLE fileHandle; WIN32_FIND_DATA findData; if (dir == NULL) return NULL; if (!GetCurrentDirectory(sizeof(cdir), cdir)) return NULL; if (!SetCurrentDirectory(dir)) return NULL; GetCurrentDirectory(sizeof(cur), cur); fprintf(stderr, "Found alternate skins in %s\n", cur); fileHandle = FindFirstFile("*.bmp", &findData); if (fileHandle != INVALID_HANDLE_VALUE) { HMENU hMenu = CreateMenu(); HMENU hMenuPopup = CreateMenu(); char *addr; do { char name[256]; skins[numSkins] = midpMalloc(1024); if (skins[numSkins] != NULL) { GetFullPathName(findData.cFileName, 1024, skins[numSkins], &addr); sprintf(name, "%s", addr); /* remove the .bmp portion */ name[strlen(name) - 4] = '\0'; fprintf(stderr, " %s\n", name); AppendMenu(hMenuPopup, MF_STRING, numSkins++, name); if (numSkins >= NUM_SKINS_SUPPORTED) break; } } while (FindNextFile(fileHandle, &findData)); AppendMenu(hMenuPopup, MF_STRING, numSkins, "Original"); AppendMenu(hMenu, MF_POPUP, (UINT)hMenuPopup, "Color"); return hMenu;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -