[Done] ClipOutput fails, and Canvas doesnt react to Shift,Ctrl keys

Post bugreports for the Mac OSX version here
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

[Done] ClipOutput fails, and Canvas doesnt react to Shift,Ctrl keys

Post by Keya »

ClipOutput() is working fine on Linux and Windows but i tested 5.42, 5.44, 5.60 on Mac and all having problems with ClipOutput and/or DrawText together.

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "ClipOutput", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If CreateImage(0, 200, 200, 24, $FFFFFF) And StartDrawing(ImageOutput(0))
      cury = 15
      For i = 1 To 5  ;draw "Test n" every 15 pixels
        ClipOutput(2, cury, 200, 15) ;Comment-out it works. Buggy if included, but works fine Win+Linux.
        DrawText(2,cury,"Test "+Str(i),$FFFFFF,0)
        cury+15
      Next i
      StopDrawing() 
      ImageGadget(0, 0, 0, 200, 200, ImageID(0))      
    EndIf    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
i cannot use Listicon gadget due to the AddGadgetItem bug that i got smashed for reporting so i was told to go off and make a custom gadget, but after making it i find i cannot get it working on Mac because of this bug, it all works apart from this. really disheartened at this stage after all this and don't know what to do now :(

Another problem i encountered was Mac's canvas doesn't respond to Shift or Ctrl keys, neither by keydown or input events, (and AddKeyboardShortcut is no option as that has no event for keyup), so i can't create a multi-select listbox where you hold down shift or ctrl and click multiple items so im stumped there too

sorry
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ClipOutput fails, and Canvas doesnt react to Shift,Ctrl

Post by wilbert »

I know this is an old thread but the bug still exists (PB 5.62) and I have a little more information about it.
If you take this simple example

Code: Select all

OpenWindow(0, 0, 0, 200, 200, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

CreateImage(0, 200, 200, 24, $808080)
StartDrawing(ImageOutput(0))

ClipOutput(50, 50, 100, 100)
DrawText(50, 50, "hello")

StopDrawing() 
ImageGadget(0, 0, 0, 200, 200, ImageID(0))      

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
the background box for the text is drawn at (50,50) but the text itself is drawn at (0,0).
For some reason ClipOutput messes with the coordinates.
Windows (x64)
Raspberry Pi OS (Arm64)
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: ClipOutput fails, and Canvas doesnt react to Shift,Ctrl

Post by mestnyi »

I confirm 5.62 mac os High Sierra ver. 10.13.2
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: ClipOutput fails, and Canvas doesnt react to Shift,Ctrl

Post by Wolfram »

Here on OSX 10.7 PB 5.62 x64 the text is on x 0 an on y 100.
It seams that it draws the y on the lowest position of the high.
The text background is correct.

ClipOutput(50, 0, 100, 50) ; draws "hello" 50px above the bottom
DrawText(50, 0, "hello")

ClipOutput(50, 0, 100, 100) ; draws "hello" 100px above the bottom
DrawText(50, 0, "hello")

ClipOutput(50, 0, 100, 100) ; draws "hello" 200px above the bottom
DrawText(50, 0, "hello")
macOS Catalina 10.15.7
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: ClipOutput fails, and Canvas doesnt react to Shift,Ctrl

Post by mestnyi »

Thanks wilbert
Fred, please correct these two procedures. :cry:

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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ClipOutput fails, and Canvas doesnt react to Shift,Ctrl

Post by srod »

Any chance of a fix Fred? :)

I only ask because I have a huge cross-platform grid control nearing completion and the ClipOutput() bug is stopping the thing running on MacOS in any sensible way.

I can work around it relatively easily (and it then runs well on MacOS), but the workaround causes a couple of graphical annoyances on Windows/LinuxQT which then lead to me employing the workaround on just the one platform which I'd rather avoid. All or nothing for me! :)
Thanks.
I may look like a mule, but I'm not a complete ass.
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Done] ClipOutput fails, and Canvas doesnt react to Shift,Ctrl keys

Post by Fred »

Fixed.
Post Reply