Advertisement
CivReborn

GDIP Tank Game

Apr 15th, 2017
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;MAIN GAME STARTS AT LINE 170 "ish"
  2.  
  3.  
  4. #SingleInstance, Force
  5. #NoEnv
  6. ;                                Draw Images
  7. ;#############################################################################################
  8. ;#############################################################################################
  9. ;#############################################################################################
  10. ;#############################################################################################
  11. ;#############################################################################################
  12.  
  13.  
  14. If !pToken := Gdip_Startup()
  15. {
  16.     MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
  17.     ExitApp
  18. }
  19. pBitmap := Gdip_CreateBitmap(100, 80)
  20. G := Gdip_GraphicsFromImage(pBitmap)
  21. Gdip_SetSmoothingMode(G, 4)
  22.                                                 ;Tanks Body
  23. pBrush := Gdip_BrushCreateSolid(0xff7BD737)
  24. Gdip_FillRectangle(G, pBrush, 10,17 , 80, 46)
  25. Gdip_DeleteBrush(pBrush)
  26. pPen := Gdip_CreatePen(0xff000000, 4)
  27. Gdip_DrawRectangle(G, pPen, 10, 17, 80, 46)
  28. Gdip_DeleteBrush(pPen)
  29. pBrush := Gdip_BrushCreateSolid(0xff479B1B)
  30. Gdip_FillRectangle(G, pBrush, 17,25 , 20, 30)
  31. Gdip_DeleteBrush(pBrush)
  32. pPen := Gdip_CreatePen(0xff000000, 3)
  33. Gdip_DrawRectangle(G, pPen, 17,25 , 20, 30)
  34. Gdip_DeleteBrush(pPen)
  35. pPen := Gdip_CreatePen(0xff000000, 3)
  36. pBrush := Gdip_BrushCreateSolid(0xff7e7e7e)
  37. y:= 30
  38. Loop 3
  39.     {
  40.  
  41.         Gdip_FillRectangle(G, pBrush, 18,y , 18, 4)
  42.         Gdip_DrawRectangle(G, pPen, 18,y , 18, 4)
  43.         y+=8
  44.     }
  45. Gdip_DeleteBrush(pPen)
  46. Gdip_DeleteBrush(pBrush)
  47. pPen := Gdip_CreatePen(0xff7e7e7e, 3)
  48. Gdip_DrawEllipse(G, pPen, 45,20 , 39, 39)
  49. Gdip_DeleteBrush(pPen)
  50. ;                                                Treads
  51. pBrush := Gdip_BrushCreatesolid(0xffD8A700)
  52. Gdip_FillRectangle(G, pBrush, 0,0 , 100, 15)
  53. Gdip_FillRectangle(G, pBrush, 0,65 , 100, 15)
  54. Gdip_DeleteBrush(pBrush)
  55. pPen := Gdip_CreatePen(0xff000000, 2)
  56. Gdip_DrawRectangle(G, pPen, 1, 1, 100-2, 15)
  57. Gdip_DrawRectangle(G, pPen, 1, 65-1, 100-2, 15)
  58. Gdip_DeleteBrush(pPen)
  59. pPen := Gdip_CreatePen(0xff000000, 2)
  60. x:= 10
  61. Loop 8
  62.     {
  63.         Gdip_DrawRectangle(G, pPen, x, 1, 10, 15)
  64.         Gdip_DrawRectangle(G, pPen, x, 65, 10, 15)
  65.         x+=10
  66.     }
  67. Gdip_DeleteBrush(pPen)
  68. pBrush := Gdip_BrushCreatesolid(0xffFFDB00)
  69. Gdip_FillRectangle(G, pBrush, 11,2 , 8, 13)
  70. Gdip_FillRectangle(G, pBrush, 11,65 , 8, 13)
  71. Gdip_DeleteBrush(pBrush)
  72. Gdip_SaveBitmapToFile(pBitmap, "BR.png")
  73. pbitmap2:=Gdip_RotateBitmap(pBitmap, 180, Dispose=1)
  74. Gdip_SaveBitmapToFile(pBitmap2, "BL.png")
  75. pbitmap2:=Gdip_RotateBitmap(pBitmap, 90, Dispose=1)
  76. Gdip_SaveBitmapToFile(pBitmap2, "BD.png")
  77. pbitmap2:=Gdip_RotateBitmap(pBitmap,270, Dispose=1)
  78. Gdip_SaveBitmapToFile(pBitmap2, "BU.png")
  79. pbitmap2:=Gdip_RotateBitmap(pBitmap, 45, Dispose=1)
  80. Gdip_SaveBitmapToFile(pBitmap2, "BDR.png")
  81. pbitmap2:=Gdip_RotateBitmap(pBitmap, 135, Dispose=1)
  82. Gdip_SaveBitmapToFile(pBitmap2, "BDL.png")
  83. pbitmap2:=Gdip_RotateBitmap(pBitmap, 315, Dispose=1)
  84. Gdip_SaveBitmapToFile(pBitmap2, "BUR.png")
  85. pbitmap2:=Gdip_RotateBitmap(pBitmap, 225, Dispose=1)
  86. Gdip_SaveBitmapToFile(pBitmap2, "BUL.png")
  87. Gdip_DisposeImage(pBitmap)
  88. pBitmap := Gdip_CreateBitmap(100, 42)
  89. G := Gdip_GraphicsFromImage(pBitmap)
  90. Gdip_SetSmoothingMode(G, 4)
  91.                                         ;Cannon
  92. pBrush := Gdip_BrushCreateSolid(0xff7e7e7e)
  93. Gdip_FillRectangle(G, pBrush, 45,15 , 54, 10)
  94. Gdip_DeleteBrush(pBrush)
  95. pPen := Gdip_CreatePen(0xff000000, 3)
  96. Gdip_DrawRectangle(G, pPen, 45, 15, 54, 10)
  97. Gdip_DeleteBrush(pPen)
  98. pBrush := Gdip_BrushCreateSolid(0xff479B1B)
  99. Gdip_FillEllipse(G, pBrush, 1,1 , 40, 40)
  100. Gdip_DeleteBrush(pBrush)
  101. pPen := Gdip_CreatePen(0xff000000, 3)
  102. Gdip_DrawEllipse(G, pPen, 1,1 , 39, 39)
  103. Gdip_DeleteBrush(pPen)
  104. pBrush := Gdip_BrushCreateSolid(0xff479B1B)
  105. Gdip_FillRectangle(G, pBrush, 35 ,10 , 10, 20)
  106. Gdip_DeleteBrush(pBrush)
  107. pPen := Gdip_CreatePen(0xff000000, 2)
  108. Gdip_DrawRectangle(G, pPen, 35 ,10 , 10, 20)
  109. Gdip_DeleteBrush(pPen)
  110. Gdip_SaveBitmapToFile(pBitmap,"TR.png")
  111. pbitmap2:=Gdip_RotateBitmap(pBitmap, 180, Dispose=1)
  112. Gdip_SaveBitmapToFile(pBitmap2, "TL.png")
  113. pbitmap2:=Gdip_RotateBitmap(pBitmap, 90, Dispose=1)
  114. Gdip_SaveBitmapToFile(pBitmap2, "TD.png")
  115. pbitmap2:=Gdip_RotateBitmap(pBitmap,270, Dispose=1)
  116. Gdip_SaveBitmapToFile(pBitmap2, "TU.png")
  117. pbitmap2:=Gdip_RotateBitmap(pBitmap, 45, Dispose=1)
  118. Gdip_SaveBitmapToFile(pBitmap2, "TDR.png")
  119. pbitmap2:=Gdip_RotateBitmap(pBitmap, 135, Dispose=1)
  120. Gdip_SaveBitmapToFile(pBitmap2, "TDL.png")
  121. pbitmap2:=Gdip_RotateBitmap(pBitmap, 315, Dispose=1)
  122. Gdip_SaveBitmapToFile(pBitmap2, "TUR.png")
  123. pbitmap2:=Gdip_RotateBitmap(pBitmap, 225, Dispose=1)
  124. Gdip_SaveBitmapToFile(pBitmap2, "TUL.png")
  125. Gdip_DisposeImage(pBitmap)
  126. Gdip_DisposeImage(pBitmap2)
  127. pBitmap := Gdip_CreateBitmap(20, 10)
  128. G := Gdip_GraphicsFromImage(pBitmap)
  129. Gdip_SetSmoothingMode(G, 4)            ; Shell
  130. pBrush := Gdip_BrushCreateSolid(0xff00ffff)
  131. Gdip_FillEllipse(G, pBrush, -20, 2, 40, 6)
  132. Gdip_DeleteBrush(pBrush)
  133. pPen := Gdip_CreatePen(0xff000000, 2)
  134. Gdip_DrawEllipse(G, ppen, -20, 2, 40, 6)
  135. Gdip_DeleteBrush(ppen)
  136. Gdip_SaveBitmapToFile(pBitmap, "SR.png")
  137. pbitmap2:=Gdip_RotateBitmap(pBitmap, 180, Dispose=1)
  138. Gdip_SaveBitmapToFile(pBitmap2, "SL.png")
  139. pbitmap2:=Gdip_RotateBitmap(pBitmap, 90, Dispose=1)
  140. Gdip_SaveBitmapToFile(pBitmap2, "SD.png")
  141. pbitmap2:=Gdip_RotateBitmap(pBitmap,270, Dispose=1)
  142. Gdip_SaveBitmapToFile(pBitmap2, "SU.png")
  143. pbitmap2:=Gdip_RotateBitmap(pBitmap, 45, Dispose=1)
  144. Gdip_SaveBitmapToFile(pBitmap2, "SDR.png")
  145. pbitmap2:=Gdip_RotateBitmap(pBitmap, 135, Dispose=1)
  146. Gdip_SaveBitmapToFile(pBitmap2, "SDL.png")
  147. pbitmap2:=Gdip_RotateBitmap(pBitmap, 315, Dispose=1)
  148. Gdip_SaveBitmapToFile(pBitmap2, "SUR.png")
  149. pbitmap2:=Gdip_RotateBitmap(pBitmap, 225, Dispose=1)
  150. Gdip_SaveBitmapToFile(pBitmap2, "SUL.png")
  151. Gdip_DisposeImage(pBitmap)
  152. Gdip_DisposeImage(pBitmap2)
  153. Gdip_DeleteGraphics(G)
  154. Gdip_Shutdown(pToken)
  155. Gdip_RotateBitmap(pBitmap, Angle, Dispose=1) {
  156. Gdip_GetImageDimensions(pBitmap, Width, Height)
  157. Gdip_GetRotatedDimensions(Width, Height, Angle, RWidth, RHeight)
  158. Gdip_GetRotatedTranslation(Width, Height, Angle, xTranslation, yTranslation)
  159.  
  160. pBitmap2 := Gdip_CreateBitmap(RWidth, RHeight)
  161. G2 := Gdip_GraphicsFromImage(pBitmap2), Gdip_SetSmoothingMode(G2, 4), Gdip_SetInterpolationMode(G2, 7)
  162. Gdip_TranslateWorldTransform(G2, xTranslation, yTranslation)
  163. Gdip_RotateWorldTransform(G2, Angle)
  164. Gdip_DrawImage(G2, pBitmap, 0, 0, Width, Height)
  165.  
  166. Gdip_ResetWorldTransform(G2)
  167. Gdip_DeleteGraphics(G2)
  168. if Dispose
  169. Gdip_DisposeImage(pBitmap)
  170. return pBitmap2
  171. }
  172.  
  173. ;                               Main Game
  174. ;#############################################################################################
  175. ;#############################################################################################
  176. ;#############################################################################################
  177. ;#############################################################################################
  178. ;#############################################################################################
  179. CoordMode,Mouse,window
  180. global New_Body_Direction := 2
  181. global Old_Body_Direction := 2
  182. global New_Turret_Direction := 1
  183. global Old_Turret_Direction := 1
  184. global Body_Type1 := "BUR.png"
  185. global Body_Type2 := "BR.png"
  186. global Body_Type3 := "BDR.png"
  187. global Body_Type4 := "BD.png"
  188. global Body_Type5 := "BDL.png"
  189. global Body_Type6 := "BL.png"
  190. global Body_Type7 := "BUL.png"
  191. global Body_Type8 := "BU.png"      
  192. global Turret_Type1 := "TR.png"
  193. global Turret_Type2 := "TL.png"
  194. global Turret_Type3 := "TU.png"
  195. global Turret_Type4 := "TD.png"
  196. global Turret_Type5 := "TUR.png"
  197. global Turret_Type6 := "TUL.png"
  198. global Turret_Type7 := "TDL.png"
  199. global Turret_Type8 := "TDR.png"
  200. Body_X := 200
  201. Body_Y := 200
  202. Turret_W1 := 100 ;TR
  203.         Turret_H1 := 42
  204.         Turret_W2 := 101 ;TL
  205.         Turret_H2 := 43
  206.         Turret_W3 := 43 ;TU
  207.         Turret_H3 := 101
  208.         Turret_W4 := 43 ;TD
  209.         Turret_H4 := 101
  210.         Turret_W5 := 101 ;TUR
  211.         Turret_H5 := 101
  212.         Turret_W6 := 101 ;TUL
  213.         Turret_H6 := 101
  214.         Turret_W7 := 101 ;TDL
  215.         Turret_H7 := 101
  216.         Turret_W8 := 101 ;TDR
  217.         Turret_H8 := 101       
  218.         BW1 := 128 ;BUR
  219.         BH1 := 128     
  220.         BW2 := 100 ;BR
  221.         BH2 := 80      
  222.         BW3 := 128 ;BDR
  223.         BH3 := 128     
  224.         BW4 := 81 ;BD
  225.         BH4 := 101     
  226.         BW5 := 128 ;BDL
  227.         BH5 := 128     
  228.         BW6 := 101 ;BL
  229.         BH6 := 81      
  230.         BW7 := 128 ;BUL
  231.         BH7 := 128     
  232.         BW8 := 81 ;BU
  233.         BH8 := 101
  234.  
  235. Get_Turret_Loctaion()
  236. Gui, 1:+AlwaysOnTop
  237. Gui, 1:Color,0x373300
  238. Gui, 2:+AlwaysOnTop +Owner1 -Caption
  239. Gui, 2:Color,0x373300
  240. Gui, 3:+AlwaysOnTop +Owner1 -Caption
  241. Gui, 3:Color,0x373300
  242. Gui, 2:Add, Picture, x200 y200 w100 h80 vTank_Body,%Body_Type2%
  243. Gui, 3:Add, Picture, x245 y219 w100 h42 vTurret,%Turret_Type1%
  244. ;Gui, 3:Add, Picture,x350 y235 ,SU.png
  245. Gui,1:Show, w1300 h700,GDip Tank Game
  246. WinGetPos,x,y,,,GDip Tank Game
  247. x2:= x+3,y2:= y+25
  248. Gui,2:Show,x%x2% y%y2% w1300 h700
  249. Gui,3:Show,x%x2% y%y2% w1300 h700
  250. Gui,2:+LAstFound
  251. WinSet,TransColor,0x373300
  252. Gui,3:+LAstFound
  253. WinSet,TransColor,0x373300
  254. SetTimer, Move_Player,10
  255. return
  256. GuiClose:
  257.     ExitApp
  258. Move_Player:
  259.     Up_Arrow := GetKeyState("Up")
  260.     Down_Arrow := GetKeyState("Down")
  261.     Left_Arrow := GetKeyState("Left")
  262.     Right_Arrow := GetKeyState("Right")
  263.     Space_Bar := GetKeyState("Space")
  264.     WW := GetKeyState("W")
  265.     SS := GetKeyState("S")
  266.     AA := GetKeyState("A")
  267.     DD := GetKeyState("D")
  268.     if(WW==True&&DD==True)
  269.         {
  270.             New_Body_Direction := 1
  271.             if(New_Body_Direction!=Old_Body_Direction)
  272.                 {
  273.                     Old_Body_Direction := New_Body_Direction
  274.                     Get_Turret_Loctaion()
  275.                     BODY_W := BW%New_Body_Direction%
  276.                     BODY_H := BH%New_Body_Direction%
  277.                     GuiControl,2:Move,Tank_Body,w%BODY_W% h%BODY_H%
  278.                     GuiControl,2:,Tank_Body,% Body_Type%New_Body_Direction%
  279.                     GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  280.                     ;msgbox,% Turret_X "`n" Turret_Y
  281.                    
  282.                 }
  283.             Body_X++
  284.             Body_Y--
  285.             Turret_X ++
  286.             Turret_Y --
  287.             GuiControl,2:Move,Tank_Body,x%Body_X% y%Body_Y%
  288.             GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%   
  289.         }
  290.     else if(SS==True&&DD==True)
  291.         {
  292.             New_Body_Direction := 3
  293.             if(New_Body_Direction!=Old_Body_Direction)
  294.                 {
  295.                     Old_Body_Direction := New_Body_Direction
  296.                     Get_Turret_Loctaion()
  297.                     BODY_W := BW%New_Body_Direction%
  298.                     BODY_H := BH%New_Body_Direction%
  299.                     GuiControl,2:Move,Tank_Body,w%BODY_W% h%BODY_H%
  300.                     GuiControl,2:,Tank_Body,% Body_Type%New_Body_Direction%
  301.                     GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  302.                     ;msgbox,% Turret_X "`n" Turret_Y
  303.                    
  304.                 }
  305.             Body_X++
  306.             Body_Y++
  307.             Turret_X ++
  308.             Turret_Y ++
  309.             GuiControl,2:Move,Tank_Body,x%Body_X% y%Body_Y%
  310.             GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  311.         }
  312.     else if(AA==True&&SS==True)
  313.         {
  314.             New_Body_Direction := 5
  315.             if(New_Body_Direction!=Old_Body_Direction)
  316.                 {
  317.                     Old_Body_Direction := New_Body_Direction
  318.                     Get_Turret_Loctaion()
  319.                     BODY_W := BW%New_Body_Direction%
  320.                     BODY_H := BH%New_Body_Direction%
  321.                     GuiControl,2:Move,Tank_Body,w%BODY_W% h%BODY_H%
  322.                     GuiControl,2:,Tank_Body,% Body_Type%New_Body_Direction%
  323.                     GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  324.                     ;msgbox,% Turret_X "`n" Turret_Y
  325.                    
  326.                 }
  327.             Body_X--
  328.             Body_Y++
  329.             Turret_X --
  330.             Turret_Y ++
  331.             GuiControl,2:Move,Tank_Body,x%Body_X% y%Body_Y%
  332.             GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  333.         }
  334.     else if(WW==True&&AA==True)
  335.         {
  336.             New_Body_Direction := 7
  337.             if(New_Body_Direction!=Old_Body_Direction)
  338.                 {
  339.                     Old_Body_Direction := New_Body_Direction
  340.                     Get_Turret_Loctaion()
  341.                     BODY_W := BW%New_Body_Direction%
  342.                     BODY_H := BH%New_Body_Direction%
  343.                     GuiControl,2:Move,Tank_Body,w%BODY_W% h%BODY_H%
  344.                     GuiControl,2:,Tank_Body,% Body_Type%New_Body_Direction%
  345.                     GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  346.                     ;msgbox,% Turret_X "`n" Turret_Y
  347.                    
  348.                 }
  349.             Body_X--
  350.             Body_Y--
  351.             Turret_X --
  352.             Turret_Y --
  353.             GuiControl,2:Move,Tank_Body,x%Body_X% y%Body_Y%
  354.             GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  355.         }
  356.     else if(WW==True)
  357.         {
  358.             New_Body_Direction := 8
  359.             if(New_Body_Direction!=Old_Body_Direction)
  360.                 {
  361.                     Old_Body_Direction := New_Body_Direction
  362.                     Get_Turret_Loctaion()
  363.                     BODY_W := BW%New_Body_Direction%
  364.                     BODY_H := BH%New_Body_Direction%
  365.                     GuiControl,2:Move,Tank_Body,w%BODY_W% h%BODY_H%
  366.                     GuiControl,2:,Tank_Body,% Body_Type%New_Body_Direction%
  367.                     GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  368.                     ;msgbox,% Turret_X "`n" Turret_Y
  369.                    
  370.                 }
  371.             ;Body_X--
  372.             Body_Y--
  373.             ;Turret_X --
  374.             Turret_Y --
  375.             GuiControl,2:Move,Tank_Body,x%Body_X% y%Body_Y%
  376.             GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  377.         }
  378.     else if(DD==True)
  379.         {
  380.             New_Body_Direction := 2
  381.             if(New_Body_Direction!=Old_Body_Direction)
  382.                 {
  383.                     Old_Body_Direction := New_Body_Direction
  384.                     Get_Turret_Loctaion()
  385.                     BODY_W := BW%New_Body_Direction%
  386.                     BODY_H := BH%New_Body_Direction%
  387.                     GuiControl,2:Move,Tank_Body,w%BODY_W% h%BODY_H%
  388.                     GuiControl,2:,Tank_Body,% Body_Type%New_Body_Direction%
  389.                     GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  390.                     ;msgbox,% Turret_X "`n" Turret_Y
  391.                    
  392.                 }
  393.             Body_X++
  394.             ;Body_Y--
  395.             Turret_X ++
  396.             ;Turret_Y --
  397.             GuiControl,2:Move,Tank_Body,x%Body_X% y%Body_Y%
  398.             GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  399.         }
  400.     else if(SS==True)
  401.         {
  402.             New_Body_Direction := 4
  403.             if(New_Body_Direction!=Old_Body_Direction)
  404.                 {
  405.                     Old_Body_Direction := New_Body_Direction
  406.                     Get_Turret_Loctaion()
  407.                     BODY_W := BW%New_Body_Direction%
  408.                     BODY_H := BH%New_Body_Direction%
  409.                     GuiControl,2:Move,Tank_Body,w%BODY_W% h%BODY_H%
  410.                     GuiControl,2:,Tank_Body,% Body_Type%New_Body_Direction%
  411.                     GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  412.                     ;msgbox,% Turret_X "`n" Turret_Y
  413.                    
  414.                 }
  415.             ;Body_X++
  416.             Body_Y++
  417.             ;Turret_X ++
  418.             Turret_Y ++
  419.             GuiControl,2:Move,Tank_Body,x%Body_X% y%Body_Y%
  420.             GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  421.         }  
  422.     else if(AA==True)
  423.         {
  424.             New_Body_Direction := 6
  425.             if(New_Body_Direction!=Old_Body_Direction)
  426.                 {
  427.                     Old_Body_Direction := New_Body_Direction
  428.                     Get_Turret_Loctaion()
  429.                     BODY_W := BW%New_Body_Direction%
  430.                     BODY_H := BH%New_Body_Direction%
  431.                     GuiControl,2:Move,Tank_Body,w%BODY_W% h%BODY_H%
  432.                     GuiControl,2:,Tank_Body,% Body_Type%New_Body_Direction%
  433.                     GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  434.                     ;msgbox,% Turret_X "`n" Turret_Y
  435.                    
  436.                 }
  437.             Body_X--
  438.             ;Body_Y++
  439.             Turret_X --
  440.             ;Turret_Y ++
  441.             GuiControl,2:Move,Tank_Body,x%Body_X% y%Body_Y%
  442.             GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y%
  443.         }
  444.     MouseGetPos,x,y
  445.     if(Up_Arrow==True&&Left_Arrow==True)
  446.         {
  447.             New_Turret_Direction := 6
  448.         }
  449.     else if(Up_Arrow==True&&Right_Arrow==True)
  450.         {
  451.             New_Turret_Direction := 5
  452.         }
  453.     else if(Down_Arrow==True&&Right_Arrow==True)
  454.         {
  455.             New_Turret_Direction := 8
  456.         }
  457.     else if(Down_Arrow==True&&Left_Arrow==True)
  458.         {
  459.             New_Turret_Direction := 7
  460.         }
  461.     else if(Left_Arrow==True)
  462.         {
  463.             New_Turret_Direction := 2
  464.         }
  465.     else if(Up_Arrow==True)
  466.         {
  467.             New_Turret_Direction := 3
  468.         }  
  469.     else if(Right_Arrow==True)
  470.         {
  471.             New_Turret_Direction := 1
  472.         }  
  473.     else if(Down_Arrow==True)  
  474.         {
  475.             New_Turret_Direction := 4
  476.         }  
  477.     if(New_Turret_Direction!=Old_Turret_Direction)
  478.         {
  479.             Old_Turret_Direction := New_Turret_Direction
  480.             Get_Turret_Loctaion()
  481.             TW := Turret_W%New_Turret_Direction%
  482.             TH := Turret_H%New_Turret_Direction%
  483.             GuiControl,3:Move,Turret,x%Turret_X% y%Turret_Y% w%TW% h%TH%
  484.             GuiControl,3:,Turret,% Turret_Type%New_Turret_Direction%
  485.         }
  486.     return
  487. Get_Turret_Loctaion()
  488.     {
  489.         Global
  490.         if(New_Body_Direction>1)
  491.         Comp_POS := ((New_Body_Direction-1) * 8) + New_Turret_Direction
  492.         else
  493.         Comp_POS := New_Body_Direction * New_Turret_Direction  
  494.         COMP_X := []
  495.         COMP_Y := []
  496.         COMP_X := [53,-5,53,53,45,3,3,45,45,-14,45,44,34,-7,-7,34,53,-5,53,53,45,3,3,45,20,-39,20,19,11,-31,-31,11,33,-26,33,32,24,-18,-18,24,14,-44,15,15,5,-36,-36,5,33,-26,33,32,23,-18,-18,23,19,-39,19,19,10,-31,-31,10]
  497.         COMP_Y := [32,32,-26,32,-18,-18,23,23,19,19,-39,19,-30,-30,10,10,53,53,-5,53,3,3,43,44,44,44,-15,44,-6,-6,34,35,54,54,-5,54,3,3,44,44,19,19,-39,19,-30,-30,10,10,33,33,-26,33,-18,-18,23,24,15,15,-43,15,-35,-35,7,7]      
  498.         Turret_X := Body_X + COMP_X[Comp_POS]
  499.         Turret_Y := Body_Y + COMP_Y[Comp_POS]
  500.         /*
  501.                              x & y compensation for tank body and turret
  502.                              
  503.                           Body               Turret                X/Y +/-         ; difference is added or subtracted from turret
  504.                       ;------------       -------------     --------------------
  505.                     1.     BUR                 TR            X + 53  /  Y + 32
  506.                     2.     BUR                 TL            X - 5   /  Y + 32
  507.                     3.     BUR                 TU            X + 53  /  Y - 26
  508.                     4.     BUR                 TD            X + 53  /  Y + 32
  509.                     5.     BUR                 TUR           X + 45  /  Y - 18
  510.                     6.     BUR                 TUL           X + 3   /  Y - 18
  511.                     7.     BUR                 TDL           X + 3   /  Y + 23
  512.                     8.     BUR                 TDR           X + 45  /  Y + 23
  513.                     ;#############################################################  
  514.                     1.     BR                  TR            X + 45 /  Y + 19
  515.                     2.     BR                  TL            X - 14 /  Y + 19
  516.                     3.     BR                  TU            X + 45 /  Y - 39
  517.                     4.     BR                  TD            X + 44 /  Y + 19
  518.                     5.     BR                  TUR           X + 34 /  Y - 30
  519.                     6.     BR                  TUL           X - 7  /  Y - 30
  520.                     7.     BR                  TDL           X - 7  /  Y + 10
  521.                     8.     BR                  TDR           X + 34 /  Y + 10
  522.                     ;#############################################################
  523.                     1.     BDR                 TR            X + 53  /  Y + 53
  524.                     2.     BDR                 TL            X - 5   /  Y + 53
  525.                     3.     BDR                 TU            X + 53  /  Y - 5
  526.                     4.     BDR                 TD            X + 53  /  Y + 53
  527.                     5.     BDR                 TUR           X + 45  /  Y + 3
  528.                     6.     BDR                 TUL           X + 3   /  Y + 3
  529.                     7.     BDR                 TDL           X + 3   /  Y + 43
  530.                     8.     BDR                 TDR           X + 45  /  Y + 44
  531.                     ;#############################################################
  532.                     1.     BD                  TR            X + 20  /  Y + 44
  533.                     2.     BD                  TL            X - 39  /  Y + 44
  534.                     3.     BD                  TU            X + 20  /  Y - 15
  535.                     4.     BD                  TD            X + 19  /  Y + 44
  536.                     5.     BD                  TUR           X + 11  /  Y -6
  537.                     6.     BD                  TUL           X - 31  /  Y - 6
  538.                     7.     BD                  TDL           X - 31  /  Y + 34
  539.                     8.     BD                  TDR           X + 11  /  Y + 35
  540.                     ;#############################################################
  541.                     1.     BDL                 TR            X + 33  /  Y + 54
  542.                     2.     BDL                 TL            X - 26  /  Y + 54
  543.                     3.     BDL                 TU            X + 33  /  Y - 5
  544.                     4.     BDL                 TD            X + 32  /  Y + 54
  545.                     5.     BDL                 TUR           X + 24  /  Y + 3  
  546.                     6.     BDL                 TUL           X - 18  /  Y + 3
  547.                     7.     BDL                 TDL           X - 18  /  Y + 44
  548.                     8.     BDL                 TDR           X + 24  /  Y + 44
  549.                     ;#############################################################
  550.                    
  551.                     1.     BL                  TR            X + 14 /  Y + 19
  552.                     2.     BL                  TL            X - 44 /  Y + 19
  553.                     3.     BL                  TU            X + 15 /  Y - 39
  554.                     4.     BL                  TD            X + 15 /  Y + 19
  555.                     5.     BL                  TUR           X + 5  /  Y - 30
  556.                     6.     BL                  TUL           X - 36 /  Y - 30
  557.                     7.     BL                  TDL           X - 36 /  Y + 10
  558.                     8.     BL                  TDR           X + 5  /  Y + 10
  559.                     ;#############################################################
  560.                     1.     BUL                 TR            X + 33  /  Y + 33
  561.                     2.     BUL                 TL            X - 26  /  Y + 33
  562.                     3.     BUL                 TU            X + 33  /  Y - 26
  563.                     4.     BUL                 TD            X + 32  /  Y + 33
  564.                     5.     BUL                 TUR           X + 23  /  Y - 18
  565.                     6.     BUL                 TUL           X - 18  /  Y - 18
  566.                     7.     BUL                 TDL           X - 18  /  Y + 23
  567.                     8.     BUL                 TDR           X + 23  /  Y + 24
  568.                     ;#############################################################
  569.                     1.     BU                  TR            X + 19  /  Y + 15
  570.                     2.     BU                  TL            X - 39  /  Y + 15
  571.                     3.     BU                  TU            X + 19  /  Y - 43
  572.                     4.     BU                  TD            X + 19  /  Y + 15
  573.                     5.     BU                  TUR           X + 10  /  Y -35
  574.                     6.     BU                  TUL           X - 31  /  Y - 35
  575.                     7.     BU                  TDL           X - 31  /  Y + 7
  576.                     8.     BU                  TDR           X + 10  /  Y + 7
  577.                     ;#############################################################
  578. */    
  579.     }
  580.  
  581. ;                              Gdip.ahk Lib
  582. ;#############################################################################################
  583. ;#############################################################################################
  584. ;#############################################################################################
  585. ;#############################################################################################
  586. ;#############################################################################################
  587. UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  588. {
  589.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  590.    
  591.     if ((x != "") && (y != ""))
  592.         VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")
  593.  
  594.     if (w = "") ||(h = "")
  595.         WinGetPos,,, w, h, ahk_id %hwnd%
  596.    
  597.     return DllCall("UpdateLayeredWindow"
  598.                     , Ptr, hwnd
  599.                     , Ptr, 0
  600.                     , Ptr, ((x = "") && (y = "")) ? 0 : &pt
  601.                     , "int64*", w|h<<32
  602.                     , Ptr, hdc
  603.                     , "int64*", 0
  604.                     , "uint", 0
  605.                     , "UInt*", Alpha<<16|1<<24
  606.                     , "uint", 2)
  607. }
  608. BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  609. {
  610.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  611.    
  612.     return DllCall("gdi32\BitBlt"
  613.                     , Ptr, dDC
  614.                     , "int", dx
  615.                     , "int", dy
  616.                     , "int", dw
  617.                     , "int", dh
  618.                     , Ptr, sDC
  619.                     , "int", sx
  620.                     , "int", sy
  621.                     , "uint", Raster ? Raster : 0x00CC0020)
  622. }
  623. StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="")
  624. {
  625.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  626.    
  627.     return DllCall("gdi32\StretchBlt"
  628.                     , Ptr, ddc
  629.                     , "int", dx
  630.                     , "int", dy
  631.                     , "int", dw
  632.                     , "int", dh
  633.                     , Ptr, sdc
  634.                     , "int", sx
  635.                     , "int", sy
  636.                     , "int", sw
  637.                     , "int", sh
  638.                     , "uint", Raster ? Raster : 0x00CC0020)
  639. }
  640. SetStretchBltMode(hdc, iStretchMode=4)
  641. {
  642.     return DllCall("gdi32\SetStretchBltMode"
  643.                     , A_PtrSize ? "UPtr" : "UInt", hdc
  644.                     , "int", iStretchMode)
  645. }
  646. SetImage(hwnd, hBitmap)
  647. {
  648.     SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
  649.     E := ErrorLevel
  650.     DeleteObject(E)
  651.     return E
  652. }
  653. SetSysColorToControl(hwnd, SysColor=15)
  654. {
  655.    WinGetPos,,, w, h, ahk_id %hwnd%
  656.    bc := DllCall("GetSysColor", "Int", SysColor, "UInt")
  657.    pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
  658.    pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap)
  659.    Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
  660.    hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  661.    SetImage(hwnd, hBitmap)
  662.    Gdip_DeleteBrush(pBrushClear)
  663.    Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
  664.    return 0
  665. }
  666. Gdip_BitmapFromScreen(Screen=0, Raster="")
  667. {
  668.     if (Screen = 0)
  669.     {
  670.         Sysget, x, 76
  671.         Sysget, y, 77  
  672.         Sysget, w, 78
  673.         Sysget, h, 79
  674.     }
  675.     else if (SubStr(Screen, 1, 5) = "hwnd:")
  676.     {
  677.         Screen := SubStr(Screen, 6)
  678.         if !WinExist( "ahk_id " Screen)
  679.             return -2
  680.         WinGetPos,,, w, h, ahk_id %Screen%
  681.         x := y := 0
  682.         hhdc := GetDCEx(Screen, 3)
  683.     }
  684.     else if (Screen&1 != "")
  685.     {
  686.         Sysget, M, Monitor, %Screen%
  687.         x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
  688.     }
  689.     else
  690.     {
  691.         StringSplit, S, Screen, |
  692.         x := S1, y := S2, w := S3, h := S4
  693.     }
  694.  
  695.     if (x = "") || (y = "") || (w = "") || (h = "")
  696.         return -1
  697.  
  698.     chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
  699.     BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
  700.     ReleaseDC(hhdc)
  701.    
  702.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  703.     SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
  704.     return pBitmap
  705. }
  706. Gdip_BitmapFromHWND(hwnd)
  707. {
  708.     WinGetPos,,, Width, Height, ahk_id %hwnd%
  709.     hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  710.     PrintWindow(hwnd, hdc)
  711.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  712.     SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  713.     return pBitmap
  714. }
  715. CreateRectF(ByRef RectF, x, y, w, h)
  716. {
  717.    VarSetCapacity(RectF, 16)
  718.    NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
  719. }
  720. CreateRect(ByRef Rect, x, y, w, h)
  721. {
  722.     VarSetCapacity(Rect, 16)
  723.     NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint")
  724. }
  725. CreateSizeF(ByRef SizeF, w, h)
  726. {
  727.    VarSetCapacity(SizeF, 8)
  728.    NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")    
  729. }
  730. CreatePointF(ByRef PointF, x, y)
  731. {
  732.    VarSetCapacity(PointF, 8)
  733.    NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")    
  734. }
  735. CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
  736. {
  737.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  738.    
  739.     hdc2 := hdc ? hdc : GetDC()
  740.     VarSetCapacity(bi, 40, 0)
  741.    
  742.     NumPut(w, bi, 4, "uint")
  743.     , NumPut(h, bi, 8, "uint")
  744.     , NumPut(40, bi, 0, "uint")
  745.     , NumPut(1, bi, 12, "ushort")
  746.     , NumPut(0, bi, 16, "uInt")
  747.     , NumPut(bpp, bi, 14, "ushort")
  748.    
  749.     hbm := DllCall("CreateDIBSection"
  750.                     , Ptr, hdc2
  751.                     , Ptr, &bi
  752.                     , "uint", 0
  753.                     , A_PtrSize ? "UPtr*" : "uint*", ppvBits
  754.                     , Ptr, 0
  755.                     , "uint", 0, Ptr)
  756.  
  757.     if !hdc
  758.         ReleaseDC(hdc2)
  759.     return hbm
  760. }
  761. PrintWindow(hwnd, hdc, Flags=0)
  762. {
  763.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  764.    
  765.     return DllCall("PrintWindow", Ptr, hwnd, Ptr, hdc, "uint", Flags)
  766. }
  767. DestroyIcon(hIcon)
  768. {
  769.     return DllCall("DestroyIcon", A_PtrSize ? "UPtr" : "UInt", hIcon)
  770. }
  771. PaintDesktop(hdc)
  772. {
  773.     return DllCall("PaintDesktop", A_PtrSize ? "UPtr" : "UInt", hdc)
  774. }
  775. CreateCompatibleBitmap(hdc, w, h)
  776. {
  777.     return DllCall("gdi32\CreateCompatibleBitmap", A_PtrSize ? "UPtr" : "UInt", hdc, "int", w, "int", h)
  778. }
  779. CreateCompatibleDC(hdc=0)
  780. {
  781.    return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  782. }
  783. SelectObject(hdc, hgdiobj)
  784. {
  785.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  786.    
  787.     return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
  788. }
  789. DeleteObject(hObject)
  790. {
  791.    return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject)
  792. }
  793. GetDC(hwnd=0)
  794. {
  795.     return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
  796. }
  797. GetDCEx(hwnd, flags=0, hrgnClip=0)
  798. {
  799.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  800.    
  801.     return DllCall("GetDCEx", Ptr, hwnd, Ptr, hrgnClip, "int", flags)
  802. }
  803. ReleaseDC(hdc, hwnd=0)
  804. {
  805.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  806.    
  807.     return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
  808. }
  809. DeleteDC(hdc)
  810. {
  811.    return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  812. }
  813. Gdip_LibraryVersion()
  814. {
  815.     return 1.45
  816. }
  817. Gdip_LibrarySubVersion()
  818. {
  819.     return 1.47
  820. }
  821. Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
  822. {
  823.     Static FName = "ObjRelease"
  824.    
  825.     if !BRAFromMemIn
  826.         return -1
  827.     Loop, Parse, BRAFromMemIn, `n
  828.     {
  829.         if (A_Index = 1)
  830.         {
  831.             StringSplit, Header, A_LoopField, |
  832.             if (Header0 != 4 || Header2 != "BRA!")
  833.                 return -2
  834.         }
  835.         else if (A_Index = 2)
  836.         {
  837.             StringSplit, Info, A_LoopField, |
  838.             if (Info0 != 3)
  839.                 return -3
  840.         }
  841.         else
  842.             break
  843.     }
  844.     if !Alternate
  845.         StringReplace, File, File, \, \\, All
  846.     RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo)
  847.     if !FileInfo
  848.         return -4
  849.    
  850.     hData := DllCall("GlobalAlloc", "uint", 2, Ptr, FileInfo2, Ptr)
  851.     pData := DllCall("GlobalLock", Ptr, hData, Ptr)
  852.     DllCall("RtlMoveMemory", Ptr, pData, Ptr, &BRAFromMemIn+Info2+FileInfo1, Ptr, FileInfo2)
  853.     DllCall("GlobalUnlock", Ptr, hData)
  854.     DllCall("ole32\CreateStreamOnHGlobal", Ptr, hData, "int", 1, A_PtrSize ? "UPtr*" : "UInt*", pStream)
  855.     DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, A_PtrSize ? "UPtr*" : "UInt*", pBitmap)
  856.     If (A_PtrSize)
  857.         %FName%(pStream)
  858.     Else
  859.         DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)
  860.     return pBitmap
  861. }
  862. Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  863. {
  864.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  865.    
  866.     return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  867. }
  868. Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
  869. {
  870.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  871.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  872.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  873.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  874.     E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  875.     Gdip_ResetClip(pGraphics)
  876.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  877.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  878.     Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
  879.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
  880.     Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
  881.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  882.     Gdip_ResetClip(pGraphics)
  883.     return E
  884. }
  885. Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h)
  886. {
  887.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  888.    
  889.     return DllCall("gdiplus\GdipDrawEllipse", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  890. }
  891. Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
  892. {
  893.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  894.    
  895.     return DllCall("gdiplus\GdipDrawBezier"
  896.                     , Ptr, pgraphics
  897.                     , Ptr, pPen
  898.                     , "float", x1
  899.                     , "float", y1
  900.                     , "float", x2
  901.                     , "float", y2
  902.                     , "float", x3
  903.                     , "float", y3
  904.                     , "float", x4
  905.                     , "float", y4)
  906. }
  907. Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  908. {
  909.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  910.    
  911.     return DllCall("gdiplus\GdipDrawArc"
  912.                     , Ptr, pGraphics
  913.                     , Ptr, pPen
  914.                     , "float", x
  915.                     , "float", y
  916.                     , "float", w
  917.                     , "float", h
  918.                     , "float", StartAngle
  919.                     , "float", SweepAngle)
  920. }
  921. Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  922. {
  923.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  924.    
  925.     return DllCall("gdiplus\GdipDrawPie", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  926. }
  927. Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
  928. {
  929.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  930.    
  931.     return DllCall("gdiplus\GdipDrawLine"
  932.                     , Ptr, pGraphics
  933.                     , Ptr, pPen
  934.                     , "float", x1
  935.                     , "float", y1
  936.                     , "float", x2
  937.                     , "float", y2)
  938. }
  939. Gdip_DrawLines(pGraphics, pPen, Points)
  940. {
  941.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  942.     StringSplit, Points, Points, |
  943.     VarSetCapacity(PointF, 8*Points0)  
  944.     Loop, %Points0%
  945.     {
  946.         StringSplit, Coord, Points%A_Index%, `,
  947.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  948.     }
  949.     return DllCall("gdiplus\GdipDrawLines", Ptr, pGraphics, Ptr, pPen, Ptr, &PointF, "int", Points0)
  950. }
  951. Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  952. {
  953.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  954.    
  955.     return DllCall("gdiplus\GdipFillRectangle"
  956.                     , Ptr, pGraphics
  957.                     , Ptr, pBrush
  958.                     , "float", x
  959.                     , "float", y
  960.                     , "float", w
  961.                     , "float", h)
  962. }
  963. Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
  964. {
  965.     Region := Gdip_GetClipRegion(pGraphics)
  966.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  967.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  968.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  969.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  970.     E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  971.     Gdip_SetClipRegion(pGraphics, Region, 0)
  972.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  973.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  974.     Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
  975.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
  976.     Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
  977.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  978.     Gdip_SetClipRegion(pGraphics, Region, 0)
  979.     Gdip_DeleteRegion(Region)
  980.     return E
  981. }
  982. Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
  983. {
  984.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  985.    
  986.     StringSplit, Points, Points, |
  987.     VarSetCapacity(PointF, 8*Points0)  
  988.     Loop, %Points0%
  989.     {
  990.         StringSplit, Coord, Points%A_Index%, `,
  991.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  992.     }  
  993.     return DllCall("gdiplus\GdipFillPolygon", Ptr, pGraphics, Ptr, pBrush, Ptr, &PointF, "int", Points0, "int", FillMode)
  994. }
  995. Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
  996. {
  997.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  998.    
  999.     return DllCall("gdiplus\GdipFillPie"
  1000.                     , Ptr, pGraphics
  1001.                     , Ptr, pBrush
  1002.                     , "float", x
  1003.                     , "float", y
  1004.                     , "float", w
  1005.                     , "float", h
  1006.                     , "float", StartAngle
  1007.                     , "float", SweepAngle)
  1008. }
  1009. Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h)
  1010. {
  1011.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1012.    
  1013.     return DllCall("gdiplus\GdipFillEllipse", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
  1014. }
  1015. Gdip_FillRegion(pGraphics, pBrush, Region)
  1016. {
  1017.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1018.    
  1019.     return DllCall("gdiplus\GdipFillRegion", Ptr, pGraphics, Ptr, pBrush, Ptr, Region)
  1020. }
  1021. Gdip_FillPath(pGraphics, pBrush, Path)
  1022. {
  1023.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1024.    
  1025.     return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path)
  1026. }
  1027. Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
  1028. {
  1029.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1030.    
  1031.     StringSplit, Points, Points, |
  1032.     VarSetCapacity(PointF, 8*Points0)  
  1033.     Loop, %Points0%
  1034.     {
  1035.         StringSplit, Coord, Points%A_Index%, `,
  1036.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1037.     }
  1038.  
  1039.     if (Matrix&1 = "")
  1040.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1041.     else if (Matrix != 1)
  1042.         ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
  1043.        
  1044.     if (sx = "" && sy = "" && sw = "" && sh = "")
  1045.     {
  1046.         sx := 0, sy := 0
  1047.         sw := Gdip_GetImageWidth(pBitmap)
  1048.         sh := Gdip_GetImageHeight(pBitmap)
  1049.     }
  1050.  
  1051.     E := DllCall("gdiplus\GdipDrawImagePointsRect"
  1052.                 , Ptr, pGraphics
  1053.                 , Ptr, pBitmap
  1054.                 , Ptr, &PointF
  1055.                 , "int", Points0
  1056.                 , "float", sx
  1057.                 , "float", sy
  1058.                 , "float", sw
  1059.                 , "float", sh
  1060.                 , "int", 2
  1061.                 , Ptr, ImageAttr
  1062.                 , Ptr, 0
  1063.                 , Ptr, 0)
  1064.     if ImageAttr
  1065.         Gdip_DisposeImageAttributes(ImageAttr)
  1066.     return E
  1067. }
  1068. Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
  1069. {
  1070.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1071.    
  1072.     if (Matrix&1 = "")
  1073.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1074.     else if (Matrix != 1)
  1075.         ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
  1076.  
  1077.     if (sx = "" && sy = "" && sw = "" && sh = "")
  1078.     {
  1079.         if (dx = "" && dy = "" && dw = "" && dh = "")
  1080.         {
  1081.             sx := dx := 0, sy := dy := 0
  1082.             sw := dw := Gdip_GetImageWidth(pBitmap)
  1083.             sh := dh := Gdip_GetImageHeight(pBitmap)
  1084.         }
  1085.         else
  1086.         {
  1087.             sx := sy := 0
  1088.             sw := Gdip_GetImageWidth(pBitmap)
  1089.             sh := Gdip_GetImageHeight(pBitmap)
  1090.         }
  1091.     }
  1092.  
  1093.     E := DllCall("gdiplus\GdipDrawImageRectRect"
  1094.                 , Ptr, pGraphics
  1095.                 , Ptr, pBitmap
  1096.                 , "float", dx
  1097.                 , "float", dy
  1098.                 , "float", dw
  1099.                 , "float", dh
  1100.                 , "float", sx
  1101.                 , "float", sy
  1102.                 , "float", sw
  1103.                 , "float", sh
  1104.                 , "int", 2
  1105.                 , Ptr, ImageAttr
  1106.                 , Ptr, 0
  1107.                 , Ptr, 0)
  1108.     if ImageAttr
  1109.         Gdip_DisposeImageAttributes(ImageAttr)
  1110.     return E
  1111. }
  1112. Gdip_SetImageAttributesColorMatrix(Matrix)
  1113. {
  1114.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1115.    
  1116.     VarSetCapacity(ColourMatrix, 100, 0)
  1117.     Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
  1118.     StringSplit, Matrix, Matrix, |
  1119.     Loop, 25
  1120.     {
  1121.         Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
  1122.         NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
  1123.     }
  1124.     DllCall("gdiplus\GdipCreateImageAttributes", A_PtrSize ? "UPtr*" : "uint*", ImageAttr)
  1125.     DllCall("gdiplus\GdipSetImageAttributesColorMatrix", Ptr, ImageAttr, "int", 1, "int", 1, Ptr, &ColourMatrix, Ptr, 0, "int", 0)
  1126.     return ImageAttr
  1127. }
  1128. Gdip_GraphicsFromImage(pBitmap)
  1129. {
  1130.     DllCall("gdiplus\GdipGetImageGraphicsContext", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  1131.     return pGraphics
  1132. }
  1133. Gdip_GraphicsFromHDC(hdc)
  1134. {
  1135.     DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  1136.     return pGraphics
  1137. }
  1138. Gdip_GetDC(pGraphics)
  1139. {
  1140.     DllCall("gdiplus\GdipGetDC", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", hdc)
  1141.     return hdc
  1142. }
  1143. Gdip_ReleaseDC(pGraphics, hdc)
  1144. {
  1145.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1146.    
  1147.     return DllCall("gdiplus\GdipReleaseDC", Ptr, pGraphics, Ptr, hdc)
  1148. }
  1149. Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
  1150. {
  1151.     return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB)
  1152. }
  1153. Gdip_BlurBitmap(pBitmap, Blur)
  1154. {
  1155.     if (Blur > 100) || (Blur < 1)
  1156.         return -1  
  1157.    
  1158.     sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
  1159.     dWidth := sWidth//Blur, dHeight := sHeight//Blur
  1160.  
  1161.     pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
  1162.     G1 := Gdip_GraphicsFromImage(pBitmap1)
  1163.     Gdip_SetInterpolationMode(G1, 7)
  1164.     Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
  1165.  
  1166.     Gdip_DeleteGraphics(G1)
  1167.  
  1168.     pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
  1169.     G2 := Gdip_GraphicsFromImage(pBitmap2)
  1170.     Gdip_SetInterpolationMode(G2, 7)
  1171.     Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
  1172.  
  1173.     Gdip_DeleteGraphics(G2)
  1174.     Gdip_DisposeImage(pBitmap1)
  1175.     return pBitmap2
  1176. }
  1177. Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
  1178. {
  1179.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1180.    
  1181.     SplitPath, sOutput,,, Extension
  1182.     if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
  1183.         return -1
  1184.     Extension := "." Extension
  1185.  
  1186.     DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
  1187.     VarSetCapacity(ci, nSize)
  1188.     DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci)
  1189.     if !(nCount && nSize)
  1190.         return -2
  1191.    
  1192.     If (A_IsUnicode){
  1193.         StrGet_Name := "StrGet"
  1194.         Loop, %nCount%
  1195.         {
  1196.             sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16")
  1197.             if !InStr(sString, "*" Extension)
  1198.                 continue
  1199.            
  1200.             pCodec := &ci+idx
  1201.             break
  1202.         }
  1203.     } else {
  1204.         Loop, %nCount%
  1205.         {
  1206.             Location := NumGet(ci, 76*(A_Index-1)+44)
  1207.             nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int",  0, "uint", 0, "uint", 0)
  1208.             VarSetCapacity(sString, nSize)
  1209.             DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
  1210.             if !InStr(sString, "*" Extension)
  1211.                 continue
  1212.            
  1213.             pCodec := &ci+76*(A_Index-1)
  1214.             break
  1215.         }
  1216.     }
  1217.    
  1218.     if !pCodec
  1219.         return -3
  1220.  
  1221.     if (Quality != 75)
  1222.     {
  1223.         Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
  1224.         if Extension in .JPG,.JPEG,.JPE,.JFIF
  1225.         {
  1226.             DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize)
  1227.             VarSetCapacity(EncoderParameters, nSize, 0)
  1228.             DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters)
  1229.             Loop, % NumGet(EncoderParameters, "UInt")      ;%
  1230.             {
  1231.                 elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
  1232.                 if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6)
  1233.                 {
  1234.                     p := elem+&EncoderParameters-pad-4
  1235.                     NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt")
  1236.                     break
  1237.                 }
  1238.             }      
  1239.         }
  1240.     }
  1241.  
  1242.     if (!A_IsUnicode)
  1243.     {
  1244.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0)
  1245.         VarSetCapacity(wOutput, nSize*2)
  1246.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize)
  1247.         VarSetCapacity(wOutput, -1)
  1248.         if !VarSetCapacity(wOutput)
  1249.             return -4
  1250.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0)
  1251.     }
  1252.     else
  1253.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0)
  1254.     return E ? -5 : 0
  1255. }
  1256. Gdip_GetPixel(pBitmap, x, y)
  1257. {
  1258.     DllCall("gdiplus\GdipBitmapGetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "uint*", ARGB)
  1259.     return ARGB
  1260. }
  1261. Gdip_SetPixel(pBitmap, x, y, ARGB)
  1262. {
  1263.    return DllCall("gdiplus\GdipBitmapSetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "int", ARGB)
  1264. }
  1265. Gdip_GetImageWidth(pBitmap)
  1266. {
  1267.    DllCall("gdiplus\GdipGetImageWidth", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Width)
  1268.    return Width
  1269. }
  1270. Gdip_GetImageHeight(pBitmap)
  1271. {
  1272.    DllCall("gdiplus\GdipGetImageHeight", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Height)
  1273.    return Height
  1274. }
  1275. Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height)
  1276. {
  1277.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1278.     DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, "uint*", Width)
  1279.     DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, "uint*", Height)
  1280. }
  1281. Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height)
  1282. {
  1283.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  1284. }
  1285. Gdip_GetImagePixelFormat(pBitmap)
  1286. {
  1287.     DllCall("gdiplus\GdipGetImagePixelFormat", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", Format)
  1288.     return Format
  1289. }
  1290. Gdip_GetDpiX(pGraphics)
  1291. {
  1292.     DllCall("gdiplus\GdipGetDpiX", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpix)
  1293.     return Round(dpix)
  1294. }
  1295. Gdip_GetDpiY(pGraphics)
  1296. {
  1297.     DllCall("gdiplus\GdipGetDpiY", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpiy)
  1298.     return Round(dpiy)
  1299. }
  1300. Gdip_GetImageHorizontalResolution(pBitmap)
  1301. {
  1302.     DllCall("gdiplus\GdipGetImageHorizontalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpix)
  1303.     return Round(dpix)
  1304. }
  1305. Gdip_GetImageVerticalResolution(pBitmap)
  1306. {
  1307.     DllCall("gdiplus\GdipGetImageVerticalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpiy)
  1308.     return Round(dpiy)
  1309. }
  1310. Gdip_BitmapSetResolution(pBitmap, dpix, dpiy)
  1311. {
  1312.     return DllCall("gdiplus\GdipBitmapSetResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float", dpix, "float", dpiy)
  1313. }
  1314. Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
  1315. {
  1316.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1317.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  1318.    
  1319.     SplitPath, sFile,,, ext
  1320.     if ext in exe,dll
  1321.     {
  1322.         Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
  1323.         BufSize := 16 + (2*(A_PtrSize ? A_PtrSize : 4))
  1324.        
  1325.         VarSetCapacity(buf, BufSize, 0)
  1326.         Loop, Parse, Sizes, |
  1327.         {
  1328.             DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, PtrA, hIcon, PtrA, 0, "uint", 1, "uint", 0)
  1329.            
  1330.             if !hIcon
  1331.                 continue
  1332.  
  1333.             if !DllCall("GetIconInfo", Ptr, hIcon, Ptr, &buf)
  1334.             {
  1335.                 DestroyIcon(hIcon)
  1336.                 continue
  1337.             }
  1338.            
  1339.             hbmMask  := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4))
  1340.             hbmColor := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4) + (A_PtrSize ? A_PtrSize : 4))
  1341.             if !(hbmColor && DllCall("GetObject", Ptr, hbmColor, "int", BufSize, Ptr, &buf))
  1342.             {
  1343.                 DestroyIcon(hIcon)
  1344.                 continue
  1345.             }
  1346.             break
  1347.         }
  1348.         if !hIcon
  1349.             return -1
  1350.  
  1351.         Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int")
  1352.         hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  1353.         if !DllCall("DrawIconEx", Ptr, hdc, "int", 0, "int", 0, Ptr, hIcon, "uint", Width, "uint", Height, "uint", 0, Ptr, 0, "uint", 3)
  1354.         {
  1355.             DestroyIcon(hIcon)
  1356.             return -2
  1357.         }
  1358.        
  1359.         VarSetCapacity(dib, 104)
  1360.         DllCall("GetObject", Ptr, hbm, "int", A_PtrSize = 8 ? 104 : 84, Ptr, &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize
  1361.         Stride := NumGet(dib, 12, "Int"), Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0)) ; padding
  1362.         DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, Ptr, Bits, PtrA, pBitmapOld)
  1363.         pBitmap := Gdip_CreateBitmap(Width, Height)
  1364.         G := Gdip_GraphicsFromImage(pBitmap)
  1365.         , Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
  1366.         SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  1367.         Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld)
  1368.         DestroyIcon(hIcon)
  1369.     }
  1370.     else
  1371.     {
  1372.         if (!A_IsUnicode)
  1373.         {
  1374.             VarSetCapacity(wFile, 1024)
  1375.             DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sFile, "int", -1, Ptr, &wFile, "int", 512)
  1376.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &wFile, PtrA, pBitmap)
  1377.         }
  1378.         else
  1379.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &sFile, PtrA, pBitmap)
  1380.     }
  1381.    
  1382.     return pBitmap
  1383. }
  1384. Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
  1385. {
  1386.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1387.    
  1388.     DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  1389.     return pBitmap
  1390. }
  1391. Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
  1392. {
  1393.     DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hbm, "int", Background)
  1394.     return hbm
  1395. }
  1396. Gdip_CreateBitmapFromHICON(hIcon)
  1397. {
  1398.     DllCall("gdiplus\GdipCreateBitmapFromHICON", A_PtrSize ? "UPtr" : "UInt", hIcon, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  1399.     return pBitmap
  1400. }
  1401. Gdip_CreateHICONFromBitmap(pBitmap)
  1402. {
  1403.     DllCall("gdiplus\GdipCreateHICONFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hIcon)
  1404.     return hIcon
  1405. }
  1406. Gdip_CreateBitmap(Width, Height, Format=0x26200A)
  1407. {
  1408.     DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  1409.     Return pBitmap
  1410. }
  1411. Gdip_CreateBitmapFromClipboard()
  1412. {
  1413.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1414.    
  1415.     if !DllCall("OpenClipboard", Ptr, 0)
  1416.         return -1
  1417.     if !DllCall("IsClipboardFormatAvailable", "uint", 8)
  1418.         return -2
  1419.     if !hBitmap := DllCall("GetClipboardData", "uint", 2, Ptr)
  1420.         return -3
  1421.     if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
  1422.         return -4
  1423.     if !DllCall("CloseClipboard")
  1424.         return -5
  1425.     DeleteObject(hBitmap)
  1426.     return pBitmap
  1427. }
  1428. Gdip_SetBitmapToClipboard(pBitmap)
  1429. {
  1430.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1431.     off1 := A_PtrSize = 8 ? 52 : 44, off2 := A_PtrSize = 8 ? 32 : 24
  1432.     hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  1433.     DllCall("GetObject", Ptr, hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 104 : 84, 0), Ptr, &oi)
  1434.     hdib := DllCall("GlobalAlloc", "uint", 2, Ptr, 40+NumGet(oi, off1, "UInt"), Ptr)
  1435.     pdib := DllCall("GlobalLock", Ptr, hdib, Ptr)
  1436.     DllCall("RtlMoveMemory", Ptr, pdib, Ptr, &oi+off2, Ptr, 40)
  1437.     DllCall("RtlMoveMemory", Ptr, pdib+40, Ptr, NumGet(oi, off2 - (A_PtrSize ? A_PtrSize : 4), Ptr), Ptr, NumGet(oi, off1, "UInt"))
  1438.     DllCall("GlobalUnlock", Ptr, hdib)
  1439.     DllCall("DeleteObject", Ptr, hBitmap)
  1440.     DllCall("OpenClipboard", Ptr, 0)
  1441.     DllCall("EmptyClipboard")
  1442.     DllCall("SetClipboardData", "uint", 8, Ptr, hdib)
  1443.     DllCall("CloseClipboard")
  1444. }
  1445. Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
  1446. {
  1447.     DllCall("gdiplus\GdipCloneBitmapArea"
  1448.                     , "float", x
  1449.                     , "float", y
  1450.                     , "float", w
  1451.                     , "float", h
  1452.                     , "int", Format
  1453.                     , A_PtrSize ? "UPtr" : "UInt", pBitmap
  1454.                     , A_PtrSize ? "UPtr*" : "UInt*", pBitmapDest)
  1455.     return pBitmapDest
  1456. }
  1457. Gdip_CreatePen(ARGB, w)
  1458. {
  1459.    DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  1460.    return pPen
  1461. }
  1462. Gdip_CreatePenFromBrush(pBrush, w)
  1463. {
  1464.     DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  1465.     return pPen
  1466. }
  1467. Gdip_BrushCreateSolid(ARGB=0xff000000)
  1468. {
  1469.     DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  1470.     return pBrush
  1471. }
  1472. Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
  1473. {
  1474.     DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  1475.     return pBrush
  1476. }
  1477. Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
  1478. {
  1479.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1480.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  1481.    
  1482.     if !(w && h)
  1483.         DllCall("gdiplus\GdipCreateTexture", Ptr, pBitmap, "int", WrapMode, PtrA, pBrush)
  1484.     else
  1485.         DllCall("gdiplus\GdipCreateTexture2", Ptr, pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, PtrA, pBrush)
  1486.     return pBrush
  1487. }
  1488. Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
  1489. {
  1490.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1491.    
  1492.     CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2)
  1493.     DllCall("gdiplus\GdipCreateLineBrush", Ptr, &PointF1, Ptr, &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  1494.     return LGpBrush
  1495. }
  1496. Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
  1497. {
  1498.     CreateRectF(RectF, x, y, w, h)
  1499.     DllCall("gdiplus\GdipCreateLineBrushFromRect", A_PtrSize ? "UPtr" : "UInt", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  1500.     return LGpBrush
  1501. }
  1502. Gdip_CloneBrush(pBrush)
  1503. {
  1504.     DllCall("gdiplus\GdipCloneBrush", A_PtrSize ? "UPtr" : "UInt", pBrush, A_PtrSize ? "UPtr*" : "UInt*", pBrushClone)
  1505.     return pBrushClone
  1506. }
  1507. Gdip_DeletePen(pPen)
  1508. {
  1509.    return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen)
  1510. }
  1511. Gdip_DeleteBrush(pBrush)
  1512. {
  1513.    return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush)
  1514. }
  1515. Gdip_DisposeImage(pBitmap)
  1516. {
  1517.    return DllCall("gdiplus\GdipDisposeImage", A_PtrSize ? "UPtr" : "UInt", pBitmap)
  1518. }
  1519. Gdip_DeleteGraphics(pGraphics)
  1520. {
  1521.    return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  1522. }
  1523. Gdip_DisposeImageAttributes(ImageAttr)
  1524. {
  1525.     return DllCall("gdiplus\GdipDisposeImageAttributes", A_PtrSize ? "UPtr" : "UInt", ImageAttr)
  1526. }
  1527. Gdip_DeleteFont(hFont)
  1528. {
  1529.    return DllCall("gdiplus\GdipDeleteFont", A_PtrSize ? "UPtr" : "UInt", hFont)
  1530. }
  1531. Gdip_DeleteStringFormat(hFormat)
  1532. {
  1533.    return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat)
  1534. }
  1535. Gdip_DeleteFontFamily(hFamily)
  1536. {
  1537.    return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily)
  1538. }
  1539. Gdip_DeleteMatrix(Matrix)
  1540. {
  1541.    return DllCall("gdiplus\GdipDeleteMatrix", A_PtrSize ? "UPtr" : "UInt", Matrix)
  1542. }
  1543. Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
  1544. {
  1545.     IWidth := Width, IHeight:= Height
  1546.    
  1547.     RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
  1548.     RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
  1549.     RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
  1550.     RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
  1551.     RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour)
  1552.     RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
  1553.     RegExMatch(Options, "i)NoWrap", NoWrap)
  1554.     RegExMatch(Options, "i)R(\d)", Rendering)
  1555.     RegExMatch(Options, "i)S(\d+)(p*)", Size)
  1556.  
  1557.     if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
  1558.         PassBrush := 1, pBrush := Colour2
  1559.    
  1560.     if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
  1561.         return -1
  1562.  
  1563.     Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
  1564.     Loop, Parse, Styles, |
  1565.     {
  1566.         if RegExMatch(Options, "\b" A_loopField)
  1567.         Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
  1568.     }
  1569.  
  1570.     Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
  1571.     Loop, Parse, Alignments, |
  1572.     {
  1573.         if RegExMatch(Options, "\b" A_loopField)
  1574.             Align |= A_Index//2.1      ; 0|0|1|1|2|2
  1575.     }
  1576.  
  1577.     xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
  1578.     ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
  1579.     Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
  1580.     Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
  1581.     if !PassBrush
  1582.         Colour := "0x" (Colour2 ? Colour2 : "ff000000")
  1583.     Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
  1584.     Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
  1585.  
  1586.     hFamily := Gdip_FontFamilyCreate(Font)
  1587.     hFont := Gdip_FontCreate(hFamily, Size, Style)
  1588.     FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
  1589.     hFormat := Gdip_StringFormatCreate(FormatStyle)
  1590.     pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
  1591.     if !(hFamily && hFont && hFormat && pBrush && pGraphics)
  1592.         return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
  1593.    
  1594.     CreateRectF(RC, xpos, ypos, Width, Height)
  1595.     Gdip_SetStringFormatAlign(hFormat, Align)
  1596.     Gdip_SetTextRenderingHint(pGraphics, Rendering)
  1597.     ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  1598.  
  1599.     if vPos
  1600.     {
  1601.         StringSplit, ReturnRC, ReturnRC, |
  1602.        
  1603.         if (vPos = "vCentre") || (vPos = "vCenter")
  1604.             ypos += (Height-ReturnRC4)//2
  1605.         else if (vPos = "Top") || (vPos = "Up")
  1606.             ypos := 0
  1607.         else if (vPos = "Bottom") || (vPos = "Down")
  1608.             ypos := Height-ReturnRC4
  1609.        
  1610.         CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
  1611.         ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  1612.     }
  1613.  
  1614.     if !Measure
  1615.         E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
  1616.  
  1617.     if !PassBrush
  1618.         Gdip_DeleteBrush(pBrush)
  1619.     Gdip_DeleteStringFormat(hFormat)  
  1620.     Gdip_DeleteFont(hFont)
  1621.     Gdip_DeleteFontFamily(hFamily)
  1622.     return E ? E : ReturnRC
  1623. }
  1624. Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
  1625. {
  1626.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1627.    
  1628.     if (!A_IsUnicode)
  1629.     {
  1630.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0)
  1631.         VarSetCapacity(wString, nSize*2)
  1632.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  1633.     }
  1634.    
  1635.     return DllCall("gdiplus\GdipDrawString"
  1636.                     , Ptr, pGraphics
  1637.                     , Ptr, A_IsUnicode ? &sString : &wString
  1638.                     , "int", -1
  1639.                     , Ptr, hFont
  1640.                     , Ptr, &RectF
  1641.                     , Ptr, hFormat
  1642.                     , Ptr, pBrush)
  1643. }
  1644. Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
  1645. {
  1646.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1647.    
  1648.     VarSetCapacity(RC, 16)
  1649.     if !A_IsUnicode
  1650.     {
  1651.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, "uint", 0, "int", 0)
  1652.         VarSetCapacity(wString, nSize*2)  
  1653.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  1654.     }
  1655.    
  1656.     DllCall("gdiplus\GdipMeasureString"
  1657.                     , Ptr, pGraphics
  1658.                     , Ptr, A_IsUnicode ? &sString : &wString
  1659.                     , "int", -1
  1660.                     , Ptr, hFont
  1661.                     , Ptr, &RectF
  1662.                     , Ptr, hFormat
  1663.                     , Ptr, &RC
  1664.                     , "uint*", Chars
  1665.                     , "uint*", Lines)
  1666.    
  1667.     return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
  1668. }
  1669. Gdip_SetStringFormatAlign(hFormat, Align)
  1670. {
  1671.    return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align)
  1672. }
  1673. Gdip_StringFormatCreate(Format=0, Lang=0)
  1674. {
  1675.    DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat)
  1676.    return hFormat
  1677. }
  1678. Gdip_FontCreate(hFamily, Size, Style=0)
  1679. {
  1680.    DllCall("gdiplus\GdipCreateFont", A_PtrSize ? "UPtr" : "UInt", hFamily, "float", Size, "int", Style, "int", 0, A_PtrSize ? "UPtr*" : "UInt*", hFont)
  1681.    return hFont
  1682. }
  1683.  
  1684. Gdip_FontFamilyCreate(Font)
  1685. {
  1686.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1687.    
  1688.     if (!A_IsUnicode)
  1689.     {
  1690.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0)
  1691.         VarSetCapacity(wFont, nSize*2)
  1692.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize)
  1693.     }
  1694.    
  1695.     DllCall("gdiplus\GdipCreateFontFamilyFromName"
  1696.                     , Ptr, A_IsUnicode ? &Font : &wFont
  1697.                     , "uint", 0
  1698.                     , A_PtrSize ? "UPtr*" : "UInt*", hFamily)
  1699.    
  1700.     return hFamily
  1701. }
  1702. Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
  1703. {
  1704.    DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  1705.    return Matrix
  1706. }
  1707.  
  1708. Gdip_CreateMatrix()
  1709. {
  1710.    DllCall("gdiplus\GdipCreateMatrix", A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  1711.    return Matrix
  1712. }
  1713. Gdip_CreatePath(BrushMode=0)
  1714. {
  1715.     DllCall("gdiplus\GdipCreatePath", "int", BrushMode, A_PtrSize ? "UPtr*" : "UInt*", Path)
  1716.     return Path
  1717. }
  1718.  
  1719. Gdip_AddPathEllipse(Path, x, y, w, h)
  1720. {
  1721.     return DllCall("gdiplus\GdipAddPathEllipse", A_PtrSize ? "UPtr" : "UInt", Path, "float", x, "float", y, "float", w, "float", h)
  1722. }
  1723.  
  1724. Gdip_AddPathPolygon(Path, Points)
  1725. {
  1726.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1727.    
  1728.     StringSplit, Points, Points, |
  1729.     VarSetCapacity(PointF, 8*Points0)  
  1730.     Loop, %Points0%
  1731.     {
  1732.         StringSplit, Coord, Points%A_Index%, `,
  1733.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1734.     }  
  1735.  
  1736.     return DllCall("gdiplus\GdipAddPathPolygon", Ptr, Path, Ptr, &PointF, "int", Points0)
  1737. }
  1738.  
  1739. Gdip_DeletePath(Path)
  1740. {
  1741.     return DllCall("gdiplus\GdipDeletePath", A_PtrSize ? "UPtr" : "UInt", Path)
  1742. }
  1743. Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
  1744. {
  1745.     return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint)
  1746. }
  1747. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  1748. {
  1749.    return DllCall("gdiplus\GdipSetInterpolationMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", InterpolationMode)
  1750. }
  1751. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  1752. {
  1753.    return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode)
  1754. }
  1755. Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
  1756. {
  1757.    return DllCall("gdiplus\GdipSetCompositingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", CompositingMode)
  1758. }
  1759. Gdip_Startup()
  1760. {
  1761.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1762.    
  1763.     if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  1764.         DllCall("LoadLibrary", "str", "gdiplus")
  1765.     VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
  1766.     DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
  1767.     return pToken
  1768. }
  1769.  
  1770. Gdip_Shutdown(pToken)
  1771. {
  1772.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1773.    
  1774.     DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
  1775.     if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  1776.         DllCall("FreeLibrary", Ptr, hModule)
  1777.     return 0
  1778. }
  1779. Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
  1780. {
  1781.     return DllCall("gdiplus\GdipRotateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", Angle, "int", MatrixOrder)
  1782. }
  1783.  
  1784. Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
  1785. {
  1786.     return DllCall("gdiplus\GdipScaleWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  1787. }
  1788.  
  1789. Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
  1790. {
  1791.     return DllCall("gdiplus\GdipTranslateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  1792. }
  1793.  
  1794. Gdip_ResetWorldTransform(pGraphics)
  1795. {
  1796.     return DllCall("gdiplus\GdipResetWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  1797. }
  1798.  
  1799. Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
  1800. {
  1801.     pi := 3.14159, TAngle := Angle*(pi/180)
  1802.  
  1803.     Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
  1804.     if ((Bound >= 0) && (Bound <= 90))
  1805.         xTranslation := Height*Sin(TAngle), yTranslation := 0
  1806.     else if ((Bound > 90) && (Bound <= 180))
  1807.         xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
  1808.     else if ((Bound > 180) && (Bound <= 270))
  1809.         xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
  1810.     else if ((Bound > 270) && (Bound <= 360))
  1811.         xTranslation := 0, yTranslation := -Width*Sin(TAngle)
  1812. }
  1813.  
  1814. Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
  1815. {
  1816.     pi := 3.14159, TAngle := Angle*(pi/180)
  1817.     if !(Width && Height)
  1818.         return -1
  1819.     RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
  1820.     RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
  1821. }
  1822. Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1)
  1823. {
  1824.     return DllCall("gdiplus\GdipImageRotateFlip", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", RotateFlipType)
  1825. }
  1826. Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
  1827. {
  1828.    return DllCall("gdiplus\GdipSetClipRect",  A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
  1829. }
  1830.  
  1831. Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
  1832. {
  1833.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1834.     return DllCall("gdiplus\GdipSetClipPath", Ptr, pGraphics, Ptr, Path, "int", CombineMode)
  1835. }
  1836.  
  1837. Gdip_ResetClip(pGraphics)
  1838. {
  1839.    return DllCall("gdiplus\GdipResetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  1840. }
  1841.  
  1842. Gdip_GetClipRegion(pGraphics)
  1843. {
  1844.     Region := Gdip_CreateRegion()
  1845.     DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt*", Region)
  1846.     return Region
  1847. }
  1848.  
  1849. Gdip_SetClipRegion(pGraphics, Region, CombineMode=0)
  1850. {
  1851.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1852.    
  1853.     return DllCall("gdiplus\GdipSetClipRegion", Ptr, pGraphics, Ptr, Region, "int", CombineMode)
  1854. }
  1855.  
  1856. Gdip_CreateRegion()
  1857. {
  1858.     DllCall("gdiplus\GdipCreateRegion", "UInt*", Region)
  1859.     return Region
  1860. }
  1861.  
  1862. Gdip_DeleteRegion(Region)
  1863. {
  1864.     return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region)
  1865. }
  1866. Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a)
  1867. {
  1868.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1869.    
  1870.     CreateRect(Rect, x, y, w, h)
  1871.     VarSetCapacity(BitmapData, 16+2*(A_PtrSize ? A_PtrSize : 4), 0)
  1872.     E := DllCall("Gdiplus\GdipBitmapLockBits", Ptr, pBitmap, Ptr, &Rect, "uint", LockMode, "int", PixelFormat, Ptr, &BitmapData)
  1873.     Stride := NumGet(BitmapData, 8, "Int")
  1874.     Scan0 := NumGet(BitmapData, 16, Ptr)
  1875.     return E
  1876. }
  1877. Gdip_UnlockBits(pBitmap, ByRef BitmapData)
  1878. {
  1879.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1880.    
  1881.     return DllCall("Gdiplus\GdipBitmapUnlockBits", Ptr, pBitmap, Ptr, &BitmapData)
  1882. }
  1883. Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride)
  1884. {
  1885.     Numput(ARGB, Scan0+0, (x*4)+(y*Stride), "UInt")
  1886. }
  1887. Gdip_GetLockBitPixel(Scan0, x, y, Stride)
  1888. {
  1889.     return NumGet(Scan0+0, (x*4)+(y*Stride), "UInt")
  1890. }
  1891. Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize)
  1892. {
  1893.     static PixelateBitmap
  1894.    
  1895.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1896.    
  1897.     if (!PixelateBitmap)
  1898.     {
  1899.         if A_PtrSize != 8 ; x86 machine code
  1900.         MCode_PixelateBitmap =
  1901.         (LTrim Join
  1902.         558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC894DD885C90F8E830200008B451099F7FB8365DC008365E000894DC88955F08945E833FF897DD4
  1903.         397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945FC89451C8945143BD87E608B45088D50028BC82BCA8BF02BF2418945F48B45E02955F4894DC4
  1904.         8D0CB80FAFCB03CA895DD08BD1895DE40FB64416030145140FB60201451C8B45C40FB604100145FC8B45F40FB604020145F883C204FF4DE475D6034D18FF
  1905.         4DD075C98B4DCC8B451499F7F98945148B451C99F7F989451C8B45FC99F7F98945FC8B45F899F7F98945F885DB7E648B450C8D50028BC82BCA83C103894D
  1906.         C48BC82BCA41894DF48B4DD48945E48B45E02955E48D0C880FAFCB03CA895DD08BD18BF38A45148B7DC48804178A451C8B7DF488028A45FC8804178A45F8
  1907.         8B7DE488043A83C2044E75DA034D18FF4DD075CE8B4DCC8B7DD447897DD43B7DE80F8CF2FEFFFF837DF0000F842C01000033C08945F88945FC89451C8945
  1908.         148945E43BD87E65837DF0007E578B4DDC034DE48B75E80FAF4D180FAFF38B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945CC0F
  1909.         B6440E030145140FB60101451C0FB6440F010145FC8B45F40FB604010145F883C104FF4DCC75D8FF45E4395DE47C9B8B4DF00FAFCB85C9740B8B451499F7
  1910.         F9894514EB048365140033F63BCE740B8B451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB
  1911.         038975F88975E43BDE7E5A837DF0007E4C8B4DDC034DE48B75E80FAF4D180FAFF38B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955CC8A55
  1912.         1488540E038A551C88118A55FC88540F018A55F888140183C104FF4DCC75DFFF45E4395DE47CA68B45180145E0015DDCFF4DC80F8594FDFFFF8B451099F7
  1913.         FB8955F08945E885C00F8E450100008B45EC0FAFC38365DC008945D48B45E88945CC33C08945F88945FC89451C8945148945103945EC7E6085DB7E518B4D
  1914.         D88B45080FAFCB034D108D50020FAF4D18034DDC8BF08BF88945F403CA2BF22BFA2955F4895DC80FB6440E030145140FB60101451C0FB6440F010145FC8B
  1915.         45F40FB604080145F883C104FF4DC875D8FF45108B45103B45EC7CA08B4DD485C9740B8B451499F7F9894514EB048365140033F63BCE740B8B451C99F7F9
  1916.         89451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975103975EC7E5585DB7E468B4DD88B450C
  1917.         0FAFCB034D108D50020FAF4D18034DDC8BF08BF803CA2BF22BFA2BC2895DC88A551488540E038A551C88118A55FC88540F018A55F888140183C104FF4DC8
  1918.         75DFFF45108B45103B45EC7CAB8BC3C1E0020145DCFF4DCC0F85CEFEFFFF8B4DEC33C08945F88945FC89451C8945148945103BC87E6C3945F07E5C8B4DD8
  1919.         8B75E80FAFCB034D100FAFF30FAF4D188B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945C80FB6440E030145140FB60101451C0F
  1920.         B6440F010145FC8B45F40FB604010145F883C104FF4DC875D833C0FF45108B4DEC394D107C940FAF4DF03BC874068B451499F7F933F68945143BCE740B8B
  1921.         451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975083975EC7E63EB0233F639
  1922.         75F07E4F8B4DD88B75E80FAFCB034D080FAFF30FAF4D188B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955108A551488540E038A551C8811
  1923.         8A55FC88540F018A55F888140883C104FF4D1075DFFF45088B45083B45EC7C9F5F5E33C05BC9C21800
  1924.         )
  1925.         else ; x64 machine code
  1926.         MCode_PixelateBitmap =
  1927.         (LTrim Join
  1928.         4489442418488954241048894C24085355565741544155415641574883EC28418BC1448B8C24980000004C8BDA99488BD941F7F9448BD0448BFA8954240C
  1929.         448994248800000085C00F8E9D020000418BC04533E4458BF299448924244C8954241041F7F933C9898C24980000008BEA89542404448BE889442408EB05
  1930.         4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C2418450FAFF14533D233F633ED4533E44533ED4585C97E5B4C63BC2490000000418D040A410FAF
  1931.         C148984C8D441802498BD9498BD04D8BD90FB642010FB64AFF4403E80FB60203E90FB64AFE4883C2044403E003F149FFCB75DE4D03C748FFCB75D0488B7C
  1932.         24188B8C24980000004C8B5C2478418BC59941F7FE448BE8418BC49941F7FE448BE08BC59941F7FE8BE88BC69941F7FE8BF04585C97E4048639C24900000
  1933.         004103CA4D8BC1410FAFC94863C94A8D541902488BCA498BC144886901448821408869FF408871FE4883C10448FFC875E84803D349FFC875DA8B8C249800
  1934.         0000488B5C24704C8B5C24784183C20448FFCF48897C24180F850AFFFFFF8B6C2404448B2424448B6C24084C8B74241085ED0F840A01000033FF33DB4533
  1935.         DB4533D24533C04585C97E53488B74247085ED7E42438D0C04418BC50FAF8C2490000000410FAFC18D04814863C8488D5431028BCD0FB642014403D00FB6
  1936.         024883C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC17CB28BCD410FAFC985C9740A418BC299F7F98BF0EB0233F685C9740B418BC3
  1937.         99F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585C97E4D4C8B74247885ED7E3841
  1938.         8D0C14418BC50FAF8C2490000000410FAFC18D04814863C84A8D4431028BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2413BD17CBD
  1939.         4C8B7424108B8C2498000000038C2490000000488B5C24704503E149FFCE44892424898C24980000004C897424100F859EFDFFFF448B7C240C448B842480
  1940.         000000418BC09941F7F98BE8448BEA89942498000000896C240C85C00F8E3B010000448BAC2488000000418BCF448BF5410FAFC9898C248000000033FF33
  1941.         ED33F64533DB4533D24533C04585FF7E524585C97E40418BC5410FAFC14103C00FAF84249000000003C74898488D541802498BD90FB642014403D00FB602
  1942.         4883C2044403D80FB642FB03F00FB642FA03E848FFCB75DE488B5C247041FFC0453BC77CAE85C9740B418BC299F7F9448BE0EB034533E485C9740A418BC3
  1943.         99F7F98BD8EB0233DB85C9740A8BC699F7F9448BD8EB034533DB85C9740A8BC599F7F9448BD0EB034533D24533C04585FF7E4E488B4C24784585C97E3541
  1944.         8BC5410FAFC14103C00FAF84249000000003C74898488D540802498BC144886201881A44885AFF448852FE4883C20448FFC875E941FFC0453BC77CBE8B8C
  1945.         2480000000488B5C2470418BC1C1E00203F849FFCE0F85ECFEFFFF448BAC24980000008B6C240C448BA4248800000033FF33DB4533DB4533D24533C04585
  1946.         FF7E5A488B7424704585ED7E48418BCC8BC5410FAFC94103C80FAF8C2490000000410FAFC18D04814863C8488D543102418BCD0FB642014403D00FB60248
  1947.         83C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC77CAB418BCF410FAFCD85C9740A418BC299F7F98BF0EB0233F685C9740B418BC399
  1948.         F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585FF7E4E4585ED7E42418BCC8BC541
  1949.         0FAFC903CA0FAF8C2490000000410FAFC18D04814863C8488B442478488D440102418BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2
  1950.         413BD77CB233C04883C428415F415E415D415C5F5E5D5BC3
  1951.         )
  1952.        
  1953.         VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2)
  1954.         Loop % StrLen(MCode_PixelateBitmap)//2      ;%
  1955.             NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "UChar")
  1956.         DllCall("VirtualProtect", Ptr, &PixelateBitmap, Ptr, VarSetCapacity(PixelateBitmap), "uint", 0x40, A_PtrSize ? "UPtr*" : "UInt*", 0)
  1957.     }
  1958.  
  1959.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  1960.    
  1961.     if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
  1962.         return -1
  1963.     if (BlockSize > Width || BlockSize > Height)
  1964.         return -2
  1965.  
  1966.     E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
  1967.     E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
  1968.     if (E1 || E2)
  1969.         return -3
  1970.  
  1971.     E := DllCall(&PixelateBitmap, Ptr, Scan01, Ptr, Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize)
  1972.    
  1973.     Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
  1974.     return 0
  1975. }
  1976. Gdip_ToARGB(A, R, G, B)
  1977. {
  1978.     return (A << 24) | (R << 16) | (G << 8) | B
  1979. }
  1980. Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B)
  1981. {
  1982.     A := (0xff000000 & ARGB) >> 24
  1983.     R := (0x00ff0000 & ARGB) >> 16
  1984.     G := (0x0000ff00 & ARGB) >> 8
  1985.     B := 0x000000ff & ARGB
  1986. }
  1987. Gdip_AFromARGB(ARGB)
  1988. {
  1989.     return (0xff000000 & ARGB) >> 24
  1990. }
  1991. Gdip_RFromARGB(ARGB)
  1992. {
  1993.     return (0x00ff0000 & ARGB) >> 16
  1994. }
  1995. Gdip_GFromARGB(ARGB)
  1996. {
  1997.     return (0x0000ff00 & ARGB) >> 8
  1998. }
  1999. Gdip_BFromARGB(ARGB)
  2000. {
  2001.     return 0x000000ff & ARGB
  2002. }
  2003. StrGetB(Address, Length=-1, Encoding=0)
  2004. {
  2005.     if Length is not integer
  2006.     Encoding := Length,  Length := -1
  2007.  
  2008.     if (Address+0 < 1024)
  2009.         return
  2010.     if Encoding = UTF-16
  2011.         Encoding = 1200
  2012.     else if Encoding = UTF-8
  2013.         Encoding = 65001
  2014.     else if SubStr(Encoding,1,2)="CP"
  2015.         Encoding := SubStr(Encoding,3)
  2016.  
  2017.     if !Encoding ; "" or 0
  2018.     {
  2019.         if (Length == -1)
  2020.             Length := DllCall("lstrlen", "uint", Address)
  2021.         VarSetCapacity(String, Length)
  2022.         DllCall("lstrcpyn", "str", String, "uint", Address, "int", Length + 1)
  2023.     }
  2024.     else if Encoding = 1200 ; UTF-16
  2025.     {
  2026.         char_count := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "uint", 0, "uint", 0, "uint", 0, "uint", 0)
  2027.         VarSetCapacity(String, char_count)
  2028.         DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "str", String, "int", char_count, "uint", 0, "uint", 0)
  2029.     }
  2030.     else if Encoding is integer
  2031.     {
  2032.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", 0, "int", 0)
  2033.         VarSetCapacity(String, char_count * 2)
  2034.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", &String, "int", char_count * 2)
  2035.         String := StrGetB(&String, char_count, 1200)
  2036.     }
  2037.    
  2038.     return String
  2039. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement