Home |
Class PegScreen HMI (Human-Machine Interface) Classes |
Class PegScreenThe abstract base class PegScreen is the device driver which provides the drawing primitives used by the individual PEG objects to draw themselves on the display device. Class PegThing provides wrapper functions for the most commonly used PegScreen Drawing operations. class PegScreen { public: void Invalidate(const PegRect &Rect); virtual void BeginDraw(PegThing * Caller); virtual void EndDraw(void); virtual void BeginDraw(PegThing * Caller, PegBitmap * pMap); virtual void EndDraw(PegBitmap * pMap); int GetXRes(void); int GetYRes(void); virtual void SetPointerType(UCHAR bType); virtual void SetPointer(PegPoint); virtual void ShowPointer(BOOL bShow); PegPoint GetPointerPos(void); UCHAR GetPointerType(void); int GetXPointerOffset(void); int GetYPointerOffset(void); PegBitmap * GetPointer(void); virtual void SetPalette(int iFirst, int iNum, const UCHAR * pGet); virtual UCHAR * GetPalette(DWORD * pPutSize); virtual void ResetPalette(void); virtual DWORD NumColors(void); virtual PegBitmap * CreateBitmap(int wWidth, int wHeight); virtual void DestroyBitmap(PegBitmap * pMap); virtual void Capture(PegCapture * Info, PegRect &Rect); virtual void Restore(PegThing * Caller, PegCapture * Info, BOOL bOnTop = FALSE); virtual void Bitmap(PegThing * Caller, PegPoint Where, PegBitmap * Getmap, BOOL bOnTop = FALSE); virtual void BitmapFill(PegThing * Caller, PegRect Rect, PegBitmap * Getmap); PegBitmap * ResizeImage(PegBitmap * pSrc, int iWidth, int iHeight); virtual COLORVAL GetPixel(PegThing * Caller, int x, int y); virtual void PutPixel(PegThing * Caller, int x, int y, COLORVAL Color); virtual void Line(PegThing * Caller, int wXStart, int wYStart, int wXEnd, int wYEnd, const PegColor &Color, int wWidth = 1); void PatternLine(PegThing * Caller, int wXStart, int wYStart, int wXEnd, int wYEnd, PegColor &Color, int wWidth, DWORD dPattern); virtual void Rectangle(PegThing * Caller, const PegRect &Rect, const PegColor &Color, int wWidth = 1); void RectangleXOR(PegThing * Caller, const PegRect &InRect); UCHAR AddPointerType(PegBitmap * pMap, PEGUINT wXOffset, PEGUINT wYOffset); void Polygon(PegThing * Caller, PegPoint * pPoints, int iNumPoints, const PegColor &Color, int iWidth = 1); void Circle(PegThing * Caller, int xCenter, int yCenter, int r, PegColor &Color, int iWidth = 0); void Ellipse(PegThing * Caller, const PegRect &Bound, PegColor Color, int iWidth); virtual int RectMove(PegThing * Caller, PegRect MoveRect, PegPoint ClipTo, int xShift, int yShift); virtual void ViewportMove(PegThing * Caller, PegRect MoveRect, PegPoint MoveTo); PegFont * MakeFont(UCHAR uHeight, BOOL bBold = FALSE, BOOL bItalic = FALSE); void DeleteFont(PegFont * pFont); virtual void DrawText(PegThing * Caller, PegPoint Where, const PEGCHAR * Text, PegColor &Color, PegFont * Font, int Count = -1); virtual PEGINT TextHeight(const PEGCHAR * Text, PegFont * Font); virtual PEGINT TextWidth (const PEGCHAR * Text, PegFont * Font, int iLen = -1); UCHAR * DumpWindowsBitmap(DWORD * PutSize, PegRect &View); }; Method InvalidateInvalidate is called to notify PegScreen that a rectangular region of the screen needs to be redrawn. PegScreen does not allow any drawing to occur to an area of the screen which has not previously been invalidated. Predefined objects normally invalidate the correct areas of the screen when they are modified via a resize, move, of other modification that requires the object to redraw itself. In some cases you will be required to invalidate the client area of your custom objects before they will be allowed to draw themselves. Method BeginDrawThis method should be called at the beginning of every Draw() function. This call prepares the screen for output. The alternate form of BeginDraw is used to begin drawing into an off-screen bitmap. When this form of BeginDraw() is used, the PegScreen driver is placed into a virtual drawing mode, where all drawing functions operate within the off-screen bitmap, rather than drawing to the visible video memory buffer. Method EndDrawThis method should be called at the end of every Draw() function to notifies PegScreen that drawing has been completed. To end drawing to an off-screen bitmap, pass a pointer to the bitmap to EndDraw. Method GetXResReturns the horizontal screen resolution, in pixels. Method GetXResReturns the vertical screen resolution, in pixels. Method NumColorsReturns the current color depth expressed in number of colors supported. Method GetPaletteReturns a pointer to the current palette, and writes the number of palette entries to pPutSize. There will be 3 UCHAR values for each palette entry. These values are the Red, Green, and Blue components for each color value. Method SetPaletteInstalls the palette indicated by pPal. The number of entries in the palette are indicated by iNum, and the first entry to be modified is indicated by iFirst. To install a custom 256 color palette, for example, you would call SetPalette like this: SetPalette(0, 256, &PalData); Color palettes are 8-8-8 RGB color values. There should be (3 * iNum) UCHAR values in the array pointed to by pPal. Method ResetPaletteResets the current color palette back to the default state. Method GetXPointerOffsetReturns the X offset of the currently used mouse pointer. Method GetYPointerOffsetReturns the Y offset of the currently used mouse pointer. Method GetPointerTypeReturns the current pointer type. The following predefined pointer types are available: PPT_NORMAL, PPT_VSIZE, PPT_HSIZE, PPT_NWSE_SIZE, PPT_NESW_SIZE, PPT_IBEAM, PPT_HAND. Additional pointer shapes can also be defined and added by the application. Method AddPointerTypeThis function can be called to define a new pointer type, meaning a new pointer bitmap, when using a mouse or similar pointing device. The first parameter is a pointer to a PegBitmap to display when this pointer type is invoked via the SetPointerType() function. The x and y offset parameters specify the distance, in pixels, from the upper left corner of the bitmap to the bitmap hotspot. The RTPEG-32 screen drivers automatically position the pointer so that the hotspot is centered over the current pointer position. Method SetPointerTypeChanges the active pointer type. For example, PegWindow objects change the pointer type during resize operations as an indication to the user that the window's border is being dragged. Method ShowPointerUsing ShowPointer an application can hide or display the mouse pointer. Method GetPointerGetPointer returns a PegBitmap pointer to the current mouse pointer bitmap. Method GetPointerPosGetPointerPos returns the current coordinates of the mouse pointer. Method SetPointerSets the current position of the mouse pointer on the screen. Method CreateBitmapCreates a PegBitmap at run-time. A bitmap created in this fashion can be used as a 'virtual screen', allowing drawing to the off-screen bitmap instead of to the actual video memory. Method DestroyBitmapDeletes the bitmap associated with the pBitmap pointer. This method takes into account bitmaps that are using video memory directly, as opposed to bitmaps that are in system memory. This is the preferred method for deleting bitmaps that were created using the CreateBitmap method. Method ResizeImageCreates a new PegBitmap from an existing PegBitmap. The new bitmap is resized to iWidth x iHeight pixels regardless of the size of the source bitmap. Method BitmapDraws a bitmap on the screen. Parameter Where defines the upper-left corner position of the bitmap on the screen. Method BitmapFillBitmapFill fills a rectangular area of the screen with tiled copies of the bitmap pointed to by parameter GetMap. Parameter Rect defines the screen area to be filled, inclusive. Method CaptureCapture copies a screen portion specified by parameter Rect into a special bitmap of type PegCapture pointed to by Info. The given PegCapture should be created first using the default constructor. Method RestoreRestores a captured area of screen pixels. Method GetPixelReturns the color value associated with the pixel at screen coordinates x, y. Method PutPixelPlots a single point at the indicate x,y position in the indicated color. Method LineDraws a line. Optimizations are performed internally for vertical and horizontal lines. The start and end points of the line are inclusive. Method PatternLineDraws a dashed line. The dash pattern is determined by the dPattern parameter. For example, a dPattern value of 0xf0f0f0f0 would draw a line alternating between 4 pixels on and four pixels off. Method RectangleDraws a rectangle on the screen. The rectangle may have any border width, and may optionally be filled if the Color.uFlags parameter is set to CF_FILL. The rectangle border is drawn with Color.uForeground, and if the rectangle is filled it is filled with Color.uBackground. Method RectangleXORInverts the pixel color values of the indicated rectangle. Method PolygonDraws a polygon with the specified width. Method CircleDraws a circle at the indicated position and radius. The iWidth parameter determines the border width. Method EllipseDraws an Ellipse with the provided parameters. The ellipse is bounded on all sides by Bound. The ellipse is filled if the Color.uFlags value includes CF_FILL. The ellipse may have a border, drawn in Color.uForeground, of iWidth pixels. If the ellipse is filled, it is filled with Color.uBackground. Method RectMoveObjects use this function to rapidly scroll. The displayed screen image at parameter MoveRect is moved by the number of pixels given by xShift and yShift. Then, it is clipped to parameter ClipTo. The function returns 1 if the move operation was performed and 0 otherwise (i.e., the rectangle would no longer be completely visible). Method ViewportMoveViewportMove is similar to RectMove, however this version does viewport validation. This can produce interesting effects, such as scrolling the background of a window underneath child windows without affecting the child windows. This function is implemented using Capture and Bitmap. This is required to add viewport validation. If the derived PegScreen class uses SPRITE style bitmaps, this automatically makes use of that feature. Method MakeFontMakeFont is used to create a new bitmapped font at the indicated point size and style. Normally, you should create fonts using PegFontCapture. MakeFont and DeleteFont are used to create new fonts at run time. Due to rounding errors and limitations in the vector font format, fonts generated using MakeFont are generally not as visually appealing as fonts generated using PegFontCapture. Method DeleteFontFrees all memory associated with OldFont. DeleteFont should be called after the use of a font created with MakeFont is complete. Method TextHeightReturns the height in pixels of the indicated string using the indicated font. Method TextWidthReturns the width in pixels of the indicated string using the indicated font. Method DrawTextDraws text on the screen. Parameter Where determines the upper left starting position for drawing the text. If Count is >= 0, a maximum of Count characters will be drawn unless the string pointed to by Text is less than Count in length. If Count is set to -1, the entire null terminated string is drawn at the indicated position. Method DumpWindowsBitmapThis function creates a Microsoft Windows compatible bitmap file in memory. The bitmap file is an exact capture of the View rectangle. This function returns a pointer of the bitmap residing in memory; it is the caller's job to write the bitmap from memory into permanent storage such as a floppy or hard disk drive for use in a PC environment. The caller is responsible for freeing the memory associated with the memory bitmap. The file size (i.e. memory buffersize) is returned in the location pointed to by parameter PutSize, or a size of 0 to indicate failure. Example:The following example installs a custom palette. This palette would normally be a palette generated by PegImageConvert, although a palette can be created using several means. PEGINT MyWindow::Message(const PegMessage &Mesg) { switch(Mesg.wType) { case PM_SHOW: Screen()->SetPalette(0, 256, PegCustomPalette); PegWindow::Message(Mesg); break; case PM_HIDE: Screen()->ResetPalette(); PegWindow::Message(Mesg); break; default: return PegWindow::Message(Mesg); } return 0; }
|