Disable warnings around all wx includes.
[dcpomatic.git] / src / wx / content_colour_conversion_dialog.cc
1 /*
2     Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "check_box.h"
23 #include "colour_conversion_editor.h"
24 #include "content_colour_conversion_dialog.h"
25 #include "wx_util.h"
26 #include "lib/colour_conversion.h"
27 #include "lib/config.h"
28 #include "lib/util.h"
29 #include "lib/warnings.h"
30 DCPOMATIC_DISABLE_WARNINGS
31 #include <wx/statline.h>
32 DCPOMATIC_ENABLE_WARNINGS
33 #include <iostream>
34
35
36 using std::cout;
37 using std::string;
38 using std::vector;
39 using boost::optional;
40
41
42 ContentColourConversionDialog::ContentColourConversionDialog (wxWindow* parent, bool yuv)
43         : wxDialog (parent, wxID_ANY, _("Colour conversion"))
44         , _editor (new ColourConversionEditor(this, yuv))
45         , _setting (false)
46 {
47         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
48         SetSizer (overall_sizer);
49
50         auto table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_Y_GAP - 2, DCPOMATIC_SIZER_X_GAP);
51         _preset_check = new CheckBox (this, _("Use preset"));
52         table->Add (_preset_check, 0, wxALIGN_CENTER_VERTICAL);
53         _preset_choice = new wxChoice (this, wxID_ANY);
54         table->Add (_preset_choice);
55
56         overall_sizer->Add (table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
57         overall_sizer->Add (new wxStaticLine (this, wxID_ANY), 0, wxEXPAND);
58         overall_sizer->Add (_editor);
59
60         auto buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
61         if (buttons) {
62                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
63         }
64
65         overall_sizer->Layout ();
66         overall_sizer->SetSizeHints (this);
67
68         _preset_check->Bind (wxEVT_CHECKBOX, boost::bind (&ContentColourConversionDialog::preset_check_clicked, this));
69         _preset_choice->Bind (wxEVT_CHOICE, boost::bind (&ContentColourConversionDialog::preset_choice_changed, this));
70
71         _editor_connection = _editor->Changed.connect (boost::bind (&ContentColourConversionDialog::check_for_preset, this));
72
73         for (auto const& i: PresetColourConversion::all ()) {
74                 _preset_choice->Append (std_to_wx (i.name));
75         }
76 }
77
78
79 ColourConversion
80 ContentColourConversionDialog::get () const
81 {
82         return _editor->get ();
83 }
84
85
86 void
87 ContentColourConversionDialog::set (ColourConversion c)
88 {
89         _setting = true;
90         _editor->set (c);
91         _setting = false;
92
93         check_for_preset ();
94 }
95
96
97 void
98 ContentColourConversionDialog::check_for_preset ()
99 {
100         if (_setting) {
101                 return;
102         }
103
104         auto preset = _editor->get().preset ();
105
106         _preset_check->SetValue (static_cast<bool>(preset));
107         _preset_choice->Enable (static_cast<bool>(preset));
108         if (preset) {
109                 _preset_choice->SetSelection (preset.get ());
110         } else {
111                 _preset_choice->SetSelection (-1);
112         }
113 }
114
115
116 void
117 ContentColourConversionDialog::preset_check_clicked ()
118 {
119         if (_preset_check->GetValue ()) {
120                 _preset_choice->SetSelection (0);
121                 preset_choice_changed ();
122         } else {
123                 _preset_choice->SetSelection (-1);
124                 _preset_choice->Enable (false);
125         }
126 }
127
128
129 void
130 ContentColourConversionDialog::preset_choice_changed ()
131 {
132         auto presets = PresetColourConversion::all ();
133         int const s = _preset_choice->GetCurrentSelection();
134         if (s != -1) {
135                 set (presets[s].conversion);
136         }
137 }