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