CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
FxUISignal.h
Go to the documentation of this file.
1//
2// (C) Copyright 2005-2025 by Graebert GmbH.
3//
4// Permission to use, copy, modify, and distribute this software in
5// object code form for any purpose and without fee is hereby granted,
6// provided that the above copyright notice appears in all copies and
7// that both that copyright notice and the limited warranty and
8// restricted rights notice below appear in all supporting
9// documentation.
10//
11// GRAEBERT PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
12// GRAEBERT SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
13// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. GRAEBERT GMBH
14// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
15// UNINTERRUPTED OR ERROR FREE.
16
17#pragma once
18
20
21#include "FxUIObject.h"
22
26
28{
29public:
33 explicit CFxUIEmitScope( CFxUIObject* slot, CFxUIObject* pSender );
34
39
40private:
41 CFxUIObject* m_pSlot;
42
43 //..
44};
45
46#ifdef emit
47#undef emit
48#define FX_REDEFINE_EMIT
49#endif
50#ifdef slots
51#undef slots
52#define FX_REDEFINE_SLOTS
53#endif
54
55#ifdef max
56#undef max
57#endif
58
59#ifdef min
60#undef min
61#endif
62
63#include "slimsig/slimsig.h"
64#include "slimsig/connection.h"
65
66#ifdef XENON
67#include "XeThreadHelper.h"
68#endif
69
70using namespace slimsig;
71
72template <class> class CFxUISignal;
73
74template <class R, class ... Args>
75
81class COMMONUI_API CFxUISignal<R(Args...)> : public slimsig::signal<R(Args...)>
82{
83public:
84 using base = slimsig::signal<R(Args...)>;
85 using connection_type = typename base::Connection;
86 using base::connect;
87
91 CFxUISignal() = delete;
92
98 explicit CFxUISignal( CFxUIObject* sender )
99 {
100 m_pSender = sender;
101 }
102
108 template <class TReciver>
109 connection_type connect( CFxUIObject* reciver, void (TReciver::*method)() )
110 {
111 auto slot = [reciver, method, this](Args&&... args)
112 {
113 TReciver* r = dynamic_cast<TReciver*>( reciver );
114 if ( r )
115 {
116 CFxUIEmitScope scope( r, m_pSender );
117 (r->*method)();
118 }
119 };
120 return slimsig::signal<R(Args...)>::connect( slot );
121 }
122
129 template <class TReciver>
130 connection_type connect( TReciver* reciver, R (TReciver::*method)( Args... args ) )
131 {
132 auto slot = [reciver, method, this](Args&&... args) -> R
133 {
134 CFxUIEmitScope scope( dynamic_cast<CFxUIObject*>( reciver ), m_pSender );
135 return (reciver->*method)( args... );
136 };
137 return slimsig::signal<R(Args...)>::connect( slot );
138 }
139
145 connection_type connect( std::function<void( Args... )> function )
146 {
147 return slimsig::signal<R( Args... )>::connect( function );
148 }
149
157 void Emit(Args... args)
158 {
159 if ( m_pSender->signalsBlocked() )
160 return;
161#ifdef XENON
162 XeThreadHelper::PostToThread(XE_THREAD_EVENT, [&, args ...]() { slimsig::signal<R(Args...)>::emit(args...); });
163#else
164 slimsig::signal<R( Args... )>::emit( std::forward<Args&&>( args )... );
165#endif
166 }
167
168private:
169 CFxUIObject* m_pSender;
170
171 //..
172};
173
174#ifdef FX_REDEFINE_EMIT
175#define emit
176#endif
177#ifdef FX_REDEFINE_SLOTS
178#define slots
179#endif
180
#define COMMONUI_API
CFxUIEmitScope(CFxUIObject *slot, CFxUIObject *pSender)
connection_type connect(TReciver *reciver, R(TReciver::*method)(Args... args))
Definition FxUISignal.h:130
void Emit(Args... args)
Definition FxUISignal.h:157
connection_type connect(CFxUIObject *reciver, void(TReciver::*method)())
Definition FxUISignal.h:109
connection_type connect(std::function< void(Args...)> function)
Definition FxUISignal.h:145
CFxUISignal(CFxUIObject *sender)
Definition FxUISignal.h:98
typename base::Connection connection_type
Definition FxUISignal.h:85
slimsig::signal< R(Args...)> base
Definition FxUISignal.h:84