Example #1
0
        public static Rect drawTexture(Rect drawRect, Texture2D texture, AspectType aspectType)
        {
            Rect useRect = getUseRect(drawRect, texture, aspectType);

            if (texture != null)
            {
                GUIX.drawTexture(useRect, texture);
            }

            return((aspectType == AspectType.CROP_IN_REGION) ? drawRect : useRect);
        }
Example #2
0
        public override bool draw(float w, float h)
        {
            bool output = base.draw(w, h);

            if (tex.isLoaded())
            {
                GUIX.beginColor(Color.white);
                GUIX.drawTexture(new Rect(0, 0, w / 4, w / 4), tex.getResource());
                GUIX.endColor();
            }

            return(output);
        }
Example #3
0
    public void draw()
    {
        if (!CrhcSettings.showAnimations || number.isDone())
        {
            return;
        }

        number.update();

        float f = number.get(), s = CrhcConstants.SIZE_TOUCH_RING.getAs(general.number.NumberType.PIXELS) * f, b = 10000;

        GUIX.beginOpacity(1 - f);
        GUIX.drawTexture(new Rect(x - s / 2, y - s / 2, s, s), tex.getResource());
        GUIX.endOpacity();
        GUIX.beginOpacity(f * (1 - f));
        GUIX.fillRect(new Rect(-b / 2, -b / 2, b, b), Color.white);
        GUIX.endOpacity();
    }
Example #4
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();
    }
Example #5
0
        public static Rect drawTexture(Rect drawRect, Texture2D texture, AspectType aspectType, float angle)
        {
            angle %= 360;

            if (angle == 0)
            {
                return(drawTexture(drawRect, texture, aspectType));
            }
            else
            {
                angle = 360 - angle;

                int w  = texture.width,
                    h  = texture.height,
                    s  = (int)(Math.Sqrt(w * w + h * h)),
                    sf = Math.Max(w, h);

                Texture2D targetTexture;
                Rect      useRect = getUseRect(drawRect, texture, aspectType);

                if (targetTextures.ContainsKey(texture))
                {
                    targetTexture = targetTextures[texture];

                    float pad = (s - sf) / 2f;
                    float xO = pad, yO = pad, f = (1f * sf) / s, xF = f / X_COUNT, yF = f / Y_COUNT;

                    if (angle > 270)
                    {
                        angle = angle - 360;
                    }
                    else if (angle > 90)
                    {
                        xF   *= -1;
                        angle = 180 - angle;
                    }

                    if (xF < 0)
                    {
                        xO += sf;
                    }

                    int i = angleToIndex(angle);
                    int xamt, yamt;
                    xamt = i % X_COUNT;
                    yamt = (i - xamt) / X_COUNT;

                    xO += xamt * s;
                    yO += yamt * s;

                    float x0, y0;
                    x0 = xO / (s * X_COUNT);
                    y0 = yO / (s * Y_COUNT);

                    Rect coords;
                    coords = new Rect(x0, y0, xF, yF);

                    GUIX.drawTexture(useRect, targetTexture, coords);
                }
                else
                {
                    RenderTexture rotateTexture = new RenderTexture(s * X_COUNT, s * Y_COUNT, 0);
                    targetTextures[texture] = targetTexture = new Texture2D(s * X_COUNT, s * Y_COUNT);

                    RenderTexture.active = rotateTexture;

                    GL.Clear(true, true, CrhcConstants.COLOR_TRANSPARENT);

                    GUIX.undoAllActions();

                    GL.PushMatrix();
                    GL.LoadOrtho();
                    GL.LoadPixelMatrix(0, s * X_COUNT, s * Y_COUNT, 0);

                    for (int y = 0; y < Y_COUNT; y++)
                    {
                        for (int x = 0; x < X_COUNT; x++)
                        {
                            Rect rect = new Rect(new Vector2(-sf / 2, -sf / 2), new Vector2(sf, sf));

                            float ang = indexToAngle(y * X_COUNT + x);

                            GL.PushMatrix();
                            GL.MultMatrix(Matrix4x4.TRS(new Vector3(s * x + s / 2, s * y + s / 2, 0), Quaternion.Euler(0, 0, ang), Vector3.one));
                            Graphics.DrawTexture(rect, texture);
                            GL.PopMatrix();
                        }
                    }

                    GL.PopMatrix();

                    targetTexture.ReadPixels(new Rect(0, 0, s * X_COUNT, s * Y_COUNT), 0, 0);
                    targetTexture.Apply();
                    GUIX.redoAllActions();

                    RenderTexture.active = null;

                    rotateTexture.Release();
                    GameObject.Destroy(rotateTexture);
                }

                return(useRect);
            }
        }
Example #6
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);
    }