change command line entry from home-grown SDL to standard wx text dlg input

This commit is contained in:
Christopher A. Mosher 2022-12-12 22:34:13 -05:00
parent 498edf22e1
commit a5c0fc047e
6 changed files with 37 additions and 87 deletions

View File

@ -28,7 +28,7 @@
#include "e2const.h" #include "e2const.h"
#include <wx/app.h> #include <wx/app.h>
#include <wx/uiaction.h> #include <wx/textdlg.h>
#include <wx/window.h> #include <wx/window.h>
#include <wx/xrc/xmlres.h> #include <wx/xrc/xmlres.h>
#include <wx/fileconf.h> #include <wx/fileconf.h>
@ -213,7 +213,7 @@ void E2wxApp::OnFnKeyPressed(const SDL_Keycode k) {
} else if (k == SDLK_F4) { } else if (k == SDLK_F4) {
// //
} else if (k == SDLK_F5) { } else if (k == SDLK_F5) {
// this->EmulatorCommand();
} else if (k == SDLK_F6) { } else if (k == SDLK_F6) {
this->Reset(); this->Reset();
} else if (k == SDLK_F7) { } else if (k == SDLK_F7) {
@ -446,3 +446,14 @@ void E2wxApp::ToggleFullScreen() {
this->emu->toggleFullScreen(); this->emu->toggleFullScreen();
} }
} }
static const wxString message = "Enter a command for the emulator. See https://cmosher01.github.io/Epple-II/usermanual.html";
static const wxString title = "Emulator command";
void E2wxApp::EmulatorCommand() {
if (this->emu) {
wxTextEntryDialog dlg(this->frame, message, title);
if (dlg.ShowModal() == wxID_OK) {
this->emu->cmd(dlg.GetValue());
}
}
}

View File

@ -95,6 +95,7 @@ public:
void TogglePower(); void TogglePower();
void ToggleBuffered(); void ToggleBuffered();
void ToggleFullScreen(); void ToggleFullScreen();
void EmulatorCommand();
virtual bool OnInit() override; virtual bool OnInit() override;
virtual int OnExit() override; virtual int OnExit() override;

View File

@ -33,6 +33,7 @@ enum E2MenuID {
ID_MENUITEM_POWER = wxID_HIGHEST+1, ID_MENUITEM_POWER = wxID_HIGHEST+1,
ID_MENUITEM_CYCLE_MONITOR, ID_MENUITEM_CYCLE_MONITOR,
ID_MENUITEM_TOGGLE_FULL_SCREEN, ID_MENUITEM_TOGGLE_FULL_SCREEN,
ID_MENUITEM_EMULATOR_COMMAND,
ID_MENUITEM_RESET, ID_MENUITEM_RESET,
ID_MENUITEM_SCREEN_SHOT, ID_MENUITEM_SCREEN_SHOT,
ID_MENUITEM_TOGGLE_BUFFERED, ID_MENUITEM_TOGGLE_BUFFERED,
@ -46,6 +47,7 @@ wxBEGIN_EVENT_TABLE(E2wxFrame, wxFrame)
EVT_MENU(ID_MENUITEM_POWER, E2wxFrame::OnTogglePower) EVT_MENU(ID_MENUITEM_POWER, E2wxFrame::OnTogglePower)
EVT_MENU(ID_MENUITEM_CYCLE_MONITOR, E2wxFrame::OnCycleMonitor) EVT_MENU(ID_MENUITEM_CYCLE_MONITOR, E2wxFrame::OnCycleMonitor)
EVT_MENU(ID_MENUITEM_TOGGLE_FULL_SCREEN, E2wxFrame::OnToggleFullScreen) EVT_MENU(ID_MENUITEM_TOGGLE_FULL_SCREEN, E2wxFrame::OnToggleFullScreen)
EVT_MENU(ID_MENUITEM_EMULATOR_COMMAND, E2wxFrame::OnEmulatorCommand)
EVT_MENU(ID_MENUITEM_RESET, E2wxFrame::OnReset) EVT_MENU(ID_MENUITEM_RESET, E2wxFrame::OnReset)
EVT_MENU(wxID_PASTE, E2wxFrame::OnPaste) EVT_MENU(wxID_PASTE, E2wxFrame::OnPaste)
EVT_MENU(ID_MENUITEM_SCREEN_SHOT, E2wxFrame::OnScreenShot) EVT_MENU(ID_MENUITEM_SCREEN_SHOT, E2wxFrame::OnScreenShot)
@ -97,6 +99,9 @@ void E2wxFrame::InitMenuBar() {
wxMenuItem *miReset = menuMachine->Append(ID_MENUITEM_RESET, "Reset"); wxMenuItem *miReset = menuMachine->Append(ID_MENUITEM_RESET, "Reset");
miReset->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F6)); miReset->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F6));
menuMachine->AppendSeparator(); menuMachine->AppendSeparator();
wxMenuItem *miCmd = menuMachine->Append(ID_MENUITEM_EMULATOR_COMMAND, "Command...");
miCmd->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F5));
menuMachine->AppendSeparator();
wxMenuItem *miBuffered = menuMachine->Append(ID_MENUITEM_TOGGLE_BUFFERED, "Toggle Keyboard Buffer"); wxMenuItem *miBuffered = menuMachine->Append(ID_MENUITEM_TOGGLE_BUFFERED, "Toggle Keyboard Buffer");
miBuffered->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F12)); miBuffered->SetAccel(new wxAcceleratorEntry(wxACCEL_NORMAL, WXK_F12));
@ -170,6 +175,10 @@ void E2wxFrame::OnToggleFullScreen(wxCommandEvent& event) {
wxGetApp().ToggleFullScreen(); wxGetApp().ToggleFullScreen();
} }
void E2wxFrame::OnEmulatorCommand(wxCommandEvent& event) {
wxGetApp().EmulatorCommand();
}
void E2wxFrame::OnReset(wxCommandEvent& event) { void E2wxFrame::OnReset(wxCommandEvent& event) {
wxGetApp().Reset(); wxGetApp().Reset();
} }
@ -185,5 +194,3 @@ void E2wxFrame::OnScreenShot(wxCommandEvent& event) {
void E2wxFrame::OnToggleBuffered(wxCommandEvent& event) { void E2wxFrame::OnToggleBuffered(wxCommandEvent& event) {
wxGetApp().ToggleBuffered(); wxGetApp().ToggleBuffered();
} }

View File

@ -45,6 +45,7 @@ private:
void OnTogglePower(wxCommandEvent& event); void OnTogglePower(wxCommandEvent& event);
void OnCycleMonitor(wxCommandEvent& event); void OnCycleMonitor(wxCommandEvent& event);
void OnToggleFullScreen(wxCommandEvent& event); void OnToggleFullScreen(wxCommandEvent& event);
void OnEmulatorCommand(wxCommandEvent& event);
void OnReset(wxCommandEvent& event); void OnReset(wxCommandEvent& event);
void OnPaste(wxCommandEvent& event); void OnPaste(wxCommandEvent& event);
void OnScreenShot(wxCommandEvent& event); void OnScreenShot(wxCommandEvent& event);

View File

@ -51,9 +51,7 @@ Emulator::Emulator() :
timable(nullptr), // No ticked object (NULL pointer) timable(nullptr), // No ticked object (NULL pointer)
repeat(false), repeat(false),
keysDown(0), keysDown(0),
prev_ms(SDL_GetTicks()), prev_ms(SDL_GetTicks()) {
command(false),
pendingCommandExit(false) {
} }
Emulator::~Emulator() { Emulator::~Emulator() {
@ -106,29 +104,13 @@ void Emulator::handleAnyPendingEvents() {
wxGetApp().CloseMainFrame(); wxGetApp().CloseMainFrame();
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
// If we're collecting a command line for changing any // we're collecting keypresses for the keyboard
// of the configurables of the emulator... // emulation (and thus the Apple ][ emulation itself)
if (this->command) dispatchKeyDown(event.key);
cmdKey(event.key); // People who have too many press-releases should be referred to as "keyboards"
else
// ...else we're collecting keypresses for the keyboard
// emulation (and thus the Apple ][ emulation itself)
dispatchKeyDown(event.key);
// People who have too many press-releases should be referred to as "keyboards"
break; break;
case SDL_KEYUP: case SDL_KEYUP:
// If we're collecting a command line for changing any dispatchKeyUp(event.key);
// of the configurables of the emulator...
if (this->command) {
if (this->pendingCommandExit) {
this->command = false;
this->pendingCommandExit = false;
}
} else {
// ...else we're collecting keypresses for the keyboard
// emulation (and thus the Apple ][ emulation itself)
dispatchKeyUp(event.key);
}
break; break;
} }
} }
@ -234,7 +216,6 @@ static bool translateKeysToAppleModernized(SDL_Keycode keycode, SDL_Keymod modif
return false; return false;
} }
return true; return true;
} }
@ -258,10 +239,6 @@ void Emulator::dispatchKeyDown(const SDL_KeyboardEvent& keyEvent) {
this->repeat = true; this->repeat = true;
this->rept = CYCLES_PER_REPT; this->rept = CYCLES_PER_REPT;
return; return;
} else if (sym == SDLK_F5) { // TODO re-do user-entered command line
this->command = true;
this->screenImage.enterCommandMode();
return;
} else if (SDLK_F1 <= sym && sym <= SDLK_F12) { } else if (SDLK_F1 <= sym && sym <= SDLK_F12) {
wxGetApp().OnFnKeyPressed(sym); wxGetApp().OnFnKeyPressed(sym);
return; return;
@ -295,63 +272,19 @@ void Emulator::dispatchKeyUp(const SDL_KeyboardEvent& keyEvent) {
void Emulator::cmd(const wxString& c) {
// TODO redo command line handling if (c.empty()) {
// Collect and edit a command line typed at the bottom of the emulator window
void Emulator::cmdKey(const SDL_KeyboardEvent& keyEvent) {
SDL_Keycode sym = keyEvent.keysym.sym;
unsigned char key = (unsigned char) (sym & 0x7F);
if (sym == SDLK_RETURN) {
processCommand();
} else if (sym == SDLK_ESCAPE) {
cmdline.erase(cmdline.begin(), cmdline.end());
processCommand();
} else if (sym == SDLK_BACKSPACE) {
if (cmdline.length()) {
cmdline.erase(cmdline.end() - 1);
this->screenImage.backspaceCommand();
}
} else if (sym == SDLK_INSERT) {
std::string s = this->clip.getText();
for (unsigned int i = 0; i < s.length(); ++i) {
key = s[i];
if (key == '\n' || key == '\r') {
processCommand();
break;
} else {
cmdline += key;
this->screenImage.addkeyCommand(key);
}
}
} else if (key) {
cmdline += key;
this->screenImage.addkeyCommand(key);
}
}
// Process a command line typed at the bottom of the emulator window
void Emulator::processCommand() {
this->screenImage.exitCommandMode();
this->screenImage.drawPower(this->timable == &this->apple2);
this->pendingCommandExit = true;
if (cmdline.empty()) {
return; return;
} }
E2Command{}.parseLine(
E2Command{}.parseLine(cmdline, this->apple2.ram, this->apple2.rom, this->apple2.slts, this->apple2.revision, this->screenImage, this->apple2.cassetteIn, this->apple2.cassetteOut, NULL); c.c_str().AsChar(),
cmdline.erase(cmdline.begin(), cmdline.end()); this->apple2.ram, this->apple2.rom, this->apple2.slts, this->apple2.revision, this->screenImage, this->apple2.cassetteIn, this->apple2.cassetteOut, nullptr);
} }
static int askSave() { static int askSave() {
wxMessageDialog *dlg = new wxMessageDialog{ wxMessageDialog *dlg = new wxMessageDialog{
nullptr, nullptr,

View File

@ -28,6 +28,7 @@
#include "hypermode.h" #include "hypermode.h"
#include "clipboardhandler.h" #include "clipboardhandler.h"
#include <SDL.h> #include <SDL.h>
#include <wx/string.h>
class Timable; class Timable;
class E2Config; class E2Config;
@ -51,14 +52,9 @@ class Emulator {
int rept; int rept;
unsigned char lastKeyDown; unsigned char lastKeyDown;
Uint32 prev_ms; Uint32 prev_ms;
bool command;
bool pendingCommandExit;
std::string cmdline;
void dispatchKeyDown(const SDL_KeyboardEvent& keyEvent); void dispatchKeyDown(const SDL_KeyboardEvent& keyEvent);
void dispatchKeyUp(const SDL_KeyboardEvent& keyEvent); void dispatchKeyUp(const SDL_KeyboardEvent& keyEvent);
void cmdKey(const SDL_KeyboardEvent& keyEvent);
void processCommand();
void powerOnComputer(); void powerOnComputer();
void powerOffComputer(); void powerOffComputer();
@ -71,6 +67,7 @@ public:
void config(E2Config& cfg); void config(E2Config& cfg);
void tick50ms(); void tick50ms();
void cmd(const wxString& c);
bool isSafeToQuit(); bool isSafeToQuit();
void toggleComputerPower(); void toggleComputerPower();