🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

copyin' bitmaps

Published August 31, 2000
Advertisement
I'm a draggin' and droppin' fool here. Got the drag-n-drop stuff working beautifully. It was basically a line-for-line translation of the drag-n-drop code in the older games. Seems to be working nicely, which is a Good Thing, as debugging drag-n-drop is quite difficult (click mouse, breakpoint fires, debug, continue program, drag cancels itself because it sees that you let go of the mouse).



Bitmap-based output devices are a pain. I created this nice little class called OutputDevice (OK, I borrowed the concept from something else and improved on it). It's a nice little wrapper for HDC's, so you can draw to the screen in a relatively platform-neutral way. One of the niceties I added was a derived bitmap output device, so you can draw to a bitmap, which is awfully handy. Only problem is the design of the object. Basically it does the following. . .

Constructor: Copy the bitmap to a draw-able temporary space.

Destructor: Copy the temporary space back to the bitmap.

Problem comes when I need to do stuff with the bitmap. Sometimes the object's not yet destructed. For example. . .



Bitmap B(Size(100, 100));

DrawableFont F;

BitmapOutputDevice OD(B); // make an OutputDevice for the bitmap

F.DrawText(OD, String("This is a test"));

Bitmap C(B); // copy the bitmap









Now, if you think C has the text I just drew to B, you'd be wrong. Since OD has not been destructed, the changes have not yet been drawn to it. You could fix that with something like this. . .



Bitmap B(Size(100, 100));

DrawableFont F;

{

BitmapOutputDevice OD(B); // make an OutputDevice for the bitmap

F.DrawText(OD, String("This is a test"));

}

Bitmap C(B); // copy the bitmap









Now C contains the changes, because OD got destructed and wrote the changes to B. Only problem is that this is ugly and hard to remember to do. An only-slightly-better solution is to add a function (besides the destructor) that copies the stuff back.



Bitmap B(Size(100, 100));

DrawableFont F;

BitmapOutputDevice OD(B); // make an OutputDevice for the bitmap

F.DrawText(OD, String("This is a test"));

OD.Commit(); // copy the bits back to B

Bitmap C(B); // copy the bitmap










Like I said, it's not as ugly, but you've still gotta keep track of it.
Previous Entry anti-money
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement