1 | /* |
---|
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. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI |
---|
17 | |
---|
18 | #include "glgui_widget.h" |
---|
19 | |
---|
20 | #include "glgui_cursor.h" |
---|
21 | |
---|
22 | #include "material.h" |
---|
23 | |
---|
24 | #include "debug.h" |
---|
25 | |
---|
26 | namespace OrxGui |
---|
27 | { |
---|
28 | |
---|
29 | /** |
---|
30 | * standard constructor |
---|
31 | */ |
---|
32 | GLGuiWidget::GLGuiWidget ( ) |
---|
33 | { |
---|
34 | this->init(); |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | /** |
---|
39 | * standard deconstructor |
---|
40 | */ |
---|
41 | GLGuiWidget::~GLGuiWidget() |
---|
42 | { |
---|
43 | } |
---|
44 | |
---|
45 | GLGuiWidget* GLGuiWidget::_focused = NULL; |
---|
46 | GLGuiWidget* GLGuiWidget::_inputGrabber = NULL; |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | /** |
---|
51 | * initializes the GUI-element |
---|
52 | */ |
---|
53 | void GLGuiWidget::init() |
---|
54 | { |
---|
55 | this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget"); |
---|
56 | |
---|
57 | this->_focusable = false; |
---|
58 | this->_clickable = false; |
---|
59 | this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE); |
---|
60 | |
---|
61 | this->backMat.setDiffuse(1.0, 1.0, 1.0); |
---|
62 | |
---|
63 | this->frontModel = 0; |
---|
64 | |
---|
65 | this->widgetSignals.resize(SignalCount, SignalConnector()); |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | bool GLGuiWidget::focusOverWidget(const Vector2D& position) const |
---|
70 | { |
---|
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); |
---|
73 | } |
---|
74 | |
---|
75 | bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const |
---|
76 | { |
---|
77 | return this->focusOverWidget(cursor->getAbsCoor2D()); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
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 | */ |
---|
86 | void GLGuiWidget::connectSignal(SignalType signalType, BaseObject* object, const Executor* signal) |
---|
87 | { |
---|
88 | if (signalType >= this->widgetSignals.size()) |
---|
89 | return; |
---|
90 | |
---|
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"); |
---|
93 | |
---|
94 | this->widgetSignals[signalType] = SignalConnector(object, signal); |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * @brief removes a Signal from a Gui-ELements' Event |
---|
99 | * @param signalType the type of Signal to remove. |
---|
100 | */ |
---|
101 | void GLGuiWidget::disconnectSignal(SignalType signalType) |
---|
102 | { |
---|
103 | if (signalType >= this->widgetSignals.size()) |
---|
104 | return; |
---|
105 | |
---|
106 | this->widgetSignals[signalType] = SignalConnector(); |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | void GLGuiWidget::show() |
---|
111 | { |
---|
112 | this->setVisibility(true); |
---|
113 | } |
---|
114 | |
---|
115 | void GLGuiWidget::hide() |
---|
116 | { |
---|
117 | this->setVisibility(false); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | void GLGuiWidget::draw() const |
---|
122 | { |
---|
123 | this->backMat.select(); |
---|
124 | |
---|
125 | glBegin(GL_QUADS); |
---|
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); |
---|
130 | glEnd(); |
---|
131 | } |
---|
132 | |
---|
133 | } |
---|