MCRC=3B8CC3F
MVersion=0.0.1
CreateShaderBitmap(width, height, vertical="false") {
Global shaderObj, RLMediaPath
Global shaderName, shaderColor, shaderTransparency, shaderChangeKey, shaderObj
if (shaderObj){
Log(A_ThisFunc . " - Started",2)
pBitmap_temp := Gdip_CreateBitmap(width, height)
G_temp := Gdip_GraphicsFromImage(pBitmap_temp), Gdip_SetSmoothingMode(G_temp, 4), Gdip_SetInterpolationMode(G_temp, 7)
if (shaderColor){ ; priority for the color defined on RL
transparency := ToBase( Round( (ToBase("0x" . SubStr(shaderColor,1,2),10)) * (shaderTransparency ? (shaderTransparency/255) : 1) ) , 16)
Gdip_FillRectangle(G_temp, Gdip_BrushCreateSolid("0x" . transparency . SubStr(shaderColor,3,6)), 0, 0, width, height)
}
for index, element in shaderObj["overlays"]
{ if !(element["orientation"]) or ( (element["orientation"]="horizontal") and (vertical = "false") ) or ( (element["orientation"]="vertical") and (vertical = "true") ) {
if ((element.HasKey("solid-color")) and !(shaderColor)){ ; solid color layer
transparency := ToBase( Round( (ToBase("0x" . SubStr(element["solid-color"],1,2),10)) * (shaderTransparency ? (shaderTransparency/255) : 1) ) , 16)
Gdip_FillRectangle(G_temp, Gdip_BrushCreateSolid("0x" . transparency . SubStr(element["solid-color"],3,6)), 0, 0, width, height)
} else if (element["filename"]){ ; image layer
alpha := element["alpha-channel"] ? element["alpha-channel"] : 255
transparency := (element["matrix"]) ? (element["matrix"]) : ( (alpha/255) * ( shaderTransparency ? (shaderTransparency/255) : 1 ) )
shaderBitmap_temp := Gdip_CreateBitmapFromFile(RLMediaPath . "\Shaders\" . shaderName . "\" . element["filename"])
if (element["size-mode"]="tile"){
shaderBitmap_temp := RepeatBitmap(shaderBitmap_temp, width, height)
Gdip_DrawImage(G_temp, shaderBitmap_temp, 0, 0, width, height,,,,, transparency)
} else {
Gdip_DrawImage(G_temp, shaderBitmap_temp, 0, 0, width, height,,,,, transparency)
}
} else
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)
}
}
If shaderBitmap_temp ;discarding temp GDIP assets
Gdip_DisposeImage(shaderBitmap_temp)
Gdip_DeleteGraphics(G_temp)
Log(A_ThisFunc . " - Ended",2)
Return pBitmap_temp
}
Return
}
RepeatBitmap(pBitmap, width, height, Dispose=1) {
Gdip_GetImageDimensions(pBitmap, origW, origH)
pBitmap_temp := Gdip_CreateBitmap(width, height)
G_temp := Gdip_GraphicsFromImage(pBitmap_temp), Gdip_SetSmoothingMode(G_temp, 4), Gdip_SetInterpolationMode(G_temp, 7)
Loop,
{ i := a_index
Loop,
{ j := A_Index
Gdip_DrawImage(G_temp, pBitmap, (i-1)*origW, (j-1)*origH, origW, origH)
if (j*origH>height)
break
}
if (i*origW>width)
break
}
Gdip_DeleteGraphics(G_temp)
if Dispose
Gdip_DisposeImage(pBitmap)
return pBitmap_temp
}
; Converts a base 10 number to base 36
;from Laszlo : http://www.autohotkey.com/board/topic/15951-base-10-to-base-36-conversion/#entry103624
ToBase(n,b) { ; n >= 0, 1 < b <= 36
Loop {
d := mod(n,b), n //= b
m := (d < 10 ? d : Chr(d+55)) . m
IfLess n,1, Break
}
Return m
}
Comments