Пример #1
0
        public UIBaseComponent(IRenderConfiguration setRenderConfig)
        {
            if (setRenderConfig == null)
            {
                throw new ArgumentNullException(nameof(setRenderConfig));
            }
            widthSizeMode         = UISizeMode.Fixed;
            heightSizeMode        = UISizeMode.Fixed;
            isPerformingLayout    = false;
            suppressPerformLayout = false;
            customLayoutHooks     = new Dictionary <string, ModifyLayout>();
            components            = new List <UIBaseComponent>();
            animations            = new List <UIAnimation>();
            renderConfig          = setRenderConfig;
            parentComponent       = null;

            Focusable              = false;
            PositionAnchor         = UIPositionAnchor.TopLeft;
            BackgroundColor        = new Color(1.0f, 1.0f, 1.0f, 0.0f);
            UserInteractionEnabled = true;
            Visible  = true;
            Alpha    = 1.0f;
            Rotation = 0.0f;
        }
Пример #2
0
        private UIImage CreateNinePatchPart(Bitmap bitmap, UIAnchorPoint anchor, Vector2 origin, int x, int y, int width, int height, UISizeMode widthMode, UISizeMode heightMode, bool forceSingleColor = false)
        {
            if (bitmap == null)
            {
                return(null);
            }

            if (forceSingleColor || IsSingleColor(bitmap))
            {
                var solidColor = bitmap.GetPixel(0, 0);
                bitmap = new Bitmap(1, 1);
                bitmap.SetPixel(0, 0, solidColor);
            }
            else if (IsTopDownRepeated(bitmap))
            {
                var oldBitmap = bitmap;

                int w = bitmap.Width;
                bitmap = new Bitmap(w, 1);
                for (int i = 0; i < w; i++)
                {
                    bitmap.SetPixel(i, 0, oldBitmap.GetPixel(i, 0));
                }
            }
            else if (IsLeftRightRepeated(bitmap))
            {
                var oldBitmap = bitmap;

                int h = bitmap.Height;
                bitmap = new Bitmap(1, h);
                for (int i = 0; i < h; i++)
                {
                    bitmap.SetPixel(0, i, oldBitmap.GetPixel(0, i));
                }
            }

            if (bitmap.Width >= 1024 || bitmap.Height >= 1024)
            {
                int i = 0;
                i = i * i;
            }

            UIImage image = new UIImage();

            image.AnchorPoint = anchor;
            image.Origin      = origin;
            image.X           = (float)x;
            image.Y           = (float)y;
            image.XMode       = UIPositionMode.Absolute;
            image.YMode       = UIPositionMode.Absolute;
            image.Width       = (float)width;
            image.Height      = (float)height;
            image.WidthMode   = widthMode;
            image.HeightMode  = heightMode;
            image.Source      = new Image(string.Empty, Rectangle.Empty)
            {
                Tag = new ImageCookingTag(bitmap)
            };

            return(image);
        }