00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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;
00102 KrWidgetEventDeactivated deactivated;
00103 KrWidgetEventCommand command;
00104 KrWidgetEventSelection 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,
00244 MIDDLE_MOUSE = 4,
00245
00246 LEFT_UP = 0,
00247 LEFT_DOWN = 1,
00248 RIGHT_UP = 2,
00249 RIGHT_DOWN = 3,
00250 MIDDLE_UP = 4,
00251 MIDDLE_DOWN = 5
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
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