mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Improve BoardCanvas
This commit is contained in:
parent
b97dedf9f1
commit
8703e306f7
2 changed files with 20 additions and 3 deletions
|
@ -74,6 +74,7 @@ void BoardCanvas::OnPaint(wxPaintEvent &event) {
|
||||||
// Setting up required attributes
|
// Setting up required attributes
|
||||||
REFRESH_MOUSE_LOCATION();
|
REFRESH_MOUSE_LOCATION();
|
||||||
square_width = t->GetSquaresSizes();
|
square_width = t->GetSquaresSizes();
|
||||||
|
piece_width = t->GetPiecesSizes();
|
||||||
canvas_size = this->GetSize();
|
canvas_size = this->GetSize();
|
||||||
boardX = (canvas_size.x - (8 * square_width)) / 2;
|
boardX = (canvas_size.x - (8 * square_width)) / 2;
|
||||||
boardY = (canvas_size.y - (8 * square_width)) / 2;
|
boardY = (canvas_size.y - (8 * square_width)) / 2;
|
||||||
|
@ -132,6 +133,7 @@ void BoardCanvas::SetupBoard(const GameState &new_gs) {
|
||||||
gs.mat_black=new_gs.mat_black;
|
gs.mat_black=new_gs.mat_black;
|
||||||
gs.black_time=new_gs.black_time;
|
gs.black_time=new_gs.black_time;
|
||||||
gs.white_time=new_gs.white_time;
|
gs.white_time=new_gs.white_time;
|
||||||
|
gs.squares_hl=new_gs.squares_hl;
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +148,6 @@ void BoardCanvas::Animate(const GameState &new_gs, const std::string &src, const
|
||||||
DrawBoard(memDC);
|
DrawBoard(memDC);
|
||||||
|
|
||||||
// Now compute piece start position and translation vector
|
// Now compute piece start position and translation vector
|
||||||
std::uint32_t piece_width = t->GetPiecesSizes();
|
|
||||||
std::uint32_t centrer_offset = (square_width - piece_width) / 2;
|
std::uint32_t centrer_offset = (square_width - piece_width) / 2;
|
||||||
if (!black_side) {
|
if (!black_side) {
|
||||||
prank = 7 - prank;
|
prank = 7 - prank;
|
||||||
|
@ -192,7 +193,6 @@ void BoardCanvas::Animate(const GameState &new_gs, const std::string &src, const
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoardCanvas::DrawBoard(wxDC &dc) {
|
void BoardCanvas::DrawBoard(wxDC &dc) {
|
||||||
std::uint32_t piece_width = t->GetPiecesSizes();
|
|
||||||
std::uint32_t centrer_offset = (square_width - piece_width) / 2;
|
std::uint32_t centrer_offset = (square_width - piece_width) / 2;
|
||||||
wxSize numbers_size=dc.GetTextExtent("0");
|
wxSize numbers_size=dc.GetTextExtent("0");
|
||||||
|
|
||||||
|
@ -221,6 +221,21 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw highlighted squares
|
||||||
|
for(const std::string &s:gs.squares_hl){
|
||||||
|
std::uint8_t srank = s[0]-'a';
|
||||||
|
std::uint8_t sfile = s[1]-'1';
|
||||||
|
if (!black_side) {
|
||||||
|
srank = 7 - srank;
|
||||||
|
sfile = 7 - sfile;
|
||||||
|
}
|
||||||
|
if(srank == rank && sfile==file){
|
||||||
|
dc.SetPen(wxPen(*wxWHITE, 1));
|
||||||
|
dc.SetBrush(wxColour(255,0,0,100));
|
||||||
|
dc.DrawRectangle(wxRect(x,y,square_width,square_width));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Draw numbers
|
// Draw numbers
|
||||||
dc.SetFont(wxFont(*wxNORMAL_FONT).MakeBold());
|
dc.SetFont(wxFont(*wxNORMAL_FONT).MakeBold());
|
||||||
if(file==7){ // Right numbers
|
if(file==7){ // Right numbers
|
||||||
|
|
|
@ -34,6 +34,7 @@ wxDECLARE_EVENT(PLAY_MOVE_EVENT, wxCommandEvent);
|
||||||
|
|
||||||
#define CAPTURE_FACTOR 0.35
|
#define CAPTURE_FACTOR 0.35
|
||||||
#define SQUARE_NUM_PADDING 5
|
#define SQUARE_NUM_PADDING 5
|
||||||
|
|
||||||
typedef std::tuple<short, short, short> ClockTime;
|
typedef std::tuple<short, short, short> ClockTime;
|
||||||
|
|
||||||
// Drawing buffer (ANIMATIONS)
|
// Drawing buffer (ANIMATIONS)
|
||||||
|
@ -62,6 +63,7 @@ typedef struct GameState {
|
||||||
std::string white, black;
|
std::string white, black;
|
||||||
std::string board;
|
std::string board;
|
||||||
std::map<char, std::uint8_t> captures;
|
std::map<char, std::uint8_t> captures;
|
||||||
|
std::vector<std::string> squares_hl;
|
||||||
bool is_black_turn;
|
bool is_black_turn;
|
||||||
bool mat_black;
|
bool mat_black;
|
||||||
bool mat_white;
|
bool mat_white;
|
||||||
|
@ -78,7 +80,7 @@ class BoardCanvas : public wxPanel {
|
||||||
|
|
||||||
// Various canvas state variables
|
// Various canvas state variables
|
||||||
bool black_side, is_dragging, valid_drag, is_black_turn;
|
bool black_side, is_dragging, valid_drag, is_black_turn;
|
||||||
std::uint32_t boardX, boardY, square_width, mouseX, mouseY, lastClickX,
|
std::uint32_t boardX, boardY, square_width, piece_width, mouseX, mouseY, lastClickX,
|
||||||
lastClickY;
|
lastClickY;
|
||||||
wxSize canvas_size;
|
wxSize canvas_size;
|
||||||
wxPoint active_square;
|
wxPoint active_square;
|
||||||
|
|
Loading…
Add table
Reference in a new issue