Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Change color of Progress Bar to show a gradient?


  • Please log in to reply
6 replies to this topic
mb777
  • Members
  • 42 posts
  • Last active: Feb 25 2009 07:06 PM
  • Joined: 08 Jan 2009
Is it possible to make a gradient progress bar?

IE: It gradually changes from 1 color to the other. I have read all the other threads, and have got it so that the whole bar changes gradually, but what I want for the bar that is already showing to remain as it is, so the bar itself becomes a gradient filled rectangle.

Murp-e
  • Members
  • 531 posts
  • Last active: Sep 27 2011 11:44 AM
  • Joined: 12 Jan 2007
Which other threads? Paste the links.

Where's your code? Paste your code.

mb777
  • Members
  • 42 posts
  • Last active: Feb 25 2009 07:06 PM
  • Joined: 08 Jan 2009
OK. Here is my code...

It is part of a big program, so it wont run on its own as it is

#IfWinActive
mapkeys:
	mapanykey:=true
	keyschangedlist:=""
	templistname:=""        ; stores the name of any keylists that are chnaged by user
  gui, 7:+0x300000 +minsize400x600 +resize +owner1
	gui, 7:font,c%txt2color% %txtfontstyle%,%txtfont%
	addlogo(7,logo)
	titlecount:=0   ;Variable to store no. of title rows so we can locate the key in the array assignkey
	titlerows:=0
	titlerownumber:=0
	count:=1
	loop,parse,listlist,|
	{
	tstartpos:=A_loopfield . "startpos"
	count:=%tstartpos%
	loop                                     ;CLEAR THE PREVIOUS TEMP KEYS
	{
		if (prevassignfunction%count%="")
			break
		prevassignfunction%count%:=""
		count++
	}
	}
	count:=1
	totalkeys:=0
	stringreplace,temptotal,allkeylist,|,,UseErrorLevel
	temptotal:=""	
	totalkeys:=errorlevel
	if (totalkeys<=1)
		msgbox ERROR K000 - Can Not Find Any Keys to Map
	stringreplace,temptotal,listlist,|,,UseErrorLevel
	temptotal:=""	
	keylistheaders:=errorlevel
	totalrows:=keylistheaders+totalkeys
	;msgbox errorlevel %errorlevel%
	titletext:="Searching For Currently Mapped Keys"
	Topline:="Please Wait... Finding Mapped Keys"
	keysfoundtext:="0 Mapped Keys Found"
	percentdonetext:="0% Processed"
	
	truecount:=1
	currcol:=""
	
	Progresscollist:="000000,F31839"  ; The colors that the bar will change to as it progresses
	;Progresscollist:="000000,8000ff,F31839"
	stringsplit,col,progresscollist,`,
	progsections:=col0<=2 ? 1 : col0-1   ;the number of sections of different colored sections of the bar
	if (col0=0)            ;          so col0 stores the number of colors in the list 'progresscollist' 
		currcol:="000000"
	else if (col0=1)
		currcol:=col1
	;this popup box shows a quick progress bar, - so this creates the box and bar with 0 progress.
	infoprogressbox(topline,keysfoundtext,titletext,mainwin2color,"",0,txtfont,txtfontstyle,1,percentdonetext,0,progressbegincolor,progressendcolor)	
	colorinterval:=totalkeys/progsections    ; totalkeys = total no. of keys that are mapped (stored in array 'assignkey')
	                                 ;colorinterval 
	; now we create a new window to display a listview of keys that can be re-mapped
	Gui,7:Add, ListView, r%totalrows% count%totalrows% w600 checked grid gassignfunctiontof vmapkeyslistview -mult, Key|Function|Description
	loop,parse,listlist,|   ; listlist ="utility|rubber|hysteria|chat|admin|normal" each of these fields have 2 arrays a 'keylist' and a corresponding 'functionlist'
	{                    ; so the key in keylist is a hotkey that calls the corres function in the function list
		tempstart:=A_LoopField . "startpos" ; they also have a 'startpos' variable which defines where this list starts in the array 'assignkey' and 'assignfunction'
		count:=%tempstart%              ;it leaves room for later additions
		percent:=0
		loop
		{
			if (assignfunction%count%<>"")             ;  this would signifiy the end of a list - (or the whole thing)
			{                                       ; because there are blank entries in the array between each list 
				tempfunction:=assignfunction%count%       ;assignfunction and assignkey are 'parralel' arrays
				tempkey:=assignkey%count%
				prevassignfunction%count%:=tempkey
				tempfuncdesc:=assignfunction%count%
				gui,7:default
				if (count=%tempstart%)
				{
					gui,7:font,%titlefontstyle%,%titlefont%
					gap:=20
					LV_Add("","",A_LoopField . "Key List")
					titlerownumber:=truecount+titlecount        ;   There is probably a better way of doing this - this keeps track of 
					titlerows:=titlerows . titlerownumber . "|"   ; where the title rows are - so we can work out where in the array the key is later on
					;msgbox,,,%A_loopfield%Key List - Row:%titelrownumber%`n`n%titlerows%
					titlecount++
					;gui,7:add,text,y+%gap%,%A_LoopField% Key List
				}	
				else
					gap:= 10
				dropdownlistname:="key" . count
				if (A_index=1)
					LV_add(focus select,tempkey,tempfunction,tempfunction)
				else
					LV_add("",tempkey,tempfunction,tempfunction)
				LV_modifycol()
				;gui, 7:add,dropdownlist,v%dropdownlistname% gduplicatekeycheck x%initcolgap% y+%gap%,%tempkeylist%
				;gui, 7:add,text,x+%slider_padding%,%tempfunction%
				 ;msgbox,,, %tempfunction%.%count%.%dropdownlistname%.tempkey:%tempkey%..`n`n%tempkeylist%,.2
				 ;truecount = a_index - i never realised when i wrote it , and just left it for now!!!
				keysfoundtext:=truecount . " Mapped Keys Found"       ;  data for the infoprogress box
				 percent:=ceil((truecount*(100/totalkeys)))             ;the percentage progress made
				percentdonetext:=percent . "% Processed"              
				howfarsection:=floor(mod(truecount,colorinterval))       ;how far into the current color section the bar is
				currentsection:=floor((truecount//colorinterval)+1)        
				currcol:=col%currentsection%
				nextcol:=currentsection+1
				nextcol:=col%nextcol%
				r1:=substr(currcol,1,2)
				g1:=substr(currcol,3,4)            ; These string functions break the colors into 3 pairs of 2chars
				b1:=substr(currcol,5,6)                 ; These represent the R,G,B values respectively
				r2:=substr(currcol,1,2)
				g2:=substr(currcol,3,4)            ; These string functions break the colors into 3 pairs of 2chars
				b2:=substr(currcol,5,6)                 ; These represent the R,G,B values respectively
				;msgbox,,,%r1%.%g1%.%b1%:%r2%.%g2%.%b2%:%currcol%.%nextcol%,.5
				r1=0x%r1%          ;add 0x at beginning so computer knows it is hex numbers
				g1=0x%g1%
				b1=0x%b1%
				r2=0x%r2%
				g2=0x%g2%
				b2=0x%b2%
				r1+=0             ;This is so the value is converted to DEC
				g1+=0
				b1+=0
				r2+=0
				g2+=0
				b2+=0
				rn:=ceil(r1+((((r2-r1)/colorinterval))*howfarsection))        ;calculation to bring each of the R G B values
				gn:=ceil(g1+((((g2-g1)/colorinterval))*howfarsection))       ;closer to the values of the next color
				bn:=ceil(b1+((((b2-b1)/colorinterval))*howfarsection))       
				SetFormat, integer, hex
				progressnowcolor:=(rn << 16) | (gn << 8) | bn           ;converts these new RGB to a color
				SetFormat, integer, d
				GuiControl, 6:+c%progressnowcolor%,MyProgress
				GuiControl, 6:, MyProgress,%percent%               ; update the infoprogressbox
				GuiControl, 6:, infoMyText,%keysfoundtext%
				GuiControl, 6:, infoBotText,%percentdonetext%
				count++
				truecount++
			}
			else
			{
			;	gui,7: add, button,,SAVE %A_LoopField%keys
				;msgbox,,, breaking,7
				break
			}
		}
	}
	stringtrimright,titlerows,titlerows,1
	 GuiControl, 6:, MyProgress,100
	GuiControl, 6:, infoMyText,%totalkeys% Mapped Keys Found
	GuiControl, 6:, infoBotText,100`% Processed
	sleep 1000
	Gui, 6:destroy
	gui, 7:add,button,y+20 x100 grestorekeys vrestorekeyconfig,RESTORE DEFAULTS
	gui, 7:add,button, x+50 gsavexitkeys vsavekeyconfig,SAVE AND EXIT
	gui, 7:add,button, x+50 gcancelkeys vcancelkeyconfig,CANCEL
	gui, 7:show,h600,Key Mapper
	Gui, 7: +LastFound
	GroupAdd, W7Gui, % "ahk_id " . WinExist()
	gui, 7:submit,nohide
	;gui, 1:+disabled
	gui, 7:color,%mainwin2color%,%control2color%
return





infoprogressbox(toptext ="",bottext ="",title ="PROCESSING...",alertcolor ="e6573e"
,ispicture="",pich =20,font ="Arial",fontsize =12,isprogress =0,mytexttext ="`%",x =0,progressbegincolor ="000000",progressendcolor ="f31839")
{
	
	SysGet, maxpix, Monitor        ;stores the coords of top left,topright,bot left, and bot rt of screen
	Gui, 6:Color, %alertcolor%
	gui, 6:font,s%fontsize%,%font%
	ypos:=10
	
	gui 6:-sysmenu
	yvar:=ypos+pich+10
	;msgbox %yvar%.%ypos%.%pich%

	global infotoptext,infobottext
	gui, 6:add, text,center vinfotoptext y%yvar%,%toptext%  
	
	if isprogress
	{	
		global myprogress
		global infomytext
		Gui, 6:Add, Progress,x30 h15 c%progressbegincolor% vmyprogress w200
		Gui, 6:Add, Text, vinfomytext wp center,%mytexttext% ; wp means "use width of previous".
	}
	;gui, 6:show,x%maxpixright%-320 y%maxpixbottom%, %title%  ;SOUND SCHEME %A_loopfilename% IS EMPTY
	gui, 6:add, text,center y+1 vinfobottext,%bottext%  
	
	x:=x=0 ? A_Caretx+20 : x
	y:=A_Carety
	 ;gui, 6:show,x%x% y%maxpixbottom% autosize, %title% 
	 gui, 6:show,x%x% y%y% autosize, %title%  
	 if (ispicture<>"")
	{
		addlogo(6,ispicture,ypos,pich,title)
	
	}
	
	return
}





addlogo(winnumber,pic="",ypos =10,pich="",wintitle="")  ;centres a pic in a window horizontally
{                           ;no matter what size window
 ;msgbox ,,,%wintitle%.%pic%,7
	if (wintitle <>"")
	{
		wingetpos,,,winwidth,ahk_id%wintitle%
		}
	else
		wingetpos,,,winwidth
	gui, %winnumber%:add,picture,hwndpichandle y%ypos% h%pich% w-1,%pic%
	controlgetpos,,,picwidth,picheight,, ahk_id%pichandle%
	xco:=(winwidth/2)-(picwidth/2)
	;msgbox %winwidth%.%xco%.%picwidth%.%picheight%.%pichandle%.%wintitle%
	controlmove,,xco,,,,ahk_id%pichandle%
	return pichandle
}




So, at the moment it is successful - but not what i really wanted. The whole bar changes color as it progresses.

What I want is for the bar to be a gradient filled rectangle when it has finished.

evan
  • Guests
  • Last active:
  • Joined: --
hand made progress bar:
(modify from http://www.autohotke... ... 1081#61081)
be creative, u can make one with gui too
w=0
IfNotExist, bg.bmp
URLDownloadToFile
, http://autohotkey.net/goyyah/Tips-N-Tricks/Gradients/bg.bmp
, bg.bmp

Gui, Margin, 0,0
Gui, Add, Picture, x30 y150 w2 h30 vTHIS, bg.bmp
Gui, Show, w300 h300
settimer, bb, 20
Return

GuiClose:
GuiEscape:
 ExitApp
Return

aa:
w-=2
GuiControl, Move, THIS, w%w%

if w < 0
{
settimer, aa, off
settimer, bb, on
}
return

bb:
w+=2
GuiControl, Move, THIS, w%w%
if w > 200
{
settimer, bb, off
settimer, aa, 20
}
return






Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I think the gradient color changes have to be horizontal, not vertical.
If you rotate Skan's bg.bmp to the right (e.g. with Irfanview), and save it as bh.bmp (62 Bytes), the following script does the trick:
w=0
Gui Add, Picture, w200 h10 hwndBAR, bh.bmp
Gui Show
SetTimer bar, 1
Return

bar: ; 1 <= width <= 200
    WinSet Region, % "0-0 H10 W" w:=1+mod(w,200), ahk_id %BAR%
Return
Of course, you can generate the desired bmp file with SKAN's code, directly:
; SKAN: http://www.autohotkey.com/forum/viewtopic.php?p=61081#61081
CreateBMPGradient("bh.bmp", "FF0000", "FF", 0)    ; Horizontal gradient, Red -> Blue

CreateBMPGradient(File, RGB1, RGB2, Vertical=1) { ; Left/Bottom -> Right/Top color, File is overwritten
   If Vertical
     H:="424d3e000000000000003600000028000000010000000200000001001800000000000800000000000000000000000000000000000000"
       . BGR(RGB1) "00" BGR(RGB2) "00"
   Else
     H:="424d3e000000000000003600000028000000020000000100000001001800000000000800000000000000000000000000000000000000"
       . BGR(RGB1) BGR(RGB2) "0000"

   Handle:= DllCall("CreateFile",Str,file,Uint,0x40000000,Uint,0,UInt,0,UInt,4,Uint,0,UInt,0)

   Loop 62 {
     Hex := "0x" SubStr(H,2*A_Index-1,2)
     DllCall("WriteFile", UInt,Handle, UCharP,Hex, UInt,1, UInt,0, UInt,0)
    }

   DllCall("CloseHandle", "Uint", Handle)
}

BGR(RGB) {
  RGB = 00000%RGB%
  Return SubStr(RGB,-1) . SubStr(RGB,-3,2) . SubStr(RGB,-5,2)
}