Improve live engine dialog

This commit is contained in:
Loic Guegan 2022-02-27 17:02:21 +01:00
parent 0e18d4ac87
commit 40a56b72fe
6 changed files with 135 additions and 11 deletions

View file

@ -17,7 +17,7 @@ EditorPanel::EditorPanel(wxFrame *parent, Game *game)
tagTextCtrl->SetHint("Tag");
valueTextCtrl->SetHint("Value");
LiveEngineDialog *diag=new LiveEngineDialog(this);
LiveEngineDialog *diag=new LiveEngineDialog(this, "stockfish");
diag->Show();
RefreshTagsList();

View file

@ -1,7 +1,27 @@
#include "LiveEngineDialog.hpp"
LiveEngineDialog::LiveEngineDialog(wxWindow *parent)
: LiveEngineDialogFB(parent) {
lines_list->InsertColumn(0, "#");
lines_list->InsertColumn(1, "Moves",wxLIST_FORMAT_LEFT, 500);
}
LiveEngineDialog::LiveEngineDialog(wxWindow *parent, std::string engine_name)
: LiveEngineDialogFB(parent), engine_name(engine_name) {
lines_list->InsertColumn(0, "#", wxLIST_FORMAT_LEFT, 50);
lines_list->InsertColumn(1, "Moves", wxLIST_FORMAT_LEFT, 300);
current_engine->SetLabel(engine_name);
StartEngine();
Bind(wxEVT_BUTTON, &LiveEngineDialog::TogglePauseEngine, this, LIVE_ENGINE_PAUSE_BUTTON);
}
void LiveEngineDialog::StartEngine() {
timer.Start(1000);
timer.Bind(wxEVT_TIMER, &LiveEngineDialog::OnTimerTick, this);
}
void LiveEngineDialog::TogglePauseEngine(wxCommandEvent &event) {
if (timer.IsRunning()) {
timer.Stop();
engine_pause_button->SetLabel("Continue");
} else {
timer.Start(1000);
engine_pause_button->SetLabel("Pause");
}
}
void LiveEngineDialog::OnTimerTick(wxTimerEvent &event) { wxLogDebug("Tick!"); }

View file

@ -1,7 +1,16 @@
#include "ochess.hpp"
#include "LiveEngineDialogFB.h"
#include "UCI.hpp"
#include "ochess.hpp"
#include <wx/timer.h>
class LiveEngineDialog : public LiveEngineDialogFB {
uciadapter::UCI *engine;
std::string engine_name;
wxTimer timer;
public:
LiveEngineDialog(wxWindow *parent);
LiveEngineDialog(wxWindow *parent, std::string engine_name);
void StartEngine();
void TogglePauseEngine(wxCommandEvent &event);
void OnTimerTick(wxTimerEvent &event);
};

View file

@ -25,13 +25,19 @@ LiveEngineDialogFB::LiveEngineDialogFB( wxWindow* parent, wxWindowID id, const w
current_engine = new wxStaticText( this, wxID_ANY, wxT("???"), wxDefaultPosition, wxDefaultSize, 0 );
current_engine->Wrap( -1 );
current_engine_sizer->Add( current_engine, 0, wxALL, 5 );
current_engine_sizer->Add( current_engine, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
current_engine_sizer->Add( 0, 0, 1, wxEXPAND, 5 );
engine_pause_button = new wxButton( this, LIVE_ENGINE_PAUSE_BUTTON, wxT("Pause"), wxDefaultPosition, wxDefaultSize, 0 );
current_engine_sizer->Add( engine_pause_button, 0, wxALL, 5 );
main_sizer->Add( current_engine_sizer, 0, wxEXPAND, 5 );
lines_list = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT );
main_sizer->Add( lines_list, 0, wxALL|wxEXPAND, 5 );
main_sizer->Add( lines_list, 1, wxALL|wxEXPAND, 5 );
this->SetSizer( main_sizer );

View file

@ -15,12 +15,17 @@
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/button.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/sizer.h>
#include <wx/listctrl.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
#define LIVE_ENGINE_PAUSE_BUTTON 1000
///////////////////////////////////////////////////////////////////////////////
/// Class LiveEngineDialogFB
@ -32,6 +37,7 @@ class LiveEngineDialogFB : public wxDialog
protected:
wxStaticText* current_engine_label;
wxStaticText* current_engine;
wxButton* engine_pause_button;
wxListCtrl* lines_list;
public: