rock_widget_collection  0.1
ImageViewOldGL.cc
Go to the documentation of this file.
1 /*
2  * File: ImageViewGL.cc
3  * Author: blueck
4  *
5  * Created on 17. Juni 2010, 14:14
6  */
7 #include <iostream>
8 #include "ImageViewOldGL.h"
9 #include "ImageViewOld.h"
10 
12  QGLWidget(&parent),
13  image_view(parent)
14 {
15 }
16 
18 {
19 }
20 
21 void ImageViewOldGL::paintGL()
22 {
23  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
24  glDrawPixels(image_view.image.width(), image_view.image.height(), GL_RGB, GL_UNSIGNED_BYTE, image_view.image.bits());
25  QList<DrawItem*>::iterator iter = image_view.items.begin();
26  for(;iter != image_view.items.end();++iter)
27  {
28  if(!image_view.disabledGroups.contains((*iter)->getGroupNr()))
29  if((*iter)->onOpenGL())
30  (*iter)->renderOnGl(*this,image_view.source,image_view.target);
31  }
32 }
33 
34 void ImageViewOldGL::setGLViewPoint(int display_width,int display_height)
35 {
36  if(!display_width || !display_height)
37  {
38  display_width = width();
39  display_height = height();
40  }
41 
42  float x =1;
43  float y =1;
44 
45  if (image_view.image.width() && image_view.image.height())
46  {
47  x = ((float)display_width)/ image_view.image.width();
48  y = ((float)display_height)/ image_view.image.height();
49  }
50 
51  int x_offset = 0;
52  int y_offset = 0;
53  if(aspect_ratio)
54  {
55  if(x < y)
56  {
57  y_offset = -0.5f*(display_height-x*image_view.image.height());
58  y = x;
59  }
60  else
61  {
62  x_offset = 0.5f*(display_width-y*image_view.image.width());
63  x = y;
64  }
65  }
66  glPixelZoom(x,-y);
67  glMatrixMode(GL_PROJECTION);
68  glLoadIdentity();
69  glOrtho(0, display_width, 0, display_height, 0, 1);
70  glMatrixMode(GL_MODELVIEW);
71  glLoadIdentity();
72  glViewport(0,0, display_width, display_height);
73  glRasterPos2i(x_offset,display_height+y_offset);
74 
75  // target.setRect(x_offset,y_offset,display_width-x_offset,display_width-y_offset);
76  // source.setRect(0,0,image->width(),image->height());
77 }
78 
79 void ImageViewOldGL::resizeGL(int w, int h)
80 {
81  setGLViewPoint(w,h);
82  paintGL();
83 }
virtual ~ImageViewOldGL()
QList< DrawItem * > items
Definition: PaintWidget.h:127
ImageViewOldGL(ImageViewOld &parent)
void setGLViewPoint(int display_width=0, int display_height=0)
QList< int > disabledGroups
Definition: PaintWidget.h:129