1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI |
---|
17 | |
---|
18 | #include "glgui_cursor.h" |
---|
19 | |
---|
20 | #include "glgui_handler.h" |
---|
21 | #include "color.h" |
---|
22 | |
---|
23 | |
---|
24 | namespace OrxGui |
---|
25 | { |
---|
26 | |
---|
27 | /** |
---|
28 | * standard constructor |
---|
29 | */ |
---|
30 | GLGuiCursor::GLGuiCursor () |
---|
31 | { |
---|
32 | this->init(); |
---|
33 | |
---|
34 | this->subscribeEvent(ES_MENU, EV_MOUSE_MOTION); |
---|
35 | this->subscribeEvent(ES_MENU, EV_WINDOW_FOCUS); |
---|
36 | |
---|
37 | |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | /** |
---|
42 | * @brief standard deconstructor |
---|
43 | */ |
---|
44 | GLGuiCursor::~GLGuiCursor() |
---|
45 | { |
---|
46 | GLGuiHandler::getInstance()->deactivateCursor(false); |
---|
47 | } |
---|
48 | |
---|
49 | float GLGuiCursor::_mouseSensitivity = 1.0; |
---|
50 | |
---|
51 | |
---|
52 | /** |
---|
53 | * @brief initializes the GUI-element |
---|
54 | */ |
---|
55 | void GLGuiCursor::init() |
---|
56 | { |
---|
57 | this->setClassID(CL_GLGUI_CURSOR, "GLGuiCursor"); |
---|
58 | |
---|
59 | this->backMaterial().setDiffuse(1.0,0.0,0.0); |
---|
60 | this->backMaterial().setDiffuseMap("cursor.png"); |
---|
61 | this->backMaterial().setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
62 | this->setSize2D(20, 30); |
---|
63 | this->setAbsCoor2D(100, 100); |
---|
64 | this->setLayer(E2D_LAYER_ABOVE_ALL); |
---|
65 | this->color = 0.0f; |
---|
66 | |
---|
67 | this->resize(); |
---|
68 | } |
---|
69 | |
---|
70 | void GLGuiCursor::tick(float dt) |
---|
71 | { |
---|
72 | this->color += dt*10.0; |
---|
73 | if (this->color > 360.0) |
---|
74 | this->color -= 360.0; |
---|
75 | Vector color = Color::HSVtoRGB(Vector(this->color, 1.0, 1.0)); |
---|
76 | this->backMaterial().setDiffuse(color.x, color.y, color.z); |
---|
77 | |
---|
78 | //if (this->movement != Vector2D()) |
---|
79 | { |
---|
80 | newPos += movement; |
---|
81 | // reposition the cursor. |
---|
82 | if (newPos.x < 0.0f ) |
---|
83 | newPos.x = 0.0f; |
---|
84 | if (newPos.x > this->_maxBorders.x) |
---|
85 | newPos.x = this->_maxBorders.x; |
---|
86 | if (newPos.y < 0.0f ) |
---|
87 | newPos.y = 0.0f; |
---|
88 | if (newPos.y > this->_maxBorders.y) |
---|
89 | newPos.y = this->_maxBorders.y; |
---|
90 | |
---|
91 | |
---|
92 | movement = Vector2D(); |
---|
93 | } |
---|
94 | this->setAbsCoor2D(newPos); |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * @brief draws the GLGuiCursor |
---|
99 | */ |
---|
100 | void GLGuiCursor::draw() const |
---|
101 | { |
---|
102 | this->beginDraw(); |
---|
103 | GLGuiWidget::draw(); |
---|
104 | this->endDraw(); |
---|
105 | } |
---|
106 | |
---|
107 | void GLGuiCursor::process(const Event& event) |
---|
108 | { |
---|
109 | switch (event.type) |
---|
110 | { |
---|
111 | case EV_WINDOW_FOCUS: |
---|
112 | if (event.bPressed) |
---|
113 | { |
---|
114 | int mouseX, mouseY; |
---|
115 | SDL_GetMouseState(&mouseX, &mouseY); |
---|
116 | newPos = Vector2D(mouseX, mouseY); |
---|
117 | } |
---|
118 | break; |
---|
119 | case EV_MOUSE_MOTION: |
---|
120 | movement += Vector2D((float)event.xRel * _mouseSensitivity, (float)event.yRel * _mouseSensitivity); |
---|
121 | break; |
---|
122 | |
---|
123 | } |
---|
124 | } |
---|
125 | } |
---|