Skip to content

Commit

Permalink
Icon: Use std::array where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
lioncash committed Sep 1, 2019
1 parent 462d2bb commit 532e690
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions specter/include/specter/Icon.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <array>
#include <cstddef>

#include "specter/View.hpp"
Expand All @@ -15,9 +16,9 @@ class ViewResources;

struct Icon {
boo::ObjToken<boo::ITexture> m_tex;
zeus::CVector2f m_uvCoords[4];
std::array<zeus::CVector2f, 4> m_uvCoords;
Icon() = default;
Icon(boo::ObjToken<boo::ITexture> tex, float rect[4]) : m_tex(std::move(tex)) {
Icon(boo::ObjToken<boo::ITexture> tex, const std::array<float, 4>& rect) : m_tex(std::move(tex)) {
m_uvCoords[0][0] = rect[0];
m_uvCoords[0][1] = -rect[3];

Expand All @@ -35,11 +36,15 @@ struct Icon {
template <size_t COLS, size_t ROWS>
class IconAtlas {
boo::ObjToken<boo::ITextureS> m_tex;
Icon m_icons[COLS][ROWS];
std::array<std::array<Icon, ROWS>, COLS> m_icons;

Icon MakeIcon(float x, float y) {
float rect[] = {x / float(COLS), y / float(ROWS), x / float(COLS) + 1.f / float(COLS),
y / float(ROWS) + 1.f / float(ROWS)};
Icon MakeIcon(float x, float y) const {
const std::array<float, 4> rect{
x / float(COLS),
y / float(ROWS),
x / float(COLS) + 1.f / float(COLS),
y / float(ROWS) + 1.f / float(ROWS),
};
return Icon(m_tex.get(), rect);
}

Expand Down

0 comments on commit 532e690

Please sign in to comment.