[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] | 23 | namespace OrxGui |
---|
[3365] | 24 | { |
---|
[9869] | 25 | ObjectListDefinition(GLGuiCursor); |
---|
[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 | { |
---|
[9869] | 57 | this->registerObject(this, GLGuiCursor::_objectList); |
---|
[5360] | 58 | |
---|
[8619] | 59 | this->setBackgroundColor(Color(1.0, 1.0, 1.0, 1.0)); |
---|
[10317] | 60 | this->setBackgroundTexture("textures/menu/cursor.png"); |
---|
[8299] | 61 | this->setSize2D(50, 50); |
---|
[7919] | 62 | this->setAbsCoor2D(100, 100); |
---|
| 63 | this->setLayer(E2D_LAYER_ABOVE_ALL); |
---|
| 64 | this->color = 0.0f; |
---|
[8619] | 65 | this->frameNumber = 0.0f; |
---|
[7919] | 66 | |
---|
[8035] | 67 | this->resize(); |
---|
[7779] | 68 | } |
---|
[5360] | 69 | |
---|
[8324] | 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 | { |
---|
[8619] | 81 | //this->background().setDiffuse(1.0, 1.0, 1.0); |
---|
[8324] | 82 | return this->seq.loadImageSeries(imageNameSubstitue, from, to); |
---|
| 83 | } |
---|
| 84 | |
---|
[7919] | 85 | void GLGuiCursor::tick(float dt) |
---|
| 86 | { |
---|
[8324] | 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)); |
---|
[8619] | 99 | //this->setBackgroundColor(color.x, color.y, color.z); |
---|
| 100 | /// FIXME |
---|
| 101 | |
---|
[8324] | 102 | } |
---|
[8035] | 103 | //if (this->movement != Vector2D()) |
---|
[7919] | 104 | { |
---|
| 105 | newPos += movement; |
---|
| 106 | // reposition the cursor. |
---|
| 107 | if (newPos.x < 0.0f ) |
---|
| 108 | newPos.x = 0.0f; |
---|
| 109 | if (newPos.x > this->_maxBorders.x) |
---|
| 110 | newPos.x = this->_maxBorders.x; |
---|
| 111 | if (newPos.y < 0.0f ) |
---|
| 112 | newPos.y = 0.0f; |
---|
| 113 | if (newPos.y > this->_maxBorders.y) |
---|
| 114 | newPos.y = this->_maxBorders.y; |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | movement = Vector2D(); |
---|
| 118 | } |
---|
[8035] | 119 | this->setAbsCoor2D(newPos); |
---|
[7919] | 120 | } |
---|
| 121 | |
---|
[7779] | 122 | /** |
---|
[7919] | 123 | * @brief draws the GLGuiCursor |
---|
[7779] | 124 | */ |
---|
[7919] | 125 | void GLGuiCursor::draw() const |
---|
[7779] | 126 | { |
---|
[8035] | 127 | this->beginDraw(); |
---|
[8324] | 128 | |
---|
[8619] | 129 | this->background().select(); |
---|
[8324] | 130 | if (!this->seq.empty()) |
---|
| 131 | glBindTexture(GL_TEXTURE_2D, this->seq.getFrameTexture((int)frameNumber)); |
---|
[8299] | 132 | this->drawRect(this->backRect()); |
---|
| 133 | |
---|
| 134 | //GLGuiWidget::draw(); |
---|
[7919] | 135 | this->endDraw(); |
---|
[7779] | 136 | } |
---|
[7919] | 137 | |
---|
[8324] | 138 | /** |
---|
| 139 | * @brief processes Events from the EventHandler. |
---|
| 140 | * @param event the Event to process. |
---|
| 141 | */ |
---|
[7919] | 142 | void GLGuiCursor::process(const Event& event) |
---|
| 143 | { |
---|
| 144 | switch (event.type) |
---|
| 145 | { |
---|
| 146 | case EV_WINDOW_FOCUS: |
---|
| 147 | if (event.bPressed) |
---|
| 148 | { |
---|
| 149 | int mouseX, mouseY; |
---|
| 150 | SDL_GetMouseState(&mouseX, &mouseY); |
---|
| 151 | newPos = Vector2D(mouseX, mouseY); |
---|
| 152 | } |
---|
| 153 | break; |
---|
| 154 | case EV_MOUSE_MOTION: |
---|
| 155 | movement += Vector2D((float)event.xRel * _mouseSensitivity, (float)event.yRel * _mouseSensitivity); |
---|
| 156 | break; |
---|
| 157 | |
---|
| 158 | } |
---|
| 159 | } |
---|
[5360] | 160 | } |
---|