Jump to content
Sozary

Navigate into a picture with drag

Recommended Posts

Sozary

Hi!

I want to nagigate on a picture: zoom, move the region of the picture that I can see..

For exemple, I want do a map like on this game (you can see the picture attached too).

 

My zoom works, but the deplacement is something that I never seen before, and I don't know how process...

My source code is:

#include <gdiplus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <misc.au3>
#include <WindowsConstants.au3>

Global $zoom=1,$xPrime=0,$YPrime=0
Global $Form1 = GUICreate("Pic editor", 622, 437, 460, 368)
GUISetState(@SW_SHOW)
Opt("MouseCoordMode",0)
 $aCoords = WinGetPos($Form1)
_MouseTrap($aCoords[0], $aCoords[1], $aCoords[0] + $aCoords[2], $aCoords[1] + $aCoords[3]);restrict the user

_GDIPlus_Startup()
Global $graph=_GDIPlus_GraphicsCreateFromHWND($Form1)
$hbitmap= _GDIPlus_BitmapCreateFromGraphics(622,437,$graph)
$hBackBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Global $img=_GDIPlus_BitmapCreateFromFile("image.png")
Global $Longueur=_GDIPlus_ImageGetWidth($img)
Global $Hauteur=_GDIPlus_ImageGetHeight($img)
$xPrime=$Longueur/2 ;I think that use coordonates for move picture with mouse is important
$YPrime=$Hauteur/2
_GDIPlus_GraphicsDrawImageRect($graph,$img,0,0,622,437)

do
    If _IsPressed("01") Then _Mouse(MouseGetPos()[0],MouseGetPos()[1])
    If _IsPressed("26") Then _Zoom(1)
    If _IsPressed("28") Then _Zoom(2)
Until GUIGetMsg()=-3

_GDIPlus_Shutdown()


Func _Mouse($x,$y)
    If $zoom<>0 Then
        $NewHauteur=Round((2^(ln($Hauteur)/ln(2)))/$zoom)
        $NewLongueur=Round((2^(ln($Longueur)/ln(2)))/$zoom)

            $AvancementY=Round(($NewHauteur/465))
            $AvancementX=Round(($NewLongueur/627))


            $xPrime=$x
            $YPrime=$y
            ;ConsoleWrite($xPrime&","&$YPrime&","&$x&","&$y&@CRLF)
            If $xPrime<=$NewLongueur And $YPrime<=$NewHauteur Then
            $bmp=_GDIPlus_BitmapCloneArea($img,$xPrime,$YPrime,$NewLongueur,$NewHauteur)
            _GDIPlus_GraphicsDrawImageRect($graph,$bmp,0,0,622,437)
            _GDIPlus_GraphicsDrawImageRect($hBackBuffer,$bmp,0,0,622,437)


        EndIf
    EndIf

EndFunc

Func _Zoom($CASE)
    If $CASE=1 Then $zoom+=1
    If $CASE=2 Then
        $zoom-=1
        If $zoom<0 Then $zoom=0
    EndIf

    If $zoom=0 Then
        $NewHauteur=$Hauteur
        $NewLongueur=$Longueur
    Else

        $NewHauteur=Round((2^(ln($Hauteur)/ln(2)))/$zoom)
        $NewLongueur=Round((2^(ln($Longueur)/ln(2)))/$zoom)
    EndIf

    If $zoom=0 Then
        _GDIPlus_GraphicsDrawImageRect($graph,$img,0,0,622,437)
        _GDIPlus_GraphicsDrawImageRect($hBackBuffer,$img,0,0,622,437)
    Else
        $bmp=_GDIPlus_BitmapCloneArea($img,$xPrime-($NewLongueur/2),$yPrime-($NewHauteur/2),$NewLongueur,$NewHauteur)
        _GDIPlus_GraphicsDrawImageRect($graph,$bmp,0,0,622,437)
        _GDIPlus_GraphicsDrawImageRect($hBackBuffer,$bmp,0,0,622,437)
    EndIf
    Sleep(200)
EndFunc

Func ln($x)
    Local $e=2.718281828
    Return Log($x)/Log($e)
EndFunc

Thank you in advance!

ex.png

Share this post


Link to post
Share on other sites
UEZ

I didn't understand what you want to do 100%. Is it something like this what I did in AutoIt Windows Screenshooter?

You can see a preview of the captured image on the right side. You can zoom in/out using the mouse wheel or the num block (+/-) and when zoomed in you can move the image by holding down lmb and moving the mouse in any direction.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Sozary

Yes, is totaly like this!

But in your program, there are 8538 lines of code, and with my programming level, it's just unaffordable for me (I have try).

In your program, when you manipulate the picture  and drag it by holding left mouse button, how did you have do this?

Thank you for your answer.

Share this post


Link to post
Share on other sites
UEZ

Well, for me it's the same problem to remember all the thinks I did. Let me try to make an example with the same functionality in the next days.

I will post an example when it's done.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
UEZ

I extracted the needed functions and variables from AWS:

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Screencapture.au3>
#include <WindowsConstants.au3>

Global $sx, $z = 10, $sy, $mc2, $f, $scroll_x, $scroll_y
Global Const $gdip_x = 0, $gdip_y = 0, $zmin = 5, $zmax = 15, $bg_c = "404040"
Global Const $gdip_w = 800, $gdip_h = 600
Global $bW = $gdip_w, $bH = $gdip_h
Global Const $hGUI = GUICreate("GDI+ Test", $gdip_w, $gdip_h)
GUISetState()

Global Const $dll = DllOpen("user32.dll")
_GDIPlus_Startup()
Global Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global Const $hBuffer_Bmp = _GDIPlus_BitmapCreateFromGraphics($gdip_w, $gdip_h, $hGraphic)
Global Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBuffer_Bmp)

Global $hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, $gdip_w / 2, $gdip_h / 2)

Global Const $hHBitmap = _ScreenCapture_Capture("", 0, 0, $gdip_w, $gdip_h)
Global Const $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)


Draw2Graphic($hBmp)
Zoom(2)

GUIRegisterMsg($WM_MOUSEWHEEL, "_Mousewheel")

Do
    $mc2 = MouseGetPos()
    While _IsPressed("01", $dll)
        $mc3 = MouseGetPos()
        If $mc2[0] <> $mc3[0] Or $mc2[1] <> $mc3[1] Then
            $scroll_x = ($sx + ($mc3[0] - $mc2[0]) / ($z ^ 2 / 16))
            $scroll_y = ($sy + ($mc3[1] - $mc2[1]) / ($z ^ 2 / 16))
            Draw2Graphic($hBmp)
            Zoom(2)
        EndIf
        Sleep(20)
    WEnd
    $sx = $scroll_x
    $sy = $scroll_y
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_MatrixDispose($hMatrix)
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_BitmapDispose($hBuffer_Bmp)
_GDIPlus_BitmapDispose($hBmp)
_GDIPlus_Shutdown()
GUIDelete()
DllClose($dll)
Exit

Func Draw2Graphic($hImage)
    Local $w, $h
    _GDIPlus_GraphicsClear($hContext, "0xFF" & $bg_c)
    If $bW <= $gdip_w And $bH <= $gdip_h Then
        $f = 1
        _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, $gdip_w / 2 - $bW / 2 - $scroll_x, $gdip_h / 2 - $bH / 2 - $scroll_y, $bW, $bH)
    Else
        If $bW >= $bH Then
            $f = $bW / $gdip_w
        Else
            $f = $bH / $gdip_h
        EndIf
        $w = Floor($bW / $f)
        $h = Floor($bH / $f)
        If $w > $gdip_w Then
            $f = $bW / $gdip_w
        ElseIf $h > $gdip_h Then
            $f = $bH / $gdip_h
        EndIf
        _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, $gdip_w / 2 - $w / 2 - $scroll_x, $gdip_h / 2 - $h / 2 - $scroll_y, $w, $h)
    EndIf
EndFunc   ;==>Draw2Graphic

Func Zoom($zoom_dir)
    Switch $zoom_dir
        Case -1
            _GDIPlus_MatrixDispose($hMatrix)
            $hMatrix = _GDIPlus_MatrixCreate()
            _GDIPlus_MatrixTranslate($hMatrix, $gdip_w / 2, $gdip_h / 2)
            _GDIPlus_MatrixScale($hMatrix, 1 / $f, 1 / $f)
            $scroll_x = 0
            $scroll_y = 0
        Case 0
            If $z > $zmin Then
                _GDIPlus_MatrixScale($hMatrix, 0.95, 0.95)
                $z -= 0.05
            EndIf
        Case 1
            If $z <= $zmax Then
                _GDIPlus_MatrixScale($hMatrix, 1.05, 1.05)
                $z += 0.05
            EndIf
        Case 2
            _GDIPlus_MatrixScale($hMatrix, 1, 1)
    EndSwitch
    _GDIPlus_GraphicsSetTransform($hContext, $hMatrix)
    _GDIPlus_GraphicsClear($hContext, "0xFF" & $bg_c)
    _GDIPlus_GraphicsDrawImage($hContext, $hBmp, -$bW / 2 + $scroll_x, -$bH / 2 + $scroll_y)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBuffer_Bmp, $gdip_x, $gdip_y, $gdip_w, $gdip_h)
EndFunc   ;==>Zoom

Func _Mousewheel($hWnd, $iMsg, $wParam, $lParam)
    Switch $wParam
        Case 0xFF880000 ;mouse wheel up
            Zoom(0)
            Return 1
        Case 0x00780000
            Zoom(1)
            Return 1
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_Mousewheel

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Sozary

Ok! There has some  functions that I did not know, but now I understand there!

Thank you!

Share this post


Link to post
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

×