1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| void SunaMap::OnMouseLeftDown(wxMouseEvent& event)
{
cursorPos.x = event.GetX() - event.GetX()%TILE_SIZE;
cursorPos.y = event.GetY() - event.GetY()%TILE_SIZE;
wxClientDC dc(panel);
this->Draw(dc);
event.Skip();
}
void SunaMap::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(panel);
this->Draw(dc);
event.Skip();
}
void SunaMap::Draw(wxDC& dc)
{
// obtenir le bitmap
std::string tilesetName("Graphics/Tilesets/"+tileset->GetTilesetName());
wxImage image;
image.AddHandler(new wxPNGHandler);
image.LoadFile(wxString(tilesetName.c_str(), wxConvFile), wxBITMAP_TYPE_PNG);
wxBitmap bitmap(image);
// dessiner la map
wxMemoryDC dcTemp(bitmap);
dcTemp.DrawBitmap(bitmap, 0, 0, true); // obtention de la palette
for(int x=0 ; x<tileWidth ; x++)
{
for(int y=0 ; y<tileHeight ; y++)
{
dc.Blit(wxCoord(x*32), wxCoord(y*32), wxCoord(32), wxCoord(32), &dcTemp, wxCoord(0), wxCoord(0));
}
}
// dessiner la grille
dc.SetPen(*wxBLACK_PEN);
for(int x=32 ; x<tileWidth*TILE_SIZE ; x+=TILE_SIZE)
{
dc.DrawLine(x, 0, x, tileHeight*TILE_SIZE+1);
for(int y=32 ; y<tileHeight*TILE_SIZE ; y+=TILE_SIZE)
{
dc.DrawLine(0, y, tileWidth*TILE_SIZE+1, y);
}
}
// dessiner curseur
// dessiner curseur : les deux carrés noir
dc.DrawLine(cursorPos.x, 0, cursorPos.x, TILE_SIZE+1);
dc.DrawLine(cursorPos.x+32, 0, cursorPos.x+32, TILE_SIZE+1);
dc.DrawLine(cursorPos.x+3, 3, cursorPos.x+3, TILE_SIZE-3+1);
dc.DrawLine(cursorPos.x+32-3, 3, cursorPos.x+32-3, TILE_SIZE-3+1);
dc.DrawLine(0, cursorPos.y, TILE_SIZE+1, cursorPos.y);
dc.DrawLine(0, cursorPos.y+32, TILE_SIZE+1, cursorPos.y+32);
dc.DrawLine(3, cursorPos.y+3, TILE_SIZE-3+1, cursorPos.y+3);
dc.DrawLine(3, cursorPos.y+32-3, TILE_SIZE-3+1, cursorPos.y+32-3);
dc.SetPen(*wxWHITE_PEN);
// dessiner curseur : les deux carrés blanc
dc.DrawLine(cursorPos.x+1, 1, cursorPos.x+1, TILE_SIZE);
dc.DrawLine(cursorPos.x+31, 1, cursorPos.x+31, TILE_SIZE);
dc.DrawLine(1, cursorPos.y+1, TILE_SIZE, cursorPos.y+1);
dc.DrawLine(1, cursorPos.y+31, TILE_SIZE, cursorPos.y+31);
dc.DrawLine(cursorPos.x+2, 2, cursorPos.x+2, TILE_SIZE-1);
dc.DrawLine(cursorPos.x+30, 2, cursorPos.x+30, TILE_SIZE-1);
dc.DrawLine(2, cursorPos.y+2, TILE_SIZE-1, cursorPos.y+2);
dc.DrawLine(2, cursorPos.y+30, TILE_SIZE-1, cursorPos.y+30);
} |
Partager