$TYPECHECK ON
DECLARE FUNCTIONI AttenueOmbre(...) AS DOUBLE
DECLARE FUNCTION Correct_RGB(Couleur AS LONG) AS LONG
DECLARE SUBI Ombrer_Std(...)
DECLARE SUB Peindre_Ombre(hdc AS LONG, hWinUnder AS LONG, Zone AS Rect, _
IntOmbre AS INTEGER, BYVAL Flou AS SINGLE, Sens AS INTEGER)
DECLARE SUB Ombrer(HWinObjetAOmbrer AS LONG, hWinSupportOmbre, IntensiteOmbre AS INTEGER, _
ProfondeurOmbre AS INTEGER, FlouOmbre AS SINGLE)
FUNCTIONI AttenueOmbre(...) AS DOUBLE
DIM a AS INTEGER, b AS INTEGER, x AS INTEGER, DeCroissante AS INTEGER
a = PARAMVAL(1) : b = PARAMVAL(2): x = PARAMVAL(3)
IF PARAMVALCOUNT = 4 THEN DeCroissante = PARAMVAL(4)
DIM y AS DOUBLE
DIM PI AS DOUBLE
PI = 4 * ATN(1)
IF PARAMVALCOUNT <> 4 THEN
y = (COS((PI * (x - A) / (B - A))))
y = (y + 1) / 2
ELSEIF DeCroissante THEN
y = (COS((PI * (x - A) / (B - A))))
y = (y + 1) / 2
ELSE
y = (COS((PI * (A - x) / (A - B))))
y = (y + 1) / 2
END IF
AttenueOmbre = y
END FUNCTION
FUNCTION Correct_RGB(Couleur AS LONG) AS LONG
IF Couleur < 0 THEN Correct_RGB = 0 ELSE Correct_RGB = Couleur
END FUNCTION
SUBI Ombrer_Std(...)
DIM HWinObjetAOmbrer AS LONG, hWinSupportOmbre AS LONG
HWinObjetAOmbrer = PARAMVAL(1)
IF PARAMVALCOUNT = 2 THEN hWinSupportOmbre = PARAMVAL(2)
IF PARAMVALCOUNT <> 2 THEN
Ombrer HWinObjetAOmbrer, GetDesktopWindow, STD_INTENSITE, STD_PROFONDEUR, STD_FLOU
ELSE
Ombrer HWinObjetAOmbrer, hWinSupportOmbre, STD_INTENSITE, STD_PROFONDEUR, STD_FLOU
END IF
END SUB
SUB Peindre_Ombre(hdc AS LONG, hWinUnder AS LONG, Zone AS Rect, _
IntOmbre AS INTEGER, BYVAL Flou AS SINGLE, Sens AS INTEGER)
DIM Color_Init AS LONG
DIM C_Rouge AS LONG
DIM C_Bleu AS LONG
DIM C_Vert AS LONG
DIM CoeffAttenuation AS DOUBLE
DIM IntOmbreLoc AS INTEGER
DIM X1 AS INTEGER
DIM Y1 AS INTEGER
DIM X2 AS INTEGER
DIM Y2 AS INTEGER
DIM XLimiteFlou AS INTEGER
DIM YLimiteFlou AS INTEGER
DIM Rayon AS INTEGER
X1 = Zone.Left
Y1 = Zone.Top
X2 = Zone.Right
Y2 = Zone.Bottom
DIM Temp_Res AS LONG
Flou = 1 + Flou / 10
SELECT CASE Sens
CASE 0
XLimiteFlou = X1 + (X2 - X1) / Flou
CASE 1
YLimiteFlou = Y1 + (Y2 - Y1) / Flou
CASE 2
XLimiteFlou = X1 + (X2 - X1) / Flou
YLimiteFlou = Y1 + (Y2 - Y1) / Flou
CASE 3
XLimiteFlou = X1 + (X2 - X1) / Flou
YLimiteFlou = Y2 - (Y2 - Y1) / Flou
CASE 4
XLimiteFlou = X2 - (X2 - X1) / Flou
YLimiteFlou = Y1 + (Y2 - Y1) / Flou
END SELECT
DIM i AS INTEGER
DIM j AS INTEGER
FOR i = X1 TO X2
FOR j = Y1 TO Y2
SELECT CASE Sens
CASE 0
IF i < XLimiteFlou OR XLimiteFlou = X2 THEN
CoeffAttenuation = 1
ELSE
CoeffAttenuation = AttenueOmbre(XLimiteFlou, X2, i)
END IF
CASE 1
IF j < YLimiteFlou OR YLimiteFlou = Y2 THEN
CoeffAttenuation = 1
ELSE
CoeffAttenuation = AttenueOmbre(YLimiteFlou, Y2, j)
END IF
CASE 2
IF i < XLimiteFlou OR XLimiteFlou = X2 THEN
CoeffAttenuation = 1
ELSE
CoeffAttenuation = AttenueOmbre(XLimiteFlou, X2, i)
END IF
IF j > YLimiteFlou AND NOT YLimiteFlou = Y2 THEN
CoeffAttenuation = CoeffAttenuation * AttenueOmbre(YLimiteFlou, Y2, j)
END IF
CASE 3
IF i < XLimiteFlou OR XLimiteFlou = X2 THEN
CoeffAttenuation = 1
ELSE
CoeffAttenuation = AttenueOmbre(XLimiteFlou, X2, i)
END IF
IF j < YLimiteFlou THEN
CoeffAttenuation = CoeffAttenuation * AttenueOmbre(YLimiteFlou, Y1, j, False)
END IF
CASE 4
IF i > XLimiteFlou OR XLimiteFlou = X1 THEN
CoeffAttenuation = 1
ELSE
CoeffAttenuation = AttenueOmbre(XLimiteFlou, X1, i, False)
END IF
IF j > YLimiteFlou THEN
CoeffAttenuation = CoeffAttenuation * AttenueOmbre(YLimiteFlou, Y2, j)
END IF
END SELECT
IntOmbreLoc = IntOmbre * CoeffAttenuation
Color_Init = GetPixel(hdc, i, j)
C_Rouge = (Color_Init AND clRed)
C_Rouge = C_Rouge - (C_Rouge / 255) * IntOmbreLoc
C_Vert = (Color_Init AND clGreen) / (clRed + 1)
C_Vert = C_Vert - (C_Vert / 255) * IntOmbreLoc
C_Bleu = (Color_Init AND clBlue) / (clGreen + clRed + 1)
C_Bleu = C_Bleu - (C_Bleu / 255) * IntOmbreLoc
Color_Init = RGB(Correct_RGB(C_Rouge), Correct_RGB(C_Vert), Correct_RGB(C_Bleu))
Temp_Res = SetPixelV(hdc, i, j, Color_Init)
NEXT j
NEXT i
END SUB
SUB Ombrer(HWinObjetAOmbrer AS LONG, hWinSupportOmbre, IntensiteOmbre AS INTEGER, _
ProfondeurOmbre AS INTEGER, FlouOmbre AS SINGLE)
DIM RectOmbre AS Rect
DIM PosXOmbre AS INTEGER
DIM PosYOmbre AS INTEGER
DIM HauteurOmbre AS INTEGER
DIM LargeurOmbre AS INTEGER
DIM Rect_Fenetre AS Rect
DIM Rect_Cl_Support AS Rect
DIM Handle_Screen_DC AS LONG
DIM hWin_Screen AS LONG
DIM hDCSupportOmbre AS LONG
DIM hWinUnder AS LONG
DIM hObjetDC AS LONG
DIM hMemDC AS LONG
STATIC hMemBitmap AS LONG
DIM hPrevBitmap AS LONG
DIM BufferRect AS Rect
DIM X_Buffer AS INTEGER
DIM Y_Buffer AS INTEGER
DIM H_Buffer AS INTEGER
DIM L_Buffer AS INTEGER
hWin_Screen = GetDesktopWindow
Handle_Screen_DC = GetDC(0)
hDCSupportOmbre = GetWindowDC(hWinSupportOmbre)
GetWindowRect HWinObjetAOmbrer, Rect_Fenetre
GetWindowRect hWinSupportOmbre, Rect_Cl_Support
IF ProfondeurOmbre MOD 2 <> 0 THEN ProfondeurOmbre = ProfondeurOmbre + 1
X_Buffer = Rect_Fenetre.Left
Y_Buffer = Rect_Fenetre.Top
L_Buffer = Rect_Fenetre.Right - Rect_Fenetre.Left + ProfondeurOmbre
H_Buffer = Rect_Fenetre.Bottom - Rect_Fenetre.Top + ProfondeurOmbre
BufferRect.Top = Y_Buffer
BufferRect.Left = X_Buffer
BufferRect.Bottom = Y_Buffer + H_Buffer
BufferRect.Right = X_Buffer + L_Buffer
hMemBitmap = CreateCompatibleBitmap(Handle_Screen_DC, X_Buffer + L_Buffer, Y_Buffer + H_Buffer)
IF hMemBitmap = 0 THEN SHOWMESSAGE "c'est foutu"
hMemDC = CreateCompatibleDC(Handle_Screen_DC)
hPrevBitmap = SelectObject(hMemDC, hMemBitmap)
BitBlt hMemDC, X_Buffer, Y_Buffer, L_Buffer, H_Buffer, _
Handle_Screen_DC, X_Buffer, Y_Buffer, SRCCOPY
PosXOmbre = Rect_Fenetre.Right
PosYOmbre = Rect_Fenetre.Top + ProfondeurOmbre + ProfondeurOmbre / 2
HauteurOmbre = (Rect_Fenetre.Bottom - Rect_Fenetre.Top) - 1 - ProfondeurOmbre / 2
LargeurOmbre = ProfondeurOmbre
RectOmbre.Left = PosXOmbre
RectOmbre.Top = PosYOmbre
RectOmbre.Right = PosXOmbre + LargeurOmbre
RectOmbre.Bottom = PosYOmbre + HauteurOmbre - ProfondeurOmbre
Peindre_Ombre hMemDC, hWinUnder, RectOmbre, IntensiteOmbre, FlouOmbre, 0
PosXOmbre = Rect_Fenetre.Left + ProfondeurOmbre + ProfondeurOmbre / 2
PosYOmbre = Rect_Fenetre.Bottom
HauteurOmbre = ProfondeurOmbre
LargeurOmbre = (Rect_Fenetre.Right - Rect_Fenetre.Left) - ProfondeurOmbre / 2
RectOmbre.Left = PosXOmbre
RectOmbre.Top = PosYOmbre
RectOmbre.Right = PosXOmbre + LargeurOmbre - ProfondeurOmbre - 1
RectOmbre.Bottom = PosYOmbre + HauteurOmbre
Peindre_Ombre hMemDC, hWinUnder, RectOmbre, IntensiteOmbre, FlouOmbre, 1
RectOmbre.Left = RectOmbre.Right + 1
RectOmbre.Top = RectOmbre.Top
RectOmbre.Right = RectOmbre.Right + ProfondeurOmbre + 1
Peindre_Ombre hMemDC, hWinUnder, RectOmbre, IntensiteOmbre, FlouOmbre, 2
RectOmbre.Top = RectOmbre.Top - ((Rect_Fenetre.Bottom - Rect_Fenetre.Top) - ProfondeurOmbre / 2) - 1
RectOmbre.Right = RectOmbre.Right
RectOmbre.Bottom = RectOmbre.Top + ProfondeurOmbre
Peindre_Ombre hMemDC, hWinUnder, RectOmbre, IntensiteOmbre, FlouOmbre, 3
RectOmbre.Top = Rect_Fenetre.Bottom
RectOmbre.Left = Rect_Fenetre.Left + ProfondeurOmbre / 2 - 1
RectOmbre.Right = RectOmbre.Left + ProfondeurOmbre
RectOmbre.Bottom = RectOmbre.Top + ProfondeurOmbre
Peindre_Ombre hMemDC, hWinUnder, RectOmbre, IntensiteOmbre, FlouOmbre, 4
BitBlt hDCSupportOmbre, (X_Buffer - Rect_Cl_Support.Left), _
(Y_Buffer - Rect_Cl_Support.Top), _
L_Buffer, H_Buffer, _
hMemDC, X_Buffer, Y_Buffer, SRCCOPY
SelectObject hMemDC, hPrevBitmap
IF DeleteObject(hMemBitmap) = 0 THEN SHOWMESSAGE "Problème : bitmap mémoire non supprimé."
IF DeleteDC(hMemDC) = 0 THEN SHOWMESSAGE "Problème : DC mémoire non supprimé."
IF ReleaseDC(hWin_Screen, Handle_Screen_DC) = 0 THEN SHOWMESSAGE "Problème : DC mémoire non restitué."
Exit_Ombrer:
END SUB
|
|