Jump to content

Draw a line from mouse positions?


 Share

Recommended Posts

Hello, I'm trying to make a script that allows the user to draw a line like in paint, but every time I try to draw it an outline of a black square appears at the mouse's first position(the square is about 100x100 pixels). I'm using GUICtrlSetGraphic() and whatnot but I feel my code is nothing near what I need, so I won't include any. If someone could give an example of how to do this that would be great. Thanks in advance, Minikori.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

Check the GDI+ functions.

I've tried using that also and it didn't work, I'm also not very skilled with GDI+. That's why I asked for an example someone can show me.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

Well I'm not good with GDI+ either...I suck. My theory is you can get the mouse coord. of the click and as long as the mouse is held constantly compare the coord and use _GDIPlus_GraphicsDrawLine() to draw when it's let go.

Link to comment
Share on other sites

A proof-of-concept using GUICtrlSetGraphic(), of course, could be finished with GDI+ functions directly. :P

#include <GUIConstants.au3>

opt("MouseCoordMode", 2)

Dim $vPointA, $vPointB, $bPntA

$bPntA=0

GUICreate("Drawing lines - (proof-of-concept by Josbe)", 400, 300)
GUISetBkColor(0xffffff)
$Graphic1 = GUICtrlCreateGraphic(0, 0, 400, 300)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000ff, 0xffffff)
GUICtrlSetBkColor(-1, 0xffffff)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Graphic1
            If $bPntA = 0 Then
                $vPointA= MouseGetPos()
                GUICtrlSetGraphic($Graphic1, $GUI_GR_DOT, $vPointA[0], $vPointA[1])
                GUICtrlSetGraphic($Graphic1, $GUI_GR_MOVE, $vPointA[0], $vPointA[1])
                $bPntA = 1
            Else
                $vPointB= MouseGetPos()
                GUICtrlSetGraphic($Graphic1, $GUI_GR_LINE, $vPointB[0], $vPointB[1])
                GUICtrlSetGraphic($Graphic1, $GUI_GR_DOT, $vPointB[0], $vPointB[1])
                GUICtrlSetGraphic($Graphic1, $GUI_GR_MOVE, $vPointB[0], $vPointB[1])
                $bPntA = 0
            EndIf
            GUICtrlSetGraphic($Graphic1, $GUI_GR_REFRESH)
            
    EndSwitch
WEnd
Link to comment
Share on other sites

A proof-of-concept using GUICtrlSetGraphic(), of course, could be finished with GDI+ functions directly. :P

#include <GUIConstants.au3>

opt("MouseCoordMode", 2)

Dim $vPointA, $vPointB, $bPntA

$bPntA=0

GUICreate("Drawing lines - (proof-of-concept by Josbe)", 400, 300)
GUISetBkColor(0xffffff)
$Graphic1 = GUICtrlCreateGraphic(0, 0, 400, 300)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000ff, 0xffffff)
GUICtrlSetBkColor(-1, 0xffffff)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Graphic1
            If $bPntA = 0 Then
                $vPointA= MouseGetPos()
                GUICtrlSetGraphic($Graphic1, $GUI_GR_DOT, $vPointA[0], $vPointA[1])
                GUICtrlSetGraphic($Graphic1, $GUI_GR_MOVE, $vPointA[0], $vPointA[1])
                $bPntA = 1
            Else
                $vPointB= MouseGetPos()
                GUICtrlSetGraphic($Graphic1, $GUI_GR_LINE, $vPointB[0], $vPointB[1])
                GUICtrlSetGraphic($Graphic1, $GUI_GR_DOT, $vPointB[0], $vPointB[1])
                GUICtrlSetGraphic($Graphic1, $GUI_GR_MOVE, $vPointB[0], $vPointB[1])
                $bPntA = 0
            EndIf
            GUICtrlSetGraphic($Graphic1, $GUI_GR_REFRESH)
            
    EndSwitch
WEnd
I didn't even wanna use GDI+ so this will work for now. I was kind of hoping for a click and drag, not two clicks(It doesn't have to show the line as the mouse is being dragged).

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

I didn't even wanna use GDI+ so this will work for now. I was kind of hoping for a click and drag, not two clicks(It doesn't have to show the line as the mouse is being dragged).

This is Josbe example with click and drag to draw line.

#include <GUIConstants.au3>
#include <misc.au3>

Opt("MouseCoordMode", 2)
Global Const $WS_SIZEBOX = 0x00040000 ; From #include <WindowsConstants.au3>
Local $bFlag = 0, $Graphic1

GUICreate("Drawing lines - (proof-of-concept by Josbe)", 400, 300,-1,-1,$WS_SIZEBOX)
GUISetBkColor(0xffffff)
$Graphic1 = GUICtrlCreateGraphic(0, 0, 400, 300)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000ff, 0xffffff)
GUICtrlSetBkColor(-1, 0xffffff)
GUISetState()

Do
    If _IsPressed("01") Then
        Draw()
        Do          
            Sleep(10)
        Until Not _IsPressed("01")
        Draw()
    EndIf
Until GUIGetMsg() = -3


Func Draw()
    Local $vPointA, $vPointB
    If $bFlag = 0 Then
        $vPointA = MouseGetPos()
        GUICtrlSetGraphic($Graphic1, $GUI_GR_DOT, $vPointA[0], $vPointA[1])
        GUICtrlSetGraphic($Graphic1, $GUI_GR_MOVE, $vPointA[0], $vPointA[1])
        $bFlag = 1
    Else
        $vPointB = MouseGetPos()
        GUICtrlSetGraphic($Graphic1, $GUI_GR_LINE, $vPointB[0], $vPointB[1])
        GUICtrlSetGraphic($Graphic1, $GUI_GR_DOT, $vPointB[0], $vPointB[1])
        GUICtrlSetGraphic($Graphic1, $GUI_GR_MOVE, $vPointB[0], $vPointB[1])
        $bFlag = 0
    EndIf
    GUICtrlSetGraphic($Graphic1, $GUI_GR_REFRESH)
EndFunc   ;==>Draw
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...