Jump to content
  • Advertisement
Sign in to follow this  
dev578

Drawing boxes over a bitmap

This topic is 4763 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am working on my Font Creator application using C++ and the Win32 API. The program can load a bitmap onto the main window. This bitmap is going to have all the characters on it. Eventually, I am going to write my own .font file format, containing the length, width, and pixels of each character in the font. What I am trying to do now is when the user clicks on the bitmap, drags, and releases the mouse, I want to draw a blue box with a top left of where the mouse was pressed down, and a bottom right of where the mouse was released. I want it to actually be re-drawn as the mouse is dragged. I know it has to be somehow done on the WM_LBUTTONDOWN, WM_LBUTTONUP, and probably WM_MOUSEMOVE. I am planning on using the Rectange() function? The problem is that inside the rectangle clears to white, and the bitmap needs to show. What I can think of is maybe storing the pixels from the bitmap, and keep redrawing it while the rectangle is being dragged. This seems like it would lagg the crap out of the computer though. Any ideas? Thank you, -Dev578 [Edited by - dev578 on October 8, 2005 7:08:42 PM]

Share this post


Link to post
Share on other sites
Advertisement
In order to get the mouse coords under Win32, when one of the mouse messages takes place do:

GetCursorPos(&Pnt);
ScreenToClient(hWnd,&Pnt);

Where Pnt is a Point type and hWnd is a HWND type.

As for the GDI stuff I really don't know how you'd do all that. For my app I'm just using SetPixel to draw 256x256 images. I would suggest if you're doing a lot of rendering to use SDL, OpenGL, D3D, etc.. as GDI is way to slow for must things.

Share this post


Link to post
Share on other sites
I know how to get the mousecoords. They are stored in the lParam parameter when the WM_LBUTTONDOWN or WM_LBUTTONUP messages occur. This can get me my coordinates for the rectangle. What I am still trying to figure out though, is how to make the rectangle over the bitmap. I also think it would be nice to actually show the rectangle being drawn as the user is dragging the mouse. Any help would be appreciated.

Thank you,



-Dev578

Share this post


Link to post
Share on other sites
Well if you just drew it to the window then when the bitmap gets updated it'll draw over the rectangle. What you would need to do is store the rectangle information and then when WM_PAINT is called, redraw the window then the bitmap and redraw the rectangle last.

Share this post


Link to post
Share on other sites
I know how to handle WM_PAINT. If I were to draw the rectangle after I draw the bitmap, like you say, the same problem is still there. All the tutorials I have been able to find draw shapes by using a pen for a border, and then using a brush to fill in the area enclosed by the pen. If you just use a pen to create the outline of a rectangle, the area enclosed by the pen is white. I need that white area to be filled with the pixels of the bitmap that got drawn over. I want to do much like the windows desktop, when you click and drag that box comes up. In the middle of the box is the desktop, and icons, etc, NOT SOLID WHITE SPACE. The windows desktop is playing the role of my loaded bitmap. Am I being clear in explaining my situation? If anyone could help me, that would be excellent. In the meantime, I will continue to search, but I'm not finding any answers. Any help is appreciated.

Thank you,



-Dev578

Share this post


Link to post
Share on other sites
It's very possible. During the WM_LBUTTONDOWN message Redraw the bitmap to the new position dragged to or be dragged to. Invalidate the previous bitmap position by calling InvalidateRect, immediately followed by UpdateWindow because WM_PAINT is a low priority message, and then draw the rectangle to the Invalidated part during WM_PAINT.

[Edited by - xeddiex on October 8, 2005 5:59:04 PM]

Share this post


Link to post
Share on other sites
When you call Rectangle the interior of the rectangle is painted using the current brush. You can use GetStockObject(NULL_BRUSH) to get a brush that doesn't do anything. Select this brush into your dc and the interior won't be painted.

Or you can just use the much simpler method of MoveToEx / LineTo to manually draw the rectangle yourself.

I'd never heard of FrameRet but it doesn't quite sound like what you want. It sounds like it draws the rectangle frame using a brush instead of the current pen.

Share this post


Link to post
Share on other sites
Quote:
Original post by Scet
For my app I'm just using SetPixel to draw 256x256 images.


You need to look at the function BitBlt. Calling SetPixel is a terrible way to render a bitmap.

Share this post


Link to post
Share on other sites
Thank you all very much:) I appreciate it. Mike, that was extremely helpful, Rating++.

[Edited by - dev578 on October 9, 2005 7:09:00 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!