AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Control Anchoring v4 for resizing windows
Goto page Previous  1, 2, 3, ... 9, 10, 11  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5041
Location: imaginationland

PostPosted: Sun Aug 13, 2006 2:29 pm    Post subject: Reply with quote

Version 3 is much easier to use. The function does all the calculations itself so resizing with multiple windows and relatively positioned controls are not a problem at all. For example you can call Anchor("MyEdit", "wh") without having to specify the width, height or window number.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Sun Aug 13, 2006 2:33 pm    Post subject: Reply with quote

That's a great improvement.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Sun Aug 13, 2006 4:29 pm    Post subject: Reply with quote

I looked at the code of version 3.
I assume there is a bug in this line:
Code:
StringRight, wy, wy, InStr(wy, ",") - 1
This will return a wrong number for wy is the gui is not the last in the list. Since the code only trims away the left part of the win string, the windows on the right of the window in question are still in the string. Am I wrong?
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Sun Aug 13, 2006 4:58 pm    Post subject: Reply with quote

Another possible bug:
The code is designed to allow to use more then one GUI. But controls might be duplicate in the GUIs, Thus the pos array should not only list the control sizes by the control name, but in combination with the GUI id. That would it make it unequivocal, thus saver.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Sun Aug 13, 2006 5:11 pm    Post subject: Reply with quote

I would suggest:
Code:
Anchor(ctrl, a, draw = false) { ; v3.2 by Titan
    static pos

    If !InStr(pos, "|" . A_Gui . "_§$§_" . ctrl . ":") {
        GuiControlGet, p, Pos, %ctrl%
        pX -= %A_GuiWidth%
        pW -= %A_GuiWidth%
        pY -= %A_GuiHeight%
        pH -= %A_GuiHeight%
        pos = %pos%|%A_Gui%_§$§_%ctrl%:%pX%,%pW%,%pY%,%pH%
      }
    Loop, Parse, pos, |
        If InStr(A_LoopField, A_Gui . "_§$§_" . ctrl . ":"){
            StringSplit, Field, A_LoopField, :
            StringSplit, CtrlSize, Field2, `,
            Break
          }

    c = xwyh
    Loop, Parse, c
        If InStr(a, A_LoopField) {
            e := CtrlSize%A_Index%
            If A_Index < 3
                e += %A_GuiWidth%
            Else
                e += %A_GuiHeight%
            m = %m% %A_LoopField%%e%
          }

    If draw
        d = Draw
    GuiControl, Move%d%, %ctrl%, %m%
  }

_________________
Ciao
toralf


Last edited by toralf on Sun Aug 13, 2006 6:25 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5041
Location: imaginationland

PostPosted: Sun Aug 13, 2006 5:38 pm    Post subject: Reply with quote

toralf wrote:
But controls might be duplicate in the GUIs
I never knew this was allowed... should be an easy fix as you pointed it out though. I'll make this update when I get back home kthx.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Sun Aug 13, 2006 5:50 pm    Post subject: Reply with quote

Titan wrote:
toralf wrote:
But controls might be duplicate in the GUIs
I never knew this was allowed...
I meant that in each GUI there can be a Button1. Since they are in different GUIs it should be allowed.

I'm wondering if the code can be optimized for speed.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Sun Aug 13, 2006 6:26 pm    Post subject: Reply with quote

It can even be made simpler. And faster, I assume. See my above post.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5041
Location: imaginationland

PostPosted: Mon Aug 14, 2006 8:13 pm    Post subject: Reply with quote

Thanks for the suggestions. I've updated it to v3.1
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Mon Aug 14, 2006 8:36 pm    Post subject: Reply with quote

Have you recognized the changes I applied in the above code? It is already version 3.2.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5041
Location: imaginationland

PostPosted: Mon Aug 14, 2006 8:50 pm    Post subject: Reply with quote

It parses twice to makes extra calculations and store values in memory for anchors that might not even be used. This means it would take longer than it should. I've used your suggestions to optimize the original script and make all control references window specific. Thanks.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Tue Aug 15, 2006 4:42 am    Post subject: Reply with quote

Titan wrote:
It parses twice to makes extra calculations

Why do you think so? It only has one loop now. It actually is less calculation.
For each control the current POS is stored with the Width/Height substracted only at initialisation. The initial window size doesn't have to be memorized in an extra list and it saves one calculation in the subsequent calls of anchor for e. Plus the handling of the win list is not needed.

Titan wrote:
and store values in memory for anchors that might not even be used.
Which? It stores less values then before. The win list doesn't exist anymore.

Titan wrote:
This means it would take longer than it should.
Why?

Titan wrote:
I've used your suggestions to optimize the original script and make all control references window specific. Thanks.
Thanks. The 3.2 version has the same feature.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5041
Location: imaginationland

PostPosted: Tue Aug 15, 2006 4:09 pm    Post subject: Reply with quote

toralf wrote:
It only has one loop now.
You have "Loop, Parse, , pos, |" and "Loop, Parse, c".

toralf wrote:
It actually is less calculation.
The calculations, pX, pW, pY and pH don't all have to be done before hand because only one or two anchors are ever used at once.

toralf wrote:
For each control the current POS is stored with the Width/Height substracted only at initialisation. The initial window size doesn't have to be memorized in an extra list and it saves one calculation in the subsequent calls of anchor for e. Plus the handling of the win list is not needed.
It's simpler to save the window dimensions to calculate the needed control positions.

Titan wrote:
... and store values in memory for anchors that might not even be used.
pX, pW, pY and pH don't have to be created because the math can be done in one go and added to "m" for GuiControl.

Titan wrote:
This means it would take longer than it should.
Extra calculations + extra variables + another parse = more time Confused
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Tue Aug 15, 2006 4:42 pm    Post subject: Reply with quote

I'm sorry. I was basing my judgement on the 3.1 code I suggested. I looked at your code again:
Code:
Anchor(ctrl, a, draw = false) { ; v3.1 by Titan
   static win, pos
   pre = `n%A_Gui%:
   If !InStr(win, pre)
      win = %win%%pre%%A_GuiWidth%,%A_GuiHeight%
   StringTrimLeft, wy, win, InStr(win, pre) + 2
   StringLeft, wx, wy, InStr(wy, ",") - 1
   StringRight, wy, wy, InStr(wy, ",") - 1
This will not work if in the string win more then one window is stored and the window that calls Anchor is not the last in the string! Since StringRight will then put a lot of garbage in wy.
Code:
   If !InStr(pos, pre . ctrl) {
      GuiControlGet, p, Pos, %ctrl%
      pos = %pos%%pre%%ctrl%,%pX%,%pW%,%pY%,%pH%,
   }
   StringTrimLeft, p, pos, InStr(pos, pre . ctrl) + StrLen(ctrl) + 1
   c = xwyh
   Loop, Parse, c
      If InStr(a, A_LoopField) {
         StringGetPos, e, p, `,, L%A_Index%
         StringTrimLeft, e, p, e + 1
         StringLeft, e, e, InStr(e, ",") - 1
         If A_Index < 3
            e += A_GuiWidth - wx
         Else e += A_GuiHeight - wy
The math with wx and wy is done every time Anchor is called, which can be very often. While in my code the wx and wy is substracted from the values only once. Which reduces the number of math actions.
Code:

         m = %m%%A_LoopField%%e%
      }
   If draw
      d = Draw
   GuiControl, Move%d%, %ctrl%, %m%
}


You say, that my code uses extra calculations. I doubt that.
1) It is less math, if you cound the number of times simple math is performed. I'm counting "e += A_GuiWidth - wx" as two math operations.
2) My code uses an extra parse loop, but your code uses much more string manipulation. It would need a test to see which is faster. And BTW: The parse loop can be avoided and replaced with your code, but then a comma has to follow the pH in the pos string.
3) One benefit of my code is that the original window size doesn't have to be fetched each time Anchor is called, it is already in the pos of the control. Which in total saves 3 string manipulations (which might be buggy as mentioned above) each time Anchor is called (but adding 4 simple math operations for each control during first call). I guess the math math in the beginning is shorter in time then doing the string maipulation each time. But I might be wrong since all these are very simple operations which might be done by the OS in no time.

Sorry, for being stuborn. Discard my comments if they offend you.

A compromize would be:
Code:
Anchor(ctrl, a, draw = false) { ; v3.3 by Titan
    static pos

    If !InStr(pos, "|" . A_Gui . "_§$§_" . ctrl . ":") {
        GuiControlGet, p, Pos, %ctrl%
        pX -= %A_GuiWidth%
        pW -= %A_GuiWidth%
        pY -= %A_GuiHeight%
        pH -= %A_GuiHeight%
        pos = %pos%|%A_Gui%_§$§_%ctrl%:%pX%,%pW%,%pY%,%pH%,
      }
    StringTrimLeft, CtrlSize, pos, InStr(pos, "|" . A_Gui . "_§$§_" . ctrl) + StrLen("|" . A_Gui . "_§$§_" . ctrl) + 1
    StringSplit, CtrlSize, CtrlSize, `,

    c = xwyh
    Loop, Parse, c
        If InStr(a, A_LoopField) {
            e := CtrlSize%A_Index%
            If A_Index < 3
                e += %A_GuiWidth%
            Else
                e += %A_GuiHeight%
            m = %m% %A_LoopField%%e%
          }

    If draw
        d = Draw
    GuiControl, Move%d%, %ctrl%, %m%
  }
*not tested*
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5041
Location: imaginationland

PostPosted: Tue Aug 15, 2006 6:29 pm    Post subject: Reply with quote

Thanks, your feedback and constructive criticism is very helpful.

Like you proved, saving the window dimensions isn't needed. I have adopted your format of calculating positions and simplified it. Please see the new 3.2 version along with the updated example.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, ... 9, 10, 11  Next
Page 2 of 11

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group