| 21 | ColorPalette::ColorPalette(m2::PointU const & canvasSize) : m_textureSize(canvasSize), m_cursor(m2::PointU::Zero()) {} |
| 22 | |
| 23 | ref_ptr<Texture::ResourceInfo> ColorPalette::ReserveResource(bool predefined, ColorKey const & key, bool & newResource) |
| 24 | { |
| 25 | TPalette & palette = predefined ? m_predefinedPalette : m_palette; |
| 26 | auto itm = palette.find(key.m_color); |
| 27 | newResource = (itm == palette.end()); |
| 28 | if (newResource) |
| 29 | { |
| 30 | PendingColor pendingColor; |
| 31 | pendingColor.m_color = key.m_color; |
| 32 | pendingColor.m_rect = m2::RectU(m_cursor.x, m_cursor.y, m_cursor.x + kResourceSize, m_cursor.y + kResourceSize); |
| 33 | { |
| 34 | std::lock_guard<std::mutex> g(m_lock); |
| 35 | m_pendingNodes.push_back(pendingColor); |
| 36 | } |
| 37 | |
| 38 | m_cursor.x += kResourceSize; |
| 39 | if (m_cursor.x >= m_textureSize.x) |
| 40 | { |
| 41 | m_cursor.y += kResourceSize; |
| 42 | m_cursor.x = 0; |
| 43 | |
| 44 | ASSERT(m_cursor.y < m_textureSize.y, ()); |
| 45 | } |
| 46 | |
| 47 | float const sizeX = static_cast<float>(m_textureSize.x); |
| 48 | float const sizeY = static_cast<float>(m_textureSize.y); |
| 49 | m2::PointF const resCenter = m2::RectF(pendingColor.m_rect).Center(); |
| 50 | float const x = resCenter.x / sizeX; |
| 51 | float const y = resCenter.y / sizeY; |
| 52 | auto res = palette.emplace(key.m_color, ColorResourceInfo(m2::RectF(x, y, x, y))); |
| 53 | ASSERT(res.second, ()); |
| 54 | itm = res.first; |
| 55 | } |
| 56 | |
| 57 | return make_ref(&itm->second); |
| 58 | } |
| 59 | |
| 60 | ref_ptr<Texture::ResourceInfo> ColorPalette::MapResource(ColorKey const & key, bool & newResource) |
| 61 | { |
no test coverage detected