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écupérer les valeurs des couleurs d'un style (entête de grille)


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 042
    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 042
    Points : 40 955
    Points
    40 955
    Billets dans le blog
    62
    Par défaut Récupérer les valeurs des couleurs d'un style (entête de grille)
    Bonjour,

    je tourne en rond sur ce sujet. J'ai besoin de récupérer les couleurs de texte et de fond des entêtes d'une grille en fonction du style utilisé.
    Nom : Capture.PNG
Affichages : 199
Taille : 9,0 Ko
    donc très certainement les deux éléments encadrés en rouge dans l'image

    j'arrive à accéder au header et à l'HeaderItem de cette manière

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    var Header : THeader;
                   HeaderItem : THeaderItem;
                   FMXObj : TFMXObj; 
                   TextColor, BackGroundColor : TAlphaColor;   
    begin
      Header:=THeader(MaGrille.FindStyleResource.('header'));
      if Assigned(Header) then
            begin
               HeaderItem:=Header.Items[i];        
               FMXObj:=HeaderItem.FindStyleResource('background');
               BackGroundColor:=TRectangle(FMXObj).Fill.Color;
               FMXObj:=HeaderItem.FindStyleResource('Text');
               TextColor:=TText(FMXObj).TextSettings.FontColor;
           end;
    Sauf que, si j'obtiens bien les valeurs indiquées dans le style (FFE0E0E0 une sorte de blanc/gris) je n'obtiens pas les valeurs escomptées.. le bleu
    Nom : Capture.PNG
Affichages : 190
Taille : 29,7 Ko
    pas de bol c'est un gradient
    la question comment obtenir la couleur 'moyenne' du gradient pour utiliser un ClearRect(couleur) ?
    question joker comment utiliser directement un gradient dans le cadre d'un FillRect ?

    l'objectif final ? un indicateur de position dans un TGrid (ou un stringgrid)
    Nom : Capture.PNG
Affichages : 177
Taille : 39,8 Ko
    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
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 042
    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 042
    Points : 40 955
    Points
    40 955
    Billets dans le blog
    62
    Par défaut
    Comme d'habitude, il fallait que je pose la question pour avoir la solution
    à la première question la réponse était Interpolate(50)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
           AFMXObj:=THeaderItem(HeaderItem).FindStyleResource('background');
           if assigned(AFMXObj) then AColor:=TRectangle(AFMXObj).Fill.Gradient.InterpolateColor(50);
    ce qui me permet d'obtenir. Je suis conscient qu'il me faille tester quand même le mode de remplissage du rectangle du style au cas où ce ne serait pas un gradient
    Nom : Capture.PNG
Affichages : 164
Taille : 39,6 Ko
    Note : je n'ai pas joué encore sur la couleur de la flèche qui selon moi devrait être de la couleur du texte

    reste la question joker (et la rotation à 90° du gradient récupéré tant qu'à faire les choses bien)
    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

  3. #3
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 042
    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 042
    Points : 40 955
    Points
    40 955
    Billets dans le blog
    62
    Par défaut un pas de plus
    Voilà, je me suis fait une petite fonction pour gérer tout ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
        function GetHeaderColors(Sender: TObject; var BackGroundColor,TextColor : TAlphaColor) : TBrush;
    Utilisation au sein du programme

    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
    procedure TForm15.Grid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas;
      const Column: TColumn; const Bounds: TRectF; const Row: Integer;
      const Value: TValue; const State: TGridDrawStates);
    var ARect : TRectF;
        ABrush : TBrush;
        ABackColor,ATextColor : TAlphaColor;
     
        procedure DrawTriangle(Bounds : TRectF; Color : TAlphaColor;
                               Direction : Word=0; Stretch : Word =1);
        var Points: array[0..2] of TPointF;
            Demi : Single;
            APath : TPath;
        begin
           if Stretch=1 then Demi:=Min(Column.Width,Bounds.Height)/2
                        else Demi:=Bounds.Height/2;
           if Direction=0 then
             begin
              Points[0] := PointF(Bounds.Left,Bounds.Top+Bounds.Height/2-Demi);
              Points[1] := PointF(Bounds.Left+Bounds.Width,Bounds.Top+(Bounds.Height/2));
              Points[2] := PointF(Bounds.Left,Bounds.Top+(Bounds.Height/2)+Demi);
             end
           else begin
              Points[0] := PointF(Bounds.Left,Bounds.Top+Bounds.Height/2);
              Points[1] := PointF(Bounds.Left+Bounds.Width,Bounds.Top+(Bounds.Height/2)-Demi);
              Points[2] := PointF(Bounds.Left+Bounds.Width,Bounds.Top+(Bounds.Height/2)+Demi);
           end;
           ABrush:=TBrush.Create(TBrushkind.Solid,Color);
           APath:=TPath.Create(Self);
            try
              APath.Data.MoveTo(Points[0]);
              APath.Data.LineTo(Points[1]);
              APath.Data.LineTo(Points[2]);
              APath.Data.ClosePath;
              Canvas.FillPath(APath.Data,1,ABrush);
            finally
              FreeAndNil(ABrush);
              FreeAndNil(APath);
            end;
        end;
     
        function GetHeaderColors(Sender: TObject; var BackGroundColor,TextColor : TAlphaColor) : TBrush;
        var Header : THeader;
            HeaderItem : THeaderItem;
            aFMXObj : TFMXObject;
            aGradient : TGradient;
        begin
          Header:=THeader((Sender as TGrid).FindStyleResource('header'));  
          if Assigned(Header) then
            begin
              HeaderItem := Header.Items[1];
              AFMXObj:=THeaderItem(HeaderItem).FindStyleResource('Text');
              TextColor:=TText(AFMXObj).TextSettings.FontColor;
              AFMXObj:=THeaderItem(HeaderItem).FindStyleResource('background');
              Result:=TRectangle(AFMXObj).Fill;
              if Result.Kind=TBrushKind.Gradient
               then BackGroundColor:=Result.Gradient.InterpolateColor(50)
               else BackGroundColor:=Result.DefaultColor;                         // hypothèse non testée
            end;
        end;
     
    begin
      ... 
      if Column.Name='Curseur' then
        begin
          ABrush:=GetHeaderColors(Sender,ABackColor,ATextColor);
          ARect:=TRectF.Create(Bounds);
          InflateRect(ARect,3,3);
          Canvas.ClearRect(ARect,ABackColor);
          Canvas.FillRect(ARect,0,0,[],1,ABrush);
          if Row=cds.RecNo-1 then
            DrawTriangle(Bounds,ATextColor,0,1);
        end;
      ... 
    end;
    Reste à passer le gradient de horizontal à vertical, des idées/pistes ?
    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 042
    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 042
    Points : 40 955
    Points
    40 955
    Billets dans le blog
    62
    Par défaut Fin du monologue
    Reste à passer le gradient de horizontal à vertical
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
      Result.Gradient.StartPosition.X:=1;
      Result.Gradient.StartPosition.Y:=1;
    rajouté dans la fonction GetHeaderColors semble faire l'affaire.
    Ceci écrit, c'est totalement empirique je ne comprend pas comment on utilise ces StartPositions, j'ai déduit cela à partir de http://docwiki.embarcadero.com/CodeE...dient_(Delphi)
    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 042
    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 042
    Points : 40 955
    Points
    40 955
    Billets dans le blog
    62
    Par défaut FAQ or not FAQ ?
    Citation Envoyé par SergioMaster Voir le message
    Ceci écrit, c'est totalement empirique
    Pour en terminer avec cet empirisme je suis aller fouiller dans les sources (le dialogue de la création du gradient)
    Cela m'a permis de créer une fonction qui permet de calculer les différentes positions (StartPosition, StopPosition) du gradient en fonction d'un angle

    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
    procedure TForm1.gradAngleChange(AGradient: TGradient; gradAngle : single);
    var
      X, Y, Koef: Single;
      Radian: Single;
      CosRadian: Single;
      SinRadian: Single;
    begin
      Radian := DegToRad(gradAngle);
      CosRadian := Cos(Radian);
      SinRadian := Sin(Radian);
      if (CosRadian <> 0) and (Abs(1 / CosRadian) >= 1) and (Abs(1 / CosRadian) <= 1.42) then
        X := Abs(1 / CosRadian)
      else
        X := 1;
     
      if (SinRadian <> 0) and (Abs(1 / SinRadian) >= 1) and (Abs(1 / SinRadian) <= 1.42) then
        Y := Abs(1 / SinRadian)
      else
        Y := 1;
      Koef := Max(X, Y);
      Koef := Koef * 0.5;
      AGradient.StartPosition.Point := PointF(0.5 - (CosRadian * Koef), 0.5 + (SinRadian * Koef));
      AGradient.StopPosition.Point := PointF(0.5 + (CosRadian * Koef), 0.5 - (SinRadian * Koef));
    end;
    exemple d'utilisation

    soit une forme composée d'un rectangle (Rectangle1) , un bouton (Button1) et un bouton rond (ArcDial1)
    Nom : Capture.PNG
Affichages : 154
Taille : 3,8 Ko

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    // onChange de ArcDial1
    procedure TForm1.ArcDial1Change(Sender: TObject);
    begin
    gradAngleChange(Rectangle1.Fill.Gradient,ArcDial1.value);
    end;
    // onClick de Button1
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    gradAngleChange(Rectangle1.Fill.Gradient,0);
    end;
    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

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 09/10/2006, 21h31
  2. [C#-XML] Récupérer les valeurs des noeuds enfants
    Par cyllix dans le forum Windows Forms
    Réponses: 1
    Dernier message: 23/06/2006, 11h54
  3. Récupérer les valeurs des champs créés dynamiquement
    Par outlawz dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 03/05/2006, 16h32
  4. [PHP-JS] Récupérer les valeurs des checkbox
    Par jamirokoi dans le forum Langage
    Réponses: 3
    Dernier message: 07/04/2006, 16h24
  5. Réponses: 4
    Dernier message: 05/01/2006, 20h29

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