Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Oct 21, 2017 9:12 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: MagicPad
PostPosted: Sun Apr 14, 2013 11:19 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Does anyone have any drop in code to support gestures from a MagicPad (or OSX laptop pad)?

Really at this time just need "pinch" ... to controll zoom in/out

For Cocoa.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: MagicPad
PostPosted: Mon Apr 15, 2013 5:03 am 
Offline

Joined: Wed Feb 04, 2009 1:43 pm
Posts: 427
DaveS wrote:
Does anyone have any drop in code to support gestures from a MagicPad (or OSX laptop pad)?

Really at this time just need "pinch" ... to controll zoom in/out

For Cocoa.


Though it is possible with declares, it is not very easy to do so (a lot of declares needed). MacLib doesn't have one either.
Your best bet is MBS plugins. They have some classes that enable gestures.


Top
 Profile  
Reply with quote  
 Post subject: Re: MagicPad
PostPosted: Mon Apr 15, 2013 9:05 am 
Offline
User avatar

Joined: Thu Sep 10, 2009 2:50 am
Posts: 418
Location: Santa Cruz, CA, USA
atarikid wrote:
Though it is possible with declares, it is not very easy to do so (a lot of declares needed). MacLib doesn't have one either..


Can you supply some more info on this please? MacOSLib seems to have most of the setup for it, I see where it's registering it's own MouseDrag handler and I think it's only 1 or 2 more declares to have pinch and rotate but I haven't cracked it yet. Still working out the details of MouseDrag. Is it really a whole lot more/different?


Top
 Profile  
Reply with quote  
 Post subject: Re: MagicPad
PostPosted: Tue May 14, 2013 12:09 pm 
Offline
User avatar

Joined: Thu Sep 10, 2009 2:50 am
Posts: 418
Location: Santa Cruz, CA, USA
Working off of NSImageView in MacOSLib I've made a single Canvas subclass with magnify and rotate events. This is a first draft. Any errors simply break and I'm wondering if certain ptrs should be retained/released, though it's working well so far.

demo http://home.comcast.net/~trochoid/NSControlGesture8b.rbp.zip
Class CanvasWithMagnifyAndRotate inherits Canvas

Private Structure NSPoint
x as Single
y as Single

Private Structure NSRect
x as Single
y as Single
w as Single
h as Single

Private Const CocoaLib = "Cocoa.framework"

Private Shared dispatchList() As CanvasWithMagnifyAndRotate //possible canvas instances to send events to

Private subviewid As Ptr //pointer to dynamically created subview instance

//New Events
Private Event Open()
Private Event GestureMagnify(zoom As Single, x As integer, y As integer)
Private Event GestureRotate(angle As Single, x As integer, y As integer)

Sub Open()

#if TargetCocoa

soft declare function initWithFrame lib CocoaLib selector "initWithFrame:" (obj_id as Ptr, frameRect as NSRect) as Ptr
soft declare function NSClassFromString lib CocoaLib (aClassName as CFStringRef) as Ptr
soft declare function alloc lib CocoaLib selector "alloc" (classRef as Ptr) as Ptr
soft declare sub addSubview lib CocoaLib selector "addSubview:" (id as Ptr, aView as Ptr)
soft declare sub setAutoresizingMask lib CocoaLib selector "setAutoresizingMask:" (id as Ptr, mask as Integer)
soft declare function objc_allocateClassPair lib CocoaLib (superclass as Ptr, name as CString, extraBytes as Integer) as Ptr
soft declare sub objc_registerClassPair lib CocoaLib (cls as Ptr)
soft declare function class_addMethod lib CocoaLib (cls as Ptr, name as Ptr, imp as Ptr, types as CString) as Boolean
soft declare function NSSelectorFromString lib CocoaLib (aSelectorName as CFStringRef) as Ptr

static GesturingPane as Ptr //pointer to dynamically created subclass

if GesturingPane = nil then //create (only do once)

GesturingPane = objc_allocateClassPair(NSClassFromString("NSView"), "GesturingPane", 0) //create class
if GesturingPane = nil then break
objc_registerClassPair(GesturingPane) //register it ?

//add event handler methods
if not class_addMethod(GesturingPane, NSSelectorFromString("magnifyWithEvent:"), AddressOf impl_Gesture, "v@:@") then break
if not class_addMethod(GesturingPane, NSSelectorFromString("rotateWithEvent:"), AddressOf impl_Gesture, "v@:@") then break

end

dispatchList.Append self //add self to dispatch list

// add GesturingPane instance as subview and bind bounds
dim frame as NSRect //setup initial bounds
frame.x = 0.0
frame.y = 0.0
frame.w = self.Width
frame.h = self.Height

self.subviewid = initWithFrame(alloc(GesturingPane), frame) //allocate an instance and set its bounds
if self.subviewid = nil then break

addSubview(Ptr(self.Handle), self.subviewid) //link instance to this RB Canvas

setAutoresizingMask(self.subviewid, 18) //track size, NSViewWidthSizable=2 or NSViewHeightSizable=16

#endif

RaiseEvent Open

End Sub


Private Sub Shared impl_Gesture(pid as Ptr, sel as Ptr, evt as Ptr)
#pragma unused sel
//Find the Canvas with matching subview id and send it the event
for i As integer = 0 to dispatchList.Ubound
if dispatchList(i).subviewid = pid then
dispatchList(i).sendGesture(evt)
return
end
next
End Sub


Private Sub sendGesture(evt As Ptr)

#if TargetCocoa

soft declare function type lib CocoaLib selector "type" (obj_id as Ptr) as integer 'EventType
soft declare function locationInWindow lib CocoaLib selector "locationInWindow" (id as Ptr) as NSPoint
soft declare function convertPoint lib CocoaLib selector "convertPoint:fromView:" ( id as Ptr, loc as NSPoint, fromView as Ptr ) as NSPoint

//get mouse coordinates from event (rather than processing System.MouseXY)
dim pnt as NSPoint = convertPoint(self.subviewid, locationInWindow(evt), nil)
pnt.y = self.Height - pnt.y

Select Case type(evt) //determine event type and send info
Case 30 //magnify
soft declare function magnification lib CocoaLib selector "magnification" (id as Ptr) as Single 'CGFloat
RaiseEvent GestureMagnify(magnification(evt), pnt.x, pnt.y)

Case 18 //rotate
soft declare function rotation lib CocoaLib selector "rotation" (id as Ptr) as Single 'Float
RaiseEvent GestureRotate(rotation(evt) * 6.28318 / 360, pnt.x, pnt.y)

End

#endif

End Sub


End Class

Some issues

The list of canvas instances is added to in Open, but never removed. Need some way to remove them when a canvas closes. Can I simply remove it in the Close event or does the attached subview need special destructing? Leaky?

Magnify and rotate occur separately. To get simultaneous action this looks promising http://stackoverflow.com/questions/3448614/uiimageview-gestures-zoom-rotate-question. maybe


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group