Changeset 71


Ignore:
Timestamp:
20/04/07 13:10:41 (6 years ago)
Author:
guyru
Message:

Make the dice look grayscale when the "keep" checkbox is ticked.
-Added SetGrayScale?() to wxDynamicBitmap
-Added event-handler for clicking on the "keep" checkboxes

Location:
trunk/OpenYahtzee
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/OpenYahtzee/openyahtzee.kdevses

    r70 r71  
    22<!DOCTYPE KDevPrjSession> 
    33<KDevPrjSession> 
    4  <DocsAndViews NumberOfDocuments="7" > 
     4 <DocsAndViews NumberOfDocuments="8" > 
    55  <Doc0 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/SettingsDB.h" > 
    66   <View0 Type="Source" /> 
    77  </Doc0> 
    88  <Doc1 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/openyahtzee.cpp" > 
    9    <View0 Type="Source" /> 
     9   <View0 line="0" Type="Source" /> 
    1010  </Doc1> 
    1111  <Doc2 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/MainFrame.cpp" > 
    12    <View0 line="332" Type="Source" /> 
     12   <View0 line="786" Type="Source" /> 
    1313  </Doc2> 
    1414  <Doc3 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/ObjectsID.h" > 
    15    <View0 Type="Source" /> 
     15   <View0 line="0" Type="Source" /> 
    1616  </Doc3> 
    1717  <Doc4 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/MainFrame.h" > 
    18    <View0 Type="Source" /> 
     18   <View0 line="64" Type="Source" /> 
    1919  </Doc4> 
    2020  <Doc5 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/wxDynamicBitmap.cpp" > 
    21    <View0 Type="Source" /> 
     21   <View0 line="63" Type="Source" /> 
    2222  </Doc5> 
    2323  <Doc6 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/wxDynamicBitmap.h" > 
    24    <View0 line="52" Type="Source" /> 
     24   <View0 line="48" Type="Source" /> 
    2525  </Doc6> 
     26  <Doc7 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/SettingsDialog.cpp" > 
     27   <View0 line="50" Type="Source" /> 
     28  </Doc7> 
    2629 </DocsAndViews> 
    2730 <pluginList> 
  • trunk/OpenYahtzee/src/MainFrame.cpp

    r69 r71  
    269269        Connect(ID_CHANCE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnChanceButton)); 
    270270        Connect(ID_DICE1,ID_DICE5, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnDiceClick)); 
     271        Connect(ID_DICE1KEEP,ID_DICE5KEEP, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (MainFrame::OnKeepClick)); 
    271272        //END connecting the scoreboard buttons to the event 
    272273 
     
    738739void MainFrame::OnDiceClick (wxCommandEvent& event) 
    739740{ 
     741        //tick the checkbox 
    740742        if (((wxCheckBox*) FindWindow(event.GetId()-ID_DICE1 + ID_DICE1KEEP))->IsEnabled()){ 
    741743                bool newvalue = (((wxCheckBox*) FindWindow(event.GetId()-ID_DICE1 + ID_DICE1KEEP))->GetValue())?false:true; 
    742744                ((wxCheckBox*) FindWindow(event.GetId()-ID_DICE1 + ID_DICE1KEEP)) -> SetValue(newvalue); 
    743745        } 
     746 
     747        //dispatch a click event on the checkbox 
     748        wxCommandEvent clickevent((event.GetId()-ID_DICE1 + ID_DICE1KEEP),wxEVT_COMMAND_CHECKBOX_CLICKED); 
     749        clickevent.SetEventObject( this ); 
     750        clickevent.SetId(event.GetId()-ID_DICE1 + ID_DICE1KEEP); 
     751        this->OnKeepClick(clickevent); ///\todo find a better way to call the event handler. 
     752} 
     753 
     754void MainFrame::OnKeepClick (wxCommandEvent& event) 
     755{ 
     756        wxCheckBox *temp = (wxCheckBox*) FindWindow(event.GetId()); 
     757        ((wxDynamicBitmap*) FindWindow(event.GetId()-ID_DICE1KEEP + ID_DICE1))->SetGrayScale(temp->GetValue()); 
    744758} 
    745759 
     
    770784                ((wxCheckBox*) FindWindow(i + ID_DICE1KEEP)) -> SetValue(false); 
    771785                ((wxCheckBox*) FindWindow(i + ID_DICE1KEEP)) -> Enable(false); 
     786                ((wxDynamicBitmap*) FindWindow(i+ID_DICE1)) -> SetGrayScale(false); 
    772787        } 
    773788} 
  • trunk/OpenYahtzee/src/MainFrame.h

    r65 r71  
    6363        void OnChanceButton (wxCommandEvent& event); 
    6464        void OnDiceClick (wxCommandEvent& event); 
    65  
    66          
     65        void OnKeepClick (wxCommandEvent& event);        
    6766 
    6867private: 
  • trunk/OpenYahtzee/src/wxDynamicBitmap.cpp

    r65 r71  
    3232        wxControl::Create(parent,id,pos,size,style,wxDefaultValidator,name); 
    3333        Connect(id, wxEVT_PAINT, wxPaintEventHandler(wxDynamicBitmap::OnPaint)); 
     34        Connect(id, wxEVT_LEFT_UP,wxMouseEventHandler(wxDynamicBitmap::OnClick)); 
    3435        SetBitmap( bitmap); 
    35         Connect(id, wxEVT_LEFT_UP,wxMouseEventHandler(wxDynamicBitmap::OnClick)); 
     36        m_grayscale=false; 
     37         
    3638} 
    3739 
     
    5052{ 
    5153        m_bitmap = bitmap; 
     54        SetGrayScale(m_grayscale); 
    5255        wxWindow::Refresh(); 
    5356        wxWindow::Update(); 
     
    6568        dc.DrawRectangle(windowRect); 
    6669 
    67         dc.DrawBitmap(m_bitmap , 0 , 0, true); 
     70        dc.DrawBitmap((m_grayscale?m_graybitmap:m_bitmap) , 0 , 0, true); 
     71         
    6872} 
    6973 
     
    8185        GetEventHandler()->ProcessEvent( newevent ); 
    8286} 
     87 
     88void wxDynamicBitmap::SetGrayScale(bool grayscale) 
     89{ 
     90        m_grayscale = grayscale; 
     91         
     92        //regenerate the grayscale bitmap; 
     93        if (grayscale) { 
     94                wxImage tempimage; 
     95                tempimage = m_bitmap.ConvertToImage(); 
     96                ConvertToGrayScale(tempimage); 
     97                m_graybitmap = wxBitmap(tempimage); 
     98        } 
     99        wxWindow::Refresh(); 
     100        wxWindow::Update(); 
     101} 
     102 
     103void wxDynamicBitmap::ConvertToGrayScale(wxImage& image) const 
     104{ 
     105        double red2Gray    = 0.297; 
     106        double green2Gray = 0.589; 
     107        double blue2Gray = 0.114; 
     108        int w = image.GetWidth(), h = image.GetHeight(); 
     109        unsigned char *data = image.GetData(); 
     110        int x,y; 
     111        for (y = 0; y < h; y++) 
     112                for (x = 0; x < w; x++) 
     113                { 
     114                        long pos = (y * w + x) * 3; 
     115                        char g = (char) (data[pos]*red2Gray + 
     116                                data[pos+1]*green2Gray + 
     117                                data[pos+2]*blue2Gray); 
     118                        data[pos] = data[pos+1] = data[pos+2] = g; 
     119                } 
     120} 
     121 
  • trunk/OpenYahtzee/src/wxDynamicBitmap.h

    r65 r71  
    4747        void OnClick(wxMouseEvent& event); 
    4848        wxSize DoGetBestSize() const; 
     49        void SetGrayScale(bool grayscale=true); 
     50        void ConvertToGrayScale(wxImage& image) const; 
    4951private: 
    5052        void PaintBitmap(wxDC& dc); 
    5153        wxBitmap m_bitmap; 
     54        wxBitmap m_graybitmap; 
     55        bool m_grayscale; 
    5256}; 
    5357 
Note: See TracChangeset for help on using the changeset viewer.