Skip to content

Instantly share code, notes, and snippets.

@xeekworx
Created September 1, 2020 19:27
Show Gist options
  • Save xeekworx/7581abb74d8932862f6b540bc77fd629 to your computer and use it in GitHub Desktop.
Save xeekworx/7581abb74d8932862f6b540bc77fd629 to your computer and use it in GitHub Desktop.
#pragma once
#include <SDL.h> // Unnecessary if the source including this header already includes SDL.h
#include <cmath> // For round()
struct SDL_RectF {
float x, y, w, h;
operator SDL_Rect()
{
return SDL_Rect{
static_cast<int>(std::round(x)),
static_cast<int>(std::round(y)),
static_cast<int>(std::round(w)),
static_cast<int>(std::round(h)),
};
}
};
struct SDL_RectD {
double x, y, w, h;
operator SDL_Rect()
{
return SDL_Rect{
static_cast<int>(std::round(x)),
static_cast<int>(std::round(y)),
static_cast<int>(std::round(w)),
static_cast<int>(std::round(h)),
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment