Skip to content

Commit

Permalink
[V] Windy 0.15.0
Browse files Browse the repository at this point in the history
#22 - Windy: new method moveBorder()
#24 - Mony: Transform coordinates into screen percents
#25 - Windy: Transform current window PosSize into screen percents
  • Loading branch information
hoppfrosch committed Jan 30, 2015
2 parents e996f2d + 63f9886 commit 6389c32
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 20 deletions.
12 changes: 12 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
(on Branch: **master**, since **2014-10-26**)

-----------------------------------------------------------------
* **Windy 0.15.0** (via Commit [86615ed](https://github.com/hoppfrosch/AHK_Windy/commit/86615edcd350ac7130cf21a1b1015b2b61baa36f))
* [#22](https://github.com/hoppfrosch/AHK_EDE/issues/22) - Windy: new method moveBorder()
* [#24](https://github.com/hoppfrosch/AHK_EDE/issues/24) - Mony: Transform coordinates into screen percents
* [#25](https://github.com/hoppfrosch/AHK_EDE/issues/25) - Windy: Transform current window PosSize into screen percents
* **Merge pull request [#23](https://github.com/hoppfrosch/AHK_EDE/issues/23) from hi5/patch-1** (via Commit [e996f2d](https://github.com/hoppfrosch/AHK_Windy/commit/e996f2d3fc30ddbdea8926a2d8d7ddaf68f68551))
* Added restore settings line before exit app
* **Windy 0.14.0** (via Commit [59848e1](https://github.com/hoppfrosch/AHK_Windy/commit/59848e1713c07e8619f971c2aa332c941f42391d))
* [#17](https://github.com/hoppfrosch/AHK_EDE/issues/17) - Make usage of %A_LineFile% to get better include-behaviour
* [#18](https://github.com/hoppfrosch/AHK_EDE/issues/18) - Windy: Setting transparency fails on windows without caption
* [#19](https://github.com/hoppfrosch/AHK_EDE/issues/19) - Windy: Property scale[] for proportional Resizing when moving monitor
* [#20](https://github.com/hoppfrosch/AHK_EDE/issues/20) - Windy: Consider Property scale in Property monitorId
* [#21](https://github.com/hoppfrosch/AHK_EDE/issues/21) - WindLy: Remove unneeded output to messagebox
* **Windy 0.13.0** (via Commit [35795da](https://github.com/hoppfrosch/AHK_Windy/commit/35795da9bda44dda986765df87ed534eadab10bf))
* [#16](https://github.com/hoppfrosch/AHK_EDE/issues/16) - WindLy: Iniitial Implementation of class for handling window lists
* **Windy 0.12.3** (via Commit [2f9f578](https://github.com/hoppfrosch/AHK_Windy/commit/2f9f578272bbc99c1a73a5db045c927b2c98f388))
Expand Down
16 changes: 16 additions & 0 deletions Examples/Windy/moveBorder.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include %A_ScriptDir%\..\..\lib\Windy
#include Windy.ahk

arrBorder := ["l","r","hc","t","b","vc", "l t", "l b", "l vc", "r t", "r b", "r vc", "hc t", "hc b", "hc vc"]
obj := new Windy(0,0)
Loop % arrBorder.MaxIndex() {
OutputDebug % "********************************* " arrBorder[A_Index] " ************************************************"
obj.move(200,200)
obj.debug := 1
obj.moveBorder(arrBorder[A_Index])
obj.debug := 0
sleep 2000
}
obj.kill()

ExitApp
30 changes: 23 additions & 7 deletions YUnit_Mony.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#SingleInstance force


ReferenceVersion := "1.0.0"
ReferenceVersion := "1.0.1"
debug := 1

;Yunit.Use(YunitStdOut, YunitWindow).Test(ExpMonyTestSuite)
Expand All @@ -29,17 +29,20 @@ class ExpMonyTestSuite
this.monCount := 2
this.mon1Width := 1920
this.mon1Height := 1080
this.mon2Width := 1600
this.mon2Width := 1920
this.mon2Height := 1200
}

primary() {
rectToPercent() {
Global debug
OutputDebug % ">>>>>[" A_ThisFunc "]>>>>>"
mon1 := new Mony(1, debug)
Yunit.assert(mon1.primary = true)
mon2 := new Mony(2, debug)
Yunit.assert(mon2.primary = false)
rect := new Recty(this.mon1Width/10,this.mon1Height/10,this.mon1Width/5,this.mon1Height/4)
per := mon1.rectToPercent(rect)
Yunit.assert(per.x == 100/10)
Yunit.assert(per.y == 100/10)
Yunit.assert(per.w == 100/5)
Yunit.assert(per.h == 100/4)
OutputDebug % "<<<<<[" A_ThisFunc "]<<<<<"
}

Expand All @@ -58,7 +61,7 @@ class MonyTestSuite
this.monCount := 2
this.mon1Width := 1920
this.mon1Height := 1080
this.mon2Width := 1600
this.mon2Width := 1920
this.mon2Height := 1200
}

Expand Down Expand Up @@ -216,6 +219,19 @@ class MonyTestSuite
Yunit.assert(mon2.primary = false)
OutputDebug % "<<<<<[" A_ThisFunc "]<<<<<"
}

rectToPercent() {
Global debug
OutputDebug % ">>>>>[" A_ThisFunc "]>>>>>"
mon1 := new Mony(1, debug)
rect := new Recty(this.mon1Width/10,this.mon1Height/10,this.mon1Width/5,this.mon1Height/4)
per := mon1.rectToPercent(rect)
Yunit.assert(per.x == 100/10)
Yunit.assert(per.y == 100/10)
Yunit.assert(per.w == 100/5)
Yunit.assert(per.h == 100/4)
OutputDebug % "<<<<<[" A_ThisFunc "]<<<<<"
}

size() {
Global debug
Expand Down
2 changes: 1 addition & 1 deletion YUnit_Windy.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
;#Warn LocalSameAsGlobal, Off
#SingleInstance force

ReferenceVersion := "0.8.3"
ReferenceVersion := "0.8.6"
debug := 1

;Yunit.Use(YunitStdOut, YunitWindow).Test(_BaseTestSuite, TempTestSuite)
Expand Down
5 changes: 3 additions & 2 deletions lib/Windy.ahk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Title: _ Windy, v0.13.0
Title: _ Windy, v0.15.0
Windy provides a collection of classes, which allow a class based approach of handling windows, monitors, etc.
Expand All @@ -10,6 +10,7 @@
* <Pointy at http://hoppfrosch.github.io/AHK_Windy/files/Pointy-ahk.html> - Points (geometric 2D-points) - this is mostly a helper class being used within this package, but maybe helpful anyway ...
* <Recty at http://hoppfrosch.github.io/AHK_Windy/files/Recty-ahk.html> - Rectangles (consisting of two <points at http://hoppfrosch.github.io/AHK_Windy/files/Pointy-ahk.html>) - - this is mostly a helper class being used within this package, but maybe helpful anyway ...
* <Windy at http://hoppfrosch.github.io/AHK_Windy/files/Windy-ahk.html> - Windows
* <WindLy at http://hoppfrosch.github.io/AHK_Windy/files/WindLy-ahk.html> - Collection (List) of Windows
Author(s):
<hoppfrosch at hoppfrosch@gmx.de>
Expand All @@ -30,4 +31,4 @@
#include Windy.ahk


Version := "0.14.0"
Version := "0.15.0"
31 changes: 30 additions & 1 deletion lib/Windy/Mony.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class Mony {
_debug := 0
_version := "1.0.0"
_version := "1.0.1"
_id := 0
_hmon := 0

Expand Down Expand Up @@ -456,7 +456,36 @@ class Mony {
OutputDebug % "<[" A_ThisFunc "([" this.id "], disptime := " disptime ", txtcolor := " txtcolor ", txtsize := " txtsize ")]" ; _DBG_
return
}

/* ---------------------------------------------------------------------------------------
Method: rectToPercent
calculates monitor percents from given rectangle.
The given rectangle-coordinates are transformed into percent of the screen. For example on a 1920x1200 screen the coordinates x=394,y=240,w=960,h=400 are transformed into
(20, 20, 50, 33.33) because 394/1920 = 20%, 240/1200=20%, 960/1920=50%, 400/1200=33.33%
Parameter(s):
x,y,w,h - position and width/height to be transformed into screen percents
Returns:
<rectangle at http://hoppfrosch.github.io/AHK_Windy/files/Recty-ahk.html> containing screen percents.
*/
rectToPercent(rect) {
monBound := this.boundary

wfactor := (rect.w/monBound.w)*100
hfactor := (rect.h/monBound.h)*100
xfactor := (rect.x/monBound.w)*100
yfactor := (rect.y/monBound.h)*100

ret := new Recty(xfactor, yfactor, wfactor, hfactor, this._debug)

if (this._debug) ; _DBG_
OutputDebug % "|[" A_ThisFunc "([" this.hwnd "], rect=(" rect.Dump()")] -> percent=(" ret.Dump() ")" ; _DBG_

return ret
}

; ===== Internal Methods =========================================================
/* -------------------------------------------------------------------------------
method: __idHide
Expand Down
149 changes: 140 additions & 9 deletions lib/Windy/Windy.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Windy {
This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See <WTFPL at http://www.wtfpl.net/> for more details.
*/
_version := "0.8.3"
_version := "0.8.6"
_debug := 0
_hWnd := 0

Expand Down Expand Up @@ -204,7 +204,8 @@ class Windy {
flag - `true` or `false` (activates/deactivates *hidden*-Property)
Remarks:
* To toogle current *hidden*-Property, simply use `obj.hidden := !obj.hidden`
* To toogle current *hidden*-Property, simply use
> obj.hidden := !obj.hidden`
*/
get {
prevState := A_DetectHiddenWindows
Expand Down Expand Up @@ -291,7 +292,8 @@ class Windy {
flag - *true* or *false (activates/deactivates *hscrollable*-Property)
Remarks:
* To toogle current *hscrollable*-Property, simply use `obj.hscrollable := !obj.hscrollable`
* To toogle current *hscrollable*-Property, simply use
> obj.hscrollable := !obj.hscrollable
*/
get {
ret := (this.style & WS.HSCROLL) > 0 ? 1 : 0
Expand Down Expand Up @@ -695,7 +697,7 @@ class Windy {
Remarks:
* To toogle, simply use
> obj.resizeable := !obj.resizeable
* Same as property *sizebox*
* Same as property <sizebox at http://hoppfrosch.github.io/AHK_Windy/files/Windy-ahk.html#sizebox>
*/
get {
Expand Down Expand Up @@ -1147,6 +1149,77 @@ class Windy {
; ##################### End of Properties (AHK >1.1.16.x) ##############################################################

; ######################## Methods to be called directly ###########################################################
/* ---------------------------------------------------------------------------------------
Method: border2percent
translates a border string to monitor percents.
When moving the actual window from current position to a certain position on the window border (given by a border string (as for example "l", "hc" or "r vc")),
the border string is transformed to factors which describe the destination size/position of actual window in relation to the monitor the window is own. Using this
factors the window can be moved via 'this.movePercental(factor.x, factor.y, factor.w, factor.h)' to the destination position as specified in border string.
This method is needed as a helper method in order to allow an easy configuration of window alignment within AHK_EDE '
Parameter(s):
border - string describing the border to move to - for further description see <moveBorder at http://hoppfrosch.github.io/AHK_Windy/files/Windy-ahk.html#moveBorder>)
Returns;
<rectangle at http://hoppfrosch.github.io/AHK_Windy/files/Recty-ahk.html> containing the screen percents
See also:
<moveBorder at http://hoppfrosch.github.io/AHK_Windy/files/Windy-ahk.html#moveBorder>
*/
border2percent(border="") {
; check whether given border string is valid
posValid := false
StringLower, border, border
border := RegExReplace(border, "S) +", A_Space)
border := RegExReplace(border, "^ ", "")
border := RegExReplace(border, " $", "")
FoundPos := RegExMatch(border, "^(|t|b|l|r|vc|hc|l t|t l|l b|b l|l vc|vc l|r t|t r|r b|b r|r vc|vc r|hc t|t hc|hc b|b hc|hc vc|vc hc)$")
if (FoundPos > 0) {
posValid := true
}

if (posValid = true) {
currPos := this.posSize
mon := new Mony(this.monitorID, this._debug)
monWorkArea := mon.workingArea
monBound := mon.boundary

x := currPos.x
if (InStr(border,"l")) {
x := 0
} else if (InStr(border,"r")) {
x:= monBound.w - currPos.w

} else if (InStr(border,"hc")) {
x:= monBound.w/2 - currPos.w/2
}

y:= currPos.y
if (InStr(border,"t")) {
y := 0
} else if (InStr(border,"b")) {
y:= monBound.h - currPos.h
} else if (InStr(border,"vc")) {
y:= monBound.h/2 - currPos.h/2
}

destPos := new Recty(x, y, currPos.w, currPos.h)
ret := mon.rectToPercent(destPos)

if (this._debug) ; _DBG_
OutputDebug % "|[" A_ThisFunc "([" this.hwnd "], border=""" border """)] pos (" this.posSize.Dump()") on Mon " this.monitorId " -> percent (" ret.Dump() ")" ; _DBG_

return ret
}

if (this._debug) ; _DBG_
OutputDebug % "|[" A_ThisFunc "([" this.hwnd "], border=""" border """)] *** ERROR: Invalid border string <" border ">" ; _DBG_

return
}
/* ---------------------------------------------------------------------------------------
Method: kill
Kills the Window (Forces the window to close)
Expand Down Expand Up @@ -1182,7 +1255,7 @@ class Windy {
h - height (absolute) the window has to be resized to - use *99999* to preserve actual value *(Optional)*
See also:
<movePercental>
<movePercental() at http://hoppfrosch.github.io/AHK_Windy/files/Windy-ahk.html#movePercental>, <moveBorder() at http://hoppfrosch.github.io/AHK_Windy/files/Windy-ahk.html#moveBorder>
*/
move(X,Y,W="99999",H="99999") {
if (this._debug) ; _DBG_
Expand Down Expand Up @@ -1223,8 +1296,8 @@ class Windy {
hFactor - height-size factor (percents of current screen height) the window has to be resized to (Range: 0.0 to 100.0) (*Optional*, Default = 100)
See also:
[move()](move)
<move() at http://hoppfrosch.github.io/AHK_Windy/files/Windy-ahk.html#move>, <moveBorder() at http://hoppfrosch.github.io/AHK_Windy/files/Windy-ahk.html#moveBorder>
Author(s):
Original - <Lexikos at http://www.autohotkey.com/forum/topic21703.html>
Expand All @@ -1240,8 +1313,8 @@ class Windy {
monBound := mon.boundary
xrel := monWorkArea.w * xFactor/100
yrel := monWorkArea.h * yFactor/100
w := monWorkArea.w * wFactor/100
h := monWorkArea.h * hFactor/100
w := monBound.w * wFactor/100
h := monBound.h * hFactor/100

x := monBound.x + xrel
y := monBound.y + yrel
Expand All @@ -1250,7 +1323,65 @@ class Windy {

if (this._debug) ; _DBG_
OutputDebug % "<[" A_ThisFunc "([" this.hwnd "], xFactor=" xFactor ", yFactor=" yFactor ", wFactor=" wFactor ", hFactor=" hFactor ")] -> padded to (" this.posSize.Dump() ") on Monitor (" this.monitorID ")" ; _DBG_
}
/* ---------------------------------------------------------------------------------------
Method: moveBorder
move the window on the current screen to a border given by string while keeping the size.
Example(s):
* moves the window to the left border
> obj.moveBorder("l")
* moves the window to the left border and centers it vertically
> obj.moveBorder("l vc")
* moves the window to the top border and centers it horizontally
> obj.moveBorder("t hc")
* moves the window to the top left corner
> obj.moveBorder("t l")
Parameter(s):
border - string describing the border to move to
* "t" - top
* "b" - bottom
* "l" - left
* "r" - right
* "vc" - vertically centered
* "hc" - horizonally centered
See also:
<move() at http://hoppfrosch.github.io/AHK_Windy/files/Windy-ahk.html#move>, <movePercental at http://hoppfrosch.github.io/AHK_Windy/files/Windy-ahk.html#movePercental>
*/
moveBorder(border="") {
if (this._debug) ; _DBG_
OutputDebug % ">[" A_ThisFunc "([" this.hwnd "], border=""" border """)] -> started from (" this.posSize.Dump() ") on Monitor (" this.monitorID ")" ; _DBG_

factor := this.border2percent(border)
if (factor) {
this.movePercental(factor.x, factor.y, factor.w, factor.h)
}

if (this._debug) ; _DBG_
OutputDebug % ">[" A_ThisFunc "([" this.hwnd "], border=""" border """)] -> moved to (" this.posSize.Dump() ") on Monitor (" this.monitorID ")" ; _DBG_
}
/* ---------------------------------------------------------------------------------------
Method: posSize2percent
Calculates screen percents from current size of actual window
This method is needed as a helper method in order to allow an easy configuration of window alignment within AHK_EDE '
Returns;
<rectangle at http://hoppfrosch.github.io/AHK_Windy/files/Recty-ahk.html> containing the screen percents
*/
posSize2percent() {
currPos := this.posSize
mon := new Mony(this.monitorID, this._debug)
ret := mon.rectToPercent(currPos)

if (this._debug) ; _DBG_
OutputDebug % "|[" A_ThisFunc "([" this.hwnd "])] pos (" this.posSize.Dump()") on Mon " this.monitorId " -> percent (" ret.Dump() ")" ; _DBG_

return ret
}
/* ---------------------------------------------------------------------------------------
Method: redraw
Redraws the window.
Expand Down

0 comments on commit 6389c32

Please sign in to comment.