Sign in to follow this  
Shock

Paint-like Application, Win32 GDI Questions

Recommended Posts

Hey Everyone Im writing a ms paint like application, I have encountered a few problems and I was hoping someone could help me with them. 1. Could someone give me a clue or guidance on how to do a color selector system? How would one implement this? How do I 'generate' all the colors and use hue/saturation ? 2. I am trying to draw ellipse's. The three types are outline/fill/outline+fill ellipse. Just like in paint. However whenever I draw a filled ellipse with the following code im getting graphical glitches/artifacts. Could anyone tell me why?
// create solid brush 
HBRUSH hBrush = CreateSolidBrush( m_dwFillColor );
SelectObject( hDC, hBrush );

// create filled ellipse
Ellipse( hDC, m_rcEllipseCoords.left +1, m_rcEllipseCoords.top+1, m_rcEllipseCoords.right+1, m_rcEllipseCoords.bottom+1 );

// free brush
SelectObject( hDC, hBrush );
DeleteObject( hBrush );

3. For drawing a rectangle outline I just drew four lines. How would I draw an outline for an ellipse? Win32 GDI's Ellipse() seems to only draw filled ellipse's. 4. How would I implement a zoom tool? To zoom in a specific section of the bitmap. Thanks

Share this post


Link to post
Share on other sites
Quote:
1. Could someone give me a clue or guidance on how to do a color selector system? How would one implement this? How do I 'generate' all the colors and use hue/saturation ?
For a basic colour selection dialog, you can use the Win32 common dialog function ChooseColor(). I've never tried, but you may be able to add functionality using a hook procedure. Alternatively, design your own dialog (But I don't know how to generate the colour rectangle / circle).
For generating hue / saturation values, you might find something on Google. I've no idea how to do it.

Quote:
2. I am trying to draw ellipse's. The three types are outline/fill/outline+fill
ellipse. Just like in paint. However whenever I draw a filled ellipse with the following code im getting graphical glitches/artifacts. Could anyone tell me why?
What sort of graphical glitches? Flickering? Tearing? Also, you should record the return value of SelectObject() and put it back into the DC before you release the brush, otherwise you'll get a resource leak:

HBRUSH hBrush = CreateSolidBrush( m_dwFillColor );
HGDIOBJ hOldBrush = SelectObject( hDC, hBrush );

// create filled ellipse
Ellipse( hDC, m_rcEllipseCoords.left +1, m_rcEllipseCoords.top+1, m_rcEllipseCoords.right+1, m_rcEllipseCoords.bottom+1 );

// free brush
SelectObject( hDC, hOldBrush );
DeleteObject( hBrush );



Quote:
3. For drawing a rectangle outline I just drew four lines. How would I draw an outline for an ellipse? Win32 GDI's Ellipse() seems to only draw filled ellipse's.
All shapes are drawn with a pen (outside line) and brush (fill type). To draw a hollow ellipse, you create a null brush, and select that into the DC:

LOGBRUSH lbBrush;
lbBrush.lbStyle = BS_HOLLOW;
HBRUSH hNullBrush = CreateBrushIndirect(&lbBrush);
HGDIOBJ hOldBrush = SelectObject(hDC,hNullBrush);



Quote:
4. How would I implement a zoom tool? To zoom in a specific section of the bitmap.
If you have a backbuffer for your drawing surface, you can use StretchBlt() to enlarge the image in WM_PAINT.

Share this post


Link to post
Share on other sites
Thanks again Evil Steve. Helped me out once again !! :)

As for the glitches/artifacts with the SelectObject() it seems I was doing it horribly wrong. My program probably has tons of memory leaks because I wasn't freeing it properly. Im going fix all of that right now.

If anyone else can help me out on the Color Pallete Creation and Hue/Saturation thing, that'd be great.

Thanks again!

Share this post


Link to post
Share on other sites
Hello once again everyone.

I have a few more problems, and hope someone can help me. Im nearly finished with the tools of my paint application. The tools that are left are rectangle/lasso select and the move tool.

Now what should happen, is you select something with the select tools and you can move it with the move tool ( well in my program anyway ).

For the rectangle I thought about getting the selected area and using GetPixel() to get the data for moving, and then filling that 'cut' area with FillRgn() with a brush the color of the background. I dont know know if this is the best method. I would rekon GetPixel() to be quite slower than accesing the pixels directly?

Anyway, the rectangle sounds easy but what about lasso? A polygon shaped selection.

Is there a GDI function to 'clip' data from a region? So I can save it to a bitmap. I was thinking if there was I could use the CreateRectRgn() and CreatePolygonRgn() functions to get data. Im totally clueless here :
Another thing i'm having problems with is transparency. Im implementing a 'simple' layer system and wanted to know how I could possible do this? I saw the AlphaBlend() and TransparentBlt() functions. But the thing I dont know is what they mean by 'alpha color'. Is there some special value that is alpha? I mean if I used say magenta/white/etc... then I wouldn't be able to draw with that color.

Thanks !

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