Re: COCOA quests?
Posted: Sat Sep 07, 2019 11:44 am
Thank you, it works now, but there is one problem, I updated the previous post, see what can be done.
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)
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
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
Code: Select all
CocoaMessage(0, 0, "NSDictionary dictionaryWithObject:", DrawingFont, "forKey:$", @"NSFontAttributeName")
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?
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")
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.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
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
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.
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())
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
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")