#define STBI_ONLY_GIF
#define STBI_ONLY_PNG
#define STBI_NO_FAILURE_STRINGS
#define STBI_NO_STDIO
#define STB_IMAGE_IMPLEMENTATION
#include "ui/imgui/stb_image.h"
#include "ui/imgui/imgui.h"
#include "ui/imgui/imgui_impl_dx9.h"
void c_gif_image::init( void* p_data, int size ) {
textures.clear( );
data = stbi_load_gif_from_memory( ( stbi_uc* )p_data, size, &delays, &x, &y, &z, &comp, 0 );
}
void c_gif_image::init(const char* path) {
FILE* pf = fopen(path, "rb");
if (!pf)
return;
fseek(pf, 0L, SEEK_END);
auto size = (int)ftell(pf);
auto data = malloc(size);
fseek(pf, 0L, SEEK_SET);
fread(data, size, 1, pf);
fclose(pf);
init(data, size);
}
void c_gif_image::draw(ImDrawList* list, ImVec2 pos) {
float time = ImGui::GetTime();
if (z != 0) {
if (time > old_time) {
old_time = time + *delays * 0.001f;
frame++;
}
if ((int)frame >= z)
frame = 0;
}
else
frame = 0;
if (!textures[frame])
textures[frame] = ImGui_CreateTextureRGBA(x, y, data + x * y * comp * frame);
list->AddImage(textures[frame], pos, ImVec2(pos.x + x / 2, pos.y + y / 2));
}