[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: |
---|
[5359] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[5359] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI |
---|
[1853] | 17 | |
---|
[5362] | 18 | #include "glgui_widget.h" |
---|
[1853] | 19 | |
---|
[6287] | 20 | #include "material.h" |
---|
| 21 | |
---|
[5392] | 22 | #include "debug.h" |
---|
| 23 | |
---|
[1856] | 24 | using namespace std; |
---|
[1853] | 25 | |
---|
[3245] | 26 | /** |
---|
[4838] | 27 | * standard constructor |
---|
[3245] | 28 | */ |
---|
[5384] | 29 | GLGuiWidget::GLGuiWidget ( ) : Element2D(NULL) |
---|
[3365] | 30 | { |
---|
[5359] | 31 | this->init(); |
---|
[3365] | 32 | } |
---|
[1853] | 33 | |
---|
| 34 | |
---|
[3245] | 35 | /** |
---|
[4838] | 36 | * standard deconstructor |
---|
[5395] | 37 | */ |
---|
[5362] | 38 | GLGuiWidget::~GLGuiWidget() |
---|
[3543] | 39 | { |
---|
[5359] | 40 | |
---|
[3543] | 41 | } |
---|
[5359] | 42 | |
---|
[5362] | 43 | |
---|
[5392] | 44 | /** |
---|
| 45 | * initializes the GUI-element |
---|
| 46 | */ |
---|
| 47 | void GLGuiWidget::init() |
---|
| 48 | { |
---|
| 49 | this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget"); |
---|
| 50 | |
---|
| 51 | this->focusable = true; |
---|
| 52 | this->clickable = true; |
---|
[5397] | 53 | this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE); |
---|
[5406] | 54 | // this->setParent2D((Element2D*)NULL); |
---|
[5392] | 55 | |
---|
[6295] | 56 | this->backMat.setDiffuse(.1, .5, .5); |
---|
| 57 | this->backMat.setTransparency(.9); |
---|
[6287] | 58 | |
---|
[5392] | 59 | this->frontModel = 0; |
---|
| 60 | |
---|
| 61 | for (unsigned int i = 0; i < GLGuiSignalCount; i++) |
---|
| 62 | this->widgetSignals[i] = NULL; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
[5391] | 66 | bool GLGuiWidget::focusOverWidget(float x, float y) |
---|
| 67 | { |
---|
| 68 | if (this->getAbsCoor2D().x < x && this->getAbsCoor2D().x+ this->getSizeX2D() > x && |
---|
| 69 | this->getAbsCoor2D().y < y && this->getAbsCoor2D().y+ this->getSizeX2D() > y) |
---|
| 70 | return true; |
---|
| 71 | else |
---|
| 72 | return false; |
---|
| 73 | } |
---|
| 74 | |
---|
[5392] | 75 | /** |
---|
| 76 | * @brief connects a Signal to the Gui-Elements' Event. |
---|
| 77 | * @param sinalType the Type of Signal to set. @see GLGuiSignalType |
---|
| 78 | * @param signal the name of the Signal |
---|
| 79 | */ |
---|
[5690] | 80 | void GLGuiWidget::connectSignal(GLGuiSignalType signalType, const Executor& signal) |
---|
[5392] | 81 | { |
---|
[5690] | 82 | if (signalType >= GLGuiSignalCount) |
---|
[5392] | 83 | return; |
---|
[5391] | 84 | |
---|
[5392] | 85 | if (this->widgetSignals[signalType] != NULL) |
---|
| 86 | PRINTF(2)("Already connected a Signal to %s (%s) type %s... overwriting\n"); |
---|
| 87 | |
---|
[5690] | 88 | this->widgetSignals[signalType] = signal.clone(); |
---|
[5392] | 89 | } |
---|
| 90 | |
---|
[5359] | 91 | /** |
---|
[5392] | 92 | * @brief removes a Signal from a Gui-ELements' Event |
---|
| 93 | * @param signalType the type of Signal to remove. |
---|
[5359] | 94 | */ |
---|
[5392] | 95 | void GLGuiWidget::disconnectSignal(GLGuiSignalType signalType) |
---|
[5359] | 96 | { |
---|
[5392] | 97 | if (signalType > GLGuiSignalCount) |
---|
| 98 | return; |
---|
[5359] | 99 | |
---|
[5392] | 100 | this->widgetSignals[signalType] = NULL; |
---|
| 101 | } |
---|
[5366] | 102 | |
---|
[5395] | 103 | |
---|
| 104 | void GLGuiWidget::show() |
---|
| 105 | { |
---|
| 106 | this->setVisibility(true); |
---|
| 107 | } |
---|
[6287] | 108 | |
---|
| 109 | |
---|
| 110 | void GLGuiWidget::draw() const |
---|
| 111 | { |
---|
[6295] | 112 | this->backMat.select(); |
---|
[6287] | 113 | |
---|
| 114 | glBegin(GL_QUADS); |
---|
[6295] | 115 | glVertex2d(0, 0); |
---|
| 116 | glVertex2d(0, this->getSizeY2D()); |
---|
| 117 | glVertex2d(this->getSizeX2D(), this->getSizeY2D()); |
---|
| 118 | glVertex2d(this->getSizeX2D(), 0); |
---|
[6287] | 119 | glEnd(); |
---|
| 120 | } |
---|
| 121 | |
---|