Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Better Signal definition

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