예제 #1
0
    private void OnFileSelected(String path)
    {
        RemoveChild(imageSprite);
        imageSprite = new Sprite();
        AddChild(imageSprite);

        string imgType = null;

        switch (System.IO.Path.GetExtension(path).ToLower())
        {
        case (".png"): imgType = ".png"; break;

        case (".jpeg"):
        case (".jpg"): imgType = ".jpg"; break;

        case (".webp"): imgType = ".webp"; break;
        }

        if (imgType == null)
        {
            errorDiag.PopupCenteredRatio();
            errorDiag.RectSize     = new Vector2(errorDiag.RectSize.x, errorLabel.RectSize.y);
            errorDiag.RectPosition = new Vector2(errorDiag.RectPosition.x, GetViewportRect().Size.y / 2f);
            return;
        }

        Task.Run(() => {
            try {
                var imageFile = new File();
                imageFile.Open(path, File.ModeFlags.Read);
                var buffer = imageFile.GetBuffer((int)imageFile.GetLen());
                var image  = new Image();
                if (imgType.Equals(".png"))
                {
                    image.LoadPngFromBuffer(buffer);
                }
                else if (imgType.Equals(".jpeg") || imgType.Equals(".jpg"))
                {
                    image.LoadJpgFromBuffer(buffer);
                }
                else if (imgType.Equals(".webp"))
                {
                    image.LoadWebpFromBuffer(buffer);
                }
                var im = new ImageTexture();
                im.CreateFromImage(image);
                imageSprite.Texture = im;
                var xScale          = GetViewportRect().Size.x / im.GetSize().x;
                imageSprite.Scale   = new Vector2(xScale * 0.95f, xScale * 0.95f);
                imageSprite.Translate(new Vector2(GetViewportRect().Size.x / 2f, GetViewportRect().Size.y / 2f));
            } catch {
                errorDiag.PopupCenteredRatio();
                errorDiag.RectSize     = new Vector2(errorDiag.RectSize.x, errorLabel.RectSize.y);
                errorDiag.RectPosition = new Vector2(errorDiag.RectPosition.x, GetViewportRect().Size.y / 2f);
            }
        });
    }
예제 #2
0
        public override void _Draw()
        {
            if (texture == null)
            {
                return;
            }

            var rr = GetParentAreaSize();
            var ts = texture.GetSize();

            DrawTexture(texture, (rr - ts) / 2);
        }
예제 #3
0
    void generateHalfRateDot(int rate)
    {
        ImageTexture halfDotTexture = new ImageTexture();

        halfDotTexture.Load("Resources/Graphics/GUI/rateDotHalf.png");

        Sprite sprite = new Sprite();

        sprite.Texture  = halfDotTexture;
        sprite.Centered = false;
        float xAxis = halfDotTexture.GetSize().x *((rate / 2)) + RATE_GAP * ((rate / 2));

        sprite.Position = new Vector2(xAxis, 0);

        AddChild(sprite);
    }
예제 #4
0
    void initializeEnduranceBar()
    {
        ImageTexture barElementTexture = new ImageTexture();

        barElementTexture.Load("Resources/Graphics/GUI/enduranceIndicator.png");

        for (int i = 0; i < ENDURANCE_BAR_MAX_LENGTH; i++)
        {
            int barElementX = i * (int)barElementTexture.GetSize().x;

            Sprite barElementSprite = new Sprite();
            barElementSprite.Texture  = barElementTexture;
            barElementSprite.Position = new Vector2(barElementX, 0);
            barElementSprite.Centered = false;
            enduranceBar.AddChild(barElementSprite);
        }
    }
예제 #5
0
    void fillVelocityBar(int barLength)
    {
        ImageTexture barElementTexture = new ImageTexture();

        barElementTexture.Load("Resources/Graphics/GUI/velocityIndicator.png");

        for (int i = 0; i < barLength; i++)
        {
            int barElementX = i * (int)barElementTexture.GetSize().x;

            Sprite barElementSprite = new Sprite();
            barElementSprite.Texture  = barElementTexture;
            barElementSprite.Position = new Vector2(barElementX, 0);
            barElementSprite.Centered = false;
            velocityBar.AddChild(barElementSprite);
        }
    }
예제 #6
0
    void generateFullRateDots(int rate)
    {
        ImageTexture fullDotTexture = new ImageTexture();

        fullDotTexture.Load("Resources/Graphics/GUI/rateDotFull.png");

        for (int i = 0; i < rate - 1; i += 2)
        {
            Sprite sprite = new Sprite();
            sprite.Texture  = fullDotTexture;
            sprite.Centered = false;
            float xAxis = fullDotTexture.GetSize().x *(i / 2) + RATE_GAP * (i / 2);
            sprite.Position = new Vector2(xAxis, 0);

            AddChild(sprite);
        }
    }
예제 #7
0
        public StatusBar(XElement xml)
        {
            Name                  = "StatusBar";
            Disable3d             = true;
            RenderTargetClearMode = ClearMode.OnlyNextFrame;
            RenderTargetVFlip     = true;
            XML = xml;
            ImageTexture pic = Assets.PicTextureSafe(XML?.Attribute("Pic")?.Value);

            Size = pic?.GetSize() ?? Vector2.Zero;
            if (pic != null)
            {
                AddChild(new Sprite()
                {
                    Name     = "StatusBarPic",
                    Texture  = pic,
                    Position = Size / 2f,
                });
            }
            foreach (XElement number in XML?.Elements("Number") ?? Enumerable.Empty <XElement>())
            {
                Add(new StatusNumber(number));
            }
        }