| 14 | } |
| 15 | |
| 16 | void CMapGrid::OnRender(CUIRect View) |
| 17 | { |
| 18 | if(!m_GridActive) |
| 19 | { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | std::shared_ptr<CLayerGroup> pGroup = Map()->SelectedGroup(); |
| 24 | if(!pGroup) |
| 25 | { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | pGroup->MapScreen(); |
| 30 | |
| 31 | float aGroupPoints[4]; |
| 32 | pGroup->Mapping(aGroupPoints); |
| 33 | |
| 34 | float ScreenX0, ScreenY0, ScreenX1, ScreenY1; |
| 35 | Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1); |
| 36 | |
| 37 | const int LineDistance = GridLineDistance(); |
| 38 | |
| 39 | const int XOffset = aGroupPoints[0] / LineDistance; |
| 40 | const int YOffset = aGroupPoints[1] / LineDistance; |
| 41 | const int XGridOffset = XOffset % m_GridFactor; |
| 42 | const int YGridOffset = YOffset % m_GridFactor; |
| 43 | |
| 44 | const int NumColumns = (int)std::ceil((ScreenX1 - ScreenX0) / LineDistance) + 1; |
| 45 | const int NumRows = (int)std::ceil((ScreenY1 - ScreenY0) / LineDistance) + 1; |
| 46 | |
| 47 | Graphics()->TextureClear(); |
| 48 | |
| 49 | IGraphics::CLineItemBatch LineItemBatch; |
| 50 | if(m_GridFactor > 1) |
| 51 | { |
| 52 | Graphics()->LinesBatchBegin(&LineItemBatch); |
| 53 | Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.15f); |
| 54 | for(int y = 0; y < NumRows; y++) |
| 55 | { |
| 56 | if((y + YGridOffset) % m_GridFactor == 0) |
| 57 | { |
| 58 | continue; |
| 59 | } |
| 60 | const float PosY = LineDistance * (y + YOffset); |
| 61 | const IGraphics::CLineItem Line = IGraphics::CLineItem(ScreenX0, PosY, ScreenX1, PosY); |
| 62 | Graphics()->LinesBatchDraw(&LineItemBatch, &Line, 1); |
| 63 | } |
| 64 | for(int x = 0; x < NumColumns; x++) |
| 65 | { |
| 66 | if((x + XGridOffset) % m_GridFactor == 0) |
| 67 | { |
| 68 | continue; |
| 69 | } |
| 70 | const float PosX = LineDistance * (x + XOffset); |
| 71 | const IGraphics::CLineItem Line = IGraphics::CLineItem(PosX, ScreenY0, PosX, ScreenY1); |
| 72 | Graphics()->LinesBatchDraw(&LineItemBatch, &Line, 1); |
| 73 | } |
nothing calls this directly
no test coverage detected