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
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[5360]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[5360]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
[1853]17
[7919]18#include "glgui_cursor.h"
[1853]19
[7919]20#include "glgui_handler.h"
21#include "color.h"
22
[7779]23namespace OrxGui
[3365]24{
[4320]25
[7779]26  /**
27   * standard constructor
28  */
[7919]29  GLGuiCursor::GLGuiCursor ()
[7779]30  {
31    this->init();
[1853]32
[8312]33    this->subscribeEvent(ES_ALL,  EV_MOUSE_MOTION);
34    this->subscribeEvent(ES_ALL, EV_WINDOW_FOCUS);
[7919]35
36
[7779]37  }
[1853]38
[5360]39
[7779]40  /**
[7919]41   * @brief standard deconstructor
42   */
43  GLGuiCursor::~GLGuiCursor()
[7779]44  {
[7919]45    GLGuiHandler::getInstance()->deactivateCursor(false);
[7779]46  }
[5360]47
[7919]48  float GLGuiCursor::_mouseSensitivity = 1.0;
49
50
[8297]51
[7779]52  /**
[7919]53   * @brief initializes the GUI-element
[7779]54   */
[7919]55  void GLGuiCursor::init()
[7779]56  {
[7919]57    this->setClassID(CL_GLGUI_CURSOR, "GLGuiCursor");
[5360]58
[8583]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);
[8299]62    this->setSize2D(50, 50);
[7919]63    this->setAbsCoor2D(100, 100);
64    this->setLayer(E2D_LAYER_ABOVE_ALL);
65    this->color = 0.0f;
[8528]66    this->frameNumber = 0.0f;
[7919]67
[8035]68    this->resize();
[7779]69  }
[5360]70
[8324]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  {
[8583]82    this->style().background().setDiffuse(1.0, 1.0, 1.0);
[8324]83    return this->seq.loadImageSeries(imageNameSubstitue, from, to);
84  }
85
[7919]86  void GLGuiCursor::tick(float dt)
87  {
[8324]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));
[8583]100      this->style().background().setDiffuse(color.x, color.y, color.z);
[8324]101    }
[8035]102    //if (this->movement != Vector2D())
[7919]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    }
[8035]118    this->setAbsCoor2D(newPos);
[7919]119  }
120
[7779]121  /**
[7919]122   * @brief draws the GLGuiCursor
[7779]123   */
[7919]124  void GLGuiCursor::draw() const
[7779]125  {
[8035]126    this->beginDraw();
[8324]127
[8583]128    this->background().select();
[8324]129    if (!this->seq.empty())
130      glBindTexture(GL_TEXTURE_2D, this->seq.getFrameTexture((int)frameNumber));
[8299]131    this->drawRect(this->backRect());
132
133    //GLGuiWidget::draw();
[7919]134    this->endDraw();
[7779]135  }
[7919]136
[8324]137  /**
138   * @brief processes Events from the EventHandler.
139   * @param event the Event to process.
140   */
[7919]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  }
[5360]159}
Note: See TracBrowser for help on using the repository browser.