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

Contribuez Pascal Discussion :

Utilisation de la bibliothèque Cairo dans une application X11 [Free Pascal]


Sujet :

Contribuez Pascal

  1. #1
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 072
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut Utilisation de la bibliothèque Cairo dans une application X11
    Bonjour !

    Je suis en train de regarder comment on peut utiliser la bibliothèque Cairo sous Linux, dans une application X11.

    Pour commencer, voici un petit programme, sans fenêtre, qui permet de faire une capture d'écran. Le programme est à lancer depuis un terminal :


    Il crée un fichier nommé screenshot.png, qui contient une capture de tout l'écran.

    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
     
    program Screenshot;
     
    { 
      Capture d'écran sous Linux
      https://stackoverflow.com/a/15524366
    }
     
    uses
      X, XLib, Cairo, CairoXLib;
     
    var
      LDisplay: PDisplay;
      LScreenNum: integer;
      LWindow: TWindow;
      LVisual: PVisual;
      LWidth: integer;
      LHeight: integer;
      LSurface: pcairo_surface_t;
     
    begin
      LDisplay   := XOpenDisplay(nil);
      LScreenNum := XDefaultScreen(LDisplay);
      LWindow    := XDefaultRootWindow(LDisplay);
      LVisual    := XDefaultVisual(LDisplay, LScreenNum);
      LWidth     := XDisplayWidth(LDisplay, LScreenNum);
      LHeight    := XDisplayHeight(LDisplay, LScreenNum);
     
      LSurface := cairo_xlib_surface_create(LDisplay, LWindow, LVisual, LWidth, LHeight);
      cairo_surface_write_to_png(LSurface, 'screenshot.png');
      cairo_surface_destroy(LSurface);
     
      XCloseDisplay(LDisplay);
    end.
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  2. #2
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 072
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut
    Voici une première version. Il reste des petites choses à fignoler, mais l'essentiel y est (enfin je crois).

    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
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
     
    program Cairo_XLib_01;
     
    {  
      Exemple d'utilisation de la bibliothèque Cairo dans une application X11
      Version 0.1
      
      https://gitlab.com/cairo/cairo-demos/-/blob/master/X11/cairo-demo.c
      https://lists.freepascal.org/pipermail/fpc-pascal/2008-March/017049.html
      https://stackoverflow.com/a/15089506
    }
     
    uses
      X, XLib, XUtil, Cairo, CairoXLib;
     
    type
      PWindowRec = ^TWindowRec;
      TWindowRec = record
        FDisplay: PDisplay;
        FScreenNum: integer;
        FWindow: TWindow;
        FX, FY, FWidth, FHeight: integer;
        FQuitCode: TKeyCode
      end;
     
    procedure WinInit(const AWindowRec: PWindowRec);
    var
      LRoot: TWindow;
      LSizeHints: PXSizeHints;
    begin
      with AWindowRec^ do
      begin
        FX := 40;
        FY := 30;
        FWidth := 400;
        FHeight := 400;
     
      { Nécessaire pour obtenir le positionnement souhaité de la fenêtre. }
        LSizeHints := XAllocSizeHints;
        LSizeHints^.Flags := PPosition or PSize;
        LSizeHints^.X := FX;
        LSizeHints^.Y := FY;
        LSizeHints^.Width := FWidth;
        LSizeHints^.Height := FHeight;
     
        LRoot := XDefaultRootWindow(FDisplay);
        FScreenNum := XDefaultScreen(FDisplay);
        FWindow := XCreateSimpleWindow(FDisplay, LRoot, 10, 10, FWidth, FHeight, 0, XBlackPixel(FDisplay, FScreenNum), XWhitePixel(FDisplay, FScreenNum));
     
        XSetNormalHints(FDisplay, FWindow, LSizeHints);
     
        FQuitCode := XKeysymToKeycode(FDisplay, XStringToKeysym('Q'));
        XSelectInput(FDisplay, FWindow, ExposureMask or KeyPressMask or ButtonPressMask or StructureNotifyMask);
        XStoreName(FDisplay, FWindow, 'Exemple Cairo X11');
        XMapWindow(FDisplay, FWindow);
      end;
    end;
     
    procedure WinDestroy(const AWindowRec: PWindowRec);
    begin
      XDestroyWindow(AWindowRec^.FDisplay, AWindowRec^.FWindow);
    end;
     
    procedure WinDraw(const AWindowRec: PWindowRec);
    var
      LVisual: PVisual;
      LSurface: pcairo_surface_t;
      LContext: pcairo_t;
    begin
      with AWindowRec^ do
      begin
        LVisual := XDefaultVisual(FDisplay, FScreenNum);
        XClearWindow(FDisplay, FWindow);
        LSurface := cairo_xlib_surface_create(FDisplay, FWindow, LVisual, FWidth, FHeight);
        LContext := cairo_create(LSurface);
      { Peindre la fenêtre en bleu. }
        cairo_set_source_rgb(LContext, 0.0, 0.0, 0.5);
        cairo_paint(LContext);
      { Tracer un trait blanc. }
        cairo_set_line_width(LContext, 24);
        cairo_set_line_cap(LContext, CAIRO_LINE_CAP_ROUND);
        cairo_set_source_rgb(LContext, 1.0, 1.0, 1.0);
        cairo_move_to(LContext, FWidth div 8, FHeight div 8);
        cairo_line_to(LContext, 7 * (FWidth div 8), 7 * (FHeight div 8));
        cairo_stroke(LContext);
        cairo_destroy(LContext);
        cairo_surface_destroy(LSurface);
      end;
    end;
     
    procedure WinHandleEvents(const AWindowRec: PWindowRec);
    var
      LEvent: TXEvent;
    begin
      while TRUE do
      begin
        XNextEvent(AWindowRec^.FDisplay, @LEvent);
        case LEvent._type of
          Expose:
            begin
              if LEvent.XExpose.Count = 0 then
              begin
                WinDraw(AWindowRec);
              end;
            end;
          ConfigureNotify:
            begin
              AWindowRec^.FWidth := LEvent.XConfigure.Width;
              AWindowRec^.FHeight := LEvent.XConfigure.Height;
            end;
          ButtonPress:
            begin
            { À terminer. Pour le moment le programme s'interrompt si l'utilisateur appuie sur une touche quelconque. }
              Break;
            end;
          KeyPress:
            begin
              Break;
            end;
        end;
      end;
    end;
     
    var
      LWindowRec: TWindowRec;
     
    begin
      LWindowRec.FDisplay := XOpenDisplay(nil);
      if LWindowRec.FDisplay = nil then
      begin
        WriteLn(ErrOutput, 'Failed to open display');
        Halt(1);
      end;
      WinInit(@LWindowRec);
      WinDraw(@LWindowRec);
      WinHandleEvents(@LWindowRec);
      WinDestroy(@LWindowRec);
      XCloseDisplay(LWindowRec.FDisplay);
    end.
    Images attachées Images attachées  
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  3. #3
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 072
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut
    Quelques petites améliorations. Le programme détecte la fermeture de la fenêtre par un clic sur le bouton "X". Il se ferme lorsque l'utilisateur appuie sur la touche "Q".

    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
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
     
    program Cairo_XLib_02;
     
    {  
      Exemple d'utilisation de la bibliothèque Cairo dans une application X11
      
      Version 0.2
        * Libération de la mémoire allouée par la fonction XAllocSizeHints
        * Gestion de l'événement ClientMessage (fermeture de la fenêtre par le bouton "X")
        * Vérification de la touche pressée par l'utilisateur
      
      https://gitlab.com/cairo/cairo-demos/-/blob/master/X11/cairo-demo.c
      https://lists.freepascal.org/pipermail/fpc-pascal/2008-March/017049.html
      https://stackoverflow.com/a/15089506
      http://supertos.free.fr/html/linux/dev/xwindow/dev/xlib/index.htm
      https://www.lemoda.net/xlib/index.html
    }
     
    uses
      X, XLib, XUtil, Cairo, CairoXLib;
     
    type
      PWindowRec = ^TWindowRec;
      TWindowRec = record
        FDisplay: PDisplay;
        FScreenNum: integer;
        FWindow: TWindow;
        FX, FY, FWidth, FHeight: integer;
        FQuitCode: TKeyCode
      end;
     
    procedure WinInit(const AWindowRec: PWindowRec);
    var
      LRoot: TWindow;
      LSizeHints: PXSizeHints;
      LWindowClosingProtocol: TAtom;
    begin
      with AWindowRec^ do
      begin
        FX := 40;
        FY := 30;
        FWidth := 400;
        FHeight := 400;
     
      { Nécessaire pour obtenir le positionnement souhaité de la fenêtre. }
        LSizeHints := XAllocSizeHints;
        LSizeHints^.Flags := PPosition or PSize;
        LSizeHints^.X := FX;
        LSizeHints^.Y := FY;
        LSizeHints^.Width := FWidth;
        LSizeHints^.Height := FHeight;
     
        LRoot := XDefaultRootWindow(FDisplay);
        FScreenNum := XDefaultScreen(FDisplay);
        FWindow := XCreateSimpleWindow(FDisplay, LRoot, 10, 10, FWidth, FHeight, 0, XBlackPixel(FDisplay, FScreenNum), XWhitePixel(FDisplay, FScreenNum));
     
        XSetNormalHints(FDisplay, FWindow, LSizeHints);
        XFree(LSizeHints); { v0.2 }
     
      { Pour pouvoir réagir à la fermeture de la fenêtre par le bouton "X", et
        éviter le message "X connection to :0 broken (explicit kill or server shutdown)."
        L'événement ClientMessage est ajouté dans la boucle de contrôle des événements. }
        LWindowClosingProtocol := XInternAtom(FDisplay, 'WM_DELETE_WINDOW', TRUE);
        if LWindowClosingProtocol = 0 then
          WriteLn(ErrOutput, 'LWindowClosingProtocol = 0')
        else
          XSetWMProtocols(FDisplay, FWindow, @LWindowClosingProtocol, 1);
     
        FQuitCode := XKeysymToKeycode(FDisplay, XStringToKeysym('Q'));
        XSelectInput(FDisplay, FWindow, ExposureMask or KeyPressMask or ButtonPressMask or StructureNotifyMask);
        XStoreName(FDisplay, FWindow, 'Exemple Cairo X11');
        XMapWindow(FDisplay, FWindow);
      end;
    end;
     
    procedure WinDestroy(const AWindowRec: PWindowRec);
    begin
      XDestroyWindow(AWindowRec^.FDisplay, AWindowRec^.FWindow);
    end;
     
    procedure WinDraw(const AWindowRec: PWindowRec);
    var
      LVisual: PVisual;
      LSurface: pcairo_surface_t;
      LContext: pcairo_t;
    begin
      with AWindowRec^ do
      begin
        LVisual := XDefaultVisual(FDisplay, FScreenNum);
        XClearWindow(FDisplay, FWindow);
        LSurface := cairo_xlib_surface_create(FDisplay, FWindow, LVisual, FWidth, FHeight);
        LContext := cairo_create(LSurface);
      { Peindre la fenêtre en bleu. }
        cairo_set_source_rgb(LContext, 0.0, 0.0, 0.5);
        cairo_paint(LContext);
      { Tracer un trait blanc. }
        cairo_set_line_width(LContext, 24);
        cairo_set_line_cap(LContext, CAIRO_LINE_CAP_ROUND);
        cairo_set_source_rgb(LContext, 1.0, 1.0, 1.0);
        cairo_move_to(LContext, FWidth div 8, FHeight div 8);
        cairo_line_to(LContext, 7 * (FWidth div 8), 7 * (FHeight div 8));
        cairo_stroke(LContext);
        cairo_destroy(LContext);
        cairo_surface_destroy(LSurface);
      end;
    end;
     
    procedure WinHandleEvents(const AWindowRec: PWindowRec);
    var
      LEvent: TXEvent;
      LKeyEvent: TXKeyEvent;
    begin
      while TRUE do
      begin
        XNextEvent(AWindowRec^.FDisplay, @LEvent);
        case LEvent._type of
          Expose:
            begin
              if LEvent.XExpose.Count = 0 then
              begin
                WinDraw(AWindowRec);
              end;
            end;
          ConfigureNotify:
            begin
              AWindowRec^.FWidth  := LEvent.XConfigure.Width;
              AWindowRec^.FHeight := LEvent.XConfigure.Height;
            end;
          ButtonPress:
            begin
              Break;
            end;
          KeyPress:
            begin
            { v0.2 }
              LKeyEvent := LEvent.XKey;
              if LKeyEvent.KeyCode = AWindowRec^.FQuitCode then
                Break
              else
                WriteLn(ErrOutput, 'LKeyEvent.KeyCode = ', LKeyEvent.KeyCode);
            end;
          ClientMessage:
            begin
            { Fermeture de la fenêtre par le bouton "X". }
              Break;
            end;
        end;
      end;
    end;
     
    var
      LWindowRec: TWindowRec;
     
    begin
      LWindowRec.FDisplay := XOpenDisplay(nil);
      if LWindowRec.FDisplay = nil then
      begin
        WriteLn(ErrOutput, 'Failed to open display');
        Halt(1);
      end;
      WinInit(@LWindowRec);
      WinDraw(@LWindowRec);
      WinHandleEvents(@LWindowRec);
      WinDestroy(@LWindowRec);
      XCloseDisplay(LWindowRec.FDisplay);
    end.
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  4. #4
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 072
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut Pixmap
    Une troisième version, qui utilise un buffer de type TPixmap au lieu de dessiner directement dans la fenêtre.

    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
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    program Cairo_XLib_03;
     
    {  
      Exemple d'utilisation de la bibliothèque Cairo dans une application X11
      
      Version 0.2
        * Libération de la mémoire allouée par la fonction XAllocSizeHints
        * Gestion de l'événement ClientMessage (fermeture de la fenêtre par le bouton "X")
        * Vérification de la touche pressée par l'utilisateur
      
      Version 0.3
        * Utilisation d'un pixmap (au lieu de dessiner directement dans la fenêtre)
        * Affichage des événements dans le terminal
      
      https://gitlab.com/cairo/cairo-demos/-/blob/master/X11/cairo-demo.c
      https://lists.freepascal.org/pipermail/fpc-pascal/2008-March/017049.html
      https://stackoverflow.com/a/15089506
      http://supertos.free.fr/html/linux/dev/xwindow/dev/xlib/index.htm
      https://www.lemoda.net/xlib/index.html
    }
     
    uses
      X, XLib, XUtil, Cairo, CairoXLib;
     
    type
      PWindowRec = ^TWindowRec;
      TWindowRec = record
        FDisplay: PDisplay;
        FScreenNum: integer;
        FWindow: TWindow;
        FX, FY, FWidth, FHeight: integer;
        FQuitCode: TKeyCode;
        FPixmap: TPixmap; { v0.3 }
        FGC: TGC;
      end;
     
    procedure WinInit(const AWindowRec: PWindowRec);
    var
      LRoot: TWindow;
      LSizeHints: PXSizeHints;
      LWindowClosingProtocol: TAtom;
    begin
      with AWindowRec^ do
      begin
        FX := 40;
        FY := 30;
        FWidth := 400;
        FHeight := 400;
     
      { Nécessaire pour obtenir le positionnement souhaité de la fenêtre. }
        LSizeHints := XAllocSizeHints;
        LSizeHints^.Flags := PPosition or PSize;
        LSizeHints^.X := FX;
        LSizeHints^.Y := FY;
        LSizeHints^.Width := FWidth;
        LSizeHints^.Height := FHeight;
     
        LRoot := XDefaultRootWindow(FDisplay);
        FScreenNum := XDefaultScreen(FDisplay);
        FWindow := XCreateSimpleWindow(FDisplay, LRoot, 10, 10, FWidth, FHeight, 0, XBlackPixel(FDisplay, FScreenNum), XWhitePixel(FDisplay, FScreenNum));
     
        XSetNormalHints(FDisplay, FWindow, LSizeHints);
        XFree(LSizeHints); { v0.2 }
     
      { Pour pouvoir réagir à la fermeture de la fenêtre par le bouton "X".
        L'événement ClientMessage sera ajouté dans la boucle de contrôle des événements. }
        LWindowClosingProtocol := XInternAtom(FDisplay, 'WM_DELETE_WINDOW', TRUE);
        if LWindowClosingProtocol = 0 then
          WriteLn(ErrOutput, 'LWindowClosingProtocol = 0')
        else
          XSetWMProtocols(FDisplay, FWindow, @LWindowClosingProtocol, 1);
     
        FQuitCode := XKeysymToKeycode(FDisplay, XStringToKeysym('Q'));
        XSelectInput(FDisplay, FWindow, ExposureMask or KeyPressMask or ButtonPressMask or StructureNotifyMask);
        XStoreName(FDisplay, FWindow, 'Exemple Cairo X11');
     
        FPixmap := XCreatePixmap(FDisplay, FWindow, FWidth, FHeight, DefaultDepth(FDisplay, FScreenNum));
        FGC := XCreateGC(FDisplay, FPixmap, 0, nil);
     
        XMapWindow(FDisplay, FWindow);
      end;
    end;
     
    procedure WinDestroy(const AWindowRec: PWindowRec);
    begin
      with AWindowRec^ do
      begin
        XDestroyWindow(FDisplay, FWindow);
        XFreePixmap(FDisplay, FPixmap);
        XFreeGC(FDisplay, FGC);
      end;
    end;
     
    procedure WinDraw(const AWindowRec: PWindowRec);
    var
      (*
      LVisual: PVisual;
      *)
      LSurface: pcairo_surface_t;
      LContext: pcairo_t;
    begin
      with AWindowRec^ do
      begin
        (*
        LVisual := XDefaultVisual(FDisplay, FScreenNum);
        *)
        XClearWindow(FDisplay, FWindow);
        (*
        LSurface := cairo_xlib_surface_create(FDisplay, FWindow, LVisual, FWidth, FHeight);
        *)
      { v0.3 }
        LSurface := cairo_xlib_surface_create(FDisplay, FPixmap, DefaultVisual(FDisplay, DefaultScreen(FDisplay)), FWidth, FHeight);
     
        LContext := cairo_create(LSurface);
      { Peindre la fenêtre en bleu. }
        cairo_set_source_rgb(LContext, 0.0, 0.0, 0.5);
        cairo_paint(LContext);
      { Tracer un trait blanc. }
        cairo_set_line_width(LContext, 24);
        cairo_set_line_cap(LContext, CAIRO_LINE_CAP_ROUND);
        cairo_set_source_rgb(LContext, 1.0, 1.0, 1.0);
        cairo_move_to(LContext, FWidth div 8, FHeight div 8);
        cairo_line_to(LContext, 7 * (FWidth div 8), 7 * (FHeight div 8));
        cairo_stroke(LContext);
        cairo_destroy(LContext);
        cairo_surface_destroy(LSurface);
     
      { v0.3 }
        XCopyArea(FDisplay, FPixmap, FWindow, FGC, 0, 0, FWidth, FHeight, 0, 0);
      end;
    end;
     
    procedure WinHandleEvents(const AWindowRec: PWindowRec);
    var
      LEvent: TXEvent;
      LKeyEvent: TXKeyEvent;
    begin
      while TRUE do
      begin
        XNextEvent(AWindowRec^.FDisplay, @LEvent);
        case LEvent._type of
          Expose:
            with LEvent.XExpose do
            begin
              WriteLn('Expose    ', X:3, ', ', Y:3, ', ', Width:3, ', ', Height:3, ', ', Count:3);
              if Count = 0 then
                WinDraw(AWindowRec);
            end;
          ConfigureNotify:
            with AWindowRec^, LEvent.XConfigure do
            begin
              WriteLn('Configure ', X:3, ', ', Y:3, ', ', Width:3, ', ', Height:3);
              FWidth  := Width;
              FHeight := Height;
              XFreePixmap(FDisplay, FPixmap);
              XFreeGC(FDisplay, FGC);
              FPixmap := XCreatePixmap(FDisplay, FWindow, FWidth, FHeight, DefaultDepth(FDisplay, FScreenNum));
              FGC := XCreateGC(FDisplay, FPixmap, 0, nil);
            end;
          ButtonPress:
            begin
              WriteLn('ButtonPress');
              Break;
            end;
          KeyPress:
            begin
              WriteLn('KeyPress');
            { v0.2 }
              LKeyEvent := LEvent.XKey;
              WriteLn('LKeyEvent.KeyCode = ', LKeyEvent.KeyCode);
              if LKeyEvent.KeyCode = AWindowRec^.FQuitCode then
                Break;
            end;
          ClientMessage:
            begin
              WriteLn('ClientMessage');
            { Fermeture de la fenêtre par le bouton "X". }
              Break;
            end;
        end;
      end;
      WriteLn('Au revoir !');
    end;
     
    var
      LWindowRec: TWindowRec;
     
    begin
      LWindowRec.FDisplay := XOpenDisplay(nil);
      if LWindowRec.FDisplay = nil then
      begin
        WriteLn(ErrOutput, 'Failed to open display');
        Halt(1);
      end;
      WinInit(@LWindowRec);
      WinDraw(@LWindowRec);
      WinHandleEvents(@LWindowRec);
      WinDestroy(@LWindowRec);
      XCloseDisplay(LWindowRec.FDisplay);
    end.
    Je crois que ce sera tout pour le moment, même s'il reste encore des choses à explorer. J'ai trouvé des tonnes d'exemples à étudier (en C, mais la traduction est vraiment facile).

    Ce projet-là notamment vaut le détour : https://github.com/brummer10/Xputty
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 11/10/2012, 13h45
  2. Utiliser un module VB .Net dans une application c#
    Par hardballer dans le forum Général Dotnet
    Réponses: 2
    Dernier message: 28/02/2012, 17h40
  3. Réponses: 0
    Dernier message: 07/05/2011, 22h30
  4. Utilisation d'un thème XP dans une application
    Par Invité dans le forum Windows
    Réponses: 3
    Dernier message: 08/09/2009, 09h55
  5. Réponses: 0
    Dernier message: 30/06/2009, 18h14

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