-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmywidget.cpp.autosave
86 lines (82 loc) · 2.49 KB
/
mywidget.cpp.autosave
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "mywidget.h"
MyWidget::MyWidget()
{
}
void MyWidget::initializeGL(){
glClearColor(1.0,1.0,1.0,1.0);
}
void MyWidget::resizeGL(int width,int height){
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
}
void MyWidget::paintGL(){
glClear(GL_COLOR_BUFFER_BIT);
/*
glBegin(GL_POLYGON);
glColor3d(1.0,0.5,0.5);
glVertex2f(0,0);
glVertex2f(0.5,0);
glVertex2f(0.5,0.5);
glVertex2f(0.25,0.25);
glVertex2f(0,0.5);
glEnd();
*/
// draw data
for(auto layer:map->LAYERS){
Style gl_style;
gl_style=layer.layer_style;
for(auto feature:layer.features){
if(feature.feature_type==1){
// draw line
glLineWidth(gl_style.lineWidth);
glBegin(GL_LINE_STRIP);
int red =gl_style.lineColor.Red;
int green=gl_style.lineColor.Green;
int blue=gl_style.lineColor.Blue;
glColor3d(1.0*red/255,1.0*green/255,1.0*blue/255);
for(auto pt:feature.pts){
glVertex2f(xy2screen(pt).x,xy2screen(pt).y);
}
glEnd();
}
if(feature.feature_type==2){
// draw polygon
glPolygonMode(GL_FRONT,GL_FILL);
glBegin(GL_POLYGON);
int red =gl_style.polyColor.Red;
int green=gl_style.polyColor.Green;
int blue=gl_style.polyColor.Blue;
glColor3d(1.0*red/255,1.0*green/255,1.0*blue/255);
for(auto pt:feature.pts){
glVertex2f(xy2screen(pt).x,xy2screen(pt).y);
}
glEnd();
}
}
}
glFlush();
}
void MyWidget::DrawTest(){
}
Point MyWidget::xy2screen(Point pt){
// transfer point to screen coordinate
double width=this->map->right-this->map->left;
double height=this->map->top-this->map->bottom;
Point screen;
screen.x=(pt.x-this->map->left)/width*2-1;
screen.y=(pt.y-this->map->bottom)/height*2-1;
return screen;
}
void MyWidget::mousePressEvent(QMouseEvent *event){
// mouse click
double x,y;
x=event->x();
y=event->y();
double width=this->map->right-this->map->left;
double height=this->map->top-this->map->bottom;
double window_width=this->width();
double window_height=this->height();
double real_x,real_y;
real_x=x/window_width*width+this->map->left;
real_y=y/window_height*height+this->map->bottom;
}