-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Wrapper] Updated wrappers and implemented Canvas event listeners in …
…C99 wrapper. - Moved event listener wrapper logic into EventListenerContainer template. - Added wrapper callback types and functions for new Canvas event listener interface. - Implemented canvas event handling in C99 wrapper. - Updated auto-generated C# and Go wrappers.
- Loading branch information
1 parent
bc8dc02
commit 2dca042
Showing
7 changed files
with
265 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* C99EventListenerContainer.h | ||
* | ||
* Copyright (c) 2015 Lukas Hermanns. All rights reserved. | ||
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt). | ||
*/ | ||
|
||
#ifndef LLGL_C99_EVENT_LISTENER_CONTAINER_H | ||
#define LLGL_C99_EVENT_LISTENER_CONTAINER_H | ||
|
||
|
||
#include "../../sources/Core/Assertion.h" | ||
#include <unordered_map> | ||
#include <mutex> | ||
#include <memory> | ||
#include <limits.h> | ||
|
||
|
||
template <typename TEventListener, typename TWrapperCallbacks> | ||
class EventListenerContainer | ||
{ | ||
|
||
public: | ||
|
||
using TEventListenerSPtr = std::shared_ptr<TEventListener>; | ||
|
||
std::pair<int, TEventListenerSPtr> Create(const TWrapperCallbacks* callbacks) | ||
{ | ||
std::lock_guard<std::mutex> guard{ mutex_ }; | ||
LLGL_ASSERT(idCounter_ < INT_MAX); | ||
const int id = ++idCounter_; | ||
std::pair<int, TEventListenerSPtr> result{ id, std::make_shared<TEventListener>(callbacks) }; | ||
eventListeners_.insert(result); | ||
return result; | ||
} | ||
|
||
TEventListenerSPtr Release(int id) | ||
{ | ||
std::lock_guard<std::mutex> guard{ mutex_ }; | ||
auto it = eventListeners_.find(id); | ||
if (it != eventListeners_.end()) | ||
{ | ||
TEventListenerSPtr result = std::move(it->second); | ||
eventListeners_.erase(it); | ||
return result; | ||
} | ||
return nullptr; | ||
} | ||
|
||
private: | ||
|
||
int idCounter_ = 0; | ||
std::unordered_map<int, TEventListenerSPtr> eventListeners_; | ||
std::mutex mutex_; | ||
|
||
}; | ||
|
||
|
||
#endif | ||
|
||
|
||
|
||
// ================================================================================ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.