How to reduce flickering for StatusBarImage?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2680
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

How to reduce flickering for StatusBarImage?

Post by Michael Vogel »

Here's a simple code which does flicker from time to time...

Code: Select all


; Define

	Enumeration
		#WinMake

		#MakeCommand
		#MakeProgram
		#MakeInfo
		#MakeProgress
		#MakeBorderIQ
		#MakeButtonIQ
		#MakeButtonProject
		#MakeButtonOk
		#MakeButtonReset
		#MakeButtonClose
		#MakeCommandText
		#MakeProgramText

		#MakeDirJavaText
		#MakeDirJavaEdit
		#MakeDirJavaButton
		#MakeDirIqText
		#MakeDirIqEdit
		#MakeDirIqButton
		#MakeDirSourceText
		#MakeDirSourceEdit
		#MakeDirSourceButton
		#MakeDirScanButton
		#MakeCmd
		#MakeEnd

	EndEnumeration

	OpenWindow(#WinMake,0,0,500,250,"Make projekt...",#PB_Window_Invisible|#PB_Window_SystemMenu)
	TextGadget(#MakeCommandText,10,20,60,24,"Project:",#SS_CENTERIMAGE)
	StringGadget(#MakeCommand,70,20,418,24,"..")
	;TextGadget(#MakeInfo,12,10,378,24,"",#SS_CENTERIMAGE)
	;TextGadget(#MakeProgress,10,40,300,20,"",#SS_CENTERIMAGE)
	;TextGadget(#MakeBorderIQ,9,61,40,30,"")
	ButtonGadget(#MakeButtonIQ,69,62,46,28,"v")
	ButtonGadget(#MakeButtonProject,125,62,120,28,"&Set project...")
	;ButtonGadget(#MakeButtonReset,168,62,100,28,"&Default values")
	ButtonGadget(#MakeButtonOk,278,62,100,28,"&Make...",#PB_Button_Default)
	ButtonGadget(#MakeButtonClose,389,62,100,28,"&Close")

	TextGadget(#MakeDirJavaText,10,114,60,24,"Java SDK:",#SS_CENTERIMAGE)
	StringGadget(#MakeDirJavaEdit,70,114,352,24,"mmm")
	ButtonGadget(#MakeDirJavaButton,431,113,58,26,"Browse")

	TextGadget(#MakeDirIqText,10,147,65,24,"ConnectIQ:",#SS_CENTERIMAGE)
	StringGadget(#MakeDirIqEdit,70,147,352,24,"make")
	ButtonGadget(#MakeDirIqButton,431,146,58,26,"Browse")

	TextGadget(#MakeDirSourceText,10,180,65,24,"Sources:",#SS_CENTERIMAGE)
	StringGadget(#MakeDirSourceEdit,70,180,352,24,"make")
	ButtonGadget(#MakeDirSourceButton,431,179,58,26,"Browse")

	#ProgressLen=420
	CreateStatusBar(#Null,WindowID(#WinMake))
	AddStatusBarField(72)
	AddStatusBarField(#ProgressLen+8)
	StatusBarText(0,0,"Hi",#PB_StatusBar_Center)
	CreateImage(0,#ProgressLen,16,32,#PB_Image_Transparent)
	StartDrawing(ImageOutput(0))
	DrawingMode(#PB_2DDrawing_AlphaBlend)
	Box(0,0,#ProgressLen,15,$FF000000)
	StopDrawing()
	;StatusBarImage(0,1,ImageID(0))
	StatusBarText(0,1,"Hi",#PB_StatusBar_Center)

	;	SetGadgetColor(#MakeBorderIQ,#PB_Gadget_BackColor,#Red)

; EndDefine

HideWindow(#WinMake,0)

Global t=0

AddWindowTimer(#WinMake,0,100)
Repeat
	Select WaitWindowEvent()
	Case #PB_Event_Gadget
		Select EventGadget()
			Case #MakeButtonIQ
				DisableGadget(#MakeDirJavaEdit,Ws)
				DisableGadget(#MakeDirIqEdit,Ws)
				DisableGadget(#MakeDirSourceEdit,Ws)
				Ws!1
				ResizeWindow(#WinMake,#PB_Ignore,#PB_Ignore,#PB_Ignore,130+Ws*140)
			Case #MakeButtonClose
				End
		EndSelect
		
	Case #PB_Event_CloseWindow
		End
	Case #PB_Event_Timer
		t+1
		StartDrawing(ImageOutput(0))
		DrawingMode(#PB_2DDrawing_AlphaBlend)
		Box(1,1,t,13,$FF00FF00)
		Box(t+1,1,#ProgressLen-2-t,13,$FFE0E0E0)
		StopDrawing()
		StatusBarImage(0,1,ImageID(0))
		StatusBarText(0,0,Str(t),#PB_StatusBar_Center)

	EndSelect

ForEver

RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: How to reduce flickering for StatusBarImage?

Post by RASHAD »

Hi MV
Workaround

Code: Select all

; Define

   Enumeration
      #WinMake

      #MakeCommand
      #MakeProgram
      #MakeInfo
      #MakeProgress
      #MakeBorderIQ
      #MakeButtonIQ
      #MakeButtonProject
      #MakeButtonOk
      #MakeButtonReset
      #MakeButtonClose
      #MakeCommandText
      #MakeProgramText

      #MakeDirJavaText
      #MakeDirJavaEdit
      #MakeDirJavaButton
      #MakeDirIqText
      #MakeDirIqEdit
      #MakeDirIqButton
      #MakeDirSourceText
      #MakeDirSourceEdit
      #MakeDirSourceButton
      #MakeDirScanButton
      #MakeCmd
      #MakeEnd

   EndEnumeration
   
   Global t=0
   
Procedure Status()
  t+1
  SetGadgetState(102,t)
  SetGadgetText(101,Str(t))
  If t >= 420
    t = 0
  EndIf
EndProcedure

   OpenWindow(0,0,0,500,270,"Make projekt...",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   TextGadget(#MakeCommandText,10,20,60,24,"Project:",#SS_CENTERIMAGE)
   StringGadget(#MakeCommand,70,20,418,24,"..")
   TextGadget(#MakeInfo,12,10,378,24,"",#SS_CENTERIMAGE)
   TextGadget(#MakeProgress,10,40,300,20,"",#SS_CENTERIMAGE)
   TextGadget(#MakeBorderIQ,9,61,40,30,"")
   ButtonGadget(#MakeButtonIQ,69,62,46,28,"v")
   ButtonGadget(#MakeButtonProject,125,62,120,28,"&Set project...")
   ButtonGadget(#MakeButtonReset,168,62,100,28,"&Default values")
   ButtonGadget(#MakeButtonOk,278,62,100,28,"&Make...");,#PB_Button_Default)
   ButtonGadget(#MakeButtonClose,389,62,100,28,"&Close")

   TextGadget(#MakeDirJavaText,10,114,60,24,"Java SDK:",#SS_CENTERIMAGE)
   StringGadget(#MakeDirJavaEdit,70,114,352,24,"mmm")
   ButtonGadget(#MakeDirJavaButton,431,113,58,26,"Browse")

   TextGadget(#MakeDirIqText,10,147,65,24,"ConnectIQ:",#SS_CENTERIMAGE)
   StringGadget(#MakeDirIqEdit,70,147,352,24,"make")
   ButtonGadget(#MakeDirIqButton,431,146,58,26,"Browse")

   TextGadget(#MakeDirSourceText,10,180,65,24,"Sources:",#SS_CENTERIMAGE)
   StringGadget(#MakeDirSourceEdit,70,180,352,24,"make")
   ButtonGadget(#MakeDirSourceButton,431,179,58,26,"Browse")
;    
 

   #ProgressLen=420
    FrameGadget(100,1,WindowHeight(0)-30,72,30,"")
    TextGadget(101,5,WindowHeight(0)-20,60,20,"",#PB_Text_Center)
    ProgressBarGadget(102, 72,WindowHeight(0)-24, 428,  24, 0, 428)
    


AddWindowTimer(#WinMake,0,100)
BindEvent(#PB_Event_Timer,@status())
Repeat
   Select WaitWindowEvent()
   Case #PB_Event_Gadget
      Select EventGadget()
         Case #MakeButtonIQ
            DisableGadget(#MakeDirJavaEdit,Ws)
            DisableGadget(#MakeDirIqEdit,Ws)
            DisableGadget(#MakeDirSourceEdit,Ws)
            Ws!1
            ResizeWindow(#WinMake,#PB_Ignore,#PB_Ignore,#PB_Ignore,130+Ws*140)
         Case #MakeButtonClose
            End
      EndSelect
      
   Case #PB_Event_CloseWindow
      End
 
   EndSelect

ForEver

Or
As long as you are using Windows (#SS_CENTERIMAGE)

Code: Select all

If OpenWindow(0, 100, 150, 300, 100, "PureBasic - StatusBar Example", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
 
  sWhnd= CreateStatusBar(0, WindowID(0))
  If hstatus
    AddStatusBarField(#PB_Ignore)
    AddStatusBarField(200)
  EndIf
  pWhnd = ProgressBarGadget(0, 120, 2,160, 20, 0,100,#PB_ProgressBar_Smooth)
  SetParent_(pWhnd,sWhnd)  
  SetGadgetState (0,50)

  Repeat
   
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Egypt my love
User avatar
Michael Vogel
Addict
Addict
Posts: 2680
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: How to reduce flickering for StatusBarImage?

Post by Michael Vogel »

Thanks Rashad,
good approach. Actually it looks like I will do something completely different by adding an image (or canvas) gadget within the window (but not in the status bar area) which works smoother. Actually I am playing around to create a wait symbol animation, here's one of my test codes...

Code: Select all


; each image has to be shrinked and placed in one large image containing the complete animation

#Arc=80

Global Dim iSin(#Arc)
Global Dim iCos(#Arc)

For i=0 To #Arc
	iSin(i)=-Sin(#PI/#Arc*2*i)*50
	iCos(i)=Cos(#PI/#Arc*2*i)*50
Next i

OpenWindow(0,100,200,160,160,"")
CanvasGadget(0,0,0,160,160)
AddWindowTimer(0,0,50)

Repeat

	Select WaitWindowEvent()
	Case #PB_Event_Timer
		rot+1

		StartDrawing(CanvasOutput(0))
		Box(0,0,160,160,#White)
		For i=0 To 7
			Circle(iSin(i*#Arc/8)+80,iCos(i*#Arc/8)+80,3,$ff6060)
		Next i
		x1=iSin(rot%#Arc)+80
		y1=iCos(rot%#Arc)+80
		Circle(x1,y1,9,#Blue)

		z=rot%10
		
		If z>2 And z<5
			Debug ""+rot+", "+z
			For i=-3 To -1
				p=(rot+i+#Arc)%#Arc
				Circle(iSin(p)+80,iCos(p)+80,z+6+i*2,#Blue)
			Next i
		EndIf
		If z>4 And z<8
			Debug ""+rot+", "+z
			For i=0 To 3
				p=(rot+i+#Arc)%#Arc
				Circle(iSin(p)+80,iCos(p)+80,z+1-i,#Blue)
			Next i
		EndIf


		StopDrawing()
	Case #PB_Event_CloseWindow
		End
	EndSelect

ForEver
User avatar
skywalk
Addict
Addict
Posts: 4003
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: How to reduce flickering for StatusBarImage?

Post by skywalk »

Nice, but use the vector drawing lib to get free anti-aliased lines.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
firace
Addict
Addict
Posts: 903
Joined: Wed Nov 09, 2011 8:58 am

Re: How to reduce flickering for StatusBarImage?

Post by firace »

Perhaps another idea (but needs some work to adapt to your needs, as it's using sprites and a WindowedScreen)

Code: Select all

InitSprite() :  W=750 : H=540  : C = $324F72 
Define cx = 260, cy = cx

OpenWindow(0, 35, 35, W, H, "E8", #PB_Window_SizeGadget|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0),0,0,W+1,H,1,0,0)  : AddWindowTimer(0, 1, 110)

CreateSprite(33, W/2+200 ,W/2+200 ) 
CreateSprite(34, W/2  ,W/2  )   
CreateSprite(35, W/4  ,W/4 )   

Repeat 
  Select WaitWindowEvent()
    Case #PB_Event_Timer :
      
      StartDrawing(SpriteOutput(33)) 
      
      For i = 0 To 359 
        Color = $62A616 ; If i<70 : Color = $fefefe : EndIf 
        If i > 65 
          Circle(cx + Sin(Radian(i)) * (cx - 5) + 25, cy + Cos(Radian(i)) * (cx - 5) + 25, 6, color) 
        EndIf
      Next
      
      StopDrawing()  
      If z=0 :  CopySprite(33,34)  : ZoomSprite(34,W/2,W/2)   
      CopySprite(33,35)  : ZoomSprite(35,W/6,W/6)   : z=1 : EndIf
      
      x = 0 :  
      Repeat : x+1
        ClearScreen(0) 
        RotateSprite(33, 9,#PB_Relative) : DisplayTransparentSprite(33,W/4 -110 ,H/4 -150, 231) 
        RotateSprite(34,-9,#PB_Relative) : DisplayTransparentSprite(34,W/4 + 5 ,H/4 - 40 , 231 )
        RotateSprite(35, 9,#PB_Relative) : DisplayTransparentSprite(35,W/4 +100 ,H/4 +100, 231) 
        FlipBuffers()
      Until x = 8
      
    Case #PB_Event_CloseWindow :   Break
      
  EndSelect
ForEver
Post Reply