Skip to content

Commit

Permalink
SDL sub-pixel rendering support
Browse files Browse the repository at this point in the history
Replaces drawing functions in `SDLPainter` with their `float` equivalents.

Fixes #2422.
  • Loading branch information
Vankata453 committed Aug 25, 2023
1 parent 6bf9b3f commit 8ab3b2d
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 87 deletions.
5 changes: 5 additions & 0 deletions src/math/rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class Rect final
top <= other.top && other.bottom <= bottom);
}

int get_left() const { return left; }
int get_right() const { return right; }
int get_top() const { return top; }
int get_bottom() const { return bottom; }

int get_width() const { return right - left; }
int get_height() const { return bottom - top; }
Size get_size() const { return Size(right - left, bottom - top); }
Expand Down
28 changes: 26 additions & 2 deletions src/math/rectf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
#include <assert.h>
#include <iosfwd>

#include <SDL.h>

#include "math/anchor_point.hpp"
#include "math/rect.hpp"
#include "math/sizef.hpp"
#include "math/vector.hpp"
#include "util/log.hpp"

class Rect;

class Rectf final
{
public:
Expand Down Expand Up @@ -69,6 +70,12 @@ class Rectf final
initialize();
}

Rectf(const SDL_FRect& rect) :
m_p1(rect.x, rect.y), m_size(rect.w, rect.h)
{
initialize();
}

Rectf(const Rect& rect);

bool operator==(const Rectf& other) const
Expand Down Expand Up @@ -125,6 +132,12 @@ class Rectf final
}
Sizef get_size() const { return m_size; }

bool empty() const
{
return get_width() <= 0 ||
get_height() <= 0;
}

void move(const Vector& v) { m_p1 += v; }
Rectf moved(const Vector& v) const { return Rectf(m_p1 + v, m_size); }

Expand Down Expand Up @@ -179,6 +192,17 @@ class Rectf final
p.y - m_p1.y);
}

Rect to_rect() const
{
return { static_cast<int>(m_p1.x), static_cast<int>(m_p1.y),
static_cast<int>(m_size.width), static_cast<int>(m_size.height) };
}

SDL_FRect to_sdl() const
{
return { m_p1.x, m_p1.y, m_size.width, m_size.height };
}

private:
/// upper left edge
Vector m_p1;
Expand Down
Loading

0 comments on commit 8ab3b2d

Please sign in to comment.