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
00034 #ifndef PG_BUTTON_H
00035 #define PG_BUTTON_H
00036
00037 #include "pgwidget.h"
00038 #include "pgsignals.h"
00039 #include "pgdraw.h"
00040 #include <string>
00041
00042
00043 class PG_ButtonDataInternal;
00044
00045
00125 class DECLSPEC PG_Button : public PG_Widget {
00126 public:
00127
00131 enum {
00132 OK = 0x80000001,
00133 YES = 0x80000002,
00134 NO = 0x80000003,
00135 APPLY = 0x80000004,
00136 CANCEL = 0x80000005,
00137 CLOSE = 0x80000006,
00138 HELP = 0x80000007
00139 };
00140
00144 typedef enum {
00145 PRESSED,
00146 UNPRESSED,
00147 HIGHLITED
00148 } STATE;
00149
00154 typedef enum {
00155 MSGCAPTURE = 0x00000001,
00156 SIGNALONCLICK = 0x00000002,
00157 SIGNALONRELEASE = 0x00000004
00158 } BEHAVIOUR;
00159
00160
00164 template<class datatype = PG_Pointer>
00165 class SignalButtonClick : public PG_Signal1<PG_Button*, datatype> {}
00166 ;
00167
00176 PG_Button(PG_Widget* parent, const PG_Rect& r = PG_Rect::null, const std::string& text = PG_NULLSTR, int id = -1, const std::string& style="Button");
00177
00179 virtual ~PG_Button();
00180
00182 void LoadThemeStyle(const std::string& widgettype);
00183
00185 void LoadThemeStyle(const std::string& widgettype, const std::string& objectname);
00186
00194 void SetGradient(STATE state, const PG_Gradient& gradient);
00195
00204 void SetBackground(STATE state, SDL_Surface* background, PG_Draw::BkMode mode = PG_Draw::TILE);
00205
00211 void SetBorderColor(int b, const PG_Color& color);
00212
00220 bool SetIcon(const std::string& filenameup=PG_NULLSTR, const std::string& filenamedown=PG_NULLSTR, const std::string& filenameover = PG_NULLSTR);
00221
00230 bool SetIcon(const std::string& filenameup, const std::string& filenamedown, const std::string& filenameover, const PG_Color& colorkey);
00231
00242 bool SetIcon(SDL_Surface* icon_up, SDL_Surface* icon_down = NULL, SDL_Surface* icon_over = NULL, bool freeSurfaces = false );
00243
00249 SDL_Surface* GetIcon(STATE num);
00250
00255 void SetIconIndent(Uint16 indent);
00256
00266 void SetBorderSize(int norm, int pressed, int high);
00267
00275 void SetToggle(bool bToggle);
00276
00281 void SetPressed(bool pressed);
00282
00288 void SetTransparency(Uint8 t, bool bRecursive = false);
00289
00296 void SetTransparency(Uint8 norm, Uint8 pressed, Uint8 high);
00297
00302 void SetShift(int pixelshift);
00303
00310 bool GetPressed();
00311
00321 void SetBlendLevel(STATE mode, Uint8 blend);
00322
00328 Uint8 GetBlendLevel(STATE mode);
00329
00336 void SetSizeByText(int Width = 0, int Height = 0, const std::string& Text = PG_NULLSTR);
00337
00342 void SetBehaviour( int behaviour );
00343
00344 void SetText(const std::string& text);
00345
00346
00347 SignalButtonClick<> sigClick;
00348
00349 static SignalButtonClick<> sigGlobalClick;
00350
00351 protected:
00352
00354 virtual void eventButtonSurface(SDL_Surface** surface, STATE newstate, Uint16 w, Uint16 h);
00355
00357 void eventBlit(SDL_Surface* surface, const PG_Rect& src, const PG_Rect& dst);
00358
00360 void eventSizeWidget(Uint16 w, Uint16 h);
00361
00363 void eventMouseLeave();
00364
00366 void eventMouseEnter();
00367
00369 bool eventMouseButtonUp(const SDL_MouseButtonEvent* button);
00370
00372 bool eventMouseButtonDown(const SDL_MouseButtonEvent* button);
00373
00375 bool eventKeyDown (const SDL_KeyboardEvent *key);
00376
00377 private:
00378
00379 PG_Button(const PG_Button&);
00380 PG_Button& operator=(const PG_Button&);
00381
00383 DLLLOCAL void FreeSurfaces();
00384
00386 DLLLOCAL void FreeIcons();
00387
00388 PG_ButtonDataInternal* _mid;
00389 };
00390
00391 #endif // PG_BUTTON_H