unsigned CharacterButton::GetUpperCharacter() const { unsigned result = character; if (result < 0x80 && IsLowerAlphaASCII((TCHAR)result)) result -= 'a' - 'A'; return result; }
void KeyboardWidget::UpdateShiftState() { if (show_shift_button) shift_button.SetCaption(shift_state ? _T("v") : _T("^")); for (unsigned i = 0; i < num_buttons; ++i) { unsigned uch = buttons[i].GetCharacter(); if (uch < 0x80) { char ch = char(uch); if (shift_state) { if (IsLowerAlphaASCII(ch)) buttons[i].SetCharacter(ch - 0x20); } else { if (IsUpperAlphaASCII(ch)) buttons[i].SetCharacter(ch + 0x20); } } } }
void KeyboardWidget::OnShiftClicked() { assert(shift_button != nullptr); shift_state = !shift_state; shift_button->SetCaption(shift_state ? _T("v") : _T("^")); for (unsigned i = 0; i < num_buttons; ++i) { unsigned uch = buttons[i].GetCharacter(); if (uch < 0x80) { char ch = char(uch); if (shift_state) { if (IsLowerAlphaASCII(ch)) buttons[i].SetCharacter(ch - 0x20); } else { if (IsUpperAlphaASCII(ch)) buttons[i].SetCharacter(ch + 0x20); } } } }
constexpr static inline bool IsAlphaASCII(char ch) { return IsUpperAlphaASCII(ch) || IsLowerAlphaASCII(ch); }