/// <summary>
        /// 将控件坐标系的点转换为屏幕坐标系的点
        /// </summary>
        /// <param name="p">点</param>
        /// <returns>转换后的点</returns>
        public Point PointToScreen(Point p)
        {
            IUIControl parent = this;
            IUIWindow  window = null;

            while (parent != null && (window = parent as IUIWindow) == null)
            {
                p.Offset(parent.Left, parent.Top);
                parent = parent.UIParent;
            }
            return(window.PointToScreen(p));
        }
        private IUIControl CreateBooleanControl()
        {
            UIInput input = new UIInput();

            input.AddInput("id", "testBooleanControl");
            input.AddInput("title", "Bool");
            input.AddInput("Description", "This is a Boolean Control");
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("Boolean");

            panel.SetInput(input);
            return(panel);
        }
        /// <summary>
        /// 将控件坐标系的矩形转换为屏幕坐标系的矩形
        /// </summary>
        /// <param name="r">矩形</param>
        /// <returns>转换后的矩形</returns>
        public Rectangle RectangleToScreen(Rectangle r)
        {
            IUIControl parent = this;
            IUIWindow  window = null;

            while (parent != null && (window = parent as IUIWindow) == null)
            {
                r.Offset(parent.Left, parent.Top);
                parent = parent.UIParent;
            }
            return(window.RectangleToScreen(r));
        }
Example #4
0
                public string Export(RectangleF parentPadding, float currYPos)
                {
                    // start by setting our position to our global position, and then we'll translate.
                    float controlLeftPos = Frame.Left;
                    float controlTopPos  = Frame.Top;

                    // for vertical, it's relative to the control above it, so just make it relative to that
                    IUIControl logicalParent = ParentNote.GetLogicalVerticalParent(this);

                    if (logicalParent != null)
                    {
                        controlTopPos -= logicalParent.GetFrame( ).Bottom;
                    }
                    else
                    {
                        controlTopPos -= currYPos;
                    }

                    // for horizontal, it just needs to remove padding, since it'll be re-applied on load
                    controlLeftPos -= parentPadding.Left;

                    string xml = "<P ";

                    string attributes = "";

                    controlLeftPos /= (ParentSize.Width - parentPadding.Left - parentPadding.Right);
                    attributes     += string.Format("Left=\"{0:#0.00}%\"", controlLeftPos * 100);


                    attributes += string.Format(" Top=\"{0}\"", controlTopPos);

                    if (string.IsNullOrWhiteSpace(ActiveUrl) == false)
                    {
                        attributes += string.Format(" Url=\"{0}\"", HttpUtility.HtmlEncode(ActiveUrl));
                    }

                    xml += attributes + ">";

                    foreach (IUIControl child in ChildControls)
                    {
                        IEditableUIControl editableChild = child as IEditableUIControl;
                        if (editableChild != null)
                        {
                            // children of paragraphs cannot set their own position, so pass 0
                            xml += editableChild.Export(new RectangleF( ), 0);
                        }
                    }

                    xml += "</P>";

                    return(xml);
                }
        private IUIControl CreateTabControl()
        {
            UIInput input = new UIInput();

            input.AddInput("Description", "Demo tab control");
            input.AddInput("controls", new List <object> {
                CreateStringControl(), CreateBooleanControl(), CreateCheckBoxCombo()
            });
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("Tab");

            panel.SetInput(input);
            return(panel);
        }
    IEnumerator Start()
    {
        player    = GameObject.Find("Player").GetComponent <Player>();
        level     = GameObject.Find("Level").GetComponent <LevelBehaviour>();
        uiControl = GetComponent <UIControl>();

        yield return(new WaitForEndOfFrame());

        UpdateUI();


        yield return(null);
    }
        private IUIControl CreateStringControl()
        {
            UIInput input = new UIInput();

            input.AddInput("id", "testStringControl");
            input.AddInput("title", "String");
            input.AddInput("Label", "Name");
            input.AddInput("Value", "Enter Name");
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("String");

            panel.SetInput(input);
            return(panel);
        }
        private IUIControl CreateDoubleControl()
        {
            UIInput input = new UIInput();

            input.AddInput("id", "testFloatControl");
            input.AddInput("Label", "Percentage");
            input.AddInput("Value", 10.1);
            input.AddInput("min", -100);
            input.AddInput("max", 100);
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("Double");

            panel.SetInput(input);
            return(panel);
        }
        private IUIControl CreateIntControl()
        {
            UIInput input = new UIInput();

            input.AddInput("id", "testIntControl");
            input.AddInput("Label", "Total");
            input.AddInput("Value", 10);
            input.AddInput("min", -100);
            input.AddInput("max", 100);
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("Int");

            panel.SetInput(input);
            return(panel);
        }
        /// <summary>
        /// 查找控件内指定坐标的子控件,按 Z 轴可见序查找
        /// </summary>
        /// <param name="control">控件</param>
        /// <param name="p">控件坐标系内的点</param>
        /// <returns>查找到返回子控件,否则返回 null</returns>
        internal static UIControl FindUIChildInternal(IUIControl control, Point p)
        {
            UIControl child;

            for (int i = control.UIControls.Count - 1; i >= 0; i--)//按 Z 轴顺序遍历
            {
                child = control.UIControls[i];
                if (child.Visible && child.Bounds.Contains(p) && (child.Region == null || child.Region.IsVisible(PointEx.Offset(p, -child.Left, -child.Top))))
                {
                    return(FindUIChildInternal(child, PointEx.Offset(p, -child.Left, -child.Top)) ?? child);
                }
            }
            return(null);
        }
        private IUIControl CreateFileControl()
        {
            UIInput input = new UIInput();

            input.AddInput("id", "testFileControl");
            input.AddInput("Description", "Please select file(s)");
            input.AddInput("enableMultipleSelection", true);
            input.AddInput("fileFilters", "txt files (*.txt)|*.txt|Images (*.png)|*.png|All files (*.*)|*.*");
            //input.AddInput("dialogType", "save");
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("FileControl");

            panel.SetInput(input);
            return(panel);
        }
        private IUIControl CreateVGroupControl()
        {
            UIInput input = new UIInput();

            input.AddInput("Description", "Vertical group control");
            //input.AddInput("controls", new List<object> { CreateGroupControl(), CreateRangeSliderControl(), CreateListControl() });
            input.AddInput("controls", new List <object> {
                CreateStringControl(), CreateBooleanControl(), CreateCheckBoxCombo()
            });
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("Group");

            panel.SetInput(input);
            return(panel);
        }
Example #13
0
 public virtual bool HighlightAll(string[] keys)
 {
     foreach (var key in keys)
     {
         IUIControl iuiControl = ControlFromName(key);
         if (iuiControl == null || !iuiControl.WaitUntilVisible(2000))
         {
             Logger.W("UIControl '{0}' is not visible.", iuiControl);
             return(false);
         }
         iuiControl.Highlight();
         Logger.D("{0}='{1}'", key, iuiControl.Text);
     }
     return(true);
 }
Example #14
0
        private IUIControl TryGetControl(Object target)
        {
            IUIControl uiControl = null;

            if (target is GameObject)
            {
                uiControl = (target as GameObject).GetComponent <IUIControl>();
            }
            if (target is Component)
            {
                uiControl = (target as Component).GetComponent <IUIControl>();
            }

            return(uiControl);
        }
Example #15
0
                public override IUIControl TouchesEnded(PointF touch)
                {
                    // let each child handle it
                    foreach (IUIControl control in ChildControls)
                    {
                        // if a child consumes it, stop and report it was consumed.
                        IUIControl consumingControl = control.TouchesEnded(touch);
                        if (consumingControl != null)
                        {
                            return(consumingControl);
                        }
                    }

                    return(null);
                }
Example #16
0
        protected void enterDetails(Dictionary <string, string> details)
        {
            PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            properties = properties.Where(p => htmlControlType.IsAssignableFrom(p.GetMethod.ReturnType)).ToArray();
            PropertyInfo[] declaringProperties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
                                                 .Where(p => htmlControlType.IsAssignableFrom(p.GetMethod.ReturnType)).ToArray();
            string[] declaringPropertyNames = declaringProperties.Select(p => p.Name).ToArray();
            IEnumerable <PropertyInfo> baseOnlyProperties = properties.Except(declaringProperties).Where(p => !declaringPropertyNames.Contains(p.Name));

            List <PropertyInfo> orderedProperties = new List <PropertyInfo>(baseOnlyProperties);

            orderedProperties.AddRange(declaringProperties);
            string[] accessorNames = orderedProperties.Select(p => p.Name).ToArray();

            for (int i = 0; i < accessorNames.Count(); i++)
            {
                string name    = accessorNames[i];
                string onclick = null;

                if (details.ContainsKey(name))
                {
                    if (WaitPageReadyBeforePerforming)
                    {
                        WebDriverManager.WaitPageReady();
                    }

                    IUIControl iuiControl = orderedProperties[i].GetMethod.Invoke(this, null) as IUIControl;
                    if (iuiControl == null || !iuiControl.IsVisible)
                    {
                        continue;
                    }
                    iuiControl.Perform(details[name]);
                    if (iuiControl.Element.TryGetAttribute("onclick", out onclick) && !string.IsNullOrEmpty(onclick))
                    {
                        Thread.Sleep(1000);
                    }
                    else if (iuiControl.Element.TryGetAttribute("onchange", out onclick) && !string.IsNullOrEmpty(onclick))
                    {
                        Thread.Sleep(1000);
                    }

                    if (WaitPageReadyAfterPerforming)
                    {
                        WebDriverManager.WaitPageReady();
                    }
                }
            }
        }
        public IUIControl GetControl(string id)
        {
            int size = GetControlCount();

            for (int i = 0; i < size; i++)
            {
                IUIControl control = GetControl(i);

                if (control.Id.Equals(id))
                {
                    return(control);
                }
            }

            return(null);
        }
Example #18
0
        private IUIControl CreateControl(string id)
        {
            IUIControl control = null;

            if (itemList.Contains(id))
            {
                Dictionary <string, object> item = itemList[id] as Dictionary <string, object>;
                control = OmegaFactory.CreateControl(id, item);
            }
            else
            {
                control = OmegaFactory.CreateControl(id);
            }
            ControlMap.Add(id, control);
            return(control);
        }
        private IUIControl CreateHGroupControlAllOmega()
        {
            UIInput input = new UIInput();

            input.AddInput("Description", "Horizontal group control");
            input.AddInput("orientation", "horizontal");
            input.AddInput("controls", new List <object> {
                CreateStringControl(), CreateIntControl(), CreateFloatControl(), CreateBooleanControl(),
                CreateXamSliderControl(), CreateRangeSliderControl(), CreateListControl(), CreateBoxCombo(),
                CreateCheckBoxCombo(), CreateFileControl()
            });
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("Group");

            panel.SetInput(input);
            return(panel);
        }
        private IUIControl CreateBoxCombo()
        {
            UIInput input = new UIInput();

            input.AddInput("id", "testBoxComboControl");
            input.AddInput("title", "ComboBox");
            input.AddInput("Description", "Check Box Combo");
            input.AddInput("options", new List <string> {
                "Mumbai", "Chennai", "Kolkata", "Delhi"
            });
            input.AddInput("Value", "Kolkata");
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("CheckBoxCombo");

            panel.SetInput(input);
            return(panel);
        }
Example #21
0
        public virtual bool PerformAll(string[][] details, bool bypassIfNotPresented = false)
        {
            WaitUntilVisible();
            int length = details[0].Length;

            if (details[1].Length != length)
            {
                throw new ArgumentException("string[2][] details should contain two array of the same size!");
            }
            for (int i = 0; i < length; i++)
            {
                string     controlName = details[0][i];
                string     value       = details[1][i];
                IUIControl iuiControl  = ControlFromName(controlName);
                if (iuiControl == null || !iuiControl.WaitUntilVisible(bypassIfNotPresented ? 3000 : 10 * 1000))
                {
                    if (bypassIfNotPresented)
                    {
                        continue;
                    }
                    return(false);
                }

                try
                {
                    if (UIControl.AssureShowControlBeforeOperation && !iuiControl.Show())
                    {
                        Logger.W("{0} is still not displayed!", iuiControl);
                    }

                    iuiControl.Perform(value);
                    Logger.D("{0} => {1}", controlName, value);
                    Thread.Sleep(300);
                }
                catch (StaleElementReferenceException)
                {
                    Logger.W("StaleElement of {0}.", iuiControl);
                    UIControl.DiscardLastInstance();
                    iuiControl.Perform(value);
                }
                if (WaitPageReadyAfterPerforming)
                {
                    WebDriverManager.WaitPageReady();
                }
            }
            return(true);
        }
 /// <summary>
 /// 重绘所在 Win32 窗口的无效区域,可以选择是否强制刷新
 /// </summary>
 /// <param name="forceUpdate">强制刷新为 true,否则为false</param>
 protected void UpdateCore(bool forceUpdate)
 {
     if (forceUpdate || !this.UpdateSuspended)
     {
         IUIControl parent = this;
         IUIWindow  window = null;
         while (parent != null && (window = parent as IUIWindow) == null)
         {
             parent = parent.UIParent;
         }
         if (window == null)
         {
             return;
         }
         window.Update();
     }
 }
        private IUIControl CreateListControl()
        {
            UIInput input = new UIInput();

            input.AddInput("id", "testListControl");
            input.AddInput("Description", "List control");
            input.AddInput("options", new List <object> {
                "Sample-1", "Sample-2", "Sample-3", "Sample-4", "Sample-5"
            });
            input.AddInput("Value", new List <object> {
                "Sample-1", "Sample-2", "Sample-6"
            });
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("List");

            panel.SetInput(input);
            return(panel);
        }
Example #24
0
//        public static byte[] ToByteArray(this MediaTypeNames.Image image, ImageFormat format = null)
//        {
//            if (image == null) return null;
//            format = format ?? ImageFormat.Bmp;
//            using (MemoryStream ms = new MemoryStream())
//            {
//                image.Save(ms, format);
//                return ms.ToArray();
//            }
//        }
//
//        public const PixelFormat DefaultPixelFormat = PixelFormat.Format24bppRgb;
//        public static byte[] AsBytes(this Bitmap bmp, Rectangle rect, PixelFormat format = DefaultPixelFormat)
//        {
//            if (bmp == null) return null;
//            //TODO: checking rect?
//
//            byte[] bytes = null;
//            BitmapData bmpData = null;
//            try
//            {
//                bmpData = bmp.LockBits(rect, ImageLockMode.ReadOnly, format);
//
//                // Get the address of the first line.
//                IntPtr ptr = bmpData.Scan0;
//
//                // Declare an array to hold the bytes of the bitmap.
//                bytes = new byte[bmpData.Stride * bmpData.Height];
//
//                // Copy the RGB values into the array.
//                System.Runtime.InteropServices.Marshal.Copy(ptr, bytes, 0, bytes.Length);
//            }
//            finally
//            {
//                if (bmpData != null)
//                    bmp.UnlockBits(bmpData);
//            }
//
//            return bytes;
//        }
//        public static byte[] AsBytes(this Bitmap bmp, PixelFormat format = DefaultPixelFormat)
//        {
//            if (bmp == null) return null;
//
//            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
//            return AsBytes(bmp, rect, format);
//        }
//
//        public static Bitmap FromBytes(this byte[] bytes, int width, int height, PixelFormat format = DefaultPixelFormat)
//        {
//            int bitsPerPixel = ((int)format & 0xff00) >> 8;
//            int bytesPerPixel = (bitsPerPixel + 7) / 8;
//            int stride = 4 * ((width * bytesPerPixel + 3) / 4);
//
//            Bitmap bmp = new Bitmap(width, height, format);
//            BitmapData data = null;
//            try
//            {
//                data = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, format);
//                System.Runtime.InteropServices.Marshal.Copy(bytes, 0, data.Scan0, bytes.Length);
//            }
//            finally
//            {
//                if (data != null) bmp.UnlockBits(data);
//            }
//
//            return bmp;
//        }
//
//        public static void Update(this Dictionary<string, string> dict, string key, string value)
//        {
//            if (string.IsNullOrEmpty(key)) throw new ArgumentException();
//            if (dict.ContainsKey(key))
//                dict[key] = value;
//            else
//            {
//                dict.Add(key, value);
//            }
//        }

        public static bool HighlightAndMarked(this IUIControl iuiControl, string[] lines, List <string> validated)
        {
            string displayed = iuiControl.Text;

            if (displayed.ContainsAny(lines))
            {
                validated.AddRange(lines.Where(l => !validated.Contains(l) && (displayed.ContainsIgnoreCase(l) || SimilarTo(l, displayed))));
                iuiControl.Highlight(UIContainer.DefaultMatchingHighlightScript);
                return(true);
            }
            else
            {
                Logger.E("Failed to match '{0}' with given details", displayed);
                iuiControl.Highlight(UIContainer.DefaultMismatchHighlightScript);
                return(false);
            }
        }
 /// <summary>
 /// 使控件矩形无效,可以选择是否强制刷新
 /// </summary>
 /// <param name="rc">无效矩形</param>
 /// <param name="invalidateChildren">使控件所在的 Win32 窗口的子控件无效为 true,否则为 false</param>
 /// <param name="forceUpdate">强制刷新为 true,否则为false</param>
 protected void InvalidateCore(Rectangle rc, bool invalidateChildren, bool forceUpdate)
 {
     if (forceUpdate || !this.UpdateSuspended)
     {
         IUIControl parent = this;
         IUIWindow  window = null;
         while (parent != null && (window = parent as IUIWindow) == null)
         {
             rc.Offset(parent.Left, parent.Top);
             parent = parent.UIParent;
         }
         if (window == null)
         {
             return;
         }
         window.Invalidate(rc, invalidateChildren);
     }
 }
        /// <summary>
        /// 查找控件内指定名称的控件,按 Z 轴可见序查找
        /// </summary>
        /// <param name="control">控件</param>
        /// <param name="name">名称</param>
        /// <returns>查找到返回子控件,否则返回 null</returns>
        internal static UIControl FindUIChildInternal(IUIControl control, string name)
        {
            UIControl child;

            for (int i = control.UIControls.Count - 1; i >= 0; i--)
            {
                child = control.UIControls[i];
                if (child.Name == name)
                {
                    return(child);
                }
                else if (child.UIControls.Count > 0)
                {
                    return(FindUIChildInternal(child, name));
                }
            }
            return(null);
        }
        //private IUIControl CreateXamSliderControl()
        //{
        //    UIInput input = new UIInput();
        //    input.AddInput("Description", "Slider control");
        //    input.AddInput("allowTextBox", true);
        //    input.AddInput("min", 50);
        //    input.AddInput("max", 150);
        //    input.AddInput("sliderType", "int");
        //    input.AddInput("adjustMinMax", false);
        //    IUIControl panel = this.UnityContainer.Resolve<IUIControl>("XamSlider");
        //    panel.SetInput(input);
        //    return panel;
        //}

        private IUIControl CreateXamSliderControl()
        {
            UIInput input = new UIInput();
            Dictionary <string, object> pairs = new Dictionary <string, object>
            {
                { "id", "testXamSliderControl" },
                { "Description", "Strand slider control" },
                { "allowTextBox", true },
                { "min", 200 },
                { "max", 500 },
                { "adjustMinMax", true },
                { "Value", 300 }
            };
            IUIControl panel = OmegaFactory.CreateControl("XamSlider", pairs);

            //IUIControl panel = OmegaFactory.CreateControl("XamSlider");
            return(panel);
        }
        /// <summary>
        /// 将控件置于 Z 轴顶层
        /// </summary>
        public void BringToFront()
        {
            IUIControl parent = this.m_UIParent;

            if (parent == null)
            {
                return;
            }
            parent.SuspendLayout();
            try
            {
                parent.UIControls.Remove(this);
                parent.UIControls.Add(this);
            }
            finally
            {
                parent.ResumeLayout();
            }
        }
        /// <summary>
        /// 将控件置于 Z 轴底层
        /// </summary>
        public void SendToBack()
        {
            IUIControl parent = this.m_UIParent;

            if (parent == null)
            {
                return;
            }
            parent.SuspendLayout();
            try
            {
                parent.UIControls.Remove(this);
                parent.UIControls.Insert(0, this);
            }
            finally
            {
                parent.ResumeLayout();
            }
        }
        private IUIControl CreateRangeSliderControl()
        {
            UIInput input = new UIInput();

            input.AddInput("id", "testRangeSliderControl");
            input.AddInput("Description", "Range slider control");
            input.AddInput("allowTextBox", true);
            input.AddInput("min", 500);
            input.AddInput("max", 900);
            input.AddInput("Value", new Dictionary <string, float> {
                { "min", 546 }, { "max", 823 }
            });
            input.AddInput("sliderType", "int");
            input.AddInput("adjustMinMax", false);
            input.AddInput("showAbsolute", false);
            IUIControl panel = this.UnityContainer.Resolve <IUIControl>("RangeSlider");

            panel.SetInput(input);
            return(panel);
        }
 public HumanPlayer(IUIControl uiControl)
 {
     this.uiControl = uiControl;
 }
 public void setUIControl(IUIControl uiControl)
 {
     this.uiControl = uiControl;
 }