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

 Delphi Discussion :

Problème de positionnement d'une ligne suivant l'épaisseur


Sujet :

Delphi

  1. #1
    Membre éclairé
    Profil pro
    Développeur Java
    Inscrit en
    Mars 2004
    Messages
    624
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Mars 2004
    Messages : 624
    Points : 681
    Points
    681
    Par défaut Problème de positionnement d'une ligne suivant l'épaisseur
    Bonjour,

    dans un TGraphicControl je trace une ligne tout en haut (position 0,0). Si la ligne fait 1 ou 2 pixels, pas de problème mais s'il fait 3 ou plus, tout ne se trace pas.
    Ainsi pour 5 pixel, on que 2 pixels.
    J'en déduis donc que lorsqu'il trace le trait il met 2 pixel d'un côté, et 3 de l'autre.
    Comment faire alors pour avoir bien 5 pixels sur les bordures ?

    Voici mon 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
        { 1 - Dessiner le rectangle }
        Canvas.Brush.Style := bsSolid ;
        Canvas.Brush.Color := FBackColor ;
        Canvas.Pen.Style := psSolid ;
        Canvas.Pen.Color := FBackColor ;
     
        Rect.Top := FBorderSize ;
        Rect.Left := FBorderSize ;
        Rect.Right := Self.Width - FBorderSize ;
        Rect.Bottom := Self.Height - FBorderSize ;
     
        { On soustrait le texte du rectangle }
        if FTextPosition in [tpBottomCenter, tpBottomLeft, tpBottomRight]
        then begin
            Rect.Bottom := Rect.Bottom - TextHeight ;
        end ;
     
        Canvas.FillRect(Rect);
     
        Canvas.Pen.Style := psSolid ;
        Canvas.Pen.Color := FBorderColor ;
        Canvas.Pen.Width := FBorderSize ;
     
        Canvas.MoveTo(0,0);
        Canvas.LineTo(Self.Width - 1, 0);
     
        if FTextPosition in [tpBottomCenter, tpBottomLeft, tpBottomRight]
        then begin
            Canvas.LineTo(Self.Width - 1, Self.Height - 1 - TextHeight) ;
            Canvas.LineTo(0, Self.Height - 1 - TextHeight) ;
        end
        else begin
            Canvas.LineTo(Self.Width - 1, Self.Height - 1) ;
            Canvas.LineTo(0, Self.Height - 1) ;
        end ;
     
        Canvas.LineTo(0, 0);
    Merci

  2. #2
    Modérateur

    Homme Profil pro
    Ingénieur retraité
    Inscrit en
    Octobre 2005
    Messages
    2 396
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur retraité

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 396
    Points : 3 263
    Points
    3 263
    Par défaut
    Salut,

    Lorsqu'on a pen.width > 1 , le LineTo[x,y] met effectivement une moitié de l'épaisseur du trait d'un côté, et l'autre moitié de l'autre côté.
    Comment faire alors pour avoir bien 5 pixels sur les bordures ?
    ... suffit de tracer avec des x,y décalés de pen.width div 2 vers l'intérieur des bords ... ou de 1 + pen.width div 2 dans le cas où pen.width est impair et que le tracé rognerait d'un pixel sur l'extérieur de certains bords.

    A+
    N'oubliez pas de consulter les FAQ Delphi et les cours et tutoriels Delphi

  3. #3
    Membre éclairé
    Profil pro
    Développeur Java
    Inscrit en
    Mars 2004
    Messages
    624
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Mars 2004
    Messages : 624
    Points : 681
    Points
    681
    Par défaut
    Je vais tracer plusieurs fois le trait, c'est plus simple

  4. #4
    Modérateur

    Homme Profil pro
    Ingénieur retraité
    Inscrit en
    Octobre 2005
    Messages
    2 396
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur retraité

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 396
    Points : 3 263
    Points
    3 263
    Par défaut
    Re-Salut,

    Et t'as vérifié si ça marche bien dans le cas de Pen.width = valeur impaire ? Par exemple avec 7 ? Car avec DecalageHaut:=FBorderSize div 2 ; 7 div 2 = 3 alors que 2*3 fait seulement 6 et il risque de manquer une bande large d'un pixel si le lineTo met 4 vers l'extérieur et 3 vers l'intérieur.

    A+
    N'oubliez pas de consulter les FAQ Delphi et les cours et tutoriels Delphi

  5. #5
    Membre éclairé
    Profil pro
    Développeur Java
    Inscrit en
    Mars 2004
    Messages
    624
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Mars 2004
    Messages : 624
    Points : 681
    Points
    681
    Par défaut
    je vais trace des rectangles. Car sinon, le bout de la ligne est ront et c'est moche

    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
        Canvas.Pen.Style := psSolid ;
        Canvas.Brush.Color := FBorderColor ;
     
        { Trait du haut }
        LineRect.Top := 0 ;
        LineRect.Left := 0 ;
        LineRect.Right := Self.Width ;
        LineRect.Bottom := FBorderSize ;
     
        Canvas.FillRect(LineRect) ;
     
        if FTextPosition in [tpBottomCenter, tpBottomLeft, tpBottomRight]
        then begin
            { trait de droite }
            LineRect.Top := 0 ;
            LineRect.Left := Self.Width - FBorderSize ;
            LineRect.Right := Self.Width ;
            LineRect.Bottom := Self.Height - TextHeight ;
     
            Canvas.FillRect(LineRect) ;
     
            { Trait du bas }
            LineRect.Top := Self.Height - TextHeight - FBorderSize ;
            LineRect.Left := 0 ;
            LineRect.Right := Self.Width ;
            LineRect.Bottom := LineRect.Top +FBorderSize ;
     
            Canvas.FillRect(LineRect) ;
        end
        else begin
            { trait de droite }
            LineRect.Top := 0 ;
            LineRect.Left := Self.Width - FBorderSize ;
            LineRect.Right := Self.Width ;
            LineRect.Bottom := Self.Height ;
     
            Canvas.FillRect(LineRect) ;
     
            { Trait du bas }
            LineRect.Top := Self.Height - FBorderSize ;
            LineRect.Left := 0 ;
            LineRect.Right := Self.Width ;
            LineRect.Bottom := LineRect.Top +FBorderSize ;
     
            Canvas.FillRect(LineRect) ;
        end ;
     
        { Trait de gauche }
        LineRect.Top := 0 ;
        LineRect.Left := 0 ;
        LineRect.Right := FBorderSize ;
        LineRect.Bottom := Self.Height ;
     
        if FTextPosition in [tpBottomCenter, tpBottomLeft, tpBottomRight]
        then begin
            Dec(LineRect.Bottom, TextHeight) ;
        end ;
     
        Canvas.FillRect(LineRect) ;

  6. #6
    Modérateur

    Homme Profil pro
    Ingénieur retraité
    Inscrit en
    Octobre 2005
    Messages
    2 396
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur retraité

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 396
    Points : 3 263
    Points
    3 263
    Par défaut
    Salut,

    je vais tracer des rectangles. Car sinon, le bout de la ligne est ront et c'est moche
    ... pire encore le bout n'est pas tout à fait rond mais assymétrique et si on fait un tracé mobile avec pen.mode:=pmNotXor pour l'effacer avec un second tracé avec pen.mode:=pmNotXor et le réafficher illico dans la nouvelle position il apparaît dans les angles du tracé (par exemple ceux d'un rectangle qu'on tire à la souris) des zones de la couleur de l'écran à la place de la couleur du trait.

    A+
    N'oubliez pas de consulter les FAQ Delphi et les cours et tutoriels Delphi

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

Discussions similaires

  1. [C#] Problème d'ajout d'une ligne dans une DataTable
    Par therock dans le forum Windows Forms
    Réponses: 3
    Dernier message: 09/11/2006, 08h27
  2. Problème de delete d'une ligne Excel
    Par Charlie47 dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 24/08/2006, 14h55
  3. Réponses: 5
    Dernier message: 10/08/2006, 12h54
  4. VBA EXCEL - Sélection d'une ligne suivant saisie
    Par brethomeau dans le forum Macros et VBA Excel
    Réponses: 48
    Dernier message: 15/11/2005, 17h41
  5. [JTable] problème après suppression d'une ligne
    Par fredo3500 dans le forum Composants
    Réponses: 7
    Dernier message: 17/03/2005, 10h01

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