Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial zooming. Grid is not drawn correctly yet

  • Loading branch information...
commit 1d8f26db165e598ba0c8cd5f5933e4bf531a6aba 1 parent 287d112
Antti Keränen authored

Showing 2 changed files with 26 additions and 15 deletions. Show diff stats Hide diff stats

  1. +23 15 editor_gl.cpp
  2. +3 0  editor_gl.h
38 editor_gl.cpp
@@ -27,6 +27,7 @@ C_GLEditor::C_GLEditor(QWidget* parent, QStandardItem* root) :
27 27
28 28 m_ViewPortX=0;
29 29 m_ViewPortY=0;
  30 + m_ZoomLevel=1.0;
30 31 }
31 32 C_GLEditor::~C_GLEditor()
32 33 {
@@ -72,7 +73,7 @@ void C_GLEditor::M_PaintPolygon(const C_Polygon& p)
72 73 {
73 74 std::pair<float, float> pos=it->M_Pos();
74 75 qglColor(it->M_Color());
75   - glVertex2f(m_ViewPortX+pos.first, m_ViewPortY+pos.second);
  76 + glVertex2f((m_ViewPortX+pos.first)*m_ZoomLevel, (m_ViewPortY+pos.second)*m_ZoomLevel);
76 77 }
77 78 glEnd();
78 79 }
@@ -92,7 +93,7 @@ void C_GLEditor::M_PaintPoints(const C_Polygon& p)
92 93 }
93 94 else qglColor(QColor::fromRgbF(0.4f, 0.4f, 0.4f, 1.0f));
94 95 std::pair<float, float> pos=it->M_Pos();
95   - glVertex3f(m_ViewPortX+pos.first, m_ViewPortY+pos.second, -1.0f);
  96 + glVertex3f((m_ViewPortX+pos.first)*m_ZoomLevel, (m_ViewPortY+pos.second)*m_ZoomLevel, -1.0f);
96 97 }
97 98 glEnd();
98 99 }
@@ -100,18 +101,18 @@ void C_GLEditor::M_PaintDrag()
100 101 {
101 102 glColor4f(0.6f, 0.8f, 1.0f, 0.4f);
102 103 glBegin(GL_TRIANGLE_STRIP);
103   - glVertex3f(m_DragPoints[0], m_DragPoints[2], -1.0f);
104   - glVertex3f(m_DragPoints[1], m_DragPoints[2], -1.0f);
105   - glVertex3f(m_DragPoints[0], m_DragPoints[3], -1.0f);
106   - glVertex3f(m_DragPoints[1], m_DragPoints[3], -1.0f);
  104 + glVertex3f(m_DragPoints[0]*m_ZoomLevel, m_DragPoints[2]*m_ZoomLevel, -1.0f);
  105 + glVertex3f(m_DragPoints[1]*m_ZoomLevel, m_DragPoints[2]*m_ZoomLevel, -1.0f);
  106 + glVertex3f(m_DragPoints[0]*m_ZoomLevel, m_DragPoints[3]*m_ZoomLevel, -1.0f);
  107 + glVertex3f(m_DragPoints[1]*m_ZoomLevel, m_DragPoints[3]*m_ZoomLevel, -1.0f);
107 108 glEnd();
108 109 glColor4f(0.0f, 0.2f, 1.0f, 0.8f);
109 110 glBegin(GL_LINE_STRIP);
110   - glVertex3f(m_DragPoints[0], m_DragPoints[2], -1.0f);
111   - glVertex3f(m_DragPoints[1], m_DragPoints[2], -1.0f);
112   - glVertex3f(m_DragPoints[1], m_DragPoints[3], -1.0f);
113   - glVertex3f(m_DragPoints[0], m_DragPoints[3], -1.0f);
114   - glVertex3f(m_DragPoints[0], m_DragPoints[2], -1.0f);
  111 + glVertex3f(m_DragPoints[0]*m_ZoomLevel, m_DragPoints[2]*m_ZoomLevel, -1.0f);
  112 + glVertex3f(m_DragPoints[1]*m_ZoomLevel, m_DragPoints[2]*m_ZoomLevel, -1.0f);
  113 + glVertex3f(m_DragPoints[1]*m_ZoomLevel, m_DragPoints[3]*m_ZoomLevel, -1.0f);
  114 + glVertex3f(m_DragPoints[0]*m_ZoomLevel, m_DragPoints[3]*m_ZoomLevel, -1.0f);
  115 + glVertex3f(m_DragPoints[0]*m_ZoomLevel, m_DragPoints[2]*m_ZoomLevel, -1.0f);
115 116 glEnd();
116 117 }
117 118
@@ -137,8 +138,8 @@ bool C_GLEditor::M_MouseOverVertex(float x, float y, const C_Vertex& v)
137 138
138 139 void C_GLEditor::mousePressEvent(QMouseEvent* e)
139 140 {
140   - float xraw=(float)e->pos().x()/(this->width()/2)-1.0f;
141   - float yraw=-((float)e->pos().y()/(this->height()/2)-1.0f);
  141 + float xraw=((float)e->pos().x()/(this->width()/2)-1.0f)/m_ZoomLevel;
  142 + float yraw=-((float)e->pos().y()/(this->height()/2)-1.0f)/m_ZoomLevel;
142 143 float x=M_RoundToPrecision(xraw, m_PointPrecision);
143 144 float y=M_RoundToPrecision(yraw, m_PointPrecision);
144 145 if(e->buttons() & Qt::LeftButton)
@@ -220,8 +221,8 @@ void C_GLEditor::M_Split()
220 221
221 222 void C_GLEditor::mouseMoveEvent(QMouseEvent* e)
222 223 {
223   - float xraw=(float)e->pos().x()/(this->width()/2)-1.0f;
224   - float yraw=-((float)e->pos().y()/(this->height()/2)-1.0f);
  224 + float xraw=((float)e->pos().x()/(this->width()/2)-1.0f)/m_ZoomLevel;
  225 + float yraw=-((float)e->pos().y()/(this->height()/2)-1.0f)/m_ZoomLevel;
225 226 float x=M_RoundToPrecision(xraw, m_PointPrecision);
226 227 float y=M_RoundToPrecision(yraw, m_PointPrecision);
227 228 if(e->buttons() & Qt::LeftButton)
@@ -361,6 +362,13 @@ void C_GLEditor::mouseDoubleClickEvent(QMouseEvent*)
361 362 if(ql.size()) emit(S_RequestColorDialog(ql));
362 363 }
363 364
  365 +void C_GLEditor::wheelEvent(QWheelEvent* e)
  366 +{
  367 + m_ZoomLevel+=(e->delta()*0.001f)*m_ZoomLevel;
  368 + if(m_ZoomLevel<0.001) m_ZoomLevel=0.001;
  369 + updateGL();
  370 +}
  371 +
364 372 bool C_GLEditor::M_PointInsideBox(float px, float py, float x1, float y1, float x2, float y2)
365 373 {
366 374 return (px >= std::min(x1,x2)) && (px <= std::max(x1,x2)) &&
3  editor_gl.h
@@ -45,6 +45,8 @@ class C_GLEditor : public QGLWidget
45 45
46 46 float m_PointPrecision;
47 47
  48 + float m_ZoomLevel;
  49 +
48 50 C_Vertex* m_SplitFirst;
49 51 C_Vertex* m_SplitSecond;
50 52
@@ -62,6 +64,7 @@ class C_GLEditor : public QGLWidget
62 64 void mouseReleaseEvent(QMouseEvent* e);
63 65 void mouseMoveEvent(QMouseEvent* e);
64 66 void mouseDoubleClickEvent(QMouseEvent* e);
  67 + void wheelEvent(QWheelEvent* e);
65 68 bool M_MouseOverVertex(float, float, const C_Vertex& v);
66 69 public:
67 70 C_GLEditor(QWidget* parent, QStandardItem* root);

0 comments on commit 1d8f26d

Please sign in to comment.
Something went wrong with that request. Please try again.