AutoHotkey Community

It is currently May 27th, 2012, 1:33 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 172 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8 ... 12  Next
Author Message
 Post subject:
PostPosted: December 3rd, 2006, 7:46 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
AGU wrote:
I don't get this thing with the factors e.g. x0.5. What's it good for?
Click to open the second window in the example script on the front page.

AGU wrote:
Then I'd like to ask if it would be possible to get a commented version of your new script (just like toralf but for the new version ;))?
I never comment my scripts, I find it confusing lol. Chris taught me the importance of commenting and I tried to make it a habit, but I guess I'm too lazy sometimes. I'll post a commented version soon.

AGU wrote:
Do I have to change s.th here or could I just paste your new version over the old one?
Version 1.x, 2.x nor 3.x are not compatible with each other. For v3 you'll have to make calls like this instead (you won't need to get control positions!):
Code:
Anchor("EdtComment", "wh")
Anchor("GrpMenuBorder", "w")
Anchor("ChkSig", "y")
Anchor("DDLSig", "y")
Anchor("BtnEditSig", "y")
Anchor("BtnDelSig", "y")
Anchor("BtnSend", "xy", true)
Anchor("BtnPreview", "xy", true)
Anchor("BtnReset", "xy", true)
Anchor("BtnPinned", "x")

If you have many more controls and speed is not an issue you can use a fancy parser:
Code:
a = EdtComment: wh, GrpMenuBorder: w, ChkSig: y, DDLSig: y, BtnEditSig: y
   , BtnDelSig: y, BtnSend: xy draw, BtnPreview: xy draw, BtnReset: xy draw
   , BtnPinned: x

Loop, Parse, a, `,, %A_Space%
{
   StringSplit, a, A_LoopField, :
   a3 := InStr(a2, "draw")
   Anchor(a1, a3 ? SubStr(a2, 1, a3 - 1) : a2, !!a3)
}

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 3rd, 2006, 8:15 pm 
hmm, Ok I checked the example but I don't get it.

Could you maybe describe this factors feature in some words? What would e.g. x0.5 do? Sorry if this a dumb question but I'm having a dumb moment. ;)
_______________________
Cheers
AGU


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2006, 6:54 pm 
Hi Titan,

still waiting for the commented version ;) :mrgreen:

My ambition is always to only use code which I fully understand. That's why I started studying your new code (v3) line by line. I even managed to understand this first regex (puh, that was a tough job :)). But now I'm stuck and would be happy about a commented version.

If it's not asked too much, I would be happy about some words about the basic mechanism behind the script. How are these positions calculated with the help of A_GuiWidth and A_GuiHeight. You don't have to, if you think this is too much. :) Sooner or later I will get it by studying the script but any help would be cool.
______________________
Cheers
AGU


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2006, 7:28 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Oh sorry about that, I started and left it half way to work on a javascript for this forum. I'll try have it ready by around this time tomorrow, thanks.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2006, 5:40 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Phew, done: http://www.autohotkey.net/~Titan/dl/dev ... .1-RFC.ahk

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2006, 5:40 pm 
Offline

Joined: January 18th, 2006, 7:39 am
Posts: 274
Location: Conway, Arkansas
Titan, this may be a bug in the Anchor script. Example code:

Code:
Gui, +Resize
Gui, Margin, 10, 10
Gui, Add, ListView, xm ym+20  w200 h100 Grid vlv_One, One|Two|Three
Gui, Add, ListView, xm ym+140 w200 h200 Grid vlv_Two , Four|Five|Six
Gui, Add, StatusBar
Gui, Show, Autosize Center
Return
; ------------------------------------------------------------------------

GuiEscape:
GuiClose:
ExitApp

; ------------------------------------------------------------------------

GuiSize:
{
    ; This works perfectly...
   
    Anchor( "lv_One", "w h0.2", 1 )
    Anchor( "lv_Two", "y0.2 w", 1 )
   
    ; ...but, I want the bottom listview to resize vertically as well so I
    ; add the 'h'. 
   
    ; Anchor( "lv_Two", "y0.2 w h", 1 )
   
    ; However, when I add the 'h', the bottom listview disappears (or is
    ; somewhere off the main form).
   
    ; Furthermore, if you take out the 'y' param, it does what it should
    ; (except, of course, that the bottom listview doesn't move up/down now).
   
    ; Anchor( "lv_Two", "w h", 1 )
}
Return

; ------------------------------------------------------------------------

Anchor( ctrl, a, draw = false ) { ; v3.4.1 - Titan
   static d
   GuiControlGet, p, Pos, %ctrl%
   If !A_Gui or ErrorLevel
      Return
   s = `n%A_Gui%:%ctrl%=
   c = x.w.y.h./.7.%A_GuiWidth%.%A_GuiHeight%
   StringSplit, c, c, .
   Loop, 4
      b%A_Index% += !RegExMatch(a, c%A_Index% . "(?P<" . A_Index . ">[\d.]+)", b)
   If !InStr(d, s)
      d := d . s . px - c7 * b1 . c5 . pw - c7 * b2
         . c5 . py - c8 * b3 . c5 . ph - c8 * b4 . c5
   Loop, 4
      If InStr(a, c%A_Index%) {
         i = %A_Index%
         c6 += i > 2
         RegExMatch(d, s . "(?:(-?[\d.]+)/){" . i . "}", p)
         m := m . c%i% . p1 + c%c6% * b%i%
      }
   If draw
      t = Draw
   GuiControl, Move%t%, %ctrl%, %m%
}

; ------------------------------------------------------------------------


If my examples weren't clear enough, please let me know. As always, thanks for the Anchor script. =]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2006, 6:14 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Thanks for the example, I fixed this bug in version 3.4.2 with c6 += !t and (t := i > 2) to prevent repetitive increments so height values are calculated properly.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2006, 6:43 pm 
Offline

Joined: January 18th, 2006, 7:39 am
Posts: 274
Location: Conway, Arkansas
Thank you very much. If anybody is interested, the final Anchor calls to do what I want look like this (using my example code above):

Code:
Anchor( "lv_One", "w h0.2", 1 )
Anchor( "lv_Two", "y0.2 w h0.8", 1 )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2006, 6:58 pm 
Offline

Joined: January 18th, 2006, 7:39 am
Posts: 274
Location: Conway, Arkansas
Upon further testing of apps I've written that use the Anchor function, it seems that this latest version has broken controls when using Move mode. If you set those controls to MoveDraw mode, they work as before.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2006, 7:05 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
My mistake sorry, the variable 't' is used for the Move/Draw part. I left the version number the same so just download it again.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2006, 7:10 pm 
Offline

Joined: January 18th, 2006, 7:39 am
Posts: 274
Location: Conway, Arkansas
Beautiful. Thanks again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 15th, 2007, 2:12 pm 
Hi Titan,

I have "AGUnized" your Anchor function. :lol:

Code:
Anchor(In_CtrlVar, In_Anchor, Draw = false)
  {
    ; Thanks to Titan for this function (v3.4.2)
    ; Details under http://www.autohotkey.com/forum/topic4348.html
   
    ; In_CtrlVar  : Controls associated variable (e.g. "MyEdit")
    ; In_Anchor   : Anchors (x, y, w, h)
    ; Draw        : true/1 to use MoveDraw otherwise leave blank for a normal Move 
 
    ; store control positions and sizes in an internally parsable table-like format
    static DataTbl
     
    ; Retrieve control's size and position
    GuiControlGet, CtrlPS, Pos, %In_CtrlVar%
    ; If control doesn't exist or this thread isn't called by a GUI event...
    If !A_Gui or ErrorLevel
      Return
     
    ; Create identifier for the control in the current window
    Signtre = `n%A_Gui%:%In_CtrlVar%=
    ; Period-delimited variable for parsing support
    PrsHlp = x.w.y.h./.7.%A_GuiWidth%.%A_GuiHeight%
    StringSplit, PrsHlp, PrsHlp, .
     
    ; Retrieve relative factors by RegEx and store them into "RelFact" array
    Loop, 4
      RelFact%A_Index% += !RegExMatch(In_Anchor, PrsHlp%A_Index% . "(?P<" . A_Index . ">[\d.]+)", RelFact)

    ; If current signature is not found in the data table, concatenate each value
    ; subtracted by the gui width for x/w or height for y/h and multiplied by it's factor.
    If !InStr(DataTbl, Signtre)
      DataTbl := DataTbl . Signtre . CtrlPSX - PrsHlp7 * RelFact1 . PrsHlp5 . CtrlPSW - PrsHlp7 * RelFact2
              .  PrsHlp5 . CtrlPSY - PrsHlp8 * RelFact3 . PrsHlp5 . CtrlPSH - PrsHlp8 * RelFact4 . PrsHlp5
     
    ; For each of the four possible anchors (again):
    Loop, 4
      If InStr(In_Anchor, PrsHlp%A_Index%)
        {
          ; Alias for the Loop index
          LoopIdx = %A_Index%
          ; For x/w, PrsHlp6 equals to the GUI width, otherwise height
           PrsHlp6 += !cx AND (cx := LoopIdx > 2)
          ; This regular expression assigns the variable CtrlPS1 to the absolute dimension
          ; stored in the data table:
           RegExMatch(DataTbl, Signtre . "(?:(-?[\d.]+)/){" . LoopIdx . "}", CtrlPS)
          ; Concatenate the new value and it's anchor to the variable 'NewVal':
           NewVal := NewVal . PrsHlp%LoopIdx% . CtrlPS1 + PrsHlp%PrsHlp6% * RelFact%LoopIdx%
        }
    ; If Draw is true use GuiControl, MoveDraw instead of normal GuiControl, Move
    If Draw
      GCtrlMv = Draw
    ; Update the positions of the control
    GuiControl, Move%GCtrlMv%, %In_CtrlVar%, %NewVal%
  }


The only thing I don't get at the moment is this 'cx' variable in
Code:
c6 += !cx and (cx := i > 2)
Is it a completely new variable or is it somehow connected to your period-delimited parse string?
__________________________
Cheers AGU


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 15th, 2007, 2:23 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
It's a complicated way of saying If (i = 3) c6++ or c6 += i = 3. I can't remember why I used that, it will be changed in the next version.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 16th, 2007, 11:07 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
In update version 3.5 I simplified loops and expressions so it should hopefully work faster.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 16th, 2007, 3:11 pm 
Commented version? ;)
______________________
Cheers AGU


Report this post
Top
  
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, 6, 7, 8 ... 12  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 15 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