Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8319 was 8312, checked in by bensch, 19 years ago

trunk: merged the water-branche back here
removed the HACK in GameWorld in the Process (hope it is not needed anymore…

merged with command:
svn merge https://svn.orxonox.net/orxonoanches/water/src/lib/gui/gl_gui src/lib/gui/gl/ -r8063:HEAD

File size: 3.3 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#include "texture_sequence.h"
23#include "loading/resource_manager.h" // HACK
24
25namespace OrxGui
26{
27
28  /**
29   * standard constructor
30  */
31  GLGuiCursor::GLGuiCursor ()
32  {
33    this->init();
34
35    this->subscribeEvent(ES_ALL,  EV_MOUSE_MOTION);
36    this->subscribeEvent(ES_ALL, EV_WINDOW_FOCUS);
37
38
39  }
40
41
42  /**
43   * @brief standard deconstructor
44   */
45  GLGuiCursor::~GLGuiCursor()
46  {
47    GLGuiHandler::getInstance()->deactivateCursor(false);
48  }
49
50  float GLGuiCursor::_mouseSensitivity = 1.0;
51
52
53
54  /**
55   * @brief initializes the GUI-element
56   */
57  void GLGuiCursor::init()
58  {
59    this->setClassID(CL_GLGUI_CURSOR, "GLGuiCursor");
60
61    this->backMaterial().setDiffuse(1.0,0.0,0.0);
62    this->backMaterial().setDiffuseMap("cursor.png");
63    this->backMaterial().setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
64    this->setSize2D(50, 50);
65    this->setAbsCoor2D(100, 100);
66    this->setLayer(E2D_LAYER_ABOVE_ALL);
67    this->color = 0.0f;
68
69    this->seq = new TextureSequence();
70    this->seq->loadImageSeries(ResourceManager::getInstance()->getDataDir() + "/maps/reap_mouse/reap_mouse_##.tif", 0, 49);
71
72    this->resize();
73  }
74
75  void GLGuiCursor::tick(float dt)
76  {
77    this->frameNumber += 25.0*dt;
78    if (frameNumber >= this->seq->getFrameCount())
79      frameNumber = 0.0;
80
81    this->color += dt*10.0;
82    if (this->color > 360.0)
83      this->color -= 360.0;
84    Vector color =  Color::HSVtoRGB(Vector(this->color, 1.0, 1.0));
85    this->backMaterial().setDiffuse(color.x, color.y, color.z);
86
87    //if (this->movement != Vector2D())
88    {
89      newPos += movement;
90      // reposition the cursor.
91      if (newPos.x < 0.0f )
92        newPos.x = 0.0f;
93      if (newPos.x > this->_maxBorders.x)
94        newPos.x = this->_maxBorders.x;
95      if (newPos.y < 0.0f )
96        newPos.y = 0.0f;
97      if (newPos.y > this->_maxBorders.y)
98        newPos.y = this->_maxBorders.y;
99
100
101      movement = Vector2D();
102    }
103    this->setAbsCoor2D(newPos);
104  }
105
106  /**
107   * @brief draws the GLGuiCursor
108   */
109  void GLGuiCursor::draw() const
110  {
111    this->beginDraw();
112    // HACK
113    glActiveTexture(GL_TEXTURE0);
114    glEnable(GL_TEXTURE_2D);
115    glBindTexture(GL_TEXTURE_2D, this->seq->getFrameTexture((int)frameNumber));
116    glColor3f(1,1,1);
117    glEnable(GL_BLEND);
118    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
119    this->drawRect(this->backRect());
120
121    //GLGuiWidget::draw();
122    this->endDraw();
123  }
124
125  void GLGuiCursor::process(const Event& event)
126  {
127    switch (event.type)
128    {
129      case EV_WINDOW_FOCUS:
130        if (event.bPressed)
131        {
132          int mouseX, mouseY;
133          SDL_GetMouseState(&mouseX, &mouseY);
134          newPos = Vector2D(mouseX, mouseY);
135        }
136        break;
137      case EV_MOUSE_MOTION:
138        movement += Vector2D((float)event.xRel * _mouseSensitivity, (float)event.yRel * _mouseSensitivity);
139        break;
140
141    }
142  }
143}
Note: See TracBrowser for help on using the repository browser.