Vergrößer/Verkleinerbares GDI Raster Ähnlich AutoCAD

  • Servus...

    Ich habe eine Frage :cursing: ... Ist es möglich folgen Quelltext schneller zu machen :?:
    Wenn ich das Raster gräßer haben möchte geht das easy...klar werden ja auch weniger Linien...
    Wirds aber kleiner wird das viel zu langsam...
    Ich sag mal 0.2 von der $relation ist ok kleiner muss es nicht sein.
    Aber es sollen noch viel mehr GDI Elemente rein kommen.

    Aber zum besseres Verständnis erst mal der Code.. 8o

    Am Mausrad drehen...dann wirds größer und kleiner... :thumbup:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $Gui_Width = 1024
    Global $Gui_Height = 768
    Global $hGraphic,$hBrush_Grid_BG,$hPen_Grid_Lines,$hBitmap,$hBackbuffer
    Global $WheelMoving
    Global $relation = 1 ; Verhältnis von der Darstellung
    Global $hMouseHook, $WheelMoving
    $struct = "DWORD vkCode;" _
    &"DWORD scanCode;" _
    &"long flags;" _
    &"ULONG_PTR dwExtraInfo"
    $CallbackMouseProc = TogglePlugMouse()

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $hGui = GUICreate ( "AutoIttest",$Gui_Width,$Gui_Height)
    GUISetBkColor ( 0x666666 )
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ##

    [/autoit] [autoit][/autoit] [autoit]

    _AutoItTest_Startup($hGui)
    _AutoItTest_Create_Grid(1)
    OnAutoItExitRegister ('_exit')

    [/autoit] [autoit][/autoit] [autoit]

    ; Main WHILE ...
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    EndSwitch
    ;==========================================
    ; Mausrad bewegung prüfen...
    $WheelMsg = _GetWheelMove()
    ToolTip ( 'Faktor = '&$relation )
    Select
    Case $WheelMsg = "U" ;UP
    $relation = Round($relation*1.1,2)
    _AutoItTest_Create_Grid($relation)
    If $relation > 6.2 Then
    $relation = 6.2
    EndIf
    Case $WheelMsg = "D" ;UP
    $relation = Round($relation*0.9,2)
    If $relation < 0.6 Then
    $relation = 0.6
    EndIf
    _AutoItTest_Create_Grid($relation)
    EndSelect
    ;==========================================
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    _GDIPlus_BrushDispose($hBrush_Grid_BG)
    _GDIPlus_PenDispose ( $hPen_Grid_Lines )
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown ()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _AutoItTest_Startup($hWnd)
    If Not IsHWnd($hWnd) Then
    SetError(1)
    Return 0
    EndIf
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGui)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($Gui_Width , $Gui_Height, $hGraphic)
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    ;~ _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 0) ;Antialiasing

    [/autoit] [autoit][/autoit] [autoit]

    ;~ _GDIPlus_GraphicsClear($hBackbuffer) ;clear buffer
    $hBrush_Grid_BG = _GDIPlus_BrushCreateSolid(0xFF666666)
    $hPen_Grid_Lines = _GDIPlus_PenCreate(0xFF444444)
    Return 1
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _AutoItTest_Create_Grid($rowSize)
    $rowSize *= 20
    _GDIPlus_GraphicsClear($hBackbuffer, 0xFF666666) ;clear buffer
    For $x = $rowSize/2 To $Gui_Width Step Round($rowSize*$relation,0)
    For $y = $rowSize/2 To $Gui_Height Step Round($rowSize*$relation,0)
    _GDIPlus_GraphicsDrawLine($hBackbuffer, 0 , $y , $Gui_Width ,$y ,$hPen_Grid_Lines)
    _GDIPlus_GraphicsDrawLine($hBackbuffer, $x , 0 , $x ,$Gui_Height ,$hPen_Grid_Lines)
    Next
    Next
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $Gui_Width, $Gui_Height)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; ===============================================================================================================================
    ; Name...........: _isPressend Funktion fürs Mausrad
    ; Description ...: prüft ob das Mausrad gedreht/gedrückt wurde
    ; ===============================================================================================================================
    Func _GetWheelMove()
    Local $x = StringLeft($WheelMoving,1)
    $WheelMoving = StringTrimLeft($WheelMoving,1)
    Return $x
    EndFunc
    Func TogglePlugMouse($hCallProc=0)
    If IsArray($hMouseHook) Then
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hMouseHook[0])
    DllCallbackFree($hCallProc)
    Return 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Local Const $WH_MOUSE_LL = 14
    ;~ Local Const $WH_MOUSE = 7
    Local $hMouseProc = DllCallbackRegister("_MouseProc", "int", "int;ptr;ptr")
    Local $hMod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
    $hMouseHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", _
    "int", $WH_MOUSE_LL, _
    "ptr", DllCallbackGetPtr($hMouseProc), _
    "hwnd", $hMod[0], _
    "dword", 0)
    Return $hMouseProc
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _MouseProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then
    Local $iRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hMouseHook[0], _
    "int", $nCode, _
    "ptr", $wParam, _
    "ptr", $lParam)
    Return $iRet[0]
    EndIf
    $dllstruct = DllStructCreate($struct,$lParam)
    If $wParam = 0x20A Then
    If DllStructGetData($dllstruct,3) > 0 Then
    $WheelMoving &= "U"
    ElseIf DllStructGetData($dllstruct,3) < 0 Then
    $WheelMoving &= "D"
    EndIf
    EndIf
    Return 0
    EndFunc

    [/autoit]

    Danke schonmal für die Hilfe

    MFG chris :D

  • Hi

    verwende die GDIp.au3 und male den Raster mit einem Path:

    Spoiler anzeigen
    [autoit]

    #include <GDIP.au3>
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $iWidth = 800
    $iHeight = 600
    $nRaster = 10

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $hGui = GUICreate("Raster", $iWidth, $iHeight)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT")
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
    $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
    $hPen = _GDIPlus_PenCreate(0xFFFFFFFF)

    [/autoit] [autoit][/autoit] [autoit]

    $hPath = _GDIPlus_PathCreate($FillModeWinding)
    For $i = 0 To 300
    _GDIPlus_PathAddLine($hPath, $i, 0, $i, 300)
    _GDIPlus_PathCloseFigure($hPath)
    _GDIPlus_PathAddLine($hPath, 0, $i, 300, $i)
    _GDIPlus_PathCloseFigure($hPath)
    Next
    $aBounds = _GDIPlus_PathGetWorldBounds($hPath)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_MOUSEWHEEL, "_WM_MOUSEWHEEL")
    GUIRegisterMsg($WM_PAINT, "WM_PAINT")
    GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")

    [/autoit] [autoit][/autoit] [autoit]

    _ReDrawBuffer()
    _WinAPI_RedrawWindow($hGui, 0, 0, 5)
    While 1
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _ReDrawBuffer()
    _GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)
    Local $hPathClone = _GDIPlus_PathClone($hPath)
    Dim $aPoints[5][2] = [[4, 0],[0, 0],[$iWidth * $nRaster, 0],[0, $iHeight * $nRaster],[$iWidth * $nRaster, $iHeight * $nRaster]]
    _GDIPlus_PathWarp($hPathClone, 0, $aPoints, $aBounds[0], $aBounds[1], $aBounds[2], $aBounds[3])
    _GDIPlus_GraphicsDrawPath($hGfxBuffer, $hPathClone, $hPen)
    _GDIPlus_PathDispose($hPathClone)
    EndFunc ;==>_ReDrawBuffer

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_PAINT

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_ERASEBKGND($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return True
    EndFunc ;==>WM_ERASEBKGND

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _WM_MOUSEWHEEL($hWnd, $Msg, $wParam, $lParam)
    Local $bDown = 1
    If BitShift($wParam, 16) > 0 Then $bDown = 0
    Switch $bDown
    Case 1
    $nRaster += 0.1
    Case Else
    $nRaster -= 0.1
    EndSwitch
    If $nRaster > 100 Then $nRaster = 100
    If $nRaster < 1 Then $nRaster = 1
    _ReDrawBuffer()
    _WinAPI_RedrawWindow($hWnd, 0, 0, 5)
    Return $GUI_RUNDEFMSG
    EndFunc ;==>_WM_MOUSEWHEEL

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    mfgE

  • Ich sollte mir wirklich bald die Path Funktionen anschauen... Scheint ja richtig mächtig zu sein!

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯