Tried to get camera to have a reset but couldn't figure out.

This commit is contained in:
Zed A. Shaw 2025-11-09 12:54:38 -05:00
parent 29409c54ce
commit de7f9f3445
4 changed files with 37 additions and 34 deletions

View file

@ -75,11 +75,7 @@ namespace boss {
void UI::zoom(const std::string &cell_name) {
auto& cell = $arena.$ui.cell_for(cell_name);
$camera.resize({BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2});
$camera.move($view_texture,
{float(cell.x/2), float(cell.y/2)});
// BUG: do I need this?
// $view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
$camera.resize(BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2);
$camera.move(float(cell.mid_x), float(cell.mid_y));
}
}

View file

@ -32,32 +32,35 @@ namespace cinematic {
{
}
void Camera::resize(sf::Vector2f to) {
size = to;
void Camera::resize(float width, float height) {
size = {width, height};
}
void Camera::style(const std::string &name) {
anim = MGR.animations.at(name);
}
void Camera::focus(float x, float y) {
position.x = x;
position.y = y;
void Camera::position(float x, float y) {
aimed_at = {x, y};
}
void Camera::move(sf::RenderTexture& target, sf::Vector2f pos) {
sf::View zoom;
void Camera::move(float x, float y) {
going_to = {x, y};
// BUG: annoying special case
if(anim.motion == ease::SLIDE) {
anim.min_x = position.x;
anim.min_y = position.y;
anim.max_x = pos.x;
anim.max_y = pos.y;
anim.min_x = aimed_at.x;
anim.min_y = aimed_at.y;
anim.max_x = going_to.x;
anim.max_y = going_to.y;
}
}
anim.apply(zoom, pos, size);
target.setView(zoom);
void Camera::render(sf::RenderTexture& target) {
if(anim.playing) {
anim.apply(view, going_to, size);
target.setView(view);
}
}
bool Camera::playing() {

View file

@ -6,16 +6,18 @@ namespace cinematic {
struct Camera {
components::Animation anim;
sf::View view;
sf::Vector2f size;
sf::Vector2f position;
sf::Vector2f size{SCREEN_WIDTH, SCREEN_WIDTH};
sf::Vector2f aimed_at{0,0};
sf::Vector2f going_to{0,0};
Camera();
void resize(sf::Vector2f size);
void move(sf::RenderTexture& target, sf::Vector2f pos);
void resize(float width, float height);
void position(float x, float y);
void move(float x, float y);
bool playing();
void render(sf::RenderTexture& target);
void play();
void focus(float x, float y);
void style(const std::string &name);
};

View file

@ -26,25 +26,28 @@ namespace storyboard {
}
void UI::render(sf::RenderWindow &window) {
if($camera.playing()) {
zoom($zoom_target);
}
$view_texture.clear();
$camera.render($view_texture);
$ui.render($view_texture);
$ui.debug_layout($view_texture);
$view_texture.display();
window.draw($view_sprite);
}
bool UI::mouse(float x, float y, guecs::Modifiers mods) {
auto& cell = $ui.cell_for($zoom_target);
$camera.focus(cell.mid_x, cell.mid_y);
$zoom_target = *$ui.$parser.hit(x, y);
zoom($zoom_target);
$camera.play();
if($zoom_target == "a") {
reset();
} else {
$camera.position(cell.mid_x, cell.mid_y);
zoom($zoom_target);
$camera.play();
}
return $ui.mouse(x, y, mods);
}
@ -52,9 +55,8 @@ namespace storyboard {
void UI::zoom(const std::string &cell_name) {
auto& cell = $ui.cell_for(cell_name);
$camera.resize({float(cell.w), float(cell.h)});
$camera.move($view_texture,
{float(cell.mid_x), float(cell.mid_y)});
$camera.resize(float(cell.w), float(cell.h));
$camera.move(float(cell.mid_x), float(cell.mid_y));
}
void UI::reset() {