1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
|
/*
Copyright 2012-2020 David Robillard <d@drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef PUGL_PUGL_HPP
#define PUGL_PUGL_HPP
#include "pugl/pugl.h"
#include <cstdint>
#if defined(PUGL_HPP_THROW_FAILED_CONSTRUCTION)
# include <exception>
#elif defined(PUGL_HPP_ASSERT_CONSTRUCTION)
# include <cassert>
#endif
namespace pugl {
/**
@defgroup puglxx Pugl C++ API
Pugl C++ API wrapper.
@{
*/
namespace detail {
/// Free function for a C object
template<typename T>
using FreeFunc = void (*)(T*);
/// Generic C++ wrapper for a C object
template<class T, FreeFunc<T> Free>
class Wrapper
{
public:
Wrapper(const Wrapper&) = delete;
Wrapper& operator=(const Wrapper&) = delete;
Wrapper(Wrapper&& wrapper) noexcept
: _ptr{wrapper._ptr}
{
wrapper._ptr = nullptr;
}
Wrapper& operator=(Wrapper&& wrapper) noexcept
{
_ptr = wrapper._ptr;
wrapper._ptr = nullptr;
return *this;
}
~Wrapper() noexcept { Free(_ptr); }
T* cobj() noexcept { return _ptr; }
const T* cobj() const noexcept { return _ptr; }
protected:
explicit Wrapper(T* ptr) noexcept
: _ptr{ptr}
{}
private:
T* _ptr;
};
} // namespace detail
using Rect = PuglRect; ///< @copydoc PuglRect
/**
@defgroup eventsxx Events
@{
*/
/**
A strongly-typed analogue of PuglEvent.
This is bit-for-bit identical to the corresponding PuglEvent, so events are
simply cast to this type to avoid any copying overhead.
@tparam t The `type` field of the corresponding PuglEvent.
@tparam Base The specific struct type of the corresponding PuglEvent.
*/
template<PuglEventType t, class Base>
struct Event final : Base {
/// The type of the corresponding C event structure
using BaseEvent = Base;
/// The `type` field of the corresponding C event structure
static constexpr const PuglEventType type = t;
};
using Mod = PuglMod; ///< @copydoc PuglMod
using Mods = PuglMods; ///< @copydoc PuglMods
using Key = PuglKey; ///< @copydoc PuglKey
using EventType = PuglEventType; ///< @copydoc PuglEventType
using EventFlag = PuglEventFlag; ///< @copydoc PuglEventFlag
using EventFlags = PuglEventFlags; ///< @copydoc PuglEventFlags
using CrossingMode = PuglCrossingMode; ///< @copydoc PuglCrossingMode
/// @copydoc PuglEventCreate
using CreateEvent = Event<PUGL_CREATE, PuglEventCreate>;
/// @copydoc PuglEventDestroy
using DestroyEvent = Event<PUGL_DESTROY, PuglEventDestroy>;
/// @copydoc PuglEventConfigure
using ConfigureEvent = Event<PUGL_CONFIGURE, PuglEventConfigure>;
/// @copydoc PuglEventMap
using MapEvent = Event<PUGL_MAP, PuglEventMap>;
/// @copydoc PuglEventUnmap
using UnmapEvent = Event<PUGL_UNMAP, PuglEventUnmap>;
/// @copydoc PuglEventUpdate
using UpdateEvent = Event<PUGL_UPDATE, PuglEventUpdate>;
/// @copydoc PuglEventExpose
using ExposeEvent = Event<PUGL_EXPOSE, PuglEventExpose>;
/// @copydoc PuglEventClose
using CloseEvent = Event<PUGL_CLOSE, PuglEventClose>;
/// @copydoc PuglEventFocus
using FocusInEvent = Event<PUGL_FOCUS_IN, PuglEventFocus>;
/// @copydoc PuglEventFocus
using FocusOutEvent = Event<PUGL_FOCUS_OUT, PuglEventFocus>;
/// @copydoc PuglEventKey
using KeyPressEvent = Event<PUGL_KEY_PRESS, PuglEventKey>;
/// @copydoc PuglEventKey
using KeyReleaseEvent = Event<PUGL_KEY_RELEASE, PuglEventKey>;
/// @copydoc PuglEventText
using TextEvent = Event<PUGL_TEXT, PuglEventText>;
/// @copydoc PuglEventCrossing
using PointerInEvent = Event<PUGL_POINTER_IN, PuglEventCrossing>;
/// @copydoc PuglEventCrossing
using PointerOutEvent = Event<PUGL_POINTER_OUT, PuglEventCrossing>;
/// @copydoc PuglEventButton
using ButtonPressEvent = Event<PUGL_BUTTON_PRESS, PuglEventButton>;
/// @copydoc PuglEventButton
using ButtonReleaseEvent = Event<PUGL_BUTTON_RELEASE, PuglEventButton>;
/// @copydoc PuglEventMotion
using MotionEvent = Event<PUGL_MOTION, PuglEventMotion>;
/// @copydoc PuglEventScroll
using ScrollEvent = Event<PUGL_SCROLL, PuglEventScroll>;
/// @copydoc PuglEventClient
using ClientEvent = Event<PUGL_CLIENT, PuglEventClient>;
/// @copydoc PuglEventTimer
using TimerEvent = Event<PUGL_TIMER, PuglEventTimer>;
/// @copydoc PuglEventLoopEnter
using LoopEnterEvent = Event<PUGL_LOOP_ENTER, PuglEventLoopEnter>;
/// @copydoc PuglEventLoopLeave
using LoopLeaveEvent = Event<PUGL_LOOP_LEAVE, PuglEventLoopLeave>;
/**
@}
@defgroup statusxx Status
@{
*/
/// @copydoc PuglStatus
enum class Status {
success, ///< @copydoc PUGL_SUCCESS
failure, ///< @copydoc PUGL_FAILURE
unknownError, ///< @copydoc PUGL_UNKNOWN_ERROR
badBackend, ///< @copydoc PUGL_BAD_BACKEND
badConfiguration, ///< @copydoc PUGL_BAD_CONFIGURATION
badParameter, ///< @copydoc PUGL_BAD_PARAMETER
backendFailed, ///< @copydoc PUGL_BACKEND_FAILED
registrationFailed, ///< @copydoc PUGL_REGISTRATION_FAILED
realizeFailed, ///< @copydoc PUGL_REALIZE_FAILED
setFormatFailed, ///< @copydoc PUGL_SET_FORMAT_FAILED
createContextFailed, ///< @copydoc PUGL_CREATE_CONTEXT_FAILED
unsupportedType, ///< @copydoc PUGL_UNSUPPORTED_TYPE
};
static_assert(Status(PUGL_UNSUPPORTED_TYPE) == Status::unsupportedType, "");
/// @copydoc puglStrerror
inline const char*
strerror(const Status status) noexcept
{
return puglStrerror(static_cast<PuglStatus>(status));
}
/**
@}
@defgroup worldxx World
@{
*/
/// @copydoc PuglWorldType
enum class WorldType {
program, ///< @copydoc PUGL_PROGRAM
module, ///< @copydoc PUGL_MODULE
};
static_assert(WorldType(PUGL_MODULE) == WorldType::module, "");
/// @copydoc PuglWorldFlag
enum class WorldFlag {
threads = PUGL_WORLD_THREADS, ///< @copydoc PUGL_WORLD_THREADS
};
static_assert(WorldFlag(PUGL_WORLD_THREADS) == WorldFlag::threads, "");
using WorldFlags = PuglWorldFlags; ///< @copydoc PuglWorldFlags
#if defined(PUGL_HPP_THROW_FAILED_CONSTRUCTION)
/// An exception thrown when construction fails
class FailedConstructionError : public std::exception
{
public:
FailedConstructionError(const char* const msg) noexcept
: _msg{msg}
{}
virtual const char* what() const noexcept override;
private:
const char* _msg;
};
# define PUGL_CHECK_CONSTRUCTION(cond, msg) \
do { \
if (!(cond)) { \
throw FailedConstructionError(msg); \
} \
} while (0)
#elif defined(PUGL_HPP_ASSERT_CONSTRUCTION)
# define PUGL_CHECK_CONSTRUCTION(cond, msg) assert(cond);
#else
/**
Configurable macro for handling construction failure.
If `PUGL_HPP_THROW_FAILED_CONSTRUCTION` is defined, then this throws a
`pugl::FailedConstructionError` if construction fails.
If `PUGL_HPP_ASSERT_CONSTRUCTION` is defined, then this asserts if
construction fails.
Otherwise, this does nothing.
*/
# define PUGL_CHECK_CONSTRUCTION(cond, msg)
#endif
/// @copydoc PuglWorld
class World : public detail::Wrapper<PuglWorld, puglFreeWorld>
{
public:
World(const World&) = delete;
World& operator=(const World&) = delete;
World(World&&) = delete;
World& operator=(World&&) = delete;
~World() = default;
World(WorldType type, WorldFlag flag)
: Wrapper{puglNewWorld(static_cast<PuglWorldType>(type),
static_cast<PuglWorldFlags>(flag))}
{
PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::World");
}
World(WorldType type, WorldFlags flags)
: Wrapper{puglNewWorld(static_cast<PuglWorldType>(type), flags)}
{
PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::World");
}
explicit World(WorldType type)
: World{type, WorldFlags{}}
{}
/// @copydoc puglGetNativeWorld
void* nativeWorld() noexcept { return puglGetNativeWorld(cobj()); }
/// @copydoc puglSetClassName
Status setClassName(const char* const name) noexcept
{
return static_cast<Status>(puglSetClassName(cobj(), name));
}
/// @copydoc puglGetTime
double time() const noexcept { return puglGetTime(cobj()); }
/// @copydoc puglUpdate
Status update(const double timeout) noexcept
{
return static_cast<Status>(puglUpdate(cobj(), timeout));
}
};
/**
@}
@defgroup viewxx View
@{
*/
using Backend = PuglBackend; ///< @copydoc PuglBackend
using NativeView = PuglNativeView; ///< @copydoc PuglNativeView
/// @copydoc PuglViewHint
enum class ViewHint {
useCompatProfile, ///< @copydoc PUGL_USE_COMPAT_PROFILE
useDebugContext, ///< @copydoc PUGL_USE_DEBUG_CONTEXT
contextVersionMajor, ///< @copydoc PUGL_CONTEXT_VERSION_MAJOR
contextVersionMinor, ///< @copydoc PUGL_CONTEXT_VERSION_MINOR
redBits, ///< @copydoc PUGL_RED_BITS
greenBits, ///< @copydoc PUGL_GREEN_BITS
blueBits, ///< @copydoc PUGL_BLUE_BITS
alphaBits, ///< @copydoc PUGL_ALPHA_BITS
depthBits, ///< @copydoc PUGL_DEPTH_BITS
stencilBits, ///< @copydoc PUGL_STENCIL_BITS
samples, ///< @copydoc PUGL_SAMPLES
doubleBuffer, ///< @copydoc PUGL_DOUBLE_BUFFER
swapInterval, ///< @copydoc PUGL_SWAP_INTERVAL
resizable, ///< @copydoc PUGL_RESIZABLE
ignoreKeyRepeat, ///< @copydoc PUGL_IGNORE_KEY_REPEAT
refreshRate, ///< @copydoc PUGL_REFRESH_RATE
};
static_assert(ViewHint(PUGL_REFRESH_RATE) == ViewHint::refreshRate, "");
using ViewHintValue = PuglViewHintValue; ///< @copydoc PuglViewHintValue
/// @copydoc PuglCursor
enum class Cursor {
arrow, ///< @copydoc PUGL_CURSOR_ARROW
caret, ///< @copydoc PUGL_CURSOR_CARET
crosshair, ///< @copydoc PUGL_CURSOR_CROSSHAIR
hand, ///< @copydoc PUGL_CURSOR_HAND
no, ///< @copydoc PUGL_CURSOR_NO
leftRight, ///< @copydoc PUGL_CURSOR_LEFT_RIGHT
upDown, ///< @copydoc PUGL_CURSOR_UP_DOWN
};
static_assert(Cursor(PUGL_CURSOR_UP_DOWN) == Cursor::upDown, "");
/// @copydoc PuglView
class View : protected detail::Wrapper<PuglView, puglFreeView>
{
public:
/**
@name Setup
Methods for creating and destroying a view.
@{
*/
explicit View(World& world)
: Wrapper{puglNewView(world.cobj())}
, _world(world)
{
PUGL_CHECK_CONSTRUCTION(cobj(), "Failed to create pugl::View");
}
const World& world() const noexcept { return _world; }
World& world() noexcept { return _world; }
/**
Set the object that will be called to handle events.
This is a type-safe wrapper for the C functions puglSetHandle() and
puglSetEventFunc() that will automatically dispatch events to the
`onEvent` method of `handler` that takes the appropriate event type.
The handler must have such a method defined for every event type, but if
the handler is the view itself, a `using` declaration can be used to
"inherit" the default implementation to avoid having to define every
method. For example:
@code
class MyView : public pugl::View
{
public:
explicit MyView(pugl::World& world)
: pugl::View{world}
{
setEventHandler(*this);
}
using pugl::View::onEvent;
pugl::Status onEvent(const pugl::ConfigureEvent& event) noexcept;
pugl::Status onEvent(const pugl::ExposeEvent& event) noexcept;
};
@endcode
This facility is just a convenience, applications may use the C API
directly to set a handle and event function to set up a different
approach for event handling.
*/
template<class Handler>
Status setEventHandler(Handler& handler)
{
puglSetHandle(cobj(), &handler);
return static_cast<Status>(puglSetEventFunc(cobj(), eventFunc<Handler>));
}
/// @copydoc puglSetBackend
Status setBackend(const PuglBackend* backend) noexcept
{
return static_cast<Status>(puglSetBackend(cobj(), backend));
}
/// @copydoc puglSetViewHint
Status setHint(ViewHint hint, int value) noexcept
{
return static_cast<Status>(
puglSetViewHint(cobj(), static_cast<PuglViewHint>(hint), value));
}
/// @copydoc puglGetViewHint
int getHint(ViewHint hint) noexcept
{
return puglGetViewHint(cobj(), static_cast<PuglViewHint>(hint));
}
/**
@}
@name Frame
Methods for working with the position and size of a view.
@{
*/
/// @copydoc puglGetFrame
Rect frame() const noexcept { return puglGetFrame(cobj()); }
/// @copydoc puglSetFrame
Status setFrame(Rect frame) noexcept
{
return static_cast<Status>(puglSetFrame(cobj(), frame));
}
/// @copydoc puglSetDefaultSize
Status setDefaultSize(int width, int height) noexcept
{
return static_cast<Status>(puglSetDefaultSize(cobj(), width, height));
}
/// @copydoc puglSetMinSize
Status setMinSize(int width, int height) noexcept
{
return static_cast<Status>(puglSetMinSize(cobj(), width, height));
}
/// @copydoc puglSetMaxSize
Status setMaxSize(int width, int height) noexcept
{
return static_cast<Status>(puglSetMaxSize(cobj(), width, height));
}
/// @copydoc puglSetAspectRatio
Status setAspectRatio(int minX, int minY, int maxX, int maxY) noexcept
{
return static_cast<Status>(
puglSetAspectRatio(cobj(), minX, minY, maxX, maxY));
}
/**
@}
@name Windows
Methods for working with top-level windows.
@{
*/
/// @copydoc puglSetWindowTitle
Status setWindowTitle(const char* title) noexcept
{
return static_cast<Status>(puglSetWindowTitle(cobj(), title));
}
/// @copydoc puglSetParentWindow
Status setParentWindow(NativeView parent) noexcept
{
return static_cast<Status>(puglSetParentWindow(cobj(), parent));
}
/// @copydoc puglSetTransientFor
Status setTransientFor(NativeView parent) noexcept
{
return static_cast<Status>(puglSetTransientFor(cobj(), parent));
}
/// @copydoc puglRealize
Status realize() noexcept { return static_cast<Status>(puglRealize(cobj())); }
/// @copydoc puglShow
Status show() noexcept { return static_cast<Status>(puglShow(cobj())); }
/// @copydoc puglHide
Status hide() noexcept { return static_cast<Status>(puglHide(cobj())); }
/// @copydoc puglGetVisible
bool visible() const noexcept { return puglGetVisible(cobj()); }
/// @copydoc puglGetNativeWindow
NativeView nativeWindow() noexcept { return puglGetNativeWindow(cobj()); }
/**
@}
@name Graphics
Methods for working with the graphics context and scheduling
redisplays.
@{
*/
/// @copydoc puglGetContext
void* context() noexcept { return puglGetContext(cobj()); }
/// @copydoc puglPostRedisplay
Status postRedisplay() noexcept
{
return static_cast<Status>(puglPostRedisplay(cobj()));
}
/// @copydoc puglPostRedisplayRect
Status postRedisplayRect(const Rect rect) noexcept
{
return static_cast<Status>(puglPostRedisplayRect(cobj(), rect));
}
/**
@}
@name Interaction
Methods for interacting with the user and window system.
@{
*/
/// @copydoc puglGrabFocus
Status grabFocus() noexcept
{
return static_cast<Status>(puglGrabFocus(cobj()));
}
/// @copydoc puglHasFocus
bool hasFocus() const noexcept { return puglHasFocus(cobj()); }
/// @copydoc puglSetCursor
Status setCursor(const Cursor cursor) noexcept
{
return static_cast<Status>(
puglSetCursor(cobj(), static_cast<PuglCursor>(cursor)));
}
/// @copydoc puglRequestAttention
Status requestAttention() noexcept
{
return static_cast<Status>(puglRequestAttention(cobj()));
}
/// @copydoc puglStartTimer
Status startTimer(const uintptr_t id, const double timeout) noexcept
{
return static_cast<Status>(puglStartTimer(cobj(), id, timeout));
}
/// @copydoc puglStopTimer
Status stopTimer(const uintptr_t id) noexcept
{
return static_cast<Status>(puglStopTimer(cobj(), id));
}
/**
@}
*/
PuglView* cobj() noexcept { return Wrapper::cobj(); }
const PuglView* cobj() const noexcept { return Wrapper::cobj(); }
private:
template<class Target>
static Status dispatch(Target& target, const PuglEvent* event)
{
switch (event->type) {
case PUGL_NOTHING:
return Status::success;
case PUGL_CREATE:
return target.onEvent(static_cast<const CreateEvent&>(event->any));
case PUGL_DESTROY:
return target.onEvent(static_cast<const DestroyEvent&>(event->any));
case PUGL_CONFIGURE:
return target.onEvent(
static_cast<const ConfigureEvent&>(event->configure));
case PUGL_MAP:
return target.onEvent(static_cast<const MapEvent&>(event->any));
case PUGL_UNMAP:
return target.onEvent(static_cast<const UnmapEvent&>(event->any));
case PUGL_UPDATE:
return target.onEvent(static_cast<const UpdateEvent&>(event->any));
case PUGL_EXPOSE:
return target.onEvent(static_cast<const ExposeEvent&>(event->expose));
case PUGL_CLOSE:
return target.onEvent(static_cast<const CloseEvent&>(event->any));
case PUGL_FOCUS_IN:
return target.onEvent(static_cast<const FocusInEvent&>(event->focus));
case PUGL_FOCUS_OUT:
return target.onEvent(static_cast<const FocusOutEvent&>(event->focus));
case PUGL_KEY_PRESS:
return target.onEvent(static_cast<const KeyPressEvent&>(event->key));
case PUGL_KEY_RELEASE:
return target.onEvent(static_cast<const KeyReleaseEvent&>(event->key));
case PUGL_TEXT:
return target.onEvent(static_cast<const TextEvent&>(event->text));
case PUGL_POINTER_IN:
return target.onEvent(
static_cast<const PointerInEvent&>(event->crossing));
case PUGL_POINTER_OUT:
return target.onEvent(
static_cast<const PointerOutEvent&>(event->crossing));
case PUGL_BUTTON_PRESS:
return target.onEvent(
static_cast<const ButtonPressEvent&>(event->button));
case PUGL_BUTTON_RELEASE:
return target.onEvent(
static_cast<const ButtonReleaseEvent&>(event->button));
case PUGL_MOTION:
return target.onEvent(static_cast<const MotionEvent&>(event->motion));
case PUGL_SCROLL:
return target.onEvent(static_cast<const ScrollEvent&>(event->scroll));
case PUGL_CLIENT:
return target.onEvent(static_cast<const ClientEvent&>(event->client));
case PUGL_TIMER:
return target.onEvent(static_cast<const TimerEvent&>(event->timer));
case PUGL_LOOP_ENTER:
return target.onEvent(static_cast<const LoopEnterEvent&>(event->any));
case PUGL_LOOP_LEAVE:
return target.onEvent(static_cast<const LoopLeaveEvent&>(event->any));
}
return Status::failure;
}
template<class Target>
static PuglStatus eventFunc(PuglView* view, const PuglEvent* event) noexcept
{
auto* target = static_cast<Target*>(puglGetHandle(view));
#ifdef __cpp_exceptions
try {
return static_cast<PuglStatus>(dispatch(*target, event));
} catch (...) {
return PUGL_UNKNOWN_ERROR;
}
#else
return static_cast<PuglStatus>(pugl::dispatch(*target, event));
#endif
}
World& _world;
};
/**
@}
@}
*/
} // namespace pugl
#endif // PUGL_PUGL_HPP
|