Advertisement
djvj

shader.ahk

Mar 9th, 2016
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. MCRC=3B8CC3F
  2. MVersion=0.0.1
  3.  
  4. CreateShaderBitmap(width, height, vertical="false") {
  5. Global shaderObj, RLMediaPath
  6. Global shaderName, shaderColor, shaderTransparency, shaderChangeKey, shaderObj
  7. if (shaderObj){
  8. Log(A_ThisFunc . " - Started",2)
  9. pBitmap_temp := Gdip_CreateBitmap(width, height)
  10. G_temp := Gdip_GraphicsFromImage(pBitmap_temp), Gdip_SetSmoothingMode(G_temp, 4), Gdip_SetInterpolationMode(G_temp, 7)
  11. if (shaderColor){ ; priority for the color defined on RL
  12. transparency := ToBase( Round( (ToBase("0x" . SubStr(shaderColor,1,2),10)) * (shaderTransparency ? (shaderTransparency/255) : 1) ) , 16)
  13. Gdip_FillRectangle(G_temp, Gdip_BrushCreateSolid("0x" . transparency . SubStr(shaderColor,3,6)), 0, 0, width, height)
  14. }
  15. for index, element in shaderObj["overlays"]
  16. { if !(element["orientation"]) or ( (element["orientation"]="horizontal") and (vertical = "false") ) or ( (element["orientation"]="vertical") and (vertical = "true") ) {
  17. if ((element.HasKey("solid-color")) and !(shaderColor)){ ; solid color layer
  18. transparency := ToBase( Round( (ToBase("0x" . SubStr(element["solid-color"],1,2),10)) * (shaderTransparency ? (shaderTransparency/255) : 1) ) , 16)
  19. Gdip_FillRectangle(G_temp, Gdip_BrushCreateSolid("0x" . transparency . SubStr(element["solid-color"],3,6)), 0, 0, width, height)
  20. } else if (element["filename"]){ ; image layer
  21. alpha := element["alpha-channel"] ? element["alpha-channel"] : 255
  22. transparency := (element["matrix"]) ? (element["matrix"]) : ( (alpha/255) * ( shaderTransparency ? (shaderTransparency/255) : 1 ) )
  23. shaderBitmap_temp := Gdip_CreateBitmapFromFile(RLMediaPath . "\Shaders\" . shaderName . "\" . element["filename"])
  24. if (element["size-mode"]="tile"){
  25. shaderBitmap_temp := RepeatBitmap(shaderBitmap_temp, width, height)
  26. Gdip_DrawImage(G_temp, shaderBitmap_temp, 0, 0, width, height,,,,, transparency)
  27. } else {
  28. Gdip_DrawImage(G_temp, shaderBitmap_temp, 0, 0, width, height,,,,, transparency)
  29. }
  30. } else
  31. Log(A_ThisFunc . " - Invalid shader overlay element: index" . index . ". Each overlay must contain a key named: filename, for the case of images, or solid-color, for the case of solid background colors.",2)
  32. }
  33. }
  34. If shaderBitmap_temp ;discarding temp GDIP assets
  35. Gdip_DisposeImage(shaderBitmap_temp)
  36. Gdip_DeleteGraphics(G_temp)
  37. Log(A_ThisFunc . " - Ended",2)
  38. Return pBitmap_temp
  39. }
  40. Return
  41. }
  42.  
  43. RepeatBitmap(pBitmap, width, height, Dispose=1) {
  44. Gdip_GetImageDimensions(pBitmap, origW, origH)
  45. pBitmap_temp := Gdip_CreateBitmap(width, height)
  46. G_temp := Gdip_GraphicsFromImage(pBitmap_temp), Gdip_SetSmoothingMode(G_temp, 4), Gdip_SetInterpolationMode(G_temp, 7)
  47. Loop,
  48. { i := a_index
  49. Loop,
  50. { j := A_Index
  51. Gdip_DrawImage(G_temp, pBitmap, (i-1)*origW, (j-1)*origH, origW, origH)
  52. if (j*origH>height)
  53. break
  54. }
  55. if (i*origW>width)
  56. break
  57. }
  58. Gdip_DeleteGraphics(G_temp)
  59. if Dispose
  60. Gdip_DisposeImage(pBitmap)
  61. return pBitmap_temp
  62. }
  63.  
  64. ; Converts a base 10 number to base 36
  65. ;from Laszlo : http://www.autohotkey.com/board/topic/15951-base-10-to-base-36-conversion/#entry103624
  66. ToBase(n,b) { ; n >= 0, 1 < b <= 36
  67. Loop {
  68. d := mod(n,b), n //= b
  69. m := (d < 10 ? d : Chr(d+55)) . m
  70. IfLess n,1, Break
  71. }
  72. Return m
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement