Jump to content


Photo

[SOLVED] Use Progress bar as a Slider? Set value by click


  • Please log in to reply
11 replies to this topic

#1 Cephei1

Cephei1
  • Members
  • 388 posts

Posted 31 May 2012 - 06:47 PM

Hi

Im trying to make a progress bar that you use as a slider (for Video purpose). Is this at all possible other than using a Slider?

Thanks

#2 Pulover

Pulover
  • Members
  • 1251 posts

Posted 31 May 2012 - 08:17 PM

Hi, there!
I don't know if there is a script like this around already, but I thought it would be fun to make one! :D
I had an idea to use OnMessage to move the progress bar to mouse position on click, so I used part of a script I had to get that.

You may consider this as a starting point for your project:
; ProgressBar Slider by Pulover

CoordMode, Mouse, Window

PBarSize := 300  ; Choose Progress Bar width in pixels.
Prop := PBarSize / 100 * 10

SetFormat, Float, 2.0  ; For the Tooltip only.
Gui, +Owner +LastFound +AlwaysOnTop +ToolWindow -Caption
Gui, Add, Progress, xm-10 w%PBarSize% h20 cGreen vMyProgress R0-100, 100
Gui, Show, w%PBarSize%
OnMessage(0x201, "WM_LBUTTONDOWN")  ; Monitors Left Clicks on Gui.
return

WM_LBUTTONDOWN(wParam, lParam)
{
   MouseGetPos, mX,,, control
   If control <> msctls_progress321  ; If the click wasn't in the progress bar, do nothing.
      return
   SetTimer, WatchCursor, 0
}

WatchCursor:
If !GetKeyState("LButton", "P")
{
   Tooltip
   SetTimer, WatchCursor, off
   return
}
MouseGetPos, mX  ; Gets mouse position relative to the Window.
X := mX * 10 / Prop
Tooltip, % PBar(X)
GuiControl,, MyProgress, %X%  ; Sets progress bar to mouse position.
return

GuiEscape:
ExitApp

PBar(X)
{
	If X < 0
		return 0
	If X > 100
		return 100
	Else
		return X
}

Edit: Added a function to avoid tooltip showing numbers out of range and a variable to set width to make it easier to adjust proportion.

#3 Cephei1

Cephei1
  • Members
  • 388 posts

Posted 31 May 2012 - 09:06 PM

Brilliant. Thanks so much!

#4 Pulover

Pulover
  • Members
  • 1251 posts

Posted 31 May 2012 - 09:44 PM

Brilliant. Thanks so much!

You're welcome!

#5 Cephei1

Cephei1
  • Members
  • 388 posts

Posted 31 May 2012 - 10:41 PM

Now i've got another problem. I get this error if I have a formula enter the value like so:
VLC.input.time := (VLC.input.length*((Pos-ProgX)/ProgW+1))
But no error if I enter the value directly like so:
VLC.input.time := 50000

Why is this? I checked the output of the formula and it's flawless.

Posted Image

#6 Pulover

Pulover
  • Members
  • 1251 posts

Posted 31 May 2012 - 11:06 PM

I can't say I know what this means, but does it have to do with the format I used for the tooltip, maybe? (SetFormat, Float, 2.0). Did you remove this part?

#7 Cephei1

Cephei1
  • Members
  • 388 posts

Posted 31 May 2012 - 11:16 PM

I have this instead:
SetFormat, Float, 0.0
Any ideas

#8 JSLover

JSLover
  • Members
  • 920 posts

Posted 31 May 2012 - 11:19 PM

Your version is very specific to the placement of the Progress bar in the window (& the margins of the window).

I wanna support any Progress bar size (width/range), anywhere in the window (X/Y).

This is what I have so far...

Clickable-Progress-Bar.ahk
...I'm still working on it, but can someone edit it so that you can click in ANY of the Progress bars & have it work correctly?

Mostly I need help with the math/formula, I'm trying to get the offset of the Progress bar in the window, into the calculations...I also want it to support Progress bars with different widths & ranges.

After all that, then I'm gonna tackle vertical Progress bars.

#9 Cephei1

Cephei1
  • Members
  • 388 posts

Posted 31 May 2012 - 11:37 PM

Okay here's something weird. If I add a MsgBox like this, the error does not come up. :O Any ideas what's the cause?
WatchCursor:
	If (GetKeyState("LButton","P") = 0) {
		Pos:="", ProgX:="", ProgW:=""
		SetTimer, WatchCursor, Off
	}

	MouseGetPos, Pos, , , Control
	If (Control = "msctls_progress321") {
		vlc.input.time := RegExReplace(vlc.input.length*(Pos-ProgX)/ProgW,"\..*","")
		[color=#FF0000]MsgBox, Random message[/color]
	}
Return


#10 Cephei1

Cephei1
  • Members
  • 388 posts

Posted 01 June 2012 - 12:10 AM

Okay I figured out what was causing the error. I was was clearing out the variables too early:
WatchCursor:

	If (GetKeyState("LButton","P") = 0) {

		[color=#FF0000]Pos:="", ProgX:="", ProgW:=""[/color]

		SetTimer, WatchCursor, Off

		[color=#FF0000]Return[/color] ; [color=#008000]I forgot to add the  "Return". After clearing the variables, it continued onto the VLC.INPUT.TIME and that caused the error.[/color]

	}

	MouseGetPos, Pos, , , Control

	If (Control = "msctls_progress321")

		vlc.input.time := vlc.input.length * (Pos-ProgX)/ProgW

Return


#11 Pulover

Pulover
  • Members
  • 1251 posts

Posted 01 June 2012 - 02:56 PM

Like I said above, that was a starting point I made using another script I had. I decided to improve it, so I updated the code to support more then one bar and work independent of size and position in the gui.

Progress Bar Slider

@JSLover: If you're going to use my code as a base, it's ok, but you could at least mention it in the credits...

#12 JSLover

JSLover
  • Members
  • 920 posts

Posted 01 June 2012 - 11:19 PM

...but you could at least mention it in the credits...

...my script doesn't have a "credits" section.

But anyway, your code & my code are almost completely different. I changed nearly every line. I also have comments on your new code (that I will post in your new topic). You still have some useless lines (that I removed in my version & you put back) & some of the lines that you adopted from my code, you changed a little, which changed the meaning.