PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Creating temporary RECTs

I suspect this is a silly question, but still...

When I use PocketFrog, I have the ability of doing something like:

Blit(x, y, image, RECT(10,10,20,20));

So I don't have to create a RECT first, do SetRect on it, and then use it.

Can this be done in GD? I'm constantly doing things like:

RECT rect;
SetRect(▭, 0, 265, 240, 295);
backbuffer.FillRect(▭, RGB(0, 0, 0), NULL, NULL);

Where I don't so much care about the rectangle beyond this one statement, I'd like to be able to take the first two lines and essentially have them in the call to FillRect, like I can do in PF. Is this possible?

Thanks all!
You could make a quick wrapper class,

do something like:

Code:


RECT* myRect(int up,int right,int down, int left)
{
RECT *rcTemp=new RECT;
rcTemp.up= up;
rcTemp.right= right;
rcTemp.down= down;
rcTemp.left= left;
return(*rcTemp);
}


of course your going to have to remember to delete the mem or just have a destructor do it for you.
You _could_ create a method that returns a RECT ptr, ie something like...

Code:

RECT * mRECT(DWORD _l, DWORD _t, DWORD _r, DWORD _b) { RECT * _rect = { _l, _t, _r, _b }; return _rect; }


Then pass this rect ptr to the gapidraw methods like you describe. I've not tried this, but it should work. I'm not sure how clean this method is, as it may leave RECT ptrs in memory.
Ok, so the short answer seems to be no, GD doesn't have such a function.

Johan, I wouldn't mind seeing this added to the next release. It's not an Earth-shattering problem, the solutions offered by DillRye and ppcStudios will work fine I'm sure, but it'd be nice if it was part of GD.
Pejo Software - Per · 08 Jul 2003, 08:00 UTC
I don't think that it is a good idea to use a method/function that generates a RECT and returns a pointer to it as proposed by Dillrey and PPCStudios. Because you then need remember to delete the pointer. Allocating it om the stack and return a pointer to it as I think ppcStudios was proposing will not work since it will be popped directly when the function runs out of scope.
You could however us the following class:
Code:
class CRect : public tagRECT
{
public:
CRect(int l, int t, int r, int b) {left=l;top=t;right=r;bottom=b;}
operator LPRECT(){return this;}
};

And then use the following call:
backbuffer.FillRect(CRect(0, 265, 240, 295), RGB(0, 0, 0), NULL, NULL);

This is how MFC's CRect works so you may take a look at that if you want inspiration.

On the other hand I don't think that it is that much work to allocate the RECT before you call the funtion just as you are doing today....
Yeah it doesn't use too much resources when declaring rects before each blit but integrating it in the blit function will give us cleaner code especially if you're using tons of setrects. :) I guess that's what fzammetti's aiming for.
That's exactly what I was trying to think of PejoSoftware - excellent piece of code. Thanks for the tip!
PejoSoftware: PocketFrog uses a class called "Rect" similar to the one Pejo suggested...

I'll add a new header file to GapiDraw 2.02 with CPoint and CRect classes. I'll just include them in the header file of the updated CGapiApplication so they work everywhere...
Excellent replies guys, and thanks Johan, that will I think make for cleaner code for all of us (which was in fact my goal, I didn't think performance was a problem or anything like that).
Yeh, I suggested a class, but did not write out the class code....
Thats a feature that is coming to C99, and assumbly later in C++. You'll be able to do something like:
Code:

backbuffer.FillRect({0, 265, 240, 295}, RGB(0, 0, 0), NULL, NULL);