Re: Universal Control Remapper (UCR) - v0.1.19 26th Dec 2017
Posted: 15 Jan 2018, 15:53
@ evilC, I get this when I add the third point, with the code in this post
Cheers.
Let's help each other out
https://www.autohotkey.com/boards/
https://www.autohotkey.com/boards/viewtopic.php?f=19&t=12249
Code: Select all
class AxisToAxisDetent extends _UCR.Classes.Plugin {
Type := "Remapper (Axis To Axis with Detent)"
Description := "Maps an axis input to a virtual axis output (With Detent)"
vAxis := 0
vDevice := 0
; Set up the GUI to allow the user to select input and output axes
Init(){
Gui, Add, GroupBox, % "xm w135 h130 section Center", Input Axis
this.AddControl("InputAxis", "IA1", 0, this.MyInputChangedState.Bind(this), "xs+5 w125 y25")
this.AddControl("AxisPreview", "", 0, this.IOControls.IA1, "xs+5 y+5 w125", 50)
fn := this.UseCurrentClicked.Bind(this)
Gui, Add, Button, hwndhwnd xs+5 y+5 w125, Copy Current >>>>
GuiControl, +g, % hwnd, % fn
Gui, Add, GroupBox, % "x155 ym w60 h130 section Center", Invert
this.AddControl("CheckBox", "Invert", 0, "xs+25 w30 y40")
Gui, Add, GroupBox, % "x225 ym w170 h130 section Center", Breakpoint settings
this.SegmentManager := new this.SegmentControl(this.OnSegmentChanged.Bind(this), this, "xs+10 y25")
Gui, Add, GroupBox, % "x400 ym w135 h130 section Center", Output Virtual Axis
this.AddControl("OutputAxis", "OA1", this.MyOutputChangedValue.Bind(this), "xs+5 y25 w125")
this.AddControl("AxisPreview", "", 0, this.IOControls.OA1, "xp y+5 w125", 50)
Gui, Add, GroupBox, x540 ym w135 h130 section center, Settings String
Gui, Add, Text, xs+5 y25, Copy this to another plugin`nof the same kind`nto duplicate settings
this.AddControl("Edit", "Segments", this.OnSettingsLoad.Bind(this), "xs+5 y+10")
}
OnSegmentChanged(value){
GuiControl, , % this.GuiControls.Segments.hwnd, % value
}
OnSettingsLoad(value){
this.SegmentManager.LoadSettings(value)
}
UseCurrentClicked(){
value := UCR.Libraries.StickOps.AHKToInternal(this.IOControls.IA1.Get())
if (this.GuiControls.Invert.Get()){
value := UCR.Libraries.StickOps.Invert(value)
}
value := UCR.Libraries.StickOps.InternalToAHK(value)
this.SegmentManager.SetInputBox(value)
}
; The user changed options - store stick and axis selected for fast retreival
MyOutputChangedValue(value){
this.vAxis := value.Binding[1]
this.vDevice := value.DeviceID
this.OutputBound := value.IsBound()
}
; The user moved the selected input axis. Manipulate the output axis accordingly
MyInputChangedState(value){
value := UCR.Libraries.StickOps.AHKToInternal(value)
if (this.OutputBound){
if (this.GuiControls.Invert.Get()){
value := UCR.Libraries.StickOps.Invert(value)
}
value := UCR.Libraries.StickOps.InternalToAHK(value)
value := this.SegmentManager.GetValue(value)
this.IOControls.OA1.Set(value)
}
}
class SegmentControl {
Segments := []
Points := []
__New(callback, parent, options := ""){
this.parent := parent
this.callback := callback
Gui, Add, ListView, % "hwndhwnd w130 h75 section " options, Input|Output
LV_ModifyCol(1, 54)
LV_ModifyCol(2, 54)
this.hLV := hwnd
Gui, Add, Button, hwndhwnd x+5 yp w20 h75, -
fn := this.DeleteClicked.Bind(this)
GuiControl, +g, % hwnd, % fn
Gui, Add, Edit, xs y+5 hwndhwnd w60
this.hEditInput := hwnd
Gui, Add, Edit, x+10 yp hwndhwnd w60
this.hEditOutput := hwnd
Gui, Add, Button, hwndhwnd x+5 yp w20, +
fn := this.AddClicked.Bind(this)
GuiControl, +g, % hwnd, % fn
}
; Set save to false when loading settings, to avoid triggering save on load
_AddPoint(i, o){
if (!this.IsNumeric(i) || !this.IsNumeric(o)){
return false
}
inserted := false
for index, obj in this.Points {
if (obj[1] == i)
return false
if (obj[1] > i){
this.Points.Insert(index, [round(i, 2), round(o, 2)])
inserted := true
break
}
}
if (!inserted){
this.Points.push([round(i, 2), round(o, 2)])
}
return true
}
_RemovePoint(index){
this.Points.RemoveAt(index)
this.BuildSegments()
this.SaveSettings()
}
LoadSettings(str){
this.Points := []
chunks := StrSplit(str, "|")
for i, pt in chunks {
p := StrSplit(pt, ",")
res := this._AddPoint(p[1], p[2], false)
}
this.BuildSegments()
}
SaveSettings(){
str := ""
for i, chunk in this.Points {
if (i > 1){
str .= "|"
}
str .= chunk[1] "," chunk[2]
}
this.callback.Call(str)
}
SetInputBox(value){
GuiControl, , % this.hEditInput, % round(value, 2)
}
BuildSegments(){
gui, % this.parent.hwnd ":default"
Gui, ListView, % this.hLV
LV_Delete()
for i, p in this.Points {
LV_Add(, p[1], p[2])
}
pts := this.Points.clone()
;~ pts.Insert(1, [0,0])
pts.Push([100,100])
;~ p0 := pts.removeat(1)
p0 := [0,0]
this.Segments := []
for i, p1 in pts {
this.Segments.push( {k : (p1.2-p0.2) / (p1.1-p0.1) , m : ( p1.1*p0.2 - p0.1*p1.2 ) / (p1.1-p0.1), end : p1.1 } ), p0 := p1
}
}
AddClicked(){
GuiControlGet, i, , % this.hEditInput
GuiControlGet, o, , % this.hEditOutput
if (!this._AddPoint(i, o)){
SoundBeep, 200, 500
return
}
this.BuildSegments()
this.SaveSettings()
}
DeleteClicked(){
Gui, ListView, % this.hLV
row := LV_GetNext()
this._RemovePoint(row)
}
IsNumeric(str){
if str is number
return true
return false
}
GetValue(x){
for i, seg in this.Segments
if (x <= seg.end)
return x*seg.k+seg.m
}
}
}
I'd recommend at the same section within a new/separate thread. If you want to link to a specific topic within this/a foreign thread/post, you can right-click on the date-stamp of the post and copy its link for reference. Thx for sharing and happy scriptingI am happy to post the code. Where is the best place to do so? I have called the plugin ButtonsToButtons.