30 data(move(other.data))
41 const_cast<imageData&
>(other).data.reset();
50 data = move(other.data);
59 if (!data.has_value())
66 case imageType::bitmap:
67 DeleteObject(any_cast<HBITMAP>(data));
71 DestroyIcon(any_cast<HICON>(data));
74 case imageType::cursor:
75 DestroyCursor(any_cast<HCURSOR>(data));
81 json::JSONBuilder BaseLoadableHolder::getStructure()
const
83 using json::utility::jsonObject;
85 uint32_t codepage = ISerializable::getCodepage();
86 json::JSONBuilder builder(codepage);
88 vector<jsonObject> jsonImages;
90 object.data.push_back({
"imagesWidth"s,
static_cast<uint64_t
>(
imagesWidth) });
91 object.data.push_back({
"imagesHeight"s,
static_cast<uint64_t
>(
imagesHeight) });
93 for (
const auto& [path, data] :
images)
98 image.data.push_back({
"type"s,
static_cast<uint64_t
>(data.type) });
100 json::utility::appendArray(move(image), jsonImages);
103 object.data.push_back({
"images"s, move(jsonImages) });
105 builder.append(
"imageHolder"s, move(
object));
112 HBITMAP image =
static_cast<HBITMAP
>(LoadImageW(
nullptr, pathToImage.wstring().data(),
static_cast<uint32_t
>(type),
imagesWidth,
imagesHeight, LR_LOADFROMFILE));
113 uint16_t resultIndex;
117 case imageType::bitmap:
118 resultIndex =
images.emplace(pathToImage,
imageData(ImageList_Add(
imageList, image, NULL), type, image)).first->second.index;
121 case imageType::icon:
122 resultIndex =
images.emplace(pathToImage,
imageData(ImageList_AddIcon(
imageList,
reinterpret_cast<HICON
>(image)), type,
reinterpret_cast<HICON
>(image))).first->second.index;
125 case imageType::cursor:
126 resultIndex =
images.emplace(pathToImage,
imageData(ImageList_AddIcon(
imageList,
reinterpret_cast<HCURSOR
>(image)), type,
reinterpret_cast<HCURSOR
>(image))).first->second.index;
131 resultIndex =
static_cast<uint16_t
>(-1);
151 auto it =
images.find(pathToImage);
155 ImageList_Remove(
imageList, it->second.index);
163 for (
const auto& [key, value] :
images)
165 if (value.index == imageIndex)
178 return images.contains(pathToImage);
193 return images.at(pathToImage).index;
198 return images.at(pathToImage).type;
203 for (
const auto& [key, value] :
images)
205 if (value.index == imageIndex)
211 throw out_of_range(format(
"Can't find imageType at {} index"sv, imageIndex));
221 return images.at(pathToImage).index;
226 for (
const auto& [key, value] :
images)
228 if (value.index == index)
234 throw out_of_range(format(
"Can't find image at {} index"sv, index));
239 vector<filesystem::path> imagesPaths;
241 imagesPaths.reserve(
images.size());
243 for (
const auto& [path, data] :
images)
245 imagesPaths.push_back(path);
253 vector<filesystem::path> imagesPaths;
255 imagesPaths.reserve(
images.size());
257 for (
const auto& [path, data] :
images)
259 imagesPaths.push_back(path);
277 return current.data.emplace_back(make_pair(
"imageHolder"s, move(this->getStructure()[
"imageHolder"])));
IBaseConstForwardIterator implementation for BaseLoadableHolder.
IBaseForwardIterator implementation for BaseLoadableHolder.
virtual iterators::loadable_const_forward_iterator cend() const noexcept final override
virtual uint16_t getImagesWidth() const final
virtual iterators::loadable_const_forward_iterator cbegin() const noexcept final override
virtual ~BaseLoadableHolder()
virtual uint16_t insertImage(const std::filesystem::path &pathToImage, imageType type) final
BaseLoadableHolder(uint16_t imagesWidth, uint16_t imagesHeight, size_t count=standard_sizes::defaultImagesCount)
virtual imageType getImageType(const std::filesystem::path &pathToImage) const final
std::unordered_map< std::wstring, imageData > images
virtual iterators::loadable_forward_iterator begin() noexcept final override
Can't be modified.
virtual void removeImage(const std::filesystem::path &pathToImage) final
virtual uint16_t operator[](const std::filesystem::path &pathToImage) const final
virtual HIMAGELIST getImageList() const final
virtual uint16_t getImagesHeight() const final
virtual std::pair< std::string, json::utility::jsonObject::variantType > & loadBaseLoadableHolderStructure(json::utility::jsonObject ¤t) const final
virtual uint16_t getImageIndex(const std::filesystem::path &pathToImage) const final
virtual bool contains(const std::filesystem::path &pathToImage) const final
virtual iterators::loadable_forward_iterator end() noexcept final override
string to_string(wstring_view stringToConvert, uint32_t codepage)
imageData(uint16_t index, imageType type, std::any &&data)
imageData & operator=(const imageData &other)