Changeset 124
- Timestamp:
- 30/11/07 17:37:49 (6 years ago)
- Location:
- trunk/OpenYahtzee/src
- Files:
-
- 2 edited
-
MainFrame.cpp (modified) (12 diffs)
-
MainFrame.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/OpenYahtzee/src/MainFrame.cpp
r123 r124 70 70 #define OY_VERSION "1.8.0" 71 71 72 DEFINE_EVENT_TYPE(wxEVT_ENABLE_ROLL) /*just to satisfy kdevelop*/; 73 const wxEventType myEVT_FRAME_LOADED = wxNewEventType(); 74 72 const wxEventType wxEVT_ENABLE_ROLL = wxNewEventType(); 75 73 76 74 MainFrame::MainFrame(const wxString& title, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE) … … 292 290 Connect(ID_DICE1KEEP,ID_DICE5KEEP, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (MainFrame::OnKeepClick)); 293 291 //END connecting the scoreboard buttons to the event 294 295 for (int i = ID_ACES; i<=ID_CHANCE; i++) 292 293 /* The following code connects the on wxEVT_ENTER_WINDOW and 294 * wxEVT_LEAVE_WINDOW events to the score buttons to handle the score 295 * hints. For some unknown technical problem we have to directly connect 296 * the events, otherwise the wxEVT_LEAVE_WINDOW doesn't get generated. 297 * We have to use event handler other than MainFrame's as the regular 298 * event handler leads to segmantation fault. 299 */ 300 wxButton *temp; 301 for (int i = ID_ACES; i<=ID_CHANCE; i++) { 302 temp = ((wxButton *)FindWindow(i)); 296 303 ((wxWindow *)FindWindow(i))->PushEventHandler(m_evt_handler); 297 m_evt_handler->Connect(ID_ACES, ID_CHANCE, wxEVT_ENTER_WINDOW, 298 wxMouseEventHandler(MainFrameEvtHandler::OnScoreMouseEnter)); 299 m_evt_handler->Connect(ID_ACES, ID_CHANCE, wxEVT_LEAVE_WINDOW, 300 wxMouseEventHandler(MainFrameEvtHandler::OnScoreMouseLeave)); 304 ((wxWindow *)FindWindow(i))->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(MainFrameEvtHandler::OnScoreMouseLeave), temp, m_evt_handler); 305 ((wxWindow *)FindWindow(i))->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(MainFrameEvtHandler::OnScoreMouseEnter), temp, m_evt_handler); 306 } 301 307 302 308 /*** End of Event Table ***/ … … 621 627 out.Printf(wxT("%i"),temp); 622 628 ((wxTextCtrl*) FindWindow(event.GetId() - ID_ACES + ID_ACESTEXT))->SetValue(out); 629 ((wxTextCtrl*) FindWindow(event.GetId() - ID_ACES + ID_ACESTEXT))->SetBackgroundColour(*wxWHITE); 623 630 624 631 PostScore(event.GetId()); … … 643 650 out.Printf(wxT("%i"),m_score_dice.ThreeOfAKind()); 644 651 ((wxTextCtrl*) FindWindow(ID_THREEOFAKINDTEXT))->SetValue(out); 652 ((wxTextCtrl*) FindWindow(ID_THREEOFAKINDTEXT))->SetBackgroundColour(*wxWHITE); 645 653 646 654 PostScore(event.GetId()); … … 662 670 out.Printf(wxT("%i"),m_score_dice.FourOfAKind()); 663 671 ((wxTextCtrl*) FindWindow(ID_FOUROFAKINDTEXT))->SetValue(out); 672 ((wxTextCtrl*) FindWindow(ID_FOUROFAKINDTEXT))->SetBackgroundColour(*wxWHITE); 664 673 665 674 PostScore(event.GetId()); … … 682 691 out.Printf(wxT("%i"), m_score_dice.FullHouse()); 683 692 ((wxTextCtrl*) FindWindow(ID_FULLHOUSETEXT))->SetValue(out); 693 ((wxTextCtrl*) FindWindow(ID_FULLHOUSETEXT))->SetBackgroundColour(*wxWHITE); 684 694 685 695 PostScore(event.GetId()); … … 703 713 out.Printf(wxT("%i"), m_score_dice.SmallSequence()); 704 714 ((wxTextCtrl*) FindWindow(ID_SMALLSEQUENCETEXT))->SetValue(out); 715 ((wxTextCtrl*) FindWindow(ID_SMALLSEQUENCETEXT))->SetBackgroundColour(*wxWHITE); 705 716 706 717 PostScore(event.GetId()); … … 724 735 out.Printf(wxT("%i"), m_score_dice.LargeSequence()); 725 736 ((wxTextCtrl*) FindWindow(ID_LARGESEQUENCETEXT))->SetValue(out); 737 ((wxTextCtrl*) FindWindow(ID_LARGESEQUENCETEXT))->SetBackgroundColour(*wxWHITE); 726 738 727 739 PostScore(event.GetId()); … … 744 756 out.Printf(wxT("%i"), m_score_dice.Yahtzee()); 745 757 ((wxTextCtrl*) FindWindow(ID_YAHTZEETEXT))->SetValue(out); 758 ((wxTextCtrl*) FindWindow(ID_YAHTZEETEXT))->SetBackgroundColour(*wxWHITE); 746 759 747 760 PostScore(event.GetId()); … … 761 774 out.Printf(wxT("%i"),m_score_dice.Chance()); 762 775 ((wxTextCtrl*) FindWindow(ID_CHANCETEXT))->SetValue(out); 776 ((wxTextCtrl*) FindWindow(ID_CHANCETEXT))->SetBackgroundColour(*wxWHITE); 763 777 764 778 PostScore(event.GetId()); … … 1197 1211 1198 1212 /** 1213 * Check whether the dice should be rolled or if the user already rolled them. 1214 * \return true if the dice are valid (rolled). 1215 */ 1216 bool MainFrame::IsValidDice() 1217 { 1218 if ( m_rolls < 3 ) 1219 return true; 1220 return false; 1221 } 1222 1223 /** 1199 1224 * 1200 1225 */ 1201 1226 void MainFrameEvtHandler::OnScoreMouseEnter (wxMouseEvent& event) 1202 1227 { 1228 int id; 1203 1229 wxTextCtrl *text_control; 1204 1230 wxString out; 1205 text_control = ((wxTextCtrl*)m_main_frame->FindWindow(event.GetId()-ID_ACES+ID_ACESTEXT)); 1206 switch (event.GetId()) { 1231 if (! m_main_frame->IsValidDice()){ 1232 event.Skip(); 1233 return; 1234 } 1235 1236 id = ((wxWindow *)event.GetEventObject())->GetId(); 1237 text_control = ((wxTextCtrl*)m_main_frame->FindWindow(id-ID_ACES+ID_ACESTEXT)); 1238 switch (id) { 1207 1239 case ID_ACES: 1208 1240 out.Printf(wxT("%i"), m_main_frame->m_score_dice.Aces()); … … 1256 1288 void MainFrameEvtHandler::OnScoreMouseLeave (wxMouseEvent& event) 1257 1289 { 1290 //we dont have the id of the control that generated the event 1258 1291 wxTextCtrl *text_control; 1259 text_control = ((wxTextCtrl*)m_main_frame->FindWindow(event.GetId()-ID_ACES+ID_ACESTEXT)); 1260 text_control->SetDefaultStyle(wxTextAttr(*wxBLACK)); 1261 text_control->Clear(); 1262 } 1292 1293 if (! m_main_frame->IsValidDice()){ 1294 event.Skip(); 1295 return; 1296 } 1297 1298 for (int i = ID_ACESTEXT; i<=ID_CHANCETEXT; i++) { 1299 text_control = (wxTextCtrl *)m_main_frame->FindWindow(i); 1300 if (text_control->GetBackgroundColour()==wxColour(239,239,239)){ 1301 text_control->Clear(); 1302 text_control->SetBackgroundColour(*wxWHITE); 1303 } 1304 } 1305 1306 event.Skip(); //allow default proccesing 1307 } -
trunk/OpenYahtzee/src/MainFrame.h
r123 r124 30 30 #ifndef MAINFRAME_INC 31 31 #define MAINFRAME_INC 32 33 DECLARE_EVENT_TYPE(wxEVT_ENABLE_ROLL, -1) /*just to satisfy kdevelop*/;34 32 35 33 /// MainFrame class - the main window … … 70 68 void OnScoreMouseEnter (wxMouseEvent& event); 71 69 void OnScoreMouseLeave (wxMouseEvent& event); 72 70 71 bool IsValidDice(); 73 72 74 73 ScoreDice m_score_dice;
Note: See TracChangeset
for help on using the changeset viewer.
