Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InexorMouseManager.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <string> // for string
5 #include <utility> // for move
6 
7 #include "SDL_events.h" // for SDL_Event
8 #include "SDL_opengl.h" // for GL_ONE
9 #include "include/cef_app.h"
10 #include "include/cef_base.h" // for CefRefPtr
11 #include "include/cef_v8.h" // for CefV8Value (p...
12 #include "inexor/ui/context/InexorContextProvider.hpp" // for InexorContext...
13 #include "inexor/ui/layer/InexorLayerManager.hpp" // for InexorLayerMa...
15 
16 #ifndef GL_ONE
17 #define GL_ONE 0x1
18 #endif
19 
20 namespace inexor {
21 namespace ui {
22 namespace input {
23 
25 {
26 
27  public:
28  InexorMouseManager(CefRefPtr<inexor::ui::layer::InexorLayerManager> layer_manager, int screen_width, int screen_height)
29  : layer_manager(std::move(layer_manager)),
30  screen_width(screen_width),
31  screen_height(screen_height),
32  x(screen_width / 2),
33  y(screen_height / 2),
34  scale_x(0.015f),
35  scale_y(0.025f),
36  visible(true),
37  texture("interface/cursor/default.png") {};
38 
39 
40  bool IsVisible() { return visible; };
41  void Hide() { visible = false; };
42  void Show() { visible = true; };
43  void SetScreenSize(int screen_width, int screen_height) { this->screen_width = screen_width; this->screen_height = screen_height; };
44  int GetAbsoluteX() { return x; };
45  int GetAbsoluteY() { return y; };
46  int GetScreenWidth() { return screen_width; };
47  int GetScreenHeight() { return screen_height; };
48  float GetScaledX() { return (float) x / (float) screen_width; };
49  float GetScaledY() { return (float) y / (float) screen_height; };
50  int GetWidth() { return screen_width * scale_x; };
51  int GetHeight() { return screen_height * scale_y; };
53  void SetTexture(std::string texture) { this->texture = texture; };
54 
55  // SDL Events
56  void SendMouseMoveEvent(SDL_Event &e);
57  void SendMouseClickEvent(SDL_Event &e);
58  void SendMouseWheelEvent(SDL_Event &e);
59 
60  // InexorContextProvider
61  void InitializeContext() override;
62  bool Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception) override;
63  bool Get(const CefString& name, const CefRefPtr<CefV8Value> object, CefRefPtr<CefV8Value>& retval, CefString& exception) override;
64  bool Set(const CefString& name, const CefRefPtr<CefV8Value> object, const CefRefPtr<CefV8Value> value, CefString& exception) override;
65  std::string GetContextName() override { return "mouse"; };
66 
67  private:
68  // Layer Manager
69  CefRefPtr<inexor::ui::layer::InexorLayerManager> layer_manager;
70 
71  // The width and height of the screen
74 
75  // The position of the mouse on the screen
76  int x;
77  int y;
78 
79  // The width/height of the mouse in percent
80  // scale_x = 0.03 => mouse width 3% of the screen width
81  float scale_x;
82  float scale_y;
83 
84  // If true, the mouse is visible
85  bool visible;
86 
87  // The texture of the mouse
89 
90  // Include the default reference counting implementation.
92 
93 };
94 
95 }
96 }
97 }
void Show()
Definition: InexorMouseManager.hpp:42
float GetScaledY()
Definition: InexorMouseManager.hpp:49
float GetScaledX()
Definition: InexorMouseManager.hpp:48
bool Set(const CefString &name, const CefRefPtr< CefV8Value > object, const CefRefPtr< CefV8Value > value, CefString &exception) override
Definition: InexorMouseManager.cpp:28
int GetHeight()
Definition: InexorMouseManager.hpp:51
CefRefPtr< inexor::ui::layer::InexorLayerManager > layer_manager
Definition: InexorMouseManager.hpp:65
void Hide()
Definition: InexorMouseManager.hpp:41
IMPLEMENT_REFCOUNTING(InexorMouseManager)
Definition: InexorContextProvider.hpp:16
std::string GetContextName() override
Definition: InexorMouseManager.hpp:65
void SendMouseWheelEvent(SDL_Event &e)
Definition: InexorMouseManager.cpp:59
Setting a texture without using more than the texture path.
int x
Definition: InexorMouseManager.hpp:76
int GetAbsoluteX()
Definition: InexorMouseManager.hpp:44
std::string texture
Definition: InexorMouseManager.hpp:88
int GetWidth()
Definition: InexorMouseManager.hpp:50
ICOMMAND * f(float *a, float *b), floatret(*a **b)
float scale_x
Definition: InexorMouseManager.hpp:81
void SetTexture(std::string texture)
Definition: InexorMouseManager.hpp:53
bool Get(const CefString &name, const CefRefPtr< CefV8Value > object, CefRefPtr< CefV8Value > &retval, CefString &exception) override
Definition: InexorMouseManager.cpp:22
void SetScreenSize(int screen_width, int screen_height)
Definition: InexorMouseManager.hpp:43
Definition: InexorMouseManager.hpp:24
bool visible
Definition: InexorMouseManager.hpp:85
int screen_height
Definition: InexorMouseManager.hpp:73
void SendMouseMoveEvent(SDL_Event &e)
Definition: InexorMouseManager.cpp:34
bool move(physent *d, vec &dir)
Definition: physics.cpp:1342
void InitializeContext() override
Definition: InexorMouseManager.cpp:12
bool IsVisible()
Definition: InexorMouseManager.hpp:40
InexorMouseManager(CefRefPtr< inexor::ui::layer::InexorLayerManager > layer_manager, int screen_width, int screen_height)
Definition: InexorMouseManager.hpp:28
void SendMouseClickEvent(SDL_Event &e)
Definition: InexorMouseManager.cpp:44
char string[MAXSTRLEN]
cube-strings (char arrays of fixed size).
Definition: cube_types.hpp:18
GLsizei GLboolean const GLfloat * value
Definition: glexts.hpp:57
int GetScreenHeight()
Definition: InexorMouseManager.hpp:47
int y
Definition: InexorMouseManager.hpp:77
float scale_y
Definition: InexorMouseManager.hpp:82
bool Execute(const CefString &name, CefRefPtr< CefV8Value > object, const CefV8ValueList &arguments, CefRefPtr< CefV8Value > &retval, CefString &exception) override
Definition: InexorMouseManager.cpp:16
int GetAbsoluteY()
Definition: InexorMouseManager.hpp:45
int GetScreenWidth()
Definition: InexorMouseManager.hpp:46
GLenum GLenum GLuint texture
Definition: glexts.hpp:296
std::string GetTexture()
Definition: InexorMouseManager.hpp:52
int screen_width
Definition: InexorMouseManager.hpp:72