void Menu::verticalLayout() { Vector2<int> topLeftPos(rect.pos); const Vector2<int> topLeftStep = Vector2<int>(0, rect.diagonal.y) / (int)labelVector.size(); for (int i = 0; i != labelVector.size(); ++i){ Rect<int> labelRect = labelVector[i]->getRect(); labelRect.setTopLeft(topLeftPos); labelVector[i]->setRect(labelRect); topLeftPos += topLeftStep; } }
void TileMapPanel::OnPaint(wxPaintEvent& event) { wxAutoBufferedPaintDC dc(this); DoPrepareDC(dc); wxPoint minPos = GetViewStart(); int width, height; GetClientSize(&width, &height); wxPoint maxPos = minPos + wxPoint(width, height); dc.SetBrush(gd::CommonBitmapManager::Get()->transparentBg); dc.DrawRectangle(minPos.x, minPos.y, width, height); if(!m_tilemap || !m_tileset || m_tileset->IsDirty()) return; dc.SetPen(wxPen(wxColor(128, 128, 128, 255), 1)); //Determine the first and last columns and rows to draw int firstCol = std::max((int)(minPos.x / m_tileset->tileSize.x - 1), 0); int firstRow = std::max((int)(minPos.y / m_tileset->tileSize.y - 1), 0); int lastCol = std::min((int)(maxPos.x / m_tileset->tileSize.x + 1), m_tilemap->GetColumnsCount()); int lastRow = std::min((int)(maxPos.y / m_tileset->tileSize.y + 1), m_tilemap->GetRowsCount()); //Draw the tiles for(int layer = 0; m_hideUpperLayers ? layer <= GetCurrentLayer() : layer < 3; layer++) { for(int col = firstCol; col < lastCol; col++) { for(int row = firstRow; row < lastRow; row++) { if(m_tilemap->GetTile(layer, col, row) == -1) continue; dc.DrawBitmap(m_tileset->GetTileBitmap(m_tilemap->GetTile(layer, col, row)), GetPositionOfTile(col, row).x, GetPositionOfTile(col, row).y, true); } } } //Draw the rectangle (when the mode is RectangleMode) if(m_insertionMode == RectangleMode && m_isDrawingRectangle) { dc.SetBrush(wxBrush(wxColour(128, 128, 255, 128))); dc.SetPen(wxPen(wxColor(128, 128, 255, 255), 1)); wxPoint topLeftPos(GetPositionOfTile(std::min(m_beginCol, m_endCol), std::min(m_beginRow, m_endRow))); wxPoint bottomRightPos(GetPositionOfTile(std::max(m_beginCol + 1, m_endCol + 1), std::max(m_beginRow + 1, m_endRow + 1))); wxSize rectSize(bottomRightPos.x - topLeftPos.x, bottomRightPos.y - topLeftPos.y); dc.DrawRectangle(topLeftPos, rectSize); } dc.SetPen(wxPen(wxColor(128, 128, 128, 255), 1)); //Draw the grid for(int col = firstCol; col < lastCol; col++) { dc.DrawLine(col * m_tileset->tileSize.x, minPos.y, col * m_tileset->tileSize.x, maxPos.y); for(int row = firstRow; row < lastRow; row++) { dc.DrawLine(minPos.x, row * m_tileset->tileSize.y, maxPos.x, row * m_tileset->tileSize.y); } } //Draw a gray rectangle outside the map dc.SetBrush(wxColor(128, 128, 128, 255)); if(maxPos.x > (m_tilemap->GetColumnsCount() * m_tileset->tileSize.x)) { dc.DrawRectangle(m_tilemap->GetColumnsCount() * m_tileset->tileSize.x, minPos.y, maxPos.x - m_tilemap->GetColumnsCount() * m_tileset->tileSize.x, maxPos.y - minPos.y); } if(maxPos.y > (m_tilemap->GetRowsCount() * m_tileset->tileSize.y)) { dc.DrawRectangle(minPos.x, m_tilemap->GetRowsCount() * m_tileset->tileSize.y, maxPos.x - minPos.x, maxPos.y - m_tilemap->GetRowsCount() * m_tileset->tileSize.y); } }