COCOA quests?
Re: COCOA quests?
Thank you, it works now, but there is one problem, I updated the previous post, see what can be done.
Re: COCOA quests?
I understand that no one knows how to get the height of the drawn text using cocoa?
Re: COCOA quests?
It's already in the code you posted.mestnyi wrote:I understand that no one knows how to get the height of the drawn text using cocoa?
Code: Select all
CocoaMessage(@Size, NSString, "sizeWithAttributes:", Attributes)
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: COCOA quests?
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?
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
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: COCOA quests?
Code: Select all
CocoaMessage(0, 0, "NSDictionary dictionaryWithObject:", DrawingFont, "forKey:$", @"NSFontAttributeName")
But it is not much faster than the built-in.
Why height is fixed regardless of text?
Re: COCOA quests?
Yes, that's right.mestnyi wrote:So it didn’t work because of him.Code: Select all
CocoaMessage(0, 0, "NSDictionary dictionaryWithObject:", DrawingFont, "forKey:$", @"NSFontAttributeName")
I'm not sure I understand what you mean.mestnyi wrote:Why height is fixed regardless of text?
Does Windows return the real size of the glyphs so a "g" returns a bigger height compared to an "o" ?
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: COCOA quests?
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
Yes, I mean, why does textheight () have a parameter
if the return value is independent of the input parameter
Re: COCOA quests?
It isn't independent. It's useful for multiline text.mestnyi wrote:Yes, I mean, why does textheight () have a parameter
if the return value is independent of the input parameter
Code: Select all
Debug TextHeight("a"+#CRLF$+"b")
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: COCOA quests?
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?
Help me find a replacement for this cocoa remedy.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
Code: Select all
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: COCOA quests?
Can you explain a bit more ?mestnyi wrote:Help me find a replacement for this cocoa remedy.Code: Select all
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
I don't understand what you are looking for.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: COCOA quests?
Of course I will try to explain.wilbert wrote:Can you explain a bit more ?mestnyi wrote:Help me find a replacement for this cocoa remedy.Code: Select all
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
I don't understand what you are looking for.
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())
Code: Select all
Procedure func()
Protected Message.MSG
While GetMessage_( Message, 0, 0, 0 )
Wend
EndProcedure
BindGadgetEvent(#gadget, @func())
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?
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.
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
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: COCOA quests?
If mestnyi wants to get rid of PureBasic's event loop, he might try a permanent run loop:
This is a working example:
Code: Select all
CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "run")
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")