Sign in to follow this  
glassman2005

C++ Guage - Copying "stacked" layers?

Recommended Posts

Is there any way to capture a region of a gauge that consists of many layers drawn with MAKE_MOVING, MAKE_STRING, MAKE_STATIC, etc, so that the captured area can be copied (BitBlt?) into a separate drawing surface?I have tried adding a transparent static layer just "below" my drawing surface and tried to copy from that hdc into my drawing surface hdc, but that approach didn't seem to yield any image.Any ideas?

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

It certainly can be done with the help of a layer which has IMAGE_CREATE_DIBSECTION and IMAGE_USE_BRIGHT properties. But what I don't understand is, why you want to do that. Perhaps there's a more decent way to achieve what you want.

Share this post


Link to post
Share on other sites

I want this because I have a working gauge that uses the macros to draw about 8 layers, but then I need to add some GDI+ functions to draw additional text on the gauge. The problem is that when you add a drawing surface to use GDI+ functions upon, you cannot use the transparency flag, so I get a big ugly black box where my drawing surface is, even though the surface's BMP color is RGB(0,0,0). So.....in order to simulate transparency, I want to capture what has been drawn "so far" by the macros during each cycle, copy it to the drawing surface, and then draw GDI+ stuff on top of that. In other words, I don't have enough knowledge to draw by myself all the work that the macros are already doing for me, and it seems like such a waste to have to scrap everything I've done and convert the entire gauge to GDI+ simply to add the text I want to add.The problem that started all this is twofold: 1) the MAKE_STRING macro doesn't seem to allow me to use a variable for the y-coordinate, so I can't "reposition" the text in each frame based on internal logic in the gauge, and 2) the MAKE_STRING macro draws text rather ugly, using equidistant spacing between characters, not the font's natural spacing.See Example: forums.avsim.net/user_files/134419.jpg

Share this post


Link to post
Share on other sites

I'd suggest that you go the GDI+ way in this case even if the work you already put into it is wasted then. The reason is this: the more stuff you put into that gauge, the more problems will come up. I can't think of a way to make this bitblt thing work because you would need to intercept FS' drawing cycle like this: draw element 1 to n, grab what's been drawn until then, blit it on element n + 1, draw element n + 1. Even if you get it to work I doubt that it'll be less work than to redo the whole thing with GDI+.

Share this post


Link to post
Share on other sites

Yikes! Ok, *sigh*..........where does one go to begin learning to draw, or more particularly, rotate (transform) and mask (hide sections) using GDI+ within an FS gauge? Are books on GDI+ sufficient? Or does the FS environment have further issues that would not be covered in "normal" GDI+ texts? The concepts are familiar....I use tools to do this all this time as part of my work, and a *long* time ago I programmed some transformation matrix stuff for very simple line drawings (but not in C++). I know in the end the gauge will come out better for it, but I don't even know where to begin learning this.

Share this post


Link to post
Share on other sites

While I tend to agree with Hans that - in the long run - your gauge would be better off with pure GDI+ drawn elements, for your simple purposes there may well be a way to fix your current situation.You use a 'mask element' for your sprite element, so it wouldn't be that difficult to cut 'transparent windows' in the mask where you want to "see" the GDI+ text elements from the lowest layer...

Share this post


Link to post
Share on other sites

Very interesting, I have to think through that one. Essentially, I'd have to "see through" several layers of sprites and statics all the way down to the drawing surface, and since the position of the text I need to draw is always moving, that means the position of the mask must move too, and I've had no luck getting the mask x,y position to respond to variables. It seems to only recognize the initial value of the variable from its declaration, not to any adjustments that are made to the variables during PANEL_SERVICE_PRE_DRAW in the callback.Is it possible that there is a more appropriate place to change variable values other than PANEL_SERVICE_PRE_DRAW so that when the macros execute, they actually see the updated value? The variables are global in scope, so I thought it wouldn't matter, but maybe I'm not be understanding the lifespan of variables between the callback function and when the macros execute.But if I do go the full GDI+ route (which I've already started experimenting with), I wanted to try to re-use some of the bitmaps I've already drawn and included as resources in the file. Should this code snipped work? It doesn't for me, but not sure why:HICON hIcon = LoadIcon(NULL, MAKEINTRESOURCE(ONE_OF_MY_BITMAPS));Bitmap bitmap(hIcon);graphics.DrawImage(&bitmap,0,0);However, if I use IDI_APPLICTION for the resource ID, it does indeed draw the application icon onto the drawing surface. Am I missing something? The resource ID signified by ONE_OF_MY_BITMAPS is defined in the header, and is properly loaded in the RC. Shouldn't I be able to get to my own resources?

Share this post


Link to post
Share on other sites

The "mask" has a fixed x,y position that defines the top left corner of the bitmap's location with respect to the base background. Being able to "move" a mask would defeat the purpose... ;)As to the other questions you've asked, that's way above my paygrade... I simply don't know enough to even sound intelligent! *:-* To answer a previous question regarding resources, I've found the book "Graphics Programming in GDI+" by Mahesh Chand to be quite informative and helpful. It is part of the MS .NET Development Series.

Share this post


Link to post
Share on other sites

The moving mask, in my real life world of special effects, is sometimes known as a "Travelling Matte", and is used for blocking off unwanted sections of the frame that contains lights, cameras, etc, even as the object moves inside the frame, leaving only your object and the green screen visible. I guess I'm trying to mix worlds too much!

Share this post


Link to post
Share on other sites

>But now a new question -- how do you define the center of>rotation during graphics.RotateTransform? gfx.TranslateTransform (200, cy); gfx.RotateTransform ((float)(- acfthdg + i));The center point is set by TranslateTransform (x,y);

Share this post


Link to post
Share on other sites

Thanks so much, mission accomplished. (at least this part of the mission!)(The little opening to see thru to the bottom drawing layer works beautifully)

Share this post


Link to post
Share on other sites

>>Thanks so much, mission accomplished. (at least this part of>the mission!)>>(The little opening to see thru to the bottom drawing layer>works beautifully)I'm delighted to hear that. I've used that technique myself in the past, but as you noted it's only effective for "windows" that remain static - that is, the underlying elements don't move... ;)

Share this post


Link to post
Share on other sites

Ended up converting most of the gauge to GDI+ afterall, someone previously suggested that might be easier than tackling some issues, but now, it turns out better all around this way.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this