Jump to content

How to delete drawn lines


Istanful
 Share

Recommended Posts

Hello!

First post on this forum so please go easy on me! :)

 

So the other day I made a script for calculating powercurves for a game I'm making. As usual the code got bigger with time and I ended up making

some graphs on my own. (Since AutoIT don't have built in graphs) I'm making the graphs by drawing a line from point A to point B specified by the generated algorithm. It works totally ok but I can't wrap my head around how I clear them when I redraw them. So how do I delete the lines? :P 

 

Thanks for the help and sorry for the messy code. :)

#Include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <ColorConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>


#Region ### START Koda GUI section ### Form=
$Xp = GUICreate("Xp", 897, 561, 453, 78)
$curveInput = GUICtrlCreateInput("", 72, 8, 81, 21)
$startingXPInput = GUICtrlCreateInput("", 72, 36, 81, 21)
$noLvlsInput = GUICtrlCreateInput("", 240, 6, 81, 21)
$targetXPInput = GUICtrlCreateInput("", 240, 33, 81, 21)
$curveLabel = GUICtrlCreateLabel("Curve:", 24, 8, 42, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$startingLabel = GUICtrlCreateLabel("Starting:", 8, 35, 56, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$noLvlsLabel = GUICtrlCreateLabel("No. levels:", 168, 6, 72, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$targetXPLabel = GUICtrlCreateLabel("Target:", 184, 33, 49, 21)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$generateEmricButton = GUICtrlCreateButton("Generate Emric curve", 8, 114, 161, 25)
$valueList1 = GUICtrlCreateListView("Cost|Diff|Total", 8, 168, 161, 353)
GUICtrlSetColor(-1, $COLOR_RED)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
$valueList2 = GUICtrlCreateListView("Cost|Diff|Total", 171, 168, 158, 353)
GUICtrlSetColor(-1, $COLOR_GREEN)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
$usingTarget = GUICtrlCreateCheckbox("", 168, 32, 17, 17)
$generateWilliamButton = GUICtrlCreateButton("Generate William curve", 8, 141, 161, 25)
$generateCurves = GUICtrlCreateButton("Generate curves", 8, 87, 321, 25)
$generateEmricButton2 = GUICtrlCreateButton("Generate Emric curve", 168, 114, 161, 25)
$generateWilliamButton2 = GUICtrlCreateButton("Generate William curve", 169, 141, 161, 25)
$copyToClipButton1 = GUICtrlCreateButton("Copy to clip", 8, 527, 161, 25)
$copyToClipButton2 = GUICtrlCreateButton("Copy to clip", 169, 527, 161, 25)
$copyToClipButton = GUICtrlCreateButton("Copy to clip", 8, 60, 321, 25)
GUISetState(@SW_SHOW)
$graphGraphic = GUICtrlCreateGraphic(344, 8, 545, 545, $SS_BLACKFRAME)
#EndRegion ### END Koda GUI section ###

Global $curve
Global $noLvls
Global $startingXP
Global $displayGraph
Global $formula[2]

#cs
ConsoleWrite(15^2 & @CRLF)
ConsoleWrite((-12.333333*15) & @CRLF)
ConsoleWrite(225 & @CRLF)
#ce

ConsoleWrite("test: " & (15^2)*(-12.3333333*15)+10  & @CRLF)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $generateEmricButton
            $activeList = $valueList1
            generateEmricCurve()
        Case $generateEmricButton2
            $activeList = $valueList2
            generateEmricCurve()
        Case $generateWilliamButton
            $activeList = $valueList1
            generateWilliamCurve()
        Case $generateWilliamButton2
            $activeList = $valueList2
            generateWilliamCurve()
        Case $generateCurves
            $activeList = $valueList1
            generateEmricCurve()
            $activeList = $valueList2
            generateWilliamCurve()
        Case $copyToClipButton
            ClipPut("Formula 1: " & $formula[0] & @CRLF & "Formula 2: " & $formula[1])
        Case $copyToClipButton1
            ClipPut("Formula 1: " & $formula[0])
        Case $copyToClipButton2
            ClipPut("Formula 1: " & $formula[1])


    EndSwitch
WEnd

Func generateEmricCurve()

    _GUICtrlListView_DeleteAllItems($activeList)
    $curve = GUICtrlRead($curveInput)
    $startingXP = GUICtrlRead($startingXPInput)
    $noLvls = GUICtrlRead($noLvlsInput)
    $targetXP = GUICtrlRead($targetXPInput)
    Local $xpClip[$noLvls+1][3]

    If GUICtrlRead($usingTarget) = 1 Then
        $curve = ($targetXP-($noLvls^2)-10)/$noLvls
    EndIf


    For $lvl = 1 To $noLvls

        $xpClip[$lvl][0] = Floor(($lvl^2)+($curve*$lvl)+$startingXP)
        $xpClip[$lvl][1] = $xpClip[$lvl][0] - $xpClip[$lvl-1][0]
        $xpClip[$lvl][2] = $xpClip[$lvl-1][2] + $xpClip[$lvl][0]
        GUICtrlCreateListViewItem( _
        $xpClip[$lvl][0] & "|"& _
        $xpClip[$lvl][1] & "|" & _
        $xpClip[$lvl][2] & "|" _
        , $activeList)

        #Region Graph
        If $activeList = $valueList2 Then
            GUICtrlSetGraphic($graphGraphic, $GUI_GR_COLOR, $COLOR_GREEN)
        Else
            GUICtrlSetGraphic($graphGraphic, $GUI_GR_COLOR, $COLOR_RED)
        EndIf

            GUICtrlSetGraphic($graphGraphic, $GUI_GR_MOVE, ($lvl-1)/$noLvls*(545/$noLvls)*10, 545 -(Floor((($lvl-1)^2)+($curve*($lvl-1))+$startingXP)/Floor(($noLvls^2)+($curve*$noLvls)+$startingXP))*545)
            GUICtrlSetGraphic($graphGraphic, $GUI_GR_LINE, ($lvl)/$noLvls*(545/$noLvls)*10, 545 -(Floor((($lvl)^2)+($curve*$lvl)+$startingXP)/Floor(($noLvls^2)+($curve*$noLvls)+$startingXP))*545)
            GUISetState(@SW_SHOW)
        #EndRegion
    Next
    $graphGraphic = GUICtrlCreateGraphic(344, 8, 545, 545, $SS_BLACKFRAME)

    If $activeList = $valueList1 Then
        If GUICtrlRead($usingTarget) = 1 Then
            $formula[0] = "lvl^2+" & $curve & "*lvl"
        Else
            $formula[0] = "lvl^2+" & $curve & "*lvl+" & $startingXP
        EndIf
    Else
        $formula[1] = "lvl^2+" & $curve & "*lvl+" & $startingXP
    EndIf


EndFunc

Func generateWilliamCurve()
    _GUICtrlListView_DeleteAllItems($activeList)
    $curve = GUICtrlRead($curveInput)
    $startingXP = GUICtrlRead($startingXPInput)
    $noLvls = GUICtrlRead($noLvlsInput)
    $targetXP = GUICtrlRead($targetXPInput)
    Local $xpClip[$noLvls+1][3]

    If GUICtrlRead($usingTarget) = 1 Then
        ConsoleWrite((Sqrt($targetXP))/($noLvls^2) & @CRLF)
        $curve = (Sqrt($targetXP-$startingXP))/($noLvls)
    EndIf

    For $lvl = 1 To $noLvls
        $xpClip[$lvl][0] = Ceiling($startingXP + ($lvl*($curve))^2)
        $xpClip[$lvl][1] = $xpClip[$lvl][0] - $xpClip[$lvl-1][0]
        $xpClip[$lvl][2] = $xpClip[$lvl-1][2] + $xpClip[$lvl][0]
        GUICtrlCreateListViewItem( _
        $xpClip[$lvl][0] & "|"& _
        $xpClip[$lvl][1] & "|" & _
        $xpClip[$lvl][2] & "|" _
        , $activeList)

        ConsoleWrite("Move from: x: " & ($lvl-1)/$noLvls*(545/$noLvls)*10 & " y: " & 545 -(Ceiling($startingXP + (($lvl-1)*($curve))^2))/(Ceiling($startingXP + ($noLvls*($curve))^2))*545 & @CRLF)
        ConsoleWrite("To: x: " & ($lvl)/$noLvls*(545/$noLvls)*10 & " y: " & 545 -(Ceiling($startingXP + (($lvl)*($curve))^2))/(Ceiling($startingXP + ($noLvls*($curve))^2))*545 & @CRLF)

        #Region Graph
        If $activeList = $valueList1 Then
            GUICtrlSetGraphic($graphGraphic, $GUI_GR_COLOR, $COLOR_RED)
        Else
            GUICtrlSetGraphic($graphGraphic, $GUI_GR_COLOR, $COLOR_GREEN)
        EndIf
            GUICtrlSetGraphic($graphGraphic, $GUI_GR_MOVE, ($lvl-1)/$noLvls*(545/$noLvls)*10, 545 -(Ceiling($startingXP + (($lvl-1)*($curve))^2))/(Ceiling($startingXP + ($noLvls*($curve))^2))*545)
            GUICtrlSetGraphic($graphGraphic, $GUI_GR_LINE, ($lvl)/$noLvls*(545/$noLvls)*10, 545 -(Ceiling($startingXP + (($lvl)*($curve))^2))/(Ceiling($startingXP + ($noLvls*($curve))^2))*545)

        #EndRegion
    Next
    $graphGraphic = GUICtrlCreateGraphic(344, 8, 545, 545, $SS_BLACKFRAME)

    Sleep(1000)
    ToolTip("Destroy!")
    GUICtrlDelete($graphGraphic)
    If $activeList = $valueList1 Then
        $formula[0] = "(lvl*" & $curve & ")^2" + $startingXP
    Else
        $formula[1] = "(lvl*" & $curve & ")^2" + $startingXP
    EndIf
EndFunc

 

Link to comment
Share on other sites

Pretty cool concept. I've never used the GUICtrlCreateGraphic object but I've done some stuff with GDI+ and Bitmap objects. There isn't any, that I know of, to just delete a drawn object without clearing everything. So what I've done (I've done a lot of simple stuff with GDI+) is either store everything you draw in an array (a buffer) first and draw each item in the array. If you need to delete something you clear the graphic and then delete that item from the array, redrawing everything. Another option I've used (to draw a highlight around a GDI+ button) was to draw the new color over the old one. So in your case you'd want to re-draw the same line you want to delete but use the back color.

I don't see any way to clear the graphic object using a GUICtrl but $GUI_GR_RECT with the back color over the whole area should erase everything, then you can redraw your lines you want to keep.

Link to comment
Share on other sites

Pretty cool concept. I've never used the GUICtrlCreateGraphic object but I've done some stuff with GDI+ and Bitmap objects. There isn't any, that I know of, to just delete a drawn object without clearing everything. So what I've done (I've done a lot of simple stuff with GDI+) is either store everything you draw in an array (a buffer) first and draw each item in the array. If you need to delete something you clear the graphic and then delete that item from the array, redrawing everything. Another option I've used (to draw a highlight around a GDI+ button) was to draw the new color over the old one. So in your case you'd want to re-draw the same line you want to delete but use the back color.

I don't see any way to clear the graphic object using a GUICtrl but $GUI_GR_RECT with the back color over the whole area should erase everything, then you can redraw your lines you want to keep.

Thank you! I ended up using the $GUI_CR_RECT method and it worked like a charm. :) Does it delete the lines or just place a rectangle over it? Also, what happens with GUICtrlCreateGraphic? Can you store a line in an array with an handle? I know you said something like that but I don't quite understand sorry :P

Link to comment
Share on other sites

$GUI_CR_RECT will just draw a filled rectangle in the area you dictate. So it's going to just draw over everything that's in that area.

You can store a line in an array but it wouldn't be a handle, you would store the points and arc. So the two functions you call where you get the values at the beginning and then set your curve, you would want to store those in a buffer. Each time you clear your graphic you would re-draw everything in your buffer (Ex. if you had two Emric curves and a William curve drawn and you wanted to delete one of the Emrics. You would delete the values, or that position of the array, used to draw the curve from the buffer, clear your graphic, and then re-draw everything still in the array. How you want to create the buffer and fill it is up to you, whatever you find most convenient)

What do you mean by "what happens with GUICtrlCreateGraphic"?

Link to comment
Share on other sites

$GUI_CR_RECT will just draw a filled rectangle in the area you dictate. So it's going to just draw over everything that's in that area.

You can store a line in an array but it wouldn't be a handle, you would store the points and arc. So the two functions you call where you get the values at the beginning and then set your curve, you would want to store those in a buffer. Each time you clear your graphic you would re-draw everything in your buffer (Ex. if you had two Emric curves and a William curve drawn and you wanted to delete one of the Emrics. You would delete the values, or that position of the array, used to draw the curve from the buffer, clear your graphic, and then re-draw everything still in the array. How you want to create the buffer and fill it is up to you, whatever you find most convenient)

What do you mean by "what happens with GUICtrlCreateGraphic"?

That was exactly what I wondered. Thank you! :D

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...