src/widget/widget_base.cpp
author KUDr
Tue, 27 Feb 2007 22:47:59 +0000
branchcpp_gui
changeset 6264 9fc3b5467396
parent 6263 19dab6a68886
child 6269 3b3bd4fe0736
permissions -rw-r--r--
(svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
-Add: new gui events (C++)
-Add: dynamic event handlers introduced (see Widget::AddReflectHandlerT)
-Add: test window using the new features (intro_gui.cpp)
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
     1
/* $Id$ */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
     2
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
     3
#include "../stdafx.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
     4
#include <stdarg.h>
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
     5
#include "../openttd.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
     6
#include "../debug.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
     7
#include "../functions.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
     8
#include "../map.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
     9
#include "../player.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    10
#include "../window.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    11
#include "../gfx.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    12
#include "../viewport.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    13
#include "../console.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    14
#include "../variables.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    15
#include "../table/sprites.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    16
#include "../genworld.h"
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    17
#include "../helpers.hpp"
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    18
#include "window_events.hpp"
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    19
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    20
namespace gui {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    21
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    22
int16 Widget::Left() const
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    23
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    24
	return m_rect.Left();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    25
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    26
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    27
int16 Widget::Top() const
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    28
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    29
	return m_rect.Top();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    30
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    31
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    32
int16 Widget::Right() const
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    33
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    34
	return m_rect.Right();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    35
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    36
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    37
int16 Widget::Bottom() const
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    38
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    39
	return m_rect.Bottom();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    40
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    41
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    42
int16 Widget::Width() const
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    43
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    44
	return m_rect.Width();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    45
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    46
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    47
int16 Widget::Height() const
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    48
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    49
	return m_rect.Height();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    50
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    51
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    52
const Point16& Widget::TopLeft() const
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    53
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    54
	return m_rect.TopLeft();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    55
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    56
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    57
const Point16& Widget::BottomRight() const
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    58
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    59
	return m_rect.BottomRight();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    60
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    61
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
    62
Point16 Widget::Size() const
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
    63
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
    64
	return m_rect.Size();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
    65
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
    66
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    67
Point16 Widget::CenterPt() const
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    68
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    69
	return m_rect.CenterPt();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    70
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    71
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    72
const Rect16& Widget::GetRect() const
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    73
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    74
	return m_rect;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    75
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    76
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    77
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    78
void Widget::SetLeft(int16 val)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    79
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    80
	m_rect.SetLeft(val);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    81
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    82
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    83
void Widget::SetTop(int16 val)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    84
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    85
	m_rect.SetTop(val);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    86
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    87
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    88
void Widget::SetRight(int16 val)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    89
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    90
	m_rect.SetRight(val);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    91
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    92
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    93
void Widget::SetBottom(int16 val)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    94
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    95
	m_rect.SetBottom(val);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    96
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    97
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    98
void Widget::SetWidth(int16 val)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
    99
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   100
	m_rect.SetWidth(val);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   101
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   102
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   103
void Widget::SetHeight(int16 val)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   104
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   105
	m_rect.SetHeight(val);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   106
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   107
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   108
void Widget::SetTopLeft(const Point16 &pt)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   109
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   110
	m_rect.SetTopLeft(pt);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   111
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   112
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   113
void Widget::SetBottomRight(const Point16 &pt)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   114
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   115
	m_rect.SetBottomRight(pt);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   116
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   117
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   118
void Widget::SetSize(const Point16 &pt)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   119
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   120
	m_rect.SetSize(pt);
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   121
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6258
diff changeset
   122
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   123
void Widget::SetRect(const Rect16 &rect)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   124
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   125
	m_rect = rect;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   126
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   127
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   128
WidgetId Widget::GetId() const
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   129
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   130
	return m_id;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   131
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   132
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   133
void Widget::AddHandler(EventHandlerDelegate *d)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   134
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   135
	m_handlers.push_back(Handler(d));
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   136
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   137
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   138
void Widget::CallHandlers(EventBase &e)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   139
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   140
	BaseWindow *w = GetWindow();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   141
	if (w == NULL) return;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   142
	for (Handlers::iterator it = m_handlers.begin(); it != m_handlers.end(); ++it) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   143
		EventHandlerDelegate *d = (*it).m_delegate;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   144
		if (d->m_code != e.GetCode()) continue;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   145
		d->HandleEvent(w, e);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   146
	}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   147
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   148
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   149
/*static*/ void Widget::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: 6263
diff changeset
   150
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   151
	uint dark         = _colour_gradient[ctab][3];
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   152
	uint medium_dark  = _colour_gradient[ctab][5];
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   153
	uint medium_light = _colour_gradient[ctab][6];
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   154
	uint light        = _colour_gradient[ctab][7];
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   155
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   156
	if (flags & FR_TRANSPARENT) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   157
		GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE));
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   158
	} else {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   159
		uint interior;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   160
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   161
		if (flags & FR_LOWERED) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   162
			GfxFillRect(left,     top,     left,  bottom,     dark);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   163
			GfxFillRect(left + 1, top,     right, top,        dark);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   164
			GfxFillRect(right,    top + 1, right, bottom - 1, light);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   165
			GfxFillRect(left + 1, bottom,  right, bottom,     light);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   166
			interior = (flags & FR_DARKENED ? medium_dark : medium_light);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   167
		} else {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   168
			GfxFillRect(left,     top,    left,      bottom - 1, light);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   169
			GfxFillRect(left + 1, top,    right - 1, top,        light);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   170
			GfxFillRect(right,    top,    right,     bottom - 1, dark);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   171
			GfxFillRect(left,     bottom, right,     bottom,     dark);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   172
			interior = medium_dark;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   173
		}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   174
		if (!(flags & FR_BORDERONLY)) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   175
			GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, interior);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   176
		}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   177
	}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   178
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   179
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   180
void Widget::DrawFrameRect(int ctab, FrameFlags flags)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   181
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   182
	DrawFrameRect(Left(), Top(), Right(), Bottom(), ctab, flags);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   183
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   184
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   185
/*virtual*/ BaseWindow* Widget::GetWindow()
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   186
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   187
	if (m_container != NULL) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   188
		return m_container->GetWindow();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   189
	}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   190
	return NULL;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   191
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   192
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   193
/*virtual*/ Widget* Widget::WidgetFromPt(const Point16 &pt)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   194
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   195
	if (m_rect.PtInRect(pt)) return this;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   196
	return NULL;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   197
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   198
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   199
/*virtual*/ void Widget::Close()
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   200
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   201
	m_is_closing = true;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   202
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff changeset
   203
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   204
/*virtual*/ void Widget::OnLeftClick(EvtClick &ev)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   205
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   206
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   207
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   208
/*virtual*/ void Widget::OnRightClick(EvtRightClick &ev)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   209
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   210
	if (m_tooltips != 0) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   211
		GuiShowTooltips(m_tooltips);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   212
		ev.SetHandled();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   213
		return;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   214
	}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   215
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   216
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   217
/*virtual*/ void Widget::DrawBackground(EvtPaint &ev)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   218
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   219
	DrawFrameRect(m_color, FR_NONE);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   220
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   221
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   222
/*virtual*/ void Widget::DispatchEvent(EventBase &ev)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   223
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   224
	if (ev.m_widget.IsNull()) ev.m_widget = this;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   225
	ev.Dispatch();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   226
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   227
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   228
}; // namespace gui