?? i_ugldsp.cpp
字號:
dib.stride = bitmap.width; dib.colorFormat = UGL_DEVICE_COLOR_32; dib.clutSize = 0; dib.imageFormat = UGL_DIRECT; dib.pClut = UGL_NULL; dib.pImage = bitmapData; if (transparent) { bitmap.transparent = true; UGL_MDIB mDib; mDib.height = bitmap.height; mDib.width = mDib.stride = bitmap.width; mDib.pImage = maskData; bitmap.handle = uglTransBitmapCreate(devID, &dib, &mDib, UGL_DIB_INIT_DATA, 0, UGL_DEFAULT_MEM); } else bitmap.handle = uglBitmapCreate(devID, &dib, UGL_DIB_INIT_DATA, 0, UGL_DEFAULT_MEM); delete []bitmapData; delete []maskData;#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif if (bitmap.handle) return (ZAF_ERROR_NONE); else return (ZAF_ERROR_INVALID);}ZafError ZafScreenDisplay::ConvertToZafBitmap(ZafBitmapStruct &){ return (ZAF_ERROR_INVALID);}ZafError ZafScreenDisplay::CopyOSBitmap(ZafBitmapStruct &dest, const ZafBitmapStruct &src){#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif if (dest.handle && !dest.staticHandle) DestroyOSBitmap(dest); UGL_DIB dib; dib.height = src.height; dib.width = dib.stride = src.width; dib.colorFormat = UGL_DEVICE_COLOR_32; dib.clutSize = 0; dib.imageFormat = UGL_DIRECT; dib.pClut = UGL_NULL; dib.pImage = UGL_NULL; dest.width = src.width; dest.height = src.height; dest.handle = uglBitmapCreate(devID, &dib, UGL_DIB_INIT_NONE, 0, UGL_DEFAULT_MEM); BitmapBlt(&src, 0, 0, src.width, src.height, &dest, 0, 0); #if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (ZAF_ERROR_NONE);}ZafBitmapStruct *ZafScreenDisplay::CreateOSBitmap(int width, int height){#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif ZafBitmapStruct *bitmap = new ZafBitmapStruct; UGL_DIB dib; dib.height = height; dib.width = dib.stride = width; dib.colorFormat = UGL_DEVICE_COLOR_32; dib.clutSize = 0; dib.imageFormat = UGL_DIRECT; dib.pClut = UGL_NULL; dib.pImage = UGL_NULL; bitmap->handle = uglBitmapCreate(devID, &dib, UGL_DIB_INIT_NONE, 0, UGL_DEFAULT_MEM); bitmap->width = width; bitmap->height = height; #if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (bitmap);}ZafBitmapStruct *ZafScreenDisplay::CreateOSBitmap(UGL_DIB *dib, UGL_MDIB *mDib){ if (!dib || !dib->pImage) return (ZAF_NULLP(ZafBitmapStruct));#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif ZafBitmapStruct *bitmap = new ZafBitmapStruct; if (mDib) { bitmap->transparent = true; bitmap->handle = uglTransBitmapCreate(devID, dib, mDib, UGL_DIB_INIT_DATA, 0, UGL_DEFAULT_MEM); } else bitmap->handle = uglBitmapCreate(devID, dib, UGL_DIB_INIT_DATA, 0, UGL_DEFAULT_MEM); bitmap->width = dib->width; bitmap->height = dib->height; #if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (bitmap);}ZafError ZafScreenDisplay::DestroyOSBitmap(ZafBitmapStruct &bitmap){#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif if (bitmap.transparent) uglTransBitmapDestroy(devID, bitmap.handle); else uglBitmapDestroy(devID, bitmap.handle); bitmap.handle = ZAF_NULLH(UGL_BITMAP_ID);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (ZAF_ERROR_NONE);}// --- Icon -----------------------------------------------------------------ZafError ZafScreenDisplay::Icon(ZafCoordinate column, ZafCoordinate line, ZafIconStruct &icon){#if defined(ZAF_RTOS) ZafAutoSemaphore autoSem(ZafScreenDisplay::classSem);#endif int pixelColumn; int pixelLine; if (coordinateType == ZAF_PIXEL) { pixelColumn = int(column * scaleNumerator / scaleDenominator + originX); pixelLine = int(line * scaleNumerator / scaleDenominator + originY); } else { pixelColumn = (int)(ConvertXValue(column, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelLine = (int)(ConvertYValue(line, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); } if (!icon.array) return (ZAF_ERROR_VALUE_MISSING); if (!icon.handle) ConvertToOSIcon(icon); // Save the user's clip region so can restore it when done drawing. ZafRegionStruct clip, saveClip = ClipRegion(); // Draw the icon on the display. uglBitmapBlt(gc, icon.handle, 0, 0, icon.width - 1, icon.height - 1, UGL_DEFAULT_ID, pixelColumn, pixelLine); return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::ConvertToOSIcon(ZafIconStruct &icon){ if (!icon.array) return (ZAF_ERROR_INVALID_SOURCE); if (icon.handle && icon.StaticHandle()) return (ZAF_ERROR_INVALID_TARGET); if (icon.handle) DestroyOSIcon(icon); ZafBitmapStruct bitmap; bitmap.width = icon.width; bitmap.height = icon.height; bitmap.array = icon.array; bitmap.staticArray = icon.staticArray; ZafError error = ConvertToOSBitmap(bitmap); if (error == ZAF_ERROR_NONE) { icon.handle = bitmap.handle; icon.mask = bitmap.mask; icon.transparent = bitmap.transparent; } return (error);}ZafError ZafScreenDisplay::ConvertToZafIcon(ZafIconStruct &){ return (ZAF_ERROR_INVALID);}ZafError ZafScreenDisplay::DestroyOSIcon(ZafIconStruct &icon){#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif if (icon.transparent) uglTransBitmapDestroy(devID, icon.handle); else uglBitmapDestroy(devID, icon.handle); icon.handle = ZAF_NULLH(UGL_BITMAP_ID);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (ZAF_ERROR_NONE);}// --- Image -----------------------------------------------------------------ZafError ZafScreenDisplay::Image(OSImageID imageID, const ZafRegionStruct &srcRegion, const ZafRegionStruct &destRegion){ if (!imageID) return (ZAF_ERROR_VALUE_MISSING);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif int pixelSrcLeft, pixelSrcTop, pixelDestLeft, pixelDestTop, pixelDestRight, pixelDestBottom; int width = srcRegion.Width(); int height = srcRegion.Height(); if (coordinateType == ZAF_PIXEL) { pixelSrcLeft = (int)(srcRegion.left * scaleNumerator / scaleDenominator + originX); pixelSrcTop = (int)(srcRegion.top * scaleNumerator / scaleDenominator + originY); pixelDestLeft = (int)(destRegion.left * scaleNumerator / scaleDenominator + originX); pixelDestTop = (int)(destRegion.top * scaleNumerator / scaleDenominator + originY); pixelDestRight = (int)(destRegion.right * scaleNumerator / scaleDenominator + originX); pixelDestBottom = (int)(destRegion.bottom * scaleNumerator / scaleDenominator + originY); } else { pixelSrcLeft = (int)(ConvertXValue(srcRegion.left, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelSrcTop = (int)(ConvertYValue(srcRegion.top, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); pixelDestLeft = (int)(ConvertXValue(destRegion.left, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelDestTop = (int)(ConvertYValue(destRegion.top, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); pixelDestRight = (int)(ConvertXValue(destRegion.right, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelDestBottom = (int)(ConvertYValue(destRegion.bottom, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); } if (srcRegion.Width() == destRegion.Width() && srcRegion.Height() == destRegion.Height()) uglBitmapBlt(gc, imageID, pixelSrcLeft, pixelSrcTop, pixelSrcLeft + width - 1, pixelSrcTop + height - 1, UGL_DEFAULT_ID, pixelDestLeft, pixelDestTop); else uglBitmapStretchBlt(gc, imageID, pixelSrcLeft, pixelSrcTop, pixelSrcLeft + width - 1, pixelSrcTop + height - 1, UGL_DEFAULT_ID, pixelDestLeft, pixelDestTop, pixelDestRight, pixelDestBottom);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Give();#endif return (ZAF_ERROR_NONE);}// --- Mouse -----------------------------------------------------------------ZafError ZafScreenDisplay::Mouse(ZafCoordinate, ZafCoordinate, ZafMouseStruct &){ return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::ConvertToOSMouse(ZafMouseStruct &mouse){ if (!mouse.array) return (ZAF_ERROR_INVALID_SOURCE); if (mouse.handle && mouse.StaticHandle()) return (ZAF_ERROR_INVALID_TARGET); if (mouse.handle) uglCursorBitmapDestroy(devID, mouse.handle); UGL_ARGB argbClut[ZAF_MAXCOLORS]; uglColorConvert(devID, colorTable, UGL_DEVICE_COLOR_32, argbClut, UGL_ARGB8888, ZAF_MAXCOLORS); UGL_UINT8 *bitmapData = new UGL_UINT8[mouse.width * mouse.height]; for (int index = 0; index < mouse.height * mouse.width; index++) { UGL_UINT8 color = mouse.array[index] == ZAF_CLR_BACKGROUND ? UGL_CURSOR_COLOR_TRANSPARENT : mouse.array[index]; bitmapData[index] = color; } UGL_CDIB cDib; cDib.width = cDib.stride = mouse.width; cDib.height = mouse.height; cDib.hotSpot.x = mouse.hotSpotX; cDib.hotSpot.y = mouse.hotSpotY; cDib.clutSize = ZAF_MAXCOLORS; cDib.pClut = argbClut; cDib.pImage = bitmapData; mouse.handle = uglCursorBitmapCreate(devID, &cDib); delete []bitmapData; return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::ConvertToZafMouse(ZafMouseStruct &){ return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::DestroyOSMouse(ZafMouseStruct &mouse){ if (!mouse.handle || mouse.StaticHandle()) return (ZAF_ERROR_INVALID_SOURCE); uglCursorBitmapDestroy(devID, mouse.handle); mouse.handle = ZAF_NULLH(UGL_CDDB_ID); return (ZAF_ERROR_NONE);}// --- Text -----------------------------------------------------------------ZafError ZafScreenDisplay::Text(ZafCoordinate left, ZafCoordinate top, const ZafIChar *text, int length, int hotKeyIndex, bool fill){#if defined(ZAF_RTOS) ZafAutoSemaphore autoSem(ZafScreenDisplay::classSem);#endif // Get the text size. ZafRegionStruct textSize = TextSize(text, length); // Draw the text (textSize.right and textSize.bottom are width & height). return (Text(left, top, left + textSize.right - 1, top + textSize.bottom - 1, text, length, ZAF_HZ_LEFT, ZAF_VT_TOP, hotKeyIndex, fill));}ZafError ZafScreenDisplay::Text(ZafCoordinate left, ZafCoordinate top, ZafCoordinate right, ZafCoordinate bottom, const ZafIChar *text, int length, ZafHzJustify hzJustify, ZafVtJustify vtJustify, int hotKeyIndex, bool fill){ // Make sure we have a valid string. if (!text || !text[0]) return (ZAF_ERROR_INVALID);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif int pixelLeft; int pixelTop; int pixelRight; int pixelBottom; if (coordinateType == ZAF_PIXEL) { pixelLeft = int(left * scaleNumerator / scaleDenominator + originX); pixelTop = int(top * scaleNumerator / scaleDenominator + originY); pixelRight = int(right * scaleNumerator / scaleDenominator + originX); pixelBottom = int(bottom * scaleNumerator / scaleDenominator + originY); } else { pixelLeft = (int)(ConvertXValue(left, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelTop = (int)(ConvertYValue(top, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); pixelRight = (int)(ConvertXValue(right, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); pixelBottom = (int)(ConvertYValue(bottom, coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); } // Set up the fill line. ZafIChar ZAF_FARDATA fillLine[256];#if defined(ZAF_UNICODE) UGL_WCHAR ZAF_FARDATA fillLineW[256];#endif if (length < 0) length = strlen(text); if (length > 255) length = 255; strncpy(fillLine, text, length); fillLine[length] = '\0'; int hotKeyLeft, hotKeyRight; hotKeyLeft = hotKeyRight = 0; if (hotKeyIndex >= 0) { ZafIChar hotKeyBuf[2]; hotKeyBuf[0] = fillLine[hotKeyIndex]; hotKeyBuf[1] = fillLine[hotKeyIndex] = 0; hotKeyLeft = hotKeyIndex == 0 ? 0 : TextSize(fillLine).Width(); fillLine[hotKeyIndex] = hotKeyBuf[0]; hotKeyRight = hotKeyLeft + TextSize(hotKeyBuf).Width() - 1; } // Check for special characters. strrepc(fillLine, '\t', ' '); strrepc(fillLine, '\r', ' '); strrepc(fillLine, '\n', ' '); // Assign the rectangle to the region structure. ZafRegionStruct textSize = TextSize(text), cRegion = ClipRegion(); int pixelWidth = (int)(ConvertXValue(textSize.Width(), coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originX); int pixelHeight = (int)(ConvertYValue(textSize.Height(), coordinateType, ZAF_PIXEL) * scaleNumerator / scaleDenominator + originY); int leftText = pixelLeft; if (hzJustify == ZAF_HZ_RIGHT) leftText = pixelRight - pixelWidth; else if (hzJustify == ZAF_HZ_CENTER) { leftText += (pixelRight - pixelLeft - pixelWidth + 1) / 2; if (leftText < pixelLeft) leftText = pixelLeft; } // Adjust hotKey offsets. hotKeyLeft += leftText; hotKeyRight += leftText; int topText = pixelTop; if (vtJustify == ZAF_VT_BOTTOM) topText = pixelBottom - pixelHeight;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -