It is currently Fri Aug 14, 2020 9:47 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 40 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: COCOA quests?
PostPosted: Sat Sep 07, 2019 11:44 am 
Offline
Addict
Addict

Joined: Mon Nov 25, 2013 6:41 am
Posts: 826
Thank you, it works now, but there is one problem, I updated the previous post, see what can be done.


Top
 Profile  
Reply with quote  
 Post subject: Re: COCOA quests?
PostPosted: Sun Sep 08, 2019 6:21 am 
Offline
Addict
Addict

Joined: Mon Nov 25, 2013 6:41 am
Posts: 826
I understand that no one knows how to get the height of the drawn text using cocoa?


Top
 Profile  
Reply with quote  
 Post subject: Re: COCOA quests?
PostPosted: Sun Sep 08, 2019 8:09 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3647
Location: Netherlands
mestnyi wrote:
I understand that no one knows how to get the height of the drawn text using cocoa?

It's already in the code you posted.
Code:
CocoaMessage(@Size, NSString, "sizeWithAttributes:", Attributes)

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: COCOA quests?
PostPosted: Sun Sep 08, 2019 12:51 pm 
Offline
Addict
Addict

Joined: Mon Nov 25, 2013 6:41 am
Posts: 826
And why does it return the same result if the font is large or small?
Code:
Procedure stringHeight(string.s)
  Protected NSSize.NSSize, Attributes, NSDictionary
 
  NSString = CocoaMessage(0, 0, "NSString stringWithString:$", @string)
 
  ;NSDictionary = CocoaMessage(0, 0, "NSDictionary dictionaryWithObject:",  DrawingFont, "forKey:$", @"NSFontAttributeName")
  ;CocoaMessage(NSSize, NSString, "sizeWithAttributes:", NSDictionary)
 
  CocoaMessage(@Attributes, 0, "NSMutableDictionary dictionaryWithCapacity:", 2)
  CocoaMessage(@NSSize, NSString, "sizeWithAttributes:", Attributes)
   
  ProcedureReturn NSSize\height
EndProcedure

LoadFont(1, "Lucida Grande", 12)
LoadFont(2, "Helvetica Neue", 12)

If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If CreateImage(0, 200, 200, 24, $FFFFFF) And StartDrawing(ImageOutput(0))
       
      DrawingFont(FontID(1))
      DrawText(30,50, "PUREBASIC")
      Debug TextHeight("a") ; 16
     
      DrawingFont(FontID(2))
      DrawText(100,50, "PUREBASIC")
      Debug TextHeight("a") ; 18
     
      ;-----
     
      DrawingFont(FontID(1))
      DrawText(30,80, "PUREBASIC")
      Debug StringHeight("a") ; 16
     
      DrawingFont(FontID(2))
      DrawText(100,80, "PUREBASIC")
      Debug StringHeight("a") ;
     
      StopDrawing()
      ImageGadget(0, 0, 0, 200, 200, ImageID(0))     
    EndIf
   
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: COCOA quests?
PostPosted: Sun Sep 08, 2019 1:42 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3647
Location: Netherlands
mestnyi wrote:
And why does it return the same result if the font is large or small?


Code:
Procedure StringHeight(String.s)
  Protected NSString, Attributes, NSSize.NSSize
  NSString = CocoaMessage(0, 0, "NSString stringWithString:$", @String)
  Attributes = CocoaMessage(0, 0, "NSDictionary dictionaryWithObject:", DrawingFont, "forKey:$", @"NSFont")
  CocoaMessage(@NSSize, NSString, "sizeWithAttributes:", Attributes)
  ProcedureReturn NSSize\height
EndProcedure

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: COCOA quests?
PostPosted: Sun Sep 08, 2019 4:37 pm 
Offline
Addict
Addict

Joined: Mon Nov 25, 2013 6:41 am
Posts: 826
Code:
CocoaMessage(0, 0, "NSDictionary dictionaryWithObject:",  DrawingFont, "forKey:$", @"NSFontAttributeName")

So it didn’t work because of him. :|
But it is not much faster than the built-in.
Why height is fixed regardless of text?


Top
 Profile  
Reply with quote  
 Post subject: Re: COCOA quests?
PostPosted: Sun Sep 08, 2019 5:26 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3647
Location: Netherlands
mestnyi wrote:
Code:
CocoaMessage(0, 0, "NSDictionary dictionaryWithObject:",  DrawingFont, "forKey:$", @"NSFontAttributeName")

So it didn’t work because of him. :|

Yes, that's right.

mestnyi wrote:
Why height is fixed regardless of text?

I'm not sure I understand what you mean.
Does Windows return the real size of the glyphs so a "g" returns a bigger height compared to an "o" ?

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: COCOA quests?
PostPosted: Sun Sep 08, 2019 6:00 pm 
Offline
Addict
Addict

Joined: Mon Nov 25, 2013 6:41 am
Posts: 826
This was a general question that I do not understand. :)
Yes, I mean, why does textheight () have a parameter
if the return value is independent of the input parameter


Top
 Profile  
Reply with quote  
 Post subject: Re: COCOA quests?
PostPosted: Sun Sep 08, 2019 7:02 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3647
Location: Netherlands
mestnyi wrote:
Yes, I mean, why does textheight () have a parameter
if the return value is independent of the input parameter

It isn't independent. It's useful for multiline text.
Code:
Debug TextHeight("a"+#CRLF$+"b")

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: COCOA quests?
PostPosted: Thu Jul 30, 2020 10:12 am 
Offline
Addict
Addict

Joined: Mon Nov 25, 2013 6:41 am
Posts: 826
what is it for mac os who knows?
Code:
Define Message.MSG
While GetMessage_( Message, 0, 0, 0 )
  Select Message
     
  EndSelect
Wend


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 40 posts ]  Go to page Previous  1, 2, 3

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye