Accueil > > > BINARY CLOCK GTK AVEC CONTRÔLE EN TRAY SOUS LINUX
BINARY CLOCK GTK AVEC CONTRÔLE EN TRAY SOUS LINUX
Information sur la source
Description
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.
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
MATRICE TEMPLATEMATRICE TEMPLATE par hjr2610
Cliquez pour lire la suite par hjr2610 RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|