Page 1 sur 1

image statusbar qui clignote

Publié : mer. 14/janv./2015 12:33
par supercdfr
Bonjour,

voici un bout de code pour mettre dans la statusbarimage du texte trouvé sur le net :

Code : Tout sélectionner

Enumeration
  #Window_0
  #statubar
  #font
EndEnumeration

LoadFont(#font, "Arial", 8,#PB_Font_Italic)
Global texte_barre.s = "essai"

Procedure StatusBarEx(fID,iNo,x,y,w,h,Text$,bColor,fColor)
  CreateImage(iNo,w,h)
  StartDrawing(ImageOutput(iNo))
    Box(0, 0, w,h,bColor)
    DrawingFont(FontID(#font))
    DrawingMode(#PB_2DDrawing_Transparent)  
    FrontColor(fColor)
    DrawText(x, y, Text$ ,fColor)
  StopDrawing()
EndProcedure

Procedure thread_flash(valeur.l)
  boucle_flash:
  buffer = 0
  For flash_i = 0 To 255
    StatusBarEx(0,8998,0,0,915,15,texte_barre,RGB(flash_i,0,flash_i),$FFFFFF )
    StatusBarImage(#statubar, 0, ImageID(8998))
    Delay(5)
  Next
  For flash_i = 255 To 1 Step - 1
    StatusBarEx(0,8998,0,0,915,15,texte_barre,RGB(flash_i,0,flash_i),$FFFFFF )
    StatusBarImage(#statubar, 0, ImageID(8998))
    Delay(5)
  Next
  Goto boucle_flash
EndProcedure

OpenWindow(#Window_0, 394, 137, 915, 490+135, "test", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
hStatus = CreateStatusBar(#statubar,WindowID(#Window_0) )
AddStatusBarField(534)
AddStatusBarField(60)
    
CreateThread(@thread_flash() , 1)

Repeat
  WaitWindowEvent()
ForEver
Le soucis, c'est que cela clignote et je n'arrive pas a retirer cet effet indesirable.
Quelqu'un saurait ?

Re: image statusbar qui clignote

Publié : mer. 14/janv./2015 14:08
par raven

Code : Tout sélectionner

Enumeration
	#Window_0
	#statubar
	#font
EndEnumeration

LoadFont(#font, "Arial", 8,#PB_Font_Italic)
Global texte_barre.s = "essai"

Procedure StatusBarEx(fID,iNo,x,y,w,h,Text$,bColor,fColor)
	CreateImage(iNo,w,h)
	StartDrawing(ImageOutput(iNo))
		Box(0, 0, w,h,bColor)
		DrawingFont(FontID(#font))
		DrawingMode(#PB_2DDrawing_Transparent)  
		FrontColor(fColor)
		DrawText(x, y, Text$ ,fColor)
	StopDrawing()
EndProcedure

Procedure thread_flash(valeur.l)
	boucle_flash:
	buffer = 0
	For flash_i = 155 To 255 Step -3
		StatusBarEx(0,8998,0,0,915,15,texte_barre,RGB(flash_i,0,flash_i),$FFFFFF )
		StatusBarImage(#statubar, 0, ImageID(8998))
		Delay(45)
	Next
	For flash_i = 255 To 155 Step - 3
		StatusBarEx(0,8998,0,0,915,15,texte_barre,RGB(flash_i,0,flash_i),$FFFFFF )
		StatusBarImage(#statubar, 0, ImageID(8998))
		Delay(45)
	Next
	;Goto boucle_flash
EndProcedure

OpenWindow(#Window_0, 394, 137, 915, 490+135, "test", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
hStatus = CreateStatusBar(#statubar,WindowID(#Window_0) )
AddStatusBarField(534)
AddStatusBarField(60)
		
CreateThread(@thread_flash() , 1)

Repeat
	WaitWindowEvent()
ForEver
en modifiant quelque valeur ?

Re: image statusbar qui clignote

Publié : mer. 14/janv./2015 16:41
par falsam
En oubliant la gestion des threads en utilisant à la place les timers.
supercdfr a écrit :voici un bout de code pour mettre dans la statusbarimage du texte trouvé sur le net :
Je supose que le texte reste quelques secondes ? avec ce code le texte reste une seconde (1000 ms) tu peux modifier cette valeur pour que le texte reste plus longtemps.

Code : Tout sélectionner

Enumeration Timer
  #Timer
EndEnumeration

Enumeration
  #Window_0
  #statubar
  #font
EndEnumeration

LoadFont(#font, "Arial", 8, #PB_Font_Italic)
Global texte_barre.s = "Essai d'image"

Global flash_i, Image, s=1

Procedure StatusBarEx(fID,iNo,x,y,w,h,Text$,bColor,fColor)
  CreateImage(iNo,w,h)
  StartDrawing(ImageOutput(iNo))
    Box(0, 0, w,h,bColor)
    DrawingFont(FontID(#font))
    DrawingMode(#PB_2DDrawing_Transparent)  
    FrontColor(fColor)
    DrawText(x, y, Text$ ,fColor)
  StopDrawing()
EndProcedure

Procedure flash()
  If flash_i = 250 
    s = -10
  EndIf
  
  If flash_i = 1
    s = 10
  EndIf
  
  Image + 1
  
  flash_i + s
  StatusBarEx(0,8998,0,0,915,15,texte_barre + " " + Str(Image),RGB(flash_i,0,flash_i),$FFFFFF )
  StatusBarImage(#statubar, 0, ImageID(8998))
  
EndProcedure

OpenWindow(#Window_0, 394, 137, 915, 490+135, "test", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)

Result = CreateStatusBar(#statubar, WindowID(#Window_0) )
AddStatusBarField(534)
AddStatusBarField(60)

AddWindowTimer(#Window_0, #Timer, 1000)
BindEvent(#PB_Event_Timer, @flash(), #Window_0, #Timer)

Repeat : Until WaitWindowEvent(10) = #PB_Event_CloseWindow

Re: image statusbar qui clignote

Publié : mer. 14/janv./2015 16:54
par supercdfr
Merci pour vos codes.

Pour RAVEN, j'avais aussi essayé de rallonger le timer, mais le changement de couleur est alors trop lent.

Pour FALSAM, c'est vrai que c'est mieux, même si un petit clignotement peut arriver.

Re: image statusbar qui clignote

Publié : jeu. 15/janv./2015 17:07
par Marc56
Ceci ne répondra peut être pas à ce que tu demande, mais ça peut servir à d'autres utilisations.
J'ai créé ce petit bout de code pour attirer l'attention de l'utilisateur sur la StatusBar en faisant clignoter une icône :idea:
(en attendant le jour où PB gèrera peut être nativement le format gif qui est maintenant dans le domaine public)

Je rejoins le conseil de falsam: pas besoin d'utiliser un thread, on peut tout faire avec un Timer :wink:

Code : Tout sélectionner

; Faire clignoter une icône dans la StatusBar

EnableExplicit

Enumeration
	#Window_Main
	#Led_Red
	#Led_Green
	#Timer_1
EndEnumeration

CreateImage(#Led_Red, 	15, 15, 24, $0000FF)	; Carré rouge de 15x15
CreateImage(#Led_Green, 15, 15, 24, $00FF00)	; Carré vert  de 15x15

OpenWindow(#Window_Main, 0, 0, 300, 200, "Blink", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	CreateStatusBar(0, WindowID(#Window_Main))
		AddStatusBarField(#PB_Ignore)

AddWindowTimer(#Window_Main, #Timer_1, 1000) 
Global Event, Alterner

Repeat
	Event = WaitWindowEvent(10)
	If Event = #PB_Event_Timer And EventTimer() = #Timer_1
		If Alterner = 1 
			Alterner = 0
			StatusBarImage(0, 0, ImageID(#Led_Red))
		Else
			Alterner = 1
			StatusBarImage(0, 0, ImageID(#Led_Green))
		EndIf
	EndIf
Until Event = #PB_Event_CloseWindow
J'ai simplifié la démo à l’extrême pour expliquer le principe.
Pour alterner les deux images, j'utilise le même principe qu'en PHP pour alterner les lignes de couleur d'un tableau.

:wink: