Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. void Minimap::draw(const Rect& screenRect, const Position& mapCenter, float scale, const Color& color)
  2. {
  3.     if (screenRect.isEmpty())
  4.         return;
  5.     Rect mapRect = calcMapRect(screenRect, mapCenter, scale);
  6.     g_painter->saveState();
  7.     g_painter->setColor(Color::alpha);
  8.     g_painter->drawFilledRect(screenRect);
  9.     g_painter->resetColor();
  10.     g_painter->setClipRect(screenRect);
  11.     if (MMBLOCK_SIZE*scale <= 1 || !mapCenter.isMapPosition()) {
  12.         g_painter->restoreSavedState();
  13.         return;
  14.     }
  15.     Point blockOff = getBlockOffset(mapRect.topLeft());
  16.     Point off = Point((mapRect.size() * scale).toPoint() - screenRect.size().toPoint()) / 2;
  17.     Point start = screenRect.topLeft() - (mapRect.topLeft() - blockOff)*scale - off;
  18.     //Point padding = (mapRect.topLeft() - blockOff)*scale - off;
  19.     for (int y = blockOff.y, ys = start.y; ys<screenRect.bottom(); y += MMBLOCK_SIZE, ys += MMBLOCK_SIZE*scale) {
  20.         if (y < 0 || y >= 65536)
  21.             continue;
  22.         for (int x = blockOff.x, xs = start.x; xs<screenRect.right(); x += MMBLOCK_SIZE, xs += MMBLOCK_SIZE*scale) {
  23.             if (x < 0 || x >= 65536)
  24.                 continue;
  25.             Position blockPos(x, y, mapCenter.z);
  26.             if (!hasBlock(blockPos))
  27.                 continue;
  28.             MinimapBlock& block = getBlock(Position(x, y, mapCenter.z));
  29.  
  30.             block.update();
  31.             const TexturePtr& tex = block.getTexture();
  32.             if (tex) {
  33.                 Rect src(0, 0, MMBLOCK_SIZE, MMBLOCK_SIZE);
  34.                 auto size = src.size() * scale;
  35.                     auto shader = g_shaders.getShader("elipsify");
  36.                     if (shader) {
  37.                         shader->bind();
  38.                         shader->setUniformValue(ShaderManager::MAP_CENTER_COORD, (float)screenRect.width() / 2, (float)screenRect.height() / 2);
  39.                         shader->setUniformValue(ShaderManager::MAP_GLOBAL_COORD, (float)(xs - screenRect.left()), (float)(ys - screenRect.top()));
  40.                         //shader->setUniformValue(ShaderManager::MAP_WALKOFFSET, size.width(), size.height());
  41.                         shader->setUniformValue(ShaderManager::MAP_ZOOM, scale);
  42.                         g_painter->setShaderProgram(shader);
  43.                     }
  44.                
  45.                 Rect dest(Point(xs, ys), size);
  46.                 tex->setSmooth(scale < 1.0f);
  47.                 g_painter->drawTexturedRect(dest, tex, src);
  48.             }
  49.             //g_painter->drawBoundingRect(Rect(xs,ys, MMBLOCK_SIZE * scale, MMBLOCK_SIZE * scale));
  50.         }
  51.     }
  52.     g_painter->restoreSavedState();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement