fixup! First hacks on OOBE help.
[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         boost::filesystem::path path = bitmap_directory() / "help" / String::compose("%1.png", m.id);
65         wxBitmap bitmap (std_to_wx(path.string()));
66         wxPoint pos;
67         if (m.anchor_point) {
68                 pos = *m.anchor_point;
69         } else if (m.anchor_landmark) {
70                 DCPOMATIC_ASSERT (_landmarks.find(*m.anchor_landmark) != _landmarks.end());
71                 wxWindow* lm = _landmarks[*m.anchor_landmark];
72                 pos = lm->GetScreenPosition();
73                 pos.x += lm->GetSize().GetWidth();
74         }
75         pos += m.offset;
76         _current_frame = new wxFrame (0, wxID_ANY, wxT(""), pos, wxSize(bitmap.GetSize().GetWidth() + 16, bitmap.GetSize().GetHeight() + 128), wxFRAME_TOOL_WINDOW);
77         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
78         wxStaticBitmap* static_bitmap = new wxStaticBitmap (_current_frame, wxID_ANY, bitmap);
79         sizer->Add (static_bitmap, 1, wxEXPAND);
80         wxSizer* buttons_sizer = new wxBoxSizer (wxHORIZONTAL);
81         wxButton* close = new wxButton (_current_frame, wxID_ANY, _("Stop showing tips"));
82         close->Bind (wxEVT_BUTTON, boost::bind(&HelpGUI::stop, this));
83         buttons_sizer->Add (close, 1, wxEXPAND | wxALL, 8);
84         sizer->Add (buttons_sizer, 0, wxALIGN_RIGHT);
85         _current_frame->SetSizer (sizer);
86         _current_frame->Show ();
87 }
88
89
90 void
91 HelpGUI::stop ()
92 {
93         _current_index = -1;
94         if (_current_frame) {
95                 _current_frame->Destroy ();
96         }
97
98         /* XXX: should write a config entry */
99 }
100
101
102 HelpGUI *
103 HelpGUI::instance ()
104 {
105         if (!_instance) {
106                 _instance = new HelpGUI ();
107         }
108
109         return _instance;
110 }
111
112