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

Lazarus Pascal Discussion :

Thèmes GTK - Comment faire ? [Lazarus]


Sujet :

Lazarus Pascal

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Août 2016
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Août 2016
    Messages : 3
    Points : 8
    Points
    8
    Par défaut Thèmes GTK - Comment faire ?
    Bonjour

    Je suis sous Linux Ubuntu 16.04 et j'aimerais avec GTK2 charger dans un TBitmap un PGTKWidget (enfin un PGTKImage). Je veux en fait utiliser les thèmes et afficher une icone "Recharger" mais impossible de trouver quoi que ce soit. J'utilise gtk_image_new_from_icon_name (gtk2.pas) pour avoir mon image.
    Actuellement mon code ci-dessous n'affiche... rien
    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
    procedure TForm1.FormShow(Sender: TObject);
      function GetGTKBmp(IconName:string;Size:integer):TBitmap;
      var
        GDIObj: PGDIObject;
        Pixbuf: PGDKPixbuf;
        Gtkimg:TGtkWidget;
        gtks:TGtkImage;
      begin
        Result := TBitmap.Create;
        PixBuf := gtk_image_get_pixbuf(PGtkImage(gtk_image_new_from_icon_name(Pgchar(IconName),Size)));
        GDIObj := Gtk2Widgetset.NewGDIObject(gdiBitmap);
        with GDIObj^ do
        begin
          GDIBitmapType := gbPixbuf;
          visual := gdk_visual_get_system();
          gdk_visual_ref(visual);
          colormap := gdk_colormap_get_system();
          gdk_colormap_ref(colormap);
          GDIPixbufObject := Pixbuf;
        end;
     
        Result := TBitmap.Create;
        Result.Handle := HBitmap({%H-}PtrUInt(GDIObj));
        Result.MaskHandle := 0;
      end;
    begin
      BitBtnRefresh.Glyph := GetGTKBmp('system-software-update.svg',25);
    end;
    En espérant que l'un d'entre vous ait la solution !

  2. #2
    Futur Membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Août 2016
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Août 2016
    Messages : 3
    Points : 8
    Points
    8
    Par défaut La nuit porte conseil
    J'ai trouvé !!! J'avais déjà regardé TGtk2ThemeServices.GetStockImage mais ce matin en la relisant je me suis rendu compte qu'en fait il faut passer par 2 API pour avoir son icône chérie (gtk_style_lookup_icon_set puis gtk_icon_set_render_icon). J'ai copié GetStockImage et l'ai adapté. J'obtiens ainsi

    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
     
    uses ...,Graphics,gtk2,LCLType,glib2,Gtk2Def,gdk2pixbuf,Gtk2Int,gdk2,Gtk2Proc;
     
    function GetStockImage(StockName:PgChar;GlyphStyle:TLazGtkStyle;Size:integer; out Image, Mask: HBitmap): Boolean;
    var
      GDIObj: PGDIObject;
      Style: PGtkStyle;
      IconSet: PGtkIconSet;
      Pixbuf: PGDKPixbuf;
    begin
      Result := False;
      Style := GetStyle(GlyphStyle);
      if (Style = nil) or (not GTK_IS_STYLE(Style)) then
      begin
        Exit;
      end;
     
      IconSet := gtk_style_lookup_icon_set(Style, StockName);
     
      if (IconSet = nil) then
      begin
        Exit;
      end;
     
      Pixbuf := gtk_icon_set_render_icon(IconSet, Style,GTK_TEXT_DIR_NONE, GTK_STATE_NORMAL, Size, GetStyleWidget(GlyphStyle), nil);
     
      GDIObj := Gtk2Widgetset.NewGDIObject(gdiBitmap);
      with GDIObj^ do
      begin
        GDIBitmapType := gbPixbuf;
        visual := gdk_visual_get_system();
        gdk_visual_ref(visual);
        colormap := gdk_colormap_get_system();
        gdk_colormap_ref(colormap);
        GDIPixbufObject := Pixbuf;
      end;
     
      Image := HBitmap({%H-}PtrUInt(GDIObj));
      Mask := 0;
      Result := True;
    end;
    Pour le faire fonctionner
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    procedure TForm1.FormShow(Sender: TObject);
    var
      BmpHwnd:HBitmap;
      BmpMask:HBITMAP;
    begin
      GetStockImage(GTK_STOCK_CDROM,lgsbutton,GTK_ICON_SIZE_BUTTON,BmpHwnd,BmpMask);
      BitBtnRefresh.Glyph.SetHandles(BmpHwnd,BmpMask);
    end;
    Attention GTK_ICON_SIZE_BUTTON=4 vous fait une icône adapteée au TBitBtn de plus de 4x4
    On met l'icône avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TBitmap.SetHandles(BmpHwnd,BmpMask);
    bien que le masque soit inutile, l'affectation séparée semble ne pas fonctionner.

    Et j'ai ma belle icône (ici de CD-ROM) !

    Pour la liste complète des stocks qui marchent c'est ici https://developer.gnome.org/gtk2/sta...ock-Items.html (bien sur vous copiez le "contenu" de ces define ).

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

Discussions similaires

  1. zip et GTK : comment faire ?
    Par troumad dans le forum GTK+ avec C & C++
    Réponses: 47
    Dernier message: 07/07/2013, 10h15
  2. comment faire une condition ou une instruction avec gtk
    Par Invité dans le forum GTK+ avec C & C++
    Réponses: 1
    Dernier message: 31/05/2009, 16h06
  3. GtK StatusIcon avec menu OU comment faire un menu en gtk
    Par lauben dans le forum GTK+ avec C & C++
    Réponses: 3
    Dernier message: 03/12/2008, 15h38
  4. [GTK] Comment faire défiler du texte dans un label ou autre container
    Par dupuyyann dans le forum GTK+ avec C & C++
    Réponses: 3
    Dernier message: 24/02/2008, 23h25

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