bogerchan / Nier-Visualizer

A lightweight and efficient Android visual library.
Apache License 2.0
576 stars 75 forks source link

How to set gradient ColumnarType1Renderer in custom renderer? #46

Closed khiemdnt closed 2 years ago

khiemdnt commented 2 years ago

Hi I doing custom ColumnarType1Renderer implement IRenderer. I want to set LinearGradient but i don't know position x0, y0, x1, y1 of wave ColumnarType1Renderer. mPaint.shader = LinearGradient( 0f, 0f, 0f, 0f, Color.parseColor("#FF7050"), Color.parseColor("#B42F8F"), Shader.TileMode.MIRROR ) So. I want to know position to set gradient wave music ColumnarType1Renderer. Please , help me Tks so much

bogerchan commented 2 years ago

Hi, @khiemdnt , I think you can try to set it according to mLastDrawArea field, please refer to the draw codes:

override fun render(canvas: Canvas) {
        canvas.save()
        canvas.translate(mLastDrawArea.left.toFloat(), (mLastDrawArea.top + mLastDrawArea.bottom) / 2F)
        mRenderColumns.forEach {
            canvas.drawRoundRect(it, mRadius, mRadius, mPaint)
        }
        canvas.restore()
    }
khiemdnt commented 2 years ago

@bogerchan tks. I found solution and set width = canvas.width.toFloat() override fun render(canvas: Canvas) { canvas.save() mPaint.shader = LinearGradient( 0f, 0f, canvas.width.toFloat(), 0f, Color.parseColor("#FF7050"), Color.parseColor("#B42F8F"), Shader.TileMode.MIRROR ) canvas.translate( mLastDrawArea.left.toFloat(), (mLastDrawArea.top + mLastDrawArea.bottom) / 2F ) mRenderColumns.forEach { canvas.drawRoundRect(it, mRadius, mRadius, mPaint) } canvas.restore() }