mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Make some changes to events handler in TileMapPanel
This commit is contained in:
@@ -16,9 +16,9 @@ TileMapPanel::TileMapPanel(wxWindow* parent, wxWindowID id, const wxPoint &pos,
|
|||||||
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
||||||
|
|
||||||
Connect(wxEVT_PAINT, wxPaintEventHandler(TileMapPanel::OnPaint), NULL, this);
|
Connect(wxEVT_PAINT, wxPaintEventHandler(TileMapPanel::OnPaint), NULL, this);
|
||||||
Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(TileMapPanel::OnLeftButtonPressed), NULL, this);
|
Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(TileMapPanel::OnMouseEvent), NULL, this);
|
||||||
Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(TileMapPanel::OnRightButtonPressed), NULL, this);
|
Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(TileMapPanel::OnMouseEvent), NULL, this);
|
||||||
Connect(wxEVT_MOTION, wxMouseEventHandler(TileMapPanel::OnMouseMoved), NULL, this);
|
Connect(wxEVT_MOTION, wxMouseEventHandler(TileMapPanel::OnMouseEvent), NULL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TileMapPanel::~TileMapPanel()
|
TileMapPanel::~TileMapPanel()
|
||||||
@@ -115,7 +115,7 @@ void TileMapPanel::OnPaint(wxPaintEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileMapPanel::OnLeftButtonPressed(wxMouseEvent &event)
|
void TileMapPanel::OnMouseEvent(wxMouseEvent &event)
|
||||||
{
|
{
|
||||||
if(!m_tilemap || !m_tileset)
|
if(!m_tilemap || !m_tileset)
|
||||||
return;
|
return;
|
||||||
@@ -128,43 +128,17 @@ void TileMapPanel::OnLeftButtonPressed(wxMouseEvent &event)
|
|||||||
if(currentColumn >= m_tilemap->GetColumnsCount() || currentRow >= m_tilemap->GetRowsCount())
|
if(currentColumn >= m_tilemap->GetColumnsCount() || currentRow >= m_tilemap->GetRowsCount())
|
||||||
return; //Stop if the position is out of range
|
return; //Stop if the position is out of range
|
||||||
|
|
||||||
//Add a tile to the current position
|
|
||||||
m_tilemap->SetTile(m_mapCurrentLayer, currentColumn, currentRow, m_tileToBeInserted);
|
|
||||||
Refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileMapPanel::OnRightButtonPressed(wxMouseEvent &event)
|
|
||||||
{
|
|
||||||
if(!m_tilemap || !m_tileset)
|
|
||||||
return;
|
|
||||||
|
|
||||||
//Get the current tile position (column and row)
|
|
||||||
int currentColumn, currentRow;
|
|
||||||
wxPoint mousePos = CalcUnscrolledPosition(event.GetPosition());
|
|
||||||
GetTileAt(mousePos, currentColumn, currentRow);
|
|
||||||
|
|
||||||
if(currentColumn >= m_tilemap->GetColumnsCount() || currentRow >= m_tilemap->GetRowsCount())
|
|
||||||
return; //Stop if the position is out of range
|
|
||||||
|
|
||||||
//Remove the tile
|
|
||||||
m_tilemap->SetTile(m_mapCurrentLayer, currentColumn, currentRow, -1);
|
|
||||||
Refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileMapPanel::OnMouseMoved(wxMouseEvent &event)
|
|
||||||
{
|
|
||||||
if(!m_tilemap || !m_tileset)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(event.LeftIsDown()) //Left mouse button pressed
|
if(event.LeftIsDown()) //Left mouse button pressed
|
||||||
{
|
{
|
||||||
//Add a tile to the current position
|
//Add a tile to the current position
|
||||||
OnLeftButtonPressed(event);
|
m_tilemap->SetTile(m_mapCurrentLayer, currentColumn, currentRow, m_tileToBeInserted);
|
||||||
|
Refresh();
|
||||||
}
|
}
|
||||||
else if(event.RightIsDown())
|
else if(event.RightIsDown())
|
||||||
{
|
{
|
||||||
//Remove the tile
|
//Remove the tile
|
||||||
OnRightButtonPressed(event);
|
m_tilemap->SetTile(m_mapCurrentLayer, currentColumn, currentRow, -1);
|
||||||
|
Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,9 +57,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnPaint(wxPaintEvent &event);
|
void OnPaint(wxPaintEvent &event);
|
||||||
void OnLeftButtonPressed(wxMouseEvent &event);
|
void OnMouseEvent(wxMouseEvent &event);
|
||||||
void OnRightButtonPressed(wxMouseEvent &event);
|
|
||||||
void OnMouseMoved(wxMouseEvent &event);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxPoint GetPositionOfTile(int column, int row);
|
wxPoint GetPositionOfTile(int column, int row);
|
||||||
|
Reference in New Issue
Block a user