The Battle for Wesnoth  1.19.5+dev
userevent.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2024
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include <SDL2/SDL_events.h>
18 
19 #include <cstring>
20 
21 namespace sdl
22 {
23 
24 class UserEvent
25 {
26 public:
28  {
29  std::memset(&event_, 0, sizeof(event_));
30  }
31 
33  {
34  event_.type = type;
35  }
36 
37  UserEvent(int type, int code) : UserEvent(type)
38  {
39  event_.code = code;
40  }
41 
42  UserEvent(int type, int code, std::size_t data1, std::size_t data2) : UserEvent(type)
43  {
44  event_.code = code;
45  event_.data1 = reinterpret_cast<void*>(data1);
46  event_.data2 = reinterpret_cast<void*>(data2);
47  }
48 
49  UserEvent(int type, void* data1) : UserEvent(type)
50  {
51  event_.data1 = data1;
52  }
53 
54  operator SDL_UserEvent()
55  {
56  return event_;
57  }
58 
59 private:
60  SDL_UserEvent event_;
61 };
62 
63 }
UserEvent(int type, int code, std::size_t data1, std::size_t data2)
Definition: userevent.hpp:42
UserEvent(int type, int code)
Definition: userevent.hpp:37
UserEvent(int type, void *data1)
Definition: userevent.hpp:49
SDL_UserEvent event_
Definition: userevent.hpp:60
UserEvent(int type)
Definition: userevent.hpp:32