GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
IconsHolder.cpp
Go to the documentation of this file.
1#include "IconsHolder.h"
2
3using namespace std;
4
5namespace gui_framework
6{
7 namespace utility
8 {
9 IconsHolder::IconsHolder(uint16_t imagesWidth, uint16_t imagesHeight, size_t count) :
11 (
12 imagesWidth,
13 imagesHeight,
14 count
15 )
16 {
17
18 }
19
20 HICON IconsHolder::getIcon(const filesystem::path& pathToIcon) const
21 {
22 return any_cast<HICON>(images.at(pathToIcon).data);
23 }
24
25 HICON IconsHolder::getIcon(uint16_t iconIndex) const
26 {
27 const any* result = nullptr;
28
29 for (const auto& [path, data] : images)
30 {
31 if (data.index == iconIndex)
32 {
33 result = &data.data;
34 }
35 }
36
37 if (!result)
38 {
39 throw out_of_range("Wrong index");
40 }
41
42 return any_cast<HICON>(*result);
43 }
44
45 uint16_t IconsHolder::addImage(const filesystem::path& pathToIcon)
46 {
47 return BaseLoadableHolder::insertImage(pathToIcon, imageType::icon);
48 }
49 }
50}
Base class for all visual asset loaders.
virtual uint16_t insertImage(const std::filesystem::path &pathToImage, imageType type) final
std::unordered_map< std::wstring, imageData > images
uint16_t addImage(const std::filesystem::path &pathToIcon) override
IconsHolder(uint16_t imagesWidth, uint16_t imagesHeight, size_t count=standard_sizes::defaultImagesCount)
HICON getIcon(const std::filesystem::path &pathToIcon) const