Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glgui_cursor.cc @ 10009

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.7 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
23namespace OrxGui
24{
25  ObjectListDefinition(GLGuiCursor);
26  /**
27   * standard constructor
28  */
29  GLGuiCursor::GLGuiCursor ()
30  {
31    this->init();
32
33    this->subscribeEvent(ES_ALL,  EV_MOUSE_MOTION);
34    this->subscribeEvent(ES_ALL, EV_WINDOW_FOCUS);
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  /**
53   * @brief initializes the GUI-element
54   */
55  void GLGuiCursor::init()
56  {
57    this->registerObject(this, GLGuiCursor::_objectList);
58
59    this->setBackgroundColor(Color(1.0, 1.0, 1.0, 1.0));
60    this->setBackgroundTexture("cursor.png");
61    this->setSize2D(50, 50);
62    this->setAbsCoor2D(100, 100);
63    this->setLayer(E2D_LAYER_ABOVE_ALL);
64    this->color = 0.0f;
65    this->frameNumber = 0.0f;
66
67    this->resize();
68  }
69
70  /**
71   * @brief Loads an Image-Series onto the Cursor.
72   * @param imageNameSubstitue The Prefix of the Image
73   * @param from From which image
74   * @param to To which image
75   * @return true on success.
76   *
77   * @see TextureSequence:: loadTextureSequence(const std::string& imageNameSubstitue, unsigned int from, unsigned int to)
78   */
79  bool GLGuiCursor::loadTextureSequence(const std::string& imageNameSubstitue, unsigned int from, unsigned int to)
80  {
81    //this->background().setDiffuse(1.0, 1.0, 1.0);
82    return this->seq.loadImageSeries(imageNameSubstitue, from, to);
83  }
84
85  void GLGuiCursor::tick(float dt)
86  {
87    if (!this->seq.empty())
88    {
89      this->frameNumber += 25.0*dt;
90      if (frameNumber >= this->seq.getFrameCount())
91        frameNumber = 0.0;
92    }
93    else
94    {
95      this->color += dt*10.0;
96      if (this->color > 360.0)
97        this->color -= 360.0;
98      Vector color =  Color::HSVtoRGB(Vector(this->color, 1.0, 1.0));
99      //this->setBackgroundColor(color.x, color.y, color.z);
100      /// FIXME
101
102    }
103    //if (this->movement != Vector2D())
104    {
105      newPos += movement;
106      // reposition the cursor.
107      if (newPos.x < 0.0f )
108        newPos.x = 0.0f;
109      if (newPos.x > this->_maxBorders.x)
110        newPos.x = this->_maxBorders.x;
111      if (newPos.y < 0.0f )
112        newPos.y = 0.0f;
113      if (newPos.y > this->_maxBorders.y)
114        newPos.y = this->_maxBorders.y;
115
116
117      movement = Vector2D();
118    }
119    this->setAbsCoor2D(newPos);
120  }
121
122  /**
123   * @brief draws the GLGuiCursor
124   */
125  void GLGuiCursor::draw() const
126  {
127    this->beginDraw();
128
129    this->background().select();
130    if (!this->seq.empty())
131      glBindTexture(GL_TEXTURE_2D, this->seq.getFrameTexture((int)frameNumber));
132    this->drawRect(this->backRect());
133
134    //GLGuiWidget::draw();
135    this->endDraw();
136  }
137
138  /**
139   * @brief processes Events from the EventHandler.
140   * @param event the Event to process.
141   */
142  void GLGuiCursor::process(const Event& event)
143  {
144    switch (event.type)
145    {
146      case EV_WINDOW_FOCUS:
147        if (event.bPressed)
148        {
149          int mouseX, mouseY;
150          SDL_GetMouseState(&mouseX, &mouseY);
151          newPos = Vector2D(mouseX, mouseY);
152        }
153        break;
154      case EV_MOUSE_MOTION:
155        movement += Vector2D((float)event.xRel * _mouseSensitivity, (float)event.yRel * _mouseSensitivity);
156        break;
157
158    }
159  }
160}
Note: See TracBrowser for help on using the repository browser.