1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#include "wx_help.h"
#include "wx_util.h"
#include <iostream>
HelpGUI* HelpGUI::_instance = 0;
HelpGUI::HelpGUI ()
: _current_index (-1)
, _current_frame (0)
{
_messages.push_back (Message("file_new", wxPoint(50, 100), Help::SUCCESSFUL_FILE_NEW));
_messages.push_back (Message("add_content", ADD_FOLDER_BUTTON, wxSize(24, -48), Help::SUCCESSFUL_ADD_CONTENT));
_messages.push_back (Message("preview", PLAY_BUTTON, wxSize(24, 0)));
Help::instance()->Event.connect (boost::bind(&HelpGUI::event, this, _1));
}
void
HelpGUI::event (Help::EventType e)
{
if (
_current_index >= 0 &&
_current_index < int(_messages.size() - 1) &&
_messages[_current_index].next_trigger &&
*_messages[_current_index].next_trigger == e) {
next ();
}
}
void
HelpGUI::landmark (wxWindow* landmark, Landmark id)
{
_landmarks[id] = landmark;
}
void
HelpGUI::next ()
{
++_current_index;
show (_current_index);
}
void
HelpGUI::start ()
{
next ();
}
void
HelpGUI::show (int index)
{
if (_current_frame) {
_current_frame->Destroy ();
_current_frame = 0;
}
Message const& m = _messages[index];
boost::filesystem::path path = bitmap_directory() / "help" / String::compose("%1.png", m.id);
wxBitmap bitmap (std_to_wx(path.string()));
wxPoint pos;
if (m.anchor_point) {
pos = *m.anchor_point;
} else if (m.anchor_landmark) {
DCPOMATIC_ASSERT (_landmarks.find(*m.anchor_landmark) != _landmarks.end());
wxWindow* lm = _landmarks[*m.anchor_landmark];
pos = lm->GetScreenPosition();
pos.x += lm->GetSize().GetWidth();
}
pos += m.offset;
_current_frame = new wxFrame (0, wxID_ANY, wxT(""), pos, wxSize(bitmap.GetSize().GetWidth() + 16, bitmap.GetSize().GetHeight() + 128), wxFRAME_TOOL_WINDOW);
wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
wxStaticBitmap* static_bitmap = new wxStaticBitmap (_current_frame, wxID_ANY, bitmap);
sizer->Add (static_bitmap, 1, wxEXPAND);
wxSizer* buttons_sizer = new wxBoxSizer (wxHORIZONTAL);
wxButton* close = new wxButton (_current_frame, wxID_ANY, _("Stop showing tips"));
close->Bind (wxEVT_BUTTON, boost::bind(&HelpGUI::stop, this));
buttons_sizer->Add (close, 1, wxEXPAND | wxALL, 8);
sizer->Add (buttons_sizer, 0, wxALIGN_RIGHT);
_current_frame->SetSizer (sizer);
_current_frame->Show ();
}
void
HelpGUI::stop ()
{
_current_index = -1;
if (_current_frame) {
_current_frame->Destroy ();
}
/* XXX: should write a config entry */
}
HelpGUI *
HelpGUI::instance ()
{
if (!_instance) {
_instance = new HelpGUI ();
}
return _instance;
}
|