31 #ifndef AGS_SHARED_UTIL_SCALING_H 32 #define AGS_SHARED_UTIL_SCALING_H 34 #include "ags/shared/core/types.h" 35 #include "ags/shared/util/geometry.h" 50 bool IsIdentity()
const {
51 return _scale == kUnit && _srcOffset == 0 && _dstOffset == 0;
54 bool IsTranslateOnly()
const {
55 return _scale == kUnit;
58 void Init(
const int32_t src_length,
const int32_t dst_length,
const int32_t src_offset = 0,
const int32_t dst_offset = 0) {
61 _srcOffset = src_offset;
62 _dstOffset = dst_offset;
64 if (src_length != 0) {
65 int32_t
scale = (dst_length << kShift) / src_length;
69 int32_t scaled_val = ScaleDistance(src_length);
70 if (scaled_val < dst_length)
76 void SetSrcOffset(int32_t x) {
80 void SetDstOffset(int32_t x) {
84 inline int32_t GetSrcOffset()
const {
88 inline int32_t ScalePt(int32_t x)
const {
89 return (((x - _srcOffset) * _scale) >> kShift) + _dstOffset;
91 inline int32_t ScaleDistance(int32_t x)
const {
92 return ((x * _scale) >> kShift);
94 inline int32_t UnScalePt(int32_t x)
const {
95 return ((x - _dstOffset) << kShift) / _unscale + _srcOffset;
97 inline int32_t UnScaleDistance(int32_t x)
const {
98 return (x << kShift) / _unscale;
112 bool IsIdentity()
const {
113 return X.IsIdentity() && Y.IsIdentity();
116 bool IsTranslateOnly()
const {
117 return X.IsTranslateOnly() && Y.IsTranslateOnly();
120 void Init(
const Size &src_size,
const Rect &dst_rect) {
121 X.Init(src_size.Width, dst_rect.GetWidth(), 0, dst_rect.Left);
122 Y.Init(src_size.Height, dst_rect.GetHeight(), 0, dst_rect.Top);
125 void Init(
const Rect &src_rect,
const Rect &dst_rect) {
126 X.Init(src_rect.GetWidth(), dst_rect.GetWidth(), src_rect.Left, dst_rect.Left);
127 Y.Init(src_rect.GetHeight(), dst_rect.GetHeight(), src_rect.Top, dst_rect.Top);
130 void SetSrcOffsets(
int x,
int y) {
135 void SetDestOffsets(
int x,
int y) {
141 return Point(X.ScalePt(p.X), Y.ScalePt(p.Y));
144 inline Rect ScaleRange(
const Rect &r)
const {
145 return RectWH(X.ScalePt(r.Left), Y.ScalePt(r.Top), X.ScaleDistance(r.GetWidth()), Y.ScaleDistance(r.GetHeight()));
149 return Point(X.UnScalePt(p.X), Y.UnScalePt(p.Y));
152 inline Rect UnScaleRange(
const Rect &r)
const {
153 return RectWH(X.UnScalePt(r.Left), Y.UnScalePt(r.Top), X.UnScaleDistance(r.GetWidth()), Y.UnScaleDistance(r.GetHeight()));
Definition: achievements_tables.h:27
Definition: geometry.h:87
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: scaling.h:108
Definition: geometry.h:219
Definition: geometry.h:148