PolygonDrawer.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. if (m_points.size() > 0) {
  24. glPointSize(5);
  25. glBegin(GL_POINTS);
  26. for (unsigned int i = 0; i < m_points.size(); ++i) {
  27. float xPos = m_points[i].x*width();
  28. float yPos = m_points[i].y*height();
  29. glVertex2f(xPos, yPos);
  30. }
  31. glEnd();
  32. glEnable (GL_LINE_SMOOTH);
  33. glEnable (GL_BLEND);
  34. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  35. glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
  36. glLineWidth(3);
  37. glColor4f(1, 1, 1, 1);
  38. glBegin(GL_LINE_LOOP);
  39. for (unsigned int i = 0; i < m_points.size(); ++i) {
  40. float xPos = m_points[i].x*width();
  41. float yPos = m_points[i].y*height();
  42. glVertex2f(xPos, yPos);
  43. }
  44. glEnd();
  45. glFlush();
  46. }
  47. };
  48. void PolygonDrawer::mousePressEvent(QMouseEvent* event) {
  49. QGLWidget::mousePressEvent(event);
  50. switch (event->button()) {
  51. case Qt::LeftButton: {
  52. m_points.push_back(CoordT<double>(static_cast<float>(event->x())/width(), 1.0f - static_cast<float>(event->y())/height()));
  53. updateGL();
  54. } break;
  55. case Qt::RightButton:
  56. m_points.clear();
  57. updateGL();
  58. break;
  59. default:
  60. break;
  61. }
  62. }
  63. void PolygonDrawer::contextMenuEvent(QContextMenuEvent* event) {
  64. }
  65. }//namespace NICE