1 /**
2  * @brief PFS library - additional utilities
3  *
4  * This file is a part of PFSTOOLS package.
5  * ----------------------------------------------------------------------
6  * Copyright (C) 2006 Radoslaw Mantiuk
7  *
8  *  This library is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU Lesser General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2.1 of the License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  * ----------------------------------------------------------------------
22  *
23  * @author Radoslaw Mantiuk, <radoslaw.mantiuk@gmail.com>
24  * @author Oliver Barth <obarth@mpi-inf.mpg.de>
25  */
26 
27 #include<stdio.h>
28 
29 #include "module.h"
30 
31 
32 
Module()33 Module::Module() {
34 
35 	isVisible = GL_TRUE;
36 	pos_x = 10;
37 	pos_y = 10;
38 	width = 100;
39 	height = 40;
40 
41 	// background color
42 	winBackgroundColor = new float[4];
43 	for(int i=0; i<3; i++)
44 		winBackgroundColor[i] = 1.0f;
45 	winBackgroundColor[3] = 0.8f;
46 }
47 
48 
49 
~Module()50 Module::~Module() {
51 
52 	delete [] winBackgroundColor;
53 }
54 
55 
56 
drawBackground(void)57 void Module::drawBackground(void) {
58 
59 	if( isVisible == GL_FALSE)
60 		return;
61 
62 	// draw background
63 	glEnable(GL_BLEND);
64 	glColor4fv(winBackgroundColor);
65 	glRecti( 0, 0, width, height);
66 	glDisable(GL_BLEND);
67 }
68 
69 
70 
redrawStart(void)71 int Module::redrawStart(void) {
72 
73 	if( isVisible == GL_FALSE)
74 		return 1;
75 
76 	glGetIntegerv( GL_VIEWPORT, param); // remember old vieport
77 
78 	glMatrixMode(GL_MODELVIEW);
79 	glPushMatrix();
80 	//glLoadIdentity();
81 
82 	glMatrixMode(GL_PROJECTION);
83 	glPushMatrix();
84 	glLoadIdentity();
85 
86 	glViewport( pos_x, pos_y, width, height);
87 	glOrtho( 0, width, 0, height, -1.0f, 1.0f);
88 
89 	drawBackground();
90 
91 	return 0;
92 }
93 
94 
95 
redrawEnd(void)96 void Module::redrawEnd(void) {
97 
98 	if( isVisible == GL_FALSE)
99 		return;
100 
101 	glMatrixMode(GL_PROJECTION);
102 	glPopMatrix();
103 	glViewport( param[0], param[1], param[2], param[3]); // restore viewport
104 	glMatrixMode(GL_MODELVIEW);
105 	glPopMatrix();
106 }
107 
108 
109 
setPosition(int _x,int _y)110 void Module::setPosition( int _x, int _y) {
111 	pos_x = _x;
112 	pos_y = _y;
113 }
114 
115 
116 
setSize(int _width,int _height)117 void Module::setSize( int _width, int _height) {
118 	width = _width;
119 	height = _height;
120 }
121 
122 
123 
getWidth()124 int Module::getWidth() {
125 	return width ;
126 }
127 
128 
129 
getHeight()130 int Module::getHeight() {
131 	return height ;
132 }
133 
134 
135 
setWidth(int _width)136 void Module::setWidth(int _width){
137 	width = _width;
138 }
139 
140 
141 
setHeight(int _height)142 void Module::setHeight(int _height){
143 	height = _height;
144 }
145 
146 
147 
setVisible(bool _isVisible)148 void Module::setVisible(bool _isVisible) {
149 
150 	isVisible = _isVisible;
151 }
152 
153 
154 
getVisible(void)155 bool Module::getVisible(void) {
156 	return isVisible;
157 }
158 
159 
160 
161 // not used anymore
162 /*
163 int RMGLWin::processSelection(int xCoord, int yCoord) {
164 
165 	if( isVisible == GL_FALSE)
166 		return 1;
167 
168 	redrawStart();
169 
170 	// Hits counter and viewport martix
171 	GLint hits, viewp[4];
172 	// Get actual viewport
173 	glGetIntegerv(GL_VIEWPORT, viewp);
174 
175 	#define BUFFER_SIZE 64
176 	// Table for selection buffer data
177 	GLuint selectionBuffer[BUFFER_SIZE];
178 	// Prepare selection buffer
179 	glSelectBuffer(BUFFER_SIZE, selectionBuffer);
180 
181 	// Change rendering mode
182 	glRenderMode(GL_SELECT);
183 	// Initializes the Name Stack
184 	glInitNames();
185 	// Push 0 (at least one entry) Onto the Stack
186 	glPushName(0);
187 	// Set new projection matrix as a box around xPos, yPos
188 	glLoadIdentity();
189 
190 	int hh = glutGet(GLUT_WINDOW_HEIGHT);
191 	// Picking matrix at position xCoord, windowSize - yCoord (fliped window Y axis)
192 	// and size of 4 units in depth
193 	gluPickMatrix(xCoord, hh - yCoord, 4, 4, viewp);
194 
195 	glOrtho(0.0f, viewp[2], 0.0f, viewp[3], -10.0f, 10.0f); // last 1.0 -1.0 it's enough
196 	drawBackground(); // draw only picked parts
197 
198 	int ret = 0;
199 
200 	hits = glRenderMode(GL_RENDER);
201 
202 	if(hits > 0) {
203 		ret = 1;
204 	}
205 
206 	redrawEnd();
207 
208 	return ret;
209 }
210  */
211 
212 
213 
214 
215 
216 
217 
218 
219 
220