[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 | |
---|
[7882] | 20 | #include "glgui_cursor.h" |
---|
| 21 | |
---|
[6287] | 22 | #include "material.h" |
---|
| 23 | |
---|
[5392] | 24 | #include "debug.h" |
---|
| 25 | |
---|
[7779] | 26 | namespace OrxGui |
---|
[3365] | 27 | { |
---|
[1853] | 28 | |
---|
[7779] | 29 | /** |
---|
| 30 | * standard constructor |
---|
| 31 | */ |
---|
| 32 | GLGuiWidget::GLGuiWidget ( ) |
---|
| 33 | { |
---|
| 34 | this->init(); |
---|
| 35 | } |
---|
[1853] | 36 | |
---|
[5359] | 37 | |
---|
[7779] | 38 | /** |
---|
| 39 | * standard deconstructor |
---|
| 40 | */ |
---|
| 41 | GLGuiWidget::~GLGuiWidget() |
---|
| 42 | { |
---|
| 43 | } |
---|
[5359] | 44 | |
---|
[7879] | 45 | GLGuiWidget* GLGuiWidget::_focused = NULL; |
---|
| 46 | GLGuiWidget* GLGuiWidget::_inputGrabber = NULL; |
---|
[5362] | 47 | |
---|
[7879] | 48 | |
---|
| 49 | |
---|
[7779] | 50 | /** |
---|
| 51 | * initializes the GUI-element |
---|
| 52 | */ |
---|
| 53 | void GLGuiWidget::init() |
---|
| 54 | { |
---|
| 55 | this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget"); |
---|
[5392] | 56 | |
---|
[7882] | 57 | this->_focusable = false; |
---|
| 58 | this->_clickable = false; |
---|
[7779] | 59 | this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE); |
---|
[5392] | 60 | |
---|
[7779] | 61 | this->backMat.setDiffuse(1.0, 1.0, 1.0); |
---|
[6287] | 62 | |
---|
[7779] | 63 | this->frontModel = 0; |
---|
[5392] | 64 | |
---|
[7855] | 65 | this->widgetSignals.resize(SignalCount, SignalConnector()); |
---|
[7779] | 66 | } |
---|
[5392] | 67 | |
---|
| 68 | |
---|
[7882] | 69 | bool GLGuiWidget::focusOverWidget(const Vector2D& position) const |
---|
[7779] | 70 | { |
---|
[7882] | 71 | return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x && |
---|
| 72 | this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y); |
---|
[7779] | 73 | } |
---|
[5391] | 74 | |
---|
[7882] | 75 | bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const |
---|
| 76 | { |
---|
| 77 | return this->focusOverWidget(cursor->getAbsCoor2D()); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
[7779] | 81 | /** |
---|
| 82 | * @brief connects a Signal to the Gui-Elements' Event. |
---|
| 83 | * @param sinalType the Type of Signal to set. @see GLGuiSignalType |
---|
| 84 | * @param signal the name of the Signal |
---|
| 85 | */ |
---|
[7855] | 86 | void GLGuiWidget::connectSignal(SignalType signalType, BaseObject* object, const Executor* signal) |
---|
[7779] | 87 | { |
---|
[7855] | 88 | if (signalType >= this->widgetSignals.size()) |
---|
[7779] | 89 | return; |
---|
[5391] | 90 | |
---|
[7855] | 91 | // if (this->widgetSignals[signalType] != NULL) |
---|
| 92 | // PRINTF(2)("Already connected a Signal to '%s::%s' type %s... overwriting\n", this->getClassName(), this->getName(), "TEST"); |
---|
[5392] | 93 | |
---|
[7855] | 94 | this->widgetSignals[signalType] = SignalConnector(object, signal); |
---|
[7779] | 95 | } |
---|
[5392] | 96 | |
---|
[7779] | 97 | /** |
---|
| 98 | * @brief removes a Signal from a Gui-ELements' Event |
---|
| 99 | * @param signalType the type of Signal to remove. |
---|
| 100 | */ |
---|
[7855] | 101 | void GLGuiWidget::disconnectSignal(SignalType signalType) |
---|
[7779] | 102 | { |
---|
[7855] | 103 | if (signalType >= this->widgetSignals.size()) |
---|
[7779] | 104 | return; |
---|
[5359] | 105 | |
---|
[7855] | 106 | this->widgetSignals[signalType] = SignalConnector(); |
---|
[7779] | 107 | } |
---|
[5366] | 108 | |
---|
[5395] | 109 | |
---|
[7779] | 110 | void GLGuiWidget::show() |
---|
| 111 | { |
---|
| 112 | this->setVisibility(true); |
---|
| 113 | } |
---|
[6287] | 114 | |
---|
[7779] | 115 | void GLGuiWidget::hide() |
---|
| 116 | { |
---|
| 117 | this->setVisibility(false); |
---|
| 118 | } |
---|
[6287] | 119 | |
---|
[6431] | 120 | |
---|
[7779] | 121 | void GLGuiWidget::draw() const |
---|
| 122 | { |
---|
| 123 | this->backMat.select(); |
---|
[6287] | 124 | |
---|
[7779] | 125 | glBegin(GL_QUADS); |
---|
[7878] | 126 | glTexCoord2i(0,0); glVertex2d(0, 0); |
---|
| 127 | glTexCoord2i(0,1); glVertex2d(0, this->getSizeY2D()); |
---|
| 128 | glTexCoord2i(1,1); glVertex2d(this->getSizeX2D(), this->getSizeY2D()); |
---|
| 129 | glTexCoord2i(1,0); glVertex2d(this->getSizeX2D(), 0); |
---|
[7779] | 130 | glEnd(); |
---|
| 131 | } |
---|
| 132 | |
---|
[6287] | 133 | } |
---|