timmalos Posted February 28, 2022 Share Posted February 28, 2022 (edited) Hey. I'm currently trying to build a mini game (trivia). Can't tell you the full reasons I do this with AutoIt but let's say it has to be So I took few samples from GDI god @UEZ and I'm almost there. Goal is simple, I'll ask where is a country for example, and players have to click somewhere and "guess" the location, then I'll take the nearest proposals to get scores. (Kinda Geoguessr) Pls do not comment my way to check for simple clicks, it really only is a poc for now I tried few mins only. But to be really sure this is doable, I'm struggling on the way to put my icon exactly where the user pressed. (Because of zooms/etc coordonates are not that easy) So if someone can help me to understand the correct locations I should set for my "icon" when usr click on a location, thanks a lot ! I include the two images if you want to run it. expandcollapse popup#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 = 1280, $gdip_h = 720 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) _GDIPlus_GraphicsSetPixelOffsetMode($hContext, 2) ;~ _GDIPlus_GraphicsSetCompositingQuality($hContext, 2) _GDIPlus_GraphicsSetInterpolationMode($hContext, 7) 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) Global $hBmp = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\worldmap.jpg") _AddText2Img($hBmp, "Where is France ?",20,20,"Comic Sans MS",150,0xFF00FFFF) Draw2Graphic($hBmp) Zoom(2) GUIRegisterMsg($WM_MOUSEWHEEL, "_Mousewheel") Do $mc2 = MouseGetPos() $t=TimerInit() $pressed = false 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 / 32)) $scroll_y = ($sy + ($mc3[1] - $mc2[1]) / ($z ^ 2 / 32)) Draw2Graphic($hBmp) Zoom(2) EndIf Sleep(10) $pressed = True WEnd $sx = $scroll_x $sy = $scroll_y If $pressed And TimerDiff($t) <= 500 Then ; Someone clicked ConsoleWrite("Clicked ! " & @CRLF) _AddPing2Img($hBmp,$mc2[0]*5400/1920, $mc2[1]*2700/1080) ;<----- Here we need to get correct coordinates. (Trying 5400/1920 cause my image was 5400 large and my screen only 1920. But ofc not working :D Zoom(2) EndIf 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 _AddText2Img($hImage, $sText, $iX = 5, $iY = 70, $sFontName = "Comic Sans MS", $fSize = 22, $iColor = 0xF00F5000) Local Const $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 4) _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 3) Local Const $hBrush = _GDIPlus_BrushCreateSolid($iColor) Local Const $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) ;center text horizontally Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFontName) Local Const $hFont = _GDIPlus_FontCreate($hFamily, $fSize) Local Const $aDim = _GDIPlus_ImageGetDimension($hImage) Local Const $tLayout = _GDIPlus_RectFCreate($iX, $iY, $aDim[0], $aDim[1]) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) EndFunc Func _AddPing2Img($hImage, $iX = 5, $iY = 70) Local $hBmp2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\icon.jpg") Local Const $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBmp2, $iX, $iY,100,100) _GDIPlus_GraphicsDispose($hGraphic) EndFunc 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.85, 0.85) $z -= 0.15 EndIf Case 1 If $z <= $zmax Then _GDIPlus_MatrixScale($hMatrix, 1.15, 1.15) $z += 0.15 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($hContext, $hBmp, -$bW / 2 + $scroll_x, -$bH / 2 + $scroll_y, $gdip_w, $gdip_h) _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 0 Case 0x00780000 Zoom(1) Return 0 EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_Mousewheel Edited February 28, 2022 by timmalos Link to comment Share on other sites More sharing options...
UEZ Posted March 1, 2022 Share Posted March 1, 2022 (edited) You may have a look here: to have a starting point. You need the coordinates of each country in your map to check the distance. Edited March 1, 2022 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ 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