Opinion sur un composant TTreePanel

Résolu
Utilisateur anonyme - 11 févr. 2008 à 10:25
 Utilisateur anonyme - 12 févr. 2008 à 09:00
Salut à tous,

Ca commence à etre de notoriété internationale : Francky et le Design, ca fait deux .
Alors quitte à faire un truc autant faire un truc sympas : Et c'est là ou j'ai besoin de vous (Il y a un de ces silences tout à coup : j'entends meme les quenottes de Cari ).

J'ai fais un petit composant : une sorte de TreeView ultra élémentaire qui utilise des Panels.

Voila le code :

unit Browser;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, Menus, Graphics, Dialogs ;

Type
  TInstrument = record
    Channel:Cardinal;
    Instrument:Cardinal;
    SoundFont:String;
    Bank:Cardinal;
    Asio:string;
    Panel:TPanel;
    TPopupMenu:TPopupMenu;
    Actived:Boolean;
  End;

Type
  TSoundFont = record
    FileName:String;
    Panel:TPanel;
    TPopupMenu:TPopupMenu;
    Actived:Boolean;
  End;

Type
  TASio = record
    FileName:String;
    Panel:TPanel;
    TPopupMenu:TPopupMenu;
    Actived:Boolean;
  End;

type
  TBrowser = class(TCustomControl)
  private
    fInstrumentList:Array[0..127] of TInstrument;
    fInstrumentPanel:TPanel;
    fSoundFontPanel:TPanel;
    fASioPanel:TPanel;
    fSoundFontList:Array of TSoundFont;
    fAsioList:Array of TAsio;
    fColorPanel:TColor;
    fColorBackGround:TColor;
    fSelectColor:TColor;
    fInstrumentsVisible:Boolean;
    fInstrumentPopupMenu:TPopupMenu;
    fSoundFontsVisible:Boolean;
    fSoundFontPopupMenu:TPopupMenu;
    fASiosVisible:Boolean;
    fASioPopupMenu:TPopupMenu;
    Procedure SetColorPanel(Value:TColor);
    Procedure SetColorBackGround(Value:TColor);
    Procedure SetSelectColor(Value:TColor);
    Procedure SetInstrumentPopupMenu(Value:TPopupMenu);
    Procedure SetSoundFontPopupMenu(Value:TPopupMenu);
    Procedure SetAsioPopupMenu(Value:TPopupMenu);
    Procedure Create_InstrumentsPanel;
    Procedure InstrumentsOnClick(Sender:TObject);
    Procedure InstrumentPanelOnClick(Sender:TObject);
    Procedure SoundFontsOnClick(Sender:TObject);
    Procedure SoundFontPanelOnClick(Sender:TObject);
    Procedure AsiosOnClick(Sender:TObject);
    Procedure AsioPanelOnClick(Sender:TObject);
  protected
    { Déclarations protégées }
  public
   Procedure Add_SoundFont(Value:String);
   Procedure Add_Asio(Value:String);
   Procedure Paint; override;
   constructor Create(AOwner:TComponent); override;
   destructor Destroy; override;
  published
    Property ColorPanel:TColor Read fColorPanel Write SetColorPanel;
    Property ColorBackGround:TColor Read fColorBackGround Write SetColorBackGround;
    Property SelectColor:TColor Read fSelectColor Write SetSelectColor;
    Property InstrumentPopupMenu:TPopupMenu Read fInstrumentPopupMenu Write SetInstrumentPopupMenu;
    Property SoundFontPopupMenu:TPopupMenu Read fSoundFontPopupMenu Write SetSoundFontPopupMenu;
    Property AsioPopupMenu:TPopupMenu Read fAsioPopupMenu Write SetAsioPopupMenu;              
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('MUSIC_PRO', [TBrowser]);
end;

constructor TBrowser.Create(AOwner:TComponent);
begin
  inherited Create(AOwner);
  fInstrumentPanel:=TPanel.Create(Self);
  fInstrumentPanel.Parent:=Self;
  Self.fInstrumentsVisible:=True;
  fInstrumentPanel.OnClick:=InstrumentPanelOnClick;
  Create_InstrumentsPanel;

  fSoundFontPanel:=TPanel.Create(Self);
  fSoundFontPanel.Parent:=Self;
  Self.fSoundFontsVisible:=True;
  fSoundFontPanel.OnClick:=SoundFontPanelOnClick;

  fAsioPanel:=TPanel.Create(Self);
  fAsioPanel.Parent:=Self;
  Self.fAsiosVisible:=True;
  fAsioPanel.OnClick:=AsioPanelOnClick;

  Initialize(fSoundFontList);
  Initialize(fAsioList);
end;

Procedure TBrowser.InstrumentPanelOnClick(Sender:TObject);
Begin
  Self.fInstrumentsVisible:=Not Self.fInstrumentsVisible;
  Self.Invalidate;
End;

Procedure TBrowser.SoundFontPanelOnClick(Sender:TObject);
Begin
  Self.fSoundFontsVisible:=Not Self.fSoundFontsVisible;
  Self.Invalidate;
End;

Procedure TBrowser.AsioPanelOnClick(Sender:TObject);
Begin
  Self.fAsiosVisible:=Not Self.fAsiosVisible;
  Self.Invalidate;
End;

Procedure TBrowser.SetColorPanel(Value:TColor);
Begin
  If Assigned(Self) Then
    Begin
      fColorPanel:=Value;
      Self.Invalidate;
    End;
End;

Procedure TBrowser.SetColorBackGround(Value:TColor);
Begin
  If Assigned(Self) Then
    Begin
      fColorBackGround:=Value;
      Self.Invalidate;
    End;
End;

Procedure TBrowser.SetSelectColor(Value:TColor);
Begin
  If Assigned(Self) Then
    Begin
      fSelectColor:=Value;
      Self.Invalidate;
    End;
End;

Procedure TBrowser.Create_InstrumentsPanel;
Const
  NameInstruments:Array [0..127] of String=
                  (   'Piano acoustique 1'
                      ,'Piano acoustique 2'
                      ,'Piano électrique'
                      ,'Piano HonkyTonk'
                      ,'Piano électrique 1'
                      ,'Piano électrique 2'
                      ,'Clavecin'
                      ,'Clavicorde'
                      ,'Célesta'
                      ,'Carillon'
                      ,'Boîte à musique'
                      ,'Vibraphone'
                      ,'Marimba'
                      ,'Xylophone'
                      ,'Cloches tubulaires'
                      ,'Tympanon'
                      ,'Orgue à tubes'
                      ,'Orgue percussif'
                      ,'Orgue rock'
                      ,'Orgue église'
                      ,'Orgue vibrato'
                      ,'Accordéon'
                      ,'Harmonica'
                      ,'Accordéon tango'
                      ,'Guitare classique'
                      ,'Guitare folk'
                      ,'Guitare electrique Jazz'
                      ,'Guitare electrique claire'
                      ,'Guitare electrique muted'
                      ,'Guitare saturée'
                      ,'Guitare à distorsion'
                      ,'Harmoniques'
                      ,'Basse acoustique'
                      ,'Basse  electrique(doigt)'
                      ,'Basse  electrique (medium)'
                      ,'Basse fretless'
                      ,'Basse Slap  1'
                      ,'Basse Slap  2'
                      ,'Basse Synthé  1'
                      ,'Basse  Synthé 2'
                      ,'Violon'
                      ,'Viole'
                      ,'Violoncelle'
                      ,'Contrebasse'
                      ,'Cordes tremolo'
                      ,'Cordes pizzicato'
                      ,'Harpe'
                      ,'Timbales'
                      ,'Quartet cordes 1'
                      ,'Quartet cordes 2'
                      ,'Cordes synthé 1'
                      ,'Cordes synthé 2'
                      ,'Chœurs Aahs'
                      ,'Voix Oohs'
                      ,'Voix synthé'
                      ,'Coup orchestre'
                      ,'Trompette'
                      ,'Trombone'
                      ,'Tuba'
                      ,'Trompette bouchée'
                      ,'Cors'
                      ,'Ensemble de cuivres'
                      ,'Cuivres synthé 1'
                      ,'Cuivres synthé 2'
                      ,'Saxo soprano'
                      ,'Saxo alto'
                      ,'Saxo ténor'
                      ,'Saxo Baryton'
                      ,'Hautbois'
                      ,'Cors anglais'
                      ,'Basson'
                      ,'Clarinette'
                      ,'Piccolo'
                      ,'Flûte'
                      ,'Flûte à bec'
                      ,'Flûte de Pan'
                      ,'Bouteille'
                      ,'Shakuhachi'
                      ,'Sifflet'
                      ,'Ocarina'
                      ,'Signal carré'
                      ,'Signal dents de scie'
                      ,'Orgue à vapeur'
                      ,'Chiff'
                      ,'Charang'
                      ,'Voix solo'
                      ,'Quinte'
                      ,'Basse'
                      ,'New Age'
                      ,'Warm'
                      ,'Polysynth'
                      ,'Chœur'
                      ,'Archet'
                      ,'Métallique'
                      ,'Halo'
                      ,'Sweep'
                      ,'Pluie'
                      ,'Bande son'
                      ,'Cristal'
                      ,'Atmosphère'
                      ,'Brightness'
                      ,'Goblins'
                      ,'Echos'
                      ,'Scie '
                      ,'Sitar'
                      ,'Banjo'
                      ,'Shamisen'
                      ,'Koto'
                      ,'Kalimba'
                      ,'Cornemuse'
                      ,'Violon folklorique'
                      ,'Shanai'
                      ,'Sonnerie'
                      ,'Agogo'
                      ,'Percussion acier'
                      ,'Woodblock'
                      ,'Taiko'
                      ,'Tom mélodique'
                      ,'Percussion synthé'
                      ,'Cymbale inversée'
                      ,'Cordes guitares'
                      ,'Respiration'
                      ,'Rivage'
                      ,'Chant oiseaux'
                      ,'Sonnerie téléphone'
                      ,'Hélicoptère'
                      ,'Applaudissements'
                      ,'Coup de feu');
Var
  Index:Cardinal;
Begin
  For Index:=0 To 127 Do
  With fInstrumentList[Index] Do
    Begin
      Channel:=0;
      Panel:=TPanel.Create(Self);
      Panel.Parent:=Self;
      Panel.OnClick:=InstrumentsOnClick;
      Panel.Tag:=Index;
      Actived:=False;
      Font.Color:=ClBlack;
      Font.Color:=ClWhite;
      Panel.Caption:=NameInstruments[Index];
    End;
End;

Procedure TBrowser.Add_SoundFont(Value:String);
Begin
  SetLength(fSoundFontList,High(fSoundFontList)+2);
  With fSoundFontList[High(fSoundFontList)] Do
    Begin
      FileName:=Value;
      Panel:=TPanel.Create(Self);
      Panel.Parent:=Self;
      Panel.OnClick:=SoundFontsOnClick;
      Panel.Tag:=High(fSoundFontList);
      Actived:=False;
      Font.Color:=Clwhite;
      Panel.Caption:=ExtractFileName(FileName);
    End;
  Self.Invalidate;
End;

Procedure TBrowser.Add_Asio(Value:String);
Begin
  SetLength(fAsioList,High(fAsioList)+2);
  With fAsioList[High(fAsioList)] Do
    Begin
      FileName:=Value;
      Panel:=TPanel.Create(Self);
      Panel.Parent:=Self;
      Panel.OnClick:=AsiosOnClick;
      Panel.Tag:=High(fAsioList);
      Actived:=False;
      Font.Color:=Clwhite;
      Panel.Caption:=ExtractFileName(FileName);
    End;
  Self.Invalidate;
End;

Procedure TBrowser.InstrumentsOnClick(Sender:TObject);
Var
  Number,Index:Cardinal;
Begin
  Number:=0;
  If (Sender is TPanel) Then
  Number:=(Sender As TPanel).Tag;
  For Index:=0 To 127 Do
  fInstrumentList[Index].Actived:=False;
  fInstrumentList[Number].Actived:=True;
  Self.Invalidate;
End;

Procedure TBrowser.SoundFontsOnClick(Sender:TObject);
Var
  Number,Index:Cardinal;
Begin
  Number:=0;
  If (Sender is TPanel) Then
  Number:=(Sender As TPanel).Tag;
  For Index:=Low(fSoundFontList) To High(fSoundFontList) Do
  fSoundFontList[Index].Actived:=False;
  fSoundFontList[Number].Actived:=True;
  Self.Invalidate;
End;

Procedure TBrowser.AsiosOnClick(Sender:TObject);
Var
  Number,Index:Cardinal;
Begin
  Number:=0;
  If (Sender is TPanel) Then
  Number:=(Sender As TPanel).Tag;
  For Index:=Low(fAsioList) To High(fAsioList) Do
  fAsioList[Index].Actived:=False;
  fAsioList[Number].Actived:=True;
  Self.Invalidate;
End;

Procedure TBrowser.SetInstrumentPopupMenu(Value:TPopupMenu);
Begin
  fInstrumentPopupMenu:=Value;
  Self.Invalidate;
End;

Procedure TBrowser.SetSoundFontPopupMenu(Value:TPopupMenu);
Begin
  fSoundFontPopupMenu:=Value;
  Self.Invalidate;
End;

Procedure TBrowser.SetAsioPopupMenu(Value:TPopupMenu);
Begin
  fAsioPopupMenu:=Value;
  Self.Invalidate;
End;

Procedure TBrowser.Paint;
Var
  Index, IndexTop:Cardinal;
Begin
  Self.Color:=Self.fColorBackGround;
  IndexTop:=0;
  With fInstrumentPanel Do
    Begin
      Width:=Self.Width-2;
      Height:=30;
      Top:=IndexTop*32;
      Left:=0;
      Color:=Self.fColorPanel;
      Caption:='INSTRUMENT';
    End;
  For Index:=0 To 127 Do
  With fInstrumentList[Index] Do
    Begin
      Panel.Width:=Round(Self.Width*0.90)-2;
      Panel.Height:=30;
      Panel.Top:=32*IndexTop+32;
      Panel.Left:=Round(Self.Width*0.1);
      If Not Actived Then Panel.Color:=Self.fColorPanel Else
      Panel.Color:=Self.fSelectColor;
      Panel.Visible:=Self.fInstrumentsVisible;
      If Panel.Visible Then Inc(IndexTop);
      if Assigned(fInstrumentPopupMenu) Then Panel.PopupMenu:=fInstrumentPopupMenu;
    End;

  With fSoundFontPanel Do
    Begin
      Width:=Self.Width-2;
      Height:=30;
      Top:=32*IndexTop+32;
      Left:=0;
      Color:=Self.fColorPanel;
      Caption:='SOUNDFONT';
      Inc(IndexTop);
    End;
  If High(fSoundFontList)>-1 Then
  For Index:=Low(fSoundFontList) To High(fSoundFontList) Do
  With fSoundFontList[Index] Do
    Begin
      Panel.Width:=Round(Self.Width*0.90)-2;
      Panel.Height:=30;
      Panel.Top:=32*IndexTop+32;
      Panel.Left:=Round(Self.Width*0.1);
      If Not Actived Then Panel.Color:=Self.fColorPanel Else
      Panel.Color:=Self.fSelectColor;
      Panel.Visible:=Self.fSoundFontsVisible;
      If Panel.Visible Then Inc(IndexTop);
      if Assigned(fSoundFontPopupMenu) Then Panel.PopupMenu:=fSoundFontPopupMenu;
    End;

  With fAsioPanel Do
    Begin
      Inc(IndexTop);
      Width:=Self.Width-2;
      Height:=30;
      Top:=IndexTop*32;
      Left:=0;
      Color:=Self.fColorPanel;
      Caption:='ASIO';
    End;
  If High(fAsioList)>-1 Then
  For Index:=Low(fAsioList) To High(fAsioList) Do
  With fAsioList[Index] Do
    Begin
      Panel.Width:=Round(Self.Width*0.90)-2;
      Panel.Height:=30;
      Panel.Top:=32*IndexTop+32;
      Panel.Left:=Round(Self.Width*0.1);
      If Not Actived Then Panel.Color:=Self.fColorPanel Else
      Panel.Color:=Self.fSelectColor;
      Panel.Visible:=Self.fAsiosVisible;
      If Panel.Visible Then Inc(IndexTop);
      if Assigned(fAsioPopupMenu) Then Panel.PopupMenu:=fAsioPopupMenu;
    End;
  Self.Height:=(IndexTop+1)*32;   
End;

destructor TBrowser.Destroy;
Var
  Index:Cardinal;
begin
  fInstrumentPanel.Free;
  fSoundFontPanel.Free;
  fASioPanel.Free;
  If High(fSoundFontList)>-1 Then
  For Index:=0 To High(fSoundFontList) Do Self.fSoundFontList[Index].Panel.Free;
  If High(fAsioList)>-1 Then
  For Index:=0 To High(fAsioList) Do Self.fAsioList[Index].Panel.Free;
  Finalize(fSoundFontList);
  Finalize(fAsioList);
  inherited;
end;

end.

Je voudrais savoir ce que vous en pensez et surtout quelles fonctionnalités je pourrais ajouter, quel effet de Design apporter pour embéllir la chose ect ect.

Ben oué c'est pratique ce machin mais il est pas tres beau.

Merci à vous

Ps : Je m'associe à la cause de Delphiproglien (Ame sensible s'abstenir).
Si vous n'avez pas reussit à voir cette video en entière : Merci de participer à la pétition  par mail  PETA2@peta.org et n'hésitez pas à en faire part.Si on peut faire cesser le dépecage de chiens et de chats vivants, en Chine c'est maintenant ou jamais : Ca va etre les jeux olympiques. Ces animaux comptent sur vous

2 réponses

cs_cantador Messages postés 4720 Date d'inscription dimanche 26 février 2006 Statut Modérateur Dernière intervention 31 juillet 2021 13
11 févr. 2008 à 22:49
j'ai installé le compo !
bon, déjà :

- mettre un bel icone au compo
- revoir les couleurs (mettre un nuancier de couleurs) sur la fenêtre
  (car pas beau le noir..)
- faire un effet visuel au passage de la souris sur les instruments (ou la sélection en générale)
- prévoir un évènement OnClic sur la sélection avec un petit effet sonore (correspondant à l'instrument)
- gérer un ascenseur car la liste est bcp trop longue

voilà pour lé début..
et bien sûr, j'ai signé la pétition..
Car même si on ne peut porter de jugement sur les coutumes des autres pays
(sinon nous les taureaux etc..)
on ne peut accepter de dépecer un animal vivant.

cantador
3
Utilisateur anonyme
12 févr. 2008 à 09:00
Merci beaucoup Cantador.

Et je rejoins ce que tu as dis : Nul jugement est porté sur ce pays et ses habitants, mais dépecer un animal et le laissez mourir est un acte barbare et donc non acceptable.
0
Rejoignez-nous