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