button.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2005
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under the LGPL. 
00008         
00009         I kindly request you display a splash screen (provided in the HTML documentation)
00010         to promote Kyra and acknowledge the software and everyone who has contributed to it, 
00011         but it is not required by the license.
00012 
00013 --- LGPL License --
00014 
00015     This library is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU Lesser General Public
00017     License as published by the Free Software Foundation; either
00018     version 2.1 of the License, or (at your option) any later version.
00019 
00020     This library is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023     Lesser General Public License for more details.
00024 
00025     You should have received a copy of the GNU Lesser General Public
00026     License along with this library; if not, write to the Free Software
00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 
00029         The full text of the license can be found in lgpl.txt
00030 */
00031 
00032 #ifndef KYRA_BUTTONWIDGET_INCLUDED
00033 #define KYRA_BUTTONWIDGET_INCLUDED
00034 
00035 #ifdef _MSC_VER
00036 // Disable the no-exception handling warning.
00037 #pragma warning( disable : 4530 )
00038 #pragma warning( disable : 4786 )
00039 #endif
00040 
00041 #include "../gui/widget.h"
00042 
00046 class KrButton : public KrWidget
00047 {
00048   public:
00049         virtual ~KrButton();
00050 
00052         void SetTextChar( const std::string& text );
00053 
00065         void SetIcon( KrSprite* giveSprite );
00066 
00067         // Used to initialize the widget.
00068         virtual void AddedtoTree();
00069 
00070   protected:
00071         KrButton(       int width, 
00072                                 int height,
00073                                 const KrScheme& scheme );
00074         KrButton(       KrSprite* graphic,
00075                                 const KrScheme& scheme );
00076 
00077 
00078         enum
00079         {
00080                 OVER = 0x01,
00081                 DOWN = 0x02,
00082 
00083                 ICON_DEPTH = 1,
00084                 TEXT_DEPTH = 2,
00085         };
00086         void SetMode( int mode );       // bitflags of OVER & DOWN
00087 
00088         virtual void ModeChange(KrColorTransform& color);
00089         void PlaceText();
00090         void PlaceIcon();
00091 
00092         int width, height, mode;
00093         KrSprite          *icon;
00094                 
00095   private:
00096         KrImNode          *holder;
00097         KrBoxResource *plateRes;
00098         KrBox             *plate;
00099         KrBevelElement bevel;
00100         bool                    userDrawn;
00101         int                        iconX, iconY;
00102 
00103         KrTextBox*                textBox;
00104         std::string               text;
00105 };
00106 
00107 
00125 class KrPushButton : public KrButton
00126 {
00127   public:
00129         KrPushButton(   int width, 
00130                                         int height,
00131                                         const KrScheme& scheme ) : KrButton( width, height, scheme )    {}
00132 
00137         KrPushButton(   KrSprite* graphic,
00138                                         const KrScheme& scheme ) : KrButton( graphic, scheme ) {}
00139 
00140         virtual ~KrPushButton() {}
00141 
00142         virtual const char* WidgetType() { return "PushButton"; }
00143 
00144         virtual int  IsMouseListener()                                          { return LEFT_MOUSE; }
00145 
00146         virtual void MouseIn( bool down, bool in );
00147         virtual void MouseMove( bool down, int x, int y );
00148         virtual bool MouseClick( int down, int x, int y );
00149 
00150         // Not a key listener.
00151         // Not groupable or selectable.
00152 
00153         virtual bool CanAccelerate()                                            { return true; }
00154         virtual void Accelerate( bool down );
00155 };
00156 
00157 
00175 class KrToggleButton : public KrButton
00176 {
00177   public:
00179         KrToggleButton( int width, 
00180                                         int height,
00181                                         const KrScheme& scheme ) : KrButton( width, height, scheme )    {}
00182 
00187         KrToggleButton( KrSprite* graphic,
00188                                         const KrScheme& scheme ) : KrButton( graphic, scheme ) {}
00189 
00190         ~KrToggleButton()       {}
00191 
00192         virtual const char* WidgetType() { return "ToggleButton"; }
00193 
00194         virtual int IsMouseListener()                                           { return LEFT_MOUSE; }
00195         virtual void MouseIn( bool down, bool in );
00196         virtual void MouseMove( bool down, int x, int y );
00197         virtual bool MouseClick( int down, int x, int y );
00198 
00199         // Not a key listener.
00200 
00201         virtual bool IsSelectable()                                                     { return true; }
00202         virtual void Selected( bool selected );
00203 //      virtual void IsGroup()                                                          { return true; }
00204         virtual void Accelerate( bool down );
00205 };
00206 
00207 
00208 #endif
00209 

Generated on Thu Jul 20 20:45:31 2006 for Kyra by  doxygen 1.4.7