📄 i_ugldsp.cpp
字号:
// Zinc Application Framework - I_SCRDSP.CPP// Copyright (c) 1999-2003 Wind River Systems, Inc.// COPYRIGHT (C) 1990-1999. All Rights Reserved.// Zinc Software Incorporated. Pleasant Grove, Utah USA/*modification history--------------------02g,19jun03,jlb Fix SPR 73194 - Font overflow02f,07jun01,bbj Cause Text() to fill to the region passed in (SPR 33551)02e,06jun01,bbj Remove some redundant code in ::Rectangle().02d,07may01,wdf Changed copyright date.02c,20dec00,bbj Fix image region ob1 error02b,06dec00,bbj Fix SPR 62156--clipping not working properly. Also fix cursor not displaying.02a,05dec00,bbj Fix text output to allow better antialiasing, especially on Agfa.01z,01dec00,wdf Fixed screen clipping problem for ID_ZAF_SCREEN in BeginDraw().01y,27oct00,bbj Fix unicode problem01x,25oct00,bbj Fix drawing problem01w,23oct00,wdf Changed copyright date.01v,12oct00,bbj Add support for distinguishing between visble and dirty region clipping with UGL windows01u,06oct00,bbj Fix capitalization on font names01t,20sep00,bbj Fix drawing to ID_ZAF_DIRECT, ID_ZAF_SCREEN01s,08aug00,bbj Switch to UGL windowing01r,13jul00,bbj UGL updates01q,01jun00,bbj Change font names01p,31may00,bbj Fix font allocation01o,19may00,bbj Add ID_ZAF_OFFSCREEN support01n,08may00,bbj Tweak BitmapBlt() for screen blts.01m,02may00,bbj Change BimapBlt to/from screen from UGL_DISPLAY_ID to UGL_DEFAULT_ID01l,02may00,bbj Add alpha channel support for UGL01k,21apr00,bbj Enable scaling for Image, BitmapBlt01j,13apr00,bbj Add image, off-screen bitmap support01i,01mar00,bbj UGL 2.0 updates01h,09feb00,bbj Use UGL region clipping01g,02feb00,bbj UGL 2.0 port01f,26oct99,wdf Added hot spot parameters to DeviceSet.01e,25oct99,jom Fix algorithm for Ellipse function01d,20oct99,wdf Fixed Bitmap() function so that bitmap will be drawn if only an ugl handle is passed in.01c,21sep99,wdf Added semaphore protection to make the library reenterant.01b,19aug99,wdf Removed statics for reentrance.01a,27jul99,wdf Eliminated commented and redundent code, unnecassary functions and #defines*/#include <zinc/z_stdio.hpp>#include <zinc/z_stdlib.hpp>#include <zinc/z_string.hpp>#include <zinc/z_scrdsp.hpp>#include <zinc/z_win.hpp>#include <zinc/z_utils.hpp>#if defined(ZAF_RTOS)# include <zinc/z_system.hpp>#endif#if defined(ZAF_MSDOS)# include <math.h># if defined(__BORLANDC__) && defined(DOSX286)# include <phapi.h># endif# include <dos.h>#elif defined(ZAF_VXWORKS)# include <math.h>#elif defined(ZAF_PSOS) && defined(__CADUL__)# include <mathcu.h>#endif#define ZAF_SCREEN_DISPLAY_INFO#include <zinc/data/gbl_def.hpp>bool _devicePainting = false;UGL_ARGB defaultColorTable[] ={ UGL_MAKE_ARGB(255, 0, 0, 0), UGL_MAKE_ARGB(255, 0, 0, 128), UGL_MAKE_ARGB(255, 0, 128, 0), UGL_MAKE_ARGB(255, 0, 128, 128), UGL_MAKE_ARGB(255, 128, 0, 0), UGL_MAKE_ARGB(255, 128, 0, 128), UGL_MAKE_ARGB(255, 128, 0, 0), UGL_MAKE_ARGB(255, 192, 192, 192), UGL_MAKE_ARGB(255, 128, 128, 128), UGL_MAKE_ARGB(255, 0, 0, 255), UGL_MAKE_ARGB(255, 0, 255, 0), UGL_MAKE_ARGB(255, 0, 255, 255), UGL_MAKE_ARGB(255, 255, 0, 0), UGL_MAKE_ARGB(255, 255, 0, 255), UGL_MAKE_ARGB(255, 255, 255, 0), UGL_MAKE_ARGB(255, 255, 255, 255)};static struct ZafPattern{ int width; int height; unsigned char data[16];} defaultPatternTable[] ={ { 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, { 64, 2, { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 } }};static OSLineStyle ZAF_FARDATA _lineStyleData[] ={ UGL_LINE_STYLE_SOLID, // ZAF_LINE_SOLID UGL_LINE_STYLE_DASHED // ZAF_LINE_DOTTED};static OSMode ZAF_FARDATA _modeData[] ={// zREPz, // ZAF_MODE_COPY// zXORz // ZAF_MODE_XOR 0, 1};static OSMono ZAF_FARDATA _monoData[] ={ ZAF_MONO_BLACK, ZAF_MONO_DIM, ZAF_MONO_NORMAL, ZAF_MONO_HIGH};static ZafPaletteStruct ZAF_FARDATA __xorPalette ={ ZAF_LINE_SOLID, ZAF_PTN_SOLID_FILL, ZAF_CLR_WHITE, ZAF_CLR_BLACK, ZAF_MONO_NULL, ZAF_MONO_NORMAL, ZAF_FNT_DIALOG};static ZafPaletteStruct ZAF_FARDATA __markedTextPalette ={ ZAF_LINE_SOLID, ZAF_PTN_SOLID_FILL, ZAF_CLR_WHITE, ZAF_CLR_BLUE, ZAF_MONO_NULL, ZAF_MONO_NORMAL, ZAF_FNT_DIALOG};ZafPaletteStruct *ZafScreenDisplay::markPalette = &__markedTextPalette;ZafPaletteStruct *ZafScreenDisplay::xorPalette = &__xorPalette;// ----- ZafScreenDisplay ---------------------------------------------------ZafScreenDisplay::ZafScreenDisplay(int &, char **) : ZafDisplay(), initialized(false){#if defined(ZAF_RTOS) ZafSystem::InitializeSemaphore(ZafScreenDisplay::classSem, false, false);#endif oldWindowRegionType = 0xFFFF; uglInitialize(); /* Obtain display device identifier */ uglDriverFind (UGL_DISPLAY_TYPE, 0, (UGL_UINT32 *)&devID); uglDriverFind (UGL_FONT_ENGINE_TYPE, 0, (UGL_UINT32 *)&fontDrvId); gc = uglGcCreate(devID); originalGC = UGL_NULL; /* Obtain the demensions of the display */ UGL_MODE_INFO modeInfo; uglInfo(devID, UGL_MODE_INFO_REQ, &modeInfo); columns = modeInfo.width; lines = modeInfo.height; // Initialize fonts. UGL_ORD textOrigin = UGL_FONT_TEXT_UPPER_LEFT; uglFontDriverInfo(fontDrvId, UGL_FONT_TEXT_ORIGIN, &textOrigin); int i; for (i = 0; i < ZAF_MAXFONTS; i++) fontTable[i] = 0; UGL_FONT_DESC fontDesc; UGL_FONT_DESC_PRIORITY fontDescPriority; UGL_FONT_DEF fontDef; fontDescPriority.faceName = 10; fontDescPriority.pixelSize = 9; fontDescPriority.weight = 8; fontDescPriority.spacing = 7; fontDescPriority.charSet = UGL_FONT_DONT_CARE; fontDescPriority.italic = UGL_FONT_DONT_CARE; fontDesc.charSet = UGL_FONT_ISO_8859_1; fontDesc.italic = UGL_FONT_UPRIGHT; fontDesc.spacing = UGL_FONT_PROPORTIONAL; fontDesc.pixelSize.min = 8; fontDesc.pixelSize.max = 8; fontDesc.weight.min = UGL_FONT_BOLD_MIN; fontDesc.weight.max = UGL_FONT_BOLD_LIGHT; strncpy(fontDesc.faceName, "Lucida Sans", sizeof(fontDesc.faceName)); fontDesc.faceName[sizeof(fontDesc.faceName) - 1] = 0; uglFontFind(fontDrvId, &fontDesc, &fontDescPriority, &fontDef); fontTable[ZAF_FNT_SMALL] = uglFontCreate(fontDrvId, &fontDef); fontDesc.pixelSize.min = 12; fontDesc.pixelSize.max = 12; uglFontFind(fontDrvId, &fontDesc, &fontDescPriority, &fontDef); fontTable[ZAF_FNT_APPLICATION] = uglFontCreate(fontDrvId, &fontDef); // Creating the same font will not actually allocate more memory. // It will simply increment a use count. fontTable[ZAF_FNT_SYSTEM] = uglFontCreate(fontDrvId, &fontDef); fontDesc.weight.min = UGL_FONT_BOLD_LIGHT; fontDesc.weight.max = UGL_FONT_BOLD_HEAVY; strncpy(fontDesc.faceName, "Helvetica", sizeof(fontDesc.faceName)); fontDesc.faceName[sizeof(fontDesc.faceName) - 1] = 0; uglFontFind(fontDrvId, &fontDesc, &fontDescPriority, &fontDef); fontTable[ZAF_FNT_DIALOG] = uglFontCreate(fontDrvId, &fontDef); fontDesc.weight.min = UGL_FONT_BOLD_MIN; fontDesc.weight.max = UGL_FONT_BOLD_LIGHT; fontDesc.spacing = UGL_FONT_MONO_SPACED; strncpy(fontDesc.faceName, "Courier", sizeof(fontDesc.faceName)); fontDesc.faceName[sizeof(fontDesc.faceName) - 1] = 0; uglFontFind(fontDrvId, &fontDesc, &fontDescPriority, &fontDef); fontTable[ZAF_FNT_FIXED] = uglFontCreate(fontDrvId, &fontDef); // Initialize tables. for (i = 0; i < sizeof(_lineStyleData) / sizeof(OSLineStyle); i++) lineTable[i] = _lineStyleData[i]; for (i = 0; i < sizeof(_modeData) / sizeof(OSMode); i++) modeTable[i] = _modeData[i]; for (i = 0; i < sizeof(_monoData) / sizeof(OSMono); i++) monoTable[i] = _monoData[i]; UGL_MDIB mDib; memset(patternTable, 0, ZAF_MAXPATTERNS * sizeof(OSFillPattern)); for (i = 0; i < sizeof(defaultPatternTable) / sizeof(ZafPattern); i++) if (defaultPatternTable[i].width) { mDib.width = defaultPatternTable[i].width; mDib.height = defaultPatternTable[i].height; mDib.stride = defaultPatternTable[i].width; mDib.pImage = defaultPatternTable[i].data; patternTable[i] = uglMonoBitmapCreate(devID, &mDib, UGL_DIB_INIT_DATA, 0, UGL_DEFAULT_MEM); } else patternTable[i] = ZAF_NULLH(UGL_MDDB_ID); // Initialize the device image array. for (i = 0; i < ZAF_MAXIMAGES; i++) { devImage[i].scrBitmapID = ZAF_NULLH(UGL_DDB_ID); devImage[i].devBitmapID = ZAF_NULLH(UGL_TDDB_ID); devImage[i].movePending = false; devImage[i].newX = devImage[i].newY = 0; devImage[i].clip.left = devImage[i].clip.top = devImage[i].clip.right = devImage[i].clip.bottom = devImage[i].devRegion.left = devImage[i].devRegion.top = devImage[i].devRegion.right = devImage[i].devRegion.bottom = 0; } // Initialize the display variables. virtualCount = 0; stopDevice = 0; drawRegionDepth = 0; palette.lineStyle = ZAF_LINE_DEFAULT; palette.fillPattern = ZAF_PTN_DEFAULT; palette.colorForeground = ZAF_CLR_DEFAULT; palette.colorBackground = ZAF_CLR_DEFAULT; palette.monoForeground = ZAF_MONO_DEFAULT; palette.monoBackground = ZAF_MONO_DEFAULT; palette.font = ZAF_FNT_DEFAULT; masterClip.left = masterClip.top = 0; masterClip.right = columns - 1; masterClip.bottom = lines - 1; masterClip.coordinateType = clipRegion.coordinateType = ZAF_PIXEL; SetClipRegion(masterClip); // Initialize the ZafCoordinateStruct statics. preSpace = 2; postSpace = 2; miniNumeratorX = miniNumeratorY = 1; miniDenominatorX = miniDenominatorY = 10; pixelsPerInchX = 60; //??? magic numbers. pixelsPerInchY = 60; // Initialize colorUsedTable. 1st 32 colors are "in use" by default. for (i = 0; i < ZAF_MAXCOLORS; ++i) colorUsedTable[i] = false; // Initialize colorTable. memset(colorTable, 0, sizeof(colorTable)); int numColors = sizeof(defaultColorTable) / sizeof(UGL_ARGB); uglColorAlloc(devID, defaultColorTable, NULL, colorTable, numColors); for (i = 0; i < numColors; i++) colorUsedTable[i] = true; // Set initial display information. SetForeground(ZAF_CLR_WHITE); SetBackground(ZAF_CLR_BLACK); SetMonoForeground(ZAF_MONO_NORMAL); SetMonoBackground(ZAF_MONO_BLACK); SetFillPattern(ZAF_PTN_SOLID_FILL); SetFont(ZAF_FNT_DIALOG); SetMode(ZAF_MODE_COPY); SetLineStyle(ZAF_LINE_SOLID); ZafRegionStruct sizeRegion = TextSize(ZAF_ITEXT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); cellWidth = (sizeRegion.Width() + 19) / 39; cellHeight = (sizeRegion.Height() * 15 + 6) / 13 + 2 * ZAF_TEXT_MARGIN_SIZE + 2 * ZAF_BORDER_SIZE + preSpace + postSpace; miniNumeratorX = 1; miniDenominatorX = 10; miniNumeratorY = 1; miniDenominatorY = 10; pixelsPerInchX = 72; pixelsPerInchY = 72; initialized = true;}ZafScreenDisplay::~ZafScreenDisplay(void){ // Restore the display if it was initialized correctly. if (initialized) { for (int logicalFont = 0; logicalFont < ZAF_MAXFONTS; logicalFont++) DestroyFont(logicalFont); int i; for (i = 0; i < ZAF_MAXIMAGES; i++) { if (devImage[i].scrBitmapID) { uglBitmapDestroy(devID, devImage[i].scrBitmapID); devImage[i].scrBitmapID = ZAF_NULLH(UGL_DDB_ID); } if (devImage[i].devBitmapID) { uglBitmapDestroy(devID, devImage[i].devBitmapID); devImage[i].devBitmapID = ZAF_NULLH(UGL_DDB_ID); } } for (i = 0; i < ZAF_MAXPATTERNS; i++) if (patternTable[i]) { uglFillPatternSet(gc, 0); uglMonoBitmapDestroy(devID, patternTable[i]); } uglGcDestroy(gc); uglDeinitialize(); }#if defined(ZAF_RTOS) if (ZafScreenDisplay::classSem) { delete ZafScreenDisplay::classSem; ZafScreenDisplay::classSem = ZAF_NULLP(ZafSemaphore);; }#endif}// --- Bitmap ---------------------------------------------------------------ZafError ZafScreenDisplay::Bitmap(ZafCoordinate column, ZafCoordinate line, ZafBitmapStruct &bitmap){#if defined(ZAF_RTOS) ZafAutoSemaphore autoSem(ZafScreenDisplay::classSem);#endif int pixelColumn, 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 (!bitmap.array && !bitmap.handle) return (ZAF_ERROR_VALUE_MISSING); if (!bitmap.handle) ConvertToOSBitmap(bitmap); // Save the user's clip region so can restore it when done drawing. ZafRegionStruct clip, saveClip = ClipRegion(); // Draw the bitmap on the display. uglBitmapBlt(gc, bitmap.handle, 0, 0, bitmap.width - 1, bitmap.height - 1, UGL_DEFAULT_ID, pixelColumn, pixelLine); return (ZAF_ERROR_NONE);}ZafError ZafScreenDisplay::ConvertToOSBitmap(ZafBitmapStruct &bitmap){ if (!bitmap.array) return (ZAF_ERROR_INVALID_SOURCE); if (bitmap.handle && bitmap.StaticHandle()) return (ZAF_ERROR_INVALID_TARGET);#if defined(ZAF_RTOS) ZafScreenDisplay::classSem->Take(ZAF_WAIT_FOREVER_SEMAPHORE);#endif if (bitmap.handle) DestroyOSBitmap(bitmap); UGL_COLOR *bitmapData = new UGL_COLOR[bitmap.width * bitmap.height]; unsigned char *maskData = new unsigned char[(bitmap.width * bitmap.height + 7) / 8]; memset(maskData, 0xFF, (bitmap.width * bitmap.height + 7) / 8); unsigned char *maskPtr = maskData; unsigned char mask = 0x80; bool transparent = false; for (int index = 0; index < bitmap.height * bitmap.width; index++) { if (bitmap.array[index] == ZAF_CLR_BACKGROUND) { bitmapData[index] = 0; *maskPtr &= ~mask; transparent = true; } else bitmapData[index] = colorTable[bitmap.array[index]]; mask >>= 1; if (mask == 0) { mask = 0x80; maskPtr++; } } UGL_DIB dib; dib.height = bitmap.height; dib.width = bitmap.width;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -