Merge pull request #38 from h4570/feature/sprite-modes
Sprite modes (stretch/repeat)
This commit is contained in:
@@ -15,6 +15,12 @@
|
|||||||
#include <draw_types.h>
|
#include <draw_types.h>
|
||||||
#include <draw_buffers.h>
|
#include <draw_buffers.h>
|
||||||
|
|
||||||
|
enum SpriteMode
|
||||||
|
{
|
||||||
|
MODE_STRETCH,
|
||||||
|
MODE_REPEAT
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class which have contain 2D image data.
|
* Class which have contain 2D image data.
|
||||||
*/
|
*/
|
||||||
@@ -37,10 +43,16 @@ public:
|
|||||||
/** Auto generated unique Id. */
|
/** Auto generated unique Id. */
|
||||||
inline const u32 &getId() const { return id; };
|
inline const u32 &getId() const { return id; };
|
||||||
|
|
||||||
|
/** Get sprite drawing mode. */
|
||||||
|
inline const SpriteMode &getMode() const { return mode; };
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// Setters
|
// Setters
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
|
/** Set sprite drawing mode. */
|
||||||
|
void setMode(const SpriteMode &t_val) { mode = t_val; }
|
||||||
|
|
||||||
// ----
|
// ----
|
||||||
// Other
|
// Other
|
||||||
// ----
|
// ----
|
||||||
@@ -59,6 +71,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
u32 id;
|
u32 id;
|
||||||
|
SpriteMode mode;
|
||||||
u8 _isSizeSet, _flipH, _flipV;
|
u8 _isSizeSet, _flipH, _flipV;
|
||||||
void setDefaultColor();
|
void setDefaultColor();
|
||||||
void setDefaultLODAndClut();
|
void setDefaultLODAndClut();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ Sprite::Sprite()
|
|||||||
_flipH = false;
|
_flipH = false;
|
||||||
_flipV = false;
|
_flipV = false;
|
||||||
scale = 1.0F;
|
scale = 1.0F;
|
||||||
|
mode = MODE_REPEAT;
|
||||||
setDefaultColor();
|
setDefaultColor();
|
||||||
setDefaultLODAndClut();
|
setDefaultLODAndClut();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,14 +101,26 @@ void Renderer::changeTexture(Texture *t_tex)
|
|||||||
|
|
||||||
void Renderer::draw(Sprite &t_sprite)
|
void Renderer::draw(Sprite &t_sprite)
|
||||||
{
|
{
|
||||||
|
Texture *texture = textureRepo.getBySprite(t_sprite.getId());
|
||||||
texrect_t rect;
|
texrect_t rect;
|
||||||
float texMax = t_sprite.size.x > t_sprite.size.y ? t_sprite.size.x : t_sprite.size.y;
|
float sizeX, sizeY;
|
||||||
float texS = texMax;
|
if (t_sprite.getMode() == MODE_REPEAT)
|
||||||
float texT = texMax;
|
{
|
||||||
if (t_sprite.size.x > t_sprite.size.y)
|
sizeX = t_sprite.size.x;
|
||||||
texT = texMax / (t_sprite.size.x / t_sprite.size.y);
|
sizeY = t_sprite.size.y;
|
||||||
else if (t_sprite.size.y > t_sprite.size.x)
|
}
|
||||||
texS = texMax / (t_sprite.size.y / t_sprite.size.x);
|
else
|
||||||
|
{
|
||||||
|
sizeX = (float)texture->getWidth();
|
||||||
|
sizeY = (float)texture->getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
float texS, texT;
|
||||||
|
float texMax = texT = texS = sizeX > sizeY ? sizeX : sizeY;
|
||||||
|
if (sizeX > sizeY)
|
||||||
|
texT = texMax / (sizeX / sizeY);
|
||||||
|
else if (sizeY > sizeX)
|
||||||
|
texS = texMax / (sizeY / sizeX);
|
||||||
rect.t0.s = t_sprite.isFlippedHorizontally() ? texS : 0.0F;
|
rect.t0.s = t_sprite.isFlippedHorizontally() ? texS : 0.0F;
|
||||||
rect.t0.t = t_sprite.isFlippedVertically() ? texT : 0.0F;
|
rect.t0.t = t_sprite.isFlippedVertically() ? texT : 0.0F;
|
||||||
rect.t1.s = t_sprite.isFlippedHorizontally() ? 0.0F : texS;
|
rect.t1.s = t_sprite.isFlippedHorizontally() ? 0.0F : texS;
|
||||||
@@ -125,7 +137,7 @@ void Renderer::draw(Sprite &t_sprite)
|
|||||||
rect.v1.y = (t_sprite.size.y * t_sprite.scale) + t_sprite.position.y;
|
rect.v1.y = (t_sprite.size.y * t_sprite.scale) + t_sprite.position.y;
|
||||||
rect.v1.z = (u32)-1;
|
rect.v1.z = (u32)-1;
|
||||||
beginFrameIfNeeded();
|
beginFrameIfNeeded();
|
||||||
changeTexture(textureRepo.getBySprite(t_sprite.getId()));
|
changeTexture(texture);
|
||||||
packet2_t *packet2 = packet2_create(12, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0);
|
packet2_t *packet2 = packet2_create(12, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0);
|
||||||
packet2_update(packet2, draw_primitive_xyoffset(packet2->next, 0, 2048, 2048));
|
packet2_update(packet2, draw_primitive_xyoffset(packet2->next, 0, 2048, 2048));
|
||||||
packet2_utils_gif_add_set(packet2, 1);
|
packet2_utils_gif_add_set(packet2, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user