Rounded corners - one more time

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 20
Reputation: bob on whidbey is an unknown quantity at this point 
Solved Threads: 0
bob on whidbey bob on whidbey is offline Offline
Newbie Poster

Rounded corners - one more time

 
0
  #1
Jan 21st, 2008
I've created a playing card descendent of TCustomControl and I want it to have rounded corners. The card is displayed in a Paint procedure where I determine the bitmap and then use a Canvas.Draw(0, 0, FCardBMP); This approach works well except - no rounded corners. Setting FCardBMP.Transparent := true; doesn't work when the card is dragged onto the table which has a different color background. It seems that "Transparent" just sets the corner, transparent pixels to the color of the initial background, but doesn't change pixels colors when the card is dragged.

With no success I've tried to use

Cnt := GenRegion(Par, FCardBMP,
(FCardBMP.Width - FCardBMP.Width+1) div 2,
(FCardBMP.Height - FCardBMP.Height+1) div 2);
hRegion := CreatePolygonRgn(Par, Cnt, ALTERNATE);
SetWindowRgn(FCardBMP.handle, hRegion, true);

I believe the secret is to useSetWindowRgn but I'm stymied. Any help would be appreciated. Thanks.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 11
Reputation: glindhot is an unknown quantity at this point 
Solved Threads: 1
glindhot glindhot is offline Offline
Newbie Poster

Re: Rounded corners - one more time

 
0
  #2
Feb 9th, 2008
Try the function
Pascal and Delphi Syntax (Toggle Plain Text)
  1. RoundRect(DC: HDC; X1, Y1, X2, Y2, X3, Y3: Integer) : Bool;
I've never got around to using it, but it says in the book "Draws a rectangle with rounded corners using the selected pen and filled using the selected brush."
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Rounded corners - one more time

 
0
  #3
Feb 10th, 2008
Regions are for windows. Not for painting.

You should be able to set the transparent and transparentColor properties of the bitmap before drawing it in your paint procedure.

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 20
Reputation: bob on whidbey is an unknown quantity at this point 
Solved Threads: 0
bob on whidbey bob on whidbey is offline Offline
Newbie Poster

Re: Rounded corners - one more time

 
0
  #4
Feb 11th, 2008
As the card is dragged from the gray side to the green "table" the background will change. Depending on where the card is, some of the time 1 or 2 corners will have a green background and 3 or 2 will have gray corners. Sometimes even half and half as the corner is about 3 x 2 pixels.

When I set the transparent color (to the unique color of the corners) it seems that the color in each corner is static....at the gray color of the initial backgroubnd of the card. Dragging the card to the table doesn't change the corner colors to green. I thought that's what was suppose to happen.

This seems to work fairly well, although not perfectly, to set the corners transparent for each bitmap card. Notice that it seems to work better to have width and height PLUS ONE. This coding is executed whenever the dimension of a card changes...generallhy only once per card...when it is instantiated.

GetWindowRgn(Handle, FRoundedReg);
DeleteObject(FRoundedReg);
D := width div 15; // "15" determined by trial and error
FRoundedReg := CreateRoundRectRgn(0, 0, Width+1, Height+1, D, D);
SetWindowRgn(Handle, FRoundedReg, TRUE);
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Rounded corners - one more time

 
0
  #5
Feb 11th, 2008
So your card is actually a separate window?

If it is just the problem of dragging the card across different components on a single form, you can use a TPaintBox (found in the System tab of the components palette) to draw on the form directly. Then you could avoid using a separate window and window regions...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC