Gadget Frame3D

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: Gadget Frame3D

Message par Mesa »

Une version sans api:

Code : Tout sélectionner


Global Window_0
Global PoliceID
;Global ImageDeFond

Global Frame3DEx0, Frame3DEx1, Frame3DEx2, Frame3DEx3, Frame3DEx4
Global  Button0,	Explorer0

LoadFont (PoliceID, "Courier", 24, #PB_Font_Underline)

Procedure Frame3DEx(ID, x, y, Largeur, Hauteur, Arrondi, Texte$, Options=0, CouleurBordure=0, CouleurTexte=0, CouleurFond=-1, PoliceID=-1)
  Protected IDGadget,OK, CouleurFond0, W, H, DecalageGauche
  ;   Options:
  ;   0                 : Cadre standard 
  ;   #PB_Frame3D_Single: Cadre enfoncé
  ;   #PB_Frame3D_Double: Cadre doublement enfoncé
  ;   #PB_Frame3D_Flat  : Cadre simple avec arrondi ou non
  
  ;Création du Gadget
  If ID=#PB_Any
    
    IDGadget=CanvasGadget(#PB_Any, x, y, Largeur, Hauteur )
    ;IDGadget=ContainerGadget(#PB_Any, x, y, Largeur, Hauteur )
    If IDGadget=0
      MessageRequester("Alerte.","Le Gadget Frame3D n'a pas pu être créé.")
      End
    EndIf
    
  Else
    ok=CanvasGadget(ID, x, y, Largeur, Hauteur )
    If ok=0
      MessageRequester("Alerte.","Le Gadget Frame3D n'a pas pu être créé.")
      End
    EndIf
    IDGadget= ID
  EndIf
  
  ;Dessin
  ;Couleur de fond
  StartDrawing(WindowOutput(Window_0))
  CouleurFond0=Point(x,y)
  StopDrawing()
  
  ok=StartDrawing(CanvasOutput(IDGadget))
  If ok=0
    MessageRequester("Alerte.","Le Gadget Frame3D n'a pas pu être dessiné.")
    End
  EndIf
  
  ;Si on utilise une police perso
  If PoliceID<>-1
    DrawingFont(FontID(PoliceID))                 
    SetGadgetFont(IDGadget, PoliceID) 
  EndIf
  
  ;Dim du texte
  W=TextWidth(Texte$)
  H=TextHeight("MgWy")
  
  DrawingMode(#PB_2DDrawing_Default)
  
  ;Fond "transparent"
  Box(0, 0, Largeur, Hauteur, CouleurFond0);
  
  ;Cadre
  DrawingMode(#PB_2DDrawing_Outlined )
  
  Select Options
    Case 0 ;Standard  
      Box(0, H/2+1, Largeur, Hauteur-H/2-1, CouleurBordure)
      Box(1, H/2+2, Largeur-2, Hauteur-H/2-3, CouleurBordure)
      Box(1, H/2+2, Largeur-1, Hauteur-H/2-2, #White)
      If CouleurFond <>-1
        FrontColor(CouleurFond)
        FillArea(Largeur/2,Hauteur/2,-1,CouleurFond)
      EndIf   
    Case #PB_Frame3D_Single
      Box(0, H/2+1, Largeur, Hauteur-H/2-1, #White)
      Box(0, H/2+1, Largeur+1, Hauteur-H/2, CouleurBordure)
      If CouleurFond <>-1
        FrontColor(CouleurFond)
        FillArea(Largeur/2,Hauteur/2,-1,CouleurFond)
      EndIf
    Case  #PB_Frame3D_Double
      Box(0, H/2+1, Largeur, Hauteur-H/2-1, #White)
      Box(0, H/2+1, Largeur+1, Hauteur-H/2, CouleurBordure)
      Box(1, H/2+2, Largeur+1, Hauteur-H/2, CouleurBordure)
      If CouleurFond <>-1
        FrontColor(CouleurFond)
        FillArea(Largeur/2,Hauteur/2,-1,CouleurFond)
      EndIf     
    Case #PB_Frame3D_Flat
      RoundBox(0, H/2+1, Largeur, Hauteur-H/2-1, Arrondi, Arrondi , CouleurBordure)
      If CouleurFond <>-1
        FrontColor(CouleurFond)
        FillArea(Largeur/2,Hauteur/2,-1,CouleurFond)
      EndIf
      
    Default
      RoundBox(0, H/2+1, Largeur, Hauteur-H/2-1, Arrondi, Arrondi , CouleurBordure)
      If CouleurFond <>-1
        FrontColor(CouleurFond)
        FillArea(Largeur/2,Hauteur/2,-1,CouleurFond)
      EndIf
  EndSelect
  
  ;Texte
  If CouleurFond=-1
    CouleurFond=CouleurFond0
  EndIf
  
  DecalageGauche=10
  DrawText(DecalageGauche, 0, Texte$ , CouleurTexte, CouleurFond)
  
  StopDrawing()
  
  DisableGadget(IDGadget,1)
  
  ProcedureReturn IDGadget
EndProcedure


Procedure InitWindow_0()
  Window_0 = OpenWindow(#PB_Any, 0, 0, 600, 400, "Frame3DEx", #PB_Window_SystemMenu)
  
  Frame3DEx0 = Frame3DEx(#PB_Any, 50, 20, 500, 100, 0, " Frame3DEx.",0, #Red)
  ;SetGadgetAttribute(Frame3DEx0, #PB_Canvas_Cursor, #PB_Cursor_Cross)
  
  Frame3DEx1 = Frame3DEx(#PB_Any, 50, 140, 500, 100, 0, "Texte1",#PB_Frame3D_Single,#Blue,#Blue,-1,PoliceID)
  Frame3DEx2 = Frame3DEx(#PB_Any, 50, 260, 140, 130, 0, "Texte2",#PB_Frame3D_Double,#Green,#Red)
  Frame3DEx3 = Frame3DEx(#PB_Any, 230, 260, 130, 130, 0, "Texte3",#PB_Frame3D_Flat,$808000,#Green,#White)
  Frame3DEx4 = Frame3DEx(#PB_Any, 410, 260, 140, 130, 20, "Une infobulle...",#PB_Frame3D_Flat,$80005D)
  ;GadgetToolTip(Frame3DEx4, "Un petit ToolTip !")
  
  Button0=ButtonGadget(#PB_Any, 60, 40, 50, 20, "TEST") 
  Explorer0=ExplorerListGadget(#PB_Any, 200, 40, 300, 75, "C:") 
  
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
      
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button0
          Select EventType()
            Case #PB_EventType_LeftClick       
              Debug " Clic sur le bouton"
              
              
          EndSelect
      EndSelect
  EndSelect
  
  ProcedureReturn #True
EndProcedure

InitWindow_0()


Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False
Dernière modification par Mesa le mar. 05/févr./2013 18:49, modifié 1 fois.
Avatar de l’utilisateur
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

Re: Gadget Frame3D

Message par graph100 »

Ok, mais ça ne permet pas la principale utilisation des frame3D, qui est d'encadrer d'autres gadgets. En soit un frame3d ne sert à rien, (juste à regrouper des éléments d'interface).

Modifie ta procedure de fenetre par la suivante qui souligne le problème : il est impossible d'interagir normalement avec les gadgets.

Code : Tout sélectionner

Procedure InitWindow_0()
	Window_0 = OpenWindow(#PB_Any, 0, 0, 600, 400, "Frame3DEx", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	
	Frame3DEx0 = Frame3DEx(#PB_Any, 50, 20, 500, 100, 0, " Le curseur est une croix ! Cliquer svp.",0, #Red)
	SetGadgetAttribute(Frame3DEx0, #PB_Canvas_Cursor, #PB_Cursor_Cross)
	Frame3DEx1 = Frame3DEx(#PB_Any, 50, 140, 500, 100, 0, "Texte1",#PB_Frame3D_Single,#Blue,#Blue,-1,PoliceID)
	Frame3DEx2 = Frame3DEx(#PB_Any, 50, 260, 140, 130, 0, "Texte2",#PB_Frame3D_Double,#Green,#Red)
	Frame3DEx3 = Frame3DEx(#PB_Any, 230, 260, 130, 130, 0, "Texte3",#PB_Frame3D_Flat,$808000,#Green,#White)
	Frame3DEx4 = Frame3DEx(#PB_Any, 410, 260, 140, 130, 20, "Une infobulle...",#PB_Frame3D_Flat,$80005D)
	GadgetToolTip(Frame3DEx4, "Un petit ToolTip !")
	
	ButtonGadget(#PB_Any, 60, 40, 50, 20, "TEST")
	ExplorerListGadget(#PB_Any, 200, 40, 300, 75, "C:")
	
	
EndProcedure
_________________________________________________
Mon site : CeriseCode (Attention Chantier perpétuel ;))
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: Gadget Frame3D

Message par Mesa »

J'ai modifié le code, c'est mieux ?

Mesa.
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Gadget Frame3D

Message par nico »

Bien joué le coup du disable, marche impec!
Avatar de l’utilisateur
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

Re: Gadget Frame3D

Message par graph100 »

Nickel :D

Il faudrait regarder si le comportement à l'affichage est le même sur mac et linux !
D'ailleurs je ne comprend pas bien pourquoi le canvas reste en dessous...

[edit] Ca dépend de l'ordre de création des gadgets ! Il faut créer les Frames3DEx en premier.
_________________________________________________
Mon site : CeriseCode (Attention Chantier perpétuel ;))
Répondre