Ticket #943: AtlasUI-wxColourPickerCtrl-v2.patch
File AtlasUI-wxColourPickerCtrl-v2.patch, 7.4 KB (added by , 12 years ago) |
---|
-
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp
22 22 23 23 #include "GameInterface/Messages.h" 24 24 #include "ScenarioEditor/ScenarioEditor.h" 25 #include "General/Observable.h" 26 #include "CustomControls/ColourDialog/ColourDialog.h" 25 #include "wx/clrpicker.h" 27 26 28 27 using AtlasMessage::Shareable; 29 28 … … 144 143 145 144 m_Sizer = new wxStaticBoxSizer(wxVERTICAL, this, label); 146 145 SetSizer(m_Sizer); 147 148 m_Button = new wxButton(this, -1); 149 m_Sizer->Add(m_Button, wxSizerFlags().Expand()); 146 147 // wxCLRP_SHOW_LABEL shows the hex code on the button, but it doesn't look very good and is 148 // invisible on 50% grey (simply inverts rather than white/black). Showing the hex code isn't 149 // realy necessary anyway. 150 //m_ColourCtrl = new wxColourPickerCtrl(this, -1, *wxBLACK, wxDefaultPosition, wxDefaultSize, wxCLRP_SHOW_LABEL); 151 m_ColourCtrl = new wxColourPickerCtrl(this, -1); 152 m_Sizer->Add(m_ColourCtrl, wxSizerFlags().Expand()); 150 153 } 151 154 152 155 void OnSettingsChange(const AtlasMessage::sEnvironmentSettings& WXUNUSED(env)) 153 156 { 154 UpdateButton();157 m_ColourCtrl->SetColour(wxColour(m_Colour->r, m_Colour->g, m_Colour->b)); 155 158 } 156 157 void OnC lick(wxCommandEvent& WXUNUSED(evt))159 160 void OnColourChange(wxColourPickerEvent& WXUNUSED(evt)) 158 161 { 159 ColourDialog dlg (this, _T("Scenario Editor/LightingColour"), 160 wxColour(m_Colour->r, m_Colour->g, m_Colour->b)); 161 162 if (dlg.ShowModal() == wxID_OK) 163 { 164 wxColour& c = dlg.GetColourData().GetColour(); 165 m_Colour = AtlasMessage::Colour(c.Red(), c.Green(), c.Blue()); 166 UpdateButton(); 167 168 g_EnvironmentSettings.NotifyObserversExcept(m_Conn); 169 } 162 wxColour c = m_ColourCtrl->GetColour(); 163 m_Colour = AtlasMessage::Colour(c.Red(), c.Green(), c.Blue()); 164 g_EnvironmentSettings.NotifyObserversExcept(m_Conn); 170 165 } 171 166 172 void UpdateButton()173 {174 m_Button->SetBackgroundColour(wxColour(m_Colour->r, m_Colour->g, m_Colour->b));175 m_Button->SetLabel(wxString::Format(_T("%02X %02X %02X"), m_Colour->r, m_Colour->g, m_Colour->b));176 177 int y = 3*m_Colour->r + 6*m_Colour->g + 1*m_Colour->b;178 if (y > 1280)179 m_Button->SetForegroundColour(wxColour(0, 0, 0));180 else181 m_Button->SetForegroundColour(wxColour(255, 255, 255));182 }183 184 185 167 private: 186 168 ObservableScopedConnection m_Conn; 187 169 wxStaticBoxSizer* m_Sizer; 188 wx Button* m_Button;170 wxColourPickerCtrl* m_ColourCtrl; 189 171 Shareable<AtlasMessage::Colour>& m_Colour; 190 172 191 173 DECLARE_EVENT_TABLE(); 192 174 }; 193 175 194 176 BEGIN_EVENT_TABLE(VariableColourBox, wxPanel) 195 EVT_ BUTTON(wxID_ANY, VariableColourBox::OnClick)177 EVT_COLOURPICKER_CHANGED(wxID_ANY, VariableColourBox::OnColourChange) 196 178 END_EVENT_TABLE() 197 179 198 180 ////////////////////////////////////////////////////////////////////////// -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.h
16 16 */ 17 17 18 18 #include "../Common/Sidebar.h" 19 20 19 #include "General/Observable.h" 21 20 22 21 class VariableListBox; -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.h
16 16 */ 17 17 18 18 #include "../Common/Sidebar.h" 19 20 19 #include "GameInterface/Messages.h" 21 20 22 #include "wx/collpane.h"23 #include "wx/spinctrl.h"24 21 25 22 using namespace AtlasMessage; 26 23 24 class wxCollapsiblePaneEvent; 25 class wxColourPickerCtrl; 26 class wxSpinCtrl; 27 27 28 class PlayerNotebookPage; 28 29 class PlayerSettingsControl; 29 30 … … 54 55 55 56 wxTextCtrl* name; 56 57 wxChoice* civ; 57 wx Button* colour;58 wxColourPickerCtrl* colour; 58 59 wxSpinCtrl* food; 59 60 wxSpinCtrl* wood; 60 61 wxSpinCtrl* stone; -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.cpp
25 25 #include "ScenarioEditor/ScenarioEditor.h" 26 26 27 27 #include "wx/choicebk.h" 28 #include "wx/collpane.h" 29 #include "wx/clrpicker.h" 30 #include "wx/spinctrl.h" 28 31 29 32 enum 30 33 { … … 84 87 gridSizer->Add(civChoice, wxSizerFlags(1).Expand().Align(wxALIGN_RIGHT)); 85 88 m_Controls.civ = civChoice; 86 89 gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Colour")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT)); 87 wx Button* colourButton = new wxButton(this, ID_PlayerColour);88 gridSizer->Add(Tooltipped(colour Button,90 wxColourPickerCtrl* colourCtrl = new wxColourPickerCtrl(this, ID_PlayerColour); 91 gridSizer->Add(Tooltipped(colourCtrl, 89 92 _("Set player colour")), wxSizerFlags(1).Expand().Align(wxALIGN_RIGHT)); 90 m_Controls.colour = colour Button;93 m_Controls.colour = colourCtrl; 91 94 gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Default AI")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT)); 92 95 wxChoice* aiChoice = new wxChoice(this, wxID_ANY); 93 96 gridSizer->Add(Tooltipped(aiChoice, … … 224 227 } 225 228 226 229 private: 227 void OnColour(wxCommandEvent& evt)228 {229 // Show colour dialog230 ColourDialog colourDlg(this, _T("Scenario Editor/PlayerColour"), m_Controls.colour->GetBackgroundColour());231 232 if (colourDlg.ShowModal() == wxID_OK)233 {234 m_Controls.colour->SetBackgroundColour(colourDlg.GetColourData().GetColour());235 236 // Pass event on to next handler237 evt.Skip();238 }239 }240 241 230 void OnCameraSet(wxCommandEvent& evt) 242 231 { 243 232 AtlasMessage::qGetView qryView; … … 273 262 }; 274 263 275 264 BEGIN_EVENT_TABLE(PlayerNotebookPage, wxPanel) 276 EVT_BUTTON(ID_PlayerColour, PlayerNotebookPage::OnColour)277 265 EVT_BUTTON(ID_CameraSet, PlayerNotebookPage::OnCameraSet) 278 266 EVT_BUTTON(ID_CameraView, PlayerNotebookPage::OnCameraView) 279 267 EVT_BUTTON(ID_CameraClear, PlayerNotebookPage::OnCameraClear) … … 382 370 SendToEngine(); 383 371 } 384 372 } 385 386 void OnPlayerColour(wxCo mmandEvent& WXUNUSED(evt))373 374 void OnPlayerColour(wxColourPickerEvent& WXUNUSED(evt)) 387 375 { 388 376 if (!m_InGUIUpdate) 389 377 { … … 476 464 }; 477 465 478 466 BEGIN_EVENT_TABLE(PlayerSettingsControl, wxPanel) 479 EVT_ BUTTON(ID_PlayerColour, PlayerSettingsControl::OnPlayerColour)467 EVT_COLOURPICKER_CHANGED(ID_PlayerColour, PlayerSettingsControl::OnPlayerColour) 480 468 EVT_BUTTON(ID_CameraSet, PlayerSettingsControl::OnEdit) 481 469 EVT_BUTTON(ID_CameraClear, PlayerSettingsControl::OnEdit) 482 470 EVT_CHOICE(wxID_ANY, PlayerSettingsControl::OnEdit) … … 669 657 clrObj = *playerDefs["Colour"]; 670 658 colour = wxColor((*clrObj["r"]).getInt(), (*clrObj["g"]).getInt(), (*clrObj["b"]).getInt()); 671 659 } 672 controls.colour->Set BackgroundColour(colour);660 controls.colour->SetColour(colour); 673 661 674 662 // player type 675 663 wxString aiID; … … 792 780 } 793 781 794 782 // colour 795 wxColour colour = controls.colour->Get BackgroundColour();783 wxColour colour = controls.colour->GetColour(); 796 784 AtObj clrObj; 797 785 clrObj.setInt("r", (int)colour.Red()); 798 786 clrObj.setInt("g", (int)colour.Green());