Fzammetti wrote:
Ok, here's how it's done. I havn't compiled this code so it might not work but atleast it'll give you the general idea of how it should be done and you can start from there.
The BlitStretch() functions stretches the image data found in the source rectangle so that it fits in the destination rectangle. So, for instance, if you do something like this:
What you wanted was a zoom effect. Imagine using PhotoShop (or some other graphical tool) and you select the zoom. You have to point somewhere on the image to zoom, and that point will be the new center of the view. You have to do the same thing if you want to zoom with PF. You need to find your zooming center.
So, first of all. You want to set the destination rectangle. Say you want to zoom in on the center of your image and display it at the upper left corner of the screen. Here's how you can do.
What did we do here? Well, we knew we wanted to zoom the image a factor of two. And we wanted to zoom toward the center of the image. So, we constructed a destination rectangle with the same size as the image, and a source rectangle with half it's size. That way, every pixel in the source rectangle will be stretched to twice it's size and this is the zoom effect. To center the zoom, we just removed/added halv the size of the zoom rectangle to the zooming point. I could have written
Anyways.. This is sort of the way to do it, but as I mentioned earlier, I havn't compiled and tested the code, so you might have some initial problems setting it up. For instance, the center of the zoom might be off by a pixel. As far as I can initially see, and please correct me if I'm wrong here, the source and destination rectangles should be from the beginning of the first, upper left, pixel down to one row below and one column beyond the last, lower right, pixel, in order to blit the whole image.
What the #ยค%# did he just say?!? Well, look at the Blit demo for instance. The fps numbers are a bitmap of 10 numbers with the size x=8, y=11. And the Blit source rectangle is Rect(num*8,0,(num+1)*8,11). So, to make it easy, the first number rectangle reaches from the upper left pixel (0,0) to one more than the lower right (7+1,10+1).
Also, you can't center a pixel of even size (=2*n pixels where n is a positive integer) to a single pixel and depending on the purpose of this zoom effect, this also must be considered.
Hope this will help you out.
In my mind, when I think of a stretch, I'm thinking of what amounts to a distortion effect... if I stretch an image horizontally right, the image's area would expand but only to the right... when I think of a scaling though, I'm thinking zoom actually, as in a magnification of the image that takes up the same screen area (or alternatively is expanded, which could mean a stretch).
Let me ask this of you and anyone else: is there an example of the stretch function I could see? It is possible what I'm thinking of is already there in the stretch function and I just don't realize it.
Ok, here's how it's done. I havn't compiled this code so it might not work but atleast it'll give you the general idea of how it should be done and you can start from there.
The BlitStretch() functions stretches the image data found in the source rectangle so that it fits in the destination rectangle. So, for instance, if you do something like this:
- Code:
Surface* image = LoadImage(display,"filename");
display->BlitStretch(&Rect;(0,0,64,32),image);
What you wanted was a zoom effect. Imagine using PhotoShop (or some other graphical tool) and you select the zoom. You have to point somewhere on the image to zoom, and that point will be the new center of the view. You have to do the same thing if you want to zoom with PF. You need to find your zooming center.
So, first of all. You want to set the destination rectangle. Say you want to zoom in on the center of your image and display it at the upper left corner of the screen. Here's how you can do.
- Code:
Rect destRect = Rect(0,0,image->GetWidth(), image->GetHeight);
- Code:
int imageWidth = image->GetWidth();
int imageHeight = image->GetHeight();
Rect sourceRect = Rect(imageWidth/4, imageHeight/4, imageWidth*3/4, imageHeight*3/4);
What did we do here? Well, we knew we wanted to zoom the image a factor of two. And we wanted to zoom toward the center of the image. So, we constructed a destination rectangle with the same size as the image, and a source rectangle with half it's size. That way, every pixel in the source rectangle will be stretched to twice it's size and this is the zoom effect. To center the zoom, we just removed/added halv the size of the zoom rectangle to the zooming point. I could have written
- Code:
Rect sourceRect = Rect(zoomX-imageWidth/4, zoomY-imageHeight/4, zoomX+imageWidth/4, zoomY+imageHeight/4)
Anyways.. This is sort of the way to do it, but as I mentioned earlier, I havn't compiled and tested the code, so you might have some initial problems setting it up. For instance, the center of the zoom might be off by a pixel. As far as I can initially see, and please correct me if I'm wrong here, the source and destination rectangles should be from the beginning of the first, upper left, pixel down to one row below and one column beyond the last, lower right, pixel, in order to blit the whole image.
What the #ยค%# did he just say?!? Well, look at the Blit demo for instance. The fps numbers are a bitmap of 10 numbers with the size x=8, y=11. And the Blit source rectangle is Rect(num*8,0,(num+1)*8,11). So, to make it easy, the first number rectangle reaches from the upper left pixel (0,0) to one more than the lower right (7+1,10+1).
Also, you can't center a pixel of even size (=2*n pixels where n is a positive integer) to a single pixel and depending on the purpose of this zoom effect, this also must be considered.
Hope this will help you out.