Page 3 of 4

Re: COCOA quests?

Posted: Sat Sep 07, 2019 11:44 am
by mestnyi
Thank you, it works now, but there is one problem, I updated the previous post, see what can be done.

Re: COCOA quests?

Posted: Sun Sep 08, 2019 6:21 am
by mestnyi
I understand that no one knows how to get the height of the drawn text using cocoa?

Re: COCOA quests?

Posted: Sun Sep 08, 2019 8:09 am
by wilbert
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: Select all

CocoaMessage(@Size, NSString, "sizeWithAttributes:", Attributes)

Re: COCOA quests?

Posted: Sun Sep 08, 2019 12:51 pm
by mestnyi
And why does it return the same result if the font is large or small?

Code: Select all

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

Re: COCOA quests?

Posted: Sun Sep 08, 2019 1:42 pm
by wilbert
mestnyi wrote:And why does it return the same result if the font is large or small?

Code: Select all

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

Re: COCOA quests?

Posted: Sun Sep 08, 2019 4:37 pm
by mestnyi

Code: Select all

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?

Re: COCOA quests?

Posted: Sun Sep 08, 2019 5:26 pm
by wilbert
mestnyi wrote:

Code: Select all

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" ?

Re: COCOA quests?

Posted: Sun Sep 08, 2019 6:00 pm
by mestnyi
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

Re: COCOA quests?

Posted: Sun Sep 08, 2019 7:02 pm
by wilbert
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: Select all

Debug TextHeight("a"+#CRLF$+"b")

Re: COCOA quests?

Posted: Thu Jul 30, 2020 10:12 am
by mestnyi
what is it for mac os who knows?

Code: Select all

Define Message.MSG
While GetMessage_( Message, 0, 0, 0 )
  Select Message
      
  EndSelect
Wend

Re: COCOA quests?

Posted: Tue Aug 25, 2020 4:51 pm
by mestnyi
mestnyi wrote:what is it for mac os who knows?

Code: Select all

Define Message.MSG
While GetMessage_( Message, 0, 0, 0 )
  Select Message
      
  EndSelect
Wend
Help me find a replacement for this cocoa remedy.

Code: Select all

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: COCOA quests?

Posted: Tue Aug 25, 2020 8:31 pm
by wilbert
mestnyi wrote:Help me find a replacement for this cocoa remedy.

Code: Select all

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Can you explain a bit more ?
I don't understand what you are looking for.

Re: COCOA quests?

Posted: Wed Aug 26, 2020 9:16 am
by mestnyi
wilbert wrote:
mestnyi wrote:Help me find a replacement for this cocoa remedy.

Code: Select all

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Can you explain a bit more ?
I don't understand what you are looking for.
Of course I will try to explain.
Since Fred forbade the use of such a construction

Code: Select all

Procedure func()
Protected event
 Repeat 
   event = WaitWindowEvent() 
 Until event = #PB_Event_CloseWindow
EndProcedure

BindGadgetEvent(#gadget, @func())
in window i could do like this

Code: Select all

Procedure func()
Protected Message.MSG
While GetMessage_( Message, 0, 0, 0 )
Wend
EndProcedure

BindGadgetEvent(#gadget, @func())
I hope this explains.

So I cannot use this.
https://github.com/mestnyi33/Widget/blo ... essage).pb
inside procedure.
https://github.com/mestnyi33/Widget/blo ... (close).pb

Re: COCOA quests?

Posted: Wed Aug 26, 2020 10:32 am
by wilbert
I'm still not exactly clear what you want.
If you want to monitor for window close, you can use NSWindowWillCloseNotification (NSNotificationCenter).

If you want to remove events from the queue, you can use
nextEventMatchingMask:untilDate:inMode:dequeue:

Besides BindGadgetEvent there's also BindEvent.
I don't know if that's something you can use.

Code: Select all

Procedure WindowCloseEvent()
  CloseWindow(0)
  End
EndProcedure
  

OpenWindow(0, 0, 0, 320, 170, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)

BindEvent(#PB_Event_CloseWindow, @WindowCloseEvent(), 0)
  
EditorGadget(0, 10, 10, 300, 150)
  
Repeat
  Event = WaitWindowEvent()
ForEver

Re: COCOA quests?

Posted: Wed Aug 26, 2020 1:23 pm
by Shardik
If mestnyi wants to get rid of PureBasic's event loop, he might try a permanent run loop:

Code: Select all

CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "run")
This is a working example:

Code: Select all

Procedure WindowCloseEvent()
  CloseWindow(0)
  End
EndProcedure

OpenWindow(0, 270, 100, 250, 100, "Permanent loop demo")
BindEvent(#PB_Event_CloseWindow, @WindowCloseEvent(), 0)

CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "run")