Ejemplo n.º 1
0
 void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.Box box)
 {
     //1. mouse down
     box.MouseDown += (s, e) =>
     {
         box.BackColor      = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
         e.MouseCursorStyle = MouseCursorStyle.Pointer;
         //--------------------------------------------
         //move controller here
         _controllerBox1.TargetBox = box;
         _controllerBox1.SetLocation(box.Left - 5, box.Top - 5);
         _controllerBox1.SetSize(box.Width + 10, box.Height + 10);
         _controllerBox1.Visible = true;
         //--------------------------------------------
         e.CancelBubbling = true;
         //change mouse capture to another control
         e.SetMouseCapturedElement(_controllerBox1);
     };
     //2. mouse up
     box.MouseUp += (s, e) =>
     {
         e.MouseCursorStyle = MouseCursorStyle.Default;
         box.BackColor      = KnownColors.LightGray;
         //hide controller
         _controllerBox1.Visible   = false;
         _controllerBox1.TargetBox = null;
         e.CancelBubbling          = true;
     };
 }
Ejemplo n.º 2
0
        protected override void OnStart(AppHost host)
        {
            var box1 = new LayoutFarm.CustomWidgets.Box(50, 50);

            box1.BackColor = Color.Red;
            box1.SetLocation(10, 10);
            //box1.dbugTag = 1;
            SetupActiveBoxProperties(box1);
            host.AddChild(box1);
            var box2 = new LayoutFarm.CustomWidgets.Box(30, 30);

            box2.SetLocation(50, 50);
            //box2.dbugTag = 2;
            SetupActiveBoxProperties(box2);
            host.AddChild(box2);
            _rectBoxController.Init();
            //------------

            host.AddChild(_rectBoxController);

            //foreach (var ui in rectBoxController.GetControllerIter())
            //{
            //    viewport.AddContent(ui);
            //}
        }
        protected override void OnStart(AppHost host)
        {
            var box1 = new LayoutFarm.CustomWidgets.Box(50, 50);

            box1.BackColor = Color.Red;
            box1.SetLocation(10, 10);
            //box1.dbugTag = 1;
            SetupActiveBoxProperties(box1);
            host.AddChild(box1);
            var box2 = new LayoutFarm.CustomWidgets.Box(30, 30);

            box2.SetLocation(50, 50);
            //box2.dbugTag = 2;
            SetupActiveBoxProperties(box2);
            host.AddChild(box2);
            _controllerBox1 = new UIControllerBox(40, 40);
            Color c = KnownColors.FromKnownColor(KnownColor.Yellow);

            _controllerBox1.BackColor = new Color(100, c.R, c.G, c.B);
            _controllerBox1.SetLocation(200, 200);
            //controllerBox1.dbugTag = 3;
            _controllerBox1.Visible = false;
            SetupControllerBoxProperties(_controllerBox1);
            host.AddChild(_controllerBox1);
        }
Ejemplo n.º 4
0
 void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.Box box)
 {
     //1. mouse down
     box.MouseDown += (s, e) =>
     {
         box.BackColor      = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
         e.MouseCursorStyle = MouseCursorStyle.Pointer;
         //--------------------------------------------
         //move controller here
         _controllerBox1.SetLocationAndSize(
             box.Left - 5, box.Top - 5,
             box.Width + 10, box.Height + 10);
         _controllerBox1.Visible   = true;
         _controllerBox1.TargetBox = box;
         e.SetMouseCapture(_controllerBox1);
     };
     //2. mouse up
     box.MouseUp += (s, e) =>
     {
         e.MouseCursorStyle        = MouseCursorStyle.Default;
         box.BackColor             = Color.LightGray;
         _controllerBox1.Visible   = false;
         _controllerBox1.TargetBox = null;
     };
 }
Ejemplo n.º 5
0
        LayoutFarm.CustomWidgets.MenuItem CreateMenuItem(int x, int y)
        {
            var mnuItem = new CustomWidgets.MenuItem(150, 20);

            mnuItem.SetLocation(x, y);
            //--------------------
            //1. create landing part
            var landPart = new LayoutFarm.CustomWidgets.Box(150, 20);

            landPart.BackColor = Color.OrangeRed;
            mnuItem.LandPart   = landPart;
            //--------------------------------------
            //add small px to land part
            //image
            //load bitmap with gdi+

            if (_arrowBmp == null)
            {
                _arrowBmp = _appHost.LoadImageAndBind("../Data/imgs/arrow_open.png");
            }
            LayoutFarm.CustomWidgets.ImageBox imgBox = new CustomWidgets.ImageBox(_arrowBmp.Width, _arrowBmp.Height);
            imgBox.ImageBinder = _arrowBmp;
            landPart.AddChild(imgBox);
            //--------------------------------------
            //if click on this image then
            imgBox.MouseDown += (s, e) =>
            {
                e.CancelBubbling = true;
                //1. maintenace parent menu***
                mnuItem.MaintenanceParentOpenState();
                //-----------------------------------------------
                if (mnuItem.IsOpened)
                {
                    mnuItem.Close();
                }
                else
                {
                    mnuItem.Open();
                }
            };
            imgBox.MouseUp += (s, e) =>
            {
                mnuItem.UnmaintenanceParentOpenState();
            };
            imgBox.LostMouseFocus += (s, e) =>
            {
                if (!mnuItem.MaintenceOpenState)
                {
                    mnuItem.CloseRecursiveUp();
                }
            };
            //--------------------------------------
            //2. float part
            var floatPart = new LayoutFarm.CustomWidgets.MenuBox(400, 100);

            floatPart.BackColor = Color.Gray;
            mnuItem.FloatPart   = floatPart;
            return(mnuItem);
        }
Ejemplo n.º 6
0
 void SetupBackgroundProperties(LayoutFarm.CustomWidgets.Box backgroundBox)
 {
     //if click on background
     backgroundBox.MouseDown += (s, e) =>
     {
         _controllerBox1.TargetBox = null;//release target box
         _controllerBox1.Visible   = false;
     };
 }
Ejemplo n.º 7
0
        public override CssBox CreateCssBox(
            DomElement domE,
            CssBox parentBox,
            BoxSpec spec,
            HtmlHost host)
        {
            switch (domE.Name)
            {
            case "select":
            {
                CssBox selectedBox = CreateSelectBox(domE, parentBox, spec, myHost.RootGfx, host);
                if (selectedBox != null)
                {
                    return(selectedBox);
                }
            }
            break;

            case "input":
            {
                CssBox inputBox = CreateInputBox(domE, parentBox, spec, myHost.RootGfx, host);
                if (inputBox != null)
                {
                    return(inputBox);
                }
            }
            break;

            case "canvas":
            {
                //test only
                //TODO: review here
                var canvas     = new LayoutFarm.CustomWidgets.MiniAggCanvasBox(400, 400);
                var wrapperBox = CreateWrapper(
                    host,
                    canvas,
                    canvas.GetPrimaryRenderElement(myHost.RootGfx),
                    spec, true);
                parentBox.AppendChild(wrapperBox);
                return(wrapperBox);
            }
            }

            //default unknown
            var simpleBox = new LayoutFarm.CustomWidgets.Box(100, 20);

            simpleBox.BackColor = PixelFarm.Drawing.Color.LightGray;
            var wrapperBox2 = CreateWrapper(
                host,
                simpleBox,
                simpleBox.GetPrimaryRenderElement(myHost.RootGfx),
                spec, false);

            parentBox.AppendChild(wrapperBox2);
            return(wrapperBox2);
        }
Ejemplo n.º 8
0
 //-----
 void SetupDockSpaces()
 {
     //1. controller
     this.dockspaceController = new DockSpacesController(this, SpaceConcept.NineSpace);
     //2.
     this.dockspaceController.LeftTopSpace.Content     = boxLeftTop = CreateTinyControlBox(SpaceName.LeftTop);
     this.dockspaceController.RightTopSpace.Content    = boxRightTop = CreateTinyControlBox(SpaceName.RightTop);
     this.dockspaceController.LeftBottomSpace.Content  = boxLeftBottom = CreateTinyControlBox(SpaceName.LeftBottom);
     this.dockspaceController.RightBottomSpace.Content = boxRightBottom = CreateTinyControlBox(SpaceName.RightBottom);
 }
Ejemplo n.º 9
0
        protected override void OnStart(AppHost host)
        {
            int x_pos = 0;

            //create behaviour for specific host, => LayoutFarm.CustomWidgets.Box
            var beh = new UIMouseBehaviour <LayoutFarm.CustomWidgets.Box, object>();

            beh.MouseEnter += (s, e) =>
            {
                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _mouseEnterState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_enter:" + box.dbugId);
#endif
            };
            beh.MouseLeave += (s, e) =>
            {
                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _normalState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_leave:" + box.dbugId);
#endif
            };
            beh.MouseHover += (s, e) =>
            {
                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _hoverState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_hover:" + box.dbugId);
#endif
            };

            beh.MousePress += (s, e) =>
            {
                LayoutFarm.CustomWidgets.Box box = s.Source;
                Color back_color = box.BackColor;
                box.BackColor = new Color((byte)System.Math.Min(back_color.A + 10, 255), back_color.R, back_color.G, back_color.B);
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_press:" + box.dbugId);
#endif
            };

            for (int i = 0; i < 10; ++i)
            {
                var sampleButton = new LayoutFarm.CustomWidgets.Box(30, 30);
                sampleButton.BackColor = _normalState;
                sampleButton.SetLocation(x_pos, 10);

                beh.AttachSharedBehaviorTo(sampleButton);

                host.AddChild(sampleButton);
                x_pos += 30 + 5;
            }
        }
Ejemplo n.º 10
0
        protected override void OnStart(AppHost host)
        {
            var sampleButton = new LayoutFarm.CustomWidgets.Box(30, 30);

            host.AddChild(sampleButton);
            int count = 0;

            sampleButton.MouseDown += new EventHandler <UIMouseEventArgs>((s, e2) =>
            {
                Console.WriteLine("click :" + (count++));
            });
        }
Ejemplo n.º 11
0
        protected override void OnStart(AppHost host)
        {
            var sampleButton = new LayoutFarm.CustomWidgets.Box(30, 30);

            host.AddChild(sampleButton);

            sampleButton.MouseDown += ((s, e2) =>
            {
                //click to create custom cursor
                if (!_showCustomCursor)
                {
                    if (_myCursor == null)
                    {
                        using (MemBitmap temp = new MemBitmap(16, 16))
                            using (Tools.BorrowAggPainter(temp, out AggPainter p))
                            {
                                //1. create a simple bitmap for our cursor
                                p.Clear(Color.FromArgb(0, Color.White));
                                p.FillRect(1, 1, 10, 10, Color.FromArgb(150, Color.Green));
                                p.FillRect(3, 3, 4, 4, Color.Yellow);
                                //-------
                                //create cursor file

                                CursorFile curFile = new CursorFile();

                                var iconBmp = new WindowBitmap(temp.Width, temp.Height);
                                iconBmp.RawBitmapData = MemBitmap.CopyImgBuffer(temp);

                                curFile.AddBitmap(iconBmp, 1, 1); //add bitmap with hotspot
                                curFile.Save("myicon.cur");       //save to temp file
                                _myCursor = UIPlatform.CreateCursor(new CursorRequest("myicon.cur", 16));
                            }
                    }
                    e2.CustomMouseCursor = _myCursor;
                    _showCustomCursor = true;
                }
                else
                {
                    _showCustomCursor = false;
                    e2.MouseCursorStyle = MouseCursorStyle.Default;
                }
            });

            sampleButton.MouseMove += ((s, e2) =>
            {
                if (_showCustomCursor && _myCursor != null)
                {
                    e2.CustomMouseCursor = _myCursor;
                }
            });
        }
Ejemplo n.º 12
0
        LayoutFarm.CustomWidgets.ComboBox CreateComboBox(int x, int y)
        {
            var comboBox = new CustomWidgets.ComboBox(400, 20);

            comboBox.SetLocation(x, y);
            //--------------------
            //1. create landing part
            var landPart = new LayoutFarm.CustomWidgets.Box(400, 20);

            landPart.BackColor = Color.Green;
            comboBox.LandPart  = landPart;
            //--------------------------------------
            //add small px to land part
            //image
            //load bitmap with gdi+
            if (_arrowBmp == null)
            {
                _arrowBmp = _appHost.LoadImageAndBind("../Data/imgs/arrow_open.png");
            }
            LayoutFarm.CustomWidgets.ImageBox imgBox = new CustomWidgets.ImageBox(_arrowBmp.Width, _arrowBmp.Height);
            imgBox.ImageBinder = _arrowBmp;
            //--------------------------------------
            //2. float part
            var floatPart = new LayoutFarm.CustomWidgets.Box(400, 100);

            floatPart.BackColor = Color.Blue;
            comboBox.FloatPart  = floatPart;
            //--------------------------------------
            //if click on this image then
            imgBox.MouseDown += (s, e) =>
            {
                e.CancelBubbling = true;
                if (comboBox.IsOpen)
                {
                    comboBox.CloseHinge();
                }
                else
                {
                    comboBox.OpenHinge();
                }
            };
            imgBox.LostMouseFocus += (s, e) =>
            {
                if (comboBox.IsOpen)
                {
                    comboBox.CloseHinge();
                }
            };
            landPart.AddChild(imgBox);
            return(comboBox);
        }
Ejemplo n.º 13
0
        protected override void OnStart(AppHost host)
        {
            var sampleButton = new LayoutFarm.CustomWidgets.Box(100, _chartHeight);

            host.AddChild(sampleButton);
            int count = 0;

            sampleButton.MouseDown += (s, e2) =>
            {
                Console.WriteLine("click :" + (count++));
            };

            TestSimplePlot1(host);
        }
Ejemplo n.º 14
0
        void AddScrollView1(AppHost host, int x, int y)
        {
            var panel = new LayoutFarm.CustomWidgets.Box(200, 175);

            panel.NeedClipArea = true;
            panel.SetLocation(x + 30, y + 30);
            panel.BackColor = Color.LightGray;
            host.AddChild(panel);
            //-------------------------
            {
                //vertical scrollbar
                var vscbar = new LayoutFarm.CustomWidgets.ScrollBar(15, 200);
                vscbar.SetLocation(x + 10, y + 10);
                vscbar.MinValue    = 0;
                vscbar.MaxValue    = 170; //just init
                vscbar.SmallChange = 20;
                host.AddChild(vscbar);
                //add relation between viewpanel and scroll bar
                var scRelation = new LayoutFarm.CustomWidgets.ScrollingRelation(vscbar.SliderBox, panel);
            }
            //-------------------------
            {
                //horizontal scrollbar
                var hscbar = new LayoutFarm.CustomWidgets.ScrollBar(200, 15);
                hscbar.ScrollBarType = CustomWidgets.ScrollBarType.Horizontal;
                hscbar.SetLocation(x + 30, y + 10);
                hscbar.MinValue    = 0;
                hscbar.MaxValue    = 170;//just init
                hscbar.SmallChange = 20;
                host.AddChild(hscbar);
                //add relation between viewpanel and scroll bar
                var scRelation = new LayoutFarm.CustomWidgets.ScrollingRelation(hscbar.SliderBox, panel);
            }

            //add content to panel
            for (int i = 0; i < 10; ++i)
            {
                var box1 = new LayoutFarm.CustomWidgets.Box(400, 30);
                box1.HasSpecificWidth  = true;
                box1.HasSpecificHeight = true;
                box1.BackColor         = Color.OrangeRed;
                box1.SetLocation(i * 20, i * 40);
                panel.AddChild(box1);
            }
            //--------------------------
            //panel.PerformContentLayout();
        }
Ejemplo n.º 15
0
 protected override void OnStart(AppHost host)
 {
     {
         var box1 = new LayoutFarm.CustomWidgets.Box(50, 50);
         box1.BackColor = Color.Red;
         box1.SetLocation(10, 10);
         //box1.dbugTag = 1;
         SetupActiveBoxProperties(box1);
         host.AddChild(box1);
     }
     //--------------------------------
     {
         var box2 = new LayoutFarm.CustomWidgets.Box(30, 30);
         box2.SetLocation(50, 50);
         //box2.dbugTag = 2;
         SetupActiveBoxProperties(box2);
         host.AddChild(box2);
     }
 }
Ejemplo n.º 16
0
 void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.Box box)
 {
     //1. mouse down
     box.MouseDown += (s, e) =>
     {
         box.BackColor      = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
         e.MouseCursorStyle = MouseCursorStyle.Pointer;
         //--------------------------------------------
         e.SetMouseCapture(_rectBoxController.ControllerBoxMain);
         _rectBoxController.UpdateControllerBoxes(box);
     };
     //2. mouse up
     box.MouseUp += (s, e) =>
     {
         e.MouseCursorStyle = MouseCursorStyle.Default;
         box.BackColor      = Color.LightGray;
         //controllerBox1.Visible = false;
         //controllerBox1.TargetBox = null;
     };
 }
Ejemplo n.º 17
0
 static void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.Box box)
 {
     //1. mouse down
     box.MouseDown += (s, e) =>
     {
         box.BackColor      = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
         e.MouseCursorStyle = MouseCursorStyle.Pointer;
     };
     //2. mouse up
     box.MouseUp += (s, e) =>
     {
         e.MouseCursorStyle = MouseCursorStyle.Default;
         box.BackColor      = Color.LightGray;
     };
     box.MouseDrag += (s, e) =>
     {
         box.BackColor = KnownColors.FromKnownColor(KnownColor.GreenYellow);
         Point pos = box.Position;
         box.SetLocation(pos.X + e.XDiff, pos.Y + e.YDiff);
         e.MouseCursorStyle = MouseCursorStyle.Pointer;
         e.CancelBubbling   = true;
     };
 }
Ejemplo n.º 18
0
        protected override void OnStart(AppHost host)
        {
            int x_pos = 0;

            GeneralEventListener evListener = new GeneralEventListener();

            evListener.MouseEnter += (s, e) =>
            {
                IUIEventListener             ctx = e.CurrentContextElement;
                LayoutFarm.CustomWidgets.Box box = (LayoutFarm.CustomWidgets.Box)ctx;
                box.BackColor = Color.Red;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_enter:" + box.dbugId);
#endif
            };
            evListener.MouseLeave += (s, e) =>
            {
                IUIEventListener             ctx = e.CurrentContextElement;
                LayoutFarm.CustomWidgets.Box box = (LayoutFarm.CustomWidgets.Box)ctx;
                box.BackColor = Color.Blue;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_leave:" + box.dbugId);
#endif
            };

            for (int i = 0; i < 10; ++i)
            {
                var sampleButton = new LayoutFarm.CustomWidgets.Box(30, 30);
                sampleButton.BackColor = Color.Blue;
                sampleButton.SetLocation(x_pos, 10);
                sampleButton.AttachExternalEventListener(evListener);

                host.AddChild(sampleButton);

                x_pos += 30 + 5;
            }
        }
Ejemplo n.º 19
0
        protected override void OnStart(AppHost host)
        {
            var box1 = new LayoutFarm.CustomWidgets.Box(50, 50);

            box1.BackColor = Color.Red;
            box1.SetLocation(10, 10);
            host.AddChild(box1);
            //--------------------------------
            var box2 = new LayoutFarm.CustomWidgets.Box(30, 30);

            box2.SetLocation(50, 50);
            host.AddChild(box2);
            //1. mouse down
            box1.MouseDown += (s, e) =>
            {
                box1.BackColor = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
                box2.Visible   = false;
            };
            box1.MouseUp += (s, e) =>
            {
                box1.BackColor = Color.Red;
                box2.Visible   = true;
            };
        }
Ejemplo n.º 20
0
        protected override void OnStart(AppHost host)
        {
            int x_pos = 0;


            //mouse behavior for LayoutFarm.CustomWidgets.Box,
            //with special attachment state => MyButtonState


            var mouseBeh = new UIMouseBehaviour <LayoutFarm.CustomWidgets.Box, MyButtonState>();

            mouseBeh.MouseEnter += (s, e) =>
            {
                //s is a behaviour object that raise the event
                //not the the current context element
                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _mouseEnterState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_enter:" + box.dbugId);
#endif
            };
            mouseBeh.MouseLeave += (s, e) =>
            {
                //s is a behaviour object that raise the event
                //not the the current context element

                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _normalState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_leave:" + box.dbugId);
#endif
            };
            mouseBeh.MouseHover += (s, e) =>
            {
                //b is a behaviour object that raise the event
                //not the the current context element

                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _hoverState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_hover:" + box.dbugId);
#endif
            };
            mouseBeh.MousePress += (s, e) =>
            {
                //s is a behaviour object that raise the event
                //not the the current context element
                LayoutFarm.CustomWidgets.Box box = s.Source;
                Color back_color = box.BackColor;
                box.BackColor = new Color((byte)System.Math.Min(back_color.A + 10, 255), back_color.R, back_color.G, back_color.B);
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_press:" + box.dbugId);
#endif
            };
            mouseBeh.MouseDown += (s, e) =>
            {
                MyButtonState buttonState = s.State;
                if (buttonState != null)
                {
                    if (buttonState.ClickCount > 3)
                    {
                        s.Source.BackColor = Color.Magenta;
                    }
                    buttonState.ClickCount++;
                }
            };


            for (int i = 0; i < 10; ++i)
            {
                var sampleButton = new LayoutFarm.CustomWidgets.Box(30, 30);
                sampleButton.BackColor = _normalState;
                sampleButton.SetLocation(x_pos, 10);

                MyButtonState state = new MyButtonState();
                mouseBeh.AttachUniqueBehaviorTo(sampleButton, state);

                host.AddChild(sampleButton);

                x_pos += 30 + 5;
            }
        }
Ejemplo n.º 21
0
        CssBox CreateInputBox(DomElement domE,
                              CssBox parentBox,
                              BoxSpec spec,
                              LayoutFarm.RootGraphic rootgfx, HtmlHost host)
        {
            //https://www.w3schools.com/tags/tag_input.asp
            //button
            //checkbox
            //color
            //date
            //datetime - local
            //email
            //file
            //hidden
            //image
            //month
            //number
            //password
            //radio
            //range
            //reset
            //search
            //submit
            //tel
            //text
            //time
            //url
            //week



            var typeAttr = domE.FindAttribute("type");

            if (typeAttr != null)
            {
                switch (typeAttr.Value)
                {
                case "password":
                {
                    var    textbox    = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false, true);
                    CssBox wrapperBox = CreateWrapper(
                        host,
                        textbox,
                        textbox.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    //place holder support
                    DomAttribute placeHolderAttr = domE.FindAttribute("placeholder");
                    if (placeHolderAttr != null)
                    {
                        textbox.PlaceHolderText = placeHolderAttr.Value;
                    }
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "text":
                {
                    // user can specific width of textbox
                    //var textbox = new LayoutFarm.CustomWidgets.TextBox(100, 17, false);
                    var    textbox    = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false);
                    CssBox wrapperBox = CreateWrapper(
                        host,
                        textbox,
                        textbox.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    //place holder support
                    DomAttribute placeHolderAttr = domE.FindAttribute("placeholder");
                    if (placeHolderAttr != null)
                    {
                        textbox.PlaceHolderText = placeHolderAttr.Value;
                    }
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "button":
                {
                    //use subdom technique ***
                    //todo: review the technique here
                    var button       = new HtmlWidgets.Button(60, 30);
                    var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement;
                    if (ihtmlElement != null)
                    {
                        button.Text = ihtmlElement.innerHTML;
                    }
                    else
                    {
                        button.Text = "testButton";
                    }

                    WebDom.Impl.HtmlElement buttonDom = (WebDom.Impl.HtmlElement)button.GetPresentationDomNode((HtmlDocument)domE.OwnerDocument);
                    buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:white;cursor:pointer");
                    CssBox buttonCssBox = host.CreateBox(parentBox, buttonDom, true);
                    parentBox.AppendChild(buttonCssBox);
                    return(buttonCssBox);
                }

                case "checkbox":
                {
                    //implement with choice box + multiple value
                    var button = new HtmlWidgets.ChoiceBox(10, 10);
                    button.OnlyOne = false;         //*** show as checked box
                    var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement;
                    WebDom.Impl.HtmlElement buttonDom = (WebDom.Impl.HtmlElement)button.GetPresentationDomNode((HtmlDocument)domE.OwnerDocument);
                    //buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:red;cursor:pointer");
                    CssBox buttonCssBox = host.CreateBox(parentBox, buttonDom, true);         //create and append to the parentBox
#if DEBUG
                    buttonCssBox.dbugMark1 = 1;
#endif
                    return(buttonCssBox);
                }

                case "radio":
                {
                    var button = new HtmlWidgets.ChoiceBox(10, 10);
                    button.OnlyOne = true;        // show as option box

                    var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement;

                    //if (ihtmlElement != null)
                    //{
                    //    button.Text = ihtmlElement.innerHTML;
                    //}
                    //else
                    //{
                    //    button.Text = "testButton";
                    //}
                    //button.Text = "C";

                    WebDom.Impl.HtmlElement buttonDom = (WebDom.Impl.HtmlElement)button.GetPresentationDomNode((HtmlDocument)domE.OwnerDocument);
                    //buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:red;cursor:pointer");
                    CssBox buttonCssBox = host.CreateBox(parentBox, buttonDom, true);         //create and append to the parentBox
#if DEBUG
                    buttonCssBox.dbugMark1 = 1;
#endif
                    return(buttonCssBox);
                }

                case "your_box":
                {
                    //tempfix -> just copy the Button code,
                    //TODO: review here, use proper radio button
                    var    box        = new LayoutFarm.CustomWidgets.Box(20, 20);
                    CssBox wrapperBox = CreateWrapper(
                        host,
                        box,
                        box.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }
                }
            }
            return(null);
        }
Ejemplo n.º 22
0
        protected override void OnStart(AppHost host)
        {
            _vgVisualDocHost = new VgVisualDocHost();
            _vgVisualDocHost.SetInvalidateDelegate(vgElem =>
            {
                //invalidate graphic here
            });

            _backBoard           = new BackDrawBoardUI(800, 600);
            _backBoard.BackColor = Color.White;
            host.AddChild(_backBoard);

            //load lion svg

            string svgfile = "../Test8_HtmlRenderer.Demo/Samples/Svg/others/tiger.svg";
            //string svgfile = "1f30b.svg";
            //string svgfile = "../Data/Svg/twemoji/1f30b.svg";
            //string svgfile = "../Data/1f30b.svg";
            //string svgfile = "../Data/Svg/twemoji/1f370.svg";

            VgVisualDoc     vgDocRoot = ReadSvgFile(svgfile);
            VgVisualElement vgVisElem = vgDocRoot.VgRootElem;
            var             uiSprite  = new UISprite(10, 10);

            uiSprite.LoadVg(vgVisElem);
            _backBoard.AddChild(uiSprite);


            //
            _redBox           = new LayoutFarm.CustomWidgets.Box(50, 50); //visual rect box
            _redBox.BackColor = Color.Red;
            _redBox.SetLocation(10, 10);
            //box1.dbugTag = 1;
            SetupActiveBoxProperties(_redBox);
            _backBoard.AddChild(_redBox);
            //----------------------


            //--------
            _rectBoxController = new CustomWidgets.RectBoxController();
            _rectBoxController.Init();
            _backBoard.AddChild(_rectBoxController);

            //foreach (var ui in rectBoxController.GetControllerIter())
            //{
            //    viewport.AddContent(ui);
            //}

            //--------
            var svgEvListener = new GeneralEventListener();

            //uiSprite.AttachExternalEventListener(svgEvListener);
            svgEvListener.MouseDown += (e) =>
            {
                //e.MouseCursorStyle = MouseCursorStyle.Pointer;
                ////--------------------------------------------
                //e.SetMouseCapture(rectBoxController.ControllerBoxMain);
                _rectBoxController.UpdateControllerBoxes(_redBox);
                _rectBoxController.Focus();
                //System.Console.WriteLine("click :" + (count++));
            };
            _rectBoxController.ControllerBoxMain.KeyDown += (s1, e1) =>
            {
                if (e1.KeyCode == UIKeys.C && e1.Ctrl)
                {
                    //test copy back image buffer from current rect area

#if DEBUG
                    //int left = rectBoxController.ControllerBoxMain.Left;
                    //int top = rectBoxController.ControllerBoxMain.Top;
                    //int width = rectBoxController.ControllerBoxMain.Width;
                    //int height = rectBoxController.ControllerBoxMain.Height;

                    //using (DrawBoard drawBoard = DrawBoardCreator.CreateNewDrawBoard(1, width, height))
                    //{

                    //    //create new draw board
                    //    drawBoard.OffsetCanvasOrigin(left, top);
                    //    _backBoard.CurrentPrimaryRenderElement.CustomDrawToThisCanvas(drawBoard, new Rectangle(0, 0, width, height));
                    //    using (var img2 = new PixelFarm.CpuBlit.ActualBitmap(width, height))
                    //    {
                    //        //copy content from drawboard to target image and save
                    //        drawBoard.RenderTo(img2, 0, 0, width, height);

                    //        PixelFarm.CpuBlit.Imaging.PngImageWriter.SaveImgBufferToPngFile(
                    //            PixelFarm.CpuBlit.ActualBitmap.GetBufferPtr(img2),
                    //            img2.Stride,
                    //            img2.Width,
                    //            img2.Height,
                    //            "d:\\WImageTest\\tiger.png");
                    //    }
                    //    //copy content from drawboard to target image and save
                    //}
#endif
                }
            };
        }
Ejemplo n.º 23
0
        void AddScrollView2(AppHost host, int x, int y)
        {
            var panel = new LayoutFarm.CustomWidgets.Box(800, 600);

            panel.HasSpecificWidthAndHeight = true;
            panel.NeedClipArea = true;
            panel.SetLocation(x + 10, y + 30);
            panel.BackColor         = Color.LightGray;
            panel.ContentLayoutKind = CustomWidgets.BoxContentLayoutKind.VerticalStack;
            host.AddChild(panel);
            //-------------------------
            //load images...

            //check folder before load
            string[] fileNames = new string[0];

            if (System.IO.Directory.Exists("../Data/imgs"))
            {
                fileNames = System.IO.Directory.GetFiles("../Data/imgs", "0*.jpg");
            }
            //select only
            int lastY = 0;


            int imgNo = 0;

            for (int i = 0; i < fileNames.Length * 4; ++i) //5 imgs
            {
                var imgbox = new LayoutFarm.CustomWidgets.ImageBox(36, 36);
                imgbox.BackColor = Color.OrangeRed;
                imgbox.SetLocation(0, lastY);
                imgbox.MouseUp += (s, e) =>
                {
                    if (e.Button == UIMouseButtons.Right)
                    {
                        //test remove this imgbox on right mouse click
                        panel.RemoveChild(imgbox);
                    }
                };

                ImageBinder imgBinder = host.CreateImageBinder(fileNames[imgNo]);
                imgbox.SetSize(imgBinder.Width, imgBinder.Height);
                imgbox.ImageBinder = imgBinder;


                lastY += imgbox.Height;
                panel.AddChild(imgbox);

                imgNo++;
                if (imgNo == fileNames.Length) //last img
                {
                    imgNo = 0;                 //reset
                }
            }
            //--------------------------
            //panel may need more
            panel.SetViewport(0, 0);

            //-------------------------
            {
                //vertical scrollbar
                var vscbar = new LayoutFarm.CustomWidgets.ScrollBar(15, 200);
                vscbar.SetLocation(x + 10, y + 10);
                vscbar.MinValue    = 0;
                vscbar.MaxValue    = lastY;
                vscbar.SmallChange = 20;
                host.AddChild(vscbar);
                //add relation between viewpanel and scroll bar
                var scRelation = new LayoutFarm.CustomWidgets.ScrollingRelation(vscbar.SliderBox, panel);
            }
            //-------------------------
            {
                //horizontal scrollbar
                var hscbar = new LayoutFarm.CustomWidgets.ScrollBar(150, 15);
                hscbar.ScrollBarType = CustomWidgets.ScrollBarType.Horizontal;
                hscbar.SetLocation(x + 30, y + 10);
                hscbar.MinValue    = 0;
                hscbar.MaxValue    = panel.Width;//just init
                hscbar.SmallChange = 20;
                host.AddChild(hscbar);
                //add relation between viewpanel and scroll bar
                var scRelation = new LayoutFarm.CustomWidgets.ScrollingRelation(hscbar.SliderBox, panel);
            }
        }
Ejemplo n.º 24
0
        protected override void OnStart(AppHost host)
        {
            //grid0
            {
                var gridView = new LayoutFarm.CustomWidgets.GridView(100, 100);
                gridView.SetLocation(50, 50);
                gridView.BuildGrid(2, 4, CellSizeStyle.UniformCell);
                host.AddChild(gridView);
                gridView.MouseDown += (s1, e1) =>
                {
                };
            }
            //grid1
            {
                var gridView = new LayoutFarm.CustomWidgets.GridView(100, 100);
                gridView.SetLocation(200, 50);
                gridView.BuildGrid(2, 4, CellSizeStyle.UniformCell);
                host.AddChild(gridView);
                var simpleButton = new LayoutFarm.CustomWidgets.Box(20, 20);
                simpleButton.BackColor = KnownColors.FromKnownColor(KnownColor.OliveDrab);
                gridView.SetCellContent(simpleButton, 1, 1);
                gridView.MouseDown += (s1, e1) =>
                {
                };

                simpleButton.MouseDown += (s1, e1) =>
                {
                    var box = (LayoutFarm.CustomWidgets.Box)s1;
                    box.BackColor = KnownColors.FromKnownColor(KnownColor.OrangeRed);
                };
            }
            ////-----
            //grid2
            {
                var gridView = new LayoutFarm.CustomWidgets.GridView(200, 100);
                gridView.SetLocation(350, 50);
                gridView.BuildGrid(10, 8, CellSizeStyle.UniformCell);
                host.AddChild(gridView);
            }

            ////-----
            //grid3
            {
                var gridView = new LayoutFarm.CustomWidgets.GridView(200, 100);
                gridView.SetLocation(50, 250);
                gridView.BuildGrid(10, 8, CellSizeStyle.UniformCell);
                host.AddChild(gridView);
            }


            ////-----
            //grid4
            //{
            //    var gridView = new LayoutFarm.CustomWidgets.GridView(800, 400);
            //    gridView.SetLocation(10, 10);
            //    gridView.HasSpecificHeight = true;
            //    gridView.HasSpecificWidth = true;
            //    gridView.NeedClipArea = true;
            //    gridView.BuildGrid(4, 4, CellSizeStyle.UniformCell);



            //    var gridBox = new LayoutFarm.CustomWidgets.GridBox(400, 200);
            //    gridBox.SetLocation(300, 250);
            //    gridBox.SetGridView(gridView);
            //    viewport.AddContent(gridBox);
            //    gridBox.PerformContentLayout();
            //}
            ////-----
            //grid5
            {
                var gridView = new LayoutFarm.CustomWidgets.GridView(200, 100);
                gridView.SetLocation(50, 500);
                gridView.BuildGrid(10, 8, CellSizeStyle.UniformCell);
                host.AddChild(gridView);
            }

            {
                //grid 6
                var gridView = new LayoutFarm.CustomWidgets.GridView(200, 100);
                //gridView.HasSpecificHeight = true; //if not set ,scroll bar will not show scroll button
                //gridView.HasSpecificWidth = true;//if not set ,scroll bar will not show scroll button

                gridView.SetLocation(300, 500);
                gridView.NeedClipArea = true;
                gridView.BuildGrid(100, 4, 5, 20);
                host.AddChild(gridView);

                //manual sc-bar
                var vscbar = new LayoutFarm.CustomWidgets.ScrollBar(15, 100);
                {
                    //add vrcbar for grid view
                    vscbar.SetLocation(gridView.Right + 10, gridView.Top);
                    vscbar.MinValue    = 0;
                    vscbar.MaxValue    = gridView.Height;
                    vscbar.SmallChange = 20;
                    host.AddChild(vscbar);

                    //add relation between viewpanel and scroll bar
                    var scRelation = new LayoutFarm.CustomWidgets.ScrollingRelation(vscbar.SliderBox, gridView);
                }
                //
                var hscbar = new LayoutFarm.CustomWidgets.ScrollBar(200, 15);
                {
                    //horizontal scrollbar
                    hscbar.ScrollBarType = CustomWidgets.ScrollBarType.Horizontal;
                    hscbar.SetLocation(gridView.Left, gridView.Bottom + 10);
                    hscbar.MinValue    = 0;
                    hscbar.MaxValue    = gridView.Width;
                    hscbar.SmallChange = 2;
                    host.AddChild(hscbar);
                    //add relation between viewpanel and scroll bar
                    var scRelation = new LayoutFarm.CustomWidgets.ScrollingRelation(hscbar.SliderBox, gridView);
                }

                //perform content layout again***
                //gridView.PerformContentLayout();
            }
        }
Ejemplo n.º 25
0
        CssBox CreateInputBox(HtmlElement domE,
                              CssBox parentBox,
                              BoxSpec spec,
                              HtmlHost host)
        {
            //https://www.w3schools.com/tags/tag_input.asp
            //button
            //checkbox
            //color
            //date
            //datetime - local
            //email
            //file
            //hidden
            //image
            //month
            //number
            //password
            //radio
            //range
            //reset
            //search
            //submit
            //tel
            //text
            //time
            //url
            //week
            HtmlInputElement htmlInputElem = (HtmlInputElement)domE;
            var typeAttr = domE.FindAttribute("type");

            if (typeAttr != null)
            {
                switch (typeAttr.Value)
                {
                case "password":
                {
                    var textbox = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false, true);
                    textbox.TextBoxSwitcher = _textboxSwitcher;

                    var subdomExtender = new TextBoxInputSubDomExtender(textbox);

                    CssBox wrapperBox = CreateCssWrapper(
                        host,
                        textbox,
                        textbox.GetPrimaryRenderElement(),
                        spec,
                        subdomExtender,
                        true);

                    textbox.KeyDown += (s, e) =>
                    {
                        ((LayoutFarm.UI.IUIEventListener)htmlInputElem).ListenKeyDown(e);
                    };


                    htmlInputElem.SubDomExtender = subdomExtender;        //connect

                    //place holder support
                    DomAttribute placeHolderAttr = domE.FindAttribute("placeholder");
                    if (placeHolderAttr != null)
                    {
                        textbox.PlaceHolderText = placeHolderAttr.Value;
                    }
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "text":
                {
                    //TODO: user can specific width of textbox
                    var textbox = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false);
                    textbox.TextBoxSwitcher = _textboxSwitcher;

                    var subdomExtender = new TextBoxInputSubDomExtender(textbox);

                    CssBox wrapperBox = CreateCssWrapper(
                        host,
                        textbox,
                        textbox.GetPrimaryRenderElement(),
                        spec,
                        subdomExtender,
                        true);

                    textbox.KeyDown += (s, e) =>
                    {
                        ((LayoutFarm.UI.IUIEventListener)htmlInputElem).ListenKeyDown(e);
                    };

                    htmlInputElem.SubDomExtender = subdomExtender;        //connect

                    //place holder support
                    DomAttribute placeHolderAttr = domE.FindAttribute("placeholder");
                    if (placeHolderAttr != null)
                    {
                        textbox.PlaceHolderText = placeHolderAttr.Value;
                    }
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "button":
                {
                    //use subdom technique ***
                    //todo: review the technique here
                    var button       = new HtmlWidgets.Button(60, 30);
                    var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement;
                    if (ihtmlElement != null)
                    {
                        button.Text = ihtmlElement.innerHTML;
                    }
                    else
                    {
                        button.Text = "testButton";
                    }

                    HtmlElement buttonDom = button.GetPresentationDomNode(domE);
                    buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:white;cursor:pointer");
                    CssBox buttonCssBox = host.CreateCssBox(parentBox, buttonDom, true);
                    parentBox.AppendChild(buttonCssBox);
                    return(buttonCssBox);
                }

                case "checkbox":
                {
                    //implement with choice box + multiple value

                    var chkbox = new HtmlWidgets.ChoiceBox(18, 10);
                    chkbox.SetHtmlInputBox(htmlInputElem);
                    chkbox.OnlyOne = false;         //*** show as checked box

                    HtmlElement chkBoxElem = chkbox.GetPresentationDomNode(domE);
                    //buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:red;cursor:pointer");

                    CssBox chkCssBox = host.CreateCssBox(parentBox, chkBoxElem, true); //create and append to the parentBox
                    htmlInputElem.SubDomExtender = chkbox;                             //connect

#if DEBUG
                    chkCssBox.dbugMark1 = 1;
#endif
                    return(chkCssBox);
                }

                case "radio":
                {
                    var radio = new HtmlWidgets.ChoiceBox(10, 10);
                    radio.OnlyOne = true;        // show as option box
                    HtmlElement radioElem = radio.GetPresentationDomNode(domE);
                    //buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:red;cursor:pointer");

                    CssBox buttonCssBox = host.CreateCssBox(parentBox, radioElem, true); //create and append to the parentBox
                    htmlInputElem.SubDomExtender = radio;                                //connect

#if DEBUG
                    buttonCssBox.dbugMark1 = 1;
#endif
                    return(buttonCssBox);
                }

                case "your_box":
                {
                    //tempfix -> just copy the Button code,
                    //TODO: review here, use proper radio button
                    var    box        = new LayoutFarm.CustomWidgets.Box(20, 20);
                    CssBox wrapperBox = CreateCssWrapper(
                        host,
                        box,
                        box.GetPrimaryRenderElement(),
                        spec,
                        null,
                        true);
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }
                }
            }
            return(null);
        }
Ejemplo n.º 26
0
        public override CssBox CreateCssBox(
            HtmlElement domE,
            CssBox parentBox,
            BoxSpec spec,
            HtmlHost host)
        {
            switch (domE.Name)
            {
            case "select":
            {
                CssBox selectedBox = CreateSelectBox(domE, parentBox, spec, host);
                if (selectedBox != null)
                {
                    return(selectedBox);
                }
            }
            break;

            case "input":
            {
                CssBox inputBox = CreateInputBox(domE, parentBox, spec, host);
                if (inputBox != null)
                {
                    return(inputBox);
                }
            }
            break;

            case "canvas":
            {
                //test only
                //TODO: review here
                //software canvas ?
                var    canvas     = new LayoutFarm.CustomWidgets.MiniAggCanvasBox(400, 400);
                CssBox wrapperBox = CreateCssWrapper(
                    host,
                    canvas,
                    canvas.GetPrimaryRenderElement(),
                    spec,
                    null,
                    true);
                parentBox.AppendChild(wrapperBox);
                return(wrapperBox);
            }

            case "textarea":
            {
                CssBox textAreaCssBox = CreateTextAreaElement(domE, parentBox, spec, host);
                if (textAreaCssBox != null)
                {
                    return(textAreaCssBox);
                }
            }
            break;
            }

            //default unknown
            var simpleBox = new LayoutFarm.CustomWidgets.Box(100, 20);

            simpleBox.BackColor = PixelFarm.Drawing.KnownColors.LightGray;
            CssBox wrapperBox2 = CreateCssWrapper(
                host,
                simpleBox,
                simpleBox.GetPrimaryRenderElement(),
                spec,
                null,
                false);

            parentBox.AppendChild(wrapperBox2);
            return(wrapperBox2);
        }
Ejemplo n.º 27
0
        protected override void OnStart(AppHost host)
        {
            //SetupImageList(host);
            for (int i = 1; i < 5; ++i)
            {
                var textbox = new LayoutFarm.CustomWidgets.Box(30, 30);
                textbox.SetLocation(i * 40, i * 40);
                host.AddChild(textbox);
            }
            //--------------------
            //image box
            //load bitmap with gdi+
            ImageBinder imgBinder = host.LoadImageAndBind("../Data/imgs/favorites32.png");

            var imgBox = new CustomWidgets.ImageBox(imgBinder.Width, imgBinder.Height);

            imgBox.ImageBinder = imgBinder;
            host.AddChild(imgBox);
            //--------------------
            //checked box
            int boxHeight = 20;
            int boxY      = 50;

            //multiple select
            for (int i = 0; i < 4; ++i)
            {
                var statedBox = new LayoutFarm.CustomWidgets.CheckBox(20, boxHeight);
                statedBox.SetLocation(10, boxY);
                boxY += boxHeight + 5;
                host.AddChild(statedBox);
            }
            //-------------------------------------------------------------------------
            //single select
            boxY += 50;
            for (int i = 0; i < 4; ++i)
            {
                var statedBox = new LayoutFarm.CustomWidgets.CheckBox(20, boxHeight);
                statedBox.SetLocation(10, boxY);
                boxY += boxHeight + 5;
                host.AddChild(statedBox);
                statedBox.CheckChanged += (s, e) =>
                {
                    var selectedBox = (LayoutFarm.CustomWidgets.CheckBox)s;
                    if (selectedBox != _currentSingleCheckedBox)
                    {
                        if (_currentSingleCheckedBox != null)
                        {
                            _currentSingleCheckedBox.Checked = false;
                        }
                        _currentSingleCheckedBox = selectedBox;
                    }
                };
            }
            //-------------------------------------------------------------------
            //test canvas
            var canvasBox = new MyDrawingCanvas(300, 300);

            canvasBox.SetLocation(400, 150);
            host.AddChild(canvasBox);
            //-------------------------------------------------------------------
        }
Ejemplo n.º 28
0
        LayoutFarm.HtmlBoxes.CssBox CreateInputBox(DomElement domE,
                                                   LayoutFarm.HtmlBoxes.CssBox parentBox,
                                                   BoxSpec spec,
                                                   LayoutFarm.RootGraphic rootgfx, HtmlHost host)
        {
            var typeAttr = domE.FindAttribute("type");

            if (typeAttr != null)
            {
                switch (typeAttr.Value)
                {
                case "text":
                {
                    // user can specific width of textbox
                    //var textbox = new LayoutFarm.CustomWidgets.TextBox(100, 17, false);
                    var textbox    = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false);
                    var wrapperBox = CreateWrapper(
                        textbox,
                        textbox.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    //place holder support
                    var placeHolderAttr = domE.FindAttribute("placeholder");
                    if (placeHolderAttr != null)
                    {
                        textbox.PlaceHolderText = placeHolderAttr.Value;
                    }
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "button":
                {
                    //use subdom? technique
                    //todo: review the technique here
                    var button       = new HtmlWidgets.Button(60, 30);
                    var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement;
                    if (ihtmlElement != null)
                    {
                        button.Text = ihtmlElement.innerHTML;
                    }
                    else
                    {
                        button.Text = "";
                    }
                    button.Text = "testButton";
                    DomElement buttonDom    = button.GetPresentationDomNode((HtmlDocument)domE.OwnerDocument);
                    CssBox     buttonCssBox = host.CreateBox2(parentBox, (WebDom.Impl.HtmlElement)buttonDom, true);     // CreateCssBox(buttonDom, parentBox, spec, host);
                    //var ui = button.GetPrimaryUIElement(this.myHost);

                    //var wrapperBox = CreateWrapper(
                    //    button,
                    //    ui.GetPrimaryRenderElement(rootgfx),
                    //    spec, true);
                    //parentBox.AppendChild(wrapperBox);
                    //return wrapperBox;

                    parentBox.AppendChild(buttonCssBox);
                    return(buttonCssBox);
                }

                case "textbox":
                {
                    var    textbox    = new LayoutFarm.CustomWidgets.TextBox(100, 17, false);
                    CssBox wrapperBox = CreateWrapper(
                        textbox,
                        textbox.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "radio":
                {
                    //tempfix -> just copy the Button code,
                    //TODO: review here, use proper radio button
                    var    box        = new LayoutFarm.CustomWidgets.Box(20, 20);
                    CssBox wrapperBox = CreateWrapper(
                        box,
                        box.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }
                }
            }
            return(null);
        }
Ejemplo n.º 29
0
        static void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.Box box)
        {
            //1. mouse down

            bool mouseUpFromDragging = false;

            System.DateTime mouseDownTime = System.DateTime.MinValue;
            System.DateTime mouseUpTime = System.DateTime.MinValue;
            int             mdown_x = 0, mdown_y = 0;
            double          velo_x = 0;
            double          velo_y = 0;
            int             x_dir  = 0;
            int             y_dir  = 0;

            UI.UITimerTask animateTimer = new UITimerTask(tim =>
            {
                box.SetLocation(box.Left + (int)(velo_x * 10 * x_dir),
                                box.Top + (int)(velo_y * 10 * y_dir));

                velo_x -= 0.1;
                velo_y -= 0.1;

                if (velo_x <= 0)
                {
                    velo_x = 0;
                }
                if (velo_y <= 0)
                {
                    velo_y = 0;
                }
                if (velo_x == 0 && velo_y == 0)
                {
                    tim.Enabled = false;
                }
            });
            animateTimer.Interval = 10;
            UIPlatform.RegisterTimerTask(animateTimer);


            box.MouseDown += (s, e) =>
            {
                mdown_x = box.Left;
                mdown_y = box.Top;
                animateTimer.Enabled = false;

                mouseDownTime       = System.DateTime.Now;
                mouseUpFromDragging = false;
                //
                box.BackColor      = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
                e.MouseCursorStyle = MouseCursorStyle.Pointer;
            };
            //2. mouse up
            box.MouseUp += (s, e) =>
            {
                mouseUpTime        = System.DateTime.Now;
                e.MouseCursorStyle = MouseCursorStyle.Default;
                box.BackColor      = KnownColors.LightGray;

                if (mouseUpFromDragging)
                {
                    int mup_x = box.Left;
                    int mup_y = box.Top;

                    System.TimeSpan drag_timespan = mouseUpTime - mouseDownTime;
                    double          ms            = drag_timespan.Milliseconds;

                    double displacement_x = mup_x - mdown_x;
                    double displacement_y = mup_y - mdown_y;
                    velo_x = System.Math.Abs(displacement_x / ms);
                    velo_y = System.Math.Abs(displacement_y / ms);

                    x_dir = (mup_x >= mdown_x) ? 1 : -1;
                    y_dir = (mup_y >= mdown_y) ? 1 : -1;
                    animateTimer.Enabled = true;
                }
            };
            box.MouseDrag += (s, e) =>
            {
                mouseUpFromDragging = true;
                box.BackColor       = KnownColors.FromKnownColor(KnownColor.GreenYellow);
                Point pos = box.Position;
                box.SetLocation(pos.X + e.XDiff, pos.Y + e.YDiff);
                e.MouseCursorStyle = MouseCursorStyle.Pointer;
                e.CancelBubbling   = true;
            };
        }