AutoHotkey Community

It is currently May 27th, 2012, 12:19 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Dual slider
PostPosted: November 1st, 2008, 5:37 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Sometimes we need to move two sliders in one scale, e.g. to set upper and lower limits. This little script (tested on Vista-32) simulates this by drawing two slider controls on top of each other, and cut off their unneeded parts. The variables 0 <= 2Slid1 <= 2Slid2 <= 100 correspond to the current slider positions.
Code:
2Slid1 := 25, 2Slid2 := 75 ; current positions of the two sliders (0..100)
2SlidW := 199              ; the width of the scale
2SlidK := 2SlidW/100, 2SlidU := 2SlidW+18, 2SlidV := 2SlidU-1 ; auxiliary variables
Loop 2
  Gui Add, Slider
 ,x0 y0 w%2SlidU% v2Slid%A_Index% g2Slid%A_Index% hwnd2SlidHwnd%A_Index% AltSubmit Range0-100 TickInterval10 Thick13 -Theme ToolTip
GoSub 2Slid
Gui Show
Return

2Slid1:
   2Slid2 := 2Slid1 < 2Slid2 ? 2Slid2 : 2Slid1
   GoTo 2Slid
2Slid2:
   2Slid1 := 2Slid1 < 2Slid2 ? 2Slid1 : 2Slid2
2Slid:
   GuiControl,,2Slid1, %2Slid1%
   GuiControl,,2Slid2, %2Slid2%
   2SlidX := round(2SlidK*2Slid1+13)
   WinSet Region,% "1-1 " 2SlidX "-1 " 2SlidX "-19 1-19", ahk_id %2SlidHwnd1%
   WinSet Region,% 2SlidX "-1 " 2SlidV "-1 " 2SlidV "-19 " 2SlidX "-19", ahk_id %2SlidHwnd2%
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2008, 1:49 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Here is a vertical version, with red line between the sliders:
Code:
2Slid1 := 25, 2Slid2 := 75 ; current positions of the two sliders (0..100)
2SlidH := 123              ; the height of the scale
2SlidK := 2SlidH/100, 2SlidU := 2SlidH+19, 2SlidV := 2SlidU-1 ; auxiliary variables
Gui Add, Progress, x5 y10 w3 h%2SlidH% Vertical BackgroundRed Disabled
Loop 2
 Gui Add, Slider, x0 y0 h%2SlidU% v2Slid%A_Index% g2Slid%A_Index% hwnd2SlidHwnd%A_Index% AltSubmit Range0-100 TickInterval10 Thick13 -Theme ToolTip Vertical
GoSub 2Slid
Gui -Border
Gui Show
Return

2Slid1:
   2Slid2 := 2Slid1 < 2Slid2 ? 2Slid2 : 2Slid1
   GoTo 2Slid
2Slid2:
   2Slid1 := 2Slid1 < 2Slid2 ? 2Slid1 : 2Slid2
2Slid:                     ; cut L shape from top slider, box of bottom slider to show background
   GuiControl,,2Slid1, %2Slid1%
   GuiControl,,2Slid2, %2Slid2%
   2SlidY := round(2SlidK*2Slid1+13)
   2SlidZ := round(2SlidK*2Slid2+6)
   WinSet Region,% "1-1 1-" 2SlidY " 15-" 2SlidY " 15-" 2SlidV  " 19-" 2SlidV " 19-1", ahk_id %2SlidHwnd1%
   WinSet Region,% "1-" 2SlidZ " 1-" 2SlidV " 15-" 2SlidV " 15-" 2SlidZ, ahk_id %2SlidHwnd2%
Return

Edit 20081109: fixed copy/paste error found by DerRaphael (thanks!)


Last edited by Laszlo on November 9th, 2008, 10:28 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2008, 2:35 am 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
hey laszlo, nice work. the 2nd example however shows only one slide at my box (win2k sp2)

this is a version which relies on tic's gdip libraries. its basically his example #9 which is modified a little so a mouseclick on the graphic sets left / right boundary. the global variable pWidth stores the set width of the displayed graphic wheras pStart / pEnd are the boundaries.

Code:
; gdi+ ahk tutorial 9 written by tic (Tariq Porter) lil mod by derRaphael
; Requires Gdip.ahk either in your Lib folder as standard library or using #Include
;
; Example to create a dual progress bar in a standard gui
; see http://www.autohotkey.net/~tic/Gdip.Tutorial.9-Create.a.progress.bar.on.standard.gui.ahk
; and http://www.autohotkey.com/forum/viewtopic.php?t=32238 for details

#SingleInstance, Force
#NoEnv
SetBatchLines, -1
#Include, Gdip.ahk

; Start gdi+
If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit

Gui, 1:Margin,10,10
Gui, 1: Add, Picture, w400 h50 0xE vProgressBar gClick
Gui, 1: Show, AutoSize, GDIP Example 9.2
pStart:=100,pEnd:=300,pWidth:=200
Gdip_SetProgress(ProgressBar,pStart,pWidth,0xff0993ea, 0xffbde5ff, pStart "/" pEnd)
Return

Click:
   MouseGetPos,x,y,w,c,2
   GuiControlGet, Pos, Pos, ProgressBar
   GuiControlGet, hwnd, hwnd, ProgressBar
   if (c=hwnd) {
      if (x<posw//2-4)
         pStart := x-14
      else if (x>posw//2-4)
         pEnd := x-14
      pWidth := pEnd - pStart
      Gdip_SetProgress(ProgressBar,pStart,pWidth,0xff0993ea, 0xffbde5ff, pStart "/" pEnd)
   }
return

Gdip_SetProgress(ByRef Variable, pStart, pEnd, Foreground, Background=0x00000000, Text="", TextOptions="x0p y15p s60p Center cff000000 r4 Bold", Font="Arial")
{
   GuiControlGet, Pos, Pos, Variable
   GuiControlGet, hwnd, hwnd, Variable
   pBrushFront := Gdip_BrushCreateSolid(Foreground), pBrushBack := Gdip_BrushCreateSolid(Background)
   pBitmap := Gdip_CreateBitmap(Posw, Posh), G := Gdip_GraphicsFromImage(pBitmap), Gdip_SetSmoothingMode(G, 4)
   Gdip_FillRectangle(G, pBrushBack, 0, 0, Posw, Posh)
   Gdip_FillRoundedRectangle(G, pBrushFront, 4+pStart, 4, pEnd-4, Posh-8, 3)
   Gdip_TextToGraphics(G, Text, TextOptions, Font, Posw, Posh)
   hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
   SetImage(hwnd, hBitmap)
   Gdip_DeleteBrush(pBrushFront), Gdip_DeleteBrush(pBrushBack)
   Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
   Return, 0
}

GuiClose:
Exit:
   Gdip_Shutdown(pToken)
   ExitApp
Return


This example is not perfect and lacks a few things (such as redraw upon lost and reset focus) - but it shows the idea

greets
dR

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2008, 4:31 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
DerRaphael wrote:
the 2nd example however shows only one slide at my box (win2k sp2)
The advantage of the script is its simplicity and very smooth operation. However, it depends on the sizes of the slider control in XP/Vista. In W2K you should play with the constants. I don’t know a simple way to find out the distance of the active parts from the edges of the control in the script, the size of the slider, etc.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2008, 11:45 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
DerRaphael wrote:
... the 2nd example however shows only one slide at my box...


This was happening on my XP box as well.

Both sliders are there, but there is something 'off' in the script and you can't grab the first one.
If you press the 'Down Arrow' on your keyboard, it will move down and then you can grab it.

Image

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2008, 12:38 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Strange. It works OK in my XP SP3 laptop and Vista SP1 desktop. The only problem is if you move a slider really fast, pieces of the red bar might remain shown. Try to change the constants a little, and post here a version, which works in your PC.

The dots on the top are a piece of the border of a slider. This could show up if the initial value of the sliders (2Slid1 or 2Slid2) are invalid (empty, non-numeric). Could you check if there was no typo in your script, or a copy/paste error?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2008, 6:38 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
Laszlo wrote:
Could you check if there was no typo in your script, or a copy/paste error?


actually i found the typo / copy n paste error. but it was neither in my script nor in SoggyDog's version. but in yours laszlo!

Code:
2Slid1 := 25, 2Slid2 := 75 ; current positions of the two sliders (0..100)
2SlidH := 123             ; the height of the scale
...


the red marked 2 was missed in your original script.

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2008, 10:29 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Oops! I fixed it in the second post. Thanks!

Does it work now in Win2K?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2008, 11:39 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
yes works on win2k aswell

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2008, 5:39 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
Yup... That did the trick.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, Yahoo [Bot] and 6 guests


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

Search for:
Powered by phpBB® Forum Software © phpBB Group