AutoHotkey Community

It is currently May 27th, 2012, 9:22 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 172 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 12  Next
Author Message
 Post subject:
PostPosted: August 13th, 2006, 2:33 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
That's a great improvement.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2006, 4:29 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2006, 4:58 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2006, 5:11 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Last edited by toralf on August 13th, 2006, 6:25 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2006, 5:38 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2006, 5:50 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2006, 6:26 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
It can even be made simpler. And faster, I assume. See my above post.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2006, 8:13 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Thanks for the suggestions. I've updated it to v3.1

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2006, 8:36 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Have you recognized the changes I applied in the above code? It is already version 3.2.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 14th, 2006, 8:50 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 15th, 2006, 4:42 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 15th, 2006, 4:09 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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 :?

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 15th, 2006, 4:42 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 15th, 2006, 6:29 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 15th, 2006, 8:21 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Your 3.2 version is great. Thanks for accepting my remarks. You have even lifted it to the next higher level. I will definetely use it in my next scripts.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 172 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 12  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: SKAN, Stigg and 8 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group