Ticket #943: AtlasUI-wxColourPickCtrl.patch

File AtlasUI-wxColourPickCtrl.patch, 7.4 KB (added by Mitchell K, 12 years ago)
  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp

     
    2222
    2323#include "GameInterface/Messages.h"
    2424#include "ScenarioEditor/ScenarioEditor.h"
    25 #include "General/Observable.h"
    26 #include "CustomControls/ColourDialog/ColourDialog.h"
     25#include "wx/clrpicker.h"
    2726
    2827using AtlasMessage::Shareable;
    2928
     
    144143
    145144        m_Sizer = new wxStaticBoxSizer(wxVERTICAL, this, label);
    146145        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());
    150153    }
    151154
    152155    void OnSettingsChange(const AtlasMessage::sEnvironmentSettings& WXUNUSED(env))
    153156    {
    154         UpdateButton();
     157        m_ColourCtrl->SetColour(wxColour(m_Colour->r, m_Colour->g, m_Colour->b));
    155158    }
    156 
    157     void OnClick(wxCommandEvent& WXUNUSED(evt))
     159   
     160    void OnColourChange(wxColourPickerEvent& WXUNUSED(evt))
    158161    {
    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());
    170164    }
    171165
    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         else
    181             m_Button->SetForegroundColour(wxColour(255, 255, 255));
    182     }
    183 
    184 
    185166private:
    186167    ObservableScopedConnection m_Conn;
    187168    wxStaticBoxSizer* m_Sizer;
    188     wxButton* m_Button;
     169    wxColourPickerCtrl* m_ColourCtrl;
    189170    Shareable<AtlasMessage::Colour>& m_Colour;
    190171
    191172    DECLARE_EVENT_TABLE();
    192173};
    193174
    194175BEGIN_EVENT_TABLE(VariableColourBox, wxPanel)
    195     EVT_BUTTON(wxID_ANY, VariableColourBox::OnClick)
     176    EVT_COLOURPICKER_CHANGED(wxID_ANY, VariableColourBox::OnColourChange)
    196177END_EVENT_TABLE()
    197178
    198179//////////////////////////////////////////////////////////////////////////
  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.h

     
    1616 */
    1717
    1818#include "../Common/Sidebar.h"
    19 
    2019#include "General/Observable.h"
    2120
    2221class VariableListBox;
  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.h

     
    1616 */
    1717
    1818#include "../Common/Sidebar.h"
    19 
    2019#include "GameInterface/Messages.h"
    2120
    22 #include "wx/collpane.h"
    23 #include "wx/spinctrl.h"
    2421
    2522using namespace AtlasMessage;
    2623
     24class wxCollapsiblePaneEvent;
     25class wxColourPickerCtrl;
     26class wxSpinCtrl;
     27
    2728class PlayerNotebookPage;
    2829class PlayerSettingsControl;
    2930
     
    5455
    5556    wxTextCtrl* name;
    5657    wxChoice* civ;
    57     wxButton* colour;
     58    wxColourPickerCtrl* colour;
    5859    wxSpinCtrl* food;
    5960    wxSpinCtrl* wood;
    6061    wxSpinCtrl* stone;
  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.cpp

     
    2525#include "ScenarioEditor/ScenarioEditor.h"
    2626
    2727#include "wx/choicebk.h"
     28#include "wx/collpane.h"
     29#include "wx/clrpicker.h"
     30#include "wx/spinctrl.h"
    2831
    2932enum
    3033{
     
    8487            gridSizer->Add(civChoice, wxSizerFlags(1).Expand().Align(wxALIGN_RIGHT));
    8588            m_Controls.civ = civChoice;
    8689            gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Colour")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
    87             wxButton* colourButton = new wxButton(this, ID_PlayerColour);
    88             gridSizer->Add(Tooltipped(colourButton,
     90            wxColourPickerCtrl* colourCtrl = new wxColourPickerCtrl(this, ID_PlayerColour);
     91            gridSizer->Add(Tooltipped(colourCtrl,
    8992                _("Set player colour")), wxSizerFlags(1).Expand().Align(wxALIGN_RIGHT));
    90             m_Controls.colour = colourButton;
     93            m_Controls.colour = colourCtrl;
    9194            gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Default AI")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
    9295            wxChoice* aiChoice = new wxChoice(this, wxID_ANY);
    9396            gridSizer->Add(Tooltipped(aiChoice,
     
    224227    }
    225228
    226229private:
    227     void OnColour(wxCommandEvent& evt)
    228     {
    229         // Show colour dialog
    230         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 handler
    237             evt.Skip();
    238         }
    239     }
    240 
    241230    void OnCameraSet(wxCommandEvent& evt)
    242231    {
    243232        AtlasMessage::qGetView qryView;
     
    273262};
    274263
    275264BEGIN_EVENT_TABLE(PlayerNotebookPage, wxPanel)
    276     EVT_BUTTON(ID_PlayerColour, PlayerNotebookPage::OnColour)
    277265    EVT_BUTTON(ID_CameraSet, PlayerNotebookPage::OnCameraSet)
    278266    EVT_BUTTON(ID_CameraView, PlayerNotebookPage::OnCameraView)
    279267    EVT_BUTTON(ID_CameraClear, PlayerNotebookPage::OnCameraClear)
     
    382370            SendToEngine();
    383371        }
    384372    }
    385 
    386     void OnPlayerColour(wxCommandEvent& WXUNUSED(evt))
     373   
     374    void OnPlayerColour(wxColourPickerEvent& WXUNUSED(evt))
    387375    {
    388376        if (!m_InGUIUpdate)
    389377        {
     
    476464};
    477465
    478466BEGIN_EVENT_TABLE(PlayerSettingsControl, wxPanel)
    479     EVT_BUTTON(ID_PlayerColour, PlayerSettingsControl::OnPlayerColour)
     467    EVT_COLOURPICKER_CHANGED(ID_PlayerColour, PlayerSettingsControl::OnPlayerColour)
    480468    EVT_BUTTON(ID_CameraSet, PlayerSettingsControl::OnEdit)
    481469    EVT_BUTTON(ID_CameraClear, PlayerSettingsControl::OnEdit)
    482470    EVT_CHOICE(wxID_ANY, PlayerSettingsControl::OnEdit)
     
    669657            clrObj = *playerDefs["Colour"];
    670658            colour = wxColor((*clrObj["r"]).getInt(), (*clrObj["g"]).getInt(), (*clrObj["b"]).getInt());
    671659        }
    672         controls.colour->SetBackgroundColour(colour);
     660        controls.colour->SetColour(colour);
    673661
    674662        // player type
    675663        wxString aiID;
     
    792780        }
    793781
    794782        // colour
    795         wxColour colour = controls.colour->GetBackgroundColour();
     783        wxColour colour = controls.colour->GetColour();
    796784        AtObj clrObj;
    797785        clrObj.setInt("r", (int)colour.Red());
    798786        clrObj.setInt("g", (int)colour.Green());