Busted ! Mais c'est parce qu'une fois que j'ai réussi à faire ce que je voulais, j'étais un peu excité
Code : Tout sélectionner
;{######################################
; Programme : CustomFrame3D
#VERSION = "1.00"
;
; Description : - Ajoute un nouveau "gadget" personnalisé, imitant le Frame3DGadget(), avec le choix de la couleur / rayon des angles / largeur de ligne en plus
;
; Détails & TODOs réalisés:
; - Création d'un cadre surmonté d'un texte, caractéristiques personnalisables.
;
;
; Auteur : - graph100
;
; Remerciements : - Kwai chang caine -> Pour avoir posté un code de Srod sur le fofo FR
; - Srod -> Code avec des bouton rond, qui m'a orienté sur la solution utilisée dans ce code
; - LSI -> Pour sa procedure SkinWindow() adaptée en ShapeObjectFromBitmap()
; - Fred -> Parce qu'on ne le remercie jamais assez :)
;}######################################
;{ Procedure/structure pour gérer le CustomFram3D
ProcedureDLL.l ShapeObjectFromBitmap(ObjectID, ImageID, Couleur) ; transforme la fenetre avec la forme de l'image avec comme couleur transparente couleur (appelée SkinWinfow() avant)
Protected bmi.BITMAPINFO, bm.BITMAP
Protected hdc, Region_Totale, Region_Temp, *Mem, Hauteur, Largeur, Y1, X1, X2, *Point
GetObject_(ImageID, SizeOf(BITMAP), @bm.BITMAP)
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = bm\bmWidth
bmi\bmiHeader\biHeight = bm\bmHeight
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
Couleur = ((Couleur & $0000FF) << 16) | (Couleur & $00FF00) | ((Couleur & $FF0000) >> 16)
Region_Totale = CreateRectRgn_(0, 0, bm\bmWidth, bm\bmHeight)
*Mem = AllocateMemory(bm\bmWidth * bm\bmHeight * 4)
If *Mem
hdc = CreateCompatibleDC_(GetDC_(ImageID))
If hdc
GetDIBits_(hdc, ImageID, 0, bm\bmHeight, *Mem, @bmi, #DIB_RGB_COLORS) ; on envoie la liste dans l'image
DeleteDC_(hdc)
EndIf
; On convertit la liste dans le bon format
Largeur = bm\bmWidth - 1
Hauteur = bm\bmHeight - 1
*Point = *Mem
For Y1 = 0 To Hauteur
For X1 = 0 To Largeur
If PeekL(*Point) = Couleur
X2 = X1
While X2 < Largeur And PeekL(*Point + 4) = Couleur
X2 + 1
*Point + 4
Wend
Region_Temp = CreateRectRgn_(X1, Hauteur - Y1, X2 + 1, Hauteur - Y1 + 1) ; On retire le point de la region
CombineRgn_(Region_Totale, Region_Totale, Region_Temp, #RGN_DIFF)
DeleteObject_(Region_Temp)
X1 = X2
EndIf
*Point + 4
Next
Next
FreeMemory(*Mem)
EndIf
SetWindowRgn_(ObjectID, Region_Totale, 1) ; On applique la region
DeleteObject_(Region_Totale) ; On efface la region
EndProcedure
Structure ICG_CustomFrame3D
Color.l
Title.s
Font.l
TextBackColor.l
rayon.l
largeur.l
zz_Is_FontDefault.b
EndStructure
; Pour redessiner / changer le titre, la couleur...
Procedure RedrawFrame3D(Gadget.l, new_color.l = #PB_Ignore, new_title.s = #CR$, new_rayon = #PB_Ignore, new_largeur = #PB_Ignore, new_Text_BackColor.l = #PB_Ignore, new_x = #PB_Ignore, new_y = #PB_Ignore, new_width = #PB_Ignore, new_height = #PB_Ignore, new_Font.l = #PB_Ignore)
#PB_CustomFrame3D_Round = 1
Protected *mem.ICG_CustomFrame3D = GetGadgetData(Gadget)
Protected color_trans, th, tw
;{ changement des paramètres
If new_color <> #PB_Ignore
*mem\Color = new_color
EndIf
If new_Text_BackColor <> #PB_Ignore
*mem\TextBackColor = new_Text_BackColor
EndIf
If new_rayon <> #PB_Ignore
*mem\rayon = new_rayon
EndIf
If new_largeur <> #PB_Ignore
*mem\largeur = new_largeur
EndIf
If new_Font <> #PB_Ignore
If *mem\zz_Is_FontDefault And IsFont(*mem\Font)
FreeFont(*mem\Font)
*mem\zz_Is_FontDefault = #False
EndIf
*mem\Font = new_Font
EndIf
If new_title <> #CR$
*mem\Title = new_title
EndIf
If new_x <> #PB_Ignore Or new_y <> #PB_Ignore Or new_height <> #PB_Ignore Or new_width <> #PB_Ignore
ResizeGadget(Gadget, new_x, new_y, new_width, new_height)
EndIf
Protected w = GadgetWidth(Gadget), h = GadgetHeight(Gadget)
Protected img = CreateImage(#PB_Any, w, h)
If *mem\Font = #PB_Ignore Or IsFont(*mem\Font) = 0
*mem\Font = LoadFont(#PB_Any, "Segoe UI", 8.5)
*mem\zz_Is_FontDefault = #True
EndIf
;}
; on calcule une autre couleur toujours valide pour la couleur transparente
color_trans = RGB(Mod(Red(*mem\Color) + 50, 256), Mod(Green(*mem\Color) + 50, 256), Mod(Blue(*mem\Color) + 50, 256))
If StartDrawing(ImageOutput(img))
Box(0, 0, w, h, color_trans)
If *mem\Title <> ""
th = TextHeight(" " + *mem\Title) / 2 - 2
tw = TextWidth(" " + *mem\Title + " ")
EndIf
RoundBox(0, th, w, h - th, *mem\rayon, *mem\rayon, *mem\Color)
RoundBox(*mem\largeur, th + *mem\largeur, w - 2 * *mem\largeur, h - th - 2 * *mem\largeur, *mem\rayon, *mem\rayon, color_trans)
If *mem\Title <> ""
DrawingFont(FontID(*mem\Font))
DrawText(7 + *mem\rayon, -1, " " + *mem\Title + " ", *mem\Color, *mem\TextBackColor)
EndIf
StopDrawing()
EndIf
ShapeObjectFromBitmap(GadgetID(Gadget), ImageID(img), color_trans)
SetGadgetAttribute(Gadget, #PB_Canvas_Image, ImageID(img))
FreeImage(img)
EndProcedure
; Pour la création du gadget
Procedure CustomFrame3D(Gadget, x.l, y.l, w.l, h.l, Title.s, color.l, rayon = 0, largeur = 1, Font = -1, Text_BackColor.l = 15790320)
If Gadget = #PB_Any
Gadget = CanvasGadget(#PB_Any, x, y, w, h);, #WS_CLIPSIBLINGS|#WS_CLIPCHILDREN)
Else
CanvasGadget(Gadget, x, y, w, h);, #WS_CLIPSIBLINGS|#WS_CLIPCHILDREN)
EndIf
Protected *mem.ICG_CustomFrame3D = AllocateMemory(SizeOf(ICG_CustomFrame3D))
SetGadgetData(Gadget, *mem)
RedrawFrame3D(Gadget, color, Title, rayon, largeur, Text_BackColor, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore, Font)
ProcedureReturn Gadget
EndProcedure
;}
;{ Chargement de la fenêtre
If OpenWindow(0, 0, 0, 320, 670, "Frame3D en folie !", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget)
Frame3DGadget(0, 10, 10, 300, 100, "Cadre en relief standard de PureBasic")
CustomFrame3D(1, 10, 120, 300, 100, "Cadre en relief standard rouge", #Red)
ButtonGadget(2, 20, 135, 100, 20, "Couleur aléatoire")
CustomFrame3D(3, 10, 230, 300, 100, "Cadre en relief standard de couleur changeante", #Red)
AddWindowTimer(0, 0, 100) : compteur.d = 0
CustomFrame3D(4, 10, 340, 300, 100, "Cadre en relief arrondis (rayon = 10), Bleu", #Blue, 7)
CustomFrame3D(5, 10, 450, 300, 100, "Cadre en relief épais (rayon = 0, largeur = 3), Vert", #Green, 0, 3)
CustomFrame3D(6, 10, 560, 300, 100, "Cadre en relief changeant (gros mix :)", #Black)
EndIf
;}
;{ Boucle principale
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 2
RedrawFrame3D(1, Random(#White), "Cadre en relief standard de couleur aléatoire")
EndSelect
Case #PB_Event_Timer
If EventTimer() = 0
compteur + #PI / 100
RedrawFrame3D(3, RGB(255 * Abs(Sin(compteur)), 255 * Abs(Sin(compteur * 2)), 255 * Abs(Cos(compteur))))
RedrawFrame3D(6, RGB(255 * Abs(Cos(compteur)), 255 * Abs(Cos(compteur * 2)), 255 * Abs(Sin(compteur))), #CR$, 15 * Abs(Cos(compteur * 1.5)), 5 * Abs(Sin(compteur * 0.5)))
EndIf
EndSelect
Until event = #PB_Event_CloseWindow
;}
End