Esempio n. 1
0
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            //System.Console.WriteLine("pictureBox1_MouseDown");
            if (e.Button == MouseButtons.Left)
            {
                _StartX = (int)(((MouseEventArgs)e).X / pDesigner.zoomLevel());
                _StartY = (int)(((MouseEventArgs)e).Y / pDesigner.zoomLevel());

                sGraphicElement elem = pDesigner.getElement((uint)_StartX, (uint)_StartY);
                if (elem != null)
                {
                    sAttribute _Attr = elem.pAttr;
                    if (_Attr != null)
                    {
                        /*if (isResize)
                        {
                            mouseDown = true;
                        }
                        else*/
                        if (inBounds(new PointF(_StartX, _StartY), _Attr.Rectangle, -2 / pDesigner.zoomLevel()))
                        {
                            treeView1.SelectedNode = pXmlHandler.getTreeNode(_Attr.myNode);

                            mouseDown = true;
                            this.Cursor = Cursors.SizeAll;
                        }
                        else if (inBounds(new PointF(_StartX, _StartY), _Attr.Rectangle, +2 / pDesigner.zoomLevel()))
                        {
                            treeView1.SelectedNode = pXmlHandler.getTreeNode(_Attr.myNode); // CHECK: Hopefully this fixes the bug in designer were an command ist set without any change.

                            mouseDown = true;
                            //this.Cursor = Cursors.SizeAll;
                        }

                        if (mouseDown)
                        {
                            remeberAttrSizeForUndo = _Attr.Size;
                            remeberAttrPositionForUndo = _Attr.Relativ;
                            Console.Out.WriteLine("Size {0}", remeberAttrSizeForUndo);
                        }
                    }
                }

                tabControl1.Focus();
            }
            else if (e.Button == MouseButtons.Right)
            {
                if(propertyGrid1.SelectedObject.GetType() != typeof(sAttributeScreen))
                    if ((propertyGrid1.SelectedObject as sAttribute).Parent != null)
                    {
                        //propertyGrid1.SelectedObject = (propertyGrid1.SelectedObject as sAttribute).Parent;
                        treeView1.SelectedNode = pXmlHandler.getTreeNode((propertyGrid1.SelectedObject as sAttribute).Parent.myNode);
                        //refresh();
                        //pDesigner.sort();
                        //refreshEditor();
                        //propertyGrid1.Refresh();
                        //pictureBox1.Invalidate();
                    }
            }
        }
Esempio n. 2
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            //System.Console.WriteLine("pictureBox1_MouseMove {0} {1}", ((MouseEventArgs)e).X, ((MouseEventArgs)e).Y);
            Int32 curX = (int)(((MouseEventArgs)e).X / pDesigner.zoomLevel());
            Int32 curY = (int)(((MouseEventArgs)e).Y / pDesigner.zoomLevel());
            //System.Console.WriteLine("{0} {1}", curX, curY);
            if (mouseDown)
            {
                if (propertyGrid1.SelectedObject != null)
                {
                    //Console.WriteLine(_Attr.pRelativX + "+(" + curX + "-" + _StartX + ")");
                    if (curX != _StartX || curY != _StartY)
                    {
                        if (isResize)
                        {
                            sAttribute _Attr = (sAttribute)propertyGrid1.SelectedObject;
                            Size size = new Size();
                            size.Width = _Attr.pWidth;
                            size.Height = _Attr.pHeight;

                            if (isResizeW || isResizeE)
                            {
                                Int32 sizeX = (Int32)(_Attr.pWidth + (curX - _StartX));
                                if (isResizeE)
                                    size.Width = (Int32)sizeX;
                                else
                                {
                                    Int32 posX = (Int32)(_Attr.pRelativX + (curX - _StartX));
                                    Int32 posY = (Int32)_Attr.pRelativY;
                                    sAttribute.Position pos = new sAttribute.Position();
                                    pos.X = ((Int32)posX).ToString();
                                    pos.Y = ((Int32)posY).ToString();
                                    _Attr.Relativ = pos;

                                    sizeX = (Int32)(_Attr.pWidth + (_StartX - curX));
                                    size.Width = (Int32)sizeX;
                                }
                            }
                            if (isResizeN || isResizeS)
                            {
                                Int32 sizeY = (Int32)(_Attr.pHeight + (curY - _StartY));
                                if (isResizeS)
                                    size.Height = (Int32)sizeY;
                                else
                                {
                                    Int32 posX = (Int32)_Attr.pRelativX;
                                    Int32 posY = (Int32)(_Attr.pRelativY + (curY - _StartY));
                                    sAttribute.Position pos = new sAttribute.Position();
                                    pos.X = ((Int32)posX).ToString();
                                    pos.Y = ((Int32)posY).ToString();
                                    _Attr.Relativ = pos;

                                    sizeY = (Int32)(_Attr.pHeight + (_StartY - curY));
                                    size.Height = (Int32)sizeY;
                                }
                                
                            }


                            /* TODO: If we would not set it here directly to Relative but to X and Y the value would only be
                             * temprarly saved, and so we could set it finaly in mouse up, this has an advantage cause we 
                             * could easier implement a UNDO functionality.
                             */
                            _Attr.Size = size;
                        }
                        else
                        {
                            sAttribute _Attr = (sAttribute)propertyGrid1.SelectedObject;
                            Int32 posX = (Int32)(_Attr.pRelativX + (curX - _StartX));
                            Int32 posY = (Int32)(_Attr.pRelativY + (curY - _StartY));
                            sAttribute.Position pos = new sAttribute.Position();

                            pos.X = ((Int32)posX).ToString();
                            pos.Y = ((Int32)posY).ToString();


                            /* TODO: If we would not set it here directly to Relative but to X and Y the value would only be
                             * temprarly saved, and so we could set it finaly in mouse up, this has an advantage cause we 
                             * could easier implement a UNDO functionality.
                             */
                            _Attr.Relativ = pos;
                        }

                        propertyGrid1.Refresh();
                        sAttribute subattr = (sAttribute)propertyGrid1.SelectedObject;
                        pDesigner.redrawFog((int)subattr.pAbsolutX, (int)subattr.pAbsolutY, (int)subattr.pWidth, (int)subattr.pHeight);
                        pictureBox1.Invalidate();
                    }
                }
            }
            else
            {
                sAttribute _Attr = (sAttribute)propertyGrid1.SelectedObject;
                if (_Attr != null)
                {
                    if (inBounds(new PointF(curX, curY), _Attr.Rectangle, 2 / pDesigner.zoomLevel()))
                    {
                        isResize = true;
                        if (inRange(curX, _Attr.Absolut.X, 2))
                        {
                            this.Cursor = Cursors.SizeWE;
                            isResizeW = true;
                        }
                        else if (inRange(curX, _Attr.Absolut.X + _Attr.Size.Width, 2 / pDesigner.zoomLevel()))
                        {
                            this.Cursor = Cursors.SizeWE;
                            isResizeE = true;
                        }
                        else if (inRange(curY, _Attr.Absolut.Y, 2 / pDesigner.zoomLevel()))
                        {
                            this.Cursor = Cursors.SizeNS;
                            isResizeN = true;
                        }
                        else if (inRange(curY, _Attr.Absolut.Y + _Attr.Size.Height, 2 / pDesigner.zoomLevel()))
                        {
                            this.Cursor = Cursors.SizeNS;
                            isResizeS = true;
                        }
                        else
                        {
                            this.Cursor = Cursors.Help;
                            isResize = false;
                            isResizeW = false;
                            isResizeE = false;
                            isResizeN = false;
                            isResizeS = false;
                        }
                    }
                    else
                    {
                        this.Cursor = Cursors.Default;
                        isResize = false;
                    }
                }
                else
                {
                    this.Cursor = Cursors.Default;
                    isResize = false;
                }
                    
            }
            _StartX = curX;
            _StartY = curY;
        }
Esempio n. 3
0
        private void tabControl1_KeyDown(object sender, KeyEventArgs e)
        {
            if (!this.keyCapture)
                return;

            // If CTRL pressed, use margin 1, else margin 5
            //Console.WriteLine(e.Control.ToString());
            if (isCURSOR(e))
            {
                int marging = 5;

                if (isCTRL(e))
                    marging = 1;

                if (propertyGrid1.SelectedObject != null)
                {
                    int x = isLEFT(e) ? -marging : (isRIGHT(e) ? +marging : 0);
                    int y = isUP(e)   ? -marging : (isDOWN(e)  ? +marging : 0);

                    sAttribute _Attr = (sAttribute)propertyGrid1.SelectedObject;
                    Int32 posX = (Int32)(_Attr.pRelativX + x);
                    Int32 posY = (Int32)(_Attr.pRelativY + y);
                    if (posX < 0) posX = 0;
                    if (posY < 0) posY = 0;

                    sAttribute.Position pos = new sAttribute.Position();

                    pos.X = ((UInt32)posX).ToString();
                    pos.Y = ((UInt32)posY).ToString();

                    cCommandQueue.cCommand cmd = new cCommandQueue.cCommand("KeyboardChange");

                    cmd.Helper = propertyGrid1.SelectedObject;

                    cmd.DoEvent += new cCommandQueue.EventHandler(eventDoPropertyGrid);
                    cmd.UndoEvent += new cCommandQueue.EventHandler(eventUndoPropertyGrid);

                    cmd.From = new Object[] { "Relativ", _Attr.Relativ };
                    cmd.To = new Object[] { "Relativ", pos };
                    pQueue.addCmd(cmd);

                    _Attr.Relativ = pos;

                    propertyGrid1.Refresh();
                    sAttribute subattr = (sAttribute)propertyGrid1.SelectedObject;
                    pDesigner.redrawFog((int)subattr.pAbsolutX, (int)subattr.pAbsolutY, (int)subattr.pWidth, (int)subattr.pHeight);
                    pictureBox1.Invalidate();
                }


                e.Handled = true;
            }
            else if (isPLUS(e))
            {
                pDesigner.zoomIn();
                //pictureBox1.Scale(new SizeF((float)0.5, (float)0.5));
                //
                //pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
                panelDesignerInner.AutoScrollMinSize = new Size((int)(cDataBase.pResolution.getResolution().Xres * pDesigner.zoomLevel()) + 100, (int)(cDataBase.pResolution.getResolution().Yres * pDesigner.zoomLevel()) + 100);
                trackBarZoom.Value = (int)((pDesigner.zoomLevel() - 1.0f)*100.0f);
                numericUpDownZoom.Value = (int)((pDesigner.zoomLevel() - 1.0f) * 100.0f);
                pictureBox1.Invalidate();
            }
            else if (isMINUS(e))
            {
                pDesigner.zoomOut();
                panelDesignerInner.AutoScrollMinSize = new Size((int)(cDataBase.pResolution.getResolution().Xres * pDesigner.zoomLevel()) + 100, (int)(cDataBase.pResolution.getResolution().Yres * pDesigner.zoomLevel()) + 100);
                trackBarZoom.Value = (int)((pDesigner.zoomLevel() - 1.0f) * 100.0f);
                numericUpDownZoom.Value = (int)((pDesigner.zoomLevel() - 1.0f) * 100.0f);
                pictureBox1.Invalidate();
            }
            /*else if (e.KeyCode == Keys.Z) //UNDO
            {
                pQueue.undoCmd();
            }
            else if (e.KeyCode == Keys.Y) //REDO
            {
                pQueue.redoCmd();
            }*/
        }