Main Page   Class Hierarchy   Compound List   File List   Compound Members  

widget.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2002
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under 2 licenses:
00008 
00009         - The GPL, with no additional restrictions.
00010         - The LGPL, provided you display the Kyra splash screen, described below.
00011 
00012 
00013 --- GPL License --
00014         This program is free software; you can redistribute it and/or
00015         modify it under the terms of the GNU General Public License
00016         as published by the Free Software Foundation; either version 2
00017         of the License, or (at your option) any later version.
00018 
00019         This program is distributed in the hope that it will be useful,
00020         but WITHOUT ANY WARRANTY; without even the implied warranty of
00021         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022         GNU General Public License for more details.
00023 
00024         You should have received a copy of the GNU General Public License
00025         along with this program; if not, write to the Free Software
00026         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028         The full text of the license can be found in license.txt
00029 
00030 
00031 --- LGPL License --
00032   **Provided you kindly display the Kyra splash screen (details below), 
00033         you     may use the LGPL license:**
00034 
00035     This library is free software; you can redistribute it and/or
00036     modify it under the terms of the GNU Lesser General Public
00037     License as published by the Free Software Foundation; either
00038     version 2.1 of the License, or (at your option) any later version.
00039 
00040     This library is distributed in the hope that it will be useful,
00041     but WITHOUT ANY WARRANTY; without even the implied warranty of
00042     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00043     Lesser General Public License for more details.
00044 
00045     You should have received a copy of the GNU Lesser General Public
00046     License along with this library; if not, write to the Free Software
00047     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00048 
00049         The full text of the license can be found in lgpl.txt
00050 
00051 
00052 --- Kyra Splash Screen.
00053 
00054         It would be appreciate if you display the Kyra splash screen when using
00055         either license, however it is only required for the LGPL. All the
00056         resources for the splash are compiled into the library, and it can be
00057         accessed through the following API:
00058 
00059                 KrEngine::StartSplash
00060                 KrEngine::UpdateSplash
00061                 KrEngine::EndSplash
00062 
00063         Full documentation is provided with the KrEngine class. The splash screen
00064         should be displayed for 2 seconds.
00065 
00066         Thank you.
00067 */
00068 
00069 
00070 #ifndef KYRA_WIDGET_INCLUDED
00071 #define KYRA_WIDGET_INCLUDED
00072 
00073 #pragma warning( disable : 4530 )
00074 #pragma warning( disable : 4786 )
00075 #include <string>
00076 #include "SDL.h"
00077 #include "../util/gllist.h"
00078 #include "../engine/engine.h"
00079 #include "../engine/color.h"
00080 
00081 
00096 class IKrWidgetListener
00097 {
00098   public:
00099         enum
00100         {
00101                 NONE,
00102                 ACTIVATED,
00103                 DEACTIVATED,
00104                 SELECTION,
00105         };
00106 
00107         virtual bool HandleWidgetEvent( KrWidget* source, 
00108                                                                         U32 event, 
00109                                                                         U32 data, 
00110                                                                         const SDL_Event* sdlEvent,
00111                                                                         const char* command, 
00112                                                                         const char* arg ) = 0;
00113 };
00114 
00115 
00126 struct KrScheme
00127 {
00128         KrScheme( KrFontResource* font );
00129 
00130         KrRGBA CalcBrightLine() const;
00131         KrRGBA CalcShadowLine() const;
00132 
00133         KrColorTransform CalcHiPrimary() const;
00134         KrColorTransform CalcHiSec() const;
00135         KrColorTransform CalcDark() const;
00136         KrColorTransform CalcDarkSec() const;
00137 
00138         KrRGBA                          primary;
00139         KrRGBA                          cursor;
00140         KrColorTransform        secondary;
00141         KrFontResource*         font;
00142         
00143         enum
00144         {
00145                 BRIGHT = 60,
00146                 DARK   = 60
00147         };
00148 };
00149 
00150 
00151 struct KrBevelElement
00152 {
00153   public:
00154         KrBevelElement( int w, int h, const KrScheme& );
00155         ~KrBevelElement();
00156 
00157         void AddToTree( KrEngine*, KrImNode* parent );
00158         void DrawIn();
00159         void DrawOut();
00160 
00161         int width;
00162         int height;
00163         KrBoxResource *vertDR, *vertLR, *horDR, *horLR;
00164         KrBox *vertD, *vertL, *horD, *horL;
00165 };
00166 
00167 
00216 class KrWidget : public KrImNode, 
00217                                  public IKrWidgetListener
00218 {
00219   public:
00220         virtual ~KrWidget();
00221         virtual KrWidget* ToWidget()    { return this; }
00222 
00227         void AddListener( IKrWidgetListener* );
00229         void RemoveListener( IKrWidgetListener* );
00230 
00231         enum {
00232                 LEFT_MOUSE   = 1,
00233                 RIGHT_MOUSE  = 2,       // not currently supported
00234                 MIDDLE_MOUSE = 4,       // not currently supported
00235 
00236                 LEFT_UP   = 0,
00237                 LEFT_DOWN = 1,
00238                 RIGHT_UP   = 2,         // not currently supported
00239                 RIGHT_DOWN = 3,         // not currently supported
00240                 MIDDLE_UP  = 4,         // not currently supported
00241                 MIDDLE_DOWN = 5         // not currently supported
00242         };
00243 
00273         virtual int  IsMouseListener()                                          { return 0; }
00274         virtual void MouseIn( bool down, bool in )                      {}                              
00275         virtual void MouseMove( bool down, int x, int y )       {}                              
00276         virtual void MouseClick( int click, int x, int y )      {}                              
00277 
00278         virtual bool IsKeyListener()                                            { return false; }
00279         virtual void KeyFocus( bool focus )                                     {}
00280         virtual bool KeyEvent( const SDL_Event& key )           { return false; }
00281 
00282         virtual bool IsSelectable()                                                     { return false; }
00283         virtual void Selected( bool selected )                          {}
00284 
00285         void SetGroup( int _groupId )                                           { groupId = _groupId; }
00286         int  Group()                                                                            { return groupId; }
00287 
00288         virtual void Accelerate( bool down )                            {}
00289         void SetAccelerator( int keymod, int keysym );
00290 
00292         virtual bool HandleWidgetEvent( KrWidget* source, 
00293                                                                         U32 event, U32 data, const SDL_Event* sdlEvent,
00294                                                                         const char* command, const char* arg )  
00295                                                                                                                 { return false; }
00296 
00298         KrWidget* ParentWidget();
00299 
00300   protected:
00301         // Send an event to all the listeners.
00302         void PublishEvent( U32 event, U32 data, const SDL_Event*, const char* command, const char* arg );
00303         // Send an event to all listeners, set data=1 for the specified listener.
00304         void PublishTaggedEvent( U32 event, const SDL_Event*, const char* com, const char* arg, IKrWidgetListener* special );
00305 
00306 
00307         KrWidget( const KrScheme& scheme );
00308 
00309         GlDynArray< IKrWidgetListener* >        eventList;
00310         int groupId;
00311         KrScheme scheme;
00312 };
00313 
00314 #endif

Generated on Mon Sep 15 12:01:11 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001