Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Minimap::draw(const Rect& screenRect, const Position& mapCenter, float scale, const Color& color)
- {
- if (screenRect.isEmpty())
- return;
- Rect mapRect = calcMapRect(screenRect, mapCenter, scale);
- g_painter->saveState();
- g_painter->setColor(Color::alpha);
- g_painter->drawFilledRect(screenRect);
- g_painter->resetColor();
- g_painter->setClipRect(screenRect);
- if (MMBLOCK_SIZE*scale <= 1 || !mapCenter.isMapPosition()) {
- g_painter->restoreSavedState();
- return;
- }
- Point blockOff = getBlockOffset(mapRect.topLeft());
- Point off = Point((mapRect.size() * scale).toPoint() - screenRect.size().toPoint()) / 2;
- Point start = screenRect.topLeft() - (mapRect.topLeft() - blockOff)*scale - off;
- //Point padding = (mapRect.topLeft() - blockOff)*scale - off;
- for (int y = blockOff.y, ys = start.y; ys<screenRect.bottom(); y += MMBLOCK_SIZE, ys += MMBLOCK_SIZE*scale) {
- if (y < 0 || y >= 65536)
- continue;
- for (int x = blockOff.x, xs = start.x; xs<screenRect.right(); x += MMBLOCK_SIZE, xs += MMBLOCK_SIZE*scale) {
- if (x < 0 || x >= 65536)
- continue;
- Position blockPos(x, y, mapCenter.z);
- if (!hasBlock(blockPos))
- continue;
- MinimapBlock& block = getBlock(Position(x, y, mapCenter.z));
- block.update();
- const TexturePtr& tex = block.getTexture();
- if (tex) {
- Rect src(0, 0, MMBLOCK_SIZE, MMBLOCK_SIZE);
- auto size = src.size() * scale;
- auto shader = g_shaders.getShader("elipsify");
- if (shader) {
- shader->bind();
- shader->setUniformValue(ShaderManager::MAP_CENTER_COORD, (float)screenRect.width() / 2, (float)screenRect.height() / 2);
- shader->setUniformValue(ShaderManager::MAP_GLOBAL_COORD, (float)(xs - screenRect.left()), (float)(ys - screenRect.top()));
- //shader->setUniformValue(ShaderManager::MAP_WALKOFFSET, size.width(), size.height());
- shader->setUniformValue(ShaderManager::MAP_ZOOM, scale);
- g_painter->setShaderProgram(shader);
- }
- Rect dest(Point(xs, ys), size);
- tex->setSmooth(scale < 1.0f);
- g_painter->drawTexturedRect(dest, tex, src);
- }
- //g_painter->drawBoundingRect(Rect(xs,ys, MMBLOCK_SIZE * scale, MMBLOCK_SIZE * scale));
- }
- }
- g_painter->restoreSavedState();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement