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 "material.h" |
---|
21 | |
---|
22 | #include "debug.h" |
---|
23 | |
---|
24 | using namespace std; |
---|
25 | |
---|
26 | /** |
---|
27 | * standard constructor |
---|
28 | */ |
---|
29 | GLGuiWidget::GLGuiWidget ( ) : Element2D(NULL) |
---|
30 | { |
---|
31 | this->init(); |
---|
32 | } |
---|
33 | |
---|
34 | |
---|
35 | /** |
---|
36 | * standard deconstructor |
---|
37 | */ |
---|
38 | GLGuiWidget::~GLGuiWidget() |
---|
39 | { |
---|
40 | |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
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; |
---|
53 | this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE); |
---|
54 | // this->setParent2D((Element2D*)NULL); |
---|
55 | |
---|
56 | this->backMat = new Material(); |
---|
57 | this->backMat->setDiffuse(0, 0, 0); |
---|
58 | |
---|
59 | this->frontMat = NULL; |
---|
60 | this->frontModel = 0; |
---|
61 | |
---|
62 | for (unsigned int i = 0; i < GLGuiSignalCount; i++) |
---|
63 | this->widgetSignals[i] = NULL; |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | bool GLGuiWidget::focusOverWidget(float x, float y) |
---|
68 | { |
---|
69 | if (this->getAbsCoor2D().x < x && this->getAbsCoor2D().x+ this->getSizeX2D() > x && |
---|
70 | this->getAbsCoor2D().y < y && this->getAbsCoor2D().y+ this->getSizeX2D() > y) |
---|
71 | return true; |
---|
72 | else |
---|
73 | return false; |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | * @brief connects a Signal to the Gui-Elements' Event. |
---|
78 | * @param sinalType the Type of Signal to set. @see GLGuiSignalType |
---|
79 | * @param signal the name of the Signal |
---|
80 | */ |
---|
81 | void GLGuiWidget::connectSignal(GLGuiSignalType signalType, const Executor& signal) |
---|
82 | { |
---|
83 | if (signalType >= GLGuiSignalCount) |
---|
84 | return; |
---|
85 | |
---|
86 | if (this->widgetSignals[signalType] != NULL) |
---|
87 | PRINTF(2)("Already connected a Signal to %s (%s) type %s... overwriting\n"); |
---|
88 | |
---|
89 | this->widgetSignals[signalType] = signal.clone(); |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * @brief removes a Signal from a Gui-ELements' Event |
---|
94 | * @param signalType the type of Signal to remove. |
---|
95 | */ |
---|
96 | void GLGuiWidget::disconnectSignal(GLGuiSignalType signalType) |
---|
97 | { |
---|
98 | if (signalType > GLGuiSignalCount) |
---|
99 | return; |
---|
100 | |
---|
101 | this->widgetSignals[signalType] = NULL; |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | void GLGuiWidget::show() |
---|
106 | { |
---|
107 | this->setVisibility(true); |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | void GLGuiWidget::draw() const |
---|
112 | { |
---|
113 | this->backMat->select(); |
---|
114 | |
---|
115 | glBegin(GL_QUADS); |
---|
116 | |
---|
117 | |
---|
118 | glVertex2d(0,0); |
---|
119 | glVertex2d(0, this->getSizeY2D()); |
---|
120 | glVertex2d(this->getSizeX2D(), this->getSizeY2D()); |
---|
121 | glVertex2d(this->getSizeX2D(),0); |
---|
122 | |
---|
123 | glEnd(); |
---|
124 | } |
---|
125 | |
---|