- fix bug in box right drag

- print int vector
- duplicate texture resized
This commit is contained in:
Frank DeMarco 2020-08-07 01:38:19 -04:00
parent f5d03b9be6
commit 2b9dd44ff7
4 changed files with 31 additions and 17 deletions

View File

@ -114,8 +114,9 @@ void Box::set_right(float right, bool drag)
void Box::drag_right(float delta) void Box::drag_right(float delta)
{ {
float previous_right = get_right(); float previous_right = get_right();
set_right(get_right() + delta); float new_right = get_right() + delta;
set_w(get_w() + previous_right - get_right()); set_w(get_w() + new_right - previous_right);
set_right(new_right);
} }
void Box::set_bottom(float bottom) void Box::set_bottom(float bottom)

View File

@ -27,7 +27,7 @@ void Sprite::associate(std::string path)
std::vector<fs::path> paths; std::vector<fs::path> paths;
std::copy(directory, fs::directory_iterator(), std::back_inserter(paths)); std::copy(directory, fs::directory_iterator(), std::back_inserter(paths));
std::sort(paths.begin(), paths.end()); std::sort(paths.begin(), paths.end());
for (const fs::path &name : paths) for (const fs::path& name : paths)
{ {
frame_paths.push_back(name); frame_paths.push_back(name);
} }
@ -84,9 +84,9 @@ void Sprite::add_frame(SDL_Texture* texture)
{ {
all_frames_frameset.add_frame_index(ii); all_frames_frameset.add_frame_index(ii);
} }
for (auto& member : framesets) for (auto& [name, frameset] : framesets)
{ {
member.second.set_size(); frameset.set_size();
} }
update_size(preserve_center); update_size(preserve_center);
} }
@ -109,7 +109,10 @@ Frameset& Sprite::set_frameset(std::string name)
{ {
current_frameset_name = name; current_frameset_name = name;
frame_animation.set_frame_length(get_current_frameset().get_frame_length()); frame_animation.set_frame_length(get_current_frameset().get_frame_length());
update_size(true); if (is_loaded())
{
update_size(true);
}
return get_current_frameset(); return get_current_frameset();
} }
@ -557,16 +560,7 @@ void Frameset::step()
void Frameset::increment_index() void Frameset::increment_index()
{ {
int increment; increment_index(reversed ? -1 : 1);
if (!reversed)
{
increment = 1;
}
else
{
increment = -1;
}
increment_index(increment);
} }
void Frameset::increment_index(int increment) void Frameset::increment_index(int increment)

View File

@ -200,7 +200,13 @@ SDL_Texture* sfw::get_filled_texture(SDL_Renderer* renderer, glm::vec2 size, SDL
SDL_Texture* sfw::duplicate_texture(SDL_Renderer* renderer, SDL_Texture* base, Uint32 format) SDL_Texture* sfw::duplicate_texture(SDL_Renderer* renderer, SDL_Texture* base, Uint32 format)
{ {
Box box = get_texture_box(base); Box box = get_texture_box(base);
SDL_Texture* duplicate = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_TARGET, box.get_w(), box.get_h()); return duplicate_texture(renderer, base, box.get_size(), format);
}
SDL_Texture* sfw::duplicate_texture(SDL_Renderer* renderer, SDL_Texture* base, const glm::vec2& size, Uint32 format)
{
Box box = get_texture_box(base);
SDL_Texture* duplicate = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_TARGET, size.x, size.y);
if (duplicate == NULL) if (duplicate == NULL)
{ {
print_sdl_error("could not create texture from base"); print_sdl_error("could not create texture from base");
@ -492,3 +498,14 @@ std::ostream& operator<<(std::ostream& out, const SDL_Color& color)
static_cast<int>(color.b) << ", " << static_cast<int>(color.a) << "}"; static_cast<int>(color.b) << ", " << static_cast<int>(color.a) << "}";
return out; return out;
} }
std::ostream& operator<<(std::ostream& out, const std::vector<int> ints)
{
out << "{ ";
for (int ii : ints)
{
out << ii << " ";
}
out << "}";
return out;
}

View File

@ -43,6 +43,7 @@ namespace sfw
SDL_Texture* get_filled_texture(SDL_Renderer*, glm::vec2, const SDL_Color&, Uint32 = SDL_PIXELFORMAT_RGBA32); SDL_Texture* get_filled_texture(SDL_Renderer*, glm::vec2, const SDL_Color&, Uint32 = SDL_PIXELFORMAT_RGBA32);
SDL_Texture* get_filled_texture(SDL_Renderer*, glm::vec2, SDL_Texture*, Uint32 = SDL_PIXELFORMAT_RGBA32); SDL_Texture* get_filled_texture(SDL_Renderer*, glm::vec2, SDL_Texture*, Uint32 = SDL_PIXELFORMAT_RGBA32);
SDL_Texture* duplicate_texture(SDL_Renderer*, SDL_Texture*, Uint32 = SDL_PIXELFORMAT_RGBA32); SDL_Texture* duplicate_texture(SDL_Renderer*, SDL_Texture*, Uint32 = SDL_PIXELFORMAT_RGBA32);
SDL_Texture* duplicate_texture(SDL_Renderer*, SDL_Texture*, const glm::vec2&, Uint32 = SDL_PIXELFORMAT_RGBA32);
SDL_Texture* get_remapped_texture( SDL_Texture* get_remapped_texture(
SDL_Renderer*, SDL_Texture*, const std::map<SDL_Color, SDL_Color>&, Uint32 = SDL_PIXELFORMAT_RGBA32); SDL_Renderer*, SDL_Texture*, const std::map<SDL_Color, SDL_Color>&, Uint32 = SDL_PIXELFORMAT_RGBA32);
SDL_Texture* get_remapped_texture( SDL_Texture* get_remapped_texture(
@ -120,5 +121,6 @@ std::ostream& operator<<(std::ostream&, const glm::vec2&);
bool operator<(const SDL_Color& color_1, const SDL_Color& color_2); bool operator<(const SDL_Color& color_1, const SDL_Color& color_2);
bool operator==(const SDL_Color& color_1, const SDL_Color& color_2); bool operator==(const SDL_Color& color_1, const SDL_Color& color_2);
std::ostream& operator<<(std::ostream&, const SDL_Color&); std::ostream& operator<<(std::ostream&, const SDL_Color&);
std::ostream& operator<<(std::ostream&, const std::vector<int>);
#endif #endif