Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sun Aug 30, 2020 6:32 pm Post subject: Trying to created Drop Shadow (gdi32) in CE Lua |
|
|
I have success to create drop shadow to an object component in VB6 using windows lib gdi32.
So, I try to port vb script to CE Lua to get same effect, but it seems doesn't work properly. Could someone take analysis the CE Lua script?.
| Code: | function RGB(r,g,b)
local colorBitShiftRed = 0
local colorBitShiftBlue = 16
local colorBitShiftGreen = 8
local function clamp(value, min, max) return math.min(math.max(value, min), max) end
r = clamp(r, 0, 255); g = clamp(g, 0, 255); b = clamp(b, 0, 255);
return (r << colorBitShiftRed) | (g << colorBitShiftGreen) | (b << colorBitShiftBlue)
end
function CreateCompatibleDC(hDC)
return executeCodeLocalEx("gdi32.CreateCompatibleDC", hDC)
end
function SelectObject(hDC, hObject)
return executeCodeLocalEx("gdi32.SelectObject", hDC, hObject)
end
function CreateCompatibleBitmap(hDC, nWidth, nHeight)
return executeCodeLocalEx("gdi32.CreateCompatibleBitmap", hDC, nWidth, nHeight)
end
function BitBlt(hDCDest, XDest, YDest, nWidth, nHeight, hDCSrc, xSrc , ySrc, dwRop)
return executeCodeLocalEx("gdi32.BitBlt", hDCDest, XDest, YDest, nWidth, nHeight, hDCSrc, xSrc , ySrc, dwRop)
end
function _SetPixel(hDC, X, Y, crColor)
return executeCodeLocalEx("gdi32.SetPixel", hDC, X, Y, crColor)
end
function _GetPixel(hDC, X, Y)
return executeCodeLocalEx("gdi32.GetPixel", hDC, X, Y)
end
function LockWindowUpdate(hWndLock)
return executeCodeLocalEx("user32.LockWindowUpdate", hWndLock)
end
function DeleteDC(hDC)
return executeCodeLocalEx("gdi32.DeleteDC", hDC)
end
function DeleteObject(hObject)
return executeCodeLocalEx("gdi32.DeleteObject", hObject)
end
function uMask(lScale, lColor)
local R, G, B, sColor
--sColor = CStr(Format(Hex(lColor), "000000"))
sColor = string.format("000000", lColor)
R = "0x"..string.sub(sColor, -2)
G = "0x"..string.sub(sColor, 3, 4)
B = "0x"..string.sub(sColor, 1, 2)
R = R - R * lScale / 255
R = math.floor(R)
if R < 0 then R = 0 end
G = G - G * lScale / 255
G = math.floor(G)
if G < 0 then G = 0 end
B = B - B * lScale / 255
B = math.floor(B)
if B < 0 then B = 0 end
return RGB(R,G,B)
end
function DrawDropShadow(objPic, sWidth)
local lDC, rDC, lBMP, rBMP, X, Y, uColor
if sWidth > 14 then sWidth = 14 end
local SRCCOPY = 0xCC0020
uColor = 0x838B8B
objPic.Visible = false
lDC = CreateCompatibleDC(objPic.hDC)
lBMP = CreateCompatibleBitmap(objPic.hDC, objPic.Width + sWidth, sWidth)
SelectObject(lDC, lBMP)
BitBlt(lDC, 0, 0, objPic.Width + sWidth, sWidth, objPic.hDC, objPic.Left, objPic.Top + objPic.Height, SRCCOPY)
rDC = CreateCompatibleDC(objPic.hDC)
rBMP = CreateCompatibleBitmap(objPic.hDC, sWidth, objPic.Height + sWidth)
SelectObject(rDC, rBMP)
BitBlt(rDC, 0, 0, sWidth, objPic.Height + sWidth, objPic.hDC, objPic.Left + objPic.Width, objPic.Top, SRCCOPY)
genDC = CreateCompatibleDC(objPic.hDC)
genBMP = CreateCompatibleBitmap(objPic.hDC, objPic.Width + sWidth, objPic.Height + sWidth)
SelectObject(genDC, genBMP)
BitBlt(genDC, 0, 0, objPic.Width - sWidth, objPic.Height - sWidth, objPic.hDC, 0, 0, SRCCOPY)
objPic.Width = objPic.Width + sWidth
objPic.Height = objPic.Height + sWidth
for X = 1, sWidth do
for Y = 0, 3 do
uColor = _GetPixel(rDC, sWidth - X, Y)
_SetPixel(objPic.hDC, objPic.Width - X, Y, uColor)
end
for Y = 4, 7 do
uColor = _GetPixel(rDC, sWidth - X, Y)
if X + Y <= objPic.Height then
_SetPixel(objPic.hDC, objPic.Width - X, Y, uMask(3 * X * (Y - 3), uColor))
end
end
for Y = 8, objPic.Height - 5 do
uColor = _GetPixel(rDC, sWidth - X, Y)
if X + Y <= objPic.Height then
_SetPixel(objPic.hDC, objPic.Width - X, Y, uMask(15 * X, uColor))
end
end
for Y = objPic.Height - 5, objPic.Height - 1 do
uColor = _GetPixel(rDC, sWidth - X, Y)
if X + Y <= objPic.Height + 3 then
_SetPixel(objPic.hDC, objPic.Width - X, Y, uMask(-3 * X * (Y - objPic.Height), uColor))
end
end
end
for Y = 1, sWidth do
for X = 0, 3 do
uColor = _GetPixel(lDC, X, sWidth - Y)
_SetPixel(objPic.hDC, X, objPic.Height - Y, uColor)
end
for X = 4, 7 do
uColor = _GetPixel(lDC, X, sWidth - Y)
_SetPixel(objPic.hDC, X, objPic.Height - Y, uMask(3 * (X - 3) * Y, uColor))
end
for X = 8, objPic.Width - 5 do
uColor = _GetPixel(lDC, X, sWidth - Y)
if X + Y <= objPic.Width then
_SetPixel(objPic.hDC, X, objPic.Height - Y, uMask(15 * Y, uColor))
end
end
end
objPic.Visible = true
DeleteDC(lDC)
DeleteObject(lBMP)
DeleteDC(rDC)
DeleteObject(rBMP)
end
---------------------------------
function Command1_Click()
LockWindowUpdate(f.handle)
DrawDropShadow(pic1, string.len(txtWidth.Text))
-- pic1.repaint() --pic1.Refresh
LockWindowUpdate(0)
Command1.Enabled = false
txtWidth.Enabled = false
Command2.Enabled = true
end
function Command2_Click()
pic1.Width = pic1.Width - string.len(txtWidth.Text)
pic1.Height = pic1.Height - string.len(txtWidth.Text)
-- pic1.repaint() --pic1.Refresh
Command1.Enabled = true
Command2.Enabled = false
txtWidth.Enabled = true
txtWidth.setFocus()
end
function txtWidth_GotFocus()
txtWidth.SelStart = 0
txtWidth.SelLength = 10
end
function Trim(s)
local _, i1 = string.find(s,'^%s*')
local i2 = find(s,'%s*$')
return string.sub(s, i1 + 1, i2 - 1)
end
function txtWidth_LostFocus()
txt = txtWidth.Text
if txtWidth.Text ~= "" then
if string.len(txtWidth.Text) < 4 then txtWidth.Text = Trim(txt) end
if string.len(txtWidth.Text) > 14 then txtWidth.Text = Trim(txt) end
end
end
---------------------------------
if f then f.Destroy() end
f = createForm()
f.setSize(430, 194)
f.Position = 'poScreenCenter'
f.Caption = 'Drop Shadow Example'
f.Color = 0xffffff
pic1 = createPanel(f)
pic1.setPosition(72, 16)
pic1.setSize(155, 65)
pic1.BorderStyle = 'bsNone'
pic1.Color = 16760576
Label1 = createLabel(f)
Label1.setPosition(296,83)
Label1.Caption = 'Width'
txtWidth = createEdit(f)
txtWidth.setPosition(336,80)
txtWidth.Text = 10
Command1 = createButton(f)
Command1.setPosition(296,110)
Command1.setSize(120,23)
Command1.Caption = 'Drop Shadow'
Command2 = createButton(f)
Command2.setPosition(296,140)
Command2.setSize(120,23)
Command2.Caption = 'Clear'
-----------------------------
f.Show()
Command1.OnClick = Command1_Click
Command2.OnClick = Command2_Click |
Attached images (comparing VB result vs CE Lua result)
EDIT:
I think the problem is on :
BitBlt(lDC, 0, 0, objPic.Width + sWidth, sWidth, objPic.hDC, objPic.Left, objPic.Top + objPic.Height, SRCCOPY)
should be
BitBlt(lDC, 0, 0, objPic.Width + sWidth, sWidth, objPic.Container.hDC, objPic.Left, objPic.Top + objPic.Height, SRCCOPY)
but I don't know to create object.Container in Lua, I think should be use a table.
| Description: |
|
| Filesize: |
72.83 KB |
| Viewed: |
1121 Time(s) |

|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|