mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-23 03:32:32 +00:00
Merge pull request #466 from TomHarte/CPCKeyboard
Improves key state handling under SDL when switching to/from full screen
This commit is contained in:
commit
1172c4fd97
@ -546,14 +546,14 @@ class KeyboardState: public GI::AY38910::PortHandler {
|
||||
Sets the row currently being reported to the AY.
|
||||
*/
|
||||
void set_row(int row) {
|
||||
row_ = row;
|
||||
row_ = static_cast<size_t>(row);
|
||||
}
|
||||
|
||||
/*!
|
||||
Reports the state of the currently-selected row as Port A to the AY.
|
||||
*/
|
||||
uint8_t get_port_input(bool port_b) {
|
||||
if(!port_b && row_ < 10) {
|
||||
if(!port_b && row_ < sizeof(rows_)) {
|
||||
return rows_[row_];
|
||||
}
|
||||
|
||||
@ -565,7 +565,7 @@ class KeyboardState: public GI::AY38910::PortHandler {
|
||||
*/
|
||||
void set_is_pressed(bool is_pressed, int line, int key) {
|
||||
int mask = 1 << key;
|
||||
assert(line < 10);
|
||||
assert(static_cast<size_t>(line) < sizeof(rows_));
|
||||
if(is_pressed) rows_[line] &= ~mask; else rows_[line] |= mask;
|
||||
}
|
||||
|
||||
@ -573,12 +573,12 @@ class KeyboardState: public GI::AY38910::PortHandler {
|
||||
Sets all keys as currently unpressed.
|
||||
*/
|
||||
void clear_all_keys() {
|
||||
memset(rows_, 0xff, 10);
|
||||
memset(rows_, 0xff, sizeof(rows_));
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t rows_[10];
|
||||
int row_;
|
||||
size_t row_;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -461,6 +461,12 @@ int main(int argc, char *argv[]) {
|
||||
fullscreen_mode ^= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
SDL_SetWindowFullscreen(window, fullscreen_mode);
|
||||
SDL_ShowCursor((fullscreen_mode&SDL_WINDOW_FULLSCREEN_DESKTOP) ? SDL_DISABLE : SDL_ENABLE);
|
||||
|
||||
// Announce a potential discontinuity in keyboard input.
|
||||
auto keyboard_machine = machine->keyboard_machine();
|
||||
if(keyboard_machine) {
|
||||
keyboard_machine->get_keyboard().reset_all_keys();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user