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
00039 #ifndef QT_POOL_IMAGE_C_DEFINED
00040 #define QT_POOL_IMAGE_C_DEFINED
00041
00042 #ifdef INVT_HAVE_QT3
00043
00044 #include "poolimage.h"
00045 #include <cmath>
00046
00047 PoolImage::PoolImage(QWidget *parent, const char *name)
00048 :QGLWidget(parent, name)
00049 {
00050 setFormat(QGLFormat(DoubleBuffer | DepthBuffer));
00051 sizeOfList = 0;
00052 angle = 0.0F;
00053 scale = 1.0F;
00054 right = false;
00055 maxX=minX=maxY=minY=0;
00056
00057 colors[0] = yellow;
00058 colors[1] = blue;
00059 colors[2] = green;
00060
00061 colors[3] = white;
00062 colors[4] = red;
00063 colors[5] = QColor(255,85,0);
00064 colors[6] = QColor(0,170,255);
00065 }
00066
00067
00068 void PoolImage::initializeGL()
00069 {
00070 qglClearColor(black);
00071 glShadeModel(GL_FLAT);
00072 glEnable(GL_DEPTH_TEST);
00073 glEnable(GL_CULL_FACE);
00074 }
00075
00076 void PoolImage::resizeGL(int w, int h)
00077 {
00078 glViewport(0, 0, w, h);
00079 glMatrixMode(GL_PROJECTION);
00080 glLoadIdentity();
00081 GLfloat x = (GLfloat)w/h;
00082 glFrustum(-x, x, -1.0, 1.0, 4.0, 15.0);
00083 glMatrixMode(GL_MODELVIEW);
00084 }
00085
00086 void PoolImage::paintGL()
00087 {
00088 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00089 draw();
00090 }
00091
00092 void PoolImage::draw()
00093 {
00094 int theone=-1, i, ci;
00095
00096 static const GLfloat coords[4][2] =
00097 {{-0.125,-0.125},{0.125,-0.125},
00098 {0.125,0.125},{-0.125,0.125}};
00099
00100 glMatrixMode(GL_MODELVIEW);
00101 glLoadIdentity();
00102 glTranslatef(0.0,0.0,-10.0);
00103
00104 for(ci=0; ci<sizeOfList ; ci++)
00105 {
00106 if(iconlist[ci].selected == 2)
00107 {
00108 glBegin(GL_QUADS);
00109 qglColor(colors[iconlist[ci].selected]);
00110 for(i=0 ; i<4 ; i++)
00111 glVertex3f(coords[i][0]+(iconlist[ci].glx), coords[i][1]+(iconlist[ci].gly), 0.0);
00112 glEnd();
00113 theone = ci;
00114 }
00115 }
00116
00117 for(ci=0; ci<sizeOfList ; ci++)
00118 {
00119 if(ci!=theone)
00120 {
00121 glBegin(GL_QUADS);
00122 qglColor(colors[iconlist[ci].selected]);
00123 for(i=0 ; i<4 ; i++)
00124 glVertex3f(coords[i][0]+(iconlist[ci].glx), coords[i][1]+(iconlist[ci].gly), 0.0);
00125 glEnd();
00126 }
00127 }
00128
00129
00130 qglColor(white);
00131 glRotatef(0+angle,0,0,1);
00132 for(i=0 ; i<40 ; i++)
00133 {
00134 glBegin(GL_LINES);
00135 glVertex2f(-5.0+i*0.25, -5.0);
00136 glVertex2f(-5.0+i*0.25,5.0);
00137 glEnd();
00138 }
00139
00140
00141 glBegin(GL_TRIANGLES);
00142 glVertex2f(0.0,0.1);
00143 glVertex2f(-0.1,-0.1);
00144 glVertex2f(0.1,-0.1);
00145 glEnd();
00146 glBegin(GL_QUADS);
00147 glVertex2f(-0.025,-0.2);
00148 glVertex2f(0.025,-0.2);
00149 glVertex2f(0.025,-0.1);
00150 glVertex2f(-0.025,-0.1);
00151 glEnd();
00152
00153 glRotatef(90,0,0,1);
00154 for(i=0 ; i<40 ; i++)
00155 {
00156 glBegin(GL_LINES);
00157 glVertex2f(-5.0+i*0.25, -5.0);
00158 glVertex2f(-5.0+i*0.25,5.0);
00159 glEnd();
00160 }
00161
00162 }
00163
00164 void PoolImage::mousePressEvent(QMouseEvent *event)
00165 {
00166 lastPos = event->pos();
00167 }
00168
00169 void PoolImage::mouseDoubleClickEvent(QMouseEvent *event)
00170 {
00171
00172
00173
00174
00175
00176
00177 }
00178
00179 void PoolImage::mouseReleaseEvent(QMouseEvent *event)
00180 {
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 }
00201
00202 void PoolImage::mouseMoveEvent(QMouseEvent *event)
00203 {
00204 int dx = event->x() - lastPos.x();
00205 int dy = event->y() - lastPos.y();
00206 lastPos = event->pos();
00207
00208 for(int i=0 ; i<sizeOfList ; i++)
00209 {
00210 if(event->state() & LeftButton)
00211 {
00212 if(
00213
00214
00215
00216 iconlist[i].selected ==2)
00217 {
00218 iconlist[i].setPosition(dx, dy);
00219 updateGL();
00220 }
00221 }
00222 else if(event->state() & RightButton)
00223 {
00224 }
00225
00226 }
00227 }
00228
00229 void PoolImage::createIcon(int num)
00230 {
00231 int i;
00232 int oldSize = sizeOfList;
00233 sizeOfList = num;
00234
00235
00236 if(oldSize != 0 && oldSize <= sizeOfList)
00237 {
00238 iconImage *temp = (iconImage *)malloc(sizeof(iconImage)*(sizeOfList+4));
00239 for(i=0 ; i<oldSize ; i++)
00240 temp[i] = iconlist[i];
00241 for(i = oldSize ; i<sizeOfList ; i++)
00242 {
00243 iconlist[i].x = 300;
00244 iconlist[i].y = 220;
00245 iconlist[i].glx = 0.0;
00246 iconlist[i].gly = 0.0;
00247 iconlist[i].edgeSize = 22;
00248 iconlist[i].selected = 0;
00249 }
00250 }
00251 else
00252 {
00253 iconlist = (iconImage *)malloc(sizeof(iconImage)*sizeOfList);
00254 for(i=0; i<sizeOfList ; i++)
00255 {
00256
00257 iconlist[i].x = 300;
00258 iconlist[i].y = 220;
00259 iconlist[i].glx = 0.0;
00260 iconlist[i].gly = 0.0;
00261 iconlist[i].edgeSize = 22;
00262 iconlist[i].selected = 0;
00263 }
00264 }
00265 updateGL();
00266 }
00267
00268 void PoolImage::currentItem(int item)
00269 {
00270 for(int i=0 ; i<sizeOfList ; i++)
00271 {
00272 if(i == item)
00273 iconlist[i].selected = 2;
00274 else
00275 {
00276 if( i < 4)
00277 iconlist[i].selected = 3+i;
00278 else
00279 iconlist[i].selected = 1;
00280 }
00281 }
00282 updateGL();
00283 }
00284
00285 void PoolImage::getCoord(int i, int &x, int &y)
00286 {
00287 x = iconlist[i].x;
00288 y = iconlist[i].y;
00289 }
00290
00291 void PoolImage::setCoordByPix(int i, int x, int y)
00292 {
00293 iconlist[i].x = x;
00294 iconlist[i].y = y;
00295 iconlist[i].glx = (GLfloat)(x-300) * 0.01137F;
00296 iconlist[i].gly = -(GLfloat)(y-220) * 0.01137F;
00297 updateGL();
00298 }
00299
00300 void PoolImage::setCoordByGL(int i, float glx, float gly)
00301 {
00302 iconlist[i].glx = glx;
00303 iconlist[i].gly = gly;
00304 iconlist[i].x = int(glx/0.01137F + 300.0F + 0.5F);
00305 iconlist[i].y = int(gly/0.01137F + 220.0F + 0.5F);
00306 updateGL();
00307 }
00308
00309 float PoolImage::getAngle()
00310 {
00311 return angle;
00312 }
00313
00314 void PoolImage::getRealPosition(int i, float &rx, float &ry)
00315 {
00316
00317 float tempx = float(iconlist[i].glx - iconlist[0].glx);
00318 float tempy = -float(iconlist[0].gly - iconlist[i].gly);
00319 float tempa = angle;
00320
00321 if(i == 0)
00322 {
00323 tempx = iconlist[0].glx;
00324 tempy = iconlist[0].gly;
00325 }
00326
00327 while(tempa > 180)
00328 tempa = tempa -360;
00329 while(tempa < -180)
00330 tempa = tempa + 360;
00331 tempa = -tempa/180.0F * 3.14F;
00332
00333
00334 rx = (tempx * cos(tempa) - tempy * sin(tempa)) * scale;
00335 ry = (tempx * sin(tempa) + tempy * cos(tempa)) * scale;
00336
00337
00338
00339
00340
00341
00342 }
00343
00344 void PoolImage::getGLPosition(float rx, float ry, float &gx, float &gy)
00345 {
00346
00347 float tx, tempx = rx / scale;
00348 float ty, tempy = ry / scale;
00349 float tempa = angle;
00350
00351
00352 while(tempa > 180)
00353 tempa = tempa -360;
00354 while(tempa < -180)
00355 tempa = tempa + 360;
00356 tempa = tempa/180.0F * 3.14F;
00357
00358
00359 tx = tempx * cos(tempa) - tempy * sin(tempa);
00360 ty = tempx * sin(tempa) + tempy * cos(tempa);
00361
00362
00363 gx = tx + iconlist[0].glx;
00364 gy = ty + iconlist[0].gly;
00365
00366 }
00367
00368 #endif // INVT_HAVE_QT3
00369
00370 #endif // QT_POOL_IMAGE_C_DEFINED
00371
00372
00373
00374
00375
00376
00377