From e323a5d6059cce4e03b468a30ddf2b04e77f7b8a Mon Sep 17 00:00:00 2001 From: Holly McFarland Date: Tue, 21 Sep 2021 15:35:47 -0400 Subject: [PATCH 1/3] Add "When space is pressed, switch direction" control in preference dialog As opposed to default "insert a blank" --- src/XGridCtrl.cpp | 31 +++- src/XGridCtrl.hpp | 2 + src/dialogs/PreferencesPanel.cpp | 8 + src/dialogs/wxFB_PreferencesPanels.cpp | 16 ++ src/dialogs/wxFB_PreferencesPanels.fbp | 210 ++++++++++++++++++++++++- src/dialogs/wxFB_PreferencesPanels.h | 3 + 6 files changed, 262 insertions(+), 8 deletions(-) diff --git a/src/XGridCtrl.cpp b/src/XGridCtrl.cpp index 52196861..64a07016 100644 --- a/src/XGridCtrl.cpp +++ b/src/XGridCtrl.cpp @@ -1545,15 +1545,40 @@ XGridCtrl::OnLetter(wxChar key, int mod) wxASSERT(! IsRebusEntry()); if (static_cast(key) == WXK_SPACE) - SetSquareText(*m_focusedSquare, _T("")); - else + { + if (HasStyle(SWAP_ON_SPACE)) + { + if (m_focusedDirection == puz::ACROSS) + { + SetFocusedSquare(m_focusedSquare, NULL, puz::DOWN); + } + else + { + SetFocusedSquare(m_focusedSquare, NULL, puz::ACROSS); + } + } + else + { + SetSquareText(*m_focusedSquare, _T("")); + } + } + else + { SetSquareText(*m_focusedSquare, key); + } // Space bar always moves forward one square if (static_cast(key) == WXK_SPACE) - SetFocusedSquare(m_focusedWord->FindNextSquare(m_focusedSquare, FIND_WHITE_SQUARE), m_focusedWord); + { + if (!HasStyle(SWAP_ON_SPACE)) + { + SetFocusedSquare(m_focusedWord->FindNextSquare(m_focusedSquare, FIND_WHITE_SQUARE), m_focusedWord); + } + } else + { MoveAfterLetter(); + } } diff --git a/src/XGridCtrl.hpp b/src/XGridCtrl.hpp index cf789b8d..56e3c9c9 100644 --- a/src/XGridCtrl.hpp +++ b/src/XGridCtrl.hpp @@ -55,6 +55,7 @@ enum GridStyle STRICT_REBUS = 0x0080, CONTEXT_MENU = 0x0100, // Not yet(?) implemented SWAP_ON_DCLICK = 0x0200, + SWAP_ON_SPACE = 0x0400, DEFAULT_GRID_STYLE = PAUSE_ON_SWITCH | MOVE_AFTER_LETTER @@ -71,6 +72,7 @@ enum GridStyle | CHECK_WHILE_TYPING | STRICT_REBUS | SWAP_ON_DCLICK + | SWAP_ON_SPACE }; enum CorrectStatus diff --git a/src/dialogs/PreferencesPanel.cpp b/src/dialogs/PreferencesPanel.cpp index c95ee5a7..94955a4b 100644 --- a/src/dialogs/PreferencesPanel.cpp +++ b/src/dialogs/PreferencesPanel.cpp @@ -215,6 +215,10 @@ void SolvePanel::DoLoadConfig() m_nextSquare->SetValue(1); m_blankOnDirection->SetValue((gridStyle & BLANK_ON_DIRECTION) != 0); m_blankOnNewWord ->SetValue((gridStyle & BLANK_ON_NEW_WORD) != 0); + if (gridStyle & SWAP_ON_SPACE) + m_switchDirectionsOnSpace->SetValue(1); + else + m_insertBlankOnSpace->SetValue(1); m_pauseOnSwitch ->SetValue((gridStyle & PAUSE_ON_SWITCH) != 0); m_moveOnRightClick->SetValue((gridStyle & MOVE_ON_RIGHT_CLICK) != 0); m_swapOnDClick ->SetValue((gridStyle & SWAP_ON_DCLICK) != 0); @@ -253,6 +257,8 @@ void SolvePanel::DoSaveConfig() gridStyle |= BLANK_ON_DIRECTION; if (m_blankOnNewWord->GetValue()) gridStyle |= BLANK_ON_NEW_WORD; + if (m_switchDirectionsOnSpace->GetValue()) + gridStyle |= SWAP_ON_SPACE; if(m_pauseOnSwitch->GetValue()) gridStyle |= PAUSE_ON_SWITCH; if (m_moveOnRightClick->GetValue()) @@ -284,6 +290,8 @@ void SolvePanel::ConnectChangedEvents() BindChangedEvent(m_nextBlank); BindChangedEvent(m_blankOnDirection); BindChangedEvent(m_blankOnNewWord); + BindChangedEvent(m_insertBlankOnSpace); + BindChangedEvent(m_switchDirectionsOnSpace); BindChangedEvent(m_pauseOnSwitch); BindChangedEvent(m_moveOnRightClick); BindChangedEvent(m_swapOnDClick); diff --git a/src/dialogs/wxFB_PreferencesPanels.cpp b/src/dialogs/wxFB_PreferencesPanels.cpp index 65acfb38..6958e437 100644 --- a/src/dialogs/wxFB_PreferencesPanels.cpp +++ b/src/dialogs/wxFB_PreferencesPanels.cpp @@ -62,6 +62,22 @@ wxFB_SolvePanel::wxFB_SolvePanel( wxWindow* parent, wxWindowID id, const wxPoint sbSizer3->Add( bSizer13, 0, wxLEFT, 20 ); + m_staticText11 = new wxStaticText( sbSizer3->GetStaticBox(), wxID_ANY, wxT("When pressing space"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText11->Wrap( -1 ); + sbSizer3->Add( m_staticText11, 0, wxALL, 5 ); + + wxBoxSizer* bSizer14; + bSizer14 = new wxBoxSizer( wxVERTICAL ); + + m_insertBlankOnSpace = new wxRadioButton( sbSizer3->GetStaticBox(), wxID_ANY, wxT("Insert a blank"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer14->Add( m_insertBlankOnSpace, 0, wxALL, 5 ); + + m_switchDirectionsOnSpace = new wxRadioButton( sbSizer3->GetStaticBox(), wxID_ANY, wxT("Switch directions"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer14->Add( m_switchDirectionsOnSpace, 0, wxALL, 5 ); + + + sbSizer3->Add( bSizer14, 0, wxLEFT, 20 ); + m_pauseOnSwitch = new wxCheckBox( sbSizer3->GetStaticBox(), wxID_ANY, wxT("Pause when switching direction"), wxDefaultPosition, wxDefaultSize, 0 ); m_pauseOnSwitch->SetValue(true); sbSizer3->Add( m_pauseOnSwitch, 0, wxALL, 5 ); diff --git a/src/dialogs/wxFB_PreferencesPanels.fbp b/src/dialogs/wxFB_PreferencesPanels.fbp index dcf992c2..624f18f9 100644 --- a/src/dialogs/wxFB_PreferencesPanels.fbp +++ b/src/dialogs/wxFB_PreferencesPanels.fbp @@ -218,11 +218,11 @@ OnMoveAfterLetter - + 20 wxLEFT 0 - + bSizer12 wxVERTICAL @@ -418,7 +418,7 @@ -1 - + 20 wxLEFT 0 @@ -557,6 +557,206 @@ + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + When pressing space + 0 + + 0 + + + 0 + + 1 + m_staticText11 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + 20 + wxLEFT + 0 + + + bSizer14 + wxVERTICAL + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Insert a blank + + 0 + + + 0 + + 1 + m_insertBlankOnSpace + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Switch directions + + 0 + + + 0 + + 1 + m_switchDirectionsOnSpace + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + 5 wxALL @@ -753,11 +953,11 @@ - + 5 wxALL|wxEXPAND 1 - + bSizer5 wxVERTICAL diff --git a/src/dialogs/wxFB_PreferencesPanels.h b/src/dialogs/wxFB_PreferencesPanels.h index 80a0bada..1bfe965d 100644 --- a/src/dialogs/wxFB_PreferencesPanels.h +++ b/src/dialogs/wxFB_PreferencesPanels.h @@ -47,6 +47,9 @@ class wxFB_SolvePanel : public wxPanel wxStaticText* m_staticText10; wxCheckBox* m_blankOnDirection; wxCheckBox* m_blankOnNewWord; + wxStaticText* m_staticText11; + wxRadioButton* m_insertBlankOnSpace; + wxRadioButton* m_switchDirectionsOnSpace; wxCheckBox* m_pauseOnSwitch; wxCheckBox* m_moveOnRightClick; wxCheckBox* m_swapOnDClick; From d75bc3d45f681b40101a50daed75336b75cfb225 Mon Sep 17 00:00:00 2001 From: Holly McFarland Date: Tue, 21 Sep 2021 18:34:06 -0400 Subject: [PATCH 2/3] Add control to OSX preferences panel as well --- src/dialogs/wxFB_PreferencesPanelsOSX.cpp | 16 ++ src/dialogs/wxFB_PreferencesPanelsOSX.fbp | 202 +++++++++++++++++++++- src/dialogs/wxFB_PreferencesPanelsOSX.h | 3 + 3 files changed, 220 insertions(+), 1 deletion(-) diff --git a/src/dialogs/wxFB_PreferencesPanelsOSX.cpp b/src/dialogs/wxFB_PreferencesPanelsOSX.cpp index 7f7f3efa..748f6f36 100644 --- a/src/dialogs/wxFB_PreferencesPanelsOSX.cpp +++ b/src/dialogs/wxFB_PreferencesPanelsOSX.cpp @@ -101,6 +101,22 @@ wxFB_SolvePanel::wxFB_SolvePanel( wxWindow* parent, wxWindowID id, const wxPoint bSizer12->Add( bSizer13, 0, wxLEFT, 25 ); + m_staticText16 = new wxStaticText( this, wxID_ANY, wxT("When pressing space"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText16->Wrap( -1 ); + bSizer12->Add( m_staticText16, 0, wxLEFT|wxRIGHT|wxTOP, 5 ); + + wxBoxSizer* bSizer25; + bSizer25 = new wxBoxSizer( wxVERTICAL ); + + m_insertBlankOnSpace = new wxRadioButton( this, wxID_ANY, wxT("Insert a blank"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer25->Add( m_insertBlankOnSpace, 0, wxLEFT|wxRIGHT|wxTOP, 5 ); + + m_switchDirectionsOnSpace = new wxRadioButton( this, wxID_ANY, wxT("Switch directions"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer25->Add( m_switchDirectionsOnSpace, 0, wxLEFT|wxRIGHT|wxTOP, 5 ); + + + bSizer12->Add( bSizer25, 1, wxLEFT, 25 ); + m_blankOnDirection = new wxCheckBox( this, wxID_ANY, wxT("Move to blank after switching direction"), wxDefaultPosition, wxDefaultSize, 0 ); m_blankOnDirection->SetValue(true); bSizer12->Add( m_blankOnDirection, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); diff --git a/src/dialogs/wxFB_PreferencesPanelsOSX.fbp b/src/dialogs/wxFB_PreferencesPanelsOSX.fbp index 8d2c0ba2..7dbdc1a9 100644 --- a/src/dialogs/wxFB_PreferencesPanelsOSX.fbp +++ b/src/dialogs/wxFB_PreferencesPanelsOSX.fbp @@ -629,7 +629,7 @@ OnMoveAfterLetter - + 25 wxLEFT 0 @@ -768,6 +768,206 @@ + + 5 + wxLEFT|wxRIGHT|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + When pressing space + 0 + + 0 + + + 0 + + 1 + m_staticText16 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 25 + wxLEFT + 1 + + + bSizer25 + wxVERTICAL + none + + 5 + wxLEFT|wxRIGHT|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Insert a blank + + 0 + + + 0 + + 1 + m_insertBlankOnSpace + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + 5 + wxLEFT|wxRIGHT|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Switch directions + + 0 + + + 0 + + 1 + m_switchDirectionsOnSpace + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + 5 wxTOP|wxRIGHT|wxLEFT diff --git a/src/dialogs/wxFB_PreferencesPanelsOSX.h b/src/dialogs/wxFB_PreferencesPanelsOSX.h index 0361dba4..b7789060 100644 --- a/src/dialogs/wxFB_PreferencesPanelsOSX.h +++ b/src/dialogs/wxFB_PreferencesPanelsOSX.h @@ -46,6 +46,9 @@ class wxFB_SolvePanel : public wxPanel wxCheckBox* m_moveAfterLetter; wxRadioButton* m_nextSquare; wxRadioButton* m_nextBlank; + wxStaticText* m_staticText16; + wxRadioButton* m_insertBlankOnSpace; + wxRadioButton* m_switchDirectionsOnSpace; wxCheckBox* m_blankOnDirection; wxCheckBox* m_blankOnNewWord; wxCheckBox* m_pauseOnSwitch; From 6c723b1c87d21b643c388470b2a4707666ef03eb Mon Sep 17 00:00:00 2001 From: Holly McFarland Date: Wed, 22 Sep 2021 15:34:26 -0400 Subject: [PATCH 3/3] Factor out function for determining 'opposite' of current focus direction --- src/XGridCtrl.cpp | 54 +++++++++++++++++++++++++---------------------- src/XGridCtrl.hpp | 2 ++ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/XGridCtrl.cpp b/src/XGridCtrl.cpp index 64a07016..e4302c0b 100644 --- a/src/XGridCtrl.cpp +++ b/src/XGridCtrl.cpp @@ -620,6 +620,32 @@ XGridCtrl::DrawSquare(wxDC & dc, const puz::Square & square, const wxColour & co //------------------------------------------------------- // Focus functions //------------------------------------------------------- +short +XGridCtrl::OppositeFocusDirection(puz::Square * square, + puz::Word * word, + short direction) +{ + if (GetGrid()->IsAcrostic()) + { + direction = puz::ACROSS; + } + else + { + puz::GridDirection newdir + = puz::IsVertical(direction) ? puz::ACROSS : puz::DOWN; + if (square->HasWord(newdir)) + direction = newdir; + else + { + word = m_puz->FindWord(square, newdir); + if (word) + direction = newdir; + } + } + + return direction; +} + puz::Square * XGridCtrl::SetFocusedSquare(puz::Square * square, puz::Word * word, @@ -644,23 +670,7 @@ XGridCtrl::SetFocusedSquare(puz::Square * square, else if (! square->HasWord(static_cast(direction)) && ! m_puz->FindWord(square, direction)) { - if (GetGrid()->IsAcrostic()) - { - direction = puz::ACROSS; - } - else - { - puz::GridDirection newdir - = puz::IsVertical(direction) ? puz::ACROSS : puz::DOWN; - if (square->HasWord(newdir)) - direction = newdir; - else - { - word = m_puz->FindWord(square, newdir); - if (word) - direction = newdir; - } - } + direction = OppositeFocusDirection(square, word, direction); } } // Save old state @@ -1548,14 +1558,8 @@ XGridCtrl::OnLetter(wxChar key, int mod) { if (HasStyle(SWAP_ON_SPACE)) { - if (m_focusedDirection == puz::ACROSS) - { - SetFocusedSquare(m_focusedSquare, NULL, puz::DOWN); - } - else - { - SetFocusedSquare(m_focusedSquare, NULL, puz::ACROSS); - } + const short direction = OppositeFocusDirection(m_focusedSquare, NULL, m_focusedDirection); + SetFocusedSquare(m_focusedSquare, NULL, direction); } else { diff --git a/src/XGridCtrl.hpp b/src/XGridCtrl.hpp index 56e3c9c9..78e0c4f7 100644 --- a/src/XGridCtrl.hpp +++ b/src/XGridCtrl.hpp @@ -169,6 +169,8 @@ class XGridCtrl bool UnscrambleSolution(unsigned short key); + short OppositeFocusDirection(puz::Square* square, puz::Word * word, short direction); + // Set* functions trigger an event. // Move* functions check BLANK_ON_NEW_WORD // Essentially this is SetFocusedSquare([square, ][word, ][direction])