Changeset 194
- Timestamp:
- 05/01/2009 08:05:17 PM (3 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
-
MainFrame.cpp (modified) (5 diffs)
-
MainFrame.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/MainFrame.cpp
r193 r194 70 70 71 71 using namespace main_frame; 72 const wxEventType wxEVT_ENABLE_ROLL = wxNewEventType();73 72 74 73 MainFrame::MainFrame(const wxString& title, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE) … … 129 128 m_yahtzeebonus = false; 130 129 m_numofplaysleft = 13; 131 m_skiproll = false; // the roll button hasn't been pressed yet, no need for skipping132 130 } 133 131 … … 352 350 //END connecting the menu items' events 353 351 354 Connect(ID_ROLL, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::OnRollButton)); 355 Connect(ID_ROLL, wxEVT_ENABLE_ROLL, wxCommandEventHandler (MainFrame::OnRollButton)); 352 Connect(ID_ROLL, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (MainFrame::DoubleRollLock)); 356 353 357 354 //BEGIN connecting the scoreboard buttons to the events … … 557 554 * \param event 558 555 */ 559 void MainFrame::OnRollButton ( wxCommandEvent& event)556 void MainFrame::OnRollButton () 560 557 { 561 558 short int dice[5]; //holds the dices score 562 559 563 if (event.GetEventType() == wxEVT_IDLE) {564 m_skiproll = false;565 Disconnect(wxEVT_IDLE, wxCommandEventHandler(MainFrame::OnRollButton));566 return;567 }568 569 //skip rolling the dice if the user accidently rolled the dice before they finished spinning.570 if (m_skiproll) return;571 m_skiproll = true;572 573 560 if (m_numofplaysleft == 13) 574 561 m_stats->game_started(); … … 633 620 (GetMenuBar()->FindItem(wxID_UNDO))->Enable(false); 634 621 m_yahtzeebonus = false; //if we scored yahtzee bonus before we don't care anymore. 635 636 Connect(wxEVT_IDLE, wxCommandEventHandler(MainFrame::OnRollButton)); 622 } 623 624 void MainFrame::DoubleRollLock(wxCommandEvent& event) 625 { 626 /* The function works by connecting to idle event, and raising a 627 * flag when it process a valid click on the Roll button. When the 628 * another click happens and the flag is up, it means it is 629 * accidental. When the idle events is triggered it means that we 630 * no longer roll the dice, so we lower the flag. 631 */ 632 static bool skip_roll = false; 633 if (event.GetEventType() == wxEVT_IDLE) { 634 skip_roll = false; 635 Disconnect(wxEVT_IDLE, wxCommandEventHandler(MainFrame::DoubleRollLock)); 636 return; 637 } 638 639 if (skip_roll) 640 return; 641 skip_roll = true; 642 643 Connect(wxEVT_IDLE, wxCommandEventHandler(MainFrame::DoubleRollLock)); 644 OnRollButton(); 637 645 } 638 646 -
trunk/src/MainFrame.h
r193 r194 57 57 void OnHelpMenuLink (wxCommandEvent& event); 58 58 59 void OnRollButton (wxCommandEvent& event); 59 /** 60 * Prevent accidental roll of the dice by double clicking the button. 61 * \param event The event that was send to the ::OnRollButton() 62 */ 63 void DoubleRollLock(wxCommandEvent& event); 64 60 65 void OnUpperButtons (wxCommandEvent& event); 61 66 void On3ofakindButton (wxCommandEvent& event); … … 94 99 void AddControlsAndLayout(); 95 100 101 void OnRollButton (); 102 96 103 wxStaticBoxSizer *uppersection, *lowersection; 97 104 wxBoxSizer *sectionsSizer; … … 107 114 short int m_lastmove; //stores the ID of the last button pressed. 108 115 short int m_rollsundo; //holds the number of remaining rolls for use with the undo option 109 110 bool m_skiproll; ///used to prevent the user from accidently rolling the dice twice111 116 112 117 class MainFrameEvtHandler *m_evt_handler;
Note: See TracChangeset
for help on using the changeset viewer.
