beobotmap.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "beobotmap.h"
00039 #include <cmath>
00040
00041 BeoBotMap::BeoBotMap(QWidget *parent, const char *name)
00042 :QGLWidget(parent, name)
00043 {
00044 setFormat(QGLFormat(DoubleBuffer | DepthBuffer));
00045
00046 iconlistx=100; iconlisty=100;
00047 iconlistgx = 0; iconlistgy= 0;
00048 colors[0] = yellow;
00049 colors[1] = blue;
00050 colors[2] = green;
00051 colors[3] = white;
00052 colors[4] = red;
00053 colors[5] = QColor(255,85,0);
00054 colors[6] = QColor(0,170,255);
00055
00056
00057 createIcon(2);
00058 }
00059
00060 void BeoBotMap::createIcon(int num)
00061 {
00062 int i;
00063 sizeOfList = num;
00064
00065 listOfIcon = (BeoBotIcon *)malloc(sizeof(BeoBotIcon)*sizeOfList);
00066 for(i=0 ; i<sizeOfList ; i++)
00067 {
00068 listOfIcon[i].x = 100;
00069 listOfIcon[i].y = 100;
00070 listOfIcon[i].glx = 0.0;
00071 listOfIcon[i].gly = 0.0;
00072 listOfIcon[i].edgeSize = 30;
00073 listOfIcon[i].selected = 0;
00074
00075
00076 if(i==1)
00077 {
00078 listOfIcon[i].x = 140;
00079 listOfIcon[i].y = 140;
00080 listOfIcon[i].glx = 1.0;
00081 listOfIcon[i].gly = -1.0;
00082 listOfIcon[i].edgeSize = 30;
00083 listOfIcon[i].selected = 0;
00084
00085 }
00086 }
00087 updateGL();
00088 }
00089
00090 void BeoBotMap::initializeGL()
00091 {
00092 qglClearColor(black);
00093 glShadeModel(GL_FLAT);
00094 glEnable(GL_DEPTH_TEST);
00095 glEnable(GL_CULL_FACE);
00096 }
00097
00098 void BeoBotMap::resizeGL(int w, int h)
00099 {
00100 glViewport(0, 0, w, h);
00101 glMatrixMode(GL_PROJECTION);
00102 glLoadIdentity();
00103 GLfloat x = (GLfloat)w/h;
00104 glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
00105 glMatrixMode(GL_MODELVIEW);
00106 }
00107
00108 void BeoBotMap::paintGL()
00109 {
00110 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00111 draw();
00112 }
00113
00114 void BeoBotMap::draw()
00115 {
00116 int i,j;
00117
00118 GLfloat coords[4][2] =
00119 {{-0.125,-0.125},{0.125,-0.125},
00120 {0.125,0.125},{-0.125,0.125}};
00121
00122 glMatrixMode(GL_MODELVIEW);
00123 glLoadIdentity();
00124 glTranslatef(0.0,0.0,-10.0);
00125
00126
00127 qglColor(red);
00128 glBegin(GL_QUADS);
00129 for(i=0 ; i<sizeOfList ; i++)
00130 for(j=0 ; j<4 ; j++)
00131 glVertex3f(coords[j][0]+listOfIcon[i].glx,coords[j][1]+listOfIcon[i].gly,0.0);
00132 glEnd();
00133
00134
00135 qglColor(white);
00136 glBegin(GL_TRIANGLES);
00137 glVertex2f(0.0,0.1);
00138 glVertex2f(-0.1,-0.1);
00139 glVertex2f(0.1,-0.1);
00140 glEnd();
00141 glBegin(GL_QUADS);
00142 glVertex2f(-0.025,-0.2);
00143 glVertex2f(0.025,-0.2);
00144 glVertex2f(0.025,-0.1);
00145 glVertex2f(-0.025,-0.1);
00146 glEnd();
00147
00148 }
00149
00150 void BeoBotMap::mousePressEvent(QMouseEvent *event)
00151 {
00152 lastPos = event->pos();
00153
00154 }
00155
00156 void BeoBotMap::mouseDoubleClickEvent(QMouseEvent *event)
00157 {
00158 int i;
00159 lastPos = event->pos();
00160
00161
00162
00163 for(i=0 ; i<sizeOfList; i++)
00164 {
00165 if(lastPos.x() < (listOfIcon[i].x)+15 &&
00166 lastPos.x() > (listOfIcon[i].x)-15 &&
00167 lastPos.y() < (listOfIcon[i].y)+15 &&
00168 lastPos.y() > (listOfIcon[i].y)-15
00169 )
00170 listOfIcon[i].selected = 1;
00171 else
00172 listOfIcon[i].selected = 0;
00173 }
00174 }
00175
00176 void BeoBotMap::mouseReleaseEvent(QMouseEvent *event)
00177 {
00178 }
00179
00180 void BeoBotMap::mouseMoveEvent(QMouseEvent *event)
00181 {
00182 int dx = event->x() - lastPos.x();
00183 int dy = event->y() - lastPos.y();
00184 lastPos = event->pos();
00185
00186 if(event->state() & LeftButton)
00187 {
00188 for(int i=0 ; i<sizeOfList ; i++)
00189 if(lastPos.x() < (listOfIcon[i].x)+15 &&
00190 lastPos.x() > (listOfIcon[i].x)-15 &&
00191 lastPos.y() < (listOfIcon[i].y)+15 &&
00192 lastPos.y() > (listOfIcon[i].y)-15 &&
00193 listOfIcon[i].selected == 1
00194 )
00195 {
00196 listOfIcon[i].x += dx;
00197 listOfIcon[i].y += dy;
00198 listOfIcon[i].glx += GLfloat(dx) * 0.025;
00199 listOfIcon[i].gly -= GLfloat(dy) * 0.025;
00200
00201
00202
00203 }
00204 }
00205 updateGL();
00206 }
00207
00208 void BeoBotMap::returnSelectedCoord(float &fx, float &fy)
00209 {
00210 int i;
00211 fx = fy = 0.0F;
00212 for(i=0 ; i<sizeOfList ; i++)
00213 if(listOfIcon[i].selected == 1)
00214 {
00215 fx = listOfIcon[i].x;
00216 fy = listOfIcon[i].y;
00217 }
00218 }