mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 20:18:47 +02:00
Moved IM_NEW, IM_DELETE helpers to imgui.h for convenient use by back-ends and user code.
This commit is contained in:
@ -165,15 +165,6 @@ static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a)
|
||||
static inline float ImLinearSweep(float current, float target, float speed) { if (current < target) return ImMin(current + speed, target); if (current > target) return ImMax(current - speed, target); return current; }
|
||||
static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); }
|
||||
|
||||
// We call C++ constructor on own allocated memory via the placement "new(ptr) Type()" syntax.
|
||||
// Defining a custom placement new() with a dummy parameter allows us to bypass including <new> which on some platforms complains when user has disabled exceptions.
|
||||
struct ImNewPlacementDummy {};
|
||||
inline void* operator new(size_t, ImNewPlacementDummy, void* ptr) { return ptr; }
|
||||
inline void operator delete(void*, ImNewPlacementDummy, void*) {} // This is only required so we can use the symetrical new()
|
||||
#define IM_PLACEMENT_NEW(_PTR) new(ImNewPlacementDummy(), _PTR)
|
||||
#define IM_NEW(_TYPE) new(ImNewPlacementDummy(), ImGui::MemAlloc(sizeof(_TYPE))) _TYPE
|
||||
template <typename T> void IM_DELETE(T*& p) { if (p) { p->~T(); ImGui::MemFree(p); p = NULL; } }
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user