Changeset 71
- Timestamp:
- 20/04/07 13:10:41 (6 years ago)
- Location:
- trunk/OpenYahtzee
- Files:
-
- 6 edited
-
openyahtzee.kdevelop.pcs (modified) (previous)
-
openyahtzee.kdevses (modified) (1 diff)
-
src/MainFrame.cpp (modified) (3 diffs)
-
src/MainFrame.h (modified) (1 diff)
-
src/wxDynamicBitmap.cpp (modified) (4 diffs)
-
src/wxDynamicBitmap.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/OpenYahtzee/openyahtzee.kdevses
r70 r71 2 2 <!DOCTYPE KDevPrjSession> 3 3 <KDevPrjSession> 4 <DocsAndViews NumberOfDocuments=" 7" >4 <DocsAndViews NumberOfDocuments="8" > 5 5 <Doc0 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/SettingsDB.h" > 6 6 <View0 Type="Source" /> 7 7 </Doc0> 8 8 <Doc1 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/openyahtzee.cpp" > 9 <View0 Type="Source" />9 <View0 line="0" Type="Source" /> 10 10 </Doc1> 11 11 <Doc2 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/MainFrame.cpp" > 12 <View0 line=" 332" Type="Source" />12 <View0 line="786" Type="Source" /> 13 13 </Doc2> 14 14 <Doc3 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/ObjectsID.h" > 15 <View0 Type="Source" />15 <View0 line="0" Type="Source" /> 16 16 </Doc3> 17 17 <Doc4 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/MainFrame.h" > 18 <View0 Type="Source" />18 <View0 line="64" Type="Source" /> 19 19 </Doc4> 20 20 <Doc5 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/wxDynamicBitmap.cpp" > 21 <View0 Type="Source" />21 <View0 line="63" Type="Source" /> 22 22 </Doc5> 23 23 <Doc6 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/wxDynamicBitmap.h" > 24 <View0 line=" 52" Type="Source" />24 <View0 line="48" Type="Source" /> 25 25 </Doc6> 26 <Doc7 NumberOfViews="1" URL="file:///home/guy/workspace/OpenYahtzee/src/SettingsDialog.cpp" > 27 <View0 line="50" Type="Source" /> 28 </Doc7> 26 29 </DocsAndViews> 27 30 <pluginList> -
trunk/OpenYahtzee/src/MainFrame.cpp
r69 r71 269 269 Connect(ID_CHANCE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnChanceButton)); 270 270 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)); 271 272 //END connecting the scoreboard buttons to the event 272 273 … … 738 739 void MainFrame::OnDiceClick (wxCommandEvent& event) 739 740 { 741 //tick the checkbox 740 742 if (((wxCheckBox*) FindWindow(event.GetId()-ID_DICE1 + ID_DICE1KEEP))->IsEnabled()){ 741 743 bool newvalue = (((wxCheckBox*) FindWindow(event.GetId()-ID_DICE1 + ID_DICE1KEEP))->GetValue())?false:true; 742 744 ((wxCheckBox*) FindWindow(event.GetId()-ID_DICE1 + ID_DICE1KEEP)) -> SetValue(newvalue); 743 745 } 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 754 void MainFrame::OnKeepClick (wxCommandEvent& event) 755 { 756 wxCheckBox *temp = (wxCheckBox*) FindWindow(event.GetId()); 757 ((wxDynamicBitmap*) FindWindow(event.GetId()-ID_DICE1KEEP + ID_DICE1))->SetGrayScale(temp->GetValue()); 744 758 } 745 759 … … 770 784 ((wxCheckBox*) FindWindow(i + ID_DICE1KEEP)) -> SetValue(false); 771 785 ((wxCheckBox*) FindWindow(i + ID_DICE1KEEP)) -> Enable(false); 786 ((wxDynamicBitmap*) FindWindow(i+ID_DICE1)) -> SetGrayScale(false); 772 787 } 773 788 } -
trunk/OpenYahtzee/src/MainFrame.h
r65 r71 63 63 void OnChanceButton (wxCommandEvent& event); 64 64 void OnDiceClick (wxCommandEvent& event); 65 66 65 void OnKeepClick (wxCommandEvent& event); 67 66 68 67 private: -
trunk/OpenYahtzee/src/wxDynamicBitmap.cpp
r65 r71 32 32 wxControl::Create(parent,id,pos,size,style,wxDefaultValidator,name); 33 33 Connect(id, wxEVT_PAINT, wxPaintEventHandler(wxDynamicBitmap::OnPaint)); 34 Connect(id, wxEVT_LEFT_UP,wxMouseEventHandler(wxDynamicBitmap::OnClick)); 34 35 SetBitmap( bitmap); 35 Connect(id, wxEVT_LEFT_UP,wxMouseEventHandler(wxDynamicBitmap::OnClick)); 36 m_grayscale=false; 37 36 38 } 37 39 … … 50 52 { 51 53 m_bitmap = bitmap; 54 SetGrayScale(m_grayscale); 52 55 wxWindow::Refresh(); 53 56 wxWindow::Update(); … … 65 68 dc.DrawRectangle(windowRect); 66 69 67 dc.DrawBitmap(m_bitmap , 0 , 0, true); 70 dc.DrawBitmap((m_grayscale?m_graybitmap:m_bitmap) , 0 , 0, true); 71 68 72 } 69 73 … … 81 85 GetEventHandler()->ProcessEvent( newevent ); 82 86 } 87 88 void 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 103 void 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 47 47 void OnClick(wxMouseEvent& event); 48 48 wxSize DoGetBestSize() const; 49 void SetGrayScale(bool grayscale=true); 50 void ConvertToGrayScale(wxImage& image) const; 49 51 private: 50 52 void PaintBitmap(wxDC& dc); 51 53 wxBitmap m_bitmap; 54 wxBitmap m_graybitmap; 55 bool m_grayscale; 52 56 }; 53 57
Note: See TracChangeset
for help on using the changeset viewer.
