Exemple #1
0
        public static IWidget LayoutHover(string key, Color color, IWidget content)
        {
            var align = new AlignmentWidget(content)
            {
                VerticalAlignment   = Alignment.Middle,
                HorizontalAlignment = Alignment.Middle,
            };

            var style = new StyleWidget(align)
            {
                Style = new Style()
            };

            var hover = new HoverWidget(key + ".hover", style);

            hover.Decoration = (h, w) =>
            {
                style.Style.Background = h ? Color.Blue : color;
                return(w);
            };

            var box = new PaddingWidget(new Padding(1), hover);

            return(box);
        }
Exemple #2
0
        public override bool OnMouseMove(int x, int y)
        {
            int deltaX = x - MousePosition.X;
            int deltaY = y - MousePosition.Y;

            MousePosition = new Point(x, y);
            MouseMoveEventArgs e = new MouseMoveEventArgs(x, y, deltaX, deltaY);

            if (ActiveWidget != null)
            {
                //TODO, ensure object is still in the graphic tree
                //send move evt even if mouse move outside bounds
                ActiveWidget.onMouseMove(this, e);
                if (!ActiveWidget.IsDragged)                //if active is dragged, process mouse move as it was not visible.
                {
                    return(true);
                }
            }

            if (HoverWidget != null)
            {
                //check topmost graphicobject first
                Widget tmp  = HoverWidget;
                Widget topc = null;
                while (tmp is Widget)
                {
                    topc = tmp;
                    tmp  = tmp.LogicalParent as Widget;
                }
                int idxhw = GraphicTree.IndexOf(topc);
                if (idxhw != 0)
                {
                    int i = 0;
                    while (i < idxhw)
                    {
                        if (GraphicTree [i].localLogicalParentIsNull)
                        {
                            if (GraphicTree [i].MouseIsIn(e.Position))
                            {
                                while (HoverWidget != null)
                                {
                                    HoverWidget.onMouseLeave(HoverWidget, e);
                                    HoverWidget = HoverWidget.LogicalParent as Widget;
                                }

                                GraphicTree [i].checkHoverWidget(e);
                                return(true);
                            }
                        }
                        i++;
                    }
                }

                if (HoverWidget.MouseIsIn(e.Position))
                {
                    if (!(HoverWidget is TemplatedControl))
                    {
                        HoverWidget.checkHoverWidget(e);
                    }
                    return(true);
                }
                else
                {
                    HoverWidget.onMouseLeave(HoverWidget, e);
                    //seek upward from last focused graph obj's
                    while (HoverWidget.LogicalParent as Widget != null)
                    {
                        HoverWidget = HoverWidget.LogicalParent as Widget;
                        if (HoverWidget.MouseIsIn(e.Position))
                        {
                            HoverWidget.checkHoverWidget(e);
                            return(true);
                        }
                        else
                        {
                            HoverWidget.onMouseLeave(HoverWidget, e);
                        }
                    }
                }
            }

            //top level graphic obj's parsing
            lock (GraphicTree) {
                for (int i = 0; i < GraphicTree.Count; i++)
                {
                    Widget g = GraphicTree [i];
                    if (g.MouseIsIn(e.Position))
                    {
                        if (!(HoverWidget is TemplatedControl))
                        {
                            g.checkHoverWidget(e);
                        }
                        if (g is Window)
                        {
                            PutOnTop(g);
                        }
                        return(true);
                    }
                }
            }
            HoverWidget = null;
            return(false);
        }
Exemple #3
0
        public void Update()
        {
            List <InputEventMouse>    mouse_events = Library.Input.GetMouseEvents();
            List <InputEventKeyboard> kb_events    = Library.Input.GetKeyboardEvents();

            #region Mouse Events
            foreach (InputEventMouse e in mouse_events)
            {
                switch (e.EventType)
                {
                case MouseEvent.Move:
                    if (PressedWidget != null)
                    {
                        PressedWidget.MouseMove(e);
                        if (PressedWidget.BlocksInput)
                        {
                            continue;
                        }
                    }
                    if (HoverWidget != null)
                    {
                        HoverWidget.MouseMove(e);
                    }
                    HoverWidget = FindHover();
                    break;

                case MouseEvent.Down:
                    if (HoverWidget != null)
                    {
                        PressedWidget       = HoverWidget;
                        KeyboardFocusWidget = HoverWidget;
                        PressedWidget.MouseDown(e);
                    }
                    break;

                case MouseEvent.Up:
                    if (PressedWidget != null)
                    {
                        PressedWidget.MouseUp(e);
                        PressedWidget = null;
                    }
                    break;

                case MouseEvent.Click:
                    if (HoverWidget != null)
                    {
                        PressedWidget = HoverWidget;
                        PressedWidget.MouseClick(e);
                    }
                    break;

                case MouseEvent.DoubleClick:
                    if (PressedWidget != null)
                    {
                        PressedWidget.MouseClick(e);
                        PressedWidget.MouseDoubleClick(e);
                    }
                    break;

                case MouseEvent.WheelScroll:
                    if (PressedWidget != null)
                    {
                        PressedWidget.MouseWheel(e);
                    }
                    else if (HoverWidget != null)
                    {
                        HoverWidget.MouseWheel(e);
                    }
                    break;
                }
            }
            #endregion

            #region Keyboard Events
            foreach (InputEventKeyboard e in kb_events)
            {
                switch (e.EventType)
                {
                case KeyboardEvent.Press:
                    if (m_KeyboardEvents != null)
                    {
                        m_KeyboardEvents(e);
                    }
                    if (KeyboardFocusWidget != null)
                    {
                        KeyboardFocusWidget.CharEntered(e);
                    }
                    break;

                case KeyboardEvent.Down:
                    if (KeyboardFocusWidget != null)
                    {
                        KeyboardFocusWidget.KeyDown(e);
                    }
                    break;

                case KeyboardEvent.Up:
                    if (KeyboardFocusWidget != null)
                    {
                        KeyboardFocusWidget.KeyUp(e);
                    }
                    break;
                }
            }

            #endregion
        }
Exemple #4
0
        protected override void onDraw(Cairo.Context gr)
        {
            base.onDraw(gr);

            Rectangle cb = new Rectangle(0, 0, designWidth, designHeight);

            gr.Save();

            double z = zoom / 100.0;

            gr.Scale(z, z);

            if (drawGrid)
            {
                double gridLineWidth = 0.2 / z;
                double glhw          = gridLineWidth / 2.0;
                int    nbLines       = cb.Width / gridSpacing;
                double d             = cb.Left + gridSpacing;
                for (int i = 0; i < nbLines; i++)
                {
                    gr.MoveTo(d - glhw, cb.Y);
                    gr.LineTo(d - glhw, cb.Bottom);
                    d += gridSpacing;
                }
                nbLines = cb.Height / gridSpacing;
                d       = cb.Top + gridSpacing;
                for (int i = 0; i < nbLines; i++)
                {
                    gr.MoveTo(cb.X, d - glhw);
                    gr.LineTo(cb.Right, d - glhw);
                    d += gridSpacing;
                }
                gr.LineWidth = gridLineWidth;
                Foreground.SetAsSource(gr, cb);
                gr.Stroke();
            }

            lock (imlVE.RenderMutex) {
                gr.SetSourceSurface(imlVE.surf, cb.Left, cb.Top);
                gr.Paint();
                imlVE.IsDirty = false;
            }

            /*if (Error == null) {
             *      gr.SetSourceColor (Color.Black);
             *      gr.Rectangle (cb, 1.0 / z);
             * } else {
             *      gr.SetSourceColor (Color.LavenderBlush);
             *      gr.Rectangle (cb, 2.0 / z);
             *      string[] lerrs = Error.ToString ().Split ('\n');
             *      Point p = cb.Center;
             *      p.Y -= lerrs.Length * 20;
             *      foreach (string le in lerrs) {
             *              drawCenteredTextLine(gr, p, le);
             *              p.Y += 20;
             *
             *      }
             * }
             * gr.Stroke ();*/

            Rectangle hr;

            if (SelectedItem?.Parent != null)
            {
                gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight);
                gr.SetFontSize(Font.Size);
                gr.FontOptions = Interface.FontRenderingOptions;
                gr.Antialias   = Interface.Antialias;

                Widget g = SelectedItem;
                hr = g.ScreenCoordinates(g.getSlot());

//				Rectangle rIcons = new Rectangle (iconSize);
//				rIcons.Width *= 4;
//				rIcons.Top = hr.Bottom;
//				rIcons.Left = hr.Right - rIcons.Width + iconSize.Width;
                Rectangle rIcoMove = new Rectangle(hr.BottomRight, iconSize);
//				Rectangle rIcoStyle = rIcoMove;
//				rIcoStyle.Left += iconSize.Width + 4;

                using (Surface mask = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) {
                    using (Context ctx = new Context(mask)) {
                        ctx.Save();
                        ctx.SetSourceRGBA(1.0, 1.0, 1.0, 0.4);
                        ctx.Paint();
                        ctx.Rectangle(hr);
                        ctx.Operator = Operator.Clear;
                        ctx.Fill();
                    }

                    gr.SetSourceSurface(mask, 0, 0);
                    gr.Paint();

                    using (Surface ol = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) {
                        using (Context ctx = new Context(ol)) {
                            ctx.SetSourceColor(Colors.Black);
                            drawDesignOverlay(ctx, g, cb, hr, 0.4 / z, 6.5);
                        }

                        gr.SetSourceSurface(ol, 0, 0);
                        gr.Paint();
                    }

                    drawIcon(gr, icoMove, rIcoMove);
                    //drawIcon (gr, icoStyle, rIcoStyle);
                }
            }
            if (HoverWidget != null)
            {
                hr = HoverWidget.ScreenCoordinates(HoverWidget.getSlot());
                gr.SetSourceColor(Colors.SkyBlue);
                //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0);
                gr.Rectangle(hr, 0.4 / z);
            }
            gr.Restore();
        }