[Solved] Prototype Window and Pane Class problems
Posted: 16 Jul 2016, 03:11
Okay, so I'm working with window boxes within another application, where the window boxes don't have handles. I have programmed my program to find and interact with the windows, but I'm having trouble figuring out how to implement the Pane Prototype class.
Example structure I need to accommodate:
ParentWindow{
TopPane{}, LeftPane{ LeftPane{}, RightPane{} }, RightPane{}
}
(The classes keep track of the parent-child relationships via the parent and child InstanceVars.)
Everything has a LeftX, RightX, TopY, and BottomY so that I can track where the objects are.
Each main Window has a title and unique configuration of Panes, so I'm using the Window prototype as my base and adding all the code for the Pane behavior/configuration within the class for the WindowTitle.
Panes hold objects that are unique to that pane, so each one is different. The panes can be hidden or change in size because you can expand one pane into the space of the adjoining Pane(s). If I drag the top Pane down, the left and right panes get shorter.
What I feel would work best here is if I could define each pane's edge coordinates as an expression using the edge coordinates of the objects that influence the pane's dimensions. Like define LeftPane's LeftX InstanceVar as "LeftPane.Parent.LeftX + 2" and LeftPane's RightX InstanceVar as "this.Parent.Left-Right Divider - 2" and so forth.
I just can't figure out how to change a class' instance variable to act like a method. Can this be done? Is there a better alternative?
This is basically the best way I can think of to accomplish my goals, but it gives me errors for the dots in stuff like "this.RightNeighborObj.%RightNeighborXName%". Basically, I want them to be able to influence each other without having to make a custom class for each pane.
Example structure I need to accommodate:
ParentWindow{
TopPane{}, LeftPane{ LeftPane{}, RightPane{} }, RightPane{}
}
(The classes keep track of the parent-child relationships via the parent and child InstanceVars.)
Everything has a LeftX, RightX, TopY, and BottomY so that I can track where the objects are.
Each main Window has a title and unique configuration of Panes, so I'm using the Window prototype as my base and adding all the code for the Pane behavior/configuration within the class for the WindowTitle.
Panes hold objects that are unique to that pane, so each one is different. The panes can be hidden or change in size because you can expand one pane into the space of the adjoining Pane(s). If I drag the top Pane down, the left and right panes get shorter.
What I feel would work best here is if I could define each pane's edge coordinates as an expression using the edge coordinates of the objects that influence the pane's dimensions. Like define LeftPane's LeftX InstanceVar as "LeftPane.Parent.LeftX + 2" and LeftPane's RightX InstanceVar as "this.Parent.Left-Right Divider - 2" and so forth.
I just can't figure out how to change a class' instance variable to act like a method. Can this be done? Is there a better alternative?
This is basically the best way I can think of to accomplish my goals, but it gives me errors for the dots in stuff like "this.RightNeighborObj.%RightNeighborXName%". Basically, I want them to be able to influence each other without having to make a custom class for each pane.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
window1 := new Window()
`::
InputBox, num, "Pane Manipulation", "Enter a x value for LeftPane's right wall, 100-200. Current value of LeftPane's right wall is " window1.LeftPane.RightX
window1.LeftPane.RightX := num
MsgBox, % "LeftPane.RightX = " window1.LeftPane.RightX "`t window1.RightPane.LeftX = " window1.RightPane.LeftX
return
Class Window{
Title :=
TitleImg :=
LeftX := 100
RightX := 100
TopY := 200
BottomY := 200
Parent :=
Children := []
LeftPane := []
RightPane := []
__New(){
;MsgBox, % "Starting Window"
this.LeftPane := new Pane(this, "LeftPane", "", this, "LeftX", 2, this.RightPane, "LeftX", -3, this, "TopY", 20, this, "BottomY", -2)
this.RightPane := new Pane(this, "RightPane", "", this.LeftPane, "RightX", 3, this, "RightX", -2, this, "TopY", 20, this, "BottomY", -2)
this.Children.Push(this.LeftPane, this.RightPane)
}
}
Class Pane{
Title :=
LeftX {
; Parent Window's coords must be set before Pane's dimensions are so that
get {
Return this._LeftX
}
set {
if(value = this.LeftNeighborObj){
this._LeftX := value.%LeftNeighborXName% + LeftNeighborOffsetX ; Only set it because it was sent by its neighbor after setting its own value
}
Else if(value = Integer && value > this.LeftNeighborObj.%LeftNeighborXName% && value < this.RightNeighborObj.%RightNeighborXName%){
this._LeftX := value
this.LeftNeighborObj.%LeftNeighborXName% := this ; Send this object so that they infinitely setting eachother
}
else{
Return False
}
}
}
RightX {
; Parent Window's coords must be set before Pane's dimensions are so that
get {
Return this._RightX
}
set {
if(value = this.RightNeighborObj){
this._RightX := value.%RightNeighborXName% + RightNeighborOffsetX ; Only set it because it was sent by its neighbor after setting its own value
}
Else if(value = Integer && value > this.RightNeighborObj.%RightNeighborXName% && value < this.LeftNeighborObj.%LeftNeighborXName%){
this._RightX := value
this.RightNeighborObj.%RightNeighborXName% := this ; Send this object so that they infinitely setting eachother
}
else{
Return False
}
}
}
TopY :=
BottomY :=
Parent :=
Children :=
__New(parent, title, titleImg, leftNeighborObj, leftNeighborXName, leftNeighborOffsetX, rightNeighborObj, rightNeighborXName, rightNeighborOffsetX, topNeighborObj, topNeighborYName, topNeighborOffsetY, bottomNeighborObj, bottomNeighborYName, bottomNeighborOffsetY){
;MsgBox, % "Starting Pane"
this.Parent := parent
this.Title:= title
this.TitleImg := titleImg
this.LeftNeighborObj := leftNeighborObj
this.LeftNeighborXName := leftNeighborXName
this.LeftNeighborOffsetX := leftNeighborOffsetX
this.RightNeighborObj := rightNeighborObj
this.RightNeighborXName := rightNeighborXName
this.RightNeighborOffsetX := rightNeighborOffsetX
this.TopNeighborObj := topNeighborObj
this.TopNeighborYName := topNeighborYName
this.TopNeighborOffsetY := topNeighborOffsetY
this.BottomNeighborObj := bottomNeighborObj
this.BottomNeighborYName := bottomNeighborYName
this.BottomNeighborOffsetY := bottomNeighborOffsetY
}
}