As I continue to extend my PngSkin example, I find that I need to do some things that I am not able to do with the current code, and I'm wondering how I could implement this.

This is the problem:
With the new LayeredTextbox control almost complete, I'd like to be able to restrict (text) drawing to a certain area of the bitmap. Otherwise the text will overlap the borders of the control's skin, which looks ugly (see bitmap below). The first thing that comes to mind is to create a separate bitmap for text drawing, and then aply a mask to it before CompositeBlend'ing it onto the control's main bitmap.

Does anybody have any ideas on a fast way to implement the masking method, or maybe somebody knows a better way? It seems like a waste to have a separate buffer for text drawing.
Posted on 2002-12-23 06:05:01 by Qweerdy
Hi Qweerdy

I have not had a close look to your code, is the bitmap selected into a DC. If so you can use CreateRectRgn and select the region inro the DC before drawing the text.

Posted on 2002-12-23 06:37:42 by KetilO

I'm sorry but that wouldn't work as I'm drawing directly to the bitmap memory. Also I'd like to be able to specify the full 255 levels of transparency, since that would make it much more versatile. Thanks for the input though :)
Posted on 2002-12-23 06:45:34 by Qweerdy
Hi Qweerdy

Still asking stupid questions.
Are you drawing the text by setting individual pixels at x, y?
If so creating region handling shoud be fairly simple.

Posted on 2002-12-23 06:57:07 by KetilO
Do you mean implementing region handling myself or using windows' region handling? Because the latter is impossible, as I already said. I don't use SetPixel but instead draw to the bitmap's binary data myself. Setting a region doesn't affect this.

As for implementing region handling by myself, I don't think this would be any faster than the method I proposed, and would make the general object structure and the PaintText proc needlessly complicated.

So, no prize this time :( But all input is welcome, even "stupid" questions :alright:
Posted on 2002-12-23 11:09:50 by Qweerdy
Afternoon, Qweerdy.

When drawing the text, why not just compare where you're drawing to the controls client area?

Posted on 2002-12-23 17:12:21 by Scronty
I think KetilO has a point, even if drawing to the bitmap yourself, it'd still be easy (enough) to figure out the x&y coords of the pixels you're plotting, then the PtInRegion function could tell you weither or not the plot the point. :confused:
Posted on 2002-12-23 19:50:11 by Eóin

If you look at the picture I posted you will see the problem :) The texbox border and text are both in the client area of the control, so they can overlap.


Ok, I can agree with that. But I refuse to believe that this would be any faster than masking the buffer later, especially with complex (rounded) regions. In fact I don't even think it would take up less memory.
Posted on 2002-12-24 05:36:59 by Qweerdy
Nevermind, I have finished an acceptable masking system. Now I just need to polish everything a bit more, make the code more modular, and I'll release the next PNGskin version.

Thanks all!
Posted on 2002-12-26 11:55:57 by Qweerdy