Page 2 of 2
					
				
				Posted: Tue Jul 18, 2006 9:58 pm
				by netmaestro
				True, he missed a line:
Code: Select all
    If StartDrawing(WindowOutput(0))
      DrawingFont(GetStockObject_(#DEFAULT_GUI_FONT))
      Length = TextWidth("Hahah") 
      StopDrawing() 
    EndIf
 
			 
			
					
				
				Posted: Tue Jul 18, 2006 10:00 pm
				by Flype
				it works for me, just use DrawingFont() to calculate sizes from the correct font.
Code: Select all
If OpenWindow(0,0,0,320,240,"test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  
  
  FontID = GetStockObject_(#DEFAULT_GUI_FONT)
  
  text$ = "haha, hoho"
  
  hDC = GetDC_(WindowID(0))
  SelectObject_(hDC, FontID)
  GetTextExtentPoint32_(hDC, text$, Len(text$), sz.SIZE) 
  ReleaseDC_(WindowID(0), hDC) 
  Debug sz\cx
  Debug sz\cy
  
  StartDrawing(WindowOutput(0)) 
  DrawingFont(FontID)
  Debug TextWidth(text$) 
  Debug TextHeight(text$)
  StopDrawing() 
  
  
EndIf
 
			 
			
					
				
				Posted: Tue Jul 18, 2006 10:01 pm
				by Flype
				too fast for me netmaestro  

 
			 
			
					
				
				Posted: Tue Jul 18, 2006 10:04 pm
				by netmaestro
				I have speed but I don't think I'll ever have the legendary Flype thoroughness!
			 
			
					
				
				Posted: Tue Jul 18, 2006 10:05 pm
				by Trond
				netmaestro wrote:True, he missed a line:
Code: Select all
    If StartDrawing(WindowOutput(0))
      DrawingFont(GetStockObject_(#DEFAULT_GUI_FONT))
      Length = TextWidth("Hahah") 
      StopDrawing() 
    EndIf
 
Yes, but not he uses API, and an API solution was already posted.
 
			 
			
					
				
				Posted: Tue Jul 18, 2006 11:11 pm
				by Flype
				@trond
So just use FontID = GetGadgetFont(#Gadget) (when it's possible).
maybe a Get/SetWindowFont() would be useful ?
@netmaestro
ah yes, you're right. iwas not sure but now that you said it :
http://www.googlefight.com/index.php?la ... netmaestro
 
i have to say that the 'trond' skills easily beats me :
http://www.googlefight.com/index.php?la ... ord2=trond
but, hey, who's the boss ?
http://www.googlefight.com/index.php?la ... ord2=trond
 
 
			 
			
					
				
				Posted: Thu Jul 27, 2006 6:21 pm
				by Trond
				Flype wrote:@trond
So just use FontID = GetGadgetFont(#Gadget) (when it's possible).
 

 
Ingenious, thank you.
 
			 
			
					
				
				Posted: Wed Dec 03, 2008 1:47 pm
				by andrasch
				tried to make a handy procedure out of it, may be you like it.
Code: Select all
Procedure writeTextGadget(GadgetLeft, GadgetTop, Text.s, GadgetNumber = #PB_Any, Flags = 0)
   ; creates a text-gadget sized according to its text
   ; returns gadget-number for #PB_Any or else gadget-id (as usual for gadget-creation)
   Protected ReturnValue
	
   ; to be able to use GetGadgetFont() when getting size gadget is created first and then resized
   ReturnValue = TextGadget(GadgetNumber, GadgetLeft, GadgetTop, 0, 0, Text, Flags)
   If GadgetNumber = #PB_Any
      GadgetNumber = ReturnValue
   EndIf
	
   If ReturnValue
      If StartDrawing(WindowOutput(GetActiveWindow()))
         DrawingFont(GetGadgetFont(GadgetNumber))
         ResizeGadget(GadgetNumber, #PB_Ignore, #PB_Ignore, TextWidth(Text), TextHeight(Text))
         StopDrawing()
         ProcedureReturn ReturnValue
      EndIf
   EndIf
	
   ProcedureReturn #False
EndProcedure