PolygonDrawer.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // C++ Implementation: PolygonDrawer
  3. //
  4. // Description:
  5. //
  6. //
  7. // Author: Marcel Brueckner <brueckner [at] informatik [dot] uni-jena [dot] de>, (C) 2008
  8. //
  9. // Copyright: See COPYING file that comes with this distribution
  10. //
  11. //
  12. #include "PolygonDrawer.h"
  13. namespace NICE {
  14. PolygonDrawer::PolygonDrawer ( QWidget* parent,
  15. const char* name ,
  16. Qt::WFlags flags )
  17. : ImageDisplay ( parent, name, flags )
  18. {
  19. };
  20. PolygonDrawer::~PolygonDrawer() {
  21. }
  22. void PolygonDrawer::paintGLObjects(void) {
  23. #ifdef NICE_USELIB_OPENGL
  24. if (m_points.size() > 0) {
  25. glPointSize(5);
  26. glBegin(GL_POINTS);
  27. for (unsigned int i = 0; i < m_points.size(); ++i) {
  28. float xPos = m_points[i].x*width();
  29. float yPos = m_points[i].y*height();
  30. glVertex2f(xPos, yPos);
  31. }
  32. glEnd();
  33. glEnable (GL_LINE_SMOOTH);
  34. glEnable (GL_BLEND);
  35. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  36. glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
  37. glLineWidth(3);
  38. glColor4f(1, 1, 1, 1);
  39. glBegin(GL_LINE_LOOP);
  40. for (unsigned int i = 0; i < m_points.size(); ++i) {
  41. float xPos = m_points[i].x*width();
  42. float yPos = m_points[i].y*height();
  43. glVertex2f(xPos, yPos);
  44. }
  45. glEnd();
  46. glFlush();
  47. }
  48. #else
  49. fthrow(Exception,"OpenGL lib not availabe, recompile using OpenGL!");
  50. #endif
  51. };
  52. void PolygonDrawer::mousePressEvent(QMouseEvent* event) {
  53. QGLWidget::mousePressEvent(event);
  54. switch (event->button()) {
  55. case Qt::LeftButton: {
  56. m_points.push_back(CoordT<double>(static_cast<float>(event->x())/width(), 1.0f - static_cast<float>(event->y())/height()));
  57. updateGL();
  58. } break;
  59. case Qt::RightButton:
  60. m_points.clear();
  61. updateGL();
  62. break;
  63. default:
  64. break;
  65. }
  66. }
  67. void PolygonDrawer::contextMenuEvent(QContextMenuEvent* event) {
  68. }
  69. }//namespace NICE