Ejemplo n.º 1
0
        /**
         * kutsutaan jos hiiren nappia painetaan
         */
        private void mouseButton(int button, int state, int x, int y)
        {
            if (mode == 0)
            {
                return;
            }
            if (selectedObj != -1)
            {
                selectedObj = -1;
                updateAll();
            }

            if (mode != 4)
            {
                Gl.glTranslatef(((Layer)layers[selectedLayer]).sx, ((Layer)layers[selectedLayer]).sy, 0);
                x -= (int)((Layer)layers[selectedLayer]).sx;
                y -= (int)((Layer)layers[selectedLayer]).sy;
            }

            switch (button)
            {
            // jos painetaan hiiren vasenta nappia
            case Glut.GLUT_LEFT_BUTTON:

                // kun painetaan pohjaan
                if (state == Glut.GLUT_DOWN)
                {
                    if (mode != 4)
                    {
                        invert = false;
                        Gl.glEnable(Gl.GL_COLOR_LOGIC_OP);
                        Gl.glLogicOp(Gl.GL_INVERT);
                    }

                    switch (mode)
                    {
                    case 1:
                        tmpObj = new Line();
                        break;

                    case 2:
                        tmpObj = new Rect();
                        break;

                    case 3:
                        tmpObj = new Circle();
                        break;

                    case 4:
                        mx = x; my = y;             // layerin liikutus
                        return;
                    }
                    tmpObj.setColor(color, fillColor, true);
                    tmpObj.add((float)x, (float)y);
                }
                else     // irrotetaan napista
                {
                    if (tmpObj == null)
                    {
                        return;
                    }
                    tmpObj.add((float)x, (float)y);

                    if (mode == 1)                          // jos kynä
                    {
                        if (fill || closed)                 // jos täyttö tai suljettu
                        {
                            // vika vertex ekaks vertexiks, sulkee polyn
                            ((Line)tmpObj).close();
                        }

                        if (fill)                                // alue pitää täyttää
                        {
                            ((Line)tmpObj).tesselate(closed);
                        }
                    }
                    if (layers.Count == 0)
                    {
                        selectedLayer = -1;
                        newLayer();
                    }

                    Gl.glDisable(Gl.GL_COLOR_LOGIC_OP);
                    tmpObj.render(true);
                    ((Layer)layers[selectedLayer]).objs.Add(tmpObj);
                    tmpObj = null;

                    Tools.updateList();
                }
                break;

            case Glut.GLUT_MIDDLE_BUTTON:
            case Glut.GLUT_RIGHT_BUTTON:
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        /**
         * kutsutaan jos hiiren nappi pohjassa liikutetaan hiirtä
         */
        private void mouseMotion(int x, int y)
        {
            if (mode == 0)
            {
                return;
            }
            if (mode != 4 && tmpObj == null)
            {
                return;
            }

            if (mode != 4)
            {
                Gl.glTranslatef(((Layer)layers[selectedLayer]).sx, ((Layer)layers[selectedLayer]).sy, 0);
                x -= (int)((Layer)layers[selectedLayer]).sx;
                y -= (int)((Layer)layers[selectedLayer]).sy;
            }

            if (tmpObj != null)
            {
                tmpObj.render(true);
            }

            int mod = Glut.glutGetModifiers();

            if (mod == Glut.GLUT_ACTIVE_CTRL)
            {
                ctrl = true;
            }
            else
            {
                ctrl = false;
            }


            switch (mode)
            {
            case 1:                             //drawLine:
                if (ctrl)                       // jos ctrl pohjassa, piirrä suora viiva, muuten lisää piste
                {
                    ((Line)tmpObj).setXY(x, y); // viivan loppukoordinaatit on hiiren koordinaatit
                }
                else
                {
                    tmpObj.add(x, y);
                    ((Line)tmpObj).setXY(-1, -1);
                }
                break;

            // x1y1 -> x2y2
            case 2:                     //drawRect:
                ((Rect)tmpObj).calcWH(x, y);

                break;

            // keskipiste ja säde
            case 3:                     //drawCircle:
                if (ctrl)               // jos ctrl pohjassa, piirrä ellipsi, muuten ympyrä
                {
                    ((Circle)tmpObj).calcXY(x, y);
                }
                else
                {
                    ((Circle)tmpObj).calcR(x, y);                     // laske säde
                }
                break;

            case 4:                     // layerin liikutus
                int xx = mx - x;
                int yy = my - y;
                ((Layer)layers[selectedLayer]).setXY(-xx, -yy);
                updateAll();
                break;
            }

            invert = !invert;
        }