Anyone??? Thanks for the help anyways....



On 14 Apr, 17:22, ricardolpd <[email protected]> wrote:
> Hello everyone,
>
> I need to draw some stuff in perspective and i need it to move it
> around as well as moving the perspective effect, i found the nice
> example polytopoly on the google samples, i made some changes to the
> code, and i found out, the following issues:
>
> – When drawing with some perspective point sometimes i will draw the
> rectangles and fill them with all the content in perspective like i
> wanted it to, but if i move this rectangle the content of the
> rectangle will be draw in perspective but i cannot fill the rectangle.
>
> – I found as well that setting the
> paint.style(Paint.Style.FILL_AND_STROKE) it will draw and fill the
> rectangle in some positions but not the others, and if i set the style
> to just fill it wont fill anything.
>
> – Does anyone know what am I doing wrong? or is this some bug in the
> android framework. I don't understand why when i move horizontally my
> boxes one of these boxes stops filling but not the other?
>
> So when i have this peace of code:
>
> canvas.save();
> doDraw(canvas, new float[] { xpos, ypos, xpos+width, ypos, xpos+width,
> ypos+height, xpos, ypos+height},
>         new float[] { xpos, ypos, xpos+width+10, ypos+10, xpos+width+10, ypos
> +height, xpos, ypos+height+20});
> canvas.restore();
>
> that draws a box in perspective i can fill it in any horizontal and
> vertical position, but only with the
> mPaint.setStyle(Paint.Style.FILL_AND_STROKE) if I set it just to FILL
> it will not fill.
>
> if call this piece of code:
>
> doDraw(canvas, new float[] { xpos, ypos, xpos+width, ypos, xpos+width,
> ypos+height, xpos, ypos+height},
>      new float[] { xpos, ypos+15, xpos+width+15, ypos, xpos+width+15,
> ypos+height+25, xpos, ypos+height});
> canvas.restore();
>
> when xpos>120 it will not fill the box, but everything inside is in
> perspective.
>
> Can anyone help me with this please, i really don't understand what
> i'm doing wrong, if there is no way around could anyone give me some
> hints on how to work around this, in a efficient way.
>
> The class code is the bottom of this message:
> Any help would be really appreciated.
>
> Regards
>
> Ricardo
>
> Here it is my class;
>
> /*
>  * Copyright (C) 2007 The Android Open Source Project
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
>  * You may obtain a copy of the License at
>  *
>  *      http://www.apache.org/licenses/LICENSE-2.0
>  *
>  * Unless required by applicable law or agreed to in writing, software
>  * distributed under the License is distributed on an "AS IS" BASIS,
>  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
>  * See the License for the specific language governing permissions and
>  * limitations under the License.
>  */
>
> package com.example.android.apis.graphics;
>
> // Need the following import to get access to the app resources, since
> this
> // class is in a sub-package.
> //import com.example.android.apis.R;
>
> import android.app.Activity;
> import android.content.Context;
> import android.graphics.*;
> import android.os.Bundle;
> import android.view.View;
>
> public class PolyToPoly extends GraphicsActivity {
>
>     @Override
>     protected void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(new SampleView(this));
>     }
>
>     private static class SampleView extends View {
>         private Paint   mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
>         private Matrix  mMatrix = new Matrix();
>         private Paint.FontMetrics mFontMetrics;
>         int xpos=10;
>         int ypos=160;
>         int width=64;
>         int height=64;
>
>         private void doDraw(Canvas canvas, float src[], float dst[]) {
>             canvas.save();
>             mMatrix.setPolyToPoly(src, 0, dst, 0, src.length >> 1);
>             canvas.concat(mMatrix);
>
>             mPaint.setColor(Color.GRAY);
>
>             mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
>
>             Path path=new Path();
>             path.moveTo(xpos, ypos);
>                 path.lineTo(xpos+width, ypos);
>                 path.lineTo(xpos+width, ypos+height);
>                 path.lineTo(xpos, ypos+height);
>             path.close();
>             canvas.drawPath(path, mPaint);
>
>             mPaint.setColor(Color.RED);
>             mPaint.setStyle(Paint.Style.FILL);
>             // how to draw the text center on our square
>             // centering in X is easy... use alignment (and X at
> midpoint)
>             float x = xpos+width/2;
>             // centering in Y, we need to measure ascent/descent first
>             float y = ypos+height/2 - (mFontMetrics.ascent +
> mFontMetrics.descent)/2;
>             canvas.drawText("blabla", x, y, mPaint);
>             canvas.restore();
>         }
>
>         public SampleView(Context context) {
>             super(context);
>
>             // for when the style is STROKE
>             mPaint.setStrokeWidth(4);
>             // for when we draw text
>             mPaint.setTextSize(13);
>             mPaint.setTextAlign(Paint.Align.CENTER);
>             mFontMetrics = mPaint.getFontMetrics();
>         }
>
>         @Override protected void onDraw(Canvas canvas) {
>             Paint paint = mPaint;
>
>             canvas.drawColor(Color.WHITE);
>             canvas.save();
>             doDraw(canvas, new float[] { xpos, ypos, xpos+width, ypos,
> xpos+width, ypos+height, xpos, ypos+height},
>                         new float[] { xpos, ypos, xpos+width+10, ypos+10, xpos
> +width+10, ypos+height, xpos, ypos+height+20});
>               canvas.restore();
> //
>             canvas.save();
>             xpos=150;
>             doDraw(canvas, new float[] { xpos, ypos, xpos+width, ypos,
> xpos+width, ypos+height, xpos, ypos+height},
>                         new float[] { xpos, ypos+15, xpos+width+15, ypos, xpos
> +width+15, ypos+height+25, xpos, ypos+height});
>
>             canvas.restore();
>
>         }
>     }
>
>
>
> }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to