Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Transforming a drawn region with drawTexturedPath

Yes, some images would be helpful. Put them on some site or add to your image gallery before posting here - otherwise it might take a day or two before I can see them (strange "feature" of this forum). Image attachments also work.

 

Unfortunately I don't have enough time to study your code, so I have to resort to looking at the results and guessing...

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Transforming a drawn region with drawTexturedPath

No problem, I know well enough about the "feature".
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Transforming a drawn region with drawTexturedPath

Images uploaded, just waiting for approval.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Transforming a drawn region with drawTexturedPath

[ Edited ]

Ok, the images were approved.

 

The examples I use are simple translation though scale and rotation are also supported.

 

Baseline (if you look at the paint function)-What happens if no PDF is open:

NoPdf.png

 

Open PDF, no transformation:

PdfNoTranslation.png

 

What I want (expect) to happen when I transform the PDF:

PdfDesiredTranslation.png

 

What actually happens:

PdfTranslation.png

 

Simple side-by-side comparison of what I want to get (left/top) and what I get (right/bottom):

PdfDesiredTranslation.pngPdfTranslation.png

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Transforming a drawn region with drawTexturedPath

Oh - it looks like you don't need to change dux, duy, dvx, dvy - rather you should adjust your xPts and yPts. The values there can be negative or bigger than the clipping region, so don't be afraid to shift them where you want them to be.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Transforming a drawn region with drawTexturedPath

That's the exact issue, that is what I do. But it doesn't work. The screen shots (with the exception of the "what I want" screen shot) is from the app itself.

 

Here is the draw function so you don't need to search through the code:

protected void paint(Graphics graphics)
{
	int pcolor = graphics.getColor();
	int palpha = graphics.getGlobalAlpha();
	
	XYRect extent = this.getExtent();
	if(super.gestureProcessing) //Simple way to check if a PDF is in use
	{
		//Clear the background
		graphics.setColor(Color.GRAY);
		graphics.fillRect(0, 0, extent.width, extent.height);
		
		//Create the path
		int[] xPts = new int[]{0, 0, this.curRenderWidth, this.curRenderWidth};
		int[] yPts = new int[]{0, this.curRenderHeight, this.curRenderHeight, 0};
		
		//Transform points
		VecMath.transformPoints(mat, DRAWING_MATRIX, xPts, yPts, xPts, yPts);
		
		//Draw "shadow"
		graphics.setColor(Color.BLACK);
		graphics.setGlobalAlpha(75);
		graphics.translate(SHADOW_OFFSET, SHADOW_OFFSET); //Offset the shadow a bit
		graphics.drawFilledPath(xPts, yPts, null, null);
		graphics.translate(-SHADOW_OFFSET, -SHADOW_OFFSET);
		graphics.setGlobalAlpha(255);
		
		//Get UV points for texture
		int widthScale = Fixed32.div(Fixed32.toFP(this.curRenderWidth), Fixed32.toFP(extent.width));
		int heightScale = Fixed32.div(Fixed32.toFP(this.curRenderHeight), Fixed32.toFP(extent.height));
		int dux = Fixed32.div(this.mat[DRAWING_MATRIX], widthScale);
		int dvx = Fixed32.div(this.mat[DRAWING_MATRIX + 1], widthScale);
		int duy = Fixed32.div(this.mat[DRAWING_MATRIX + 3], heightScale);
		int dvy = Fixed32.div(this.mat[DRAWING_MATRIX + 4], heightScale);
		
		//Draw
		graphics.drawTexturedPath(xPts, yPts, null, null, 0, 0, dux, dvx, duy, dvy, this.drawnPage);
	}
	else
	{
		//No PDF to draw
		String text = "No page selected";
		
		graphics.setColor(Color.BLACK);
		graphics.drawText(text, 0, (extent.height >> 1) - (graphics.getFont().getHeight() >> 1), Graphics.HCENTER, extent.width);
	}
	
	graphics.setGlobalAlpha(palpha);
	graphics.setColor(pcolor);
}

 

curRenderWidth/Height is the size of the image to be displayed.

mat is the transformation matrix that moves xPts and yPts around.

 

Unfortunetly, as shown in the screen shots, it isn't working.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Transforming a drawn region with drawTexturedPath

You think that would be a bug? Or a "feature"?
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Transforming a drawn region with drawTexturedPath

You know - I never checked where the (0, 0) Bitmap's point is projected by drawTexturedPath. It might not be (xPts[0], yPts[0]) at all! (Your experience suggests that it's (0,0)).

 

Could you try the following workaround:

1. drawTexturedPath into an intermediate Bitmap with transformed but not shifted xPts and yPts (xPts[0] = 0 and yPts[0] = 0). (Look at Graphics.create for that)

2. drawBitmap onto the screen with the appropriate x and y parameters.

 

There will be some efficiency hit, but not much. And hey - without functionality, efficiency doesn't matter, does it?

 

Good luck!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Highlighted
Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Transforming a drawn region with drawTexturedPath

I was starting to wonder that myself. I never did get around to testing it and just assumed that the Bitmap's origin would be drawn at xPts[0], yPts[0]. I modified my code so the Bitmap origin is xPts[0], yPts[0]. Testing now.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 1,806
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Transforming a drawn region with drawTexturedPath

That did the trick, works perfectly now. Just replace:

graphics.drawTexturedPath(xPts, yPts, null, null, 0, 0, dux, dvx, duy, dvy, this.drawnPage);

 With:

graphics.drawTexturedPath(xPts, yPts, null, null, xPts[0], yPts[0], dux, dvx, duy, dvy, this.drawnPage);

 And transformation will work just fine. The issue, I realized after douple-checking the API docs is the wording:

"X/Y component of the texture origin in local screen coordinates." Since dux, duy, dvx, dvy are transformation matrix values (that dictate how the Bitmap should be drawn on screen), I assumed that xOrigin/yOrigin where the "duz, dvz" values (sticking with the pattern) of the matrix. Not the actual origin point on the screen that the Bitmap is being drawn on (making it more like your standard x/y parameters used in something like drawBitmap than the left/top parameters).

 

Thanks for the help.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.