PocketMatrix forums

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

BtlFast TINT

Can you tell how to use flags in BltFast:
EFX_TINT //Blit with a colored tint, pass the desired color as a parameter
EFX_ALPHA //Pixel blending: Add color channels of each pixel

Is EFX_ALPHA deprecated (as I fond in one .h) and for what I can use it?

What EFX_TINT do with Surface? And can you tell me the format of DWORD property for it ?
Hi Villy,

Here are some examples of blitting with several effects. Please check the comments on what it does:

Code:

//Blit with a colorkey previously set with the SetColorKey function
buffer->BltFast(0, 0, &source;, ▭, EFX_COLORKEY, 0);

//Blit with 50% opacity
buffer->BltFast(0, 0, &source;, ▭, EFX_OPACITY, 128);

//Blit with colorkey and additive alpha
buffer->BltFast(0, 0, &source;, ▭, EFX_COLORKEY | EFX_ADD);

//Blit with (red) colorization effect
buffer->BltFast(0, 0, &source;, ▭, EFX_COLORIZE, E_RGBX(255, 0, 0));

//Blit with (blue) tint and 75% opacity
buffer->BltFast(0, 0, &source;, ▭, EFX_TINT | EFX_OPACITY, E_RGBA(0, 0, 255, 192));


I hope this helps :)
Thanks for help.

Another question.
How can I Blt surface to fill some RECT. I mean something like DestSurface.Blt(DestRect,oSrcSurface,SrcRect); similar to ::StretchBlt in Windows.

Or maybe you suggest another way to do such operation by other functions. But I need exactly the same effect.
Hi Villy,

You can use the EFX_COLORFILL filter to fill with a solid color. It works similar to EFX_TINT and can also be combined with other filters such as opacity.
I need to Stretch image. I don't understand how for this I can use EFX_COLORFILL. Can use give example?
RapchikProgrammer · 18 Nov 2008, 11:24 UTC
ERESULT Blt(long center_x, long center_y, E2DSurface *source, RECT *rc, unsigned short rotation, unsigned long scale, unsigned char flipflags = EFLIP_NONE, long flags = 0, unsigned long property = 0)

center_x, center_y (in)

The position of the destination to blit, the center of the source surface rectangle.

*source (in)

A pointer to a 2D surface to blit from.

*rc (in)

A pointer to a rectangle structure with the shape and position of the rectangle.

rotation (in)

Used to rotate blitting, a value between 0 and 4096 represents a whole circle.

scale (in)

Used for scale blitting. Values bigger than 65536 will enlarge the image, values smaller than 65536 will shrink the image.

flipflags (in)

Extra flags to flip the image.

flags (in)

Extra flags for drawing effects.

property (in)

A property to be used in combination with the flag parameter.


Use the scale parameter.. i think its pretty self explanatory above..
This function can`t Blt to defined RECT. *rc (in) is the rect of source but not the destination.
In this function you can define only center_x and center_y but not out rect.

scale (in) can help to zoom.
But from help (Values bigger than 65536 will enlarge the image, values smaller than 65536 will shrink the image.) I can't understand if scale=80000 is it zoom x2 or maybe x3 ?

I need a clear formula to make the same effect as WinAPI StretchBlt:
MSDN->This function copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. Windows stretches or compresses the bitmap according to the stretching mode set in the destination device context.

BOOL StretchBlt(
HDC hdcDest,
int nXOriginDest,
int nYOriginDest,
int nWidthDest,
int nHeightDest,
HDC hdcSrc,
int nXOriginSrc,
int nYOriginSrc,
int nWidthSrc,
int nHeightSrc,
DWORD dwRop
);
Hi Villy,

You can do scaling with the following formula:
Code:

float scaling = 0.5;
unsigned long bltscale = (unsigned long)(scale * 65536);


In the above sample, it scales the image 50%. If you like to scale 200%, use value 131072 (65536 * 2).

Perhaps it's easier to use FillRect directly?
1) Blt with scale (in) parameter can scale only proportionally. So I can't make a wrapper to emulate real StretchBlt. I need to make not proportional Image scale (example: out image width*=0.5 hight*=10).

2) To process WM_RBUTTONDOWN and WM_RBUTTONUP in windows I need to convert coordinates from windows to native EDGELIB coordinate space. How to do this ?
Hi Villy,

We strongly recommend using FillRect to emulate the stretchblit function. You can use your own formula's without having to mess around with the scale parameter. With FillRect you define the position onscreen in pixel coordinates. Also, using FillRect directly is faster.

Regarding your second question:
Use the input class to fetch the mouse events and coordinates. They should already be in the correct format (with 0,0 being the topleft pixel of the EDGELIB area). It also handles display orientation, when needed. I assume this is what you need?
Do you talk about this FillRect ?
void E2DSurface::FillRect(RECT *rc, COLORREF col, long flags = 0, unsigned long property = 0)

I don't understand how can I stretch Image with it.

For Example:
E2DSurface oSrc;
display->CreateSurface(&oSrc;,"image.bmp");
//image.bmp size: widht=40 height=50

How can I stretch oSrc to display->buffer. I Need to fill all the display->buffer surface with oSrc image (not a solid color).

PS. And can you give some example how to work with ClassEInput. In documentation I can't find any information about this.

Thank you for your help.
Hi Villy,

Ok, forget what I said about FillRect. I thought you wanted to fill a solid rectangle on the screen.

To have scaling options for the x and y axis seperately, you need the BltFx function. It is similar to Blt, but has more parameters. Use the E2DBLTFX structure to specify the parameters.

For ClassEInput documentation refer to the EDGELIB reference at: http://www.edgelib.com/index.php?node=764

In your framework, you can access the input class through ecd. For example, use: ecd.input->GetClickPosition.
Thank's for advice use BltFx. I miss that E2DBLTFX have separate xscale and yscale. Sorry :)

About ClassEInput documentation.
It's not clear from it how to implement OnClickDown (to process Right click) or how to get pressed Char. This functions is not virtual. But even if they are, it's no way to change ecd.input to my new derived class.
I even try to call ecd.input->GetChar() in ClassMain::OnButtonDown callback. But there are no chars.

Please give me advice.
Hi Villy,

The OnXxx callback functions are for internal use, we advise not to use them. The other functions, such as GetClickPressCount and GetChar should be called from OnNextFrame. These work through a poll mechanism.
Thank's.

I already test this mechanism, and it's works :)

But can you tell me if I call ecd.input->GetClickEvent from OnNextFrame and process like this:
Code:

E_INPUTEVENT oIEvent;
while (ecd.input->GetClickEvent(&oIEvent;)){
if(oIEvent.action==EIC_RIGHT){
if (oIEvent.type==EIE_PRESSED){
POINT p;
p.x=oIEvent.clickx;
p.y=oIEvent.clicky;
DebugDown(p,0);
}else
if (oIEvent.type==EIE_RELEASED){
POINT p;
p.x=oIEvent.clickx;
p.y=oIEvent.clicky;
DebugUp(p,0);
}
}
}


Do callbacks virtual void OnStylusUp(POINT pnt); and the others be processed before OnNextFrame or not ?

In manual written that GetClickEvent: When calling this function and an event is found, it will be removed from the event list. so is above code broke something or not ?
Hi Villy,

The event list is emptied after OnNextFrame is called internally. On the start of OnNextFrame it checks windows messages and fills the list with new events.

Using GetClickEvent copies the first event from the internal event list. Then it removes the event from the list. The next call to GetClickEvent will copy the next event from the list.
Thank's for your help.
Now I have a working clone of game with EDGELIB :) (Of course I use my own AlphaBlt from 2 surfaces)

But as you understand BltFx can't 100% make the right emulation of real StretchBlt. In BltFx center_x and center_y are integer, so if I set some scale I can get +-1 pixel moved image. So there it's no guarantee that you get image in proper coordinates.

So please add native analog of StretchBlt to EDGELIB.
Hi Villy,

Please use the following emulation function, it may work even with odd coordinates. Please test if all your cases are handled correctly:

Code:

//Stretch blitter
ERESULT BltStretch(E2DSurface *dest, RECT *dstrc, E2DSurface *source, RECT *srcrc, unsigned char flipflags, long flags, unsigned long property)
{
E2DBLTFX bltfx;
RECT drc, src;
long xdec = 0, ydec = 0;
if (dstrc != NULL)
SetRect(&drc;, dstrc->left, dstrc->top, dstrc->right, dstrc->bottom);
else
SetRect(&drc;, 0, 0, dest->GetWidth(), dest->GetHeight());
if (srcrc != NULL)
SetRect(&src;, srcrc->left, srcrc->top, srcrc->right, srcrc->bottom);
else
SetRect(&src;, 0, 0, source->GetWidth(), source->GetHeight());
if ((src.right - src.left) % 2 == 1)
xdec = 1;
if ((src.bottom - src.top) % 2 == 1)
ydec = 1;
bltfx.xscale = ((drc.right - drc.left) * 65536 + 16383) / (src.right - src.left);
bltfx.yscale = ((drc.bottom - drc.top) * 65536 + 16383) / (src.bottom - src.top);
bltfx.rotation = 0;
bltfx.flipflags = flipflags;
bltfx.flags = flags;
bltfx.property = property;
return(dest->BltFx(drc.left + (drc.right - drc.left + 1) / 2 - xdec, drc.top + (drc.bottom - drc.top + 1) / 2 - ydec, source, &src;, &bltfx;));
}