simulation.h
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 <qgl.h>
00039
00040 class iconImage
00041 {
00042 public:
00043 iconImage(){};
00044 iconImage(int ax, int ay,int size)
00045 {
00046 x = ax; y = ay;
00047 edgeSize = size;
00048 selected = false;
00049 glx = (x - 300) * 0.01137; gly = (y - 220) * 0.01137;
00050 };
00051 void setPosition(int ax, int ay)
00052 {
00053 x = x + ax; y = y + ay;
00054 glx = glx + GLfloat(ax) * 0.01137;
00055 gly = gly - GLfloat(ay) * 0.01137;
00056 };
00057 iconImage operator=(const iconImage other)
00058 {
00059 iconImage temp;
00060 temp.x = other.x;
00061 temp.y = other.y;
00062 temp.glx = other.glx;
00063 temp.gly = other.gly;
00064 temp.selected = other.selected;
00065 temp.edgeSize = other.edgeSize;
00066 return temp;
00067 };
00068 int x, y;
00069 GLfloat glx, gly;
00070
00071 int selected;
00072 int edgeSize;
00073 };
00074 class Simulation : public QGLWidget
00075 {
00076 public:
00077 Simulation(QWidget * parent = 0, const char *name = 0);
00078 void createIcon(int num);
00079 void currentItem(int item);
00080 float getAngle();
00081 void getCoord(int i, int &x, int &y);
00082
00083 void setCoordByPix(int i, int x, int y);
00084 void setCoordByGL(int i, float glx, float gly);
00085
00086 void getRealPosition(int i, float &rx, float &ry);
00087 void getGLPosition(float rx, float ry, float &gx, float &gy);
00088
00089 inline void reset(){free(iconlist); sizeOfList = 0;};
00090 inline iconImage *getList(){return iconlist;};
00091
00092 float angle;
00093 float scale;
00094 protected:
00095 void initializeGL();
00096 void resizeGL(int w, int h);
00097 void paintGL();
00098
00099 void mousePressEvent(QMouseEvent *event);
00100 void mouseMoveEvent(QMouseEvent *event);
00101
00102 void mouseReleaseEvent(QMouseEvent *event);
00103 private:
00104 void draw();
00105 bool right;
00106 QColor colors[7];
00107 QPoint lastPos;
00108 QPoint dragPos;
00109 int sizeOfList;
00110 int maxX, minX, maxY, minY;
00111 iconImage *iconlist;
00112 };