50 #include <ACG/GL/acg_glew.hh>
51 #include "QtWidgetNode.hh"
52 #include <ACG/Geometry/Types/PlaneT.hh>
54 #include <QApplication>
63 namespace SceneGraph {
68 bool QtWidgetNode::NodeEventFilter::eventFilter(QObject *_obj, QEvent *_event)
72 if (_event->type() == QEvent::LayoutRequest || _event->type() == QEvent::Paint)
76 repaint = repaint && node_->planeCreated_;
78 bool result = QObject::eventFilter(_obj, _event);
103 planeCreated_(false),
105 anisotropicSupport_(false)
124 glDeleteTextures(1,&texID_);
134 widget_->removeEventFilter(ef_);
140 planeCreated_ =
false;
146 widget_->installEventFilter(ef_);
169 _bbMin.minimize( pos0 );
170 _bbMin.minimize( pos0 + xDird);
171 _bbMin.minimize( pos0 + yDird);
172 _bbMin.minimize( pos0 + xDird + yDird);
173 _bbMax.maximize( pos1 );
174 _bbMax.maximize( pos1 + xDird);
175 _bbMax.maximize( pos1 + yDird);
176 _bbMax.maximize( pos1 + xDird + yDird);
200 const size_t buffersize = 4*8;
201 float vboData_[buffersize] = { 0.0,0.0,0.0,
207 (
float)outerCorner[0],(float)outerCorner[1],(
float)outerCorner[2],
216 glGenBuffersARB(1, &
vbo_);
219 glBindBufferARB(GL_ARRAY_BUFFER_ARB,
vbo_);
222 glBufferDataARB(GL_ARRAY_BUFFER_ARB, buffersize *
sizeof(
float), &vboData_[0], GL_STATIC_DRAW_ARB);
224 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
231 widget_->removeEventFilter(ef_);
232 QPixmap pix = QPixmap::grabWidget(
widget_);
233 widget_->installEventFilter(ef_);
235 QImage image = pix.toImage();
236 image = QGLWidget::convertToGLFormat( image );
241 glGenTextures( 1, &texID_ );
244 glBindTexture( GL_TEXTURE_2D, texID_ );
246 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
247 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
248 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
249 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
251 if (anisotropicSupport_)
253 GLfloat anisotropyValue;
254 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropyValue);
255 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropyValue);
258 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA,
259 GL_UNSIGNED_BYTE, image.bits());
260 glGenerateMipmap(GL_TEXTURE_2D);
268 oldWidgetHeight_=
widget_->height();;
274 projNullPos = _state.
unproject(projNullPos);
278 const ACG::Vec3d xDirection =
Vec3d(projPos[0]-projNullPos[0],0.0,0.0);
279 const ACG::Vec3d yDirection =
Vec3d(0.0,projPos[1]-projNullPos[1],0.0);
291 double heightRatio =
widget_->height() / (double)oldWidgetHeight_;
294 oldWidgetHeight_ =
widget_->height();
303 void QtWidgetNode::mouseEvent(
GLState& _state , QMouseEvent* _event )
320 ACG::Vec3d rayDir = (unprojEventPos - _state.
eye()).normalize();
321 if (!intersectPlane.intersect_ray(_state.
eye(),_state.
eye()+rayDir,intersecPos,distance))
326 ACG::Vec3d toInter = intersecPos - topLeftCorner;
329 double sX = (xDir | toInter)/xDir.sqrnorm();
330 double sY = (yDir | toInter)/yDir.sqrnorm();
332 if (sX < 0.0 || sX > 1.0 || sY < 0.0 || sY > 1.0)
336 QPoint widgetEventPos(sX *
widget_->width(), sY *
widget_->height());
339 QWidget *childWidget =
widget_->childAt(widgetEventPos);
344 widgetEventPos -= childWidget->pos();
347 QMouseEvent event(_event->type(),widgetEventPos,_event->button(),_event->buttons(),_event->modifiers());
348 QApplication::sendEvent(childWidget,&event);
351 QEvent paintEvent(QEvent::Paint);
352 QApplication::sendEvent(
widget_,&paintEvent);
356 void QtWidgetNode::mouseEvent(QMouseEvent* _event )
360 mouseEvent(*
state_,_event);
374 ro.debugName = (std::string(
"QtWidgetNode: ")+
name()).c_str();
382 planeCreated_ =
true;
388 _state.
translate(pos[0], pos[1], pos[2]);
402 texture.type = GL_TEXTURE_2D;
403 texture.shadow =
false;
416 ro.setMaterial(&localMaterial);
419 ro.glDrawArrays(GL_QUADS, 0, 4);
QWidget * widget_
current widget
ShaderGenDesc shaderDesc
Drawmode and other shader params.
Namespace providing different geometric functions concerning angles.
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const
return available draw modes
std::string name() const
Returns: name of node (needs not be unique)
QtWidgetNode(QWidget *_widget, BaseNode *_parent=0, std::string _name="<QtWidgetNode>")
Construct a QtWidget Node.
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
const GLMatrixd & modelview() const
get modelview matrix
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
void setWidget(QWidget *_w)
set a new widget at the current widgets position (if last widget wasn't zero)
VectorT< double, 3 > Vec3d
void addElement(const VertexElement *_pElement)
void baseColor(const Vec4f &_c)
set the base color
bool checkExtensionSupported(const std::string &_extension)
~QtWidgetNode()
destructor
void push_modelview_matrix()
push modelview matrix
ACGDLLEXPORT DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
void createGeometry(GLState &_state)
widgetgeometry will be screen aligned. the width/height and position is in respect to the _state proj...
bool hidden()
Is node not visible (status != Active)?
void updateGeometry()
update geometry on current position with old projection/view matrix
Interface class between scenegraph and renderer.
GLMatrixd modelview
Modelview transform.
void diffuseColor(const Vec4f &_d)
set the diffuse color.
unsigned int vbo_
VBO used to render the plane.
static void deleteBuffers(GLsizei n, const GLuint *buffers)
void getRenderObjects(ACG::IRenderer *_renderer, ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat)
Add the objects to the given renderer.
ACGDLLEXPORT DrawMode POINTS
draw unlighted points using the default base color
void addTexture(const Texture &_t)
adds a texture to stage RenderObjects::numTextures()
void setPlane(const ACG::Vec3d &_position, const ACG::Vec3d &_xDirection, const ACG::Vec3d &)
Set plane.
void pop_modelview_matrix()
pop modelview matrix
GLState * state_
last state
void specularColor(const Vec4f &_s)
set the specular color
void uploadPlane()
upload widget plane data to graphics card
void createTexture()
create and update the widget texture
Vec3d eye() const
get eye point
Plane plane_
plane position and dimensions
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
int viewport_height() const
get viewport height
int oldWidgetWidth_
initial widgetHeight/Width. Is 0, if widget is 0 or if plane wasn't initialized with current view/pro...
void boundingBox(ACG::Vec3d &_bbMin, ACG::Vec3d &_bbMax)
update bounding box
void setDirty(bool _dirty=true)
mark node for redrawn
void ambientColor(const Vec4f &_a)
set the ambient color.