diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index 476b3aa..abe77c5 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -14,7 +14,6 @@ BoardCanvas::BoardCanvas(wxFrame *parent) ApplyPreferences(); // The following should be called when using an EVT_PAINT handler SetBackgroundStyle(wxBG_STYLE_PAINT); - //buffer=new wxBitmap(500,500,32); } BoardCanvas::~BoardCanvas() { @@ -35,6 +34,8 @@ void BoardCanvas::OnPaint(wxPaintEvent &event) { wxBufferedPaintDC dc(this); dc.SetBackground(*wxWHITE_BRUSH); dc.Clear(); + + // Setting up required attributes REFRESH_MOUSE_LOCATION(); square_width = t->GetSquaresSizes(); canvas_size = dc.GetSize(); @@ -44,15 +45,12 @@ void BoardCanvas::OnPaint(wxPaintEvent &event) { boardX = 0; if (boardY > canvas_size.y) boardY = 0; - DrawBoard(dc); - - // TODO: Make DrawBoard() drawing into wxMemoryDC! - /*wxMemoryDC dc2(*buffer); - dc2.SetBackgroundMode(wxTRANSPARENT); - dc2.SetPen(wxPen(*wxBLACK, 3)); - dc2.DrawRectangle(10,10,100,100); - dc.Blit(0, 0, 500,500, (wxDC*)&dc2,0,0);*/ + // Setup buffer (later use for animations) + buffer=new wxBitmap(canvas_size.x,canvas_size.y,32); + wxMemoryDC memDC(*buffer); + DrawBoard(memDC); + dc.Blit(0,0,canvas_size.x,canvas_size.y,(wxDC*)&memDC,0,0); } void BoardCanvas::ApplyPreferences() { @@ -85,7 +83,7 @@ void BoardCanvas::SetupBoard(std::string board, bool is_black_turn, Refresh(); } -void BoardCanvas::DrawBoard(wxBufferedPaintDC &dc) { +void BoardCanvas::DrawBoard(wxDC &dc) { std::uint32_t piece_width = t->GetPiecesSizes(); std::uint32_t centrer_offset = (square_width - piece_width) / 2; diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp index 4a610aa..ee3dc29 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.hpp +++ b/src/game_tab/left_panel/board/BoardCanvas.hpp @@ -41,8 +41,13 @@ wxDECLARE_EVENT(NEXT_MOVE_EVENT, wxCommandEvent); typedef std::tuple ClockTime; class BoardCanvas : public wxPanel { + // *t is theme for board+pieces and + // *t_captures is theme for captured pieces (scale down version of t) Theme *t, *t_captures; + // Board to draw (char version) std::string board; + + // Various canvas state variables bool black_side, is_dragging, valid_drag, is_black_turn; std::uint32_t boardX, boardY, square_width, mouseX, mouseY, lastClickX, lastClickY; @@ -52,6 +57,7 @@ class BoardCanvas : public wxPanel { ClockTime black_time, white_time; bool frozen,lock_square_size; + // Drawing buffer wxBitmap *buffer; public: @@ -59,7 +65,7 @@ public: BoardCanvas(wxFrame *parent,std::uint32_t square_width, bool frozen); ~BoardCanvas(); void ApplyPreferences(); - void DrawBoard(wxBufferedPaintDC &dc); + void DrawBoard(wxDC &dc); void OnPaint(wxPaintEvent &event); void OnKeyEvent(wxKeyEvent &event); void MouseEvent(wxMouseEvent &event); diff --git a/src/game_tab/right_panel/editor/EditorCanvas.cpp b/src/game_tab/right_panel/editor/EditorCanvas.cpp index 0e2f77a..870dd26 100644 --- a/src/game_tab/right_panel/editor/EditorCanvas.cpp +++ b/src/game_tab/right_panel/editor/EditorCanvas.cpp @@ -37,6 +37,7 @@ wxPoint EditorCanvas::Middle(cgeditor::Element e) { } void EditorCanvas::DrawElement(const cgeditor::Element &e) { + // TODO: Optimize brush!!!! Always instanciated at each call dc->SetPen(wxNullPen); dc->SetBrush(*wxRED_BRUSH); if (e.prop & cgeditor::Property::Rectangle) { @@ -45,7 +46,7 @@ void EditorCanvas::DrawElement(const cgeditor::Element &e) { } else if (e.prop & cgeditor::Property::Scrollbar) { dc->SetBrush(*wxGREY_BRUSH); } else if (e.prop & cgeditor::Property::Margin) { - dc->SetBrush(*wxLIGHT_GREY_BRUSH); + dc->SetBrush(wxBrush(wxColour(243,243,243))); } else if (e.prop & cgeditor::Property::Button) { if (e.prop & cgeditor::Property::On) { dc->DrawBitmap(hide_icon, e.x, e.y); @@ -77,25 +78,25 @@ void EditorCanvas::DrawElement(const cgeditor::Element &e) { } if (e.prop & cgeditor::Property::Current) { wxRect recToDraw(e.x, e.y, e.width, e.height); - dc->SetBrush(*wxLIGHT_GREY_BRUSH); + dc->SetBrush(wxBrush(wxColour(216, 216, 216))); dc->DrawRectangle(recToDraw); } dc->DrawBitmap(*t.Get(p), e.x, y); } else if (e.prop & cgeditor::Property::Comment) { wxRect recToDraw(e.x, e.y, e.width, e.height); - dc->SetBrush(*wxYELLOW_BRUSH); + dc->SetBrush(wxBrush(wxColour(255, 255, 204))); dc->DrawRectangle(recToDraw); dc->DrawText(wxString(e.text), wxPoint(e.x, e.y)); } else if (e.prop & cgeditor::Property::Menuitem) { wxRect recToDraw(e.x, e.y, e.width, e.height); - dc->SetBrush(*wxLIGHT_GREY_BRUSH); + dc->SetBrush(wxBrush(wxColour(216, 216, 216))); dc->DrawRectangle(recToDraw); dc->DrawText(wxString(e.text), wxPoint(e.x, Middle(e).y)); } else { if (e.prop & cgeditor::Property::Move) { if (e.prop & cgeditor::Property::Current) { wxRect recToDraw(e.x, e.y, e.width, e.height); - dc->SetBrush(*wxLIGHT_GREY_BRUSH); + dc->SetBrush(wxBrush(wxColour(216, 216, 216))); dc->DrawRectangle(recToDraw); } if (CGEditor::status.UseMoveIcons) {