IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants FMX Delphi Discussion :

Répartir 12 libellés de façon circulaire


Sujet :

Composants FMX Delphi

  1. #1
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 017
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 017
    Points : 40 932
    Points
    40 932
    Billets dans le blog
    62
    Par défaut Répartir 12 libellés de façon circulaire
    Bonjour,

    mon challenge du week-end afficher une horloge (pas les aiguilles mais les chiffres) de façon à avoir cette impression d'horloge circulaire.
    Oui, vous commencez à le deviner, c'est suite à cette discussion
    Je vais replonger dans les démos de Thierry Laborde, je me souviens de son horloge j'ai retrouvé des sources (c'est pas du récent XE5) et la vidéo explicative (Dev du Jeudi du 14 novembre 2013


    J'ai plus qu'à. A moins que quelqu'un n'ai en tête un composant/dépôt déjà existant ?
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  2. #2
    Membre expert
    Avatar de pprem
    Homme Profil pro
    MVP Embarcadero - formateur&développeur Delphi, PHP et JS
    Inscrit en
    Juin 2013
    Messages
    1 876
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : MVP Embarcadero - formateur&développeur Delphi, PHP et JS
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 1 876
    Points : 3 611
    Points
    3 611
    Par défaut
    mettre tous les chiffres au même endroit et simplement jouer sur l'angle de rotation en basculant le pivot sur le centre du composant ?

  3. #3
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 017
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 017
    Points : 40 932
    Points
    40 932
    Billets dans le blog
    62
    Par défaut
    J'ai un premier jus, bâti autour de l'exemple de Thierry (des TLayouts dans un cercle)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    unit UHorloge;
    
    interface
    
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
      FMX.Layouts, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Ani;
    
    type
      TForm1 = class(TForm)
        Circle5: TCircle;
        Button1: TButton;
        ColorAnimation1: TColorAnimation;
        procedure Button1Click(Sender: TObject);
      private
        { Déclarations privées }
        procedure CircleClick(Sender : Tobject);
      public
        { Déclarations publiques }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.fmx}
    
    procedure TForm1.Button1Click(Sender: TObject);
    var i : Word;
        aLayout : TLayout;
        aCircle : TCircle;
    begin
    for i := 0 to 11 do
      begin
        aLayout:=Tlayout.Create(Circle5);
        aLayout.Parent:=circle5;
        aLayout.Width:=60;
        aLayout.Height:=Circle5.Height-50;
        aLayout.Align:=TAlignLayout.VertCenter;
        aLayout.RotationAngle:=i*30;
        aLayout.HitTest:=False;
        acircle:=TCircle.Create(aLayout);
        acircle.parent:=aLayout;
        acircle.width:=58;
        acircle.height:=58;
        acircle.Stroke.Kind:=TBrushKind.None;
        acircle.Fill.Color:=TAlphaColors.Aliceblue;
        acircle.align:=TAlignLayout.Top;
        aCircle.HitTest:=True;
        aCircle.Tag:=i;
        aCircle.OnClick:=CircleClick;
        with TcolorAnimation.Create(aCircle) do
         begin
           parent:=aCircle;
           propertyname:='Fill.color';
           startValue:=Talphacolors.Aliceblue;
           StopValue:=Talphacolors.Aquamarine;
           Trigger:='IsMouseOver=true';
           TriggerInverse:='IsMouseOver=False';
         end;
        with Tlabel.Create(aCircle) do
         begin
           Parent:=aCircle;
           text:=I.ToString;
           Align:=TAlignLayout.Client;
           textSettings.HorzAlign:=TTextAlign.Center;
           RotationAngle:=360-aLayout.rotationAngle;
           HitTest:=False;
         end;
      end;
    end;
    
    procedure TForm1.CircleClick(Sender: Tobject);
    begin
    Showmessage(TCircle(Sender).Tag.ToString);
    end;
    
    end.
    mais plusieurs choses ne vont pas, en rouge les valeurs trouvées par tâtonnement
    Nom : Capture_1.PNG
Affichages : 99
Taille : 20,8 Ko
    Mais c'est la ColorAnimation qui ne fonctionne pas bien (je vais tenter d'en faire une petite vidéo pour le montrer)

    Mais tu as raison, jouer sur l'angle de rotation n'est peut-être pas suffisant , jouer sur le pivot ? je vais y réfléchir
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  4. #4
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 017
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 017
    Points : 40 932
    Points
    40 932
    Billets dans le blog
    62
    Par défaut Trigonométrie appliquée
    Alors, une chose qui me plait mieux.

    Selon ce que j'ai lu les positions sur un cercle peuvent se calculer X=R*Cos(AngleenRadian) Y=R*sin(AngleenRadian)
    cela donnerait donc ce code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    procedure TForm1.Button2Click(Sender: TObject);
    var i : Word;
        aCircle : TCircle;
        LCenter : TPointF;
        R,RadAngle: Single;
    
    begin
       Lcenter:=TPointf.Create(Layout1.Width/2,Layout1.Height/2);
       R:=Layout1.Width/2;
    
    for i := 0 to 11 do
      begin
        acircle:=TCircle.Create(Layout1);
        acircle.parent:=Layout1;
        acircle.width:=40;
        acircle.height:=40;
        acircle.Stroke.Kind:=TBrushKind.None;
        acircle.Fill.Color:=TAlphaColors.Aqua;
        acircle.align:=TAlignLayout.Top;
        aCircle.HitTest:=True;
        aCircle.Tag:=i;
        RadAngle:=DegToRad(30*i);
        aCircle.Position.X:=LCenter.X + (R * cos(RadAngle))-20;
        aCircle.Position.Y:=LCenter.Y + (R * sin(RadAngle))-20;
        aCircle.OnClick:=CircleClick;
        with TcolorAnimation.Create(aCircle) do
         begin
           parent:=aCircle;
           propertyname:='Fill.color';
           startValue:=Talphacolors.Aliceblue;
           StopValue:=Talphacolors.Aquamarine;
           Trigger:='IsMouseOver=true';
           TriggerInverse:='IsMouseOver=False';
         end;
        with TLabel.Create(aCircle) do
         begin
           Parent:=aCircle;
           text:=I.ToString;
           Align:=TAlignLayout.Client;
           textSettings.HorzAlign:=TTextAlign.Center;
           HitTest:=False;
         end;
      end;
    end;
    sauf que j'ai un résultat plutôt décevant
    Nom : Capture.PNG
Affichages : 88
Taille : 16,1 Ko
    j'ai merdé quelque part ! Effectivement acircle.align:=TAlignLayout.Top; reste d'un copier coller me mettait dans la panade !

    Nom : Capture.PNG
Affichages : 103
Taille : 13,0 Ko

    pour demain :
    mon 0 n'est pas en haut pour cela une modification du calcul de l'angle sera nécessaire
    ajouter un cercle qui englobe le tout et, tant qu'à faire un cercle inscrit.
    s'amuser à faire une horloge à la Dali (une élipse plutôt qu'un cercle cela pourrait être sympa ) peut-être grace à un scaledlayout ?
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  5. #5
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 017
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 017
    Points : 40 932
    Points
    40 932
    Billets dans le blog
    62
    Par défaut
    Citation Envoyé par SergioMaster Voir le message
    pour demain :
    • mon 0 n'est pas en haut pour cela une modification du calcul de l'angle sera nécessaire
    • ajouter un cercle qui englobe le tout

    première solution, faire une rotation du Layout parent RotationAngle:=-90 et rectifier l'angle du Tlabel enfant (rotationAngle:=90)
    J'en ai profité pour intégrer les 24 heures et le cercle
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    procedure TForm1.Button2Click(Sender: TObject);
    var i : Word;
     
        LCenter : TPointF;
        R : Single;
     
        procedure AddCircle(Valeur : Integer; AM : Boolean);
        var aCircle : TCircle;
            RadAngle: Single;
            wR : Single;
        begin
          if Am then wR:=R else Wr:=R-45;
     
          acircle:=TCircle.Create(Layout1);
          acircle.parent:=Layout1;
          acircle.width:=40;
          acircle.height:=40;
          acircle.Stroke.Kind:=TBrushKind.None;
          acircle.Fill.Color:=TAlphaColors.Aqua;
          aCircle.HitTest:=True;
          aCircle.Tag:=valeur;
          RadAngle:=DegToRad(30*valeur);
          aCircle.Position.X:=LCenter.X + (wR * cos(RadAngle))-20;
          aCircle.Position.Y:=LCenter.Y + (wR * sin(RadAngle))-20;
          aCircle.OnClick:=CircleClick;
          with TcolorAnimation.Create(aCircle) do
           begin
             parent:=aCircle;
             propertyname:='Fill.color';
             startValue:=Talphacolors.Aliceblue;
             StopValue:=Talphacolors.Aquamarine;
             Trigger:='IsMouseOver=true';
             TriggerInverse:='IsMouseOver=False';
           end;
          with TLabel.Create(aCircle) do
           begin
             Parent:=aCircle;
             text:=Valeur.ToString;
             rotationAngle:=90;
             Align:=TAlignLayout.Client;
             textSettings.HorzAlign:=TTextAlign.Center;
             HitTest:=False;
           end;
        end;
     
    begin
       Lcenter:=TPointf.Create(Layout1.Width/2,Layout1.Height/2);
       R:=Layout1.Width/2;
     
    for i := 0 to 11 do
      begin
        AddCircle(i,True);
        AddCircle(i+12,false);
      end;
     
    with Tcircle.Create(Layout1)
    do begin
      parent:=Layout1;
      Height:=R*2 + 41 ;
      Width:=R*2 + 41 ;
      Stroke.Thickness:=1;
      Align:=TalignLayout.Center;
      Fill.Color:=TalphaColors.Null;
      HitTest:=False;
    end;
     
    end;
    Nom : Capture.PNG
Affichages : 86
Taille : 21,3 Ko

    Le cercle inscrit ? Tout aussi facile cela ne vaut pas le coup de se pencher dessus

    s'amuser à faire une horloge à la Dali (une élipse plutôt qu'un cercle cela pourrait être sympa ) peut-être grace à un scaledlayout ?
    C'est pas du Dali mais c'est jouable
    Nom : Capture_1.PNG
Affichages : 87
Taille : 17,7 Ko

    Je m'atteler m'atteler à "l'aiguille" de sélection de même qu'à la partie minute
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  6. #6
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 017
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 017
    Points : 40 932
    Points
    40 932
    Billets dans le blog
    62
    Par défaut
    Citation Envoyé par SergioMaster Voir le message
    Je m'atteler m'atteler à "l'aiguille" de sélection
    c'est pas encore au point

    https://serge-girard.developpez.com/...p/horloge.webm

    comme vous pouvez le constater sur la vidéo un bogue sur les heures 11, 23 et 22 a priori dans ce morceau de code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    // Ajouté dans la création de "l'horloge"
    aiguille:=Tlayout.Create(Layout1);
    aiguille.Parent:=Layout1;
    aiguille.Width:=4;
    aiguille.Height:=layout1.Height;
    aiguille.Align:=TAlignLayout.None;
    aiguille.Position.X:=LCenter.X-2;
    aiguille.Padding.top:=0;
    aiguille.Padding.Bottom:=R;
    aiguille.visible:=false;
    with Trectangle.Create(aiguille) do
     begin
       parent:=aiguille;
       align:=TalignLayout.client;
       fill.Color:=Talphacolors.Black;
       rotationangle:=0;
     end;
     
     
    procedure TForm1.CircleClick(Sender: Tobject);
    var bCircle : Single;
        couronne : integer;
    begin
    couronne:=(Tcircle(Sender).tag div 11)+1;
    bCircle:=Tcircle(Sender).Height*couronne - 20;  // pb de calcul
    aiguille.Padding.top:=bcircle;
    aiguille.RotationAngle:=30*Tcircle(Sender).tag;
    aiguille.Visible:=true;
    end;
    [Edit] une erreur bête de diviseur ! avec couronne:=(Tcircle(Sender).tag div 12)+1;
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

Discussions similaires

  1. [XL-2007] Comment reformater des libellés de façon dynamique ?
    Par leinadjan dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 18/02/2013, 22h24
  2. Réponses: 0
    Dernier message: 09/04/2010, 14h02
  3. ordonner un ensemble de points de façon circulaire
    Par Valais04 dans le forum Algorithmes et structures de données
    Réponses: 9
    Dernier message: 20/02/2009, 16h18
  4. Réponses: 2
    Dernier message: 26/07/2007, 17h08
  5. Réponses: 3
    Dernier message: 06/05/2002, 19h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo