Advertisement
pastamaker

moving image around the screen

May 29th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5.  
  6. #maxhotkeysperinterval 100000
  7. #Include,<hellbents_gdip>
  8. SetBatchLines, -1
  9. ;~ C:\Users\Admin\Desktop\drag.ahk
  10.  
  11.  
  12. win:=Layered_Window_SetUp(4,20,20,500,500,1,"+alwaysontop")
  13. gui,1:show,,me
  14.  
  15. pbrush:={black:New_Brush("000000"),green:New_Brush("00ff00")}
  16.  
  17. image = bitmap.png
  18. pbitmap:=Gdip_CreateBitmapFromFile(image)
  19. Gdip_GetImageDimensions(pBitmap,  Width,  Height)
  20. global image:={w:Width,h:height}
  21.  
  22.  
  23. global image_old_pos:={x:150,y:150}
  24. global image_pos:={x:150,y:150}
  25. Fill_Box(win.g,pBrush.black,0,0,win.w,win.h)   
  26. Gdip_DrawImage(win.g, pbitmap,image_pos.x,image_pos.y,image.w,image.w)
  27.  
  28.  
  29. UpdateLayeredWindow(win.hwnd, win.hdc, win.x, win.y, win.w, win.h)
  30.  
  31. loop {
  32.     key:=GetKeyState("lbutton")
  33.    
  34.     if(key and mouse_is_there()){
  35.         MouseGetPos,xwaspressed,ywaspressed
  36.         loop {
  37.             key:=GetKeyState("lbutton")
  38.             if(key ){
  39.                
  40.                 gosub draw_image
  41.             }
  42.             else {
  43.             image_old_pos.y:=image_pos.y
  44.             image_old_pos.x:=image_pos.x
  45.         break  
  46.         }
  47.        
  48.        
  49.         }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.    
  56.     }
  57.  
  58.     }
  59.    
  60.  
  61. return
  62.  
  63.  
  64. draw_image:
  65. MouseGetPos,x,y
  66. x:=x - xwaspressed + image_old_pos.x
  67. y:=y - ywaspressed + image_old_pos.y
  68. image_pos.x:=x
  69.     image_pos.y:=y
  70. Fill_Box(win.g,pBrush.black,0,0,win.w,win.h)   
  71. Gdip_DrawImage(win.g, pbitmap,x,y,image.w,image.w)
  72. UpdateLayeredWindow(win.hwnd, win.hdc)
  73. return
  74.  
  75.  
  76. mouse_is_there(){
  77.    
  78.     MouseGetPos,x,y
  79.     x1:=image_old_pos.x
  80.     y1:=image_old_pos.y
  81.    
  82.     x2:=x1+image.w
  83.     y2:=y1+image.h
  84.     if( x > x1 and x < x2 and y > y1 and y < y2 )
  85.         return true
  86.    
  87.     return false
  88.    
  89.  
  90. }
  91.  
  92. GuiClose:
  93. GuiEscape:
  94. *x::
  95.  
  96.  
  97. Layered_Window_ShutDown(win)
  98. ;~ gdip_deletebrush(pbrush)
  99. ExitApp
  100.  
  101.  
  102.  
  103.  
  104.  
  105. update:
  106. Gdip_GraphicsClear(win.g)
  107.  
  108. Gdip_FillEllipse(win.g, circle.brush, circle.x-win.x, circle.y-win.y,circle.d , circle.d)
  109. colour=000000
  110. Drawbox_2(win.g,colour,"ff",0,0,win.w,win.h,10)
  111. UpdateLayeredWindow(win.hwnd, win.hdc,win.x,win.y)
  112. return
  113.  
  114.  
  115. Drawbox_2(g,colour,Alpha,x0,y0,w0,h0,d0){
  116. pPen1:=New_Pen(colour,Alpha,d0)
  117. Gdip_DrawRectangle(g, pPen1, x0+d0/2, y0+d0/2, w0-d0, h0-d0)
  118.  
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement