1010#include < CS2/Panorama/CImagePanel.h>
1111#include < MemoryPatterns/PatternTypes/PanoramaImagePanelPatternTypes.h>
1212
13- #include " PanoramaImagePanelContext.h"
14-
1513struct SvgImageParams {
1614 const char * imageUrl;
1715 int textureHeight{-1 };
1816 std::optional<cs2::Color> fillColor{};
1917};
2018
21- template <typename HookContext, typename Context = PanoramaImagePanelContext<HookContext> >
19+ template <typename HookContext>
2220struct PanoramaImagePanel {
2321 using RawType = cs2::CImagePanel;
2422
25- template <typename ... Args>
26- requires std::is_constructible_v<Context, Args...>
27- PanoramaImagePanel (Args&&... args) noexcept
28- : context{std::forward<Args>(args)...}
23+ PanoramaImagePanel (HookContext& hookContext, cs2::CImagePanel* panel) noexcept
24+ : hookContext{hookContext}
25+ , panel{panel}
2926 {
3027 }
3128
3229 [[nodiscard]] decltype (auto ) uiPanel() const noexcept
3330 {
34- return context .uiPanel ();
31+ return hookContext .uiPanel (panel ? panel-> uiPanel : nullptr );
3532 }
3633
3734 [[nodiscard]] cs2::ImageProperties* getImageProperties () const noexcept
3835 {
39- return context. hookContext .patternSearchResults ().template get <ImagePropertiesOffset>().of (context. panel ).get ();
36+ return hookContext.patternSearchResults ().template get <ImagePropertiesOffset>().of (panel).get ();
4037 }
4138
4239 [[nodiscard]] std::string_view getImagePath () const noexcept
4340 {
44- if (auto && imagePath = context. getImagePath () )
45- return imagePath;
41+ if (auto && imagePath = hookContext. patternSearchResults (). template get <OffsetToImagePath>(). of (panel). get (); imagePath && imagePath-> m_pString )
42+ return imagePath-> m_pString ;
4643 return {};
4744 }
4845
@@ -53,9 +50,6 @@ struct PanoramaImagePanel {
5350
5451 void setImageSvg (const SvgImageParams& params) const noexcept
5552 {
56- if (context.panel == nullptr )
57- return ;
58-
5953 const auto properties{getImageProperties ()};
6054 if (!properties)
6155 return ;
@@ -68,17 +62,18 @@ struct PanoramaImagePanel {
6862 properties->presentSvgAttributes |= 1 << static_cast <std::size_t >(cs2::SvgAttributeType::FillColor);
6963 }
7064
71- if (context. hookContext .patternSearchResults ().template get <SetImageFunctionPointer>())
72- context. hookContext .patternSearchResults ().template get <SetImageFunctionPointer>()(context. panel , params.imageUrl , nullptr , properties);
65+ if (hookContext.patternSearchResults ().template get <SetImageFunctionPointer>())
66+ hookContext.patternSearchResults ().template get <SetImageFunctionPointer>()(panel, params.imageUrl , nullptr , properties);
7367 }
7468
7569private:
7670 [[nodiscard]] decltype (auto ) uiScaleFactor() const
7771 {
78- const auto scale = context. uiPanel ().getUiScaleFactor ().valueOr (1 .0f );
72+ const auto scale = uiPanel ().getUiScaleFactor ().valueOr (1 .0f );
7973 assert (scale >= 0 .1f && scale <= 10 .0f && " Invalid UI scale factor" );
8074 return scale;
8175 }
8276
83- Context context;
77+ HookContext& hookContext;
78+ cs2::CImagePanel* panel;
8479};
0 commit comments