spacebox/src/extension.hpp

80 lines
2.1 KiB
C++

#ifndef extension_h_
#define extension_h_
#include <vector>
#include <iostream>
#include <regex>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stdexcept>
#define GLM_ENABLE_EXPERIMENTAL
#include "glm/trigonometric.hpp"
#include "glm/vec2.hpp"
#include "glm/gtx/vector_angle.hpp"
#include "SDL.h"
#include "Box.hpp"
#include "filesystem.hpp"
namespace sfw
{
glm::vec2 get_step(glm::vec2, glm::vec2, float);
void set_magnitude(glm::vec2&, float);
Box get_texture_box(SDL_Texture*);
void fill_texture(SDL_Renderer*, SDL_Texture*, int, int, int, int = 0xff);
void fill_texture(SDL_Renderer*, SDL_Texture*, SDL_Texture*);
SDL_Texture* duplicate_texture(SDL_Renderer*, SDL_Texture*);
std::vector<fs::path> glob(fs::path);
fs::path get_next_file_name(
fs::path, int = 0, std::string = "", std::string = "");
template<typename T>
std::string pad(T end, int width, char fill = '0')
{
std::stringstream padded;
padded.fill(fill);
padded.width(width);
padded << end;
return padded.str();
}
// from https://stackoverflow.com/a/30312659/1256386
template <typename IntType>
std::vector<IntType> range(IntType start, IntType stop, IntType step)
{
if (step == IntType(0))
{
throw std::invalid_argument("step for range must be non-zero");
}
std::vector<IntType> result;
IntType i = start;
while ((step > 0) ? (i < stop) : (i > stop))
{
result.push_back(i);
i += step;
}
return result;
}
// from https://stackoverflow.com/a/30312659/1256386
template <typename IntType>
std::vector<IntType> range(IntType start, IntType stop)
{
return range(start, stop, IntType(1));
}
// from https://stackoverflow.com/a/30312659/1256386
template <typename IntType>
std::vector<IntType> range(IntType stop)
{
return range(IntType(0), stop, IntType(1));
}
}
std::ostream& operator<<(std::ostream&, const glm::vec2&);
#endif