Luigi Posted October 11, 2013 Share Posted October 11, 2013 (edited) Hi, I read some topics about move pic and adapt this script, to move a picture in a box. I see a little problem, when the pic is bigger than box, the mouse pointer is not stay in the same position... Take a picture near a 400x300px, load in script and move up, down, left and right, you see, the mouse point stay in the same point always the time. But, if the pic is bigger than this, you see the pointer not at the same position. The mouse point move more than picture... I can´t explain very clear in english this... Test the script. I thinking the script need a mathematic correction depending of size picture. When the biggest picture, the correction is biggest too. This is the first point. Another point is zoom. Some one have any idea how do build zoom? Or suggest to me a exemple? Best regards, Detefon expandcollapse popup#include <Array.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Global $hGui, $hMsg, $active = True Global $hGraphic, $hPen, $width = 400, $height = 300, $aMousePos[4][2], $active = 0, $aOldMouse[2] Global $hBitmap[4], $hBackbuffer[4], $hButtonLoad[4], $hButtonRemove[4], $hFile[4] Global $aPos[4][4] Global $iGuiWidth = 800, $iGuiHeight = 600 Global $aBoxPosition[4][2] = [[10, 10],[420, 10],[10, 410],[420, 410]] Global $aLimit[4][4] = [ _ [$aBoxPosition[0][0], $aBoxPosition[0][1], $aBoxPosition[0][0] + $width, $aBoxPosition[0][1] + $height], _ [$aBoxPosition[1][0], $aBoxPosition[1][1], $aBoxPosition[1][0] + $width, $aBoxPosition[1][1] + $height], _ [$aBoxPosition[2][0], $aBoxPosition[2][1], $aBoxPosition[2][0] + $width, $aBoxPosition[2][1] + $height], _ [$aBoxPosition[3][0], $aBoxPosition[3][1], $aBoxPosition[3][0] + $width, $aBoxPosition[3][1] + $height] _ ] $hGui = GUICreate('Título', $iGuiWidth, $iGuiHeight) $mousePos = GUICtrlCreateLabel('*', 200, 315, 160, 20) $mouseOld = GUICtrlCreateLabel('*', 200, 335, 160, 20) GUISetState(@SW_SHOWNORMAL) Opt('GUIOnEventMode', 1) ;0=disabled, 1=OnEvent mode enabled Opt('GUIEventOptions', 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt('MouseCoordMode', 2) GUISetOnEvent($GUI_EVENT_CLOSE, '_exit') ;~ GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ;~ $GUI_EVENT_PRIMARYDOWN ;~ $GUI_EVENT_PRIMARYUP _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui) $hBitmap[0] = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) $hBackbuffer[0] = _GDIPlus_ImageGetGraphicsContext($hBitmap[0]) $hButtonLoad[0] = GUICtrlCreateButton('load image', 10, 315, 80, 20) GUICtrlSetOnEvent($hButtonLoad[0], 'loadA') $hButtonRemove[0] = GUICtrlCreateButton('remove image', 90, 315, 80, 20) GUICtrlSetOnEvent($hButtonRemove[0], 'removeA') $hPen = _GDIPlus_PenCreate() _GDIPlus_GraphicsClear($hBackbuffer[0]) _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer[0], 2) While 1 $aMousePos = GUIGetCursorInfo() If $aMousePos[0] <> $aOldMouse[0] Or $aMousePos[1] <> $aOldMouse[1] Then GUICtrlSetData($mouseOld, '[' & $aMousePos[0] & ',' & $aMousePos[1] & ']' & @LF) Select Case $aMousePos[0] >= $aLimit[0][0] And $aMousePos[0] <= $aLimit[0][2] And $aMousePos[1] >= $aLimit[0][1] And $aMousePos[1] <= $aLimit[0][3] $active = 1 If $aMousePos[2] And $active And $hFile[0] Then $mosPos = GUIGetCursorInfo($hGui);GUIGetCursorInfo($hGui) $iSubtractX = $mosPos[0] + $aPos[0][2] $iSubtractY = $mosPos[1] + $aPos[0][3] Do $aMousePos = GUIGetCursorInfo($hGui) GUICtrlSetData($mousePos, '[' & $mosPos[0] & ',' & $mosPos[1] & '] {' & $aMousePos[0] - $iSubtractX & ',' & $aMousePos[1] - $iSubtractY & '}') $aPos[0][2] = $iSubtractX - $aMousePos[0] $aPos[0][3] = $iSubtractY - $aMousePos[1] _update() Until Not $aMousePos[2] EndIf Case Else $active = 0 EndSelect $aOldMouse[0] = $aMousePos[0] $aOldMouse[1] = $aMousePos[1] EndIf ;~ $hMsg = GUIGetMsg() ;~ Switch $hMsg ;~ Case $GUI_EVENT_CLOSE ;~ _exit() ;~ EndSwitch Sleep(20) If WinActive($hGui) Then _update() If Not $active Then $active = True ElseIf Not WinActive($hGui) And $active Then $active = False EndIf WEnd Func _update() _GDIPlus_GraphicsClear($hBackbuffer[0], 0xF0FFFFFF) If $hFile[0] Then _GDIPlus_GraphicsDrawImageRectRect($hBackbuffer[0], $hFile[0], $aPos[0][2], $aPos[0][3], $width, $height, 0, 0, $aPos[0][0], $aPos[0][1]) If $active == 1 Then _box($hBackbuffer[0], 0, 0, $width - 1, $height - 1) _GDIPlus_GraphicsDrawLine($hBackbuffer[0], 10, 150, 390, 150, $hPen) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap[0], $aBoxPosition[0][0], $aBoxPosition[0][1], $width, $height) EndFunc ;==>_update Func loadA() Local $sFile = FileOpenDialog('choose a picture', @ScriptDir, '(*.jpg;*.bmp;*.png)', 1) $hFile[0] = _GDIPlus_ImageLoadFromFile($sFile) $aPos[0][0] = _GDIPlus_ImageGetWidth($hFile[0]) $aPos[0][1] = _GDIPlus_ImageGetHeight($hFile[0]) $aPos[0][2] = 0 $aPos[0][3] = 0 ConsoleWrite('file[' & $sFile & '] dimensão[' & $aPos[0][0] & ',' & $aPos[0][1] & ',' & $aPos[0][2] & ',' & $aPos[0][3] & ']' & @LF) _update() EndFunc ;==>loadA Func removeA() $hFile[0] = 0 _GDIPlus_GraphicsClear($hBackbuffer[0], 0xF0FFFFFF) EndFunc ;==>removeA Func _box($hToGraphic, $xx, $yy, $ll, $aa) Local $aBox[5][2] $aBox[0][0] = 4 $aBox[1][0] = $xx $aBox[1][1] = $yy $aBox[2][0] = $xx + $ll $aBox[2][1] = $yy $aBox[3][0] = $xx + $ll $aBox[3][1] = $yy + $aa $aBox[4][0] = $xx $aBox[4][1] = $yy + $aa _GDIPlus_GraphicsDrawPolygon($hToGraphic, $aBox) EndFunc ;==>_box Func _exit() _GDIPlus_GraphicsDispose($hBackbuffer[0]) If $hFile[0] Then _GDIPlus_ImageDispose($hFile[0]) _GDIPlus_BitmapDispose($hBitmap[0]) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Exit EndFunc ;==>_exit Edited October 11, 2013 by detefon Visit my repository Link to comment Share on other sites More sharing options...
Luigi Posted October 11, 2013 Author Share Posted October 11, 2013 I am shamed... I solve the first mistery... No need mathematic correction, its my mistake Make this changes in _update function and work fine... Change: If $hFile[0] Then _GDIPlus_GraphicsDrawImageRectRect($hBackbuffer[0], $hFile[0], $aPos[0][2], $aPos[0][3], $width, $height, 0, 0, $aPos[0][0], $aPos[0][1]) To: If $hFile[0] Then _GDIPlus_GraphicsDrawImageRectRect($hBackbuffer[0], $hFile[0], $aPos[0][2], $aPos[0][3], $aPos[0][0], $aPos[0][1], 0, 0, $aPos[0][0], $aPos[0][1]) Visit my repository Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now