1 // Crimson Fields -- a game of tactical warfare 2 // Copyright (C) 2000-2007 Jens Granseuer 3 // 4 // This program is free software; you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation; either version 2 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 // 18 19 /////////////////////////////////////////////////////////////// 20 // button.h - button widget class 21 /////////////////////////////////////////////////////////////// 22 23 #ifndef _INCLUDE_BUTTON_H 24 #define _INCLUDE_BUTTON_H 25 26 #include <string> 27 using namespace std; 28 29 #include "widget.h" 30 31 class ButtonWidget : public Widget { 32 public: 33 ButtonWidget( short id, short x, short y, unsigned short w, 34 unsigned short h, unsigned short flags, 35 const char *title, Window *window ); 36 37 virtual void Draw( void ); 38 39 void SetImage( Surface *image, const Rect &state1, const Rect &state2 ); 40 41 virtual GUI_Status MouseDown( const SDL_MouseButtonEvent &button ); 42 virtual GUI_Status MouseUp( const SDL_MouseButtonEvent &button ); 43 virtual GUI_Status KeyDown( const SDL_keysym &key ); 44 virtual GUI_Status KeyUp( const SDL_keysym &key ); 45 46 virtual void Push( void ); 47 GUI_Status Activate( void ); 48 49 protected: 50 Image image[2]; 51 }; 52 53 54 #define DEFAULT_CBW_SIZE 15 55 56 class CheckboxWidget : public ButtonWidget { 57 public: 58 CheckboxWidget( short id, short x, short y, unsigned short w, 59 unsigned short h, bool state, unsigned short flags, 60 const char *title, Window *window ); 61 62 GUI_Status MouseDown( const SDL_MouseButtonEvent &button ); MouseUp(const SDL_MouseButtonEvent & button)63 GUI_Status MouseUp( const SDL_MouseButtonEvent &button ) { return GUI_OK; } 64 GUI_Status KeyDown( const SDL_keysym &key ); KeyUp(const SDL_keysym & key)65 GUI_Status KeyUp( const SDL_keysym &key ) { return GUI_OK; } 66 }; 67 68 69 class MenuButtonWidget : public ButtonWidget { 70 public: 71 MenuButtonWidget( short id, short x, short y, unsigned short w, 72 unsigned short h, unsigned short flags, 73 const char *title, Window *window ); 74 75 virtual GUI_Status MouseMove( const SDL_MouseMotionEvent &move ); 76 IsMenu(void)77 bool IsMenu( void ) const { return (flags & WIDGET_STYLE_SUBMENU) != 0; } IsCurrent(void)78 bool IsCurrent( void ) const 79 { return (flags & (WIDGET_STYLE_HIGHLIGHT|WIDGET_DEFAULT)) == 80 (WIDGET_STYLE_HIGHLIGHT|WIDGET_DEFAULT); } ToggleCurrent(void)81 void ToggleCurrent( void ) 82 { flags ^= (WIDGET_STYLE_HIGHLIGHT|WIDGET_DEFAULT); } 83 }; 84 85 86 class CycleWidget : public ButtonWidget { 87 public: 88 CycleWidget( short id, short x, short y, unsigned short w, unsigned short h, 89 unsigned short flags, const char *title, unsigned short defval, 90 const char *labels[], Window *window ); ~CycleWidget(void)91 ~CycleWidget( void ) { delete [] choices; } 92 93 void SetValue( unsigned short value ); GetValue(void)94 unsigned short GetValue( void ) const { return val; } GetLabel(void)95 const char *GetLabel( void ) const { return choices[val].c_str(); } 96 97 GUI_Status MouseDown( const SDL_MouseButtonEvent &button ); 98 GUI_Status MouseUp( const SDL_MouseButtonEvent &button ); 99 GUI_Status KeyUp( const SDL_keysym &key ); 100 void Draw( void ); 101 102 private: 103 void CycleValue( void ); 104 105 unsigned short val; 106 unsigned short maxval; 107 bool up; 108 string *choices; 109 }; 110 111 112 class DropWidget : public ButtonWidget { 113 public: 114 DropWidget( short id, short x, short y, unsigned short w, 115 unsigned short h, unsigned short flags, 116 const char *title, Window *window ); 117 118 void Draw( void ); 119 }; 120 121 #endif /* _INCLUDE_BUTTON_H */ 122 123