Slider - same position/on top of each other

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Slider - same position/on top of each other

Post by teadrinker » 14 Mar 2019, 08:02

Slightly simplified the code, added the parameter "tooltipID".

Code: Select all

SetBatchLines, -1
slider1 := new MySlider("h", 400, 15, 70, "Lime", "Fuchsia", 10, 1)
Gui, % slider1.hWnd ":Show", x300 y350

slider2 := new MySlider("v", 400, 17, 70, "Silver", "Red", 50)  ; without tooltip smoother motion
Gui, % slider2.hWnd ":Show", x800 y150
Return

Esc::ExitApp

class MySlider
{
   __New(orientation, len, height, thumbWidth, backColor, thumbColor, startPosPercent := 0, tooltipID := false) {
      static styles := "+"  . (WS_CLIPCHILDREN  := 0x2000000)
                    . " +E" . (WS_EX_COMPOSITED := 0x2000000)
      this.vert := !!InStr(orientation, "v")
      this.height := height
      this._thumb := thumbWidth
      dpi := A_ScreenDPI/96
      this.thumb := thumbWidth*dpi
      this.size := (len - thumbWidth)*dpi
      this.tooltipID := tooltipID
      
      Gui, New, +hwndhBack +ToolWindow -Caption +AlwaysOnTop %styles%
      this.hWnd := hBack
      Gui, Color, % backColor
      
      Gui, New, +hwndhThumb +ToolWindow -Caption +Parent%hBack%
      this.hThumb := hThumb
      Gui, Color, % thumbColor
      this.pos := Round( this.size/100*startPosPercent )
      Gui, Show, % this.BuildCoords()
      
      coords := this.vert ? "w" . height . " h" . len : "w" . len . " h" . height
      Gui, %hBack%: Show, Hide %coords%
      
      self := this.Clone(), self.self := true
      this.onClick := this.WM_LBUTTONDOWN.Bind(self)
      this.onWheel := this.WM_MOUSEWHEEL.Bind(self)
      OnMessage(0x201, this.onClick)
      OnMessage(0x20A, this.onWheel)
   }
   
   __Delete() {
      if this.self
         Return
      Gui, % this.hThumb ": Destroy"
      Gui, % this.hWnd   ": Destroy"
      OnMessage(0x201, this.onClick, 0)
      OnMessage(0x20A, this.onWheel, 0)
   }
   
   WM_LBUTTONDOWN() {
      static newPos
      if !GetKeyState("LButton", "P")
         Return
      prevCMM := A_CoordModeMouse
      CoordMode, Mouse, Screen
      MouseGetPos, X_Mouse, Y_Mouse, hwnd, hCtrl, 2
      WinGetPos, X_Gui, Y_Gui,,, % "ahk_id" this.hWnd
      
      prevX := X_Mouse - X_Gui
      prevY := Y_Mouse - Y_Gui
      
      if (hCtrl = "" && hwnd = this.hWnd) {
         if this.vert
            this.pos := this.size - prevY + this.thumb//2
         else
            this.pos := prevX - this.thumb//2
         
         this.PosInRange()
         Gui, % this.hThumb ": Show", % this.BuildCoords()
         hCtrl := this.hThumb
      }
      if (hCtrl = this.hThumb) {
         prevPos := this.pos
         while GetKeyState("LButton", "P") {
            MouseGetPos, X_Mouse, Y_Mouse
            X := X_Mouse - X_Gui
            Y := Y_Mouse - Y_Gui
            if this.vert
               this.pos := prevPos - Y + prevY
            else
               this.pos := prevPos + X - prevX
            
            this.PosInRange()
            try Gui, % this.hThumb ": Show", % this.BuildCoords()
            if this.tooltipID
               ToolTip % Round(this.pos*100/this.size),,, this.tooltipID
            Sleep, 10
         }
         if this.tooltipID
            ToolTip,,,, this.tooltipID
      }
      CoordMode, Mouse, % prevCMM
   }
   
   WM_MOUSEWHEEL(wp, lp, msg, hwnd) {
      if !(WinActive("ahk_id" this.hWnd) && hwnd = this.hWnd)
         Return
      dir := (wp >> 16) & 0xFFFF = 120 ? 1 : -1
      this.pos += dir*this.thumb//2
      this.PosInRange()
      Gui, % this.hThumb ": Show", % this.BuildCoords()
   }
   
   BuildCoords() {
      Return "NA " . ( this.vert ? "x0            y" this.size - this.pos " w" this.height " h" this._thumb
                                 : "x" this.pos " y0                        w" this._thumb " h" this.height )
   }
   
   PosInRange() {
      Return this.pos := this.pos < 0 ? 0 : this.pos > this.size ? this.size : this.pos
   }
}
Actually, someone can create his own scrollbar for GUI based on this slider. If I have time, I'll try. :)

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Slider - same position/on top of each other

Post by wolf_II » 14 Mar 2019, 08:54

I cleaned my mess and ended up with a Slider class. (same as teadrinker).

Code: Select all

; https://www.autohotkey.com/boards/viewtopic.php?p=267762#p267762

#NoEnv

    new Slider(400, 6)
    Wheel := ObjBindMethod(Slider, "onChange")

return ; end of auto-execute section

Esc:: ExitApp
F5::  Reload



;-------------------------------------------------------------------------------
#If WinActive("ahk_id " Slider.hBackdrop)
;-------------------------------------------------------------------------------
    WheelUp::   %Wheel%("Up")
    WheelDown:: %Wheel%("Dn")

#If ; end



;===============================================================================
class Slider { ;
;===============================================================================

    ; CONSTANTS
    static DPI := A_ScreenDPI / 96
    static Size
    static Parts
    static THeight
    static maxPos

    ; variable
    static ThumbPos := 0

    __New(Size, Parts) { ; constructor

        ; housekeeping
        Slider.Size := Size
        Slider.Parts := Parts
        Slider.THeight := THeight := Ceil(Size / Parts)
        Slider.maxPos := (Size - THeight) * Slider.DPI

        ; GUI for backdrop
        Gui, New, ToolWindow -Caption HWNDhBackdrop AlwaysOnTop
        Gui, +0x02000000 ; WS_CLIPCHILDREN
        Gui, Color, Lime

        ; GUI for thumb
        Gui, New, -Caption HWNDhThumb Parent%hBackdrop%
        Gui, Color, Fuchsia
        Gui, Show, NA x0 y0 w15 h%THeight%
        Gui, %hBackdrop%: Show, w15 h%Size%

        ; housekeeping again
        Slider.hBackdrop := hBackdrop
        Slider.hThumb := hThumb

        ; event handlers
        fn := Func("WM_LBUTTONDOWN")
        OnMessage(0x201, fn) ; WM_LBUTTONDOWN
    }

    onChange(Direction) { ; wheel events
        Slider.ThumbPos += (Direction = "Up") ? -1 : 1
        Slider.ThumbPos := clamp(Slider.ThumbPos, 0, this.Parts - 1)
        newY := Slider.ThumbPos * (THeight := Slider.THeight)
        Gui, % this.hThumb ":Show", NA x0 w15 y%newY% h%THeight%
    }

} ; end of class



;-------------------------------------------------------------------------------
WM_LBUTTONDOWN(wp, lp, msg, hWnd) { ; event handler
;-------------------------------------------------------------------------------
    WinGetPos,, BackdropY,,, % "ahk_id " Slider.hBackdrop
    WinGetPos,, ThumbY,,, % "ahk_id " Slider.hThumb
    Y_offset := ThumbY - BackdropY

    ; shorthands
    THeight := Slider.THeight
    maxPos := Slider.maxPos

    if (hWnd = Slider.hThumb) {
        MouseGetPos,, prevY
        while GetKeyState("LButton", "P") {
            MouseGetPos,, currY
            newY := Y_offset + (currY - prevY)
            newY := clamp(newY, 0, maxPos)
            Gui, % Slider.hThumb ":Show", NA x0 w15 y%newY% h%THeight%
            Slider.ThumbPos := Round(newY * (Slider.Parts - 1) / maxPos)
            percent := newY * 100 / maxPos
            ToolTip, % Round(percent), 20, 25 + newY
            Sleep, 10
        }
        ToolTip ; off
    }
}



;-------------------------------------------------------------------------------
clamp(Variable, min, max) { ; limit variable range to [min..max]
;-------------------------------------------------------------------------------
	Return, (Variable < min) ? min
          : (Variable > max) ? max : Variable
}
I will look into scrollable GUI again. Current state is: Lexikos made one, just me made one, AHK_H has it built-in.
I will probably never use one. VLC has this feature and I don't like it. But reading the respective code will give me pleasure. :)

I need to look closer how to squeeze both methods into a single class.
BTW, I am not competing, I am learning as I code. very enjoyable challenge. thx to OP

Trej
Posts: 13
Joined: 10 Mar 2019, 19:25

Re: Slider - same position/on top of each other

Post by Trej » 14 Mar 2019, 10:26

Hi Wolf,

You have said a whole lot of statements that flew way over my head :D What did you mean by VLC having a feature?

Also, I am not sure why but when I run the script I can't scroll past 50, it will move only between the top -> middle, but I can drag it down to the bottom.

I think it could be my high dpi screen. I have a Surface Book 2 15", and I have noticed when using a monitor (1080p) there doesnt seem to be any issues.

teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Slider - same position/on top of each other

Post by teadrinker » 14 Mar 2019, 10:37

wolf_II, your code works for me on the desktop, but on the laptop with 150% screen scalling the scrolling doesn't work at all.

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Slider - same position/on top of each other

Post by wolf_II » 14 Mar 2019, 11:18

Trej wrote:
14 Mar 2019, 10:26
Hi Wolf,

You have said a whole lot of statements that flew way over my head :D What did you mean by VLC having a feature?

Also, I am not sure why but when I run the script I can't scroll past 50, it will move only between the top -> middle, but I can drag it down to the bottom.

I think it could be my high dpi screen. I have a Surface Book 2 15", and I have noticed when using a monitor (1080p) there doesnt seem to be any issues.
Sorry, context was missing.

With regards to writing a class for general use, such as a scrollable GUI:
This is a feature, which was asked for on multiple occasions. To see it in action, look at VLC configuration GUI, oops .. sorry
I just looked again, and it seems to have changed with some update. IIRC an older version had one, but that is irrelevant now.

https://www.autohotkey.com/board/topic/26033-scrollable-gui-proof-of-concept/#entry168174
https://www.autohotkey.com/boards/viewtopic.php?p=237412#p237412
https://www.autohotkey.com/boards/viewtopic.php?p=230770#p230770

a class by just me
https://www.autohotkey.com/boards/viewtopic.php?p=37402#p37402


I'm sorry, I have not played aroud with DPI, that is entirely untested by me.
I took inspiration from teadrinker. All my tests had DPI = 96, and the factor was always 1.
I should not have left that in without testing, sorry

wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Slider - same position/on top of each other

Post by wolf_II » 14 Mar 2019, 11:20

teadrinker wrote:
14 Mar 2019, 10:37
wolf_II, your code works for me on the desktop, but on the laptop with 150% screen scalling the scrolling doesn't work at all.
sorry, I have never tested the scaling, I should have removed the thing. :( :oops:

Trej
Posts: 13
Joined: 10 Mar 2019, 19:25

Re: Slider - same position/on top of each other

Post by Trej » 19 Mar 2019, 21:31

Hi @wolf_II

So I have done some more tinkering, and would like to know if I can get some help... I have made the code do what I want it to do, but it is by no means 'clean' :D

What I would like to do is when I press the Enter button, I want the sliding bar to flicker/flash for a few moments, and close the GUI. At the moment I am testing by calling a GoSub to call a popup. My end goal will be to have the bar flash, and then store a number to a variable.

I would also like to make all the Gui's cleaner and working together. Can you provide some guidance on how to do this?

I also fixed the issue I was having with the bar going only halfway by changing the code below

From :static DPI := A_ScreenDPI / 96
To: static DPI := 96 / A_ScreenDPI

Code: Select all

#NoEnv


Width := 500
X_Pos1 := 50
Y_Pos1 := 50
Wide := Width

Gui, +LastFound
;WinSet, Transparent, 150
Gui, Color, cD0D0D0
Gui, Margin, 0, 0
Gui, Font, s15  Bold
Gui, Add, Progress, % "x-0 y0 w" (Width) "r1 H40 Background737373  Disabled hwndHPROG"
Gui, Add, Text, % "xm y0 w" Width "r1 H40 BackgroundTrans Center 0x200  gGuiMove vCaption", Select Slider
Gui, Font, s8
Gui, Add, Text, % "x7 y+0 w" (Width-14) "r1 h40 +0x4000 BackgroundTrans 0x200  vTX1 gS1", Slider 1
Gui, Add, Text, % "x7 y+0 w" (Width-14) "r1 h40 +0x4000 BackgroundTrans 0x200  vTX2 gS2", Slider 2
Gui, Add, Text, % "x7 y+0 w" (Width-14) "r1 h40 +0x4000 BackgroundTrans 0x200  vTX3 gs3", Slider 3
Gui, Add, Text, % "x7 y+0 w" (Width-14) "r1 h40 +0x4000 BackgroundTrans 0x200  vTX4 gs4", Slider 4
Gui, Add, Text, % "x7 y+0 w" (Width-14) "r1 h40 +0x4000 BackgroundTrans 0x200  vTX5 gClose", Close
Gui, Add, Text, % "x7 y+0 w" (Width-14) "h40 vP  "
GuiControlGet, P, Pos
H := PY + PH 
Gui, -Caption
WinSet, TransColor, cD0D0D0
WinSet, Region, 0-0 w%Width% h%H% r6-6 DPIScale
Gui, Show, % "w" Width " NA" " x" X_Pos1 " y" Y_Pos1
WinSet AlwaysOnTop

H_Slider := H - PH
X_Pos:= X_Pos1
Y_Pos:= Y_Pos1
Bar_Colour := c5c5c5

    new Slider(H_Slider, 6, Wide, X_Pos1, Y_Pos1, Bar_Colour)
    Wheel := ObjBindMethod(Slider, "onChange")

Check := (40*(A_ScreenDPI/96))
DPI := A_ScreenDPI

return

GuiMove:
   PostMessage, 0xA1, 2
return

S1:
MsgBox, You clicked Slider 1 (%A_GuiControl%).
return

S2:
MsgBox, You clicked Slider 2 (%A_GuiControl%).
return

S3:
MsgBox, You clicked Slider 3 (%A_GuiControl%).
return

S4:
MsgBox, You clicked Slider 4 (%A_GuiControl%).
return

Enter::
If (newY = (40*(A_ScreenDPI/96)))
    goSub, S1
If (newY = (80*(A_ScreenDPI/96)))
    goSub S2
If (newY = (120*(A_ScreenDPI/96)))
    goSub S3
If (newY = (160*(A_ScreenDPI/96)))
    goSub S4
If (NewY = (200*(A_ScreenDPI/96)))
    goSub Close
Return

Escape::
ExitApp
return

Close:
ExitApp

    
return ; end of auto-execute section

Esc:: ExitApp
;F5::  Reload



;-------------------------------------------------------------------------------
#If WinActive("ahk_id " Slider.hBackdrop)
;-------------------------------------------------------------------------------
    WheelUp::   %Wheel%("Up")
    WheelDown:: %Wheel%("Dn")

#If ; end



;===============================================================================
class Slider { ;
;===============================================================================

    ; CONSTANTS
    static DPI := 96 / A_ScreenDPI
    static H_Slider
    static Parts
    static THeight
    static maxPos
    static TWidth
    static X_Pos1
    static Y_Pos1
    ;static Bar_Colour

    ; variable
    static ThumbPos := 0
    static Bar_Colour := 0

    __New(H_Slider, Parts, TWidth, X_Pos1, Y_Pos1, Bar_Colour) { ; constructor

        ; housekeeping
        Slider.H_Slider := H_Slider
        Slider.Parts := Parts
        Slider.TWidth := TWidth
        Slider.X_Pos := X_Pos
        Slider.Y_Pos := Y_Pos
        Slider.THeight := THeight := Ceil(H_Slider / Parts)
        Slider.maxPos := (H_Slider - THeight)
        Slider.Bar_Colour := Bar_Colour
                
        ; GUI for backdrop
        Gui, New, ToolWindow -Caption HWNDhBackdrop
        Gui, +Lastfound
        Gui, +0x02000000 ; WS_CLIPCHILDREN
        Gui, Color, e7e7e7
        
        ; GUI for thumb
        Gui, New, -Caption HWNDhThumb Parent%hBackdrop%
        ;Global Bar_Colour
        ;Bar_Colour := c5c5c5
        Gui, Color, c5c5c5
        Gui, Show, NA x0 y0 w%TWidth% h%THeight% 
        Gui, %hBackdrop%: Show, x%X_Pos1% y%Y_Pos1% w%TWidth% h%H_Slider% 

        ; housekeeping again
        Slider.hBackdrop := hBackdrop
        Slider.hThumb := hThumb

        ; event handlers
        fn := Func("WM_LBUTTONDOWN")
        OnMessage(0x201, fn) ; WM_LBUTTONDOWN
    }

    onChange(Direction) { ; wheel events
        Slider.ThumbPos += (Direction = "Up") ? -1 : 1
        Slider.ThumbPos := clamp(Slider.ThumbPos, 0, this.Parts - 1)
        TWidth := Slider.TWidth
        Global newY
        newY := (Slider.ThumbPos * (THeight := Slider.THeight) ) / Slider.DPI
        Gui, % this.hThumb ":Show", NA x0 w%TWidth% y%newY% h%THeight%
    }

} ; end of class



;-------------------------------------------------------------------------------
clamp(Variable, min, max) { ; limit variable range to [min..max]
;-------------------------------------------------------------------------------
	Return, (Variable < min) ? min
          : (Variable > max) ? max : Variable
}


wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Slider - same position/on top of each other

Post by wolf_II » 20 Mar 2019, 03:35

Hi, Trej

I made some progress on the "make all the Gui's cleaner and working together."
However, I have doubts this will be useful at all. Maybe I have only a single hammer, and all things around me look like nails.

I messed with a few options in your Gui setup, like remove some gLabels, which don't fire and so on.
I then included the "MoveTogether" hammer. I am uncertain if this is the right way to go.
Maybe you want to look into Gdip windows, I have not yet looked.
I take it for now: you need to use this script on a tablet? with some fancy DPI-stuff included? I have no such device, I can only test on Desktop.
Or is it running on Desktop with some input-device?

long story short: here is the mess I made, clean-up will follow.
Right now, I am looking for feedback, this might be useful? (despite the mouse jumping like crazy.)
Try this:

Trej
Posts: 13
Joined: 10 Mar 2019, 19:25

Re: Slider - same position/on top of each other

Post by Trej » 20 Mar 2019, 09:34

Hi @Wolf_II

So I went a different way with the flashing and made the text flash.

I am running a 1080 monitor with a laptop (Surface Book 2 15inch) so it behaves differently between the two.

Slowly piecing it together. Next now is understanding how to call on events from the Surface Dial. Need to wrap my head around the Windows.UI.Input Namespace https://docs.microsoft.com/en-us/uwp/api/windows.ui.input

Here's the code updated, but you're not wrong about the jumpy Gui :crazy:

Thanks again mate....

Code: Select all

; https://www.autohotkey.com/boards/viewtopic.php?p=267762#p267762

#NoEnv


Width := 500
X_Pos1 := 50
Y_Pos1 := 50
Wide := Width

Gui, +LastFound
;WinSet, Transparent, 150
Gui, Color, cD0D0D0
Gui, Margin, 0, 0
Gui, Font, s15  Bold
Gui, Add, Progress, % "x-0 y0 w" (Width) "r1 H40 Background737373  Disabled hwndHPROG"
Gui, Add, Text, % "xm y0 w" Width "r1 H40 BackgroundTrans Center 0x200  gGuiMove vCaption", Select Slider
Gui, Font, s8 Q5
Gui, Add, Text, % "x7 y+0 w" (Width-14) "r1 h40 +0x4000 BackgroundTrans 0x200  vTX1 gS1", Slider 1
Gui, Add, Text, % "x7 y+0 w" (Width-14) "r1 h40 +0x4000 BackgroundTrans 0x200  vTX2 gS2", Slider 2
Gui, Add, Text, % "x7 y+0 w" (Width-14) "r1 h40 +0x4000 BackgroundTrans 0x200  vTX3 gs3", Slider 3
Gui, Add, Text, % "x7 y+0 w" (Width-14) "r1 h40 +0x4000 BackgroundTrans 0x200  vTX4 gs4", Slider 4
Gui, Add, Text, % "x7 y+0 w" (Width-14) "r1 h40 +0x4000 BackgroundTrans 0x200  vTX5 gClose", Close
Gui, Add, Text, % "x7 y+0 w" (Width-14) "h40 vP  "
GuiControlGet, P, Pos
H := PY + PH 
Gui, -Caption
WinSet, TransColor, cD0D0D0
WinSet, Region, 0-0 w%Width% h%H% r6-6 DPIScale
Gui, Show, % "w" Width " NA" " x" X_Pos1 " y" Y_Pos1
WinSet AlwaysOnTop

H_Slider := H - PH
X_Pos:= X_Pos1
Y_Pos:= Y_Pos1
Bar_Colour := c5c5c5

    new Slider(H_Slider, 6, Wide, X_Pos1, Y_Pos1, Bar_Colour)
    Wheel := ObjBindMethod(Slider, "onChange")

Check := (40*(A_ScreenDPI/96))
DPI := A_ScreenDPI

return

GuiMove:
   PostMessage, 0xA1, 2
return

S1:
MsgBox, You clicked Slider 1 (%A_GuiControl%).
return

S2:
MsgBox, You clicked Slider 2 (%A_GuiControl%).
return

S3:
MsgBox, You clicked Slider 3 (%A_GuiControl%).
return

S4:
MsgBox, You clicked Slider 4 (%A_GuiControl%).
return

Enter::
If (newY = (40*(A_ScreenDPI/96))) {
                Loop,4 {
                    GuiControl, % "Disable" b:=!b, TX1
                    Sleep,80
                    }
}
If (newY = (80*(A_ScreenDPI/96))) {
                Loop,6 {
                    GuiControl, % "Disable" b:=!b, TX2
                    Sleep,100
                    }
}
If (newY = (120*(A_ScreenDPI/96))) {
                Loop,6 {
                    GuiControl, % "Disable" b:=!b, TX3
                    Sleep,100
                    }
}
If (newY = (160*(A_ScreenDPI/96))) {
                Loop,6 {
                    GuiControl, % "Disable" b:=!b, TX4
                    Sleep,100
                    }
}
If (NewY = (200*(A_ScreenDPI/96))) {
                Loop,6 {
                    GuiControl, % "Disable" b:=!b, TX5
                    Sleep,100
                    }
                goSub Close
}
Return

Escape::
ExitApp
return

Close:
ExitApp

    
return ; end of auto-execute section

Esc:: ExitApp
;F5::  Reload



;-------------------------------------------------------------------------------
#If WinActive("ahk_id " Slider.hBackdrop)
;-------------------------------------------------------------------------------
    WheelUp::   %Wheel%("Up")
    WheelDown:: %Wheel%("Dn")

#If ; end



;===============================================================================
class Slider { ;
;===============================================================================

    ; CONSTANTS
    static DPI := 96 / A_ScreenDPI
    static H_Slider
    static Parts
    static THeight
    static maxPos
    static TWidth
    static X_Pos1
    static Y_Pos1
    ;static Bar_Colour

    ; variable
    static ThumbPos := 0
    static Bar_Colour := 0

    __New(H_Slider, Parts, TWidth, X_Pos1, Y_Pos1, Bar_Colour) { ; constructor

        ; housekeeping
        Slider.H_Slider := H_Slider
        Slider.Parts := Parts
        Slider.TWidth := TWidth
        Slider.X_Pos := X_Pos
        Slider.Y_Pos := Y_Pos
        Slider.THeight := THeight := Ceil(H_Slider / Parts)
        Slider.maxPos := (H_Slider - THeight)
        Slider.Bar_Colour := Bar_Colour
                
        ; GUI for backdrop
        Gui, New, ToolWindow -Caption HWNDhBackdrop
        Gui, +Lastfound
        Gui, +0x02000000 ; WS_CLIPCHILDREN
        Gui, Color, e7e7e7
        
        ; GUI for thumb
        Gui, New, -Caption HWNDhThumb Parent%hBackdrop%
        ;Global Bar_Colour
        ;Bar_Colour := c5c5c5
        Gui, Color, c5c5c5
        Gui, Show, NA x0 y0 w%TWidth% h%THeight% 
        Gui, %hBackdrop%: Show, x%X_Pos1% y%Y_Pos1% w%TWidth% h%H_Slider% 

        ; housekeeping again
        Slider.hBackdrop := hBackdrop
        Slider.hThumb := hThumb
        ;Global hThumb

        ; event handlers
        fn := Func("WM_LBUTTONDOWN")
        OnMessage(0x201, fn) ; WM_LBUTTONDOWN
    }

    onChange(Direction) { ; wheel events
        Slider.ThumbPos += (Direction = "Up") ? -1 : 1
        Slider.ThumbPos := clamp(Slider.ThumbPos, 0, this.Parts - 1)
        TWidth := Slider.TWidth
        Global newY
        newY := (Slider.ThumbPos * (THeight := Slider.THeight) ) / Slider.DPI
        Gui, % this.hThumb ":Show", NA x0 w%TWidth% y%newY% h%THeight%
    }

} ; end of class



;-------------------------------------------------------------------------------
clamp(Variable, min, max) { ; limit variable range to [min..max]
;-------------------------------------------------------------------------------
	Return, (Variable < min) ? min
          : (Variable > max) ? max : Variable
}



;https://autohotkey.com/board/topic/10084-a-guixy/

Post Reply

Return to “Ask for Help (v1)”