OSDN Git Service

e546e0a09fe05b7b11ac27b24b0c3f8dc6661992
[marathon/Aorta.git] / DDSOptionsDialog.cpp
1 /*
2
3   DDSOptionsDialog.cpp: part of the Aleph One Replacement Texture Utility
4   Copyright (C) 2006  Gregory Smith
5
6   This program is free software; you can redistribute it and/or
7   modify it under the terms of the GNU General Public License
8   as published by the Free Software Foundation; either version 2
9   of the License, or (at your option) any later version.
10
11   This program 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 this program; if not, write to the Free Software
18   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19  
20 */
21
22 #include "DDSOptionsDialog.h"
23
24 DDSOptionsDialog::DDSOptionsDialog(const wxString& prefix, bool HasAlpha)
25         : wxDialog(NULL, -1, wxT("DDS Options"), wxDefaultPosition, wxDefaultSize), m_prefix(prefix), m_hasAlpha(HasAlpha)
26 {
27
28         mipmapBox_staticbox = new wxStaticBox(this, -1, wxT("Mipmap Halo Removal"));
29         useDXTC = new wxCheckBox(this, -1, wxT("Use DXTC (Texture Compression)"));
30         generateMipmaps = new wxCheckBox(this, BUTTON_GenerateMipmaps, wxT("Generate Mipmaps"));
31         wxArrayString filterChoices;
32         filterChoices.Add(wxT("Box"));
33         filterChoices.Add(wxT("Triangle"));
34         filterChoices.Add(wxT("Kaiser"));
35         mipmapFilterChoice = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize, filterChoices);
36
37         repeatingTexture = new wxCheckBox(this, -1, wxT("Image Repeats"));
38
39         colorFillBackground = new wxCheckBox(this, BUTTON_ColorFillBackground, wxT("Fast Halo Removal"));
40         reconstructColors = new wxCheckBox(this, BUTTON_ReconstructColors, wxT("Reconstruct Edge Colors"));
41         chooseBackground = new wxButton(this, BUTTON_ChooseBackground, wxT("Choose Background Color..."));
42
43         fill_from_prefs();
44         update_enablement();
45         do_layout();
46 }
47
48 void DDSOptionsDialog::fill_from_prefs()
49 {
50         wxConfig config;
51         config.SetPath(m_prefix);
52
53         bool value;
54         config.Read(wxT("UseDXTC"), &value, true);
55         useDXTC->SetValue(value ? 1 : 0);
56         
57         config.Read(wxT("GenerateMipmaps"), &value, true);
58         generateMipmaps->SetValue(value ? 1 : 0);
59
60         long filter;
61         config.Read(wxT("MipmapFilter"), &filter, 1);
62         mipmapFilterChoice->SetSelection(filter);
63
64         config.Read(wxT("WrapMode"), &filter, 1);
65         repeatingTexture->SetValue((filter == 1) ? 1 : 0);
66
67         wxString haloRemovalStrategy;
68         config.Read(wxT("FastHaloRemoval"), &value, true);
69         colorFillBackground->SetValue(value ? 1 : 0);
70
71         config.Read(wxT("ReconstructEdgeColors"), &value, true);
72         reconstructColors->SetValue(value ? 1 : 0);
73
74         long r, g, b;
75         config.Read(wxT("BackgroundColor/R"), &r, 0xff);
76         config.Read(wxT("BackgroundColor/G"), &g, 0xff);
77         config.Read(wxT("BackgroundColor/B"), &b, 0xff);
78         backgroundColor.Set((unsigned char) r, (unsigned char) g, (unsigned char) b);
79 }
80
81 void DDSOptionsDialog::update_enablement()
82 {
83         repeatingTexture->Enable(generateMipmaps->GetValue());
84         mipmapFilterChoice->Enable(generateMipmaps->GetValue());
85         colorFillBackground->Enable(generateMipmaps->GetValue() && m_hasAlpha);
86         reconstructColors->Enable(generateMipmaps->GetValue() && m_hasAlpha && colorFillBackground->GetValue());
87         chooseBackground->Enable(generateMipmaps->GetValue() && m_hasAlpha && colorFillBackground->GetValue() && reconstructColors->GetValue());
88 }
89
90 bool DDSOptionsDialog::Validate()
91 {
92         wxConfig config;
93         config.SetPath(m_prefix);
94         config.Write(wxT("UseDXTC"), useDXTC->GetValue());
95         config.Write(wxT("GenerateMipmaps"), generateMipmaps->GetValue());
96         if (generateMipmaps->GetValue())
97         {
98                 config.Write(wxT("MipmapFilter"), mipmapFilterChoice->GetSelection());
99                 config.Write(wxT("WrapMode"), repeatingTexture->GetValue() ? 1 : 0);
100                 if (colorFillBackground->GetValue())
101                 {
102                         config.Write(wxT("FastHaloRemoval"), true);
103                         config.Write(wxT("ReconstructEdgeColors"), reconstructColors->GetValue() == 1);
104                         
105                         config.Write(wxT("BackgroundColor/R"), (long) backgroundColor.Red());
106                         config.Write(wxT("BackgroundColor/G"), (long) backgroundColor.Green());
107                         config.Write(wxT("BackgroundColor/B"), (long) backgroundColor.Blue());
108                 }
109                 else
110                 {
111                         config.Write(wxT("FastHaloRemoval"), false);
112                 }
113         }
114
115         return TRUE;
116 }
117
118 void DDSOptionsDialog::do_layout()
119 {
120         // begin wxGlade: MyFrame::do_layout
121         wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
122         wxBoxSizer* mipmapIndenter = new wxBoxSizer(wxHORIZONTAL);
123         wxBoxSizer* mipmapSizer = new wxBoxSizer(wxVERTICAL);
124         wxBoxSizer* mipmapFilterSizer = new wxBoxSizer(wxHORIZONTAL);
125         wxStaticBoxSizer* mipmapBox = new wxStaticBoxSizer(mipmapBox_staticbox, wxVERTICAL);
126         wxBoxSizer* colorFillIndenter = new wxBoxSizer(wxHORIZONTAL);
127         wxBoxSizer* colorFillBox = new wxBoxSizer(wxVERTICAL);
128         wxBoxSizer* chooseBackgroundIndenter = new wxBoxSizer(wxHORIZONTAL);
129         mipmapFilterSizer->Add(new wxStaticText(this, -1, wxT("Filter:")), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 10);
130         mipmapFilterSizer->Add(mipmapFilterChoice, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND);
131         topSizer->Add(useDXTC, 0, wxALL |wxADJUST_MINSIZE, 10);
132         topSizer->Add(generateMipmaps, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxADJUST_MINSIZE, 10);
133         mipmapSizer->Add(repeatingTexture, 0, wxRIGHT|wxLEFT|wxBOTTOM | wxADJUST_MINSIZE|wxEXPAND, 10);
134         mipmapSizer->Add(mipmapFilterSizer, 0, wxRIGHT|wxLEFT|wxBOTTOM| wxADJUST_MINSIZE | wxEXPAND, 10);
135         mipmapIndenter->Add(20, 20, 0, wxADJUST_MINSIZE, 1);
136         mipmapBox->Add(colorFillBackground, 0, wxALL|wxADJUST_MINSIZE, 10);
137         colorFillIndenter->Add(20, 20, 0, wxADJUST_MINSIZE, 0);
138         colorFillBox->Add(reconstructColors, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxADJUST_MINSIZE, 10);
139         chooseBackgroundIndenter->Add(20, 20, 0, wxADJUST_MINSIZE, 0);
140         chooseBackgroundIndenter->Add(chooseBackground, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxADJUST_MINSIZE, 10);
141         colorFillBox->Add(chooseBackgroundIndenter, 1, wxEXPAND, 0);
142         colorFillIndenter->Add(colorFillBox, 1, wxEXPAND, 0);
143         mipmapBox->Add(colorFillIndenter, 1, wxEXPAND, 0);
144         mipmapSizer->Add(mipmapBox, 1, wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, 10);
145         mipmapIndenter->Add(mipmapSizer, 1, wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, 10);
146         topSizer->Add(mipmapIndenter, 1, wxEXPAND, 0);
147         wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
148         wxButton *cancelButton = new wxButton(this, wxID_CANCEL);
149         buttonSizer->Add(cancelButton, 1, wxLEFT|wxRIGHT, 10);
150         wxButton *okButton = new wxButton(this, wxID_OK);
151         buttonSizer->Add(okButton, 1, wxLEFT|wxRIGHT, 10);
152         topSizer->Add(buttonSizer, 0, wxEXPAND|wxBOTTOM, 10);
153         SetAutoLayout(true);
154         SetSizer(topSizer);
155         topSizer->Fit(this);
156         topSizer->SetSizeHints(this);
157         Layout();
158 }
159
160 void DDSOptionsDialog::OnChooseBackground(wxCommandEvent &)
161 {
162         wxColourData data;
163         data.SetColour(backgroundColor);
164         wxColourDialog dialog(this, &data);
165         if (dialog.ShowModal() == wxID_OK)
166         {
167                 wxColourData redData = dialog.GetColourData();
168                 backgroundColor = redData.GetColour();
169         }
170 }
171
172 void DDSOptionsDialog::OnUpdateEnablement(wxCommandEvent &)
173 {
174         update_enablement();
175 }
176
177 BEGIN_EVENT_TABLE(DDSOptionsDialog, wxDialog)
178 EVT_BUTTON(BUTTON_ChooseBackground, DDSOptionsDialog::OnChooseBackground)
179 EVT_CHECKBOX(BUTTON_ColorFillBackground, DDSOptionsDialog::OnUpdateEnablement)
180 EVT_CHECKBOX(BUTTON_ReconstructColors, DDSOptionsDialog::OnUpdateEnablement)
181 EVT_CHECKBOX(BUTTON_GenerateMipmaps, DDSOptionsDialog::OnUpdateEnablement)
182
183 END_EVENT_TABLE()
184
185