Draw in abstract units and scale to pixels at the end.
This commit is contained in:
parent
a561242395
commit
0c6275f41c
9 changed files with 73 additions and 22 deletions
|
@ -261,18 +261,21 @@ namespace cloonel {
|
|||
m_texture = SDL_CreateTextureFromSurface(m_sdlmain->GetRenderer(), surf);
|
||||
SDL_FreeSurface(surf);
|
||||
if (m_texture) {
|
||||
int width, height;
|
||||
SDL_QueryTexture(m_texture, nullptr, nullptr, &width, &height);
|
||||
m_size = static_cast<ushort2>(int2(width, height));
|
||||
int2 wh;
|
||||
SDL_QueryTexture(m_texture, nullptr, nullptr, &wh.x(), &wh.y());
|
||||
m_size = static_cast<float2>(wh);
|
||||
}
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void Texture::Render (int2 parPos, ushort2 parSize) const {
|
||||
void Texture::Render (const float2& parPos, const float2& parSize) const {
|
||||
assert(IsLoaded());
|
||||
const float2 scaling(m_sdlmain->WHScaling());
|
||||
const ushort2 pos(static_cast<ushort2>(parPos * scaling + 0.5f));
|
||||
const ushort2 siz(static_cast<ushort2>(parSize * scaling + 0.5f));
|
||||
const int screenHeight = m_sdlmain->WidthHeight().y();
|
||||
const SDL_Rect dest = { parPos.x(), screenHeight - parPos.y() - parSize.y(), parSize.x(), parSize.y() };
|
||||
const SDL_Rect dest = { pos.x(), screenHeight - pos.y() - siz.y(), siz.x(), siz.y() };
|
||||
SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, &dest);
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue