Fred, please correct these two procedures.
Code: Select all
Global _drawing_mode_
Procedure DrawRotatedText_(x.CGFloat, y.CGFloat, Text.s, Angle.CGFloat, FrontColor=$ffffff, BackColor=0)
Protected.CGFloat r,g,b,a
Protected.i Transform, NSString, Attributes, Color
Protected Size.NSSize, Point.NSPoint
CocoaMessage(@Attributes, 0, "NSMutableDictionary dictionaryWithCapacity:", 2)
r = Red(FrontColor)/255 : g = Green(FrontColor)/255 : b = Blue(FrontColor)/255 : a = 1
Color = CocoaMessage(0, 0, "NSColor colorWithDeviceRed:@", @r, "green:@", @g, "blue:@", @b, "alpha:@", @a)
CocoaMessage(0, Attributes, "setValue:", Color, "forKey:$", @"NSColor")
r = Red(BackColor)/255 : g = Green(BackColor)/255 : b = Blue(BackColor)/255 : a = Bool(Not _drawing_mode_&#PB_2DDrawing_Transparent)
Color = CocoaMessage(0, 0, "NSColor colorWithDeviceRed:@", @r, "green:@", @g, "blue:@", @b, "alpha:@", @a)
CocoaMessage(0, Attributes, "setValue:", Color, "forKey:$", @"NSBackgroundColor")
NSString = CocoaMessage(0, 0, "NSString stringWithString:$", @Text)
CocoaMessage(@Size, NSString, "sizeWithAttributes:", Attributes)
If Angle
CocoaMessage(0, 0, "NSGraphicsContext saveGraphicsState")
y = OutputHeight()-y
Transform = CocoaMessage(0, 0, "NSAffineTransform transform")
CocoaMessage(0, Transform, "translateXBy:@", @x, "yBy:@", @y)
CocoaMessage(0, Transform, "rotateByDegrees:@", @Angle)
x = 0 : y = -Size\height
CocoaMessage(0, Transform, "translateXBy:@", @x, "yBy:@", @y)
CocoaMessage(0, Transform, "concat")
CocoaMessage(0, NSString, "drawAtPoint:@", @Point, "withAttributes:", Attributes)
CocoaMessage(0, 0, "NSGraphicsContext restoreGraphicsState")
Else
Point\x = x : Point\y = OutputHeight()-Size\height-y
CocoaMessage(0, NSString, "drawAtPoint:@", @Point, "withAttributes:", Attributes)
EndIf
EndProcedure
Procedure DrawText_(x, y, Text.s, FrontColor=$ffffff, BackColor=0)
ProcedureReturn DrawRotatedText_(x, y, Text.s, 0, FrontColor, BackColor)
EndProcedure
Procedure ClipOutput_(x, y, width, height)
Protected Rect.NSRect
Rect\origin\x = x
Rect\origin\y = OutputHeight()-height-y
Rect\size\width = width
Rect\size\height = height
CocoaMessage(0, CocoaMessage(0, 0, "NSBezierPath bezierPathWithRect:@", @Rect), "setClip")
EndProcedure
Macro PB(Function)
Function
EndMacro
Macro DrawingMode(_mode_)
PB(DrawingMode)(_mode_) : _drawing_mode_ = _mode_
EndMacro
Macro ClipOutput(x, y, width, height)
PB(ClipOutput)(x, y, width, height)
ClipOutput_(x, y, width, height)
EndMacro
Macro DrawText(x, y, Text, FrontColor=$ffffff, BackColor=0)
DrawText_(x, y, Text, FrontColor, BackColor)
EndMacro
Macro DrawRotatedText(x, y, Text, Angle, FrontColor=$ffffff, BackColor=0)
DrawRotatedText_(x, y, Text, Angle, FrontColor, BackColor)
EndMacro
Macro UnclipOutput()
PB(UnclipOutput)()
ClipOutput_(0, 0, OutputWidth(), OutputHeight())
EndMacro
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; example
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Procedure draw_h_gadget(x, y, w, h)
Protected i, iy
ClipOutput(x, y, w, h)
; item of the gadget
For i=0 To 10
iy = y+i*16
DrawingMode(#PB_2DDrawing_Outlined)
Box(x,iy, w,16)
; text of the item
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(x-20, iy, "clip output of the line "+Str(i), 0)
Next
; frame gadget
DrawingMode(#PB_2DDrawing_Outlined)
Box(x,y, w,h, $FFFF00)
EndProcedure
Procedure draw_v_gadget(x, y, w, h)
Protected i, ix, iy
ClipOutput(x, y, w, h)
; item of the gadget
For i=0 To 10
ix = i*16
DrawingMode(#PB_2DDrawing_Outlined)
Box(x+ix,y,16, h)
; text of the item
DrawingMode(#PB_2DDrawing_Transparent)
DrawRotatedText(x+16+ix, y, "clip line "+Str(i)+" rotated text", 270, 0)
Next
; frame gadget
DrawingMode(#PB_2DDrawing_Outlined)
Box(x,y, w,h, $FFFF00)
EndProcedure
OpenWindow(0, 0, 0, 300, 300, "sample demonstration fixes clip output", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateImage(0, 300, 300, 24, $c0c0c0)
StartDrawing(ImageOutput(0))
; 1 - gadget
draw_h_gadget(50, 30, 80, 100)
; 2 - gadget
draw_v_gadget(150, 90, 80, 100)
; 3 - gadget
draw_h_gadget(50, 180, 80, 100)
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(0))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow