Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[How To] Draw Lines in a GUI :: GuiDrawLine()


  • Please log in to reply
8 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Laszlo, :)

How to Create a Vertical / Horizontal line in a GUI ?

That was my long standing question. I did not want Bump that topic because it was posted in "Wish List".
So I post my Thanks here.

I would have never imagined that the font size could be less than "8".

Regards, :)
kWo4Lk1.png

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Vertical and horizontal lines can be drawn also with SplashImage, although they are not part of a Gui. If you want them moveable with your Gui, you have to dock them. And, of course, you can always create an empty, narrow Gui, without caption. Its border provides the lines. Inside a GUI, other narrow controls work, too, but GroupBoxes looked the simplest.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

How to Draw Lines in a GUI? GuiDrawLine()
http://www.autohotke...p?p=60228#60228

Foreword:
Thanks to Laszlo & PhiLho for invoking
creativity in me. (Please refer the above few posts.)

I hope, someday AHK will have something like:
Gui, Draw, Line,,
Gui, Draw, Box,,



GuiDrawLine(X,Y,LineLength,Horizontal,Gui_Instance_Number)
Note: All the 5 parameters are expected as numbers.

[*:192fqqar]The X Coordinate on the GUI
[*:192fqqar]The Y Coordinate on the GUI
[*:192fqqar]The Length of the line
[*:192fqqar]0 for Vertical Line and 1 for Horizontal Line.
[*:192fqqar]GUI Instance Number 1-99
GuiDrawLine(X,Y,Size,VH="",Guin="") {
If (Guin="" OR Guin<1 OR Guin>99)
    Guin=1

If VH=
   VH=1

Size+=4

Gui, %Guin%:Font, S1

if VH
   Gui, %Guin%:Add, Text, x%X% y%Y% w%Size% 0x10
Else
   Gui, %Guin%:Add, Text, x%X% y%Y% h%Size% 0x11

Gui, %Guin%:Font, S
Return errorlevel
}

Important Notes:[*:192fqqar]The lines drawn are Text Control so GUI, Font affects it. The functions sets it to lowest! (Thanks to Laszlo!)

[*:192fqqar]For example, if the Font size was 14 when GuiDrawLine() was called, it will be reset to Windows Default Font Size.
[*:192fqqar]You may add line: GUI, Font, s%RequiredFontSize% after calling GuiDrawLine().[*:192fqqar]Again, remember that the lines are Text Control and that there is an upper limit to controls. ( 5000+ ?! ).

[*:192fqqar]I tested a 100 Pixels wide line, and only 96 pixels wide line was drawn.

[*:192fqqar]To overcome this, I have included the line Size+=4 on the function.
[*:192fqqar]One should/may modify it ( to suit needs ) if the lines are not in proper size.[/list]
Experiment 1 :
Posted Image
Gui, 1:+ToolWindow
Gui,1:Margin,0,0
GuiDrawLine(20,20,80)
GuiDrawLine(20,20,80,0)
GuiDrawLine(80, 0,80,0)
GuiDrawLine(0, 80,80)
Gui,1:Show,x10 y10 w100 h100,GUI:1

Gui, 2:+ToolWindow
GuiDrawLine(0,10,100,1,2)
GuiDrawLine(0,90,100,1,2)
GuiDrawLine(10,0,100,0,2)
GuiDrawLine(90,0,100,0,2)
Gui,2:Show,x125 y10 w100 h100,GUI:2

Gui, 3:+ToolWindow
GuiDrawLine(0,33,100,1,3)
GuiDrawLine(0,66,100,1,3)
GuiDrawLine(33,0,100,0,3)
GuiDrawLine(66,0,100,0,3)
Gui,3:Show,x240 y10 w100 h100,GUI:3
Return

; Copy and Paste GuiDrawLine() below

Experiment 2 :
Posted Image
Gui,1:+ToolWindow
Gui,1:Margin,0,0
Gui, 1:Font, s36 Bold , Verdana
Gui, 1:Add, Text, x10 y10 w400, Text Written Before Line Drawing
LineSize=1
y=1

Loop, 65 {
 GuiDrawLine(0,Y,LineSize,1,1)
 LineSize+=5
 y+=6
}

Gui, 1:Font, s36 Bold
Gui, 1:Add, Text, x10 y200 w400 BackgroundTrans, Transparent Text Written After Drawing
Gui,1:Show, ,GUI:1
Return

; Copy and Paste GuiDrawLine() below
Comments / Suggestions are welcome.

:D :D :D



evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
Interesting effect. Now if you want a real challenge you can try to get your head around the line drawing code that shimanov posted a while back (and is used for the window/control highlighting in the AHK Window Info script) - I've been meaning to make a window/control highlighting function, but never enough time :lol:

Reminds me of a line-drawing 3D first person shooting game that I played a few times on my old TI-85 graphics calculator :lol: If it can be done on a calculator with a few MHz of processing power it's only a matter of time before it's done in AHK :D

Veovis
  • Members
  • 389 posts
  • Last active: Mar 17 2009 12:24 AM
  • Joined: 13 Feb 2006
Nice Work! I remember reading a post in which groupboxes where used draw boxes and lines, and i couldnt get it to work. This works perfectly! Your TipsNTricks continue to amaze me! Keep up the good work!
Posted Image
"Power can be given overnight, but responsibility must be taught. Long years go into its making."

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Very nice and creative use of the SS_ETCHEDHORZ and SS_ETCHEDVERT styles (I give away your "trade secrets"... :-)).

I get undue credit, as I only suggested to use a Picture. My solution has the advantage of allowing to change colors (but using system colors is good too) and the disavantage of necessitating an image file (or some complex trick...).
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Interesting effect. Now if you want a real challenge you can try to get your head around the line drawing code that shimanov posted a while back (and is used for the window/control highlighting in the AHK Window Info script) - I've been meaning to make a window/control highlighting function, but never enough time :lol:


I guess you are referring to Analytic graphing facility by Shimanov. Or something else?

Shimanov's code :!: :shock:
I am not that good in Scripting! :D



Nice Work! .............This works perfectly! Your TipsNTricks continue to amaze me! Keep up the good work!


Thank you Veovis :D



Very nice and creative use of the SS_ETCHEDHORZ and SS_ETCHEDVERT styles (I give away your "trade secrets"... :-)).


No secrets!... Just an accidental discovery! I was attempting brute force method to Vertically center text in a Text Control and to my surprise I found this out. ( I'm yet to find a way for Vertically centering text! Or maybe it cannot be done .. :( ... Mr.Chris? )

I get undue credit, as I only suggested to use a Picture. My solution has the advantage of allowing to change colors (but using system colors is good too) and the disavantage of necessitating an image file (or some complex trick...).


These days I've been using your set of Binary Functions for many things. I did attempt to write a function that will create a line.bmp based on window background color.

But we have a better solution now, Simple and Straight ;)

Regards, :)



PS: Please bear with me for delayed reply. I am using replies to *Bump* this topic at appropriate time.
kWo4Lk1.png

Ronins
  • Members
  • 120 posts
  • Last active: Apr 18 2016 10:54 PM
  • Joined: 11 Apr 2012
I know this thread is pretty old, just wanted to add another way.

I do it using extremely narrow groupbox, here is the code

Gui, Add, GroupBox,w300 h10

Add x and y according to your needs. Change height with width to generate vertical lines. I prefer a "double line". So i increase the height of this groupbox to give "double line" effect.

Klark92
  • Members
  • 870 posts
  • Last active: Dec 29 2015 09:47 PM
  • Joined: 19 Feb 2012
Where is the Skan's download link ?

Edit: Yeah that is good function :)

I CAN PROTECT YOUR SCRIPT (ANTI-DECOMPILER by Klark92) (AHK_L*)(PM)
Klark92's Script2Exe Wizard
AHK_L / AHK COMPILED EXE / BIN ICON CHANGER