From: Andy D. <kha...@us...> - 2003-07-27 18:56:34
|
Update of /cvsroot/planeshift/planeshift/src/client/paws In directory sc8-pr-cvs1:/tmp/cvs-serv21813 Modified Files: pawsbutton.cpp pawsbutton.h Log Message: The pawsButton widget now supports button labels which will be drawn on top of any button images, the colour and font of the label can be set, and the text can be read from a xml file Index: pawsbutton.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/paws/pawsbutton.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** pawsbutton.cpp 27 Jul 2003 17:37:49 -0000 1.4 --- pawsbutton.cpp 27 Jul 2003 18:56:31 -0000 1.5 *************** *** 22,28 **** --- 22,31 ---- #include <config.h> + #include <ivideo/fontserv.h> + #include "pspawsmanager.h" #include "pawsbutton.h" #include "pawstexturemanager.h" + #include "pawsprefmanager.h" ////////////////////////////////////////////////////////////////////// *************** *** 39,42 **** --- 42,47 ---- pressedImage = NULL; releasedImage = NULL; + SetColour(); + font = windowManager->GetPrefs()->GetDefaultFont(); } *************** *** 70,74 **** } ! return true; } --- 75,84 ---- } ! // Get the button label ! csRef<iDocumentNode> buttonLabel = node->GetNode( "label" ); ! if ( buttonLabel ) ! { ! buttonLabel = buttonLabel->GetAttributeValue("text"); ! } return true; } *************** *** 88,91 **** --- 98,118 ---- } + void pawsButton::SetText(const char* text) + { + buttonLabel = text; + } + + void pawsButton::SetColour( int newColour ) + { + if ( newColour != -1 ) + { + colour = newColour; + } + else + { + colour = windowManager->GetPrefs()->GetDefaultFontColour(); + } + } + pawsButton::~pawsButton() { *************** *** 105,108 **** --- 132,156 ---- { if ( releasedImage ) releasedImage->Draw( screenFrame ); + } + if (!(buttonLabel.IsEmpty())) + { + // Draw the button label centered, on top of any graphics + int drawX=0; + int drawY=0; + int width; + int height; + font->GetDimensions( (const char*)buttonLabel, width, height ); + + int midX = screenFrame.Width() / 2; + int midY = screenFrame.Height() / 2; + + drawX = screenFrame.xmin + midX - width/2; + drawY = screenFrame.ymin + midY - height/2; + graphics2D->Write( windowManager->GetPrefs()->GetDefaultFont(), + drawX, + drawY, + colour, + -1, + (const char*)buttonLabel ); } } Index: pawsbutton.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/paws/pawsbutton.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** pawsbutton.h 27 Jul 2003 17:37:49 -0000 1.5 --- pawsbutton.h 27 Jul 2003 18:56:31 -0000 1.6 *************** *** 47,50 **** --- 47,54 ---- virtual void SetNotify ( pawsWidget* widget ); + void SetColour( int newColour = -1 ); + + void SetText(const char* text); + protected: /// Track to see if the button is down. *************** *** 59,63 **** --- 63,73 ---- /// Check to see if this is a toggle button. bool toggle; + + csString buttonLabel; + int colour; + + csRef<iFont> font; + /// Widget to which event notifications are sent. If NULL, notifications go to parent pawsWidget* notify; |