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 | |
---|
36 | |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | /** |
---|
41 | * @brief standard deconstructor |
---|
42 | */ |
---|
43 | GLGuiCursor::~GLGuiCursor() |
---|
44 | { |
---|
45 | GLGuiHandler::getInstance()->deactivateCursor(false); |
---|
46 | } |
---|
47 | |
---|
48 | float GLGuiCursor::_mouseSensitivity = 1.0; |
---|
49 | |
---|
50 | |
---|
51 | /** |
---|
52 | * @brief initializes the GUI-element |
---|
53 | */ |
---|
54 | void GLGuiCursor::init() |
---|
55 | { |
---|
56 | this->setClassID(CL_GLGUI_CURSOR, "GLGuiCursor"); |
---|
57 | |
---|
58 | this->backMaterial().setDiffuse(1.0,0.0,0.0); |
---|
59 | this->backMaterial().setDiffuseMap("cursor.png"); |
---|
60 | this->setSize2D(10, 20); |
---|
61 | this->setAbsCoor2D(100, 100); |
---|
62 | this->setLayer(E2D_LAYER_ABOVE_ALL); |
---|
63 | this->color = 0.0f; |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | void GLGuiCursor::tick(float dt) |
---|
68 | { |
---|
69 | this->color += dt*10.0; |
---|
70 | if (this->color > 360.0) |
---|
71 | this->color -= 360.0; |
---|
72 | Vector color = Color::HSVtoRGB(Vector(this->color, 1.0, 1.0)); |
---|
73 | this->backMaterial().setDiffuse(color.x, color.y, color.z); |
---|
74 | |
---|
75 | //if (this->movement != Vector2D()) |
---|
76 | { |
---|
77 | /* if (this->getAbsCoor2D().x < 0.0 ) |
---|
78 | movement.x = -this->getAbsCoor2D().x; |
---|
79 | if (this->getAbsCoor2D().x > 200.0) |
---|
80 | movement.x = (200.0-this->getAbsCoor2D().x); |
---|
81 | if (this->getAbsCoor2D().y < 0.0 ) |
---|
82 | movement.x = -this->getAbsCoor2D().y; |
---|
83 | if (this->getAbsCoor2D().y > 200.0) |
---|
84 | movement.x = (200.0-this->getAbsCoor2D().y);*/ |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | //this->shiftCoor2D(movement); |
---|
89 | this->setAbsCoor2D(newPos); |
---|
90 | movement = Vector2D(); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * @brief draws the GLGuiCursor |
---|
96 | */ |
---|
97 | void GLGuiCursor::draw() const |
---|
98 | { |
---|
99 | this->startDraw(); |
---|
100 | GLGuiWidget::draw(); |
---|
101 | this->endDraw(); |
---|
102 | } |
---|
103 | |
---|
104 | void GLGuiCursor::process(const Event& event) |
---|
105 | { |
---|
106 | switch (event.type) |
---|
107 | { |
---|
108 | case EV_MOUSE_MOTION: |
---|
109 | newPos = Vector2D(event.x, event.y); |
---|
110 | movement += Vector2D(event.xRel * _mouseSensitivity, event.yRel * _mouseSensitivity); |
---|
111 | break; |
---|
112 | |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|