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

GTK+ avec C & C++ Discussion :

GTK fenetre transparente [Fait]


Sujet :

GTK+ avec C & C++

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 23
    Par défaut GTK fenetre transparente
    Bonjour,
    Connaissez vous des librairies permettant la création de fenêtre transparente, et qu'on ne peut pas la fermer.

    Merci d'avance

  2. #2
    Rédacteur
    Avatar de Franck.H
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2004
    Messages
    6 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2004
    Messages : 6 951
    Par défaut
    Fenêtre transparente, surement pas avec GTK+, faut voir les fonctions suivant ton système mais cela n'arrange pas la portabilité de ton programme !

    Pour ne pas fermer une fenêtre ... voir pour redéfinir le comportement du programme lors de l'appel du signal "delete-event" peut-être mais je n'est jamais cette manip ... a moins que tu fasse une fenêtre sans bordure
    Mon Site
    Ma bibliothèque de gestion des chaînes de caractères en C

    L'imagination est plus importante que le savoir. A. Einstein

    Je ne répond à aucune question technique par MP, merci d'avance !

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 23
    Par défaut
    et Comment faire une fenêtre sans bordure?

  4. #4
    Rédacteur
    Avatar de Franck.H
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2004
    Messages
    6 951
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Haut Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2004
    Messages : 6 951
    Par défaut
    Citation Envoyé par jamfr73
    et Comment faire une fenêtre sans bordure?
    Suffit de regarde dans la ref de l'api GKT+, toutes les réponses sont là quelque part !
    Voir la fonction: gtk_window_set_decorated
    Mon Site
    Ma bibliothèque de gestion des chaînes de caractères en C

    L'imagination est plus importante que le savoir. A. Einstein

    Je ne répond à aucune question technique par MP, merci d'avance !

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 23
    Par défaut
    Merci.
    Ca marche bien

  6. #6
    Rédacteur

    Avatar de gege2061
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juin 2004
    Messages
    5 840
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur de base de données

    Informations forums :
    Inscription : Juin 2004
    Messages : 5 840
    Par défaut
    Citation Envoyé par Franck.H
    Fenêtre transparente, surement pas avec GTK+,
    Il ne faut pas sous-estimer GTK : gtk windows with alpha channels. Voici le code proposé :
    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
    #include <gtk/gtk.h>
    #include <gdk/gdkscreen.h>
    #include <cairo.h>
     
    /*
     * This program shows you how to create semi-transparent windows,
     * without any of the historical screenshot hacks. It requires
     * a modern system, with a compositing manager. I use xcompmgr
     * and the nvidia drivers with RenderAccel, and it works well.
     *
     * I'll take you through each step as we go. Minimal GTK+ knowledge is
     * assumed.
     */
     
    static void screen_changed(GtkWidget *widget, GdkScreen *old_screen, gpointer user_data);
    static gboolean expose(GtkWidget *widget, GdkEventExpose *event, gpointer user_data);
    static void clicked(GtkWindow *win, GdkEventButton *event, gpointer user_data);
     
    int main(int argc, char **argv)
    {
        /* boilerplate initialization code */
        gtk_init(&argc, &argv);
     
        GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(window), "Alpha Demo");
        g_signal_connect(G_OBJECT(window), "delete-event", gtk_main_quit, NULL);
     
     
        /* Tell GTK+ that we want to draw the windows background ourself.
         * If we don't do this then GTK+ will clear the window to the
         * opaque theme default color, which isn't what we want.
         */
        gtk_widget_set_app_paintable(window, TRUE);
     
        /* We need to handle two events ourself: "expose-event" and "screen-changed".
         *
         * The X server sends us an expose event when the window becomes
         * visible on screen. It means we need to draw the contents.  On a
         * composited desktop expose is normally only sent when the window
         * is put on the screen. On a non-composited desktop it can be
         * sent whenever the window is uncovered by another.
         *
         * The screen-changed event means the display to which we are
         * drawing changed. GTK+ supports migration of running
         * applications between X servers, which might not support the
         * same features, so we need to check each time.
         */
     
        g_signal_connect(G_OBJECT(window), "expose-event", G_CALLBACK(expose), NULL);
        g_signal_connect(G_OBJECT(window), "screen-changed", G_CALLBACK(screen_changed), NULL);
     
        /* toggle title bar on click - we add the mask to tell X we are interested in this event */
        gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
        gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);
        g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(clicked), NULL);
     
        /* initialize for the current display */
        screen_changed(window, NULL, NULL);
     
        /* Run the program */
        gtk_widget_show_all(window);
        gtk_main();
     
        return 0;
    }
     
     
    /* Only some X servers support alpha channels. Always have a fallback */
    gboolean supports_alpha = FALSE;
     
    static void screen_changed(GtkWidget *widget, GdkScreen *old_screen, gpointer userdata)
    {
        /* To check if the display supports alpha channels, get the colormap */
        GdkScreen *screen = gtk_widget_get_screen(widget);
        GdkColormap *colormap = gdk_screen_get_rgba_colormap(screen);
     
        if (!colormap)
        {
            printf("Your screen does not support alpha channels!\n");
            colormap = gdk_screen_get_rgb_colormap(screen);
            supports_alpha = FALSE;
        }
        else
        {
            printf("Your screen supports alpha channels!\n");
            supports_alpha = TRUE;
        }
     
        /* Now we have a colormap appropriate for the screen, use it */
        gtk_widget_set_colormap(widget, colormap);
    }
     
    /* This is called when we need to draw the windows contents */
    static gboolean expose(GtkWidget *widget, GdkEventExpose *event, gpointer userdata)
    {
        cairo_t *cr = gdk_cairo_create(widget->window);
     
        if (supports_alpha)
            cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
        else
            cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* opaque white */
     
        /* draw the background */
        cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
        cairo_paint (cr);
     
        /* draw a circle */
        int width, height;
        gtk_window_get_size(GTK_WINDOW(widget), &width, &height);
     
        cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.6);
        cairo_arc(cr, width / 2, height / 2, (width < height ? width : height) / 2 - 8 , 0, 2 * 3.14);
        cairo_fill(cr);
        cairo_stroke(cr);
     
        cairo_destroy(cr);
        return FALSE;
    }
     
    static void clicked(GtkWindow *win, GdkEventButton *event, gpointer user_data)
    {
        /* toggle window manager frames */
        gtk_window_set_decorated(win, !gtk_window_get_decorated(win));
    }
    Par contre il faut que ton système le suporte.

Discussions similaires

  1. Fenetres Transparentes ou pas de fenetres
    Par a7aa7a dans le forum Interfaces Graphiques en Java
    Réponses: 9
    Dernier message: 16/05/2007, 21h07
  2. Fenetre transparente ?
    Par Bob Groove dans le forum MFC
    Réponses: 6
    Dernier message: 22/02/2007, 00h20
  3. Realisation d'une fenetre transparente
    Par ide92 dans le forum Delphi
    Réponses: 3
    Dernier message: 19/12/2006, 09h56
  4. faire une Fenetre Transparente
    Par kedare dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 25/05/2006, 19h15
  5. [GTK#] Fenêtre transparente ?
    Par nicolas.pied dans le forum Général Dotnet
    Réponses: 2
    Dernier message: 15/05/2006, 22h54

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