1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-24 07:40:22 +01:00

Internals: Using ImU64 for internal ImFile api so we can later wrap them to fseeko/ftello//_fseeki64/_ftelli64 (#2734)

This commit is contained in:
omar 2019-11-20 10:40:14 +01:00
parent ecbedc8c26
commit a899c1e570
2 changed files with 17 additions and 15 deletions

View File

@ -1395,10 +1395,12 @@ ImFileHandle ImFileOpen(const char* filename, const char* mode)
return fopen(filename, mode);
#endif
}
int ImFileClose(ImFileHandle f) { return fclose(f); }
size_t ImFileGetSize(ImFileHandle f) { long off = 0, sz = 0; return ((off = ftell(f)) != -1 && !fseek(f, 0, SEEK_END) && (sz = ftell(f)) != -1 && !fseek(f, off, SEEK_SET)) ? (size_t)sz : (size_t)-1; }
size_t ImFileRead(void* data, size_t sz, size_t count, ImFileHandle f) { return fread(data, sz, count, f); }
size_t ImFileWrite(const void* data, size_t sz, size_t count, ImFileHandle f) { return fwrite(data, sz, count, f); }
// We should in theory be using fseeko()/ftello() with off_t and _fseeki64()/_ftelli64() with __int64, waiting for the PR that does that in a very portable pre-C++11 zero-warnings way.
bool ImFileClose(ImFileHandle f) { return fclose(f) == 0; }
ImU64 ImFileGetSize(ImFileHandle f) { long off = 0, sz = 0; return ((off = ftell(f)) != -1 && !fseek(f, 0, SEEK_END) && (sz = ftell(f)) != -1 && !fseek(f, off, SEEK_SET)) ? (ImU64)sz : (ImU64)-1; }
ImU64 ImFileRead(void* data, ImU64 sz, ImU64 count, ImFileHandle f) { return fread(data, (size_t)sz, (size_t)count, f); }
ImU64 ImFileWrite(const void* data, ImU64 sz, ImU64 count, ImFileHandle f) { return fwrite(data, (size_t)sz, (size_t)count, f); }
#endif // #ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
// Helper: Load file content into memory
@ -1413,7 +1415,7 @@ void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_f
if ((f = ImFileOpen(filename, mode)) == NULL)
return NULL;
size_t file_size = ImFileGetSize(f);
size_t file_size = (size_t)ImFileGetSize(f);
if (file_size == (size_t)-1)
{
ImFileClose(f);
@ -9076,7 +9078,7 @@ void ImGui::LogText(const char* fmt, ...)
{
g.LogBuffer.Buf.resize(0);
g.LogBuffer.appendfv(fmt, args);
ImFileWrite(g.LogBuffer.c_str(), sizeof(char), (size_t)g.LogBuffer.size(), g.LogFile);
ImFileWrite(g.LogBuffer.c_str(), sizeof(char), (ImU64)g.LogBuffer.size(), g.LogFile);
}
else
{

View File

@ -266,19 +266,19 @@ static inline ImVec4 operator*(const ImVec4& lhs, const ImVec4& rhs)
#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
typedef void* ImFileHandle;
static inline ImFileHandle ImFileOpen(const char*, const char*) { return NULL; }
static inline int ImFileClose(ImFileHandle) { return -1; }
static inline size_t ImFileGetSize(ImFileHandle) { return (size_t)-1; }
static inline size_t ImFileRead(void*, size_t, size_t, ImFileHandle) { return 0; }
static inline size_t ImFileWrite(const void*, size_t, size_t, ImFileHandle) { return 0; }
static inline bool ImFileClose(ImFileHandle) { return false; }
static inline ImU64 ImFileGetSize(ImFileHandle) { return (ImU64)-1; }
static inline ImU64 ImFileRead(void*, ImU64, ImU64, ImFileHandle) { return 0; }
static inline ImU64 ImFileWrite(const void*, ImU64, ImU64, ImFileHandle) { return 0; }
#endif
#ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
typedef FILE* ImFileHandle;
IMGUI_API ImFileHandle ImFileOpen(const char* filename, const char* mode);
IMGUI_API int ImFileClose(ImFileHandle file);
IMGUI_API size_t ImFileGetSize(ImFileHandle file);
IMGUI_API size_t ImFileRead(void* data, size_t size, size_t count, ImFileHandle file);
IMGUI_API size_t ImFileWrite(const void* data, size_t size, size_t count, ImFileHandle file);
IMGUI_API bool ImFileClose(ImFileHandle file);
IMGUI_API ImU64 ImFileGetSize(ImFileHandle file);
IMGUI_API ImU64 ImFileRead(void* data, ImU64 size, ImU64 count, ImFileHandle file);
IMGUI_API ImU64 ImFileWrite(const void* data, ImU64 size, ImU64 count, ImFileHandle file);
#else
#define IMGUI_DISABLE_TTY_FUNCTIONS // Can't use stdout, fflush if we are not using default file functions
#endif
@ -1512,7 +1512,7 @@ struct ImGuiTabItem
float Width; // Width currently displayed
float ContentWidth; // Width of actual contents, stored during BeginTabItem() call
ImGuiTabItem() { ID = Flags = 0; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = ContentWidth = 0.0f; }
ImGuiTabItem() { ID = 0; Flags = 0; LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; Offset = Width = ContentWidth = 0.0f; }
};
// Storage for a tab bar (sizeof() 92~96 bytes)