diff --git a/src/game_tab/left_panel/GameTabLeftPanel.cpp b/src/game_tab/left_panel/GameTabLeftPanel.cpp index d1604e4..c5bf8ae 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.cpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.cpp @@ -4,9 +4,13 @@ GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr 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) 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){ diff --git a/src/game_tab/left_panel/GameTabLeftPanel.hpp b/src/game_tab/left_panel/GameTabLeftPanel.hpp index d254ace..25cbcf0 100644 --- a/src/game_tab/left_panel/GameTabLeftPanel.hpp +++ b/src/game_tab/left_panel/GameTabLeftPanel.hpp @@ -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); @@ -27,4 +28,5 @@ public: void OnSwap(wxCommandEvent &event); void OnRefreshBoard(wxCommandEvent &event); void ApplyPreferences(); + void OnToolClick(wxCommandEvent &event); }; \ No newline at end of file diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index 0d75c62..47b7661 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -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 captures) { + std::map 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) { diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp index d3ce5c4..2ea44ae 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.hpp +++ b/src/game_tab/left_panel/board/BoardCanvas.hpp @@ -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 captures); + std::map captures, + std::string white_player, std::string black_player); void Animate(const std::string &board, bool is_black_turn, std::map captures, std::string src, std::string dst,bool faster); void SetClockTime(short hours, short min, short sec, bool IsBlack); DECLARE_EVENT_TABLE() diff --git a/src/gui.cpp b/src/gui.cpp index de87bcc..4702692 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -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 ); diff --git a/src/gui.h b/src/gui.h index 705c8a7..3380e02 100644 --- a/src/gui.h +++ b/src/gui.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -258,6 +259,7 @@ class TabGameLeftPanel : public wxPanel protected: wxBoxSizer* main_sizer; + wxToolBar* game_toolbar; wxBitmapButton* zoomin_button; wxBitmapButton* zoomout_button; wxBitmapButton* swap_button; diff --git a/tools/wxFrameBuilder.fbp b/tools/wxFrameBuilder.fbp index 40e735f..ab8d3d3 100644 --- a/tools/wxFrameBuilder.fbp +++ b/tools/wxFrameBuilder.fbp @@ -3739,6 +3739,68 @@ main_sizer wxVERTICAL protected + + 5 + wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + + 0 + + + 0 + + 1 + game_toolbar + 1 + 1 + + + protected + 1 + + Resizable + 5 + 1 + + wxTB_HORIZONTAL + ; ; forward_declare + 0 + + + + + + 5 wxEXPAND @@ -4035,7 +4097,7 @@ - + 0 wxAUI_MGR_DEFAULT @@ -4058,16 +4120,16 @@ wxTAB_TRAVERSAL - + main_sizer wxVERTICAL none - + 5 wxEXPAND | wxALL 1 - + 1 1 1 @@ -4120,11 +4182,11 @@ - + Editor 0 - + 1 1 1 @@ -4175,7 +4237,7 @@ wxTAB_TRAVERSAL - + editor_page_sizer wxVERTICAL @@ -4374,11 +4436,11 @@ - + 5 wxEXPAND | wxALL 1 - + 1 1 1