2007-05-30 21:56:52 +00:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers , whose names
* are too numerous to list here . Please refer to the COPYRIGHT
* file distributed with this source distribution .
2002-07-05 16:56:53 +00:00
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
2005-10-18 01:30:26 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2002-07-05 16:56:53 +00:00
*
2006-02-11 10:08:56 +00:00
* $ URL $
* $ Id $
2002-07-05 16:56:53 +00:00
*/
2003-11-02 14:50:53 +00:00
# ifndef GUI_WIDGET_H
# define GUI_WIDGET_H
2002-07-05 16:56:53 +00:00
2003-08-01 12:21:04 +00:00
# include "common/scummsys.h"
2002-09-08 01:08:12 +00:00
# include "common/str.h"
2007-06-30 12:26:59 +00:00
# include "common/keyboard.h"
2005-05-08 22:38:29 +00:00
# include "graphics/surface.h"
2003-11-02 14:50:53 +00:00
# include "gui/object.h"
2007-11-04 03:38:30 +00:00
# include "gui/theme.h"
2002-07-05 16:56:53 +00:00
2003-11-10 23:40:48 +00:00
namespace GUI {
2002-07-05 16:56:53 +00:00
class Dialog ;
enum {
WIDGET_ENABLED = 1 < < 0 ,
WIDGET_INVISIBLE = 1 < < 1 ,
2002-07-06 12:57:51 +00:00
WIDGET_HILITED = 1 < < 2 ,
WIDGET_BORDER = 1 < < 3 ,
2007-11-04 03:38:30 +00:00
//WIDGET_INV_BORDER = 1 << 4,
2002-10-19 01:22:41 +00:00
WIDGET_CLEARBG = 1 < < 5 ,
WIDGET_WANT_TICKLE = 1 < < 7 ,
WIDGET_TRACK_MOUSE = 1 < < 8 ,
WIDGET_RETAIN_FOCUS = 1 < < 9 // Retain focus on mouse up. By default widgets lose focus on mouseup, but some widgets might want to retain it - widgets where you enter text, for instance
2002-07-05 16:56:53 +00:00
} ;
2002-07-08 11:55:55 +00:00
enum {
kStaticTextWidget = ' TEXT ' ,
2002-11-21 15:20:52 +00:00
kEditTextWidget = ' EDIT ' ,
2002-07-08 11:55:55 +00:00
kButtonWidget = ' BTTN ' ,
kCheckboxWidget = ' CHKB ' ,
2002-07-10 22:49:41 +00:00
kSliderWidget = ' SLDE ' ,
2002-07-12 16:24:11 +00:00
kListWidget = ' LIST ' ,
2003-11-02 17:41:01 +00:00
kScrollBarWidget = ' SCRB ' ,
2003-11-03 01:00:26 +00:00
kPopUpWidget = ' POPU ' ,
2005-05-08 22:38:29 +00:00
kTabWidget = ' TABW ' ,
2006-05-27 05:46:04 +00:00
kGraphicsWidget = ' GFXW ' ,
kContainerWidget = ' CTNR '
2002-07-12 16:24:11 +00:00
} ;
2002-11-21 15:20:52 +00:00
enum {
kCaretBlinkTime = 300
} ;
2005-05-11 19:30:30 +00:00
enum WidgetSize {
kDefaultWidgetSize ,
kNormalWidgetSize ,
kBigWidgetSize
} ;
2002-10-12 00:26:24 +00:00
enum {
2003-04-12 17:19:28 +00:00
kButtonWidth = 72 ,
2005-05-11 19:30:30 +00:00
kButtonHeight = 16 ,
2005-05-18 15:58:39 +00:00
kSliderWidth = 85 ,
kSliderHeight = 12 ,
2005-05-11 19:30:30 +00:00
kBigButtonWidth = 108 ,
2005-05-18 15:58:39 +00:00
kBigButtonHeight = 24 ,
kBigSliderWidth = 128 ,
kBigSliderHeight = 18
2002-10-12 00:26:24 +00:00
} ;
2002-07-05 16:56:53 +00:00
/* Widget */
2003-11-02 14:50:53 +00:00
class Widget : public GuiObject {
2003-11-02 02:18:16 +00:00
friend class Dialog ;
2002-07-05 16:56:53 +00:00
protected :
2002-07-13 22:41:29 +00:00
uint32 _type ;
2003-11-02 14:50:53 +00:00
GuiObject * _boss ;
2002-07-05 16:56:53 +00:00
Widget * _next ;
uint16 _id ;
2006-01-27 15:43:23 +00:00
uint16 _hints ;
2002-07-16 10:52:48 +00:00
bool _hasFocus ;
2007-11-04 03:38:30 +00:00
Theme : : WidgetStateInfo _state ;
private :
uint16 _flags ;
2002-07-13 22:41:29 +00:00
2003-11-02 18:57:20 +00:00
public :
static Widget * findWidgetInChain ( Widget * start , int x , int y ) ;
2006-04-19 01:05:28 +00:00
static Widget * findWidgetInChain ( Widget * start , const char * name ) ;
2003-11-02 18:57:20 +00:00
2002-07-05 16:56:53 +00:00
public :
2003-11-02 14:50:53 +00:00
Widget ( GuiObject * boss , int x , int y , int w , int h ) ;
2006-06-03 13:33:39 +00:00
Widget ( GuiObject * boss , const Common : : String & name ) ;
2003-11-07 14:50:32 +00:00
virtual ~ Widget ( ) ;
2002-07-05 16:56:53 +00:00
2006-03-07 05:39:52 +00:00
void init ( ) ;
2006-04-19 01:05:28 +00:00
void resize ( int x , int y , int w , int h ) ;
void setNext ( Widget * w ) { _next = w ; }
Widget * next ( ) { return _next ; }
2006-03-07 05:39:52 +00:00
2003-11-02 22:31:20 +00:00
virtual int16 getAbsX ( ) const { return _x + _boss - > getChildX ( ) ; }
virtual int16 getAbsY ( ) const { return _y + _boss - > getChildY ( ) ; }
2005-07-30 21:11:48 +00:00
2006-05-18 16:44:44 +00:00
virtual void setPos ( int x , int y ) { _x = x ; _y = y ; }
virtual void setSize ( int w , int h ) { _w = w ; _h = h ; }
2003-11-02 17:41:01 +00:00
2002-07-27 14:16:14 +00:00
virtual void handleMouseDown ( int x , int y , int button , int clickCount ) { }
virtual void handleMouseUp ( int x , int y , int button , int clickCount ) { }
2002-07-10 22:49:41 +00:00
virtual void handleMouseEntered ( int button ) { }
virtual void handleMouseLeft ( int button ) { }
2002-07-08 13:52:50 +00:00
virtual void handleMouseMoved ( int x , int y , int button ) { }
2002-10-16 20:32:12 +00:00
virtual void handleMouseWheel ( int x , int y , int direction ) { }
2007-06-30 12:26:59 +00:00
virtual bool handleKeyDown ( Common : : KeyState state ) { return false ; } // Return true if the event was handled
virtual bool handleKeyUp ( Common : : KeyState state ) { return false ; } // Return true if the event was handled
2002-07-13 22:41:29 +00:00
virtual void handleTickle ( ) { }
2003-11-02 22:31:20 +00:00
2006-08-04 13:55:53 +00:00
virtual void reflowLayout ( ) { GuiObject : : reflowLayout ( ) ; }
2006-04-19 01:05:28 +00:00
2002-07-05 16:56:53 +00:00
void draw ( ) ;
2002-07-16 22:34:16 +00:00
void receivedFocus ( ) { _hasFocus = true ; receivedFocusWidget ( ) ; }
2002-07-16 10:52:48 +00:00
void lostFocus ( ) { _hasFocus = false ; lostFocusWidget ( ) ; }
2005-04-06 15:21:32 +00:00
virtual bool wantsFocus ( ) { return false ; }
2002-07-05 16:56:53 +00:00
2007-11-04 03:38:30 +00:00
void setFlags ( int flags ) ;
void clearFlags ( int flags ) ;
2002-07-05 16:56:53 +00:00
int getFlags ( ) const { return _flags ; }
2003-03-06 19:52:54 +00:00
2006-01-27 15:43:23 +00:00
void setHints ( int hints ) { _hints | = hints ; }
void clearHints ( int hints ) { _hints & = ~ hints ; }
int getHints ( ) const { return _hints ; }
2002-10-01 23:11:19 +00:00
void setEnabled ( bool e ) { if ( e ) setFlags ( WIDGET_ENABLED ) ; else clearFlags ( WIDGET_ENABLED ) ; }
2007-10-28 12:02:09 +00:00
bool isEnabled ( ) const ;
2006-03-07 13:41:36 +00:00
bool isVisible ( ) const ;
2002-07-05 16:56:53 +00:00
protected :
2007-11-04 03:38:30 +00:00
void updateState ( int oldFlags , int newFlags ) ;
virtual void drawWidget ( ) = 0 ;
2002-07-16 10:52:48 +00:00
2002-07-16 22:34:16 +00:00
virtual void receivedFocusWidget ( ) { }
2002-07-16 10:52:48 +00:00
virtual void lostFocusWidget ( ) { }
2003-11-08 23:22:16 +00:00
2003-11-02 02:18:16 +00:00
virtual Widget * findWidget ( int x , int y ) { return this ; }
2003-11-02 14:50:53 +00:00
2003-11-03 00:17:12 +00:00
void releaseFocus ( ) { assert ( _boss ) ; _boss - > releaseFocus ( ) ; }
// By default, delegate unhandled commands to the boss
void handleCommand ( CommandSender * sender , uint32 cmd , uint32 data ) { assert ( _boss ) ; _boss - > handleCommand ( sender , cmd , data ) ; }
2002-07-05 16:56:53 +00:00
} ;
/* StaticTextWidget */
class StaticTextWidget : public Widget {
protected :
2004-03-21 21:20:25 +00:00
typedef Graphics : : TextAlignment TextAlignment ;
2002-08-31 13:42:07 +00:00
2007-02-03 21:32:18 +00:00
Common : : String _label ;
2005-05-11 19:30:30 +00:00
TextAlignment _align ;
2002-07-05 16:56:53 +00:00
public :
2007-02-03 21:32:18 +00:00
StaticTextWidget ( GuiObject * boss , int x , int y , int w , int h , const Common : : String & text , TextAlignment align ) ;
StaticTextWidget ( GuiObject * boss , const Common : : String & name , const Common : : String & text ) ;
2002-07-27 00:05:46 +00:00
void setValue ( int value ) ;
2007-02-03 21:32:18 +00:00
void setLabel ( const Common : : String & label ) ;
const Common : : String & getLabel ( ) const { return _label ; }
2005-04-16 17:53:18 +00:00
void setAlign ( TextAlignment align ) ;
2004-03-13 13:03:25 +00:00
TextAlignment getAlign ( ) const { return _align ; }
2002-07-05 16:56:53 +00:00
protected :
2007-11-04 03:38:30 +00:00
void drawWidget ( ) ;
2002-07-05 16:56:53 +00:00
} ;
/* ButtonWidget */
2002-07-12 16:24:11 +00:00
class ButtonWidget : public StaticTextWidget , public CommandSender {
friend class Dialog ; // Needed for the hotkey handling
2002-07-05 16:56:53 +00:00
protected :
2002-10-19 01:22:41 +00:00
uint32 _cmd ;
uint8 _hotkey ;
2002-07-05 16:56:53 +00:00
public :
2007-02-03 21:32:18 +00:00
ButtonWidget ( GuiObject * boss , int x , int y , int w , int h , const Common : : String & label , uint32 cmd = 0 , uint8 hotkey = 0 ) ;
ButtonWidget ( GuiObject * boss , const Common : : String & name , const Common : : String & label , uint32 cmd = 0 , uint8 hotkey = 0 ) ;
2002-07-12 16:24:11 +00:00
2003-07-22 16:26:12 +00:00
void setCmd ( uint32 cmd ) { _cmd = cmd ; }
uint32 getCmd ( ) const { return _cmd ; }
2002-07-06 12:57:51 +00:00
2002-07-27 14:16:14 +00:00
void handleMouseUp ( int x , int y , int button , int clickCount ) ;
2002-07-07 21:46:53 +00:00
void handleMouseEntered ( int button ) { setFlags ( WIDGET_HILITED ) ; draw ( ) ; }
void handleMouseLeft ( int button ) { clearFlags ( WIDGET_HILITED ) ; draw ( ) ; }
2002-10-12 00:26:24 +00:00
protected :
2007-11-04 03:38:30 +00:00
void drawWidget ( ) ;
2002-07-05 16:56:53 +00:00
} ;
2002-10-19 01:22:41 +00:00
/* CheckboxWidget */
2003-11-03 23:33:40 +00:00
class CheckboxWidget : public ButtonWidget {
2002-10-19 01:22:41 +00:00
protected :
2003-11-03 23:33:40 +00:00
bool _state ;
2002-10-19 01:22:41 +00:00
public :
2007-02-03 21:32:18 +00:00
CheckboxWidget ( GuiObject * boss , int x , int y , int w , int h , const Common : : String & label , uint32 cmd = 0 , uint8 hotkey = 0 ) ;
CheckboxWidget ( GuiObject * boss , const Common : : String & name , const Common : : String & label , uint32 cmd = 0 , uint8 hotkey = 0 ) ;
2002-07-07 23:37:47 +00:00
2002-10-19 01:22:41 +00:00
void handleMouseUp ( int x , int y , int button , int clickCount ) ;
2006-02-01 15:11:39 +00:00
virtual void handleMouseEntered ( int button ) { setFlags ( WIDGET_HILITED ) ; draw ( ) ; }
virtual void handleMouseLeft ( int button ) { clearFlags ( WIDGET_HILITED ) ; draw ( ) ; }
2002-07-07 23:37:47 +00:00
2003-11-03 23:33:40 +00:00
void setState ( bool state ) ;
void toggleState ( ) { setState ( ! _state ) ; }
bool getState ( ) const { return _state ; }
2002-07-07 23:37:47 +00:00
protected :
2007-11-04 03:38:30 +00:00
void drawWidget ( ) ;
2002-07-07 23:37:47 +00:00
} ;
2002-07-08 13:52:50 +00:00
/* SliderWidget */
2005-05-18 10:24:02 +00:00
class SliderWidget : public Widget , public CommandSender {
2002-07-08 13:52:50 +00:00
protected :
2005-05-18 10:24:02 +00:00
uint32 _cmd ;
2002-07-26 23:29:43 +00:00
int _value , _oldValue ;
2002-07-26 15:34:04 +00:00
int _valueMin , _valueMax ;
2002-07-13 18:32:09 +00:00
bool _isDragging ;
2003-11-03 01:00:26 +00:00
uint _labelWidth ;
2002-07-08 13:52:50 +00:00
public :
2005-05-18 10:24:02 +00:00
SliderWidget ( GuiObject * boss , int x , int y , int w , int h , uint32 cmd = 0 ) ;
2006-06-03 13:33:39 +00:00
SliderWidget ( GuiObject * boss , const Common : : String & name , uint32 cmd = 0 ) ;
2005-05-18 10:24:02 +00:00
void setCmd ( uint32 cmd ) { _cmd = cmd ; }
uint32 getCmd ( ) const { return _cmd ; }
2002-07-28 14:59:27 +00:00
void setValue ( int value ) { _value = value ; }
int getValue ( ) const { return _value ; }
2002-07-08 22:11:47 +00:00
2002-07-26 15:34:04 +00:00
void setMinValue ( int value ) { _valueMin = value ; }
2002-07-26 00:41:07 +00:00
int getMinValue ( ) const { return _valueMin ; }
2002-07-26 15:34:04 +00:00
void setMaxValue ( int value ) { _valueMax = value ; }
2002-07-26 00:41:07 +00:00
int getMaxValue ( ) const { return _valueMax ; }
2002-07-08 13:52:50 +00:00
void handleMouseMoved ( int x , int y , int button ) ;
2002-07-27 14:16:14 +00:00
void handleMouseDown ( int x , int y , int button , int clickCount ) ;
void handleMouseUp ( int x , int y , int button , int clickCount ) ;
2005-05-18 10:24:02 +00:00
void handleMouseEntered ( int button ) { setFlags ( WIDGET_HILITED ) ; draw ( ) ; }
void handleMouseLeft ( int button ) { clearFlags ( WIDGET_HILITED ) ; draw ( ) ; }
2002-07-08 13:52:50 +00:00
protected :
2007-11-04 03:38:30 +00:00
void drawWidget ( ) ;
2003-03-06 19:52:54 +00:00
2002-07-26 23:29:43 +00:00
int valueToPos ( int value ) ;
int posToValue ( int pos ) ;
2002-07-08 13:52:50 +00:00
} ;
2005-05-08 22:38:29 +00:00
/* GraphicsWidget */
class GraphicsWidget : public Widget {
public :
GraphicsWidget ( GuiObject * boss , int x , int y , int w , int h ) ;
2006-06-03 13:33:39 +00:00
GraphicsWidget ( GuiObject * boss , const Common : : String & name ) ;
2005-05-08 22:38:29 +00:00
~ GraphicsWidget ( ) ;
2005-07-30 21:11:48 +00:00
2005-05-08 22:38:29 +00:00
void setGfx ( const Graphics : : Surface * gfx ) ;
2006-05-29 14:38:56 +00:00
void setGfx ( int w , int h , int r , int g , int b ) ;
2006-03-14 02:19:38 +00:00
2006-05-29 14:00:00 +00:00
void useAlpha ( int alpha ) { _alpha = alpha ; }
2006-05-29 14:55:43 +00:00
void useThemeTransparency ( bool enable ) { _transparency = enable ; }
2006-03-14 02:19:38 +00:00
2005-05-08 22:38:29 +00:00
protected :
2007-11-04 03:38:30 +00:00
void drawWidget ( ) ;
2005-07-30 21:11:48 +00:00
2005-05-08 22:38:29 +00:00
Graphics : : Surface _gfx ;
2006-05-29 14:00:00 +00:00
int _alpha ;
2006-05-29 14:55:43 +00:00
bool _transparency ;
2005-05-08 22:38:29 +00:00
} ;
2006-05-27 05:46:04 +00:00
/* ContainerWidget */
class ContainerWidget : public Widget {
public :
ContainerWidget ( GuiObject * boss , int x , int y , int w , int h ) ;
2006-06-03 13:33:39 +00:00
ContainerWidget ( GuiObject * boss , const Common : : String & name ) ;
2006-05-27 05:46:04 +00:00
protected :
2007-11-04 03:38:30 +00:00
void drawWidget ( ) ;
2006-05-27 05:46:04 +00:00
} ;
2003-11-10 23:40:48 +00:00
} // End of namespace GUI
2002-07-08 13:52:50 +00:00
2002-07-05 16:56:53 +00:00
# endif