CursorDeviceMoveTo() is missing in Carbon

Moderator
Posts: 508
Joined: 2002.09
Post: #1
Perhaps that is old news but I just found out that the function CursorDeviceMoveTo (which apparently move the cursor to another location) is not carbonized. Does anyone know a replacement or a trick to get the same feature in Carbon?

"When you dream, there are no rules..."
Quote this message in a reply
Tobi
Unregistered
 
Post: #2
Right, that is a painful problem. There is no Carbon API that moves the cursor to another position.
The only method to have the cursor moved in Carbon is by using InterfaceLib in case the app is running in OS 9 and the CoreGraphics DirectDisplay API in case running in OS X.

You must import the symbols directly your code because you cannot link to the needed libraries directly.

Use the GetSharedLibrary() / FindSymbol technique to link to the CursorDeviceMoveTo() function in case you are in OS 9 and some sort of LoadFrameworkBundle() if you are in X.
To do this you need a function which checks what system you are running in and determines the function to load.

Apple has sample code for exactly this problem, but I can't find it at the moment.
You can also try the GLUT command glutWarpPointer()

I hope this helps a bit.

-Tobi
Quote this message in a reply
ylaporte
Unregistered
 
Post: #3
I don't know if these are part of the carbon API (They are available on OSX) but there are a few places where you can find interesting things such as this:
http://developer.apple.com/technotes/tn/tn2007.html

of course the interesting section is controlling the mouse cursor...
Quote this message in a reply
Tobi
Unregistered
 
Post: #4
OK, it seems that you have not found a solution to the problem yet so I'm willing to give you my code for this. I also spend endless hours to find this code and modify it to my needs. It's from Apple sample code. The first is a function RunningOnCarbonX() that checks if the app is run in Mac OS X or a classic system. The second function ImportCursorRoutines() must be placed somewhere in your game's init. The last function SetCursorPosition() actually moves the cursor to a given position.
Please let me know if this works for you, or if you get any compile or link errors.
Good luck!

-Tobi

Code:
////// Some global variables //////
CursorDevicePtr    gCursorDevice;//for classic only.
//OS 9 cursor stuff
typedef CALLBACK_API_C( void , CreateCursor )(CursorDevicePtr *theDevice);
typedef CALLBACK_API_C( void , MoveCursor )(CursorDevicePtr ourDevice, long absX, long absY);
CreateCursor            CreateCursorFunction = nil;
MoveCursor                MoveCursorFunction=nil;

///OS X cursor stuff
typedef UInt32 (*CGWarpMouseCursorPositionProcPtr)(CGPoint newCursorPosition);
typedef UInt32 (*CGSetLocalEventsSuppressionIntervalProcPtr)(double pSeconds);
static CGWarpMouseCursorPositionProcPtr sCGWarpMouseCursorPositionProcPtr = nil;


static Boolean RunningOnCarbonX(void)
{
    static Boolean first = true;
    static Boolean result = false;

    if (first)
    {
        UInt32 response;

        first = false;

        result = (Gestalt(gestaltSystemVersion,
                    (SInt32 *) &response) == noErr)
                && (response >= 0x01000);
    
    }
    return result;
}



void ImportCursorRoutines()
{
OSErr                        err, anErr;
CFragConnectionID            connID=kInvalidID;
CFragSymbolClass            symClass;
Ptr                            mainAddr=nil;
Str255                      errName;

if (RunningOnCarbonX())
{
    if (nil == sCGWarpMouseCursorPositionProcPtr)
    {
    CFBundleRef tCFBundleRef;
    anErr=LoadFrameworkBundle(CFSTR("ApplicationServices.framework"), &tCFBundleRef);

    if (noErr == anErr)
    {
    CGSetLocalEventsSuppressionIntervalProcPtr tCGSetLocalEventsSuppressionIntervalProcPtr = nil;

                sCGWarpMouseCursorPositionProcPtr = (CGWarpMouseCursorPositionProcPtr)
                    CFBundleGetFunctionPointerForName( tCFBundleRef, CFSTR("CGWarpMouseCursorPosition") );
                if (nil == sCGWarpMouseCursorPositionProcPtr)
                    anErr = cfragNoSymbolErr;

                tCGSetLocalEventsSuppressionIntervalProcPtr = (CGSetLocalEventsSuppressionIntervalProcPtr)
                    CFBundleGetFunctionPointerForName(tCFBundleRef,CFSTR("CGSetLocalEventsSuppressionInterval"));
                if (nil != tCGSetLocalEventsSuppressionIntervalProcPtr)
                    (*tCGSetLocalEventsSuppressionIntervalProcPtr)(0.0f);
            }
        }
}
else
{
err=GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kImportLibraryCFrag, &connID, &mainAddr, errName);
err=FindSymbol(connID, "\pCrsrDevNewDevice", (Ptr *) &CreateCursorFunction, &symClass);
(*CreateCursorFunction)(&gCursorDevice);
err=FindSymbol(connID, "\pCrsrDevMoveTo", (Ptr *) &MoveCursorFunction, &symClass);
}
}

void SetCursorPosition(int x, int y)
{
if (!RunningOnCarbonX())
{
(*MoveCursorFunction)(gCursorDevice, startLoc.h, startLoc.v);
}
else
{
CGPoint    mouseLoc;

mouseLoc.x=x;
mouseLoc.y=y;
(*sCGWarpMouseCursorPositionProcPtr)(mouseLoc);
}
}
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  new xcode project missing build settings kendric 3 3,257 Nov 18, 2009 07:11 PM
Last Post: kendric