8#pragma warning(disable: 6001)
16 void ImageButton::drawImage()
20 function<HANDLE()> load;
22 if (!pathToImage.empty())
26 return LoadImageW(
nullptr, pathToImage.wstring().data(),
static_cast<uint32_t
>(iType), imageWidth, imageHeight, LR_LOADFROMFILE);
29 else if (imageResource)
33 return LoadImageW(
GUIFramework::get()[resourceModuleName], MAKEINTRESOURCE(imageResource),
static_cast<uint32_t
>(iType), imageWidth, imageHeight, NULL);
46 resourceType = IMAGE_ICON;
49 case imageType::bitmap:
52 resourceType = IMAGE_BITMAP;
65 image =
static_cast<HICON
>(imageHandle);
68 case imageType::bitmap:
69 image =
static_cast<HBITMAP
>(imageHandle);
80 SendMessageW(
handle, BM_SETIMAGE, resourceType,
reinterpret_cast<LPARAM
>(imageHandle));
92 SendMessageW(
handle, BM_SETIMAGE, resourceType,
reinterpret_cast<LPARAM
>(imageHandle));
101 ImageButton::ImageButton(
const wstring& buttonName,
const filesystem::path& pathToImage, drawingType dType,
imageType iType, uint16_t imageWidth, uint16_t imageHeight,
const utility::ComponentSettings& settings, BaseComposite* parent,
const function<
void()>& onClick) :
107 styles::DefaultButtonStyles(),
116 pathToImage(pathToImage),
119 imageWidth(imageWidth),
120 imageHeight(imageHeight)
125 ImageButton::ImageButton(
const wstring& buttonName,
const filesystem::path& pathToImage, drawingType dType, imageType iType, uint16_t imageWidth, uint16_t imageHeight,
const utility::ComponentSettings& settings, BaseComposite* parent,
const string& functionName,
const string& moduleName) :
131 styles::DefaultButtonStyles(),
141 pathToImage(pathToImage),
144 imageWidth(imageWidth),
145 imageHeight(imageHeight)
150 ImageButton::ImageButton(
const wstring& buttonName, uint32_t imageResources, drawingType dType, imageType iType, uint16_t imageWidth, uint16_t imageHeight,
const utility::ComponentSettings& settings, BaseComposite* parent,
const function<
void()>& onClick,
const string& resourceModuleName) :
156 styles::DefaultButtonStyles(),
165 imageResource(imageResource),
166 resourceModuleName(resourceModuleName),
169 imageWidth(imageWidth),
170 imageHeight(imageHeight)
175 ImageButton::ImageButton(
const wstring& buttonName, uint32_t imageResources, drawingType dType, imageType iType, uint16_t imageWidth, uint16_t imageHeight,
const utility::ComponentSettings& settings, BaseComposite* parent,
const string& functionName,
const string& moduleName,
const string& resourceModuleName) :
181 styles::DefaultButtonStyles(),
191 imageResource(imageResource),
192 resourceModuleName(resourceModuleName),
195 imageWidth(imageWidth),
196 imageHeight(imageHeight)
201 void ImageButton::setImage(
const filesystem::path& pathToImage, drawingType dType, imageType iType, uint16_t imageWidth, uint16_t imageHeight)
203 this->pathToImage = pathToImage;
206 this->imageWidth = imageWidth;
207 this->imageHeight = imageHeight;
209 resourceModuleName.clear();
210 imageResource = NULL;
215 void ImageButton::setImage(uint32_t imageResource, drawingType dType, imageType iType, uint16_t imageWidth, uint16_t imageHeight,
const string& resourceModuleName)
217 this->imageResource = imageResource;
218 this->resourceModuleName = resourceModuleName;
221 this->imageWidth = imageWidth;
222 this->imageHeight = imageHeight;
229 const filesystem::path& ImageButton::getPathToImage()
const
234 uint16_t ImageButton::getImageWidth()
const
239 uint16_t ImageButton::getImageHeight()
const
254 size_t ImageButton::getHash()
const
259 json::JSONBuilder ImageButton::getStructure()
const
261 using json::utility::jsonObject;
263 json::JSONBuilder builder = BaseButton::getStructure();
264 jsonObject& current = get<jsonObject>(builder[utility::to_string(windowName, ISerializable::getCodepage())]);
266 current.setUnsignedInt(
"imageWidth"s,
static_cast<uint64_t
>(imageWidth));
267 current.setUnsignedInt(
"imageHeight"s,
static_cast<uint64_t
>(imageHeight));
269 current.setString(
"pathToImage", utility::getStringFromRawPath(pathToImage));
270 current.setString(
"resourceModuleName", resourceModuleName);
272 current.setUnsignedInt(
"drawingType"s,
static_cast<uint64_t
>(dType));
273 current.setUnsignedInt(
"imageType"s,
static_cast<uint64_t
>(iType));
274 current.setUnsignedInt(
"imageResource", imageResource);
279 ImageButton::~ImageButton()
283 DeleteObject(any_cast<HBITMAP>(image));
285 catch (
const bad_any_cast&)
287 DeleteObject(any_cast<HICON>(image));
static GUIFramework & get()
Singleton instance access.
void removeStyle(HWND handle, LONG_PTR styleToRemove)
Remove WinAPI style.
void appendStyle(HWND handle, LONG_PTR newStyle)
Append WinAPI style.
utility::BaseLoadableHolder::imageType imageType