For showing coordinates you should create something yourself but with a little cocoa you can define several tips for one canvas.
Here's an example. The NSString objects for the tooltip are not allowed to be autorelease objects so I used a PureBasic map object for those.
If a new tip is assigned on a previous location, the previous object is reused. The only problem is that it won't work properly if you resize your canvas gadget.
Code: Select all
Global NewMap ToolTipString.i()
Procedure.i AddCanvasTip(CanvasGadget, x, y, Width, Height, Text.s)
Protected ToolTipRect.NSRect, TipID.s, Tip.i
ToolTipRect\origin\x = x
ToolTipRect\origin\y = GadgetHeight(CanvasGadget) - y - Height
ToolTipRect\size\width = width
ToolTipRect\size\height = height
TipID = Str(CanvasGadget) + ":" + Str(x) + ":" + Str(y)
Tip = ToolTipString(TipID)
If Tip = 0
Tip = CocoaMessage(0, CocoaMessage(0, 0, "NSMutableString alloc"), "initWithCapacity:", 0)
ToolTipString(TipID) = Tip
EndIf
CocoaMessage(0, Tip, "setString:$", @Text)
ProcedureReturn CocoaMessage(0, GadgetID(CanvasGadget), "addToolTipRect:@", @ToolTipRect, "owner:", Tip, "userData:", 0)
EndProcedure
Procedure RemoveCanvasTip(CanvasGadget, Tip)
CocoaMessage(0, GadgetID(CanvasGadget), "removeToolTip:", Tip)
EndProcedure
OpenWindow(0, 100, 100, 300, 200, "Test")
CanvasGadget(0, 10, 10, 280, 180)
StartDrawing(CanvasOutput(0))
Box(10, 10, 100, 20, RGB(255, 0, 0))
Box(10, 30, 100, 20, RGB(0, 255, 0))
StopDrawing()
AddCanvasTip(0, 10, 10, 100, 20, "Tip 1")
AddCanvasTip(0, 10, 30, 100, 20, "Tip 2")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver