src/widget/widget.h
author KUDr
Sat, 10 Mar 2007 04:52:01 +0000
branchcpp_gui
changeset 6294 6c74bf9cc5a4
parent 6290 8078f7a3c8a0
child 6295 a88d8c2cff6e
permissions -rw-r--r--
(svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
-Codechange: order of some includes changed (solved min/max macro conflict with stl)
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
     1
/* $Id$ */
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
     2
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
     3
#ifndef WIDGET_H
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
     4
#define WIDGET_H
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
     5
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
     6
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
     7
#include <list>
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
     8
#include <map>
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
     9
#include "../macros.h"
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    10
#include "../string.h"
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    11
#include "../order.h"
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    12
#include "../rail.h"
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    13
#include "../airport.h"
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    14
#include "../misc/rect.hpp"
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    15
#include "../misc/countedptr.hpp"
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    16
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    17
#include "window_event_base.h"
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    18
6265
7054c910251d (svn r8932) [cpp_gui] -Fix(r8931): forward enum declaration doesn't work for g++
KUDr
parents: 6264
diff changeset
    19
enum FrameFlags {
7054c910251d (svn r8932) [cpp_gui] -Fix(r8931): forward enum declaration doesn't work for g++
KUDr
parents: 6264
diff changeset
    20
	FR_NONE         = 0x00,
7054c910251d (svn r8932) [cpp_gui] -Fix(r8931): forward enum declaration doesn't work for g++
KUDr
parents: 6264
diff changeset
    21
	FR_TRANSPARENT  = 0x01,  ///< Makes the background transparent if set
7054c910251d (svn r8932) [cpp_gui] -Fix(r8931): forward enum declaration doesn't work for g++
KUDr
parents: 6264
diff changeset
    22
	FR_BORDERONLY   = 0x10,  ///< Draw border only, no background
7054c910251d (svn r8932) [cpp_gui] -Fix(r8931): forward enum declaration doesn't work for g++
KUDr
parents: 6264
diff changeset
    23
	FR_LOWERED      = 0x20,  ///< If set the frame is lowered and the background color brighter (ie. buttons when pressed)
7054c910251d (svn r8932) [cpp_gui] -Fix(r8931): forward enum declaration doesn't work for g++
KUDr
parents: 6264
diff changeset
    24
	FR_DARKENED     = 0x40,  ///< If set the background is darker, allows for lowered frames with normal background color when used with FR_LOWERED (ie. dropdown boxes)
6286
6e8eec87fa9d (svn r9006) [cpp_gui] -Add: Label widget (MiHaMiX)
KUDr
parents: 6283
diff changeset
    25
	FR_BG_ONLY      = 0x80,  ///< If set only the background is drawn without any frame (labels and such)
6265
7054c910251d (svn r8932) [cpp_gui] -Fix(r8931): forward enum declaration doesn't work for g++
KUDr
parents: 6264
diff changeset
    26
};
7054c910251d (svn r8932) [cpp_gui] -Fix(r8931): forward enum declaration doesn't work for g++
KUDr
parents: 6264
diff changeset
    27
7054c910251d (svn r8932) [cpp_gui] -Fix(r8931): forward enum declaration doesn't work for g++
KUDr
parents: 6264
diff changeset
    28
DECLARE_ENUM_AS_BIT_SET(FrameFlags);
7054c910251d (svn r8932) [cpp_gui] -Fix(r8931): forward enum declaration doesn't work for g++
KUDr
parents: 6264
diff changeset
    29
6278
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    30
enum Anchors {
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    31
	PIN_NONE     = 0x00,
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    32
	PIN_LEFT     = 0x01,
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    33
	PIN_TOP      = 0x02,
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    34
	PIN_RIGHT    = 0x04,
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    35
	PIN_BOTTOM   = 0x08,
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    36
};
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    37
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    38
DECLARE_ENUM_AS_BIT_SET(Anchors);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    39
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    40
namespace gui {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    41
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    42
enum FeatureFlags {
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    43
	FF_NONE                = 0,
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    44
	FF_NO_CAPTION_BAR      = (1 <<  0),
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    45
	FF_NO_CLOSE_BOX        = (1 <<  1),
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    46
	FF_NO_STICKY_BOX       = (1 <<  2),
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    47
	FF_NO_RESIZE_BOX       = (1 <<  3),
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    48
	FF_UNMOVABLE           = (1 <<  4),
6286
6e8eec87fa9d (svn r9006) [cpp_gui] -Add: Label widget (MiHaMiX)
KUDr
parents: 6283
diff changeset
    49
	FF_TRANSPARENT         = (1 <<  5),
6289
be3d8bd9fb02 (svn r9010) [cpp_gui] -Add: Sticky button widget
KUDr
parents: 6287
diff changeset
    50
	FF_TOGGLE_BUTTON       = (1 <<  6),
be3d8bd9fb02 (svn r9010) [cpp_gui] -Add: Sticky button widget
KUDr
parents: 6287
diff changeset
    51
	FF_STICKED             = (1 <<  7),
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    52
};
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    53
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    54
DECLARE_ENUM_AS_BIT_SET(FeatureFlags);
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    55
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    56
struct Widget;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    57
typedef CCountedPtr<Widget> WidgetPtr;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    58
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    59
struct CompositeWidget;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    60
typedef CCountedPtr<CompositeWidget> CompositeWidgetPtr;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    61
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    62
typedef int32 WidgetId;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    63
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    64
struct Widget : public SimpleCountedObject {
6269
3b3bd4fe0736 (svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents: 6265
diff changeset
    65
	typedef AdaptT<EventHandlerDelegatePtr> Handler;
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    66
	typedef std::list<Handler> Handlers;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    67
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    68
	CompositeWidget *m_container;       ///< widget container (can be any panel or window)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    69
	WidgetId        m_id;               ///< Widget id in its container
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    70
	Rect16          m_rect;             ///< The position offsets relative to the container
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    71
	uint16          m_data;             ///< The String/Image or special code (list-matrices) of a widget
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    72
	FeatureFlags    m_feature_flags;    ///< @see FeatureFlags
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    73
	byte            m_color;            ///< Widget color, see docs/ottd-colourtext-palette.png
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    74
	bool            m_is_closing : 1;   ///< Widget was logically destroyed
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    75
	bool            m_dont_clip : 1;    ///< should not be clipped by parent (container)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    76
	StringID        m_tooltips;         ///< Tooltips that are shown when right clicking on a widget
6278
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    77
	Anchors         m_anchors;          ///< Resize/move when container resizes?
6294
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6290
diff changeset
    78
	Point16         m_min_size;         ///< Minimum size
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6290
diff changeset
    79
	Point16         m_max_size;         ///< Maximum size
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6290
diff changeset
    80
	Point16         m_size_step;        ///< When resizing, what step is the best
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    81
	Handlers        m_handlers;         ///< dynamically registered event handlers
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    82
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    83
	Widget()
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    84
		: m_container(NULL), m_id(0), m_rect(), m_data(0), m_feature_flags(FF_NONE), m_color(0)
6278
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    85
		, m_is_closing(false), m_tooltips(0), m_anchors(PIN_NONE)
6294
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6290
diff changeset
    86
		, m_max_size(Point16::max()), m_size_step(1, 1)
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    87
	{}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    88
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    89
	Widget(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, byte color, const Rect16 &rect, StringID tooltips)
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    90
		: m_container(container)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    91
		, m_id(id)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    92
		, m_rect(rect)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    93
		, m_data(0)
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
    94
		, m_feature_flags(feature_flags)
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    95
		, m_color(color)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    96
		, m_is_closing(false)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    97
		, m_dont_clip(false)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
    98
		, m_tooltips(tooltips)
6278
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
    99
		, m_anchors(PIN_NONE)
6294
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6290
diff changeset
   100
		, m_max_size(Point16::max())
6c74bf9cc5a4 (svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
KUDr
parents: 6290
diff changeset
   101
		, m_size_step(1, 1)
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   102
	{}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   103
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   104
	int16 Left() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   105
	int16 Top() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   106
	int16 Right() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   107
	int16 Bottom() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   108
	int16 Width() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   109
	int16 Height() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   110
	const Point16& TopLeft() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   111
	const Point16& BottomRight() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   112
	Point16 Size() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   113
	Point16 CenterPt() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   114
	const Rect16& GetRect() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   115
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   116
	void SetLeft(int16 val);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   117
	void SetTop(int16 val);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   118
	void SetRight(int16 val);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   119
	void SetBottom(int16 val);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   120
	void SetWidth(int16 val);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   121
	void SetHeight(int16 val);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   122
	void SetTopLeft(const Point16 &pt);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   123
	void SetBottomRight(const Point16 &pt);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   124
	void SetSize(const Point16 &pt);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   125
	void SetRect(const Rect16 &rect);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   126
6286
6e8eec87fa9d (svn r9006) [cpp_gui] -Add: Label widget (MiHaMiX)
KUDr
parents: 6283
diff changeset
   127
	byte GetColor() const;
6e8eec87fa9d (svn r9006) [cpp_gui] -Add: Label widget (MiHaMiX)
KUDr
parents: 6283
diff changeset
   128
	void SetColor(byte val);
6e8eec87fa9d (svn r9006) [cpp_gui] -Add: Label widget (MiHaMiX)
KUDr
parents: 6283
diff changeset
   129
6278
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
   130
	void SetAnchors(Anchors a);
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
   131
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   132
	WidgetId GetId() const;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   133
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   134
	void AddHandler(EventHandlerDelegate *d);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   135
	void CallHandlers(EventBase &e);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   136
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   137
	void Invalidate() {}; ///< now we redraw gui all the time, so no processing is needed here
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   138
	static /*static*/ void FillRect(const Rect16 &rc, int color);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   139
	static void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlags flags);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   140
	void DrawFrameRect(int ctab, FrameFlags flags);
6290
8078f7a3c8a0 (svn r9023) [cpp_gui] -Add: ImageButton and ImageButton2
KUDr
parents: 6289
diff changeset
   141
	void DrawSprite(SpriteID img, SpriteID pal, const Point16 &local_pos);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   142
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   143
	virtual BaseWindow* GetWindow();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   144
	virtual Widget* WidgetFromPt(const Point16 &pt);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   145
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   146
	virtual void Close();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   147
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   148
	virtual void DrawBackground(EvtPaint &ev);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   149
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   150
	/**
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   151
	 * OnCreate() handler called when window gets created. Override this method in your
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   152
	 * Window subclass and place widgets into your window from there.
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   153
	 */
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   154
	virtual void OnCreate(EvtCreate &ev) {};
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   155
	virtual void OnDestroy(EvtDestroy &ev) {};
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   156
	virtual void OnPaint(EvtPaint &ev) = 0;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   157
	virtual void OnKeyPress(EvtKeyPress &ev) {};
6282
c5b92f2d924f (svn r8996) [cpp_gui] -Add: CloseBox added into CaptionBar
KUDr
parents: 6279
diff changeset
   158
	virtual void OnLeftButtonDown(EvtLeftButtonDown &ev) {};
c5b92f2d924f (svn r8996) [cpp_gui] -Add: CloseBox added into CaptionBar
KUDr
parents: 6279
diff changeset
   159
	virtual void OnLeftClick(EvtLeftClick &ev);
c5b92f2d924f (svn r8996) [cpp_gui] -Add: CloseBox added into CaptionBar
KUDr
parents: 6279
diff changeset
   160
	virtual void OnRightButtonDown(EvtRightButtonDown &ev);
6271
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6269
diff changeset
   161
	virtual void OnMouseOver(EvtMouseOver &ev) {};
6278
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
   162
	virtual void OnResize(EvtResize &ev) {};
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
   163
	virtual void OnResizeParent(EvtResizeParent &ev);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   164
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   165
	/**
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   166
	 * Dispatch event by its type calling appropriate OnCreate(), OnDestroy(), etc.
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   167
	 */
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   168
	virtual void DispatchEvent(EventBase &ev);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   169
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   170
	/**
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   171
	 * @function AddReflectHandlerT Registers reflected event handler. Use it from
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   172
	 * BaseWindow subclasses (Window implementations) to register custom event handler.
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   173
	 * For example if you are implementing 'MyWindow' class and want to handle OnLeftClick()
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   174
	 * event for your button 'MyButton', define your handler method inside 'MyWindow' class
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   175
	 * like:
6282
c5b92f2d924f (svn r8996) [cpp_gui] -Add: CloseBox added into CaptionBar
KUDr
parents: 6279
diff changeset
   176
	 *       void MyWindow::MyButtonClickHandler(gui::EvtLeftClick &e)
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   177
	 *       {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   178
	 *          ...
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   179
	 *       }
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   180
	 * then from inside OnCreate() handler, create your button 'my_button' and
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   181
	 * call:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   182
	 *       my_button->AddReflectHandlerT(&MyWindow::MyButtonClickHandler);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   183
	 * and your MyButtonClickHandler will be called on every click on my_button.
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   184
	 */
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   185
	template <class Twnd_cls, EventCode Tevt_code> void AddReflectHandlerT(void (Twnd_cls::*handler)(gui::EventT<Tevt_code>&))
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   186
	{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   187
		typedef ReflectHandlerDelegateT<Twnd_cls, Tevt_code> Delegate;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   188
		AddHandler(new Delegate(handler));
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   189
	}
6271
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6269
diff changeset
   190
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6269
diff changeset
   191
	/** add capture handler using default delegate type (CaptureHandlerDelegateT<>) */
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6269
diff changeset
   192
	template <class Twd_cls, EventCode Tevt_code> CaptureTicket CaptureEventsT(Twd_cls *wd, void (Twd_cls::*handler)(EventT<Tevt_code>&))
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6269
diff changeset
   193
	{
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6269
diff changeset
   194
		CaptureTicket ticket = EventCaptureStack::AddHandler(new CaptureHandlerDelegateT<Twd_cls, Tevt_code>(wd, handler));
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6269
diff changeset
   195
		return ticket;
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6269
diff changeset
   196
	}
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6269
diff changeset
   197
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   198
};
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   199
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   200
struct CompositeWidget : public Widget {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   201
	typedef Widget super;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   202
	typedef std::map<WidgetId, WidgetPtr> Widgets;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   203
	typedef Widgets::iterator WidgetIterator;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   204
	typedef Widgets::reverse_iterator WidgetReverseIterator;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   205
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   206
protected:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   207
	Widgets m_widgets;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   208
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   209
public:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   210
	CompositeWidget()
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   211
		: Widget()
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   212
	{}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   213
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   214
	CompositeWidget(CompositeWidget *container, WidgetId id, FeatureFlags feature_flags, byte color, const Rect16 &rect, StringID tooltips)
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   215
		: Widget(container, id, feature_flags, color, rect, tooltips)
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   216
	{}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   217
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   218
	void AddWidget(Widget *wd);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   219
	Widget* GetWidget(WidgetId id);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   220
	Widget* RemoveWidget(WidgetId id);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   221
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   222
	/*virtual*/ Widget* WidgetFromPt(const Point16 &pt);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   223
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   224
	virtual void CreateNcWidgets() {};
6279
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6278
diff changeset
   225
	virtual void CreateWidgets() = 0;
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   226
	virtual void Close();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   227
6278
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
   228
	/*virtual*/ void OnCreate(EvtCreate &ev);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   229
	/*virtual*/ void OnPaint(EvtPaint &ev);
6282
c5b92f2d924f (svn r8996) [cpp_gui] -Add: CloseBox added into CaptionBar
KUDr
parents: 6279
diff changeset
   230
	/*virtual*/ void OnLeftButtonDown(EvtLeftButtonDown &ev);
c5b92f2d924f (svn r8996) [cpp_gui] -Add: CloseBox added into CaptionBar
KUDr
parents: 6279
diff changeset
   231
	/*virtual*/ void OnRightButtonDown(EvtRightButtonDown &ev);
6278
c09f5e53af9b (svn r8986) [cpp_gui] -Add: resizing window by dragging ResizeBox
KUDr
parents: 6277
diff changeset
   232
	/*virtual*/ void OnResize(EvtResize &ev);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   233
};
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   234
6273
d8a2c6844650 (svn r8981) [cpp_gui] -Add: simple CaptionBar Widget
KUDr
parents: 6271
diff changeset
   235
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   236
}; // namespace gui
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   237
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents:
diff changeset
   238
#endif /* WIDGET_H */