Page 1 of 1
cocoa function
Posted: Sat Feb 18, 2023 3:52 pm
by mestnyi
how to convert this to Purebasic?
Code: Select all
@property(class, readonly, nullable, strong) NSCursor *currentSystemCursor;
it looks like the value returned is not constant, it seems to return the mouse coordinates as well.
Code: Select all
Debug CocoaMessage(0, 0, "NSCursor currentSystemCursor")
Re: cocoa function
Posted: Sat Feb 18, 2023 4:19 pm
by mk-soft
It's return an object NSCursor. Not mouse coordinates
Update
Code: Select all
;-TOP Dump Object Methods
; by mk-soft, 29.12.2019 - 06.11.2022, v1.08.2
Structure ArrayOfMethods
i.i[0]
EndStructure
ImportC ""
class_copyMethodList(*Class, *p_methodCount)
; -> An array of pointers of type Method describing
; the instance methods implemented by the class
; Any instance methods implemented by superclasses are Not included
; You must free the array with free()
class_getName(*Class) ; -> UnsafePointer<Int8> -> *string
sel_getName(*Selector); -> const char *
method_getName(*Method) ; -> Selector
method_getTypeEncoding(*Method) ; -> const char *
method_getReturnType(*Method, *dst, dst_len) ; -> void
method_getNumberOfArguments(*Method) ; -> unsigned int
method_getArgumentType(*Method, index, *dst, dst_len) ; -> void
NSGetSizeAndAlignment(*StringPtr, *p_size, *p_align)
; -> const char *
; Obtains the actual size and the aligned size of an encoded type.
EndImport
; ----
Procedure.s GetArgumentType(*String)
Protected r1.s, arg.s, size.i, ofs.i
arg = PeekS(*String, -1, #PB_UTF8)
r1 + arg + " - "
If Left(arg, 1) = "^"
r1 + "A pointer to type of "
arg = Mid(arg, 2)
EndIf
Select arg
Case "c" : r1 + "A char "
Case "i" : r1 + "An int "
Case "s" : r1 + "A short "
Case "l" : r1 + "A long "
Case "q" : r1 + "A long long"
Case "C" : r1 + "An unsigned char "
Case "I" : r1 + "An unsigned int "
Case "S" : r1 + "An unsigned short "
Case "L" : r1 + "An unsigned long "
Case "Q" : r1 + "An unsigned long long "
Case "f" : r1 + "A float "
Case "d" : r1 + "A double "
Case "B" : r1 + "A C++ bool Or a C99 _Bool "
Case "v" : r1 + "A void"
Case "*" : r1 + "A character string (char *) "
Case "@" : r1 + "An object (whether statically typed Or typed id) "
Case "#" : r1 + "A class object (Class) "
Case ":" : r1 + "A method selector (SEL) "
Default:
NSGetSizeAndAlignment(*String, @size, @ofs)
r1 + "[" + Str(size) + " bytes]"
EndSelect
If Right(arg, 1) = "?"
r1 + "An unknown type (e.g. function pointer)"
EndIf
ProcedureReturn r1
EndProcedure
; ----
Procedure.s DumpObjectMethods(*Object, SuperLevel = 0, HidePrivate = #True, ShowEncoding = #False, FirstArgument = 2)
Protected r1.s, i, c, n, methodCount, Method.s
Protected *Class, *SuperClass, *Method, *Methods.ArrayOfMethods
Protected *String
*Class = object_getclass_(*Object)
If *Class
*String = AllocateMemory(1024)
r1 = PeekS(class_getName(*Class), -1, #PB_UTF8)
If SuperLevel
For i = 1 To SuperLevel
*SuperClass = class_getsuperclass_(*Class)
If *SuperClass
*Class = *SuperClass
r1 + " -> " + PeekS(class_getName(*Class), -1, #PB_UTF8)
Else
Break
EndIf
Next
EndIf
*Methods = class_copyMethodList(*Class, @methodCount)
r1 + #LF$ + #LF$ + "Count of Methods: " + methodCount + #LF$ + #LF$
For i = 0 To methodCount - 1
*Method = *Methods\i[i];
Method = PeekS(sel_getName(method_getName(*Method)), -1, #PB_UTF8)
If HidePrivate And Left(Method, 1) = "_"
Continue
EndIf
r1 + "Method " + Method + #LF$
If ShowEncoding
r1 + " * Encoding " + PeekS(method_getTypeEncoding(*Method), -1, #PB_UTF8) + #LF$
EndIf
method_getReturnType(*Method, *String, 1024)
r1 + " -- ReturnType = " + GetArgumentType(*String) + #LF$
c = method_getNumberOfArguments(*Method)
For n = FirstArgument To c - 1
method_getArgumentType(*Method, n, *String, 1024)
r1 + " -- Argument " + Str(n - FirstArgument + 1) + " = " + GetArgumentType(*String) + #LF$
Next
r1 + #LF$
Next
r1 + "End Class" + #LF$ + #LF$
If *Methods
free_(*Methods)
EndIf
FreeMemory(*String)
Else
r1 = "Object is nil" + #LF$
EndIf
ProcedureReturn r1
EndProcedure
; ****
;-TOP
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(0)
dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
; Resize Gadgets
EndProcedure
Procedure Main()
Protected dx, dy
#WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
; MenuBar
CreateMenu(0, WindowID(0))
MenuTitle("File")
; StatusBar
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(0)
dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
NSCurrentCursor = CocoaMessage(0, 0, "NSCursor currentSystemCursor")
Debug DumpObjectMethods(NSCurrentCursor)
; Main Loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case 0
Break
EndSelect
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
Re: cocoa function
Posted: Sat Feb 18, 2023 7:03 pm
by mestnyi
how to get the current system cursor from all this? Not the application cursor, but the system cursor?
Re: cocoa function
Posted: Sat Feb 18, 2023 8:42 pm
by mk-soft
mestnyi wrote: Sat Feb 18, 2023 7:03 pm
how to get the current system cursor from all this? Not the application cursor, but the system cursor?
This is the current system cursor. A cursor is a object
Link:
https://developer.apple.com/documentati ... guage=objc
Maybe you want something completely different!?
P.S. Example with CanvasGadget and macOS cursors
Code: Select all
;-TOP
Global sharedApplication = CocoaMessage(0, 0, "NSApplication sharedApplication")
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(0)
dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
; Resize Gadgets
ResizeGadget(0, 0, 0, dx, dy)
EndProcedure
Procedure Main()
Protected dx, dy
#WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
; MenuBar
CreateMenu(0, WindowID(0))
MenuTitle("File")
; StatusBar
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(0)
dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
CanvasGadget(0, 0, 0, dx, dy, #PB_Canvas_Keyboard)
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
NSCurrentCursor = CocoaMessage(0, 0, "NSCursor currentCursor")
NSOpenHandCursor = CocoaMessage(0, 0, "NSCursor openHandCursor")
NSCloseHandCursor = CocoaMessage(0, 0, "NSCursor closedHandCursor")
SetGadgetAttribute(0, #PB_Canvas_CustomCursor, NSOpenHandCursor)
;Debug DumpObjectMethods(NSCurrentCursor)
; Main Loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case 0
Break
EndSelect
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_LeftButtonDown
SetGadgetAttribute(0, #PB_Canvas_CustomCursor, NSCloseHandCursor)
Case #PB_EventType_LeftButtonUp
SetGadgetAttribute(0, #PB_Canvas_CustomCursor, NSOpenHandCursor)
EndSelect
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
Re: cocoa function
Posted: Sun Feb 19, 2023 7:35 pm
by mestnyi
just in your example, press the mouse button and without releasing move the cursor to the edge of the window, the cursor will change to arrows and remain so. And in theory, while the button was pressed, the cursor should not have changed, or, at least, when we went beyond the borders of the window, it would return to the "cursor closedhand"
Re: cocoa function
Posted: Mon Feb 20, 2023 1:04 am
by mk-soft
For me, the cursor remains close to hand, even over the edge of the window.
Re: cocoa function
Posted: Mon Feb 20, 2023 7:46 am
by mestnyi
mk-soft wrote: Mon Feb 20, 2023 1:04 am
For me, the cursor remains close to hand, even over the edge of the window.
I have mac os big sur 11.6.8 purebasic 573 lts
Re: cocoa function
Posted: Mon Feb 20, 2023 5:25 pm
by mk-soft
Just tested with v5.73, v6.00, v6.01.
Hand remains closed when leaving the window.
Probably due to the OS. With me macOS Ventura v13.0.1
Re: cocoa function
Posted: Mon Feb 20, 2023 7:30 pm
by Shardik
I have tested mk-soft's last code example on my iMac 2019 with MacOS 11.7.4' Big Sur' with PB 5.73 and PB 6.00 (Asm and C backend). In all tests the cursor is an open hand cursor when inside the window and changes to an arrow when over the titlebar or statusbar and when leaving the window. After returning into the window the cursor changes back to the open hand image.
When keeping the left mouse button pressed, the cursor changes to a closed hand cursor. When keeping the mouse button pressed while leaving the window, the cursor changes to an image with a connected left and right arrow. When returning the cursor to the window, the open hand or closed hand (when still keeping the mouse button pressed) is reinstated.
@mestnyi,
in which environment do you code? On a real Mac, a Hackintosh or a PC or Mac with VM (Virtual Box, VMware, Parallels, ...)?
Re: cocoa function
Posted: Tue Feb 21, 2023 9:14 pm
by mestnyi
Shardik wrote: Mon Feb 20, 2023 7:30 pm
@mestnyi,
in which environment do you code? On a real Mac, a Hackintosh or a PC or Mac with VM (Virtual Box, VMware, Parallels, ...)?
MacBook Air (13-inch, Mid 2013) 1.3 GHz dual-core Intel Core i5 processor
Shardik Sometimes when the cursor returns it is a closed hand, but in most cases it remains an arrow cursor.
I wonder what it could be related to?
Re: cocoa function
Posted: Tue Feb 21, 2023 10:58 pm
by mk-soft
Touch or Mouse? Perhaps sometime lost mouse down
Re: cocoa function
Posted: Wed Feb 22, 2023 8:05 am
by mestnyi
mk-soft wrote: Tue Feb 21, 2023 10:58 pm
Touch or Mouse? Perhaps sometime lost mouse down
touchpad
Я думаю, что это ошибка Macos или PureBasic, так как при уже нажатой кнопке курсор в окне не должен был измениться.