Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/gui/gl_gui/glgui_cursor.cc @ 7917

Last change on this file since 7917 was 7906, checked in by bensch, 18 years ago

orxonox/trunk: very smooth cursor

File size: 2.6 KB
Line 
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
24namespace 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->setSize2D(10, 20);
62    this->setAbsCoor2D(100, 100);
63    this->setLayer(E2D_LAYER_ABOVE_ALL);
64    this->color = 0.0f;
65
66  }
67
68  void GLGuiCursor::tick(float dt)
69  {
70    this->color += dt*10.0;
71    if (this->color > 360.0)
72      this->color -= 360.0;
73    Vector color =  Color::HSVtoRGB(Vector(this->color, 1.0, 1.0));
74    this->backMaterial().setDiffuse(color.x, color.y, color.z);
75
76    if (this->movement != Vector2D())
77    {
78      newPos += movement;
79      // reposition the cursor.
80      if (newPos.x < 0.0f )
81        newPos.x = 0.0f;
82      if (newPos.x > this->_maxBorders.x)
83        newPos.x = this->_maxBorders.x;
84      if (newPos.y < 0.0f )
85        newPos.y = 0.0f;
86      if (newPos.y > this->_maxBorders.y)
87        newPos.y = this->_maxBorders.y;
88
89
90      this->setAbsCoorSoft2D(newPos, 10);
91      movement = Vector2D();
92    }
93  }
94
95  /**
96   * @brief draws the GLGuiCursor
97   */
98  void GLGuiCursor::draw() const
99  {
100    this->startDraw();
101    GLGuiWidget::draw();
102    this->endDraw();
103  }
104
105  void GLGuiCursor::process(const Event& event)
106  {
107    switch (event.type)
108    {
109      case EV_WINDOW_FOCUS:
110        if (event.bPressed)
111        {
112          int mouseX, mouseY;
113          SDL_GetMouseState(&mouseX, &mouseY);
114          newPos = Vector2D(mouseX, mouseY);
115        }
116        break;
117      case EV_MOUSE_MOTION:
118        movement += Vector2D((float)event.xRel * _mouseSensitivity, (float)event.yRel * _mouseSensitivity);
119        break;
120
121    }
122  }
123}
Note: See TracBrowser for help on using the repository browser.