Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gui: using style.

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