widget.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 
00033 #ifndef KYRA_WIDGET_INCLUDED
00034 #define KYRA_WIDGET_INCLUDED
00035 
00036 #ifdef _MSC_VER
00037 #pragma warning( disable : 4530 )
00038 #pragma warning( disable : 4786 )
00039 #endif
00040 
00041 #include <string>
00042 #include "SDL.h"
00043 #include "../util/gllist.h"
00044 #include "../../grinliz/glpublisher.h"
00045 #include "../engine/engine.h"
00046 #include "../engine/color.h"
00047 
00048 
00051 struct KrWidgetEventActivated
00052 {
00053         int type;
00054 };
00055 
00058 struct KrWidgetEventDeactivated
00059 {
00060         int type;
00061 };
00062 
00069 struct KrWidgetEventCommand
00070 {
00071         int type;
00072         bool recognized;
00073         const char* command;
00074         const char* arg;
00075 };
00076 
00082 struct KrWidgetEventSelection
00083 {
00084         int type;
00085         int index;
00086         const char* text;
00087 };
00088 
00089 union KrWidgetEvent
00090 {
00091         enum
00092         {
00093                 NO_EVENT,
00094                 ACTIVATED,
00095                 DEACTIVATED,
00096                 COMMAND,
00097                 SELECTION,
00098         };
00099 
00100         int type;
00101         KrWidgetEventActivated          activated;              // ACTIVATED
00102         KrWidgetEventDeactivated        deactivated;    // DEACTIVATED
00103         KrWidgetEventCommand            command;                // COMMAND
00104         KrWidgetEventSelection          selection;              // SELECTION
00105 };
00106 
00107 
00122 class IKrWidgetListener : public grinliz::Listener< IKrWidgetListener >
00123 {
00124   public:
00125 
00126 
00127         virtual bool HandleWidgetEvent( KrWidget* source, const KrWidgetEvent& event ) = 0;
00128 };
00129 
00130 
00141 struct KrScheme
00142 {
00143         KrScheme( KrFontResource* font );
00144 
00145         KrRGBA CalcBrightLine() const;
00146         KrRGBA CalcShadowLine() const;
00147 
00148         KrColorTransform CalcHiPrimary() const;
00149         KrColorTransform CalcHiSec() const;
00150         KrColorTransform CalcDark() const;
00151         KrColorTransform CalcDarkSec() const;
00152 
00153         KrRGBA                          primary;
00154         KrRGBA                          cursor;
00155         KrColorTransform        secondary;
00156         KrFontResource*         font;
00157         
00158         enum
00159         {
00160                 BRIGHT = 60,
00161                 DARK   = 60
00162         };
00163 };
00164 
00165 
00166 struct KrBevelElement
00167 {
00168   public:
00169         KrBevelElement( int w, int h, const KrScheme& );
00170         ~KrBevelElement();
00171 
00172         void AddToTree( KrEngine*, KrImNode* parent );
00173         void DrawIn();
00174         void DrawOut();
00175 
00176         int width;
00177         int height;
00178         KrBoxResource *vertDR, *vertLR, *horDR, *horLR;
00179         KrBox *vertD, *vertL, *horD, *horL;
00180 };
00181 
00182 
00231 class KrWidget : public KrImNode, public IKrWidgetListener
00232 {
00233   public:
00234         virtual ~KrWidget();
00235         virtual KrWidget* ToWidget()    { return this; }
00236 
00239         grinliz::Publisher< IKrWidgetListener > widgetPublish;
00240 
00241         enum {
00242                 LEFT_MOUSE   = 1,
00243                 RIGHT_MOUSE  = 2,       // not currently supported
00244                 MIDDLE_MOUSE = 4,       // not currently supported
00245 
00246                 LEFT_UP   = 0,
00247                 LEFT_DOWN = 1,
00248                 RIGHT_UP   = 2,         // not currently supported
00249                 RIGHT_DOWN = 3,         // not currently supported
00250                 MIDDLE_UP  = 4,         // not currently supported
00251                 MIDDLE_DOWN = 5         // not currently supported
00252         };
00253 
00254         virtual const char* WidgetType() { return "Widget"; }
00255 
00285         virtual int  IsMouseListener()                                          { return 0; }
00286         virtual void MouseIn( bool down, bool in )                      {}                                      
00287         virtual void MouseMove( bool down, int x, int y )       {}                                      
00288         virtual bool MouseClick( int click, int x, int y )      { return false; }       
00289 
00290         virtual bool IsKeyListener()                                            { return false; }
00291         virtual void KeyFocus( bool focus )                                     {}
00292         virtual bool KeyEvent( const SDL_Event& key )           { return false; }
00293 
00294         virtual bool IsSelectable()                                                     { return false; }
00295         virtual void Selected( bool selected )                          {}
00296 
00297 //      virtual bool IsGroup()                                                          { return false; }
00298 
00299         virtual void Accelerate( bool down )                            {}
00300         void SetAccelerator( int keymod, int keysym );
00301 
00303         virtual bool HandleWidgetEvent( KrWidget* source, const KrWidgetEvent& event )  { return false; }
00304 
00306         KrWidget* ParentWidget();
00307 
00308   protected:
00309         KrWidget( const KrScheme& scheme );
00310 
00311         int groupId;
00312         KrScheme scheme;
00313 };
00314 
00315 #endif

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