Files
aee-arcade/source/core/rendering/sprite/sprite.cpp
T
JailDesignerandClaude Opus 4.7 da66a7c03f refactor(core/rendering): netejar ctors de Sprite/MovingSprite (INC-06 + INC-07)
- MovingSprite: el ctor delegat Sprite(surface, pos) ja assigna pos_;
  el Sprite::pos_ = pos; manual que seguia era redundant (INC-06).
- Sprite(surface) usava initializer posicional {0.0F, 0.0F, ...} mentre
  la resta del projecte usa designated initializers ({.x = ..., .y = ...}).
  Unificat (INC-07).

INC-05 (el static_cast<int> de pos_.x a MovingSprite::move i setters)
es marca WONTFIX al document: és snap intencional a píxel per al
pixel-art, divergent només al setter per SDL_FRect que es reserva per
a posicionament directe sense arrodoniment.

Build + smoke 5s xvfb OK (exit 124).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 09:57:17 +02:00

46 lines
1.3 KiB
C++

#include "core/rendering/sprite/sprite.hpp"
#include <utility>
#include "core/rendering/surface.hpp"
Sprite::Sprite() = default;
Sprite::Sprite(std::shared_ptr<Surface> surface, float x, float y, float w, float h)
: surface_(std::move(surface)),
pos_{.x = x, .y = y, .w = w, .h = h},
clip_{.x = 0.0F, .y = 0.0F, .w = pos_.w, .h = pos_.h} {}
Sprite::Sprite(std::shared_ptr<Surface> surface, SDL_FRect rect)
: surface_(std::move(surface)),
pos_(rect),
clip_{.x = 0.0F, .y = 0.0F, .w = pos_.w, .h = pos_.h} {}
Sprite::Sprite(std::shared_ptr<Surface> surface)
: surface_(std::move(surface)),
pos_{.x = 0.0F, .y = 0.0F, .w = static_cast<float>(surface_->getWidth()), .h = static_cast<float>(surface_->getHeight())},
clip_(pos_) {}
void Sprite::render() {
surface_->render(static_cast<int>(pos_.x), static_cast<int>(pos_.y), &clip_);
}
void Sprite::render(Uint8 source_color, Uint8 target_color) {
surface_->renderWithColorReplace(static_cast<int>(pos_.x), static_cast<int>(pos_.y), source_color, target_color, &clip_);
}
void Sprite::setPosition(float x, float y) {
pos_.x = x;
pos_.y = y;
}
void Sprite::setPosition(SDL_FPoint p) {
pos_.x = p.x;
pos_.y = p.y;
}
void Sprite::clear() {
pos_ = {.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F};
clip_ = {.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F};
}