Advertisement
Guest User

ahk vector class example

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