Can anyone help me with this Objective-C?

Miscellaneous Forums/MacOS X Discussion/Can anyone help me with this Objective-C?

Thanks Craig...

I think we've cracked it - I managed to get the absoluteFrom function to work correctly (i.e. returning absolute screen co-ordinates from panel coords). In order to do so, I had to convert the bottom-left coordinate so it's relative to top-left.

From there, relativeTo function was easy by finding the absolute distance between point 0,0 on the panel and the passed location gives me the relative positions.

In case anybody is interested. Here's the working program:

SuperStrict

Import "screenposlib.m"

Extern "macos"

	Function relativeTo(x:Int Ptr, y:Int Ptr, panel:Int)
	Function absoluteFrom(x:Int Ptr, y:Int Ptr, panel:Int)
	
EndExtern

Global wndMain:TGadget = CreateWindow("Test Window",100,100,400,300,Null,15)

	Global gadPanel1:TGadget = CreatePanel(10,10,150,250,wndMain,PANEL_ACTIVE)
	SetPanelColor(gadPanel1,128,255,0)
	Global gadPanel2:TGadget = CreatePanel(160,10,150,250,wndMain,PANEL_ACTIVE)
	SetPanelColor(gadPanel2,255,128,0)
	
Repeat

	Select WaitEvent()
	
		Case EVENT_WINDOWCLOSE;End
		
		Case EVENT_MOUSEMOVE
			
			?MacOs
			
			DebugLog CurrentEvent.ToString$()
			
			Local tmpX% = EventX(),tmpY% = EventY()
			
			absoluteFrom(Varptr(tmpX),Varptr(tmpY),QueryGadget(TGadget(EventSource()),QUERY_NSVIEW_CLIENT))
			
			DebugLog "Screen Mouse x: " + tmpX + " Screen Mouse y: " + tmpY
			
			relativeTo(Varptr(tmpX),Varptr(tmpY),QueryGadget(TGadget(gadPanel2),QUERY_NSVIEW_CLIENT))
			
			DebugLog "Relative to Panel 2 x: " + tmpX + " y: " + tmpY
			
			?
		
	EndSelect
	
Forever


#include <AppKit/AppKit.h>

#import <brl.mod/system.mod/system.h>

// absoluteFrom
// should convert panel coordinates into top left screen coordinates

void absoluteFrom( int *x,int *y,NSView *panel ){

	NSPoint returnPoint = [[panel window] convertBaseToScreen:[panel convertPoint:NSMakePoint(*x,*y) toView:nil]];
	
	*x=returnPoint.x;
	*y=returnPoint.y;
	
	*y=[[NSScreen deepestScreen] frame].size.height - *y;
	
}

// relativeTo
// should convert top-left screen-coordinates into coords relative to panel 

void relativeTo( int *x,int *y,NSView *panel ){

	int cx = 0;
	int cy = 0;
	
	absoluteFrom( &cx, &cy, panel);
	
	*x = *x - cx;
	*y = *y - cy;
	
}


I've removed the previous versions to avoid confusion for any people wanting to use this code.

Thanks Craig & Skid for all your help,


Seb