mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-07-01 17:57:40 +00:00
Improve UI
This commit is contained in:
parent
2fd237a78f
commit
98e31a2c11
7 changed files with 116 additions and 16 deletions
|
@ -4,9 +4,13 @@
|
|||
GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
|
||||
: TabGameLeftPanel(parent), game(game), repeat(false) {
|
||||
|
||||
// Configure toolbal
|
||||
game_toolbar->AddTool(0, wxT("Exit application"),
|
||||
wxArtProvider::GetBitmap(wxART_FILE_SAVE, wxART_TOOLBAR));
|
||||
|
||||
// Add board
|
||||
board_canvas = new BoardCanvas((wxFrame *)this);
|
||||
main_sizer->Insert(0, board_canvas, 1, wxEXPAND);
|
||||
main_sizer->Insert(1, board_canvas, 1, wxEXPAND);
|
||||
|
||||
// Configure buttons
|
||||
swap_button->SetBitmapLabel(LoadPNG("swap"));
|
||||
|
@ -22,6 +26,16 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
|
|||
Bind(wxEVT_BUTTON, &GameTabLeftPanel::OnZoomOut, this, ZOOM_OUT_BTN);
|
||||
Bind(wxEVT_KEY_DOWN, [p=this](wxKeyEvent &e){e.ResumePropagation(1);e.Skip();});
|
||||
Bind(wxEVT_KEY_UP, [p=this](wxKeyEvent &e){e.ResumePropagation(1);e.Skip();});
|
||||
game_toolbar->Bind(wxEVT_TOOL,&GameTabLeftPanel::OnToolClick,this);
|
||||
}
|
||||
|
||||
void GameTabLeftPanel::OnToolClick(wxCommandEvent &event){
|
||||
short id=event.GetId();
|
||||
if(id==0){
|
||||
if(related_file.size()>0){
|
||||
// Todo implement save file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameTabLeftPanel::PreviousMove(bool isKeyDown) {
|
||||
|
@ -90,7 +104,8 @@ void GameTabLeftPanel::Notify(bool animate, bool backward) {
|
|||
last_absolute_move=m->GetAbsoluteMove();
|
||||
}
|
||||
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
|
||||
game->IsBlackToPlay(), captures);
|
||||
game->IsBlackToPlay(), captures,
|
||||
game->GetTag("White"),game->GetTag("Black"));
|
||||
}
|
||||
else{
|
||||
if(backward && last_absolute_move.size()>0){
|
||||
|
|
|
@ -14,6 +14,7 @@ class GameTabLeftPanel : public TabGameLeftPanel {
|
|||
void NotifyEditor();
|
||||
std::string last_absolute_move;
|
||||
bool repeat;
|
||||
std::string related_file;
|
||||
|
||||
public:
|
||||
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
|
||||
|
@ -27,4 +28,5 @@ public:
|
|||
void OnSwap(wxCommandEvent &event);
|
||||
void OnRefreshBoard(wxCommandEvent &event);
|
||||
void ApplyPreferences();
|
||||
void OnToolClick(wxCommandEvent &event);
|
||||
};
|
|
@ -75,7 +75,7 @@ void BoardCanvas::OnPaint(wxPaintEvent &event) {
|
|||
adata.frame++;
|
||||
if(adata.frame>=adata.frames){
|
||||
adata.reuseBuffer=false;
|
||||
SetupBoard(adata.final_board, adata.final_is_black_turn, adata.final_captures);
|
||||
SetupBoard(adata.final_board, adata.final_is_black_turn, adata.final_captures,white_player,black_player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,10 +103,13 @@ void BoardCanvas::ApplyPreferences() {
|
|||
}
|
||||
|
||||
void BoardCanvas::SetupBoard(std::string board, bool is_black_turn,
|
||||
std::map<char, std::uint8_t> captures) {
|
||||
std::map<char, std::uint8_t> captures,
|
||||
std::string white_player, std::string black_player) {
|
||||
this->board = board;
|
||||
this->is_black_turn = is_black_turn;
|
||||
this->captures = captures;
|
||||
this->white_player=white_player;
|
||||
this->black_player=black_player;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
@ -208,8 +211,9 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
|
|||
if(rank==7){ // Bottom numbers
|
||||
dc.DrawText(wxString((char)('a'+7-file)),
|
||||
x+square_width/2-numbers_size.x/2,y+square_width);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw pieces
|
||||
std::uint8_t prank = rank;
|
||||
std::uint8_t pfile = file;
|
||||
if (black_side) {
|
||||
|
@ -252,13 +256,16 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
|
|||
badgeWidth);
|
||||
dc.DrawRectangle(badge);
|
||||
|
||||
// Draw captures first for white then for black
|
||||
// Draw captures (+player names) first for white then for black
|
||||
std::uint32_t captures_size = t_captures->GetPiecesSizes();
|
||||
std::uint8_t padding = numbers_size.y+10;
|
||||
std::uint32_t offsetX = 0;
|
||||
std::uint32_t offsetY = -(captures_size + padding);
|
||||
std::uint32_t offsetYPlayerName=offsetY-captures_size;
|
||||
// White
|
||||
if (black_side) {
|
||||
offsetY = 8 * square_width + padding;
|
||||
offsetYPlayerName = offsetY+captures_size;
|
||||
}
|
||||
for (char p : {'P', 'N', 'B', 'R', 'Q'}) {
|
||||
if (captures.find(p) != captures.end()) {
|
||||
|
@ -269,11 +276,15 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
|
|||
offsetX += captures_size / 2;
|
||||
}
|
||||
}
|
||||
dc.DrawText(wxString(black_player),boardX,boardY + offsetYPlayerName);
|
||||
// Black
|
||||
offsetX = 0;
|
||||
if (black_side) {
|
||||
offsetY = -(captures_size + padding);
|
||||
offsetYPlayerName = offsetY-captures_size;
|
||||
} else {
|
||||
offsetY = 8 * square_width + padding;
|
||||
offsetYPlayerName = offsetY+captures_size;
|
||||
}
|
||||
for (char p : {'p', 'n', 'b', 'r', 'q'}) {
|
||||
if (captures.find(p) != captures.end()) {
|
||||
|
@ -284,6 +295,7 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
|
|||
offsetX += captures_size / 2;
|
||||
}
|
||||
}
|
||||
dc.DrawText(wxString(white_player),boardX,boardY + offsetYPlayerName);
|
||||
|
||||
// Draw dragging piece
|
||||
if (DrawDraggingPiece) {
|
||||
|
|
|
@ -74,6 +74,7 @@ class BoardCanvas : public wxPanel {
|
|||
Theme *t, *t_captures;
|
||||
// Board to draw (char version)
|
||||
std::string board;
|
||||
std::string white_player,black_player;
|
||||
|
||||
// Various canvas state variables
|
||||
bool black_side, is_dragging, valid_drag, is_black_turn;
|
||||
|
@ -99,7 +100,8 @@ public:
|
|||
void Zoom(std::int32_t zoom);
|
||||
void Swap();
|
||||
void SetupBoard(std::string board, bool is_black_turn,
|
||||
std::map<char, std::uint8_t> captures);
|
||||
std::map<char, std::uint8_t> captures,
|
||||
std::string white_player, std::string black_player);
|
||||
void Animate(const std::string &board, bool is_black_turn, std::map<char, std::uint8_t> captures, std::string src, std::string dst,bool faster);
|
||||
void SetClockTime(short hours, short min, short sec, bool IsBlack);
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
|
|
@ -392,6 +392,11 @@ TabGameLeftPanel::TabGameLeftPanel( wxWindow* parent, wxWindowID id, const wxPoi
|
|||
{
|
||||
main_sizer = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
game_toolbar = new wxToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL );
|
||||
game_toolbar->Realize();
|
||||
|
||||
main_sizer->Add( game_toolbar, 0, wxEXPAND, 5 );
|
||||
|
||||
wxBoxSizer* bar_sizer;
|
||||
bar_sizer = new wxBoxSizer( wxHORIZONTAL );
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <wx/checkbox.h>
|
||||
#include <wx/splitter.h>
|
||||
#include <wx/notebook.h>
|
||||
#include <wx/toolbar.h>
|
||||
#include <wx/bmpbuttn.h>
|
||||
#include <wx/combobox.h>
|
||||
|
||||
|
@ -258,6 +259,7 @@ class TabGameLeftPanel : public wxPanel
|
|||
|
||||
protected:
|
||||
wxBoxSizer* main_sizer;
|
||||
wxToolBar* game_toolbar;
|
||||
wxBitmapButton* zoomin_button;
|
||||
wxBitmapButton* zoomout_button;
|
||||
wxBitmapButton* swap_button;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue