Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/water/src/lib/gui/gl/glgui_cursor.cc @ 8585

Last change on this file since 8585 was 8324, checked in by bensch, 19 years ago

trunk: Texture-Sequence is initialized smoothly now in the GLGuiCursor

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
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->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(50, 50);
63    this->setAbsCoor2D(100, 100);
64    this->setLayer(E2D_LAYER_ABOVE_ALL);
65    this->color = 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->backMaterial().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->backMaterial().setDiffuse(color.x, color.y, color.z);
100    }
101    //if (this->movement != Vector2D())
102    {
103      newPos += movement;
104      // reposition the cursor.
105      if (newPos.x < 0.0f )
106        newPos.x = 0.0f;
107      if (newPos.x > this->_maxBorders.x)
108        newPos.x = this->_maxBorders.x;
109      if (newPos.y < 0.0f )
110        newPos.y = 0.0f;
111      if (newPos.y > this->_maxBorders.y)
112        newPos.y = this->_maxBorders.y;
113
114
115      movement = Vector2D();
116    }
117    this->setAbsCoor2D(newPos);
118  }
119
120  /**
121   * @brief draws the GLGuiCursor
122   */
123  void GLGuiCursor::draw() const
124  {
125    this->beginDraw();
126
127    this->backMaterial().select();
128    if (!this->seq.empty())
129      glBindTexture(GL_TEXTURE_2D, this->seq.getFrameTexture((int)frameNumber));
130    this->drawRect(this->backRect());
131
132    //GLGuiWidget::draw();
133    this->endDraw();
134  }
135
136  /**
137   * @brief processes Events from the EventHandler.
138   * @param event the Event to process.
139   */
140  void GLGuiCursor::process(const Event& event)
141  {
142    switch (event.type)
143    {
144      case EV_WINDOW_FOCUS:
145        if (event.bPressed)
146        {
147          int mouseX, mouseY;
148          SDL_GetMouseState(&mouseX, &mouseY);
149          newPos = Vector2D(mouseX, mouseY);
150        }
151        break;
152      case EV_MOUSE_MOTION:
153        movement += Vector2D((float)event.xRel * _mouseSensitivity, (float)event.yRel * _mouseSensitivity);
154        break;
155
156    }
157  }
158}
Note: See TracBrowser for help on using the repository browser.