|
|
|
@ -289,7 +289,7 @@ public: |
|
|
|
|
Create(w, h); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
olcSprite(std::wstring sFile) |
|
|
|
|
olcSprite(std::string sFile) |
|
|
|
|
{ |
|
|
|
|
if (!Load(sFile)) |
|
|
|
|
Create(8, 8); |
|
|
|
@ -370,30 +370,15 @@ public: |
|
|
|
|
|
|
|
|
|
bool Save(std::string sFile) |
|
|
|
|
{ |
|
|
|
|
FILE *f = nullptr; |
|
|
|
|
std::ofstream f(sFile.c_str(), std::ios::out | std::ios::binary); |
|
|
|
|
if (!f.is_open()) return false; |
|
|
|
|
|
|
|
|
|
char buff[256]; |
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
size_t t; |
|
|
|
|
wcstombs_s(&t, buff, sFile.c_str(), 256); |
|
|
|
|
#else |
|
|
|
|
wcstombs(buff, sFile.c_str(), 256); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
fopen_s(&f, buff, "wb"); |
|
|
|
|
#else |
|
|
|
|
f = std::fopen(buff, "wb"); |
|
|
|
|
#endif |
|
|
|
|
if (f == nullptr) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
fwrite(&nWidth, sizeof(int), 1, f); |
|
|
|
|
fwrite(&nHeight, sizeof(int), 1, f); |
|
|
|
|
fwrite(m_Colours, sizeof(short), nWidth * nHeight, f); |
|
|
|
|
fwrite(m_Glyphs, sizeof(wchar_t), nWidth * nHeight, f); |
|
|
|
|
f.write((char*)&nWidth, sizeof(int)); |
|
|
|
|
f.write((char*)&nHeight, sizeof(int)); |
|
|
|
|
f.write((char*)m_Colours, sizeof(short) * nWidth * nHeight); |
|
|
|
|
f.write((char*)m_Glyphs, sizeof(wchar_t) * nWidth * nHeight); |
|
|
|
|
|
|
|
|
|
fclose(f); |
|
|
|
|
f.close(); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -405,32 +390,20 @@ public: |
|
|
|
|
nWidth = 0; |
|
|
|
|
nHeight = 0; |
|
|
|
|
|
|
|
|
|
FILE *f = nullptr; |
|
|
|
|
char buff[256]; |
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
size_t t; |
|
|
|
|
wcstombs_s(&t, buff, sFile.c_str(), 256); |
|
|
|
|
#else |
|
|
|
|
wcstombs(buff, sFile.c_str(), 256); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
fopen_s(&f, buff, "rb"); |
|
|
|
|
#else |
|
|
|
|
f = std::fopen(buff, "rb"); |
|
|
|
|
#endif |
|
|
|
|
if (f == nullptr) |
|
|
|
|
return false; |
|
|
|
|
std::ifstream f(sFile.c_str(), std::ios::in | std::ios::binary); |
|
|
|
|
if (!f.is_open()) return false; |
|
|
|
|
|
|
|
|
|
fread(&nWidth, sizeof(int), 1, f); |
|
|
|
|
fread(&nHeight, sizeof(int), 1, f); |
|
|
|
|
// get file data
|
|
|
|
|
f.read ((char*)&nWidth, sizeof(int)); |
|
|
|
|
f.read ((char*)&nHeight, sizeof(int)); |
|
|
|
|
|
|
|
|
|
Create(nWidth, nHeight); |
|
|
|
|
|
|
|
|
|
fread(m_Colours, sizeof(short), nWidth * nHeight, f); |
|
|
|
|
fread(m_Glyphs, sizeof(wchar_t), nWidth * nHeight, f); |
|
|
|
|
f.read ((char*)m_Colours, sizeof(short) * nWidth * nHeight); |
|
|
|
|
f.read ((char*)m_Glyphs, sizeof(wchar_t) * nWidth * nHeight); |
|
|
|
|
|
|
|
|
|
f.close(); |
|
|
|
|
|
|
|
|
|
fclose(f); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|