PureBasic Forum
http://forums.purebasic.com/english/

PB v5.45, v5.61 ImageGadget Workaround
http://forums.purebasic.com/english/viewtopic.php?f=15&t=69280
Page 1 of 1

Author:  mk-soft [ Thu Sep 28, 2017 8:22 am ]
Post subject:  PB v5.45, v5.61 ImageGadget Workaround

Bug Link ImageGadget : viewtopic.php?f=23&t=69231

Workaround ImageGadget and SetGadgetState over CanvasGadget

Update v0.3
Code:
;-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

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/