It is currently Mon Nov 18, 2019 7:50 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: ImageGadget, SetGadgetState and 24 bit...
PostPosted: Fri Apr 19, 2019 8:58 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2445
I'd like to update an imagegadget which results in flickering from time to time, so I changed my code to use 24 bit for doing this...

Init part:
Code:
#FlickeringLights=0
CompilerIf #FlickeringLights
   CreateImage(#WaitIcon,#Wait_End,#WaitHeight,32,#PB_Image_Transparent)
CompilerElse
   CreateImage(#WaitIcon,#Wait_End,#WaitHeight,24,GetSysColor_(#COLOR_BTNFACE))
CompilerEndIf

StartDrawing(ImageOutput(#WaitIcon))
Box(0,0,#Wait_End,#WaitHeight,#DrawOpaque|#Red)
StopDrawing()


Image update:
Code:
GrabImage(#WaitIcon,#WaitTemp,n*#WaitBox,0,#WaitBox,#WaitHeight)
SetGadgetState(#MakeStateProgress,ImageID(#WaitTemp))


But when using the 24 bits variant, the imagegadget is never updated (it looks empty :shock: ). The 32 bit version works perfect. I saved the grabbed image as a file, it looks fine. And the most irritating thing - when I change the setgadgetstate command by using the image id of #WaitIcon, the gadget gets the correct content...

..any ideas what I am doing wrong?


Top
 Profile  
Reply with quote  
 Post subject: Re: ImageGadget, SetGadgetState and 24 bit...
PostPosted: Fri Apr 19, 2019 10:40 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3456
Why you are sure that 24 bit image will get rid of the flicker ?
Anyhow
Code:
GrabImage(#WaitIcon,#WaitTemp,n*#WaitBox,0,#WaitBox, #WaitHeight)
*buffer = EncodeImage(#WaitTempm,#PB_ImagePlugin_BMP,0,24)
CatchImage(#WaitTemp2,*buffer)
SetGadgetState(#MakeStateProgress,ImageID(#WaitTemp2))

;*********************************************************
GrabImage(#WaitIcon,#WaitTemp,n*#WaitBox,0,#WaitBox, #WaitHeight)
imgID = CopyImage_(ImageID(#WaitTemp),#IMAGE_BITMAP   ,#WaitBox,#WaitHeight,#LR_COPYDELETEORG   )
SetGadgetState(#MakeStateProgress,imgID)

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: ImageGadget, SetGadgetState and 24 bit...
PostPosted: Sat Apr 20, 2019 2:19 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 629
Location: Linz, Austria
Why don't you use the CanvadGadget instead?
CanvasOutput() wrote:
Drawing on a CanvasGadget() is double-buffered. This means that the drawing operations only become visible at the StopDrawing() command to avoid visible flicker during the drawing.


Top
 Profile  
Reply with quote  
 Post subject: Re: ImageGadget, SetGadgetState and 24 bit...
PostPosted: Sat Apr 20, 2019 7:10 am 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2445
Thanks, good points...

Rashad, tried both variants, the first hasn't worked here (or I did something wrong), but the second method works excellent.

I am still confused about what's going on in two points:
1. why I need to polish the #WaitTemp image after grabbing? The color depth is already 24 bit, so what is missing?
2. what about memory management? I am updating the imagegadget thousand of times, how can I free the generated images?

PS: I avoided CanvasGadget because I tried to preserve the background of the dialog and draw an overlaying image - but meantime I also think about grabbing the background content at the beginning which saves me to do overlays on the fly...

Here's a small example 'bout the actual trends... :lol:
Code:

#AntiFlickering=0

Procedure Init()

   Enumeration
      #Win
      #MakeStateProgress
      #WaitIcon
      #WaitTemp
   EndEnumeration

   #WaitSize=   21
   #WaitSpace=3
   #WaitBox=   #WaitSize+#WaitSpace*2
   #WaitHeight=#WaitSize
   #WaitWidth=   #WaitSize/3
   #WaitLineX=   #WaitSize
   #WaitLineY=   #WaitSize-3
   #WaitLoop=   (#WaitLineX+#WaitLineY-#WaitWidth*2)*4
   #WaitColor=   #Blue
   #Wait_End=      #WaitLoop*#WaitBox

   OpenWindow(#Win,0,0,320,100,"Image Refresh",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
   CompilerIf #AntiFlickering<2
      ImageGadget(#MakeStateProgress,148,40,#WaitBox,#WaitHeight,0)
   CompilerElse
      CanvasGadget(#MakeStateProgress,148,40,#WaitBox,#WaitHeight)
   CompilerEndIf
   AddWindowTimer(#Win,0,5)


   CompilerIf #AntiFlickering
      CreateImage(#WaitIcon,#Wait_End,#WaitHeight,24,GetSysColor_(#COLOR_BTNFACE))
   CompilerElse
      CreateImage(#WaitIcon,#Wait_End,#WaitHeight,32,#PB_Image_Transparent)
   CompilerEndIf

   StartDrawing(ImageOutput(#WaitIcon))

   For i=0 To #WaitLoop-1
      o=#WaitLineY*4+#WaitLineX*2-#WaitWidth*6
      If i>=o
         n=#WaitLineX-#WaitWidth
         direction=3
      Else
         o=#WaitLineY*2+#WaitLineX*2-#WaitWidth*4
         If i>=o
            n=#WaitLineY-#WaitWidth
            direction=2
         Else
            o=#WaitLineY*2-#WaitWidth*2
            If i>=o
               n=#WaitLineX-#WaitWidth
               direction=1
            Else
               o=0
               n=#WaitLineY-#WaitWidth
               direction=0
            EndIf
         EndIf
      EndIf

      mode=i-o
      m=mode/n*n
      n+#WaitWidth
      phase=mode-m

      pos=Bool(m)*phase
      If m
         len=n-phase
      Else
         len=#WaitWidth+phase
      EndIf

      w=#WaitWidth
      h=len
      If direction&1
         Swap w,h
      EndIf

      Select direction
      Case 0
         x=0 : y=n-pos-len
      Case 1
         x=pos : y=0
      Case 2
         x=#WaitLineX-#WaitWidth : y=pos
      Case 3
         x=n-pos-len : y=#WaitLineY-#WaitWidth
      EndSelect

      DrawingMode(#PB_2DDrawing_AllChannels|#PB_2DDrawing_Outlined)
      Box(i*#WaitBox,0,#WaitBox,#WaitHeight,$FFFFFFFF)

      x+i*#WaitBox+#WaitSpace
      y+#WaitSpace-1
      DrawingMode(#PB_2DDrawing_AllChannels)
      Box(x,y,w,h,$FF000000)
      Box(x+1,y+1,w-2,h-2,$FFff7060)
   Next i

   StopDrawing()

EndProcedure
Procedure Update(n)

   GrabImage(#WaitIcon,#WaitTemp,(n%#WaitLoop)*#WaitBox,0,#WaitBox,#WaitHeight)

   CompilerSelect #AntiFlickering
   CompilerCase 0;         32-Bit Image
      If GetKeyState_(#VK_SHIFT)&128
         n=GadgetID(#MakeStateProgress)
         GetClientRect_(n,r)
         ValidateRect_(n,r)
      EndIf
      SetGadgetState(#MakeStateProgress,ImageID(#WaitTemp))

   CompilerCase 1;         24-Bit Image
      Protected Image
      Image=CopyImage_(ImageID(#WaitTemp),#IMAGE_BITMAP,#WaitBox,#WaitHeight,#LR_COPYDELETEORG)
      SetGadgetState(#MakeStateProgress,Image)

   CompilerCase 2;         24-Bit Image & CanvasGadget
      StartDrawing(CanvasOutput(#MakeStateProgress))
      DrawImage(ImageID(#WaitTemp),0,0)
      StopDrawing()

   CompilerEndSelect

EndProcedure

Init()

While #True
   Select WaitWindowEvent()
   Case #PB_Event_CloseWindow
      End
   Case #PB_Event_Timer
      Update(n)
      n+1
   EndSelect
Wend


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye