Jump to content

GUICtrlCreateLine


erifash
 Share

Recommended Posts

I guess it could be something like, click the "Triangle" button, then you click 3 points on the GUI and it joins them together. I guess if you wanted you could go as far as having Scalene, Equilateral and Isosceles triangles :).

qq

Link to comment
Share on other sites

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I guess it could be something like, click the "Triangle" button, then you click 3 points on the GUI and it joins them together. I guess if you wanted you could go as far as having Scalene, Equilateral and Isosceles triangles :).

<{POST_SNAPBACK}>

I suppose next your going to want 'Rhombus', 'Parallelogram' functions. Ok, I'll think about it.

601DisengageEnd Program

Link to comment
Share on other sites

You guessed it lol, while your at it why not add Pentagon, Hexagon, Heptagon, Octagon, Nonagon and a Decagon :), jk lol.

<{POST_SNAPBACK}>

Sure... NP, I'll just add the "Keep clicking untill I tell you to stop" tip, LOL :D Edited by Smed

601DisengageEnd Program

Link to comment
Share on other sites

I updated the include with sylvanie's version of GUICtrlCreateLine that can make vertical and backwards lines (meaning that x2 + y2 < x1 + y1).

Here it is:

line.au3

...and if you try out the new backwards and vertical lines in the example:

#include <GUIConstants.au3>
#include <line.au3>

GUICreate("Linear Example", 320, 320)
$x = GUICtrlCreateLine(20, 10, 20, 300, 1, "0xFF0000")
$y = GUICtrlCreateLine(300, 20, 50, 300, 5, "0x00FF00")
$z = GUICtrlCreateLine(60, 120, 250, 180, 10, "0x0000FF")

GUISetState()

Do
  $msg = GUIGetMsg()
  Sleep(10)
Until $msg = $GUI_EVENT_CLOSE

GUICtrlDeleteGroup($x)
GUICtrlDeleteGroup($y)
GUICtrlDeleteGroup($z)

Sleep(3000)

...you will notice that it ACTUALLY works!

(hint: the green line is the backwards one)

Link to comment
Share on other sites

Hello,

it's kind to use this method Erifash, but I think that the Smed's code is better than the modelisation with Cartian Line.

Another problem, with my last post, is that if we have a big coefficient, the points are not linked very well. exple : GUICtrlCreateLine(60, 120, 70, 280, 1, "0x0000FF")

So If you want to use the method, replace the code by this one :

Func GUICtrlCreateLine($x1, $y1, $x2, $y2, $size = 1, $color = "0x000000")
if $x1<>$x2 Then
  if $x1>$x2 Then  Return (GUICtrlCreateLine($x2, $y2, $x1, $y1, $size, $color))
  $diffx=$x2-$x1
  $coeff_line = ( $y2-$y1 ) / $diffx
  $p = $y2 - ( $coeff_line * $x2 )
  $step=1
  if abs($coeff_line)>1 Then $step=abs(1/$coeff_line); $step is calculate to draw "nice" line, if coeff_line > 1 then we need coeff_line vertical points beetwen 2 horizontal; if coeff_line<1 only 1 vertical point is needed
  $alg = _Ceil($diffx/$step)
  Dim $id[$alg + 2]
  $id[0] = $alg + 1
  $alg=1
  For $a = $x1 to $x2 Step $step
        $id[$alg ] = GUICtrlCreateLabel("", $a, $a * $coeff_line  + $p, $size, $size)
        GUICtrlSetBkColor($id[$alg], $color)
        $alg=$alg+1
  Next
Else    
   $alg = Int(Abs($y2 - $y1) / $size)
    Dim $id[$alg + 2]
    $id[0] = $alg + 1
    $step = 1
    if $y1>$y2 Then $step = -1
    $alg=1
    For $a = $y1 to $y2 step $step
    $id[$alg] = GUICtrlCreateLabel("", $x1, $a, $size, $size)
    GUICtrlSetBkColor($id[$alg], $color)
    $alg = $alg+1
    Next
EndIf
Return $id
EndFunc

I have modified the calc of the index of $id to avoid divisions. And I have caculated a step wich represents the number of vertical points to draw between 2 horizontal points.

so let m=the coefficient.

if abs(m) > 1 then we need abs(m) verical points to link 2 horizontal points

else 1 point is needed.

So this code works, doesn't take more cpu time than Smed's code, but mine is longer and less readable.

Good job Smed ! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...