Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/gui/gl_gui/glgui_cursor.cc @ 7985

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

EVENTS WORK :)

File size: 2.6 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
23
[7779]24namespace OrxGui
[3365]25{
[4320]26
[7779]27  /**
28   * standard constructor
29  */
[7919]30  GLGuiCursor::GLGuiCursor ()
[7779]31  {
32    this->init();
[1853]33
[7919]34    this->subscribeEvent(ES_MENU,  EV_MOUSE_MOTION);
35    this->subscribeEvent(ES_MENU, EV_WINDOW_FOCUS);
36
37
[7779]38  }
[1853]39
[5360]40
[7779]41  /**
[7919]42   * @brief standard deconstructor
43   */
44  GLGuiCursor::~GLGuiCursor()
[7779]45  {
[7919]46    GLGuiHandler::getInstance()->deactivateCursor(false);
[7779]47  }
[5360]48
[7919]49  float GLGuiCursor::_mouseSensitivity = 1.0;
50
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
[7919]59    this->backMaterial().setDiffuse(1.0,0.0,0.0);
60    this->backMaterial().setDiffuseMap("cursor.png");
61    this->setSize2D(10, 20);
62    this->setAbsCoor2D(100, 100);
63    this->setLayer(E2D_LAYER_ABOVE_ALL);
64    this->color = 0.0f;
65
[7925]66    this->resize();
[7779]67  }
[5360]68
[7919]69  void GLGuiCursor::tick(float dt)
70  {
71    this->color += dt*10.0;
72    if (this->color > 360.0)
73      this->color -= 360.0;
74    Vector color =  Color::HSVtoRGB(Vector(this->color, 1.0, 1.0));
75    this->backMaterial().setDiffuse(color.x, color.y, color.z);
76
77    if (this->movement != Vector2D())
78    {
79      newPos += movement;
80      // reposition the cursor.
81      if (newPos.x < 0.0f )
82        newPos.x = 0.0f;
83      if (newPos.x > this->_maxBorders.x)
84        newPos.x = this->_maxBorders.x;
85      if (newPos.y < 0.0f )
86        newPos.y = 0.0f;
87      if (newPos.y > this->_maxBorders.y)
88        newPos.y = this->_maxBorders.y;
89
90
91      movement = Vector2D();
92    }
[7985]93    this->setAbsCoorSoft2D(newPos, 10);
[7919]94  }
95
[7779]96  /**
[7919]97   * @brief draws the GLGuiCursor
[7779]98   */
[7919]99  void GLGuiCursor::draw() const
[7779]100  {
[7928]101    this->beginDraw();
[7919]102    GLGuiWidget::draw();
103    this->endDraw();
[7779]104  }
[7919]105
106  void GLGuiCursor::process(const Event& event)
107  {
108    switch (event.type)
109    {
110      case EV_WINDOW_FOCUS:
111        if (event.bPressed)
112        {
113          int mouseX, mouseY;
114          SDL_GetMouseState(&mouseX, &mouseY);
115          newPos = Vector2D(mouseX, mouseY);
116        }
117        break;
118      case EV_MOUSE_MOTION:
119        movement += Vector2D((float)event.xRel * _mouseSensitivity, (float)event.yRel * _mouseSensitivity);
120        break;
121
122    }
123  }
[5360]124}
Note: See TracBrowser for help on using the repository browser.