Advertisement
pastamaker

POLYGON V3 G

Jun 30th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5.  
  6. CoordMode,mouse,screen
  7.  
  8.  
  9. ;~ #Include,<hellbents_gdip>
  10.  
  11.  SetBatchLines,-1
  12.  
  13.  #MaxHotkeysPerInterval,10000000000
  14.  
  15.  popUp:=Layered_Window_SetUp(4,0,0,A_ScreenWidth,A_ScreenHeight,1,"Alwaysontop")
  16.  
  17. pointsmass:=[]
  18. pBrush:=new_brush("000000")
  19. backBrush:=new_brush("a00000","90")
  20. point:={x:500,y:350}
  21. loop {
  22.    
  23.     points:=""
  24.     howmany := pointsmass.length() - 1
  25.     Loop % HOWmany {
  26.         points.= pointsmass[a_index].x  " , "  pointsmass[a_index].y " || "
  27.    
  28.     }
  29.     points.= pointsmass[pointsmass.length()].x  " , "  pointsmass[pointsmass.length()].y  
  30.    
  31.     gosub justDraw
  32.     if(getkeystate("capslock","T"))
  33.         break
  34.     if(GetKeyState("lbutton")){
  35.         MouseGetPos,x,y
  36.         a:={x:x,y:y}
  37.        
  38.         PointsMass.insert(a.clone())
  39.        
  40.         loop {
  41.             if(getkeystate("lbutton") = 0)
  42.                 break
  43.         }
  44.        
  45.     }
  46. }
  47.  
  48. howmany := pointsmass.length() - 1
  49. massLines:=[]
  50. loop % howmany {
  51.     x1:=PointsMass[A_Index].x
  52.     y1:=PointsMass[A_Index].y
  53.     x2:=PointsMass[A_Index+1].x
  54.     y2:=PointsMass[A_Index+1].y
  55.    
  56.    
  57.    
  58.     mass:={x1:x1,x2:x2,y2:y2,y1:y1}
  59.     massLines.insert(mass.clone())
  60. }
  61.  
  62. last := pointsmass.length()
  63. x1:=PointsMass[last].x
  64. y1:=PointsMass[last].y
  65. x2:=PointsMass[1].x
  66. y2:=PointsMass[1].y
  67.  
  68. mass:={x1:x1,x2:x2,y2:y2,y1:y1}
  69. massLines.insert(mass.clone())
  70.  
  71.  
  72.  
  73. massValue:=[]
  74. ANGLEVALUE:=[]
  75. howmany := pointsmass.length()
  76. ;~ *******************
  77.  
  78. ;~ *******************
  79. loop % howmany {
  80.     line:=massLines[a_index]
  81.     massValue.insert(getValue(line,point))
  82.     if(line.x1 = line.x2){
  83.         if(point.x > line.x1)
  84.             angle:=0
  85.         else
  86.             angle:=180
  87.     }
  88.     else {
  89.         angle1:=getangle((line.y2 - line.y1)/(line.x2 - line.x1),-1)
  90.         ;~ ANGLE2:=mod(angle1+180,360)
  91.         angle0:=getangle(-line.x1 +point.x,-line.y1 + point.y)
  92.         abs1:=abs(angle1 - angle0)
  93.         ;~ abs2:=abs(angle2 - angle0)
  94.         if(abs1 < 90)
  95.             angle:=angle1
  96.         else
  97.             angle:=mod(angle1+180,360)
  98.     }
  99.     vals:={sin:sing(angle),cos:cosg(angle)}
  100.     ANGLEVALUE.insert(vals.clone())
  101.    
  102.    
  103.    
  104. }
  105.  
  106.  ball1:= New BallClass(300,300,10,"a00000",50,20,0,1)
  107.  
  108. SetTimer,gameLoop,10
  109. return
  110.  
  111.  
  112. 1::
  113. SetTimer,gameLoop,10
  114. return
  115.  
  116. 2::
  117. SetTimer,gameLoop,50
  118. return
  119. 3::
  120. SetTimer,gameLoop,150
  121. return
  122.  
  123. justDraw:
  124. Gdip_GraphicsClear(popUp.g)
  125.  
  126. Gdip_FillRectangle(popup.g,backBrush,0,0,popup.w,popup.h)
  127.  
  128. Gdip_FillPolygon(popup.g, pBrush, Points, 0)
  129. fill_boxx(popup.g,"000000",POINT.x -5,point.y -5,10,10)
  130.  
  131.  
  132.  
  133. UpdateLayeredWindow(popUp.hwnd, popUp.hdc, popUp.x, popUp.y, popUp.w, popUp.h)
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. return
  149. gameLoop:
  150. SPEED:=10
  151. BALL1.G/=SPEED
  152. BALL1.VX/=10
  153. BALL1.VY/=10
  154. LOOP % SPEED {
  155.     ball1.move()
  156.     gosub checkOutside
  157.  
  158.  
  159. }
  160. BALL1.G*=SPEED
  161. BALL1.VX*=10
  162. BALL1.VY*=10
  163. Gdip_GraphicsClear(popUp.g)
  164.  
  165. Gdip_FillRectangle(popup.g,backBrush,0,0,popup.w,popup.h)
  166.  
  167. Gdip_FillPolygon(popup.g, pBrush, Points, 0)
  168.  
  169. BALL1.DRAW(POPUP.G)
  170.  
  171. UpdateLayeredWindow(popUp.hwnd, popUp.hdc, popUp.x, popUp.y, popUp.w, popUp.h)
  172. return
  173.  
  174.  
  175. checkOutside:
  176.  
  177.  
  178.  
  179. out:=0
  180.  
  181. howmany := pointsmass.length()
  182. loop % howmany {
  183.    
  184.     x:=ball1.x - ball1.r*ANGLEVALUE[A_INDEX].cos
  185.     y:=ball1.y - ball1.r*ANGLEVALUE[A_INDEX].sin
  186.     point:={x:x,y:y}
  187.     line:=massLines[a_index]
  188.     Value:=getValue(line,point)
  189.     if(massValue[a_index] <> Value){
  190.         ;~ ToolTip,% GETANGLE(ANGLEVALUE[A_INDEX].cos,ANGLEVALUE[A_INDEX].SIN)
  191.         out:=A_Index
  192.         break
  193.     }
  194.    
  195.    
  196.    
  197.    
  198. }
  199. If(out <> 0){
  200.         ball1.bump(massLines[out])
  201.         ball1.x+=ball1.r*ANGLEVALUE[out].cos
  202.         ball1.y+=ball1.r*ANGLEVALUE[out].sin
  203.         ToolTip,% getangle(ANGLEVALUE[out].cos,ANGLEVALUE[out].sin)
  204.         LOOP 1 {
  205.             BALL1.MOVE()
  206.         }
  207.     }
  208. ;~ ToolTip,% BALL1.VX " " BALL1.VY
  209. return
  210.  
  211. class BallClass {
  212.     __New(X,Y,R,COLOUR,VX,VY,ANGLE,G){
  213.         this.x:=x,this.y:=y,this.r:=r,this.colour:=colour,this.vx:=vx,this.vy:=vy,this.angle:=angle,this.g:=g
  214.     }
  215.     move(){
  216.         this.vy+=this.g
  217.         this.y+=this.vy
  218.         this.x+=this.vx
  219.     }
  220.     draw(g){
  221.         Fill_ellipse(g,this.colour,this.x - this.r,this.y - this.r,2*this.r,2*this.r)
  222.     }
  223.    
  224.     bump(LINE){
  225.        
  226.         if(line.x1 = line.x2){
  227.             this.vx:= - this.vx
  228.             return
  229.         }
  230.        
  231.         angleNorm:=getangle((line.y2 - line.y1)/(line.x2 - line.x1),-1)
  232.        
  233.         angleSpeed:=getAngle(this.vx, this.vy)
  234.         brandNewAngle:= 180 + 2*angleNorm - angleSpeed
  235.         v:=Sqrt(THIS.vx**2 + THIS.vy**2)
  236.         THIS.angle:=brandNewAngle
  237.         this.vx:=v*cosg(brandNewAngle)
  238.         this.vy:=v*sing(brandNewAngle)
  239.        
  240.     }
  241.  
  242. }
  243.    
  244. getValue(line,point){
  245.     x:=point.x,y:=point.y
  246.     x1:=line.x1,y1:=line.y1,x2:=line.x2,y2:=line.y2
  247.     if(x1 = x2){
  248.         if(x > x1)
  249.             return 1
  250.         else if(x <= x1)
  251.             return -1
  252.     }
  253.     else if (x1 <> x2){
  254.         val:= y - (y1 + ((y2-y1)/(x2-x1) )*(x-x1))
  255.         if(val = 0)
  256.             return -1
  257.         return val/abs(val)
  258.     }
  259.    
  260.    
  261.    
  262.    
  263.    
  264. }
  265.  
  266.  
  267.  
  268. getAngle(dx,dy){
  269.     r:=Sqrt(dx**2 + dy**2)
  270.     if(dx>=0)
  271.         angle:= asinG(dy/r)
  272.     else if(dy>=0)
  273.         angle:= acosG(dx/r)
  274.     else if(dx < 0 && dy < 0)
  275.         angle:= 180 + asing(abs(dy/r))
  276.     if(angle < 0)
  277.         angle+=360
  278.     return angle
  279. }
  280.  
  281.  
  282. x::
  283. gosub getOutOfHere
  284. return
  285.  
  286. getOutOfHere:
  287. ExitApp
  288. Layered_Window_ShutDown(popUp)
  289. return
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302. ;STUFF  Hellbent HAS  added
  303. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  304. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  305. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  306.  
  307. Layered_Window_SetUp(Smoothing,Window_X,Window_Y,Window_W,Window_H,Window_Name:=1,Window_Options:="")
  308.     {
  309.         Layered:={}
  310.         Layered.W:=Window_W
  311.         Layered.H:=Window_H
  312.         Layered.X:=Window_X
  313.         Layered.Y:=Window_Y
  314.         Layered.Name:=Window_Name
  315.         Layered.Options:=Window_Options
  316.         Layered.Token:=Gdip_Startup()
  317.         Create_Layered_GUI(Layered)
  318.         Layered.hwnd:=winExist()
  319.         Layered.hbm := CreateDIBSection(Window_W,Window_H)
  320.         Layered.hdc := CreateCompatibleDC()
  321.         Layered.obm := SelectObject(Layered.hdc,Layered.hbm)
  322.         Layered.G := Gdip_GraphicsFromHDC(Layered.hdc)
  323.         Gdip_SetSmoothingMode(Layered.G,Smoothing)
  324.         return Layered
  325.     }
  326.  
  327. Create_Layered_GUI(Layered)
  328.     {
  329.         Gui,% Layered.Name ": +E0x80000 +LastFound " Layered.Options
  330.         Gui,% Layered.Name ":Show",% "x" Layered.X " y" Layered.Y " w" Layered.W " h" Layered.H " NA"
  331.     }
  332.    
  333. Layered_Window_ShutDown(This)
  334.     {
  335.         SelectObject(This.hdc,This.obm)
  336.         DeleteObject(This.hbm)
  337.         DeleteDC(This.hdc)
  338.         gdip_deleteGraphics(This.g)
  339.         Gdip_Shutdown(This.Token)
  340.     }
  341.  
  342. Gdip_RotateBitmap(pBitmap, Angle, Dispose=1) { ; returns rotated bitmap. By Learning one.
  343. Gdip_GetImageDimensions(pBitmap, Width, Height)
  344. Gdip_GetRotatedDimensions(Width, Height, Angle, RWidth, RHeight)
  345. Gdip_GetRotatedTranslation(Width, Height, Angle, xTranslation, yTranslation)
  346.  
  347. pBitmap2 := Gdip_CreateBitmap(RWidth, RHeight)
  348. G2 := Gdip_GraphicsFromImage(pBitmap2), Gdip_SetSmoothingMode(G2, 4), Gdip_SetInterpolationMode(G2, 7)
  349. Gdip_TranslateWorldTransform(G2, xTranslation, yTranslation)
  350. Gdip_RotateWorldTransform(G2, Angle)
  351. Gdip_DrawImage(G2, pBitmap, 0, 0, Width, Height)
  352.  
  353. Gdip_ResetWorldTransform(G2)
  354. Gdip_DeleteGraphics(G2)
  355. if Dispose
  356. Gdip_DisposeImage(pBitmap)
  357. return pBitmap2
  358. }
  359.  
  360. New_Brush(colour:="000000",Alpha:="FF")
  361.     {
  362.         static Hellbent_Brush:=[]
  363.         new_colour := "0x" Alpha colour
  364.         Hellbent_Brush[Hellbent_Brush.Length()+1]:=Gdip_BrushCreateSolid(new_colour)
  365.         return Hellbent_Brush[Hellbent_Brush.Length()]
  366.     }
  367.    
  368.    
  369. New_Pen(colour:="000000",Alpha:="FF",Width:= 5)
  370.     {
  371.         static Hellbent_Pen:=[]
  372.         new_colour := "0x" Alpha colour
  373.         Hellbent_Pen[Hellbent_Pen.Length()+1]:=Gdip_CreatePen(New_Colour,Width)
  374.         return Hellbent_Pen[Hellbent_Pen.Length()]
  375.     }  
  376.    
  377. Fill_Box(pGraphics,pBrush,x,y,w,h) 
  378.     {
  379.         ;~ Gdip_FillRectangle(G, Brush, x, y, w, h)
  380.         Ptr := A_PtrSize ? "UPtr" : "UInt"
  381.    
  382.         return DllCall("gdiplus\GdipFillRectangle"
  383.                     , Ptr, pGraphics
  384.                     , Ptr, pBrush
  385.                     , "float", x
  386.                     , "float", y
  387.                     , "float", w
  388.                     , "float", h)
  389.     }
  390. Fill_Boxx(pGraphics,colour,x,y,w,h){
  391.     pBrush:=new_brush(colour)
  392. Fill_Box(pGraphics,pBrush,x,y,w,h) 
  393. }
  394. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  395. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  396. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  397.  
  398. atang(tann){
  399.     angle:=ATan(tann)
  400.     angle:=angle/(3.14159265359/180)
  401.     return angle
  402. }
  403. tang(angle){
  404.     return tan(angle*(3.14159265359/180))
  405. }
  406.  
  407.  
  408.  
  409.  
  410.  
  411. turn_bitmap(byref xbitmap,xturn){
  412. xWidth := Gdip_GetImageWidth(xbitmap)
  413. xHeight := Gdip_GetImageHeight(xbitmap)
  414.  
  415.  
  416. Gdip_GetRotatedDimensions(xWidth, xHeight, xturn, xRWidth, xRHeight)
  417. ;~ MsgBox,% "Rwidth: " RWidth "`nrheight: " rheight
  418.  
  419. ; xTranslation and yTranslation now contain the distance to shift the image by
  420. Gdip_GetRotatedTranslation(xWidth, xHeight, xturn, xxTranslation, xyTranslation)
  421. ;~ MsgBox,% "xTranslation: " xTranslation "`nyTranslation: " yTranslation
  422. xpBitmap := Gdip_CreateBitmap(xRWidth, xRHeight)                       ; Create a new bitmap
  423. xg := Gdip_GraphicsFromImage(xpBitmap)                                ; Get a pointer to the graphics of the bitmap
  424. Gdip_SetSmoothingMode(xg, 4)
  425.  
  426. Gdip_SetInterpolationMode(xg, 7)
  427. Gdip_TranslateWorldTransform(xg, xxTranslation, xyTranslation)
  428. Gdip_RotateWorldTransform(xg, xturn)
  429.  
  430.  
  431. Gdip_DrawImage(xg, xbitmap, 0,0, xWidth, xHeight)  
  432. Gdip_ResetWorldTransform(xg)
  433.  
  434. xbitmap:=xpbitmap
  435. }
  436.  
  437. turn_in_graphics(byref xg,xx,xy,xturn,xbitmap){
  438.    
  439.     turn_bitmap(xbitmap,xturn)
  440.     xWidth := Gdip_GetImageWidth(xbitmap)
  441. xHeight := Gdip_GetImageHeight(xbitmap)
  442.     Gdip_DrawImage(xG, xBitmap, xx-xWidth/2, xy-xheight/2, xWidth, xHeight)
  443.    
  444. }
  445. fill_ellipse(g,colour,x1,y1,w,h){
  446.         pBrush:=new_brush(colour)
  447.     Gdip_FillEllipse(g, pBrush, x1, y1, w, h)
  448.  
  449. }
  450.  
  451. sinG(x){
  452. return sin(x*3.14159265359/180)
  453. }
  454. asinG(sinn){
  455.     angle:=Asin(sinn)
  456.     angle:=angle/(3.14159265359/180)
  457.     return angle
  458. }
  459.  
  460.  
  461. acosG(coss){
  462.     angle:=Acos(coss)
  463.     angle:=angle/(3.14159265359/180)
  464.     return angle
  465. }
  466.  
  467.  
  468.  
  469. cosG(x){
  470. return cos(x*3.14159265359/180)
  471. }
  472. /*
  473. two new functions and an opportunity to change
  474.  
  475. GDIP_SCALE(Map,SCALE)
  476. ; map you want to get a changed copy that is scale times less than
  477. original one
  478. fileScale(sFile,newName,SCALE)
  479. ;saves a changed( scale times less copy) of image from sfile Path
  480. to newname Path
  481. */
  482. GDIP_SCALE(Map,SCALE){
  483. Gdip_GetImageDimensions(MAP,  wOrig,  hOrig)
  484. newSize:={w:wOrig//SCALE,h:hOrig//SCALE}
  485.  
  486. newMap := Gdip_CreateBitmap(newSize.w, newSize.h)                    
  487. newMapG := Gdip_GraphicsFromImage(newMap)                              
  488. Gdip_SetSmoothingMode(newMapG, 4)
  489. Gdip_DrawImage(newMapG, map, 0, 0 ,newSize.w,newSize.h,0,0,wOrig,hOrig)
  490. return newMap
  491.    
  492.    
  493. }
  494.  
  495. fileScale(sFile,newName,SCALE){
  496.     map:=Gdip_CreateBitmapFromFile(sfile)
  497.     newmap:=GDIP_SCALE(Map,SCALE)
  498.     Gdip_SaveBitmapToFile(newmap, newname)
  499. }
  500.  
  501.  
  502.  
  503.         ;~ split(string){
  504.     ;~ string := StrSplit(string, A_Space)  
  505.     ;~ t:=1
  506.     ;~ while ( string.length() >= t) {
  507.         ;~ if(string[t]<>"")
  508.             ;~ t++
  509.         ;~ else
  510.             ;~ string.Remove(t)
  511.     ;~ }
  512.     ;~ return string
  513. ;~ }
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522. ; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11
  523. ; Modifed by Rseding91 using fincs 64 bit compatible Gdip library 5/1/2013
  524. ; Supports: Basic, _L ANSi, _L Unicode x86 and _L Unicode x64
  525. ;
  526. ; Updated 2/20/2014 - fixed Gdip_CreateRegion() and Gdip_GetClipRegion() on AHK Unicode x86
  527. ; Updated 5/13/2013 - fixed Gdip_SetBitmapToClipboard() on AHK Unicode x64
  528. ;
  529. ;#####################################################################################
  530. ;#####################################################################################
  531. ; STATUS ENUMERATION
  532. ; Return values for functions specified to have status enumerated return type
  533. ;#####################################################################################
  534. ;
  535. ; Ok =                      = 0
  536. ; GenericError              = 1
  537. ; InvalidParameter          = 2
  538. ; OutOfMemory               = 3
  539. ; ObjectBusy                = 4
  540. ; InsufficientBuffer        = 5
  541. ; NotImplemented            = 6
  542. ; Win32Error                = 7
  543. ; WrongState                = 8
  544. ; Aborted                   = 9
  545. ; FileNotFound              = 10
  546. ; ValueOverflow             = 11
  547. ; AccessDenied              = 12
  548. ; UnknownImageFormat        = 13
  549. ; FontFamilyNotFound        = 14
  550. ; FontStyleNotFound         = 15
  551. ; NotTrueTypeFont           = 16
  552. ; UnsupportedGdiplusVersion = 17
  553. ; GdiplusNotInitialized     = 18
  554. ; PropertyNotFound          = 19
  555. ; PropertyNotSupported      = 20
  556. ; ProfileNotFound           = 21
  557. ;
  558. ;#####################################################################################
  559. ;#####################################################################################
  560. ; FUNCTIONS
  561. ;#####################################################################################
  562. ;
  563. ; UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  564. ; BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  565. ; StretchBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, sw, sh, Raster="")
  566. ; SetImage(hwnd, hBitmap)
  567. ; Gdip_BitmapFromScreen(Screen=0, Raster="")
  568. ; CreateRectF(ByRef RectF, x, y, w, h)
  569. ; CreateSizeF(ByRef SizeF, w, h)
  570. ; CreateDIBSection
  571. ;
  572. ;#####################################################################################
  573.  
  574. ; Function:                 UpdateLayeredWindow
  575. ; Description:              Updates a layered window with the handle to the DC of a gdi bitmap
  576. ;
  577. ; hwnd                      Handle of the layered window to update
  578. ; hdc                       Handle to the DC of the GDI bitmap to update the window with
  579. ; Layeredx                  x position to place the window
  580. ; Layeredy                  y position to place the window
  581. ; Layeredw                  Width of the window
  582. ; Layeredh                  Height of the window
  583. ; Alpha                     Default = 255 : The transparency (0-255) to set the window transparency
  584. ;
  585. ; return                    If the function succeeds, the return value is nonzero
  586. ;
  587. ; notes                     If x or y omitted, then layered window will use its current coordinates
  588. ;                           If w or h omitted then current width and height will be used
  589.  
  590. UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  591. {
  592.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  593.    
  594.     if ((x != "") && (y != ""))
  595.         VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")
  596.  
  597.     if (w = "") ||(h = "")
  598.         WinGetPos,,, w, h, ahk_id %hwnd%
  599.    
  600.     return DllCall("UpdateLayeredWindow"
  601.                     , Ptr, hwnd
  602.                     , Ptr, 0
  603.                     , Ptr, ((x = "") && (y = "")) ? 0 : &pt
  604.                     , "int64*", w|h<<32
  605.                     , Ptr, hdc
  606.                     , "int64*", 0
  607.                     , "uint", 0
  608.                     , "UInt*", Alpha<<16|1<<24
  609.                     , "uint", 2)
  610. }
  611.  
  612. ;#####################################################################################
  613.  
  614. ; Function              BitBlt
  615. ; Description           The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle
  616. ;                       of pixels from the specified source device context into a destination device context.
  617. ;
  618. ; dDC                   handle to destination DC
  619. ; dx                    x-coord of destination upper-left corner
  620. ; dy                    y-coord of destination upper-left corner
  621. ; dw                    width of the area to copy
  622. ; dh                    height of the area to copy
  623. ; sDC                   handle to source DC
  624. ; sx                    x-coordinate of source upper-left corner
  625. ; sy                    y-coordinate of source upper-left corner
  626. ; Raster                raster operation code
  627. ;
  628. ; return                If the function succeeds, the return value is nonzero
  629. ;
  630. ; notes                 If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle
  631. ;
  632. ; BLACKNESS             = 0x00000042
  633. ; NOTSRCERASE           = 0x001100A6
  634. ; NOTSRCCOPY            = 0x00330008
  635. ; SRCERASE              = 0x00440328
  636. ; DSTINVERT             = 0x00550009
  637. ; PATINVERT             = 0x005A0049
  638. ; SRCINVERT             = 0x00660046
  639. ; SRCAND                = 0x008800C6
  640. ; MERGEPAINT            = 0x00BB0226
  641. ; MERGECOPY             = 0x00C000CA
  642. ; SRCCOPY               = 0x00CC0020
  643. ; SRCPAINT              = 0x00EE0086
  644. ; PATCOPY               = 0x00F00021
  645. ; PATPAINT              = 0x00FB0A09
  646. ; WHITENESS             = 0x00FF0062
  647. ; CAPTUREBLT            = 0x40000000
  648. ; NOMIRRORBITMAP        = 0x80000000
  649.  
  650. BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  651. {
  652.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  653.    
  654.     return DllCall("gdi32\BitBlt"
  655.                     , Ptr, dDC
  656.                     , "int", dx
  657.                     , "int", dy
  658.                     , "int", dw
  659.                     , "int", dh
  660.                     , Ptr, sDC
  661.                     , "int", sx
  662.                     , "int", sy
  663.                     , "uint", Raster ? Raster : 0x00CC0020)
  664. }
  665.  
  666. ;#####################################################################################
  667.  
  668. ; Function              StretchBlt
  669. ; Description           The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle,
  670. ;                       stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
  671. ;                       The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.
  672. ;
  673. ; ddc                   handle to destination DC
  674. ; dx                    x-coord of destination upper-left corner
  675. ; dy                    y-coord of destination upper-left corner
  676. ; dw                    width of destination rectangle
  677. ; dh                    height of destination rectangle
  678. ; sdc                   handle to source DC
  679. ; sx                    x-coordinate of source upper-left corner
  680. ; sy                    y-coordinate of source upper-left corner
  681. ; sw                    width of source rectangle
  682. ; sh                    height of source rectangle
  683. ; Raster                raster operation code
  684. ;
  685. ; return                If the function succeeds, the return value is nonzero
  686. ;
  687. ; notes                 If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt    
  688.  
  689. StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="")
  690. {
  691.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  692.    
  693.     return DllCall("gdi32\StretchBlt"
  694.                     , Ptr, ddc
  695.                     , "int", dx
  696.                     , "int", dy
  697.                     , "int", dw
  698.                     , "int", dh
  699.                     , Ptr, sdc
  700.                     , "int", sx
  701.                     , "int", sy
  702.                     , "int", sw
  703.                     , "int", sh
  704.                     , "uint", Raster ? Raster : 0x00CC0020)
  705. }
  706.  
  707. ;#####################################################################################
  708.  
  709. ; Function              SetStretchBltMode
  710. ; Description           The SetStretchBltMode function sets the bitmap stretching mode in the specified device context
  711. ;
  712. ; hdc                   handle to the DC
  713. ; iStretchMode          The stretching mode, describing how the target will be stretched
  714. ;
  715. ; return                If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0
  716. ;
  717. ; STRETCH_ANDSCANS      = 0x01
  718. ; STRETCH_ORSCANS       = 0x02
  719. ; STRETCH_DELETESCANS   = 0x03
  720. ; STRETCH_HALFTONE      = 0x04
  721.  
  722. SetStretchBltMode(hdc, iStretchMode=4)
  723. {
  724.     return DllCall("gdi32\SetStretchBltMode"
  725.                     , A_PtrSize ? "UPtr" : "UInt", hdc
  726.                     , "int", iStretchMode)
  727. }
  728.  
  729. ;#####################################################################################
  730.  
  731. ; Function              SetImage
  732. ; Description           Associates a new image with a static control
  733. ;
  734. ; hwnd                  handle of the control to update
  735. ; hBitmap               a gdi bitmap to associate the static control with
  736. ;
  737. ; return                If the function succeeds, the return value is nonzero
  738.  
  739. SetImage(hwnd, hBitmap)
  740. {
  741.     SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
  742.     E := ErrorLevel
  743.     DeleteObject(E)
  744.     return E
  745. }
  746.  
  747. ;#####################################################################################
  748.  
  749. ; Function              SetSysColorToControl
  750. ; Description           Sets a solid colour to a control
  751. ;
  752. ; hwnd                  handle of the control to update
  753. ; SysColor              A system colour to set to the control
  754. ;
  755. ; return                If the function succeeds, the return value is zero
  756. ;
  757. ; notes                 A control must have the 0xE style set to it so it is recognised as a bitmap
  758. ;                       By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control
  759. ;
  760. ; COLOR_3DDKSHADOW              = 21
  761. ; COLOR_3DFACE                  = 15
  762. ; COLOR_3DHIGHLIGHT             = 20
  763. ; COLOR_3DHILIGHT               = 20
  764. ; COLOR_3DLIGHT                 = 22
  765. ; COLOR_3DSHADOW                = 16
  766. ; COLOR_ACTIVEBORDER            = 10
  767. ; COLOR_ACTIVECAPTION           = 2
  768. ; COLOR_APPWORKSPACE            = 12
  769. ; COLOR_BACKGROUND              = 1
  770. ; COLOR_BTNFACE                 = 15
  771. ; COLOR_BTNHIGHLIGHT            = 20
  772. ; COLOR_BTNHILIGHT              = 20
  773. ; COLOR_BTNSHADOW               = 16
  774. ; COLOR_BTNTEXT                 = 18
  775. ; COLOR_CAPTIONTEXT             = 9
  776. ; COLOR_DESKTOP                 = 1
  777. ; COLOR_GRADIENTACTIVECAPTION   = 27
  778. ; COLOR_GRADIENTINACTIVECAPTION = 28
  779. ; COLOR_GRAYTEXT                = 17
  780. ; COLOR_HIGHLIGHT               = 13
  781. ; COLOR_HIGHLIGHTTEXT           = 14
  782. ; COLOR_HOTLIGHT                = 26
  783. ; COLOR_INACTIVEBORDER          = 11
  784. ; COLOR_INACTIVECAPTION         = 3
  785. ; COLOR_INACTIVECAPTIONTEXT     = 19
  786. ; COLOR_INFOBK                  = 24
  787. ; COLOR_INFOTEXT                = 23
  788. ; COLOR_MENU                    = 4
  789. ; COLOR_MENUHILIGHT             = 29
  790. ; COLOR_MENUBAR                 = 30
  791. ; COLOR_MENUTEXT                = 7
  792. ; COLOR_SCROLLBAR               = 0
  793. ; COLOR_WINDOW                  = 5
  794. ; COLOR_WINDOWFRAME             = 6
  795. ; COLOR_WINDOWTEXT              = 8
  796.  
  797. SetSysColorToControl(hwnd, SysColor=15)
  798. {
  799.    WinGetPos,,, w, h, ahk_id %hwnd%
  800.    bc := DllCall("GetSysColor", "Int", SysColor, "UInt")
  801.    pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
  802.    pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap)
  803.    Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
  804.    hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  805.    SetImage(hwnd, hBitmap)
  806.    Gdip_DeleteBrush(pBrushClear)
  807.    Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
  808.    return 0
  809. }
  810.  
  811. ;#####################################################################################
  812.  
  813. ; Function              Gdip_BitmapFromScreen
  814. ; Description           Gets a gdi+ bitmap from the screen
  815. ;
  816. ; Screen                0 = All screens
  817. ;                       Any numerical value = Just that screen
  818. ;                       x|y|w|h = Take specific coordinates with a width and height
  819. ; Raster                raster operation code
  820. ;
  821. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  822. ;                       -1:     one or more of x,y,w,h not passed properly
  823. ;
  824. ; notes                 If no raster operation is specified, then SRCCOPY is used to the returned bitmap
  825.  
  826. Gdip_BitmapFromScreen(Screen=0, Raster="")
  827. {
  828.     if (Screen = 0)
  829.     {
  830.         Sysget, x, 76
  831.         Sysget, y, 77  
  832.         Sysget, w, 78
  833.         Sysget, h, 79
  834.     }
  835.     else if (SubStr(Screen, 1, 5) = "hwnd:")
  836.     {
  837.         Screen := SubStr(Screen, 6)
  838.         if !WinExist( "ahk_id " Screen)
  839.             return -2
  840.         WinGetPos,,, w, h, ahk_id %Screen%
  841.         x := y := 0
  842.         hhdc := GetDCEx(Screen, 3)
  843.     }
  844.     else if (Screen&1 != "")
  845.     {
  846.         Sysget, M, Monitor, %Screen%
  847.         x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
  848.     }
  849.     else
  850.     {
  851.         StringSplit, S, Screen, |
  852.         x := S1, y := S2, w := S3, h := S4
  853.     }
  854.  
  855.     if (x = "") || (y = "") || (w = "") || (h = "")
  856.         return -1
  857.  
  858.     chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
  859.     BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
  860.     ReleaseDC(hhdc)
  861.    
  862.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  863.     SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
  864.     return pBitmap
  865. }
  866.  
  867. ;#####################################################################################
  868.  
  869. ; Function              Gdip_BitmapFromHWND
  870. ; Description           Uses PrintWindow to get a handle to the specified window and return a bitmap from it
  871. ;
  872. ; hwnd                  handle to the window to get a bitmap from
  873. ;
  874. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  875. ;
  876. ; notes                 Window must not be not minimised in order to get a handle to it's client area
  877.  
  878. Gdip_BitmapFromHWND(hwnd)
  879. {
  880.     WinGetPos,,, Width, Height, ahk_id %hwnd%
  881.     hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  882.     PrintWindow(hwnd, hdc)
  883.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  884.     SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  885.     return pBitmap
  886. }
  887.  
  888. ;#####################################################################################
  889.  
  890. ; Function              CreateRectF
  891. ; Description           Creates a RectF object, containing a the coordinates and dimensions of a rectangle
  892. ;
  893. ; RectF                 Name to call the RectF object
  894. ; x                     x-coordinate of the upper left corner of the rectangle
  895. ; y                     y-coordinate of the upper left corner of the rectangle
  896. ; w                     Width of the rectangle
  897. ; h                     Height of the rectangle
  898. ;
  899. ; return                No return value
  900.  
  901. CreateRectF(ByRef RectF, x, y, w, h)
  902. {
  903.    VarSetCapacity(RectF, 16)
  904.    NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
  905. }
  906.  
  907. ;#####################################################################################
  908.  
  909. ; Function              CreateRect
  910. ; Description           Creates a Rect object, containing a the coordinates and dimensions of a rectangle
  911. ;
  912. ; RectF                 Name to call the RectF object
  913. ; x                     x-coordinate of the upper left corner of the rectangle
  914. ; y                     y-coordinate of the upper left corner of the rectangle
  915. ; w                     Width of the rectangle
  916. ; h                     Height of the rectangle
  917. ;
  918. ; return                No return value
  919.  
  920. CreateRect(ByRef Rect, x, y, w, h)
  921. {
  922.     VarSetCapacity(Rect, 16)
  923.     NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint")
  924. }
  925. ;#####################################################################################
  926.  
  927. ; Function              CreateSizeF
  928. ; Description           Creates a SizeF object, containing an 2 values
  929. ;
  930. ; SizeF                 Name to call the SizeF object
  931. ; w                     w-value for the SizeF object
  932. ; h                     h-value for the SizeF object
  933. ;
  934. ; return                No Return value
  935.  
  936. CreateSizeF(ByRef SizeF, w, h)
  937. {
  938.    VarSetCapacity(SizeF, 8)
  939.    NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")    
  940. }
  941. ;#####################################################################################
  942.  
  943. ; Function              CreatePointF
  944. ; Description           Creates a SizeF object, containing an 2 values
  945. ;
  946. ; SizeF                 Name to call the SizeF object
  947. ; w                     w-value for the SizeF object
  948. ; h                     h-value for the SizeF object
  949. ;
  950. ; return                No Return value
  951.  
  952. CreatePointF(ByRef PointF, x, y)
  953. {
  954.    VarSetCapacity(PointF, 8)
  955.    NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")    
  956. }
  957. ;#####################################################################################
  958.  
  959. ; Function              CreateDIBSection
  960. ; Description           The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly
  961. ;
  962. ; w                     width of the bitmap to create
  963. ; h                     height of the bitmap to create
  964. ; hdc                   a handle to the device context to use the palette from
  965. ; bpp                   bits per pixel (32 = ARGB)
  966. ; ppvBits               A pointer to a variable that receives a pointer to the location of the DIB bit values
  967. ;
  968. ; return                returns a DIB. A gdi bitmap
  969. ;
  970. ; notes                 ppvBits will receive the location of the pixels in the DIB
  971.  
  972. CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
  973. {
  974.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  975.    
  976.     hdc2 := hdc ? hdc : GetDC()
  977.     VarSetCapacity(bi, 40, 0)
  978.    
  979.     NumPut(w, bi, 4, "uint")
  980.     , NumPut(h, bi, 8, "uint")
  981.     , NumPut(40, bi, 0, "uint")
  982.     , NumPut(1, bi, 12, "ushort")
  983.     , NumPut(0, bi, 16, "uInt")
  984.     , NumPut(bpp, bi, 14, "ushort")
  985.    
  986.     hbm := DllCall("CreateDIBSection"
  987.                     , Ptr, hdc2
  988.                     , Ptr, &bi
  989.                     , "uint", 0
  990.                     , A_PtrSize ? "UPtr*" : "uint*", ppvBits
  991.                     , Ptr, 0
  992.                     , "uint", 0, Ptr)
  993.  
  994.     if !hdc
  995.         ReleaseDC(hdc2)
  996.     return hbm
  997. }
  998.  
  999. ;#####################################################################################
  1000.  
  1001. ; Function              PrintWindow
  1002. ; Description           The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC
  1003. ;
  1004. ; hwnd                  A handle to the window that will be copied
  1005. ; hdc                   A handle to the device context
  1006. ; Flags                 Drawing options
  1007. ;
  1008. ; return                If the function succeeds, it returns a nonzero value
  1009. ;
  1010. ; PW_CLIENTONLY         = 1
  1011.  
  1012. PrintWindow(hwnd, hdc, Flags=0)
  1013. {
  1014.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1015.    
  1016.     return DllCall("PrintWindow", Ptr, hwnd, Ptr, hdc, "uint", Flags)
  1017. }
  1018.  
  1019. ;#####################################################################################
  1020.  
  1021. ; Function              DestroyIcon
  1022. ; Description           Destroys an icon and frees any memory the icon occupied
  1023. ;
  1024. ; hIcon                 Handle to the icon to be destroyed. The icon must not be in use
  1025. ;
  1026. ; return                If the function succeeds, the return value is nonzero
  1027.  
  1028. DestroyIcon(hIcon)
  1029. {
  1030.     return DllCall("DestroyIcon", A_PtrSize ? "UPtr" : "UInt", hIcon)
  1031. }
  1032.  
  1033. ;#####################################################################################
  1034.  
  1035. PaintDesktop(hdc)
  1036. {
  1037.     return DllCall("PaintDesktop", A_PtrSize ? "UPtr" : "UInt", hdc)
  1038. }
  1039.  
  1040. ;#####################################################################################
  1041.  
  1042. CreateCompatibleBitmap(hdc, w, h)
  1043. {
  1044.     return DllCall("gdi32\CreateCompatibleBitmap", A_PtrSize ? "UPtr" : "UInt", hdc, "int", w, "int", h)
  1045. }
  1046.  
  1047. ;#####################################################################################
  1048.  
  1049. ; Function              CreateCompatibleDC
  1050. ; Description           This function creates a memory device context (DC) compatible with the specified device
  1051. ;
  1052. ; hdc                   Handle to an existing device context                   
  1053. ;
  1054. ; return                returns the handle to a device context or 0 on failure
  1055. ;
  1056. ; notes                 If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen
  1057.  
  1058. CreateCompatibleDC(hdc=0)
  1059. {
  1060.    return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  1061. }
  1062.  
  1063. ;#####################################################################################
  1064.  
  1065. ; Function              SelectObject
  1066. ; Description           The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type
  1067. ;
  1068. ; hdc                   Handle to a DC
  1069. ; hgdiobj               A handle to the object to be selected into the DC
  1070. ;
  1071. ; return                If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced
  1072. ;
  1073. ; notes                 The specified object must have been created by using one of the following functions
  1074. ;                       Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time)
  1075. ;                       Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
  1076. ;                       Font - CreateFont, CreateFontIndirect
  1077. ;                       Pen - CreatePen, CreatePenIndirect
  1078. ;                       Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect
  1079. ;
  1080. ; notes                 If the selected object is a region and the function succeeds, the return value is one of the following value
  1081. ;
  1082. ; SIMPLEREGION          = 2 Region consists of a single rectangle
  1083. ; COMPLEXREGION         = 3 Region consists of more than one rectangle
  1084. ; NULLREGION            = 1 Region is empty
  1085.  
  1086. SelectObject(hdc, hgdiobj)
  1087. {
  1088.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1089.    
  1090.     return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
  1091. }
  1092.  
  1093. ;#####################################################################################
  1094.  
  1095. ; Function              DeleteObject
  1096. ; Description           This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object
  1097. ;                       After the object is deleted, the specified handle is no longer valid
  1098. ;
  1099. ; hObject               Handle to a logical pen, brush, font, bitmap, region, or palette to delete
  1100. ;
  1101. ; return                Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context
  1102.  
  1103. DeleteObject(hObject)
  1104. {
  1105.    return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject)
  1106. }
  1107.  
  1108. ;#####################################################################################
  1109.  
  1110. ; Function              GetDC
  1111. ; Description           This function retrieves a handle to a display device context (DC) for the client area of the specified window.
  1112. ;                       The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window.
  1113. ;
  1114. ; hwnd                  Handle to the window whose device context is to be retrieved. If this value is NULL, GetDC retrieves the device context for the entire screen                  
  1115. ;
  1116. ; return                The handle the device context for the specified window's client area indicates success. NULL indicates failure
  1117.  
  1118. GetDC(hwnd=0)
  1119. {
  1120.     return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
  1121. }
  1122.  
  1123. ;#####################################################################################
  1124.  
  1125. ; DCX_CACHE = 0x2
  1126. ; DCX_CLIPCHILDREN = 0x8
  1127. ; DCX_CLIPSIBLINGS = 0x10
  1128. ; DCX_EXCLUDERGN = 0x40
  1129. ; DCX_EXCLUDEUPDATE = 0x100
  1130. ; DCX_INTERSECTRGN = 0x80
  1131. ; DCX_INTERSECTUPDATE = 0x200
  1132. ; DCX_LOCKWINDOWUPDATE = 0x400
  1133. ; DCX_NORECOMPUTE = 0x100000
  1134. ; DCX_NORESETATTRS = 0x4
  1135. ; DCX_PARENTCLIP = 0x20
  1136. ; DCX_VALIDATE = 0x200000
  1137. ; DCX_WINDOW = 0x1
  1138.  
  1139. GetDCEx(hwnd, flags=0, hrgnClip=0)
  1140. {
  1141.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1142.    
  1143.     return DllCall("GetDCEx", Ptr, hwnd, Ptr, hrgnClip, "int", flags)
  1144. }
  1145.  
  1146. ;#####################################################################################
  1147.  
  1148. ; Function              ReleaseDC
  1149. ; Description           This function releases a device context (DC), freeing it for use by other applications. The effect of ReleaseDC depends on the type of device context
  1150. ;
  1151. ; hdc                   Handle to the device context to be released
  1152. ; hwnd                  Handle to the window whose device context is to be released
  1153. ;
  1154. ; return                1 = released
  1155. ;                       0 = not released
  1156. ;
  1157. ; notes                 The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common device context
  1158. ;                       An application cannot use the ReleaseDC function to release a device context that was created by calling the CreateDC function; instead, it must use the DeleteDC function.
  1159.  
  1160. ReleaseDC(hdc, hwnd=0)
  1161. {
  1162.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1163.    
  1164.     return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
  1165. }
  1166.  
  1167. ;#####################################################################################
  1168.  
  1169. ; Function              DeleteDC
  1170. ; Description           The DeleteDC function deletes the specified device context (DC)
  1171. ;
  1172. ; hdc                   A handle to the device context
  1173. ;
  1174. ; return                If the function succeeds, the return value is nonzero
  1175. ;
  1176. ; notes                 An application must not delete a DC whose handle was obtained by calling the GetDC function. Instead, it must call the ReleaseDC function to free the DC
  1177.  
  1178. DeleteDC(hdc)
  1179. {
  1180.    return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  1181. }
  1182. ;#####################################################################################
  1183.  
  1184. ; Function              Gdip_LibraryVersion
  1185. ; Description           Get the current library version
  1186. ;
  1187. ; return                the library version
  1188. ;
  1189. ; notes                 This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts
  1190.  
  1191. Gdip_LibraryVersion()
  1192. {
  1193.     return 1.45
  1194. }
  1195.  
  1196. ;#####################################################################################
  1197.  
  1198. ; Function              Gdip_LibrarySubVersion
  1199. ; Description           Get the current library sub version
  1200. ;
  1201. ; return                the library sub version
  1202. ;
  1203. ; notes                 This is the sub-version currently maintained by Rseding91
  1204. Gdip_LibrarySubVersion()
  1205. {
  1206.     return 1.47
  1207. }
  1208.  
  1209. ;#####################################################################################
  1210.  
  1211. ; Function:             Gdip_BitmapFromBRA
  1212. ; Description:          Gets a pointer to a gdi+ bitmap from a BRA file
  1213. ;
  1214. ; BRAFromMemIn          The variable for a BRA file read to memory
  1215. ; File                  The name of the file, or its number that you would like (This depends on alternate parameter)
  1216. ; Alternate             Changes whether the File parameter is the file name or its number
  1217. ;
  1218. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  1219. ;                       -1 = The BRA variable is empty
  1220. ;                       -2 = The BRA has an incorrect header
  1221. ;                       -3 = The BRA has information missing
  1222. ;                       -4 = Could not find file inside the BRA
  1223.  
  1224. Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
  1225. {
  1226.     Static FName = "ObjRelease"
  1227.    
  1228.     if !BRAFromMemIn
  1229.         return -1
  1230.     Loop, Parse, BRAFromMemIn, `n
  1231.     {
  1232.         if (A_Index = 1)
  1233.         {
  1234.             StringSplit, Header, A_LoopField, |
  1235.             if (Header0 != 4 || Header2 != "BRA!")
  1236.                 return -2
  1237.         }
  1238.         else if (A_Index = 2)
  1239.         {
  1240.             StringSplit, Info, A_LoopField, |
  1241.             if (Info0 != 3)
  1242.                 return -3
  1243.         }
  1244.         else
  1245.             break
  1246.     }
  1247.     if !Alternate
  1248.         StringReplace, File, File, \, \\, All
  1249.     RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo)
  1250.     if !FileInfo
  1251.         return -4
  1252.    
  1253.     hData := DllCall("GlobalAlloc", "uint", 2, Ptr, FileInfo2, Ptr)
  1254.     pData := DllCall("GlobalLock", Ptr, hData, Ptr)
  1255.     DllCall("RtlMoveMemory", Ptr, pData, Ptr, &BRAFromMemIn+Info2+FileInfo1, Ptr, FileInfo2)
  1256.     DllCall("GlobalUnlock", Ptr, hData)
  1257.     DllCall("ole32\CreateStreamOnHGlobal", Ptr, hData, "int", 1, A_PtrSize ? "UPtr*" : "UInt*", pStream)
  1258.     DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, A_PtrSize ? "UPtr*" : "UInt*", pBitmap)
  1259.     If (A_PtrSize)
  1260.         %FName%(pStream)
  1261.     Else
  1262.         DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)
  1263.     return pBitmap
  1264. }
  1265.  
  1266. ;#####################################################################################
  1267.  
  1268. ; Function              Gdip_DrawRectangle
  1269. ; Description           This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap
  1270. ;
  1271. ; pGraphics             Pointer to the Graphics of a bitmap
  1272. ; pPen                  Pointer to a pen
  1273. ; x                     x-coordinate of the top left of the rectangle
  1274. ; y                     y-coordinate of the top left of the rectangle
  1275. ; w                     width of the rectanlge
  1276. ; h                     height of the rectangle
  1277. ;
  1278. ; return                status enumeration. 0 = success
  1279. ;
  1280. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1281.  
  1282. Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  1283. {
  1284.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1285.    
  1286.     return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  1287. }
  1288.  
  1289. ;#####################################################################################
  1290.  
  1291. ; Function              Gdip_DrawRoundedRectangle
  1292. ; Description           This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap
  1293. ;
  1294. ; pGraphics             Pointer to the Graphics of a bitmap
  1295. ; pPen                  Pointer to a pen
  1296. ; x                     x-coordinate of the top left of the rounded rectangle
  1297. ; y                     y-coordinate of the top left of the rounded rectangle
  1298. ; w                     width of the rectanlge
  1299. ; h                     height of the rectangle
  1300. ; r                     radius of the rounded corners
  1301. ;
  1302. ; return                status enumeration. 0 = success
  1303. ;
  1304. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1305.  
  1306. Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
  1307. {
  1308.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  1309.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  1310.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  1311.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  1312.     E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  1313.     Gdip_ResetClip(pGraphics)
  1314.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  1315.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  1316.     Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
  1317.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
  1318.     Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
  1319.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  1320.     Gdip_ResetClip(pGraphics)
  1321.     return E
  1322. }
  1323.  
  1324. ;#####################################################################################
  1325.  
  1326. ; Function              Gdip_DrawEllipse
  1327. ; Description           This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap
  1328. ;
  1329. ; pGraphics             Pointer to the Graphics of a bitmap
  1330. ; pPen                  Pointer to a pen
  1331. ; x                     x-coordinate of the top left of the rectangle the ellipse will be drawn into
  1332. ; y                     y-coordinate of the top left of the rectangle the ellipse will be drawn into
  1333. ; w                     width of the ellipse
  1334. ; h                     height of the ellipse
  1335. ;
  1336. ; return                status enumeration. 0 = success
  1337. ;
  1338. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1339.  
  1340. Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h)
  1341. {
  1342.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1343.    
  1344.     return DllCall("gdiplus\GdipDrawEllipse", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  1345. }
  1346.  
  1347. ;#####################################################################################
  1348.  
  1349. ; Function              Gdip_DrawBezier
  1350. ; Description           This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap
  1351. ;
  1352. ; pGraphics             Pointer to the Graphics of a bitmap
  1353. ; pPen                  Pointer to a pen
  1354. ; x1                    x-coordinate of the start of the bezier
  1355. ; y1                    y-coordinate of the start of the bezier
  1356. ; x2                    x-coordinate of the first arc of the bezier
  1357. ; y2                    y-coordinate of the first arc of the bezier
  1358. ; x3                    x-coordinate of the second arc of the bezier
  1359. ; y3                    y-coordinate of the second arc of the bezier
  1360. ; x4                    x-coordinate of the end of the bezier
  1361. ; y4                    y-coordinate of the end of the bezier
  1362. ;
  1363. ; return                status enumeration. 0 = success
  1364. ;
  1365. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1366.  
  1367. Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
  1368. {
  1369.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1370.    
  1371.     return DllCall("gdiplus\GdipDrawBezier"
  1372.                     , Ptr, pgraphics
  1373.                     , Ptr, pPen
  1374.                     , "float", x1
  1375.                     , "float", y1
  1376.                     , "float", x2
  1377.                     , "float", y2
  1378.                     , "float", x3
  1379.                     , "float", y3
  1380.                     , "float", x4
  1381.                     , "float", y4)
  1382. }
  1383.  
  1384. ;#####################################################################################
  1385.  
  1386. ; Function              Gdip_DrawArc
  1387. ; Description           This function uses a pen to draw the outline of an arc into the Graphics of a bitmap
  1388. ;
  1389. ; pGraphics             Pointer to the Graphics of a bitmap
  1390. ; pPen                  Pointer to a pen
  1391. ; x                     x-coordinate of the start of the arc
  1392. ; y                     y-coordinate of the start of the arc
  1393. ; w                     width of the arc
  1394. ; h                     height of the arc
  1395. ; StartAngle            specifies the angle between the x-axis and the starting point of the arc
  1396. ; SweepAngle            specifies the angle between the starting and ending points of the arc
  1397. ;
  1398. ; return                status enumeration. 0 = success
  1399. ;
  1400. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1401.  
  1402. Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1403. {
  1404.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1405.    
  1406.     return DllCall("gdiplus\GdipDrawArc"
  1407.                     , Ptr, pGraphics
  1408.                     , Ptr, pPen
  1409.                     , "float", x
  1410.                     , "float", y
  1411.                     , "float", w
  1412.                     , "float", h
  1413.                     , "float", StartAngle
  1414.                     , "float", SweepAngle)
  1415. }
  1416.  
  1417. ;#####################################################################################
  1418.  
  1419. ; Function              Gdip_DrawPie
  1420. ; Description           This function uses a pen to draw the outline of a pie into the Graphics of a bitmap
  1421. ;
  1422. ; pGraphics             Pointer to the Graphics of a bitmap
  1423. ; pPen                  Pointer to a pen
  1424. ; x                     x-coordinate of the start of the pie
  1425. ; y                     y-coordinate of the start of the pie
  1426. ; w                     width of the pie
  1427. ; h                     height of the pie
  1428. ; StartAngle            specifies the angle between the x-axis and the starting point of the pie
  1429. ; SweepAngle            specifies the angle between the starting and ending points of the pie
  1430. ;
  1431. ; return                status enumeration. 0 = success
  1432. ;
  1433. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1434.  
  1435. Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1436. {
  1437.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1438.    
  1439.     return DllCall("gdiplus\GdipDrawPie", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  1440. }
  1441.  
  1442. ;#####################################################################################
  1443.  
  1444. ; Function              Gdip_DrawLine
  1445. ; Description           This function uses a pen to draw a line into the Graphics of a bitmap
  1446. ;
  1447. ; pGraphics             Pointer to the Graphics of a bitmap
  1448. ; pPen                  Pointer to a pen
  1449. ; x1                    x-coordinate of the start of the line
  1450. ; y1                    y-coordinate of the start of the line
  1451. ; x2                    x-coordinate of the end of the line
  1452. ; y2                    y-coordinate of the end of the line
  1453. ;
  1454. ; return                status enumeration. 0 = success    
  1455.  
  1456. Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
  1457. {
  1458.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1459.    
  1460.     return DllCall("gdiplus\GdipDrawLine"
  1461.                     , Ptr, pGraphics
  1462.                     , Ptr, pPen
  1463.                     , "float", x1
  1464.                     , "float", y1
  1465.                     , "float", x2
  1466.                     , "float", y2)
  1467. }
  1468.  
  1469. ;#####################################################################################
  1470.  
  1471. ; Function              Gdip_DrawLines
  1472. ; Description           This function uses a pen to draw a series of joined lines into the Graphics of a bitmap
  1473. ;
  1474. ; pGraphics             Pointer to the Graphics of a bitmap
  1475. ; pPen                  Pointer to a pen
  1476. ; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1477. ;
  1478. ; return                status enumeration. 0 = success            
  1479.  
  1480. Gdip_DrawLines(pGraphics, pPen, Points)
  1481. {
  1482.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1483.     StringSplit, Points, Points, |
  1484.     VarSetCapacity(PointF, 8*Points0)  
  1485.     Loop, %Points0%
  1486.     {
  1487.         StringSplit, Coord, Points%A_Index%, `,
  1488.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1489.     }
  1490.     return DllCall("gdiplus\GdipDrawLines", Ptr, pGraphics, Ptr, pPen, Ptr, &PointF, "int", Points0)
  1491. }
  1492.  
  1493. ;#####################################################################################
  1494.  
  1495. ; Function              Gdip_FillRectangle
  1496. ; Description           This function uses a brush to fill a rectangle in the Graphics of a bitmap
  1497. ;
  1498. ; pGraphics             Pointer to the Graphics of a bitmap
  1499. ; pBrush                Pointer to a brush
  1500. ; x                     x-coordinate of the top left of the rectangle
  1501. ; y                     y-coordinate of the top left of the rectangle
  1502. ; w                     width of the rectanlge
  1503. ; h                     height of the rectangle
  1504. ;
  1505. ; return                status enumeration. 0 = success
  1506.  
  1507. Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1508. {
  1509.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1510.    
  1511.     return DllCall("gdiplus\GdipFillRectangle"
  1512.                     , Ptr, pGraphics
  1513.                     , Ptr, pBrush
  1514.                     , "float", x
  1515.                     , "float", y
  1516.                     , "float", w
  1517.                     , "float", h)
  1518. }
  1519.  
  1520. ;#####################################################################################
  1521.  
  1522. ; Function              Gdip_FillRoundedRectangle
  1523. ; Description           This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap
  1524. ;
  1525. ; pGraphics             Pointer to the Graphics of a bitmap
  1526. ; pBrush                Pointer to a brush
  1527. ; x                     x-coordinate of the top left of the rounded rectangle
  1528. ; y                     y-coordinate of the top left of the rounded rectangle
  1529. ; w                     width of the rectanlge
  1530. ; h                     height of the rectangle
  1531. ; r                     radius of the rounded corners
  1532. ;
  1533. ; return                status enumeration. 0 = success
  1534.  
  1535. Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
  1536. {
  1537.     Region := Gdip_GetClipRegion(pGraphics)
  1538.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  1539.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  1540.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  1541.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  1542.     E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1543.     Gdip_SetClipRegion(pGraphics, Region, 0)
  1544.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  1545.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  1546.     Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
  1547.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
  1548.     Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
  1549.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  1550.     Gdip_SetClipRegion(pGraphics, Region, 0)
  1551.     Gdip_DeleteRegion(Region)
  1552.     return E
  1553. }
  1554.  
  1555. ;#####################################################################################
  1556.  
  1557. ; Function              Gdip_FillPolygon
  1558. ; Description           This function uses a brush to fill a polygon in the Graphics of a bitmap
  1559. ;
  1560. ; pGraphics             Pointer to the Graphics of a bitmap
  1561. ; pBrush                Pointer to a brush
  1562. ; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1563. ;
  1564. ; return                status enumeration. 0 = success
  1565. ;
  1566. ; notes                 Alternate will fill the polygon as a whole, wheras winding will fill each new "segment"
  1567. ; Alternate             = 0
  1568. ; Winding               = 1
  1569.  
  1570. Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
  1571. {
  1572.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1573.    
  1574.     StringSplit, Points, Points, |
  1575.     VarSetCapacity(PointF, 8*Points0)  
  1576.     Loop, %Points0%
  1577.     {
  1578.         StringSplit, Coord, Points%A_Index%, `,
  1579.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1580.     }  
  1581.     return DllCall("gdiplus\GdipFillPolygon", Ptr, pGraphics, Ptr, pBrush, Ptr, &PointF, "int", Points0, "int", FillMode)
  1582. }
  1583.  
  1584. ;#####################################################################################
  1585.  
  1586. ; Function              Gdip_FillPie
  1587. ; Description           This function uses a brush to fill a pie in the Graphics of a bitmap
  1588. ;
  1589. ; pGraphics             Pointer to the Graphics of a bitmap
  1590. ; pBrush                Pointer to a brush
  1591. ; x                     x-coordinate of the top left of the pie
  1592. ; y                     y-coordinate of the top left of the pie
  1593. ; w                     width of the pie
  1594. ; h                     height of the pie
  1595. ; StartAngle            specifies the angle between the x-axis and the starting point of the pie
  1596. ; SweepAngle            specifies the angle between the starting and ending points of the pie
  1597. ;
  1598. ; return                status enumeration. 0 = success
  1599.  
  1600. Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
  1601. {
  1602.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1603.    
  1604.     return DllCall("gdiplus\GdipFillPie"
  1605.                     , Ptr, pGraphics
  1606.                     , Ptr, pBrush
  1607.                     , "float", x
  1608.                     , "float", y
  1609.                     , "float", w
  1610.                     , "float", h
  1611.                     , "float", StartAngle
  1612.                     , "float", SweepAngle)
  1613. }
  1614.  
  1615. ;#####################################################################################
  1616.  
  1617. ; Function              Gdip_FillEllipse
  1618. ; Description           This function uses a brush to fill an ellipse in the Graphics of a bitmap
  1619. ;
  1620. ; pGraphics             Pointer to the Graphics of a bitmap
  1621. ; pBrush                Pointer to a brush
  1622. ; x                     x-coordinate of the top left of the ellipse
  1623. ; y                     y-coordinate of the top left of the ellipse
  1624. ; w                     width of the ellipse
  1625. ; h                     height of the ellipse
  1626. ;
  1627. ; return                status enumeration. 0 = success
  1628.  
  1629. Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h)
  1630. {
  1631.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1632.    
  1633.     return DllCall("gdiplus\GdipFillEllipse", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
  1634. }
  1635.  
  1636. ;#####################################################################################
  1637.  
  1638. ; Function              Gdip_FillRegion
  1639. ; Description           This function uses a brush to fill a region in the Graphics of a bitmap
  1640. ;
  1641. ; pGraphics             Pointer to the Graphics of a bitmap
  1642. ; pBrush                Pointer to a brush
  1643. ; Region                Pointer to a Region
  1644. ;
  1645. ; return                status enumeration. 0 = success
  1646. ;
  1647. ; notes                 You can create a region Gdip_CreateRegion() and then add to this
  1648.  
  1649. Gdip_FillRegion(pGraphics, pBrush, Region)
  1650. {
  1651.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1652.    
  1653.     return DllCall("gdiplus\GdipFillRegion", Ptr, pGraphics, Ptr, pBrush, Ptr, Region)
  1654. }
  1655.  
  1656. ;#####################################################################################
  1657.  
  1658. ; Function              Gdip_FillPath
  1659. ; Description           This function uses a brush to fill a path in the Graphics of a bitmap
  1660. ;
  1661. ; pGraphics             Pointer to the Graphics of a bitmap
  1662. ; pBrush                Pointer to a brush
  1663. ; Region                Pointer to a Path
  1664. ;
  1665. ; return                status enumeration. 0 = success
  1666.  
  1667. Gdip_FillPath(pGraphics, pBrush, Path)
  1668. {
  1669.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1670.    
  1671.     return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path)
  1672. }
  1673.  
  1674. ;#####################################################################################
  1675.  
  1676. ; Function              Gdip_DrawImagePointsRect
  1677. ; Description           This function draws a bitmap into the Graphics of another bitmap and skews it
  1678. ;
  1679. ; pGraphics             Pointer to the Graphics of a bitmap
  1680. ; pBitmap               Pointer to a bitmap to be drawn
  1681. ; Points                Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap
  1682. ; sx                    x-coordinate of source upper-left corner
  1683. ; sy                    y-coordinate of source upper-left corner
  1684. ; sw                    width of source rectangle
  1685. ; sh                    height of source rectangle
  1686. ; Matrix                a matrix used to alter image attributes when drawing
  1687. ;
  1688. ; return                status enumeration. 0 = success
  1689. ;
  1690. ; notes                 if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1691. ;                       Matrix can be omitted to just draw with no alteration to ARGB
  1692. ;                       Matrix may be passed as a digit from 0 - 1 to change just transparency
  1693. ;                       Matrix can be passed as a matrix with any delimiter
  1694.  
  1695. Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
  1696. {
  1697.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1698.    
  1699.     StringSplit, Points, Points, |
  1700.     VarSetCapacity(PointF, 8*Points0)  
  1701.     Loop, %Points0%
  1702.     {
  1703.         StringSplit, Coord, Points%A_Index%, `,
  1704.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1705.     }
  1706.  
  1707.     if (Matrix&1 = "")
  1708.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1709.     else if (Matrix != 1)
  1710.         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")
  1711.        
  1712.     if (sx = "" && sy = "" && sw = "" && sh = "")
  1713.     {
  1714.         sx := 0, sy := 0
  1715.         sw := Gdip_GetImageWidth(pBitmap)
  1716.         sh := Gdip_GetImageHeight(pBitmap)
  1717.     }
  1718.  
  1719.     E := DllCall("gdiplus\GdipDrawImagePointsRect"
  1720.                 , Ptr, pGraphics
  1721.                 , Ptr, pBitmap
  1722.                 , Ptr, &PointF
  1723.                 , "int", Points0
  1724.                 , "float", sx
  1725.                 , "float", sy
  1726.                 , "float", sw
  1727.                 , "float", sh
  1728.                 , "int", 2
  1729.                 , Ptr, ImageAttr
  1730.                 , Ptr, 0
  1731.                 , Ptr, 0)
  1732.     if ImageAttr
  1733.         Gdip_DisposeImageAttributes(ImageAttr)
  1734.     return E
  1735. }
  1736.  
  1737. ;#####################################################################################
  1738.  
  1739. ; Function              Gdip_DrawImage
  1740. ; Description           This function draws a bitmap into the Graphics of another bitmap
  1741. ;
  1742. ; pGraphics             Pointer to the Graphics of a bitmap
  1743. ; pBitmap               Pointer to a bitmap to be drawn
  1744. ; dx                    x-coord of destination upper-left corner
  1745. ; dy                    y-coord of destination upper-left corner
  1746. ; dw                    width of destination image
  1747. ; dh                    height of destination image
  1748. ; sx                    x-coordinate of source upper-left corner
  1749. ; sy                    y-coordinate of source upper-left corner
  1750. ; sw                    width of source image
  1751. ; sh                    height of source image
  1752. ; Matrix                a matrix used to alter image attributes when drawing
  1753. ;
  1754. ; return                status enumeration. 0 = success
  1755. ;
  1756. ; notes                 if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1757. ;                       Gdip_DrawImage performs faster
  1758. ;                       Matrix can be omitted to just draw with no alteration to ARGB
  1759. ;                       Matrix may be passed as a digit from 0 - 1 to change just transparency
  1760. ;                       Matrix can be passed as a matrix with any delimiter. For example:
  1761. ;                       MatrixBright=
  1762. ;                       (
  1763. ;                       1.5     |0      |0      |0      |0
  1764. ;                       0       |1.5    |0      |0      |0
  1765. ;                       0       |0      |1.5    |0      |0
  1766. ;                       0       |0      |0      |1      |0
  1767. ;                       0.05    |0.05   |0.05   |0      |1
  1768. ;                       )
  1769. ;
  1770. ; notes                 MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
  1771. ;                       MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
  1772. ;                       MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1
  1773.  
  1774. Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
  1775. {
  1776.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1777.    
  1778.     if (Matrix&1 = "")
  1779.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1780.     else if (Matrix != 1)
  1781.         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")
  1782.  
  1783.     if (sx = "" && sy = "" && sw = "" && sh = "")
  1784.     {
  1785.         if (dx = "" && dy = "" && dw = "" && dh = "")
  1786.         {
  1787.             sx := dx := 0, sy := dy := 0
  1788.             sw := dw := Gdip_GetImageWidth(pBitmap)
  1789.             sh := dh := Gdip_GetImageHeight(pBitmap)
  1790.         }
  1791.         else
  1792.         {
  1793.             sx := sy := 0
  1794.             sw := Gdip_GetImageWidth(pBitmap)
  1795.             sh := Gdip_GetImageHeight(pBitmap)
  1796.         }
  1797.     }
  1798.  
  1799.     E := DllCall("gdiplus\GdipDrawImageRectRect"
  1800.                 , Ptr, pGraphics
  1801.                 , Ptr, pBitmap
  1802.                 , "float", dx
  1803.                 , "float", dy
  1804.                 , "float", dw
  1805.                 , "float", dh
  1806.                 , "float", sx
  1807.                 , "float", sy
  1808.                 , "float", sw
  1809.                 , "float", sh
  1810.                 , "int", 2
  1811.                 , Ptr, ImageAttr
  1812.                 , Ptr, 0
  1813.                 , Ptr, 0)
  1814.     if ImageAttr
  1815.         Gdip_DisposeImageAttributes(ImageAttr)
  1816.     return E
  1817. }
  1818.  
  1819. ;#####################################################################################
  1820.  
  1821. ; Function              Gdip_SetImageAttributesColorMatrix
  1822. ; Description           This function creates an image matrix ready for drawing
  1823. ;
  1824. ; Matrix                a matrix used to alter image attributes when drawing
  1825. ;                       passed with any delimeter
  1826. ;
  1827. ; return                returns an image matrix on sucess or 0 if it fails
  1828. ;
  1829. ; notes                 MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
  1830. ;                       MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
  1831. ;                       MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1
  1832.  
  1833. Gdip_SetImageAttributesColorMatrix(Matrix)
  1834. {
  1835.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1836.    
  1837.     VarSetCapacity(ColourMatrix, 100, 0)
  1838.     Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
  1839.     StringSplit, Matrix, Matrix, |
  1840.     Loop, 25
  1841.     {
  1842.         Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
  1843.         NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
  1844.     }
  1845.     DllCall("gdiplus\GdipCreateImageAttributes", A_PtrSize ? "UPtr*" : "uint*", ImageAttr)
  1846.     DllCall("gdiplus\GdipSetImageAttributesColorMatrix", Ptr, ImageAttr, "int", 1, "int", 1, Ptr, &ColourMatrix, Ptr, 0, "int", 0)
  1847.     return ImageAttr
  1848. }
  1849.  
  1850. ;#####################################################################################
  1851.  
  1852. ; Function              Gdip_GraphicsFromImage
  1853. ; Description           This function gets the graphics for a bitmap used for drawing functions
  1854. ;
  1855. ; pBitmap               Pointer to a bitmap to get the pointer to its graphics
  1856. ;
  1857. ; return                returns a pointer to the graphics of a bitmap
  1858. ;
  1859. ; notes                 a bitmap can be drawn into the graphics of another bitmap
  1860.  
  1861. Gdip_GraphicsFromImage(pBitmap)
  1862. {
  1863.     DllCall("gdiplus\GdipGetImageGraphicsContext", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  1864.     return pGraphics
  1865. }
  1866.  
  1867. ;#####################################################################################
  1868.  
  1869. ; Function              Gdip_GraphicsFromHDC
  1870. ; Description           This function gets the graphics from the handle to a device context
  1871. ;
  1872. ; hdc                   This is the handle to the device context
  1873. ;
  1874. ; return                returns a pointer to the graphics of a bitmap
  1875. ;
  1876. ; notes                 You can draw a bitmap into the graphics of another bitmap
  1877.  
  1878. Gdip_GraphicsFromHDC(hdc)
  1879. {
  1880.     DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  1881.     return pGraphics
  1882. }
  1883.  
  1884. ;#####################################################################################
  1885.  
  1886. ; Function              Gdip_GetDC
  1887. ; Description           This function gets the device context of the passed Graphics
  1888. ;
  1889. ; hdc                   This is the handle to the device context
  1890. ;
  1891. ; return                returns the device context for the graphics of a bitmap
  1892.  
  1893. Gdip_GetDC(pGraphics)
  1894. {
  1895.     DllCall("gdiplus\GdipGetDC", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", hdc)
  1896.     return hdc
  1897. }
  1898.  
  1899. ;#####################################################################################
  1900.  
  1901. ; Function              Gdip_ReleaseDC
  1902. ; Description           This function releases a device context from use for further use
  1903. ;
  1904. ; pGraphics             Pointer to the graphics of a bitmap
  1905. ; hdc                   This is the handle to the device context
  1906. ;
  1907. ; return                status enumeration. 0 = success
  1908.  
  1909. Gdip_ReleaseDC(pGraphics, hdc)
  1910. {
  1911.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1912.    
  1913.     return DllCall("gdiplus\GdipReleaseDC", Ptr, pGraphics, Ptr, hdc)
  1914. }
  1915.  
  1916. ;#####################################################################################
  1917.  
  1918. ; Function              Gdip_GraphicsClear
  1919. ; Description           Clears the graphics of a bitmap ready for further drawing
  1920. ;
  1921. ; pGraphics             Pointer to the graphics of a bitmap
  1922. ; ARGB                  The colour to clear the graphics to
  1923. ;
  1924. ; return                status enumeration. 0 = success
  1925. ;
  1926. ; notes                 By default this will make the background invisible
  1927. ;                       Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics
  1928.  
  1929. Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
  1930. {
  1931.     return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB)
  1932. }
  1933.  
  1934. ;#####################################################################################
  1935.  
  1936. ; Function              Gdip_BlurBitmap
  1937. ; Description           Gives a pointer to a blurred bitmap from a pointer to a bitmap
  1938. ;
  1939. ; pBitmap               Pointer to a bitmap to be blurred
  1940. ; Blur                  The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur)
  1941. ;
  1942. ; return                If the function succeeds, the return value is a pointer to the new blurred bitmap
  1943. ;                       -1 = The blur parameter is outside the range 1-100
  1944. ;
  1945. ; notes                 This function will not dispose of the original bitmap
  1946.  
  1947. Gdip_BlurBitmap(pBitmap, Blur)
  1948. {
  1949.     if (Blur > 100) || (Blur < 1)
  1950.         return -1  
  1951.    
  1952.     sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
  1953.     dWidth := sWidth//Blur, dHeight := sHeight//Blur
  1954.  
  1955.     pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
  1956.     G1 := Gdip_GraphicsFromImage(pBitmap1)
  1957.     Gdip_SetInterpolationMode(G1, 7)
  1958.     Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
  1959.  
  1960.     Gdip_DeleteGraphics(G1)
  1961.  
  1962.     pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
  1963.     G2 := Gdip_GraphicsFromImage(pBitmap2)
  1964.     Gdip_SetInterpolationMode(G2, 7)
  1965.     Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
  1966.  
  1967.     Gdip_DeleteGraphics(G2)
  1968.     Gdip_DisposeImage(pBitmap1)
  1969.     return pBitmap2
  1970. }
  1971.  
  1972. ;#####################################################################################
  1973.  
  1974. ; Function:             Gdip_SaveBitmapToFile
  1975. ; Description:          Saves a bitmap to a file in any supported format onto disk
  1976. ;  
  1977. ; pBitmap               Pointer to a bitmap
  1978. ; sOutput               The name of the file that the bitmap will be saved to. Supported extensions are: .BMP,.DIB,.RLE,.JPG,.JPEG,.JPE,.JFIF,.GIF,.TIF,.TIFF,.PNG
  1979. ; Quality               If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality
  1980. ;
  1981. ; return                If the function succeeds, the return value is zero, otherwise:
  1982. ;                       -1 = Extension supplied is not a supported file format
  1983. ;                       -2 = Could not get a list of encoders on system
  1984. ;                       -3 = Could not find matching encoder for specified file format
  1985. ;                       -4 = Could not get WideChar name of output file
  1986. ;                       -5 = Could not save file to disk
  1987. ;
  1988. ; notes                 This function will use the extension supplied from the sOutput parameter to determine the output format
  1989.  
  1990. Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
  1991. {
  1992.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1993.    
  1994.     SplitPath, sOutput,,, Extension
  1995.     if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
  1996.         return -1
  1997.     Extension := "." Extension
  1998.  
  1999.     DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
  2000.     VarSetCapacity(ci, nSize)
  2001.     DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci)
  2002.     if !(nCount && nSize)
  2003.         return -2
  2004.    
  2005.     If (A_IsUnicode){
  2006.         StrGet_Name := "StrGet"
  2007.         Loop, %nCount%
  2008.         {
  2009.             sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16")
  2010.             if !InStr(sString, "*" Extension)
  2011.                 continue
  2012.            
  2013.             pCodec := &ci+idx
  2014.             break
  2015.         }
  2016.     } else {
  2017.         Loop, %nCount%
  2018.         {
  2019.             Location := NumGet(ci, 76*(A_Index-1)+44)
  2020.             nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int",  0, "uint", 0, "uint", 0)
  2021.             VarSetCapacity(sString, nSize)
  2022.             DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
  2023.             if !InStr(sString, "*" Extension)
  2024.                 continue
  2025.            
  2026.             pCodec := &ci+76*(A_Index-1)
  2027.             break
  2028.         }
  2029.     }
  2030.    
  2031.     if !pCodec
  2032.         return -3
  2033.  
  2034.     if (Quality != 75)
  2035.     {
  2036.         Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
  2037.         if Extension in .JPG,.JPEG,.JPE,.JFIF
  2038.         {
  2039.             DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize)
  2040.             VarSetCapacity(EncoderParameters, nSize, 0)
  2041.             DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters)
  2042.             Loop, % NumGet(EncoderParameters, "UInt")      ;%
  2043.             {
  2044.                 elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
  2045.                 if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6)
  2046.                 {
  2047.                     p := elem+&EncoderParameters-pad-4
  2048.                     NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt")
  2049.                     break
  2050.                 }
  2051.             }      
  2052.         }
  2053.     }
  2054.  
  2055.     if (!A_IsUnicode)
  2056.     {
  2057.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0)
  2058.         VarSetCapacity(wOutput, nSize*2)
  2059.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize)
  2060.         VarSetCapacity(wOutput, -1)
  2061.         if !VarSetCapacity(wOutput)
  2062.             return -4
  2063.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0)
  2064.     }
  2065.     else
  2066.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0)
  2067.     return E ? -5 : 0
  2068. }
  2069.  
  2070. ;#####################################################################################
  2071.  
  2072. ; Function              Gdip_GetPixel
  2073. ; Description           Gets the ARGB of a pixel in a bitmap
  2074. ;
  2075. ; pBitmap               Pointer to a bitmap
  2076. ; x                     x-coordinate of the pixel
  2077. ; y                     y-coordinate of the pixel
  2078. ;
  2079. ; return                Returns the ARGB value of the pixel
  2080.  
  2081. Gdip_GetPixel(pBitmap, x, y)
  2082. {
  2083.     DllCall("gdiplus\GdipBitmapGetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "uint*", ARGB)
  2084.     return ARGB
  2085. }
  2086.  
  2087. ;#####################################################################################
  2088.  
  2089. ; Function              Gdip_SetPixel
  2090. ; Description           Sets the ARGB of a pixel in a bitmap
  2091. ;
  2092. ; pBitmap               Pointer to a bitmap
  2093. ; x                     x-coordinate of the pixel
  2094. ; y                     y-coordinate of the pixel
  2095. ;
  2096. ; return                status enumeration. 0 = success
  2097.  
  2098. Gdip_SetPixel(pBitmap, x, y, ARGB)
  2099. {
  2100.    return DllCall("gdiplus\GdipBitmapSetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "int", ARGB)
  2101. }
  2102.  
  2103. ;#####################################################################################
  2104.  
  2105. ; Function              Gdip_GetImageWidth
  2106. ; Description           Gives the width of a bitmap
  2107. ;
  2108. ; pBitmap               Pointer to a bitmap
  2109. ;
  2110. ; return                Returns the width in pixels of the supplied bitmap
  2111.  
  2112. Gdip_GetImageWidth(pBitmap)
  2113. {
  2114.    DllCall("gdiplus\GdipGetImageWidth", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Width)
  2115.    return Width
  2116. }
  2117.  
  2118. ;#####################################################################################
  2119.  
  2120. ; Function              Gdip_GetImageHeight
  2121. ; Description           Gives the height of a bitmap
  2122. ;
  2123. ; pBitmap               Pointer to a bitmap
  2124. ;
  2125. ; return                Returns the height in pixels of the supplied bitmap
  2126.  
  2127. Gdip_GetImageHeight(pBitmap)
  2128. {
  2129.    DllCall("gdiplus\GdipGetImageHeight", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Height)
  2130.    return Height
  2131. }
  2132.  
  2133. ;#####################################################################################
  2134.  
  2135. ; Function              Gdip_GetDimensions
  2136. ; Description           Gives the width and height of a bitmap
  2137. ;
  2138. ; pBitmap               Pointer to a bitmap
  2139. ; Width                 ByRef variable. This variable will be set to the width of the bitmap
  2140. ; Height                ByRef variable. This variable will be set to the height of the bitmap
  2141. ;
  2142. ; return                No return value
  2143. ;                       Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  2144.  
  2145. Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height)
  2146. {
  2147.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2148.     DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, "uint*", Width)
  2149.     DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, "uint*", Height)
  2150. }
  2151.  
  2152. ;#####################################################################################
  2153.  
  2154. Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height)
  2155. {
  2156.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  2157. }
  2158.  
  2159. ;#####################################################################################
  2160.  
  2161. Gdip_GetImagePixelFormat(pBitmap)
  2162. {
  2163.     DllCall("gdiplus\GdipGetImagePixelFormat", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", Format)
  2164.     return Format
  2165. }
  2166.  
  2167. ;#####################################################################################
  2168.  
  2169. ; Function              Gdip_GetDpiX
  2170. ; Description           Gives the horizontal dots per inch of the graphics of a bitmap
  2171. ;
  2172. ; pBitmap               Pointer to a bitmap
  2173. ; Width                 ByRef variable. This variable will be set to the width of the bitmap
  2174. ; Height                ByRef variable. This variable will be set to the height of the bitmap
  2175. ;
  2176. ; return                No return value
  2177. ;                       Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  2178.  
  2179. Gdip_GetDpiX(pGraphics)
  2180. {
  2181.     DllCall("gdiplus\GdipGetDpiX", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpix)
  2182.     return Round(dpix)
  2183. }
  2184.  
  2185. ;#####################################################################################
  2186.  
  2187. Gdip_GetDpiY(pGraphics)
  2188. {
  2189.     DllCall("gdiplus\GdipGetDpiY", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpiy)
  2190.     return Round(dpiy)
  2191. }
  2192.  
  2193. ;#####################################################################################
  2194.  
  2195. Gdip_GetImageHorizontalResolution(pBitmap)
  2196. {
  2197.     DllCall("gdiplus\GdipGetImageHorizontalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpix)
  2198.     return Round(dpix)
  2199. }
  2200.  
  2201. ;#####################################################################################
  2202.  
  2203. Gdip_GetImageVerticalResolution(pBitmap)
  2204. {
  2205.     DllCall("gdiplus\GdipGetImageVerticalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpiy)
  2206.     return Round(dpiy)
  2207. }
  2208.  
  2209. ;#####################################################################################
  2210.  
  2211. Gdip_BitmapSetResolution(pBitmap, dpix, dpiy)
  2212. {
  2213.     return DllCall("gdiplus\GdipBitmapSetResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float", dpix, "float", dpiy)
  2214. }
  2215.  
  2216. ;#####################################################################################
  2217.  
  2218. Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
  2219. {
  2220.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2221.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  2222.    
  2223.     SplitPath, sFile,,, ext
  2224.     if ext in exe,dll
  2225.     {
  2226.         Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
  2227.         BufSize := 16 + (2*(A_PtrSize ? A_PtrSize : 4))
  2228.        
  2229.         VarSetCapacity(buf, BufSize, 0)
  2230.         Loop, Parse, Sizes, |
  2231.         {
  2232.             DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, PtrA, hIcon, PtrA, 0, "uint", 1, "uint", 0)
  2233.            
  2234.             if !hIcon
  2235.                 continue
  2236.  
  2237.             if !DllCall("GetIconInfo", Ptr, hIcon, Ptr, &buf)
  2238.             {
  2239.                 DestroyIcon(hIcon)
  2240.                 continue
  2241.             }
  2242.            
  2243.             hbmMask  := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4))
  2244.             hbmColor := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4) + (A_PtrSize ? A_PtrSize : 4))
  2245.             if !(hbmColor && DllCall("GetObject", Ptr, hbmColor, "int", BufSize, Ptr, &buf))
  2246.             {
  2247.                 DestroyIcon(hIcon)
  2248.                 continue
  2249.             }
  2250.             break
  2251.         }
  2252.         if !hIcon
  2253.             return -1
  2254.  
  2255.         Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int")
  2256.         hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  2257.         if !DllCall("DrawIconEx", Ptr, hdc, "int", 0, "int", 0, Ptr, hIcon, "uint", Width, "uint", Height, "uint", 0, Ptr, 0, "uint", 3)
  2258.         {
  2259.             DestroyIcon(hIcon)
  2260.             return -2
  2261.         }
  2262.        
  2263.         VarSetCapacity(dib, 104)
  2264.         DllCall("GetObject", Ptr, hbm, "int", A_PtrSize = 8 ? 104 : 84, Ptr, &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize
  2265.         Stride := NumGet(dib, 12, "Int"), Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0)) ; padding
  2266.         DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, Ptr, Bits, PtrA, pBitmapOld)
  2267.         pBitmap := Gdip_CreateBitmap(Width, Height)
  2268.         G := Gdip_GraphicsFromImage(pBitmap)
  2269.         , Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
  2270.         SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  2271.         Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld)
  2272.         DestroyIcon(hIcon)
  2273.     }
  2274.     else
  2275.     {
  2276.         if (!A_IsUnicode)
  2277.         {
  2278.             VarSetCapacity(wFile, 1024)
  2279.             DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sFile, "int", -1, Ptr, &wFile, "int", 512)
  2280.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &wFile, PtrA, pBitmap)
  2281.         }
  2282.         else
  2283.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &sFile, PtrA, pBitmap)
  2284.     }
  2285.    
  2286.     return pBitmap
  2287. }
  2288.  
  2289. ;#####################################################################################
  2290.  
  2291. Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
  2292. {
  2293.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2294.    
  2295.     DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  2296.     return pBitmap
  2297. }
  2298.  
  2299. ;#####################################################################################
  2300.  
  2301. Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
  2302. {
  2303.     DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hbm, "int", Background)
  2304.     return hbm
  2305. }
  2306.  
  2307. ;#####################################################################################
  2308.  
  2309. Gdip_CreateBitmapFromHICON(hIcon)
  2310. {
  2311.     DllCall("gdiplus\GdipCreateBitmapFromHICON", A_PtrSize ? "UPtr" : "UInt", hIcon, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  2312.     return pBitmap
  2313. }
  2314.  
  2315. ;#####################################################################################
  2316.  
  2317. Gdip_CreateHICONFromBitmap(pBitmap)
  2318. {
  2319.     DllCall("gdiplus\GdipCreateHICONFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hIcon)
  2320.     return hIcon
  2321. }
  2322.  
  2323. ;#####################################################################################
  2324.  
  2325. Gdip_CreateBitmap(Width, Height, Format=0x26200A)
  2326. {
  2327.     DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  2328.     Return pBitmap
  2329. }
  2330.  
  2331. ;#####################################################################################
  2332.  
  2333. Gdip_CreateBitmapFromClipboard()
  2334. {
  2335.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2336.    
  2337.     if !DllCall("OpenClipboard", Ptr, 0)
  2338.         return -1
  2339.     if !DllCall("IsClipboardFormatAvailable", "uint", 8)
  2340.         return -2
  2341.     if !hBitmap := DllCall("GetClipboardData", "uint", 2, Ptr)
  2342.         return -3
  2343.     if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
  2344.         return -4
  2345.     if !DllCall("CloseClipboard")
  2346.         return -5
  2347.     DeleteObject(hBitmap)
  2348.     return pBitmap
  2349. }
  2350.  
  2351. ;#####################################################################################
  2352.  
  2353. Gdip_SetBitmapToClipboard(pBitmap)
  2354. {
  2355.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2356.     off1 := A_PtrSize = 8 ? 52 : 44, off2 := A_PtrSize = 8 ? 32 : 24
  2357.     hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  2358.     DllCall("GetObject", Ptr, hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 104 : 84, 0), Ptr, &oi)
  2359.     hdib := DllCall("GlobalAlloc", "uint", 2, Ptr, 40+NumGet(oi, off1, "UInt"), Ptr)
  2360.     pdib := DllCall("GlobalLock", Ptr, hdib, Ptr)
  2361.     DllCall("RtlMoveMemory", Ptr, pdib, Ptr, &oi+off2, Ptr, 40)
  2362.     DllCall("RtlMoveMemory", Ptr, pdib+40, Ptr, NumGet(oi, off2 - (A_PtrSize ? A_PtrSize : 4), Ptr), Ptr, NumGet(oi, off1, "UInt"))
  2363.     DllCall("GlobalUnlock", Ptr, hdib)
  2364.     DllCall("DeleteObject", Ptr, hBitmap)
  2365.     DllCall("OpenClipboard", Ptr, 0)
  2366.     DllCall("EmptyClipboard")
  2367.     DllCall("SetClipboardData", "uint", 8, Ptr, hdib)
  2368.     DllCall("CloseClipboard")
  2369. }
  2370.  
  2371. ;#####################################################################################
  2372.  
  2373. Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
  2374. {
  2375.     DllCall("gdiplus\GdipCloneBitmapArea"
  2376.                     , "float", x
  2377.                     , "float", y
  2378.                     , "float", w
  2379.                     , "float", h
  2380.                     , "int", Format
  2381.                     , A_PtrSize ? "UPtr" : "UInt", pBitmap
  2382.                     , A_PtrSize ? "UPtr*" : "UInt*", pBitmapDest)
  2383.     return pBitmapDest
  2384. }
  2385.  
  2386. ;#####################################################################################
  2387. ; Create resources
  2388. ;#####################################################################################
  2389.  
  2390. Gdip_CreatePen(ARGB, w)
  2391. {
  2392.    DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  2393.    return pPen
  2394. }
  2395.  
  2396. ;#####################################################################################
  2397.  
  2398. Gdip_CreatePenFromBrush(pBrush, w)
  2399. {
  2400.     DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  2401.     return pPen
  2402. }
  2403.  
  2404. ;#####################################################################################
  2405.  
  2406. Gdip_BrushCreateSolid(ARGB=0xff000000)
  2407. {
  2408.     DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  2409.     return pBrush
  2410. }
  2411.  
  2412. ;#####################################################################################
  2413.  
  2414. ; HatchStyleHorizontal = 0
  2415. ; HatchStyleVertical = 1
  2416. ; HatchStyleForwardDiagonal = 2
  2417. ; HatchStyleBackwardDiagonal = 3
  2418. ; HatchStyleCross = 4
  2419. ; HatchStyleDiagonalCross = 5
  2420. ; HatchStyle05Percent = 6
  2421. ; HatchStyle10Percent = 7
  2422. ; HatchStyle20Percent = 8
  2423. ; HatchStyle25Percent = 9
  2424. ; HatchStyle30Percent = 10
  2425. ; HatchStyle40Percent = 11
  2426. ; HatchStyle50Percent = 12
  2427. ; HatchStyle60Percent = 13
  2428. ; HatchStyle70Percent = 14
  2429. ; HatchStyle75Percent = 15
  2430. ; HatchStyle80Percent = 16
  2431. ; HatchStyle90Percent = 17
  2432. ; HatchStyleLightDownwardDiagonal = 18
  2433. ; HatchStyleLightUpwardDiagonal = 19
  2434. ; HatchStyleDarkDownwardDiagonal = 20
  2435. ; HatchStyleDarkUpwardDiagonal = 21
  2436. ; HatchStyleWideDownwardDiagonal = 22
  2437. ; HatchStyleWideUpwardDiagonal = 23
  2438. ; HatchStyleLightVertical = 24
  2439. ; HatchStyleLightHorizontal = 25
  2440. ; HatchStyleNarrowVertical = 26
  2441. ; HatchStyleNarrowHorizontal = 27
  2442. ; HatchStyleDarkVertical = 28
  2443. ; HatchStyleDarkHorizontal = 29
  2444. ; HatchStyleDashedDownwardDiagonal = 30
  2445. ; HatchStyleDashedUpwardDiagonal = 31
  2446. ; HatchStyleDashedHorizontal = 32
  2447. ; HatchStyleDashedVertical = 33
  2448. ; HatchStyleSmallConfetti = 34
  2449. ; HatchStyleLargeConfetti = 35
  2450. ; HatchStyleZigZag = 36
  2451. ; HatchStyleWave = 37
  2452. ; HatchStyleDiagonalBrick = 38
  2453. ; HatchStyleHorizontalBrick = 39
  2454. ; HatchStyleWeave = 40
  2455. ; HatchStylePlaid = 41
  2456. ; HatchStyleDivot = 42
  2457. ; HatchStyleDottedGrid = 43
  2458. ; HatchStyleDottedDiamond = 44
  2459. ; HatchStyleShingle = 45
  2460. ; HatchStyleTrellis = 46
  2461. ; HatchStyleSphere = 47
  2462. ; HatchStyleSmallGrid = 48
  2463. ; HatchStyleSmallCheckerBoard = 49
  2464. ; HatchStyleLargeCheckerBoard = 50
  2465. ; HatchStyleOutlinedDiamond = 51
  2466. ; HatchStyleSolidDiamond = 52
  2467. ; HatchStyleTotal = 53
  2468. Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
  2469. {
  2470.     DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  2471.     return pBrush
  2472. }
  2473.  
  2474. ;#####################################################################################
  2475.  
  2476. Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
  2477. {
  2478.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2479.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  2480.    
  2481.     if !(w && h)
  2482.         DllCall("gdiplus\GdipCreateTexture", Ptr, pBitmap, "int", WrapMode, PtrA, pBrush)
  2483.     else
  2484.         DllCall("gdiplus\GdipCreateTexture2", Ptr, pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, PtrA, pBrush)
  2485.     return pBrush
  2486. }
  2487.  
  2488. ;#####################################################################################
  2489.  
  2490. ; WrapModeTile = 0
  2491. ; WrapModeTileFlipX = 1
  2492. ; WrapModeTileFlipY = 2
  2493. ; WrapModeTileFlipXY = 3
  2494. ; WrapModeClamp = 4
  2495. Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
  2496. {
  2497.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2498.    
  2499.     CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2)
  2500.     DllCall("gdiplus\GdipCreateLineBrush", Ptr, &PointF1, Ptr, &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  2501.     return LGpBrush
  2502. }
  2503.  
  2504. ;#####################################################################################
  2505.  
  2506. ; LinearGradientModeHorizontal = 0
  2507. ; LinearGradientModeVertical = 1
  2508. ; LinearGradientModeForwardDiagonal = 2
  2509. ; LinearGradientModeBackwardDiagonal = 3
  2510. Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
  2511. {
  2512.     CreateRectF(RectF, x, y, w, h)
  2513.     DllCall("gdiplus\GdipCreateLineBrushFromRect", A_PtrSize ? "UPtr" : "UInt", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  2514.     return LGpBrush
  2515. }
  2516.  
  2517. ;#####################################################################################
  2518.  
  2519. Gdip_CloneBrush(pBrush)
  2520. {
  2521.     DllCall("gdiplus\GdipCloneBrush", A_PtrSize ? "UPtr" : "UInt", pBrush, A_PtrSize ? "UPtr*" : "UInt*", pBrushClone)
  2522.     return pBrushClone
  2523. }
  2524.  
  2525. ;#####################################################################################
  2526. ; Delete resources
  2527. ;#####################################################################################
  2528.  
  2529. Gdip_DeletePen(pPen)
  2530. {
  2531.    return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen)
  2532. }
  2533.  
  2534. ;#####################################################################################
  2535.  
  2536. Gdip_DeleteBrush(pBrush)
  2537. {
  2538.    return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush)
  2539. }
  2540.  
  2541. ;#####################################################################################
  2542.  
  2543. Gdip_DisposeImage(pBitmap)
  2544. {
  2545.    return DllCall("gdiplus\GdipDisposeImage", A_PtrSize ? "UPtr" : "UInt", pBitmap)
  2546. }
  2547.  
  2548. ;#####################################################################################
  2549.  
  2550. Gdip_DeleteGraphics(pGraphics)
  2551. {
  2552.    return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2553. }
  2554.  
  2555. ;#####################################################################################
  2556.  
  2557. Gdip_DisposeImageAttributes(ImageAttr)
  2558. {
  2559.     return DllCall("gdiplus\GdipDisposeImageAttributes", A_PtrSize ? "UPtr" : "UInt", ImageAttr)
  2560. }
  2561.  
  2562. ;#####################################################################################
  2563.  
  2564. Gdip_DeleteFont(hFont)
  2565. {
  2566.    return DllCall("gdiplus\GdipDeleteFont", A_PtrSize ? "UPtr" : "UInt", hFont)
  2567. }
  2568.  
  2569. ;#####################################################################################
  2570.  
  2571. Gdip_DeleteStringFormat(hFormat)
  2572. {
  2573.    return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat)
  2574. }
  2575.  
  2576. ;#####################################################################################
  2577.  
  2578. Gdip_DeleteFontFamily(hFamily)
  2579. {
  2580.    return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily)
  2581. }
  2582.  
  2583. ;#####################################################################################
  2584.  
  2585. Gdip_DeleteMatrix(Matrix)
  2586. {
  2587.    return DllCall("gdiplus\GdipDeleteMatrix", A_PtrSize ? "UPtr" : "UInt", Matrix)
  2588. }
  2589.  
  2590. ;#####################################################################################
  2591. ; Text functions
  2592. ;#####################################################################################
  2593.  
  2594. Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
  2595. {
  2596.     IWidth := Width, IHeight:= Height
  2597.    
  2598.     RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
  2599.     RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
  2600.     RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
  2601.     RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
  2602.     RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour)
  2603.     RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
  2604.     RegExMatch(Options, "i)NoWrap", NoWrap)
  2605.     RegExMatch(Options, "i)R(\d)", Rendering)
  2606.     RegExMatch(Options, "i)S(\d+)(p*)", Size)
  2607.  
  2608.     if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
  2609.         PassBrush := 1, pBrush := Colour2
  2610.    
  2611.     if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
  2612.         return -1
  2613.  
  2614.     Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
  2615.     Loop, Parse, Styles, |
  2616.     {
  2617.         if RegExMatch(Options, "\b" A_loopField)
  2618.         Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
  2619.     }
  2620.  
  2621.     Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
  2622.     Loop, Parse, Alignments, |
  2623.     {
  2624.         if RegExMatch(Options, "\b" A_loopField)
  2625.             Align |= A_Index//2.1      ; 0|0|1|1|2|2
  2626.     }
  2627.  
  2628.     xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
  2629.     ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
  2630.     Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
  2631.     Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
  2632.     if !PassBrush
  2633.         Colour := "0x" (Colour2 ? Colour2 : "ff000000")
  2634.     Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
  2635.     Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
  2636.  
  2637.     hFamily := Gdip_FontFamilyCreate(Font)
  2638.     hFont := Gdip_FontCreate(hFamily, Size, Style)
  2639.     FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
  2640.     hFormat := Gdip_StringFormatCreate(FormatStyle)
  2641.     pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
  2642.     if !(hFamily && hFont && hFormat && pBrush && pGraphics)
  2643.         return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
  2644.    
  2645.     CreateRectF(RC, xpos, ypos, Width, Height)
  2646.     Gdip_SetStringFormatAlign(hFormat, Align)
  2647.     Gdip_SetTextRenderingHint(pGraphics, Rendering)
  2648.     ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2649.  
  2650.     if vPos
  2651.     {
  2652.         StringSplit, ReturnRC, ReturnRC, |
  2653.        
  2654.         if (vPos = "vCentre") || (vPos = "vCenter")
  2655.             ypos += (Height-ReturnRC4)//2
  2656.         else if (vPos = "Top") || (vPos = "Up")
  2657.             ypos := 0
  2658.         else if (vPos = "Bottom") || (vPos = "Down")
  2659.             ypos := Height-ReturnRC4
  2660.        
  2661.         CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
  2662.         ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2663.     }
  2664.  
  2665.     if !Measure
  2666.         E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
  2667.  
  2668.     if !PassBrush
  2669.         Gdip_DeleteBrush(pBrush)
  2670.     Gdip_DeleteStringFormat(hFormat)  
  2671.     Gdip_DeleteFont(hFont)
  2672.     Gdip_DeleteFontFamily(hFamily)
  2673.     return E ? E : ReturnRC
  2674. }
  2675.  
  2676. ;#####################################################################################
  2677.  
  2678. Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
  2679. {
  2680.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2681.    
  2682.     if (!A_IsUnicode)
  2683.     {
  2684.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0)
  2685.         VarSetCapacity(wString, nSize*2)
  2686.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  2687.     }
  2688.    
  2689.     return DllCall("gdiplus\GdipDrawString"
  2690.                     , Ptr, pGraphics
  2691.                     , Ptr, A_IsUnicode ? &sString : &wString
  2692.                     , "int", -1
  2693.                     , Ptr, hFont
  2694.                     , Ptr, &RectF
  2695.                     , Ptr, hFormat
  2696.                     , Ptr, pBrush)
  2697. }
  2698.  
  2699. ;#####################################################################################
  2700.  
  2701. Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
  2702. {
  2703.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2704.    
  2705.     VarSetCapacity(RC, 16)
  2706.     if !A_IsUnicode
  2707.     {
  2708.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, "uint", 0, "int", 0)
  2709.         VarSetCapacity(wString, nSize*2)  
  2710.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  2711.     }
  2712.    
  2713.     DllCall("gdiplus\GdipMeasureString"
  2714.                     , Ptr, pGraphics
  2715.                     , Ptr, A_IsUnicode ? &sString : &wString
  2716.                     , "int", -1
  2717.                     , Ptr, hFont
  2718.                     , Ptr, &RectF
  2719.                     , Ptr, hFormat
  2720.                     , Ptr, &RC
  2721.                     , "uint*", Chars
  2722.                     , "uint*", Lines)
  2723.    
  2724.     return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
  2725. }
  2726.  
  2727. ; Near = 0
  2728. ; Center = 1
  2729. ; Far = 2
  2730. Gdip_SetStringFormatAlign(hFormat, Align)
  2731. {
  2732.    return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align)
  2733. }
  2734.  
  2735. ; StringFormatFlagsDirectionRightToLeft    = 0x00000001
  2736. ; StringFormatFlagsDirectionVertical       = 0x00000002
  2737. ; StringFormatFlagsNoFitBlackBox           = 0x00000004
  2738. ; StringFormatFlagsDisplayFormatControl    = 0x00000020
  2739. ; StringFormatFlagsNoFontFallback          = 0x00000400
  2740. ; StringFormatFlagsMeasureTrailingSpaces   = 0x00000800
  2741. ; StringFormatFlagsNoWrap                  = 0x00001000
  2742. ; StringFormatFlagsLineLimit               = 0x00002000
  2743. ; StringFormatFlagsNoClip                  = 0x00004000
  2744. Gdip_StringFormatCreate(Format=0, Lang=0)
  2745. {
  2746.    DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat)
  2747.    return hFormat
  2748. }
  2749.  
  2750. ; Regular = 0
  2751. ; Bold = 1
  2752. ; Italic = 2
  2753. ; BoldItalic = 3
  2754. ; Underline = 4
  2755. ; Strikeout = 8
  2756. Gdip_FontCreate(hFamily, Size, Style=0)
  2757. {
  2758.    DllCall("gdiplus\GdipCreateFont", A_PtrSize ? "UPtr" : "UInt", hFamily, "float", Size, "int", Style, "int", 0, A_PtrSize ? "UPtr*" : "UInt*", hFont)
  2759.    return hFont
  2760. }
  2761.  
  2762. Gdip_FontFamilyCreate(Font)
  2763. {
  2764.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2765.    
  2766.     if (!A_IsUnicode)
  2767.     {
  2768.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0)
  2769.         VarSetCapacity(wFont, nSize*2)
  2770.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize)
  2771.     }
  2772.    
  2773.     DllCall("gdiplus\GdipCreateFontFamilyFromName"
  2774.                     , Ptr, A_IsUnicode ? &Font : &wFont
  2775.                     , "uint", 0
  2776.                     , A_PtrSize ? "UPtr*" : "UInt*", hFamily)
  2777.    
  2778.     return hFamily
  2779. }
  2780.  
  2781. ;#####################################################################################
  2782. ; Matrix functions
  2783. ;#####################################################################################
  2784.  
  2785. Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
  2786. {
  2787.    DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  2788.    return Matrix
  2789. }
  2790.  
  2791. Gdip_CreateMatrix()
  2792. {
  2793.    DllCall("gdiplus\GdipCreateMatrix", A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  2794.    return Matrix
  2795. }
  2796.  
  2797. ;#####################################################################################
  2798. ; GraphicsPath functions
  2799. ;#####################################################################################
  2800.  
  2801. ; Alternate = 0
  2802. ; Winding = 1
  2803. Gdip_CreatePath(BrushMode=0)
  2804. {
  2805.     DllCall("gdiplus\GdipCreatePath", "int", BrushMode, A_PtrSize ? "UPtr*" : "UInt*", Path)
  2806.     return Path
  2807. }
  2808.  
  2809. Gdip_AddPathEllipse(Path, x, y, w, h)
  2810. {
  2811.     return DllCall("gdiplus\GdipAddPathEllipse", A_PtrSize ? "UPtr" : "UInt", Path, "float", x, "float", y, "float", w, "float", h)
  2812. }
  2813.  
  2814. Gdip_AddPathPolygon(Path, Points)
  2815. {
  2816.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2817.    
  2818.     StringSplit, Points, Points, |
  2819.     VarSetCapacity(PointF, 8*Points0)  
  2820.     Loop, %Points0%
  2821.     {
  2822.         StringSplit, Coord, Points%A_Index%, `,
  2823.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  2824.     }  
  2825.  
  2826.     return DllCall("gdiplus\GdipAddPathPolygon", Ptr, Path, Ptr, &PointF, "int", Points0)
  2827. }
  2828.  
  2829. Gdip_DeletePath(Path)
  2830. {
  2831.     return DllCall("gdiplus\GdipDeletePath", A_PtrSize ? "UPtr" : "UInt", Path)
  2832. }
  2833.  
  2834. ;#####################################################################################
  2835. ; Quality functions
  2836. ;#####################################################################################
  2837.  
  2838. ; SystemDefault = 0
  2839. ; SingleBitPerPixelGridFit = 1
  2840. ; SingleBitPerPixel = 2
  2841. ; AntiAliasGridFit = 3
  2842. ; AntiAlias = 4
  2843. Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
  2844. {
  2845.     return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint)
  2846. }
  2847.  
  2848. ; Default = 0
  2849. ; LowQuality = 1
  2850. ; HighQuality = 2
  2851. ; Bilinear = 3
  2852. ; Bicubic = 4
  2853. ; NearestNeighbor = 5
  2854. ; HighQualityBilinear = 6
  2855. ; HighQualityBicubic = 7
  2856. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  2857. {
  2858.    return DllCall("gdiplus\GdipSetInterpolationMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", InterpolationMode)
  2859. }
  2860.  
  2861. ; Default = 0
  2862. ; HighSpeed = 1
  2863. ; HighQuality = 2
  2864. ; None = 3
  2865. ; AntiAlias = 4
  2866. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  2867. {
  2868.    return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode)
  2869. }
  2870.  
  2871. ; CompositingModeSourceOver = 0 (blended)
  2872. ; CompositingModeSourceCopy = 1 (overwrite)
  2873. Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
  2874. {
  2875.    return DllCall("gdiplus\GdipSetCompositingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", CompositingMode)
  2876. }
  2877.  
  2878. ;#####################################################################################
  2879. ; Extra functions
  2880. ;#####################################################################################
  2881.  
  2882. Gdip_Startup()
  2883. {
  2884.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2885.    
  2886.     if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  2887.         DllCall("LoadLibrary", "str", "gdiplus")
  2888.     VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
  2889.     DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
  2890.     return pToken
  2891. }
  2892.  
  2893. Gdip_Shutdown(pToken)
  2894. {
  2895.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2896.    
  2897.     DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
  2898.     if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  2899.         DllCall("FreeLibrary", Ptr, hModule)
  2900.     return 0
  2901. }
  2902.  
  2903. ; Prepend = 0; The new operation is applied before the old operation.
  2904. ; Append = 1; The new operation is applied after the old operation.
  2905. Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
  2906. {
  2907.     return DllCall("gdiplus\GdipRotateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", Angle, "int", MatrixOrder)
  2908. }
  2909.  
  2910. Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2911. {
  2912.     return DllCall("gdiplus\GdipScaleWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2913. }
  2914.  
  2915. Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2916. {
  2917.     return DllCall("gdiplus\GdipTranslateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2918. }
  2919.  
  2920. Gdip_ResetWorldTransform(pGraphics)
  2921. {
  2922.     return DllCall("gdiplus\GdipResetWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2923. }
  2924.  
  2925. Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
  2926. {
  2927.     pi := 3.14159, TAngle := Angle*(pi/180)
  2928.  
  2929.     Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
  2930.     if ((Bound >= 0) && (Bound <= 90))
  2931.         xTranslation := Height*Sin(TAngle), yTranslation := 0
  2932.     else if ((Bound > 90) && (Bound <= 180))
  2933.         xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
  2934.     else if ((Bound > 180) && (Bound <= 270))
  2935.         xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
  2936.     else if ((Bound > 270) && (Bound <= 360))
  2937.         xTranslation := 0, yTranslation := -Width*Sin(TAngle)
  2938. }
  2939.  
  2940. Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
  2941. {
  2942.     pi := 3.14159, TAngle := Angle*(pi/180)
  2943.     if !(Width && Height)
  2944.         return -1
  2945.     RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
  2946.     RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
  2947. }
  2948.  
  2949. ; RotateNoneFlipNone   = 0
  2950. ; Rotate90FlipNone     = 1
  2951. ; Rotate180FlipNone    = 2
  2952. ; Rotate270FlipNone    = 3
  2953. ; RotateNoneFlipX      = 4
  2954. ; Rotate90FlipX        = 5
  2955. ; Rotate180FlipX       = 6
  2956. ; Rotate270FlipX       = 7
  2957. ; RotateNoneFlipY      = Rotate180FlipX
  2958. ; Rotate90FlipY        = Rotate270FlipX
  2959. ; Rotate180FlipY       = RotateNoneFlipX
  2960. ; Rotate270FlipY       = Rotate90FlipX
  2961. ; RotateNoneFlipXY     = Rotate180FlipNone
  2962. ; Rotate90FlipXY       = Rotate270FlipNone
  2963. ; Rotate180FlipXY      = RotateNoneFlipNone
  2964. ; Rotate270FlipXY      = Rotate90FlipNone
  2965.  
  2966. Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1)
  2967. {
  2968.     return DllCall("gdiplus\GdipImageRotateFlip", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", RotateFlipType)
  2969. }
  2970.  
  2971. ; Replace = 0
  2972. ; Intersect = 1
  2973. ; Union = 2
  2974. ; Xor = 3
  2975. ; Exclude = 4
  2976. ; Complement = 5
  2977. Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
  2978. {
  2979.    return DllCall("gdiplus\GdipSetClipRect",  A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
  2980. }
  2981.  
  2982. Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
  2983. {
  2984.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2985.     return DllCall("gdiplus\GdipSetClipPath", Ptr, pGraphics, Ptr, Path, "int", CombineMode)
  2986. }
  2987.  
  2988. Gdip_ResetClip(pGraphics)
  2989. {
  2990.    return DllCall("gdiplus\GdipResetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2991. }
  2992.  
  2993. Gdip_GetClipRegion(pGraphics)
  2994. {
  2995.     Region := Gdip_CreateRegion()
  2996.     DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt*", Region)
  2997.     return Region
  2998. }
  2999.  
  3000. Gdip_SetClipRegion(pGraphics, Region, CombineMode=0)
  3001. {
  3002.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3003.    
  3004.     return DllCall("gdiplus\GdipSetClipRegion", Ptr, pGraphics, Ptr, Region, "int", CombineMode)
  3005. }
  3006.  
  3007. Gdip_CreateRegion()
  3008. {
  3009.     DllCall("gdiplus\GdipCreateRegion", "UInt*", Region)
  3010.     return Region
  3011. }
  3012.  
  3013. Gdip_DeleteRegion(Region)
  3014. {
  3015.     return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region)
  3016. }
  3017.  
  3018. ;#####################################################################################
  3019. ; BitmapLockBits
  3020. ;#####################################################################################
  3021.  
  3022. Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a)
  3023. {
  3024.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3025.    
  3026.     CreateRect(Rect, x, y, w, h)
  3027.     VarSetCapacity(BitmapData, 16+2*(A_PtrSize ? A_PtrSize : 4), 0)
  3028.     E := DllCall("Gdiplus\GdipBitmapLockBits", Ptr, pBitmap, Ptr, &Rect, "uint", LockMode, "int", PixelFormat, Ptr, &BitmapData)
  3029.     Stride := NumGet(BitmapData, 8, "Int")
  3030.     Scan0 := NumGet(BitmapData, 16, Ptr)
  3031.     return E
  3032. }
  3033.  
  3034. ;#####################################################################################
  3035.  
  3036. Gdip_UnlockBits(pBitmap, ByRef BitmapData)
  3037. {
  3038.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3039.    
  3040.     return DllCall("Gdiplus\GdipBitmapUnlockBits", Ptr, pBitmap, Ptr, &BitmapData)
  3041. }
  3042.  
  3043. ;#####################################################################################
  3044.  
  3045. Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride)
  3046. {
  3047.     Numput(ARGB, Scan0+0, (x*4)+(y*Stride), "UInt")
  3048. }
  3049.  
  3050. ;#####################################################################################
  3051.  
  3052. Gdip_GetLockBitPixel(Scan0, x, y, Stride)
  3053. {
  3054.     return NumGet(Scan0+0, (x*4)+(y*Stride), "UInt")
  3055. }
  3056.  
  3057. ;#####################################################################################
  3058.  
  3059. Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize)
  3060. {
  3061.     static PixelateBitmap
  3062.    
  3063.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3064.    
  3065.     if (!PixelateBitmap)
  3066.     {
  3067.         if A_PtrSize != 8 ; x86 machine code
  3068.         MCode_PixelateBitmap =
  3069.         (LTrim Join
  3070.         558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC894DD885C90F8E830200008B451099F7FB8365DC008365E000894DC88955F08945E833FF897DD4
  3071.         397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945FC89451C8945143BD87E608B45088D50028BC82BCA8BF02BF2418945F48B45E02955F4894DC4
  3072.         8D0CB80FAFCB03CA895DD08BD1895DE40FB64416030145140FB60201451C8B45C40FB604100145FC8B45F40FB604020145F883C204FF4DE475D6034D18FF
  3073.         4DD075C98B4DCC8B451499F7F98945148B451C99F7F989451C8B45FC99F7F98945FC8B45F899F7F98945F885DB7E648B450C8D50028BC82BCA83C103894D
  3074.         C48BC82BCA41894DF48B4DD48945E48B45E02955E48D0C880FAFCB03CA895DD08BD18BF38A45148B7DC48804178A451C8B7DF488028A45FC8804178A45F8
  3075.         8B7DE488043A83C2044E75DA034D18FF4DD075CE8B4DCC8B7DD447897DD43B7DE80F8CF2FEFFFF837DF0000F842C01000033C08945F88945FC89451C8945
  3076.         148945E43BD87E65837DF0007E578B4DDC034DE48B75E80FAF4D180FAFF38B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945CC0F
  3077.         B6440E030145140FB60101451C0FB6440F010145FC8B45F40FB604010145F883C104FF4DCC75D8FF45E4395DE47C9B8B4DF00FAFCB85C9740B8B451499F7
  3078.         F9894514EB048365140033F63BCE740B8B451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB
  3079.         038975F88975E43BDE7E5A837DF0007E4C8B4DDC034DE48B75E80FAF4D180FAFF38B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955CC8A55
  3080.         1488540E038A551C88118A55FC88540F018A55F888140183C104FF4DCC75DFFF45E4395DE47CA68B45180145E0015DDCFF4DC80F8594FDFFFF8B451099F7
  3081.         FB8955F08945E885C00F8E450100008B45EC0FAFC38365DC008945D48B45E88945CC33C08945F88945FC89451C8945148945103945EC7E6085DB7E518B4D
  3082.         D88B45080FAFCB034D108D50020FAF4D18034DDC8BF08BF88945F403CA2BF22BFA2955F4895DC80FB6440E030145140FB60101451C0FB6440F010145FC8B
  3083.         45F40FB604080145F883C104FF4DC875D8FF45108B45103B45EC7CA08B4DD485C9740B8B451499F7F9894514EB048365140033F63BCE740B8B451C99F7F9
  3084.         89451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975103975EC7E5585DB7E468B4DD88B450C
  3085.         0FAFCB034D108D50020FAF4D18034DDC8BF08BF803CA2BF22BFA2BC2895DC88A551488540E038A551C88118A55FC88540F018A55F888140183C104FF4DC8
  3086.         75DFFF45108B45103B45EC7CAB8BC3C1E0020145DCFF4DCC0F85CEFEFFFF8B4DEC33C08945F88945FC89451C8945148945103BC87E6C3945F07E5C8B4DD8
  3087.         8B75E80FAFCB034D100FAFF30FAF4D188B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945C80FB6440E030145140FB60101451C0F
  3088.         B6440F010145FC8B45F40FB604010145F883C104FF4DC875D833C0FF45108B4DEC394D107C940FAF4DF03BC874068B451499F7F933F68945143BCE740B8B
  3089.         451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975083975EC7E63EB0233F639
  3090.         75F07E4F8B4DD88B75E80FAFCB034D080FAFF30FAF4D188B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955108A551488540E038A551C8811
  3091.         8A55FC88540F018A55F888140883C104FF4D1075DFFF45088B45083B45EC7C9F5F5E33C05BC9C21800
  3092.         )
  3093.         else ; x64 machine code
  3094.         MCode_PixelateBitmap =
  3095.         (LTrim Join
  3096.         4489442418488954241048894C24085355565741544155415641574883EC28418BC1448B8C24980000004C8BDA99488BD941F7F9448BD0448BFA8954240C
  3097.         448994248800000085C00F8E9D020000418BC04533E4458BF299448924244C8954241041F7F933C9898C24980000008BEA89542404448BE889442408EB05
  3098.         4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C2418450FAFF14533D233F633ED4533E44533ED4585C97E5B4C63BC2490000000418D040A410FAF
  3099.         C148984C8D441802498BD9498BD04D8BD90FB642010FB64AFF4403E80FB60203E90FB64AFE4883C2044403E003F149FFCB75DE4D03C748FFCB75D0488B7C
  3100.         24188B8C24980000004C8B5C2478418BC59941F7FE448BE8418BC49941F7FE448BE08BC59941F7FE8BE88BC69941F7FE8BF04585C97E4048639C24900000
  3101.         004103CA4D8BC1410FAFC94863C94A8D541902488BCA498BC144886901448821408869FF408871FE4883C10448FFC875E84803D349FFC875DA8B8C249800
  3102.         0000488B5C24704C8B5C24784183C20448FFCF48897C24180F850AFFFFFF8B6C2404448B2424448B6C24084C8B74241085ED0F840A01000033FF33DB4533
  3103.         DB4533D24533C04585C97E53488B74247085ED7E42438D0C04418BC50FAF8C2490000000410FAFC18D04814863C8488D5431028BCD0FB642014403D00FB6
  3104.         024883C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC17CB28BCD410FAFC985C9740A418BC299F7F98BF0EB0233F685C9740B418BC3
  3105.         99F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585C97E4D4C8B74247885ED7E3841
  3106.         8D0C14418BC50FAF8C2490000000410FAFC18D04814863C84A8D4431028BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2413BD17CBD
  3107.         4C8B7424108B8C2498000000038C2490000000488B5C24704503E149FFCE44892424898C24980000004C897424100F859EFDFFFF448B7C240C448B842480
  3108.         000000418BC09941F7F98BE8448BEA89942498000000896C240C85C00F8E3B010000448BAC2488000000418BCF448BF5410FAFC9898C248000000033FF33
  3109.         ED33F64533DB4533D24533C04585FF7E524585C97E40418BC5410FAFC14103C00FAF84249000000003C74898488D541802498BD90FB642014403D00FB602
  3110.         4883C2044403D80FB642FB03F00FB642FA03E848FFCB75DE488B5C247041FFC0453BC77CAE85C9740B418BC299F7F9448BE0EB034533E485C9740A418BC3
  3111.         99F7F98BD8EB0233DB85C9740A8BC699F7F9448BD8EB034533DB85C9740A8BC599F7F9448BD0EB034533D24533C04585FF7E4E488B4C24784585C97E3541
  3112.         8BC5410FAFC14103C00FAF84249000000003C74898488D540802498BC144886201881A44885AFF448852FE4883C20448FFC875E941FFC0453BC77CBE8B8C
  3113.         2480000000488B5C2470418BC1C1E00203F849FFCE0F85ECFEFFFF448BAC24980000008B6C240C448BA4248800000033FF33DB4533DB4533D24533C04585
  3114.         FF7E5A488B7424704585ED7E48418BCC8BC5410FAFC94103C80FAF8C2490000000410FAFC18D04814863C8488D543102418BCD0FB642014403D00FB60248
  3115.         83C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC77CAB418BCF410FAFCD85C9740A418BC299F7F98BF0EB0233F685C9740B418BC399
  3116.         F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585FF7E4E4585ED7E42418BCC8BC541
  3117.         0FAFC903CA0FAF8C2490000000410FAFC18D04814863C8488B442478488D440102418BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2
  3118.         413BD77CB233C04883C428415F415E415D415C5F5E5D5BC3
  3119.         )
  3120.        
  3121.         VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2)
  3122.         Loop % StrLen(MCode_PixelateBitmap)//2      ;%
  3123.             NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "UChar")
  3124.         DllCall("VirtualProtect", Ptr, &PixelateBitmap, Ptr, VarSetCapacity(PixelateBitmap), "uint", 0x40, A_PtrSize ? "UPtr*" : "UInt*", 0)
  3125.     }
  3126.  
  3127.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  3128.    
  3129.     if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
  3130.         return -1
  3131.     if (BlockSize > Width || BlockSize > Height)
  3132.         return -2
  3133.  
  3134.     E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
  3135.     E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
  3136.     if (E1 || E2)
  3137.         return -3
  3138.  
  3139.     E := DllCall(&PixelateBitmap, Ptr, Scan01, Ptr, Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize)
  3140.    
  3141.     Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
  3142.     return 0
  3143. }
  3144.  
  3145. ;#####################################################################################
  3146.  
  3147. Gdip_ToARGB(A, R, G, B)
  3148. {
  3149.     return (A << 24) | (R << 16) | (G << 8) | B
  3150. }
  3151.  
  3152. ;#####################################################################################
  3153.  
  3154. Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B)
  3155. {
  3156.     A := (0xff000000 & ARGB) >> 24
  3157.     R := (0x00ff0000 & ARGB) >> 16
  3158.     G := (0x0000ff00 & ARGB) >> 8
  3159.     B := 0x000000ff & ARGB
  3160. }
  3161.  
  3162. ;#####################################################################################
  3163.  
  3164. Gdip_AFromARGB(ARGB)
  3165. {
  3166.     return (0xff000000 & ARGB) >> 24
  3167. }
  3168.  
  3169. ;#####################################################################################
  3170.  
  3171. Gdip_RFromARGB(ARGB)
  3172. {
  3173.     return (0x00ff0000 & ARGB) >> 16
  3174. }
  3175.  
  3176. ;#####################################################################################
  3177.  
  3178. Gdip_GFromARGB(ARGB)
  3179. {
  3180.     return (0x0000ff00 & ARGB) >> 8
  3181. }
  3182.  
  3183. ;#####################################################################################
  3184.  
  3185. Gdip_BFromARGB(ARGB)
  3186. {
  3187.     return 0x000000ff & ARGB
  3188. }
  3189.  
  3190. ;#####################################################################################
  3191.  
  3192. StrGetB(Address, Length=-1, Encoding=0)
  3193. {
  3194.     ; Flexible parameter handling:
  3195.     if Length is not integer
  3196.     Encoding := Length,  Length := -1
  3197.  
  3198.     ; Check for obvious errors.
  3199.     if (Address+0 < 1024)
  3200.         return
  3201.  
  3202.     ; Ensure 'Encoding' contains a numeric identifier.
  3203.     if Encoding = UTF-16
  3204.         Encoding = 1200
  3205.     else if Encoding = UTF-8
  3206.         Encoding = 65001
  3207.     else if SubStr(Encoding,1,2)="CP"
  3208.         Encoding := SubStr(Encoding,3)
  3209.  
  3210.     if !Encoding ; "" or 0
  3211.     {
  3212.         ; No conversion necessary, but we might not want the whole string.
  3213.         if (Length == -1)
  3214.             Length := DllCall("lstrlen", "uint", Address)
  3215.         VarSetCapacity(String, Length)
  3216.         DllCall("lstrcpyn", "str", String, "uint", Address, "int", Length + 1)
  3217.     }
  3218.     else if Encoding = 1200 ; UTF-16
  3219.     {
  3220.         char_count := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "uint", 0, "uint", 0, "uint", 0, "uint", 0)
  3221.         VarSetCapacity(String, char_count)
  3222.         DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "str", String, "int", char_count, "uint", 0, "uint", 0)
  3223.     }
  3224.     else if Encoding is integer
  3225.     {
  3226.         ; Convert from target encoding to UTF-16 then to the active code page.
  3227.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", 0, "int", 0)
  3228.         VarSetCapacity(String, char_count * 2)
  3229.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", &String, "int", char_count * 2)
  3230.         String := StrGetB(&String, char_count, 1200)
  3231.     }
  3232.    
  3233.     return String
  3234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement