summaryrefslogtreecommitdiff
path: root/src/wx/colour_conversion_dialog.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/wx/colour_conversion_dialog.cc')
-rw-r--r--src/wx/colour_conversion_dialog.cc150
1 files changed, 150 insertions, 0 deletions
diff --git a/src/wx/colour_conversion_dialog.cc b/src/wx/colour_conversion_dialog.cc
new file mode 100644
index 000000000..976d295d5
--- /dev/null
+++ b/src/wx/colour_conversion_dialog.cc
@@ -0,0 +1,150 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/lexical_cast.hpp>
+#include <wx/spinctrl.h>
+#include <wx/gbsizer.h>
+#include "lib/colour_conversion.h"
+#include "wx_util.h"
+#include "colour_conversion_dialog.h"
+
+using std::string;
+using std::cout;
+using boost::shared_ptr;
+using boost::lexical_cast;
+
+ColourConversionDialog::ColourConversionDialog (wxWindow* parent, shared_ptr<ColourConversion> conversion)
+ : wxDialog (parent, wxID_ANY, _("Colour conversion"))
+ , _conversion (conversion)
+{
+ wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
+ SetSizer (overall_sizer);
+
+ wxGridBagSizer* table = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+ overall_sizer->Add (table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
+
+ int r = 0;
+
+ add_label_to_grid_bag_sizer (table, this, _("Name"), true, wxGBPosition (r, 0));
+ _name = new wxTextCtrl (this, wxID_ANY, wxT (""));
+ table->Add (_name, wxGBPosition (r, 1));
+ ++r;
+
+ add_label_to_grid_bag_sizer (table, this, _("Input gamma"), true, wxGBPosition (r, 0));
+ _input_gamma = new wxSpinCtrlDouble (this);
+ table->Add (_input_gamma, wxGBPosition (r, 1));
+ ++r;
+
+ _input_gamma_linearised = new wxCheckBox (this, wxID_ANY, _("Linearise input gamma curve for low values"));
+ table->Add (_input_gamma_linearised, wxGBPosition (r, 0), wxGBSpan (1, 2));
+ ++r;
+
+ wxClientDC dc (parent);
+ wxSize size = dc.GetTextExtent (wxT ("0.123456789012"));
+ size.SetHeight (-1);
+
+ wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
+ wxArrayString list;
+
+ wxString n (wxT ("0123456789.-"));
+ for (size_t i = 0; i < n.Length(); ++i) {
+ list.Add (n[i]);
+ }
+
+ validator.SetIncludes (list);
+
+ add_label_to_grid_bag_sizer (table, this, _("Matrix"), true, wxGBPosition (r, 0));
+ wxFlexGridSizer* matrix_sizer = new wxFlexGridSizer (3, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
+ for (int x = 0; x < 3; ++x) {
+ for (int y = 0; y < 3; ++y) {
+ _matrix[x][y] = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, size, 0, validator);
+ matrix_sizer->Add (_matrix[x][y]);
+ }
+ }
+ table->Add (matrix_sizer, wxGBPosition (r, 1));
+ ++r;
+
+ add_label_to_grid_bag_sizer (table, this, _("Output gamma"), true, wxGBPosition (r, 0));
+ wxBoxSizer* output_sizer = new wxBoxSizer (wxHORIZONTAL);
+ /* TRANSLATORS: this means the mathematical reciprocal operation, i.e. we are dividing 1 by the control that
+ comes after it.
+ */
+ add_label_to_sizer (output_sizer, this, _("1 / "), false);
+ _output_gamma = new wxSpinCtrlDouble (this);
+ output_sizer->Add (_output_gamma);
+ table->Add (output_sizer, wxGBPosition (r, 1));
+ ++r;
+
+ wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
+ if (buttons) {
+ overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
+ }
+
+ SetSizer (overall_sizer);
+ overall_sizer->Layout ();
+ overall_sizer->SetSizeHints (this);
+
+ _input_gamma->SetRange(0.1, 4.0);
+ _input_gamma->SetDigits (1);
+ _input_gamma->SetIncrement (0.1);
+ _output_gamma->SetRange(0.1, 4.0);
+ _output_gamma->SetDigits (1);
+ _output_gamma->SetIncrement (0.1);
+
+ _name->SetValue (std_to_wx (conversion->name));
+ _input_gamma->SetValue (conversion->input_gamma);
+ _input_gamma_linearised->SetValue (conversion->input_gamma_linearised);
+ for (int i = 0; i < 3; ++i) {
+ for (int j = 0; j < 3; ++j) {
+ _matrix[i][j]->SetValue (std_to_wx (lexical_cast<string> (conversion->matrix(i, j))));
+ }
+ }
+ _output_gamma->SetValue (conversion->output_gamma);
+
+ _name->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&ColourConversionDialog::changed, this));
+ _input_gamma->Bind (wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, boost::bind (&ColourConversionDialog::changed, this));
+ _input_gamma_linearised->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&ColourConversionDialog::changed, this));
+ _output_gamma->Bind (wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, boost::bind (&ColourConversionDialog::changed, this));
+ for (int i = 0; i < 3; ++i) {
+ for (int j = 0; j < 3; ++j) {
+ _matrix[i][j]->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&ColourConversionDialog::changed, this));
+ }
+ }
+}
+
+void
+ColourConversionDialog::changed ()
+{
+ _conversion->name = wx_to_std (_name->GetValue ());
+ _conversion->input_gamma = _input_gamma->GetValue ();
+ _conversion->input_gamma_linearised = _input_gamma_linearised->GetValue ();
+
+ for (int i = 0; i < 3; ++i) {
+ for (int j = 0; j < 3; ++j) {
+ string const v = wx_to_std (_matrix[i][j]->GetValue ());
+ if (v.empty ()) {
+ _conversion->matrix (i, j) = 0;
+ } else {
+ _conversion->matrix (i, j) = lexical_cast<float> (v);
+ }
+ }
+ }
+ _conversion->output_gamma = _output_gamma->GetValue ();
+}
+