mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-07-03 02:37:39 +00:00
Improve board canvas
This commit is contained in:
parent
dcf6c01e54
commit
29d5850b2f
8 changed files with 51 additions and 17 deletions
|
@ -19,12 +19,22 @@ BoardCanvas::BoardCanvas(wxFrame *parent)
|
|||
adata.duration=5000;
|
||||
adata.duration_fast=80;
|
||||
adata.fps=30;
|
||||
adata.buffer=new wxBitmap(500,500,32);
|
||||
// Let GameTableLeftPanel process keyboard events:
|
||||
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();});
|
||||
Bind(wxEVT_PAINT, &BoardCanvas::OnPaint, this);
|
||||
//Bind(wxEVT_IDLE, [p=this](wxIdleEvent& event){p->Refresh();p->Update();});
|
||||
Bind(wxEVT_SIZE, &BoardCanvas::OnResize, this);
|
||||
}
|
||||
|
||||
void BoardCanvas::OnResize(wxSizeEvent &e){
|
||||
wxSize size=e.GetSize();
|
||||
if(size.x>100 && size.y>100){
|
||||
// Setup buffer (use for animations)
|
||||
if(adata.buffer!=nullptr)
|
||||
free(adata.buffer);
|
||||
adata.buffer=new wxBitmap(size.x,size.y,32);
|
||||
}
|
||||
}
|
||||
|
||||
BoardCanvas::~BoardCanvas() {
|
||||
|
@ -46,8 +56,6 @@ BoardCanvas::BoardCanvas(wxFrame *parent, std::uint32_t square_width,
|
|||
void BoardCanvas::OnPaint(wxPaintEvent &event) {
|
||||
wxBufferedPaintDC dc(this);
|
||||
dc.SetBackground(*wxWHITE_BRUSH);
|
||||
dc.Clear();
|
||||
wxLogDebug("lll");
|
||||
|
||||
if(!adata.reuseBuffer){
|
||||
// Setting up required attributes
|
||||
|
@ -60,12 +68,8 @@ void BoardCanvas::OnPaint(wxPaintEvent &event) {
|
|||
boardX = 0;
|
||||
if (boardY > canvas_size.y)
|
||||
boardY = 0;
|
||||
|
||||
// Setup buffer (later use for animations)
|
||||
if(adata.buffer!=nullptr)
|
||||
free(adata.buffer);
|
||||
adata.buffer=new wxBitmap(canvas_size.x,canvas_size.y,32);
|
||||
wxMemoryDC memDC(*adata.buffer);
|
||||
memDC.Clear();
|
||||
DrawBoard(memDC);
|
||||
dc.Blit(0,0,canvas_size.x,canvas_size.y,(wxDC*)&memDC,0,0);
|
||||
}
|
||||
|
@ -77,8 +81,7 @@ void BoardCanvas::OnPaint(wxPaintEvent &event) {
|
|||
dc.DrawBitmap(*t->Get(adata.piece_moved),
|
||||
adata.src.x + adata.frame*(adata.transVect.x/adata.frames),
|
||||
adata.src.y + adata.frame*(adata.transVect.y/adata.frames), false);
|
||||
wxLogDebug("Here: %d",(int)adata.src.y + adata.frame*(adata.transVect.y/adata.frames));
|
||||
// end drawing
|
||||
// End drawing
|
||||
adata.frame++;
|
||||
}
|
||||
}
|
||||
|
@ -390,7 +393,8 @@ void BoardCanvas::MouseEvent(wxMouseEvent &event) {
|
|||
}
|
||||
|
||||
void BoardCanvas::Zoom(std::int32_t zoom) {
|
||||
t->Zoom(zoom);
|
||||
if(!t->Zoom(zoom))
|
||||
return;
|
||||
t_captures->ResizePieces(t->GetPiecesSizes() * CAPTURE_FACTOR);
|
||||
Refresh();
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ public:
|
|||
void MouseEvent(wxMouseEvent &event);
|
||||
void Zoom(std::int32_t zoom);
|
||||
void Swap();
|
||||
void OnResize(wxSizeEvent &e);
|
||||
void SetupBoard(std::string board, bool is_black_turn,
|
||||
std::map<char, std::uint8_t> captures,
|
||||
std::string white_player, std::string black_player);
|
||||
|
|
|
@ -130,10 +130,13 @@ void Theme::ResizeSquares(std::uint32_t width) {
|
|||
skin_scaled['3']->SetMask(RoundedMask(width, 3));
|
||||
}
|
||||
|
||||
void Theme::Zoom(int amount) {
|
||||
bool Theme::Zoom(int amount) {
|
||||
double width = skin_scaled['s']->GetWidth() + amount;
|
||||
if(width<=20)
|
||||
return false;
|
||||
ResizeSquares(std::max(width, 1.0));
|
||||
ResizePieces(std::max(width * PIECE_SIZE_FACTOR, 1.0));
|
||||
return true;
|
||||
}
|
||||
|
||||
void Theme::SetSquareRadius(std::uint8_t radius) {
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
void ResizeSquaresAndPieces(std::uint32_t width);
|
||||
void SetSquareRadius(std::uint8_t radius);
|
||||
std::uint8_t GetSquareRadius();
|
||||
void Zoom(int amount);
|
||||
bool Zoom(int amount);
|
||||
double GetPiecesSizes();
|
||||
double GetSquaresSizes();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue