Home |
Class PegTextButton HMI (Human-Machine Interface) Classes |
Class PegTextButtonPegTextButton provides a pushbutton object with visual feedback indicating to the user the button depress and release operation. Any custom fonts or colors may be applied to PegTextButton. Users often create custom derived versions of PegTextButton to draw modified border styles, modified border shapes, etc.. PegTextButton is also commonly used to populate PegHorzList and PegVertList objects. While PegTextButton is most often a 'bottom level' object, it is possible to add children to a PegTextButton to further customize the appearance of your user interface. The text string displayed on the button face is vertically centered over button client area, and may be horizontally justified in different ways using the text justification style flags. class PegTextButton : public PegButton, public PegTextThing { public: PegTextButton(PegRect &, const PEGCHAR * Text, PEGUINT wId = 0, PEGUINT wStyle = AF_ENABLED); PegTextButton(int wLeft, int wTop, int iWidth, const PEGCHAR * Text, PEGUINT wId = 0, PEGUINT wStyle = AF_ENABLED); PegTextButton(int wLeft, int wTop, const PEGCHAR * Text, PEGUINT wId = 0, PEGUINT wStyle = AF_ENABLED); virtual void Draw(void); virtual void DataSet(const PEGCHAR * Text); }; Demo programs PegDemo, Robot, and Table use this class. Style FlagsTJ_RIGHT, TJ_LEFT, TJ_CENTER, TT_COPY, BF_REPEAT, BF_DOWNACTION, AF_ENABLED. SignalsPegTextButton sends PSF_CLICKED signals when selected. ConstructorsPegTextButton offers three constructors, depending on how you want to specify the button size. The first constructor allows you to fully specify the button size and position. The second constructor allows you to specify the top-left corner of the button and the button width. The last constructor allows you to specify the top-left corner position of the button. In this case the button calculates its own height based on the default system font. Method DrawPegTextButton overrides the Draw() function to draw the text on the button face. Method DataSetPegTextButton overrides the DataSet() function to invalidate the button client area. ExamplesThe following are each different styles of PegTextButton: The following is an example of overriding the Draw() function to create a custom button appearance. This example creates a button similar to the lower-right example above. void CustomButton::Draw(void) { PegColor Color; BeginDraw(); if (Style() & BF_SELECTED) Color.uForeground = BLACK; else Color.uForeground = LIGHTGRAY; // draw the top: Line(mReal.wLeft, mReal.wTop, mReal.wRight, mReal.wTop, Color, 3); // draw the left: Line(mReal.wLeft, mReal.wTop, mReal.wLeft, mReal.wBottom, Color, 3); if (Style() & BF_SELECTED) Color.uForeground = LIGHTGRAY; else Color.uForeground = BLACK; // draw the right shadow: Line(mReal.wRight, mReal.wTop, mReal.wRight, mReal.wBottom - 2, Color, 1); Line(mReal.wRight - 1, mReal.wTop + 1, mReal.wRight - 1, mReal.wBottom - 2, Color, 1); Line(mReal.wRight - 2, mReal.wTop + 2, mReal.wRight - 2, mReal.wBottom - 2, Color, 1); // draw the bottom shadow: Line(mReal.wLeft, mReal.wBottom, mReal.wRight, mReal.wBottom, Color, 1); Line(mReal.wLeft + 1, mReal.wBottom - 1, mReal.wRight, mReal.wBottom - 1, Color, 1); Line(mReal.wLeft + 2, mReal.wBottom - 2, mReal.wRight, mReal.wBottom - 1, Color, 1); // fill in the button client area: Color.Set(LIGHTRED, DARKGRAY, CF_FILL); Rectangle(mClient, Color); // draw the text centered: PegPoint Put; Put.x = (mClient.wLeft + mClient.wRight) >> 1; Put.x -= TextWidth(mpText, &SysFont) >> 1; Put.y = mClient.wTop + 1; if (Style() & BF_SELECTED) { Put.x++; Put.y++; } Color.Set(WHITE, BLACK, CF_NONE); DrawText(Put, mpText, Color, &SysFont); EndDraw(); }
|