Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotate interface images #9943

Merged
merged 5 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,14 +496,14 @@ void Interface::ImageElement::Draw(const Rectangle &rect, const Information &inf
return;

float frame = info.GetSpriteFrame(name);
Point unit = info.GetSpriteUnit(name);
if(isOutline)
{
Color color = (isColored ? info.GetOutlineColor() : Color(1.f, 1.f));
Point unit = info.GetSpriteUnit(name);
OutlineShader::Draw(sprite, rect.Center(), rect.Dimensions(), color, unit, frame);
}
else
SpriteShader::Draw(sprite, rect.Center(), rect.Width() / sprite->Width(), 0, frame);
SpriteShader::Draw(sprite, rect.Center(), rect.Width() / sprite->Width(), 0, frame, unit);
}


Expand Down
18 changes: 12 additions & 6 deletions source/SpriteShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,21 @@ void SpriteShader::Init()



void SpriteShader::Draw(const Sprite *sprite, const Point &position, float zoom, int swizzle, float frame)
void SpriteShader::Draw(const Sprite *sprite, const Point &position,
float zoom, int swizzle, float frame, const Point &unit)
{
if(!sprite)
return;

Bind();
Add(Prepare(sprite, position, zoom, swizzle, frame));
Add(Prepare(sprite, position, zoom, swizzle, frame, unit));
Unbind();
}



SpriteShader::Item SpriteShader::Prepare(const Sprite *sprite, const Point &position,
float zoom, int swizzle, float frame)
float zoom, int swizzle, float frame, const Point &unit)
{
if(!sprite)
return {};
Expand All @@ -319,9 +320,14 @@ SpriteShader::Item SpriteShader::Prepare(const Sprite *sprite, const Point &posi
// Position.
item.position[0] = static_cast<float>(position.X());
item.position[1] = static_cast<float>(position.Y());
// Rotation (none) and scale.
item.transform[0] = sprite->Width() * zoom;
item.transform[3] = sprite->Height() * zoom;
// Rotation and scale.
Point scaledUnit = unit * zoom;
Point uw = scaledUnit * sprite->Width();
Point uh = scaledUnit * sprite->Height();
item.transform[0] = static_cast<float>(-uw.Y());
item.transform[1] = static_cast<float>(uw.X());
item.transform[2] = static_cast<float>(-uh.X());
item.transform[3] = static_cast<float>(-uh.Y());
// Swizzle.
item.swizzle = swizzle;

Expand Down
11 changes: 6 additions & 5 deletions source/SpriteShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef SPRITE_SHADER_H_
#define SPRITE_SHADER_H_

#include "Point.h"
Amazinite marked this conversation as resolved.
Show resolved Hide resolved

class Sprite;
class Point;

#include <cstdint>

Expand Down Expand Up @@ -50,10 +51,10 @@ class SpriteShader {
static void Init();

// Draw a sprite.
static void Draw(const Sprite *sprite, const Point &position, float zoom = 1.f, int swizzle = 0,
float frame = 0.f);
static Item Prepare(const Sprite *sprite, const Point &position, float zoom = 1.f, int swizzle = 0,
float frame = 0.f);
static void Draw(const Sprite *sprite, const Point &position, float zoom = 1.f,
int swizzle = 0, float frame = 0.f, const Point &unit = Point(0., -1.));
static Item Prepare(const Sprite *sprite, const Point &position, float zoom = 1.f,
int swizzle = 0, float frame = 0.f, const Point &unit = Point(0., -1.));

static void Bind();
static void Add(const Item &item, bool withBlur = false);
Expand Down
Loading