begin process at 2012 05 27 13:54:04
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

GTK+

 > BINARY CLOCK GTK AVEC CONTRÔLE EN TRAY SOUS LINUX

BINARY CLOCK GTK AVEC CONTRÔLE EN TRAY SOUS LINUX


 Information sur la source

Note :
Aucune note
Catégorie :GTK+ Niveau :Débutant Date de création :14/10/2008 Vu / téléchargé :2 662 / 78

Auteur : dje_jay

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Lorsque j'utilisais ma WindBox, j'avais une petite Binary clock... Elle me manquait trop...
Je me suis donc lancé dans le développement de mon premier source GTK.

Je n'ai pas cherché à faire un code hautement didactique ou super complet, mais je pense que c'est une bonne chose de le soumettre ici, car j'ai du gratter un peu(3 à 4h) pour trouver les éléments nécessaires à sa réalisation.

Comme dit le titre, c'est une petite horloge sans prétention qui affiche en binaire sur 3*6bit (pas comme sur Thinkgeek qui est un truc trop simple à lire et en plus breveté).

Si vous laissez le bc.png dans le répertoire d'exécution, une icône sera ajouté dans le tray, un clic gauche permet d'afficher/effacer l'horloge.

Le clic droit est implémenté, mais il faut construire la boite de dialogue qui servira à la configuration. (Me concernant, le design est à mon gout) ;-) .

AFFICHAGE : si vous ne la voyez pas, elle doit être hors écran, je la positionne au démarrage à x=0 et y=1024, peut-être n'avez vous pas assez de résolution, il faut modifier la ligne 335...

Le déplacement peut se faire avec un clic droit sur la tâche dans votre barre des tâches, ainsi que de forcer l'affichage en premier plan et sur tous les bureaux. (Je n'ai pas cherché pour le faire programmatiquement).

C'est un projet Code::Block, je ne sentais pas le besoin d'installer Glade & co. pour si peu.

Pour recompiler sans passer par C::B utilisez la commande suivante :
gcc GTKBinaryClock.c -o GTKBinaryClock $(pkg-config --libs gtk+-2.0 --cflags)

(Il faut évidement que les librairies GTK-dev soient installés)

Source

  • #include <stdlib.h>
  • #include <gtk/gtk.h>
  • #include <cairo.h>
  • GtkWidget *win = NULL;
  • struct tm* now_hms;
  • int rayon_led=6;//taille des leds =>taille appli calculé sur cette constante
  • /* Only some X servers support alpha channels. Always have a fallback */
  • gboolean supports_alpha = FALSE;
  • gboolean isVisible = TRUE;
  • //********************************************************************************************************************
  • void tray_icon_on_click(GtkStatusIcon *status_icon,gpointer user_data)
  • {
  • if (isVisible)
  • {
  • gtk_widget_hide (win);
  • isVisible=FALSE;
  • }else
  • {
  • gtk_widget_show(win);
  • isVisible=TRUE;
  • }
  • //printf("Clicked on tray icon\n");
  • }
  • //********************************************************************************************************************
  • void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button,guint activate_time, gpointer user_data)
  • {
  • printf("A finir : créer la dialogue de config ici\n");
  • //TODO: Ouvrir la dialogue de configuration(modal)
  • //dial=gtk_dialog_new();
  • // gtk_window_set_modal(GTK_WINDOW(dial), TRUE);
  • //config position au start
  • //config Always on top
  • //config couleurs
  • //config taille
  • //config avec tray ou non
  • }
  • //********************************************************************************************************************
  • static GtkStatusIcon *create_tray_icon()
  • {
  • GtkStatusIcon *tray_icon;
  • GtkStatusIcon *p_status_icon = NULL;
  • tray_icon = gtk_status_icon_new();
  • //gtk_status_icon_set_from_icon_name(tray_icon, GTK_STOCK_MEDIA_STOP);
  • p_status_icon = gtk_status_icon_new_from_file ("bc.png");
  • gtk_status_icon_set_tooltip (GTK_STATUS_ICON (p_status_icon),"Binary Clock");
  • //gtk_status_icon_set_tooltip(tray_icon, "Binary Clock");
  • gtk_status_icon_set_visible(tray_icon, TRUE);
  • g_signal_connect(G_OBJECT(p_status_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL);
  • g_signal_connect(G_OBJECT(p_status_icon), "popup-menu",G_CALLBACK(tray_icon_on_menu), NULL);
  • return tray_icon;
  • }
  • //********************************************************************************************************************
  • static void screen_changed (GtkWidget *widget, GdkScreen *old_screen,gpointer userdata)
  • {
  • /* To check if the display supports alpha channels, get the colormap */
  • GdkScreen *screen = NULL;
  • GdkColormap *colormap = NULL;
  • screen = gtk_widget_get_screen (widget);
  • colormap = gdk_screen_get_rgba_colormap (screen);
  • if (colormap == NULL)
  • {
  • g_message ("Your screen does not support alpha channels!\n");
  • colormap = gdk_screen_get_rgb_colormap(screen);
  • supports_alpha = FALSE;
  • }
  • else
  • {
  • g_message ("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 = NULL;
  • time_t now = time(NULL);
  • int r=rayon_led,r2=r*2;
  • int x1=r,x2=x1+r2,x3=x2+r2;
  • int y1=r,y2=y1+r2,y3=y2+r2,y4=y3+r2,y5=y4+r2,y6=y5+r2;
  • unsigned char hh1,hh2,hh3,hh4,hh5,hh6,mm1,mm2,mm3,mm4,mm5,mm6,ss1,ss2,ss3,ss4,ss5,ss6;
  • cr = gdk_cairo_create(widget->window);
  • if (supports_alpha)
  • {
  • /* transparent */
  • cairo_set_source_rgba (cr, 0, 0, 0, 0);
  • }
  • else
  • {
  • /* opaque noir */
  • cairo_set_source_rgb (cr, 0, 0, 0);
  • }
  • /* draw the background */
  • cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  • cairo_paint (cr);
  • now_hms = localtime(&now);
  • //TODO: Gestion d'alarmes
  • int temp=now_hms->tm_hour;
  • //converti en binaire
  • hh1=(temp%2);
  • temp/=2;
  • hh2=(temp%2);
  • temp/=2;
  • hh3=(temp%2);
  • temp/=2;
  • hh4=(temp%2);
  • temp/=2;
  • hh5=(temp%2);
  • hh6=0;
  • temp=now_hms->tm_min;
  • mm1=(temp%2);
  • temp/=2;
  • mm2=(temp%2);
  • temp/=2;
  • mm3=(temp%2);
  • temp/=2;
  • mm4=(temp%2);
  • temp/=2;
  • mm5=(temp%2);
  • temp/=2;
  • mm6=(temp%2);
  • temp=now_hms->tm_sec;
  • ss1=(temp%2);
  • temp/=2;
  • ss2=(temp%2);
  • temp/=2;
  • ss3=(temp%2);
  • temp/=2;
  • ss4=(temp%2);
  • temp/=2;
  • ss5=(temp%2);
  • temp/=2;
  • ss6=(temp%2);
  • //couleur par defaut
  • //cairo_set_source_rgba (cr, 0, 0, 0.5, 0.6);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • //HH6
  • //if (now_hms->tm_hour%2) cairo_set_source_rgb(cr, 0, 0, 1); // tj à 0
  • cairo_move_to(cr,x1, y1);
  • cairo_arc (cr, x1, y1, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (hh5) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x1, y2);
  • cairo_arc (cr, x1, y2, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (hh4) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x1, y3);
  • cairo_arc (cr, x1, y3, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (hh3) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x1, y4);
  • cairo_arc (cr, x1, y4, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (hh2) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x1, y5);
  • cairo_arc (cr, x1, y5, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (hh1) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x1, y6);
  • cairo_arc (cr, x1, y6, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • //MM
  • if (mm6) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x2, y1);
  • cairo_arc (cr, x2, y1, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (mm5) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x2, y2);
  • cairo_arc (cr, x2, y2, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (mm4) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x2, y3);
  • cairo_arc (cr, x2, y3, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (mm3) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x2, y4);
  • cairo_arc (cr, x2, y4, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (mm2) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x2, y5);
  • cairo_arc (cr, x2, y5, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (mm1) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x2, y6);
  • cairo_arc (cr, x2, y6, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • //SS
  • if (ss6) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x3, y1);
  • cairo_arc (cr, x3, y1, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (ss5) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x3, y2);
  • cairo_arc (cr, x3, y2, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (ss4) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x3, y3);
  • cairo_arc (cr, x3, y3, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (ss3) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x3, y4);
  • cairo_arc (cr, x3, y4, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • if (ss2) cairo_set_source_rgb(cr, 0, 0, 1);
  • cairo_move_to(cr,x3, y5);
  • cairo_arc (cr, x3, y5, r , 0, 2 * 3.14);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • //cairo_save (cr);
  • if (ss1) cairo_set_source_rgb(cr, 0, 0, 1); //cairo_set_source_rgba (cr, 0, 0, 1, 0.6);
  • cairo_move_to(cr,x3, y6);
  • cairo_arc (cr, x3, y6, r , 0, 2 * 3.14);
  • //cairo_stroke_preserve(cr);
  • cairo_fill(cr);
  • cairo_stroke(cr);
  • //cairo_restore(cr);
  • cairo_set_source_rgb (cr, 0, 0, 0.5);
  • //cairo_fill (cr);
  • //cairo_stroke (cr);
  • cairo_destroy (cr);
  • return FALSE;
  • }
  • //********************************************************************************************************************
  • gboolean tick(gpointer data)
  • {
  • gtk_widget_queue_draw(win);
  • return TRUE;
  • }
  • //********************************************************************************************************************
  • int main (int argc, char *argv[])
  • {
  • GtkStatusIcon *tray_icon;
  • /* boilerplate initialization code */
  • g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
  • gtk_init (&argc, &argv);
  • g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);
  • tray_icon = create_tray_icon();//crée l'icone en tray
  • win = gtk_window_new (GTK_WINDOW_TOPLEVEL);//instance de fenêtre
  • //configuration de la fenêtre
  • gtk_container_set_border_width (GTK_CONTAINER (win), 1);
  • gtk_window_set_title (GTK_WINDOW(win), "Binary Clock");
  • gtk_window_set_decorated(GTK_WINDOW (win), FALSE);
  • //gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);//pour info
  • gtk_window_move (GTK_WINDOW (win), 0,1024);//position
  • gtk_window_set_default_size(GTK_WINDOW(win), rayon_led*6, rayon_led*12);
  • g_signal_connect (G_OBJECT(win), "delete-event", gtk_main_quit, NULL);
  • gtk_widget_set_app_paintable (win, TRUE);//signale qu'on va faire du dessin
  • g_signal_connect (G_OBJECT (win), "expose-event", G_CALLBACK (expose),NULL);
  • g_signal_connect (G_OBJECT (win), "screen-changed",G_CALLBACK (screen_changed), NULL);
  • //TODO : Chercher à retirer la tâche de la taskbox
  • /* initialize for the current display */
  • screen_changed (win, NULL, NULL);
  • /* Enter the main loop */
  • gtk_widget_show_all (win);
  • g_timeout_add(1000, tick, NULL);//Execute tick tous les secondes (qui fait un redraw)
  • gtk_main ();
  • return 0;
  • }
#include <stdlib.h>
#include <gtk/gtk.h>
#include <cairo.h>


GtkWidget *win = NULL;
struct tm* now_hms;
int rayon_led=6;//taille des leds =>taille appli calculé sur cette constante

/* Only some X servers support alpha channels. Always have a fallback */
gboolean supports_alpha = FALSE;
gboolean isVisible = TRUE;

//********************************************************************************************************************
void tray_icon_on_click(GtkStatusIcon *status_icon,gpointer user_data)
{
  if (isVisible)
  {
    gtk_widget_hide (win);
    isVisible=FALSE;
  }else
  {
    gtk_widget_show(win);
    isVisible=TRUE;
  }
  //printf("Clicked on tray icon\n");
}

//********************************************************************************************************************
void tray_icon_on_menu(GtkStatusIcon *status_icon, guint button,guint activate_time, gpointer user_data)
{
  printf("A finir : créer la dialogue de config ici\n");
  //TODO: Ouvrir la dialogue de configuration(modal)
  //dial=gtk_dialog_new();
  //  gtk_window_set_modal(GTK_WINDOW(dial), TRUE);

  //config position au start
  //config Always on top
  //config couleurs
  //config taille
  //config avec tray ou non

}

//********************************************************************************************************************
static GtkStatusIcon *create_tray_icon()
{
        GtkStatusIcon *tray_icon;
        GtkStatusIcon *p_status_icon = NULL;

        tray_icon = gtk_status_icon_new();
        //gtk_status_icon_set_from_icon_name(tray_icon, GTK_STOCK_MEDIA_STOP);

        p_status_icon = gtk_status_icon_new_from_file ("bc.png");
        gtk_status_icon_set_tooltip (GTK_STATUS_ICON (p_status_icon),"Binary Clock");

        //gtk_status_icon_set_tooltip(tray_icon, "Binary Clock");
        gtk_status_icon_set_visible(tray_icon, TRUE);

        g_signal_connect(G_OBJECT(p_status_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL);
        g_signal_connect(G_OBJECT(p_status_icon), "popup-menu",G_CALLBACK(tray_icon_on_menu), NULL);

        return tray_icon;
}

//********************************************************************************************************************
  static void screen_changed (GtkWidget *widget, GdkScreen *old_screen,gpointer userdata)
  {
    /* To check if the display supports alpha channels, get the colormap */
    GdkScreen *screen = NULL;
    GdkColormap *colormap = NULL;

    screen = gtk_widget_get_screen (widget);
    colormap = gdk_screen_get_rgba_colormap (screen);
    if (colormap == NULL)
    {
      g_message ("Your screen does not support alpha channels!\n");
      colormap = gdk_screen_get_rgb_colormap(screen);
      supports_alpha = FALSE;
    }
    else
    {
      g_message ("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 = NULL;
    time_t now = time(NULL);
    int r=rayon_led,r2=r*2;
    int x1=r,x2=x1+r2,x3=x2+r2;
    int y1=r,y2=y1+r2,y3=y2+r2,y4=y3+r2,y5=y4+r2,y6=y5+r2;
    unsigned char hh1,hh2,hh3,hh4,hh5,hh6,mm1,mm2,mm3,mm4,mm5,mm6,ss1,ss2,ss3,ss4,ss5,ss6;


    cr = gdk_cairo_create(widget->window);
    if (supports_alpha)
    {
      /* transparent */
      cairo_set_source_rgba (cr, 0, 0, 0, 0);
    }
    else
    {
      /* opaque noir */
      cairo_set_source_rgb (cr, 0, 0, 0);
    }

    /* draw the background */
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint (cr);

    now_hms = localtime(&now);

    //TODO: Gestion d'alarmes

    int temp=now_hms->tm_hour;

    //converti en binaire
    hh1=(temp%2);
    temp/=2;
    hh2=(temp%2);
    temp/=2;
    hh3=(temp%2);
    temp/=2;
    hh4=(temp%2);
    temp/=2;
    hh5=(temp%2);
    hh6=0;

    temp=now_hms->tm_min;

    mm1=(temp%2);
    temp/=2;
    mm2=(temp%2);
    temp/=2;
    mm3=(temp%2);
    temp/=2;
    mm4=(temp%2);
    temp/=2;
    mm5=(temp%2);
    temp/=2;
    mm6=(temp%2);

    temp=now_hms->tm_sec;

    ss1=(temp%2);
    temp/=2;
    ss2=(temp%2);
    temp/=2;
    ss3=(temp%2);
    temp/=2;
    ss4=(temp%2);
    temp/=2;
    ss5=(temp%2);
    temp/=2;
    ss6=(temp%2);


    //couleur par defaut
    //cairo_set_source_rgba (cr, 0, 0, 0.5, 0.6);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    //HH6
    //if (now_hms->tm_hour%2)  cairo_set_source_rgb(cr, 0, 0, 1); // tj à 0
    cairo_move_to(cr,x1, y1);
    cairo_arc (cr, x1, y1, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (hh5)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x1, y2);
    cairo_arc (cr, x1, y2, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (hh4)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x1, y3);
    cairo_arc (cr, x1, y3, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (hh3)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x1, y4);
    cairo_arc (cr, x1, y4, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (hh2)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x1, y5);
    cairo_arc (cr, x1, y5, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (hh1)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x1, y6);
    cairo_arc (cr, x1, y6, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    //MM
    if (mm6)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x2, y1);
    cairo_arc (cr, x2, y1, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (mm5)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x2, y2);
    cairo_arc (cr, x2, y2, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (mm4)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x2, y3);
    cairo_arc (cr, x2, y3, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (mm3)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x2, y4);
    cairo_arc (cr, x2, y4, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (mm2)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x2, y5);
    cairo_arc (cr, x2, y5, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (mm1)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x2, y6);
    cairo_arc (cr, x2, y6, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    //SS
    if (ss6)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x3, y1);
    cairo_arc (cr, x3, y1, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (ss5)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x3, y2);
    cairo_arc (cr, x3, y2, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (ss4)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x3, y3);
    cairo_arc (cr, x3, y3, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (ss3)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x3, y4);
    cairo_arc (cr, x3, y4, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    if (ss2)  cairo_set_source_rgb(cr, 0, 0, 1);
    cairo_move_to(cr,x3, y5);
    cairo_arc (cr, x3, y5, r , 0, 2 * 3.14);
    cairo_fill(cr);
    cairo_stroke(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    //cairo_save (cr);
    if (ss1)  cairo_set_source_rgb(cr, 0, 0, 1); //cairo_set_source_rgba (cr, 0, 0, 1, 0.6);
    cairo_move_to(cr,x3, y6);
    cairo_arc (cr, x3, y6, r , 0, 2 * 3.14);
    //cairo_stroke_preserve(cr);
    cairo_fill(cr);
    cairo_stroke(cr);
    //cairo_restore(cr);
    cairo_set_source_rgb (cr, 0, 0, 0.5);

    //cairo_fill (cr);
    //cairo_stroke (cr);

    cairo_destroy (cr);
    return FALSE;
  }
//********************************************************************************************************************
  gboolean tick(gpointer data)
  {
    gtk_widget_queue_draw(win);
    return TRUE;
  }

//********************************************************************************************************************
int main (int argc, char *argv[])
{
  GtkStatusIcon *tray_icon;

  /* boilerplate initialization code */
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
  gtk_init (&argc, &argv);
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

  tray_icon = create_tray_icon();//crée l'icone en tray

  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);//instance de fenêtre

  //configuration de la fenêtre
  gtk_container_set_border_width (GTK_CONTAINER (win), 1);
  gtk_window_set_title (GTK_WINDOW(win), "Binary Clock");
  gtk_window_set_decorated(GTK_WINDOW (win), FALSE);
  //gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);//pour info
  gtk_window_move (GTK_WINDOW (win), 0,1024);//position
  gtk_window_set_default_size(GTK_WINDOW(win), rayon_led*6, rayon_led*12);
  g_signal_connect (G_OBJECT(win), "delete-event", gtk_main_quit, NULL);

  gtk_widget_set_app_paintable (win, TRUE);//signale qu'on va faire du dessin

  g_signal_connect (G_OBJECT (win), "expose-event", G_CALLBACK (expose),NULL);
  g_signal_connect (G_OBJECT (win), "screen-changed",G_CALLBACK (screen_changed), NULL);

  //TODO : Chercher à retirer la tâche de la taskbox


  /* initialize for the current display */
  screen_changed (win, NULL, NULL);

  /* Enter the main loop */
  gtk_widget_show_all (win);

  g_timeout_add(1000, tick, NULL);//Execute tick tous les secondes (qui fait un redraw)

  gtk_main ();
  return 0;
}

 Conclusion

C'est de nouveau un truc inutile mais tellement indispensable...

On peut mettre en valeur les technos utilisés:
* graphique en GTK cairo
* Appels périodique (g_timeout_add)
* Mise en tray (avec icône et récup d'évènements)
* Fenêtre transparente et non décorée sous GTK

GTK me semble plus simple à coder que les MFC windows.
Par contre, la doc n'est pas aussi simple d'accès que sous java par exemple (ou .NET ~ Mono)
Un ide permettant la construction des écrans à la chaine pour une grosse application est impérative.

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   GTKBinaryClock
    •   bin
      •   Debug
        • bc.pngTélécharger ce fichier [Réservé aux membres club]Voir ce fichier1 370 octets
        • GTKBinaryClockTélécharger ce fichier [Réservé aux membres club]32 151 octets
    •   obj
      •   Debug
        • main.oTélécharger ce fichier [Réservé aux membres club]22 908 octets
        • tray1.oTélécharger ce fichier [Réservé aux membres club]5 048 octets
    • bc.pngTélécharger ce fichier [Réservé aux membres club]Voir ce fichier1 370 octets
    • GTKBinaryClock.cbpTélécharger ce fichier [Réservé aux membres club]1 254 octets
    • GTKBinaryClock.dependTélécharger ce fichier [Réservé aux membres club]39 404 octets
    • GTKBinaryClock.layoutTélécharger ce fichier [Réservé aux membres club]239 octets
    • main.cTélécharger ce fichier [Réservé aux membres club]Voir ce fichier10 467 octets

Télécharger le zip


 Sources de la même categorie

Source avec Zip Source avec une capture INFORMATION GTK CONCERNANT UNE TOUCHE par Phelim
Source avec Zip Source avec une capture [GTK+] FENÊTRE POPUP ANIMÉE EN BAS À DROITE DE L' ÉCRAN par katsankat
Source avec Zip GTK _CALCUL par jabirmed
Source avec Zip DICTIONNER RECHERCHE GTK par jabirmed
Source avec Zip JEU DE PIONS EN RESAUX EN GTK+ par karamimed

Commentaires et avis

Commentaire de petifa le 15/10/2008 15:09:26

slt dje_jay quelques remarques
-tu utilise des variables globales, à éviter quand même.
-ta fonction expose peut être améliorée car tu fais des traitements quasi identiques
#  //HH6
# //if (now_hms->tm_hour%2) cairo_set_source_rgb(cr, 0, 0, 1); // tj à 0
-tray_icon_on_menu, cette fonction ne sert à rien alors tu aurais du l'enlever.
Pour l'instant j'ai pas d'autre commentaires ...

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,374 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales