Files
metin2-client/src/platform/EterLib/GrpSubImage.cpp
T
shenleiandClaude Opus 5.5 a46093104c layout: restructure into src/ tests/ android/ scripts/ tools/
- extension/src/{port,platform,codepage} -> src/; native_render -> src/host
  (+ dxt, shaders/); libgr2 -> src/gr2; extension/third_party -> third_party
- extension/tests -> tests/port, libgr2/tests -> tests/gr2
- android-native -> android (build.sh, push-client.sh moved in)
- script -> scripts; tools/40250 -> tools/server; oracle -> tools/granny-oracle;
  perf tools -> tools/perf
- all build trees under build/ (native, release, android, port-gate)
- xrender:: CMake aliases -> mt::; port-map ledger impl paths rewritten

No code changes. ctest 15/15, port_gate macos+android PASS, port_map check 0 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 19:08:19 +09:00

101 lines
3.2 KiB
C++

#include "EterLib/StdAfx.h"
#include "EterLib/GrpSubImage.h"
#include "EterLib/ResourceManager.h"
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <map>
#include <sstream>
#include <string>
char CGraphicSubImage::m_SearchPath[256] = "D:/Ymir Work/UI/";
auto CGraphicSubImage::Type() -> TType
{
static TType type = StringToType("CGraphicSubImage");
return type;
}
CGraphicSubImage::CGraphicSubImage(const char* name) : CGraphicImage(name) {}
CGraphicSubImage::~CGraphicSubImage() { m_roImage.Clear(); }
bool CGraphicSubImage::CreateDeviceObjects()
{
if (m_roImage.IsNull()) return false;
m_imageTexture.CreateFromTexturePointer(m_roImage->GetTexturePointer());
return true;
}
void CGraphicSubImage::SetImagePointer(CGraphicImage* image)
{
m_roImage.SetPointer(image);
CreateDeviceObjects();
}
bool CGraphicSubImage::SetImageFileName(const char* name)
{
CResource* resource = CResourceManager::Instance().GetResourcePointer(name);
if (!resource || !resource->IsType(CGraphicImage::Type())) return false;
SetImagePointer(static_cast<CGraphicImage*>(resource));
return true;
}
void CGraphicSubImage::SetRectPosition(int left, int top, int right, int bottom)
{
m_rect = {left, top, right, bottom};
}
void CGraphicSubImage::SetRectReference(const RECT& rect) { m_rect = rect; }
void CGraphicSubImage::SetSearchPath(const char* path)
{
if (!path) return;
std::strncpy(m_SearchPath, path, sizeof(m_SearchPath) - 1);
m_SearchPath[sizeof(m_SearchPath) - 1] = 0;
}
bool CGraphicSubImage::OnLoad(int size, const void* bytes)
{
if (!bytes || size <= 0) return false;
std::istringstream input(std::string(static_cast<const char*>(bytes), static_cast<size_t>(size)));
std::map<std::string, std::string> tokens;
std::string line;
while (std::getline(input, line)) {
std::istringstream fields(line);
std::string key, value;
if (!(fields >> key >> value)) continue;
if (!value.empty() && value.front() == '"') {
value.erase(0, 1);
if (!value.empty() && value.back() == '"') value.pop_back();
}
std::transform(key.begin(), key.end(), key.begin(), [](unsigned char c) { return std::tolower(c); });
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char c) { return std::tolower(c); });
tokens[key] = value;
}
if (tokens["title"] != "subimage" || tokens["image"].empty()) return false;
std::string image_path;
if (tokens["version"] == "2.0") {
const std::string parent = GetFileNameString();
const auto slash = parent.find_last_of("\\/");
image_path = slash == std::string::npos ? tokens["image"] : parent.substr(0, slash + 1) + tokens["image"];
} else {
image_path = std::string(m_SearchPath) + tokens["image"];
}
if (!SetImageFileName(image_path.c_str())) return false;
SetRectPosition(std::atoi(tokens["left"].c_str()), std::atoi(tokens["top"].c_str()),
std::atoi(tokens["right"].c_str()), std::atoi(tokens["bottom"].c_str()));
return true;
}
void CGraphicSubImage::OnClear()
{
m_roImage.Clear();
m_imageTexture.Destroy();
m_rect = {0, 0, 0, 0};
}
bool CGraphicSubImage::OnIsEmpty() const { return m_roImage.IsNull() || m_roImage->IsEmpty(); }
bool CGraphicSubImage::OnIsType(TType type) { return type == Type() || CGraphicImage::OnIsType(type); }