示例#1
0
    public override bool draw(float w, float h)
    {
        Rect rect = TextureUtility.getUseRect(new Rect(0, 0, w, h), AspectType.FIT_IN_REGION);

        float s = CrhcConstants.FONT_HEIGHT_NORMAL.getAs(general.number.NumberType.PIXELS);

        float x = rect.x, y = rect.y;

        w = Math.Min(s, rect.width);
        h = Math.Min(s, rect.height);

        x += rect.width / 2 - w / 2;
        y += rect.height / 2 - h / 2;

        rect = new Rect(x, y, w, h);

        filledAmount.update();

        float th = w / 10, p = 1.5f * th, f = filledAmount.get(), sx = (w - 2 * p) * f, sy = (h - 2 * p) * f;

        GUIX.fillRect(rect, Color.white);
        GUIX.strokeRect(rect, Color.black, th);

        GUIX.fillRect(new Rect(x + w / 2 - sx / 2, y + h / 2 - sy / 2, sx, sy), Color.black);

        return(false);
    }
示例#2
0
        public static Rect drawTexture(Rect drawRect, Reference <Texture2D> textureReference, AspectType aspectType, float angle)
        {
            if (textureReference.isLoaded())
            {
                return(drawTexture(drawRect, textureReference.getResource(), aspectType, angle));
            }
            else
            {
                Rect useRect = getUseRect(drawRect, textureReference.getResource(), aspectType);

                GUIX.beginOpacity(.5f);
                GUIX.strokeRect(useRect, 1);
                GUIX.fillRect(new Rect(useRect.x, useRect.y, useRect.width * textureReference.getLoadFraction(), useRect.height));
                GUIX.endOpacity();

                return(useRect);
            }
        }
示例#3
0
    public void OnGUI()
    {
        if (!VuforiaBehaviour.Instance.enabled)
        {
            return;
        }

        if (exp == null)
        {
            return;
        }

        Reference <Texture2D> img, overlay, outline;

        img     = exp.getImg();
        overlay = exp.getOverlay();
        outline = exp.getOutline();

        if (!img.isLoaded())
        {
            return;
        }

        Texture2D imgTex = img.getResource();

        float scrW = AppRunner.getScreenWidth(), scrH = AppRunner.getScreenHeight(), angle = 0, xOffset = 0, yOffset = 0;
        float s = CrhcConstants.SIZE_VUFORIA_FRAME.getAs(NumberType.PIXELS), p = 30;

        Orientation orientation = AppRunner.getOrientation();

        if (orientation == Orientation.PORTRAIT_DOWN)
        {
            angle   = 180;
            xOffset = -scrW;
            yOffset = -scrH;
        }
        else if (orientation == Orientation.LANDSCAPE_LEFT)
        {
            angle   = 90;
            yOffset = -scrH;
        }
        else if (orientation == Orientation.LANDSCAPE_RIGHT)
        {
            angle   = 270;
            xOffset = -scrW;
        }


        Rect region             = TextureUtility.getUseRect(new Rect(xOffset + scrW - s - p, yOffset + p, s, s), imgTex, AspectType.FIT_IN_REGION);

        if (didMatch)
        {
            frameAlpha += (0 - frameAlpha) / 10;
        }

        alphaAngle += .5f * Time.deltaTime;

        float a = .5f + .5f * Mathf.Sin(alphaAngle);

        Vector2 pivot = Vector2.zero;

        GUIX.beginRotate(pivot, angle);

        GUIX.beginOpacity(frameAlpha);

        if (img != null)
        {
            if (img.isLoaded())
            {
                GUIX.beginColor(Color.white);
                GUIX.drawTexture(region, img.getResource());
                GUIX.endColor();
            }
        }

        GUIX.beginOpacity(a);

        GUIX.beginOpacity(.75f);
        GUIX.fillRect(region, Color.black);
        GUIX.endOpacity();

        if (outline != null)
        {
            if (outline.isLoaded())
            {
                GUIX.beginColor(Color.white);
                GUIX.drawTexture(region, outline.getResource());
                GUIX.endColor();
            }
        }
        GUIX.endOpacity();

        GUIX.beginOpacity(1 - a);
        if (overlay != null)
        {
            if (overlay.isLoaded())
            {
                Texture2D tex = overlay.getResource();
                GUIX.drawTexture(region, tex);

                if (overlayPlane != null)
                {
                    MeshRenderer renderer = overlayPlane.GetComponent <MeshRenderer>();
                    renderer.material.shader      = shader;
                    renderer.material.mainTexture = tex;

                    float tw = tex.width, th = tex.height, f = tw / th, nf = th / tw;
                    float ss = .1f;
                    float xv = -ss, yv = ss, zv = -ss;

                    zv *= nf;

                    overlayPlane.transform.localScale = new Vector3(xv, yv, zv);
                }
            }
        }
        GUIX.endOpacity();

        GUIStyle style = new GUIStyle();

        GUIX.strokeRect(region, Color.white, 3);
        GUIX.endOpacity();

        if (!isMatching)
        {
            //TODO: Draw on screen too.
            GUIX.beginColor(Color.white);
            TextureUtility.drawTexture(new Rect(xOffset, yOffset, scrW, scrH), outline, AspectType.FIT_IN_REGION);
            GUIX.endColor();
        }

        if (debugMessage != null && debugMessage != "")
        {
            float x, y, w, h;
            w = scrW;
            h = 20;
            x = xOffset;
            y = yOffset + scrH - h;

            GUIX.fillRect(new Rect(x, y, w, h), Color.black);
            GUI.Label(new Rect(x, y, w, h), debugMessage);
        }

        GUIX.endRotate();
    }
示例#4
0
    public override bool draw(float w)
    {
        // Create player.

        float padding = CrhcConstants.PADDING_H.getAs(NumberType.PIXELS);

        w -= 2 * padding;
        float h = getPixelHeight(w);

        Rect region = new Rect(0, 0, w, h), paddingRegion = new Rect(padding, 0, w, h);

        GUIX.beginClip(paddingRegion);

        if (hasWaveformTexture)
        {
            GUIX.drawTexture(region, waveformTexture);

            ITouch iTouch = ServiceLocator.getITouch();
            if (GUIX.isTouchInsideRect(region))
            {
                if (iTouch.checkTap())
                {
                    onClick();
                    togglePlayPause();
                }
                else if (!wasHeld && iTouch.isHeld())
                {
                    if (!isScrubbing)
                    {
                        onClick();
                        isScrubbing = true;
                        pause();
                    }
                }
            }
            wasHeld = iTouch.isHeld();

            if (iTouch.isDown())
            {
                if (isScrubbing)
                {
                    float len = audioClip.getResource().length;

                    audioSource.time = Math.Max(0, Math.Min(len * (iTouch.getTouchPosition().x - padding) / w, len));
                    iTouch.clearDragVector();
                }
            }
            else
            {
                if (isScrubbing)
                {
                    isScrubbing = false;
                    play();
                }
            }

            if (!audioSource.isPlaying && playState == PlayState.PLAYING)
            {
                stop();
            }

            if (playState != PlayState.STOPPED)
            {
                Color color = (playState == PlayState.PLAYING) ? CrhcConstants.COLOR_RED : CrhcConstants.COLOR_BLUE_DARK;
                float frac = audioSource.time / audioSource.clip.length, bx = w * frac, bw = 5;
                GUIX.fillRect(new Rect(bx - bw / 2, 0, bw, h), color);
            }

            drawTouchRing(region);
        }
        else
        {
            if (audioClip.isLoaded() && waveformTexture == null)
            {
                AudioClip_onLoad();
            }

            GUIX.strokeRect(region, CrhcConstants.COLOR_GRAY_DARK, 1);
            GUIX.fillRect(new Rect(0, 0, w * progress, h), CrhcConstants.COLOR_GRAY_DARK);
        }

        GUIX.endClip();

        return(false);
    }