PB v5.45, v5.61 ImageGadget Workaround

Linux specific forum
User avatar
mk-soft
Addict
Addict
Posts: 3086
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

PB v5.45, v5.61 ImageGadget Workaround

Post by mk-soft »

Bug Link ImageGadget : http://www.purebasic.fr/english/viewtop ... 23&t=69231

Workaround ImageGadget and SetGadgetState over CanvasGadget

Update v0.3

Code: Select all

;-TOP
; Workaround ImageGadget for Linux PB Version v5.45, v5.61 by mk-soft
; Version v0.3

Procedure MyImageGadget(Gadget, x, y, Width, Height, ImageID, Flags=0)
  Protected r1, MyFlags, id
  Select Flags
    Case #PB_Image_Border
      MyFlags = #PB_Canvas_Border
  EndSelect
  r1 = CanvasGadget(Gadget, x, y, Width, Height, MyFlags)
  If r1
    If Gadget = #PB_Any
      id = r1
    Else
      id = Gadget
    EndIf
    If ImageID
      If StartDrawing(CanvasOutput(id))
        DrawImage(ImageID, 0, 0) ;, Width, Height)
        StopDrawing()
      EndIf
    EndIf
  EndIf
  ProcedureReturn r1
EndProcedure

Procedure MySetGadgetState(Gadget, State)
  If GadgetType(Gadget) = #PB_GadgetType_Canvas
    If State
      If StartDrawing(CanvasOutput(Gadget))
        Box(0, 0, GadgetWidth(Gadget), GadgetHeight(Gadget), $F5F0F0)
        DrawImage(State, 0, 0)
        StopDrawing()
      EndIf
    EndIf
  Else
    SetGadgetState(Gadget, State)
  EndIf
EndProcedure

Macro ImageGadget(Gadget, x, y, Width, Height, ImageID, Flags=0)
  MyImageGadget(Gadget, x, y, Width, Height, ImageID, Flags)
EndMacro

Macro SetGadgetState(Gadget, State)
  MySetGadgetState(Gadget, State)
EndMacro

;- Test

If OpenWindow(0, 0, 0, 200, 200, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CreateImage(0, 100, 100, 32, $FFFF)
  CreateImage(1, 80, 80, 32, $FFFF00)
  ImageGadget(0,  10, 10, 100, 100, ImageID(0))
  Repeat
    Define Event.i = WaitWindowEvent()
    Select Event.i
      Case #PB_Event_Gadget
        Define Gad.i = EventGadget()
         Select Gad.i
           Case 0 :
             Select EventType()
               Case #PB_EventType_LeftClick
                 Debug "Clicked ImageGadget"
                 If Not toggle
                   toggle = #True
                   SetGadgetState(0, ImageID(1))
                 Else
                   toggle = #False
                   SetGadgetState(0, ImageID(0))
                 EndIf 
             EndSelect
             
         EndSelect
       Case #PB_Event_CloseWindow
         Quit.i = 1
     EndSelect
  Until Quit.i = 1
EndIf
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace