RefreshGadget()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Phantomas
User
User
Posts: 96
Joined: Wed Jul 01, 2009 12:59 pm

RefreshGadget()

Post by Phantomas »

Hello, I use ImageGadget(), ButtonImageGadget() and other gadgets which uses images. If I edit Image, which use in my any gadget then this Image will be update when I use this gadget (ex. set cursor or click on ButtonImageGadget()). For fast update after change my Image content I can use this hook:

Code: Select all

DisableGadget(#gadget, 1)
DisableGadget(#gadget, 0)
But this not sure, maybe need to add special RefreshGadget() function for this? See code:

Code: Select all

Enumeration
  #window
  #image_one
  #image_two
  #button_one
  #button_two
EndEnumeration

Macro RefreshGadget(gadget)
  DisableGadget(gadget, 1)
  DisableGadget(gadget, 0)
EndMacro

If OpenWindow(#window, #PB_Any, #PB_Any, 140, 270, "PB Window", #PB_Window_ScreenCentered | #PB_Window_Invisible | #PB_Window_SystemMenu)

  If CreateImage(#image_one, 120, 120)
    If StartDrawing(ImageOutput(#image_one))
      Box(0, 0, 119, 119, RGB(Random(255), Random(255), Random(255)))
    StopDrawing()
    EndIf
    ButtonImageGadget(#button_one, 10, 10, 120, 120, ImageID(#image_one))
    ButtonGadget(#button_two, 10, 140, 120, 120, "Change")
  EndIf
  
  HideWindow(#window, 0)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #button_two
            If StartDrawing(ImageOutput(#image_one))
              Box(0, 0, 119, 119, RGB(Random(255), Random(255), Random(255)))
            StopDrawing()
            EndIf
            RefreshGadget(#button_one) ;New feature request here. Comment/uncomment this line
        EndSelect
    EndSelect
  ForEver
EndIf
Comment/uncomment 38 line for understand what I want.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: RefreshGadget()

Post by Trond »

For image button:
SetGadgetAttribute(#button_one, #PB_Button_Image, ImageID(#image_one))

For image gadget:
SetGadgetState(imagegadget, ImageId(Image))
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: RefreshGadget()

Post by PureLust »

Nevertheless, imho a native "DisableGadgetRefresh(#Gadget, State)" would be a good Idea, especially if one works with large lists.

(like: SendMessage_(GadgetID(0), #WM_SETREDRAW, 0, 0) on Windows Machines)
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
Post Reply