Skip to content

Commit

Permalink
Add "When space is pressed, switch direction" control in preference d…
Browse files Browse the repository at this point in the history
…ialog

As opposed to default "insert a blank"
  • Loading branch information
undergroundmonorail committed Sep 21, 2021
1 parent 1960e5d commit 7f0b1f0
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 13 deletions.
29 changes: 27 additions & 2 deletions src/XGridCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,15 +1545,40 @@ XGridCtrl::OnLetter(wxChar key, int mod)
wxASSERT(! IsRebusEntry());

if (static_cast<int>(key) == WXK_SPACE)
SetSquareText(*m_focusedSquare, _T(""));
{
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<int>(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();
}
}


Expand Down
2 changes: 2 additions & 0 deletions src/XGridCtrl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -71,6 +72,7 @@ enum GridStyle
| CHECK_WHILE_TYPING
| STRICT_REBUS
| SWAP_ON_DCLICK
| SWAP_ON_SPACE
};

enum CorrectStatus
Expand Down
20 changes: 14 additions & 6 deletions src/dialogs/PreferencesPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,16 @@ void SolvePanel::DoLoadConfig()
m_nextBlank->SetValue(1);
else
m_nextSquare->SetValue(1);
m_blankOnDirection->SetValue((gridStyle & BLANK_ON_DIRECTION) != 0);
m_blankOnNewWord ->SetValue((gridStyle & BLANK_ON_NEW_WORD) != 0);
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);
m_checkWhileTyping->SetValue((gridStyle & CHECK_WHILE_TYPING) != 0);
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);
m_checkWhileTyping ->SetValue((gridStyle & CHECK_WHILE_TYPING) != 0);
m_strictRebus->SetValue((gridStyle & STRICT_REBUS) != 0);

// Timer
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions src/dialogs/wxFB_PreferencesPanels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Loading

0 comments on commit 7f0b1f0

Please sign in to comment.