GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
Draw.cpp
Go to the documentation of this file.
1#include "Draw.h"
2
3using namespace std;
4
5template<typename T>
6bool drawImplementation(const gui_framework::BaseWindow* window, const gui_framework::utility::BaseLoadableHolder& holder, int x, int y, const T& index);
7
8namespace gui_framework
9{
10 namespace utility
11 {
12 namespace paint
13 {
14 GUI_FRAMEWORK_API_FUNCTION bool drawImageByIndex(const BaseWindow* window, const ImagesHolder& holder, int x, int y, uint16_t index)
15 {
16 return drawImplementation(window, holder, x, y, index);
17 }
18
19 GUI_FRAMEWORK_API_FUNCTION bool drawImageByPath(const BaseWindow* window, const ImagesHolder& holder, int x, int y, const filesystem::path& pathToImage)
20 {
21 return drawImplementation(window, holder, x, y, pathToImage);
22 }
23
24 GUI_FRAMEWORK_API_FUNCTION bool drawIconByIndex(const BaseWindow* window, const IconsHolder& holder, int x, int y, uint16_t index)
25 {
26 return drawImplementation(window, holder, x, y, index);
27 }
28
29 GUI_FRAMEWORK_API_FUNCTION bool drawIconByPath(const BaseWindow* window, const IconsHolder& holder, int x, int y, const filesystem::path& pathToImage)
30 {
31 return drawImplementation(window, holder, x, y, pathToImage);
32 }
33 }
34 }
35}
36
37template<typename T>
38bool drawImplementation(const gui_framework::BaseWindow* window, const gui_framework::utility::BaseLoadableHolder& holder, int x, int y, const T& index)
39{
40 PAINTSTRUCT paint = {};
41 HWND handle = window->getHandle();
42 HDC deviceContext = BeginPaint(handle, &paint);
43 LPARAM drawData = NULL;
44 uint32_t flags = DSS_NORMAL;
45 bool result = false;
46
47 try
48 {
49 const gui_framework::utility::ImagesHolder& imagesHolder = dynamic_cast<const gui_framework::utility::ImagesHolder&>(holder);
50
51 drawData = reinterpret_cast<LPARAM>(imagesHolder.getImage(index));
52
53 flags |= DST_BITMAP;
54 }
55 catch (const bad_cast&)
56 {
57 const gui_framework::utility::IconsHolder& iconsHolder = dynamic_cast<const gui_framework::utility::IconsHolder&>(holder);
58
59 drawData = reinterpret_cast<LPARAM>(iconsHolder.getIcon(index));
60
61 flags |= DST_ICON;
62 }
63
64 result = DrawStateW(deviceContext, NULL, nullptr, drawData, NULL, x, y, holder.getImagesWidth(), holder.getImagesHeight(), flags);
65
66 ReleaseDC(handle, deviceContext);
67
68 EndPaint(handle, &paint);
69
70 return result;
71}
bool drawImplementation(const gui_framework::BaseWindow *window, const gui_framework::utility::BaseLoadableHolder &holder, int x, int y, const T &index)
Definition Draw.cpp:38
#define GUI_FRAMEWORK_API_FUNCTION
Base class for composite windows.
Definition BaseWindow.h:13
Base class for all visual asset loaders.
virtual uint16_t getImagesWidth() const final
virtual uint16_t getImagesHeight() const final
HICON getIcon(const std::filesystem::path &pathToIcon) const
HBITMAP getImage(const std::filesystem::path &pathToImage) const
GUI_FRAMEWORK_API_FUNCTION bool drawIconByIndex(const BaseWindow *window, const IconsHolder &holder, int x, int y, uint16_t index)
Draw single icon from holder. Multiple calls doesn't work. Better use BaseWindow drawing.
Definition Draw.cpp:24
GUI_FRAMEWORK_API_FUNCTION bool drawImageByPath(const BaseWindow *window, const ImagesHolder &holder, int x, int y, const filesystem::path &pathToImage)
Definition Draw.cpp:19
GUI_FRAMEWORK_API_FUNCTION bool drawIconByPath(const BaseWindow *window, const IconsHolder &holder, int x, int y, const filesystem::path &pathToImage)
Definition Draw.cpp:29
GUI_FRAMEWORK_API_FUNCTION bool drawImageByIndex(const BaseWindow *window, const ImagesHolder &holder, int x, int y, uint16_t index)
Draw single image from holder. Multiple calls doesn't work. Better use BaseWindow drawing.
Definition Draw.cpp:14