#51 Le 22/12/2009, à 14:35
- bece
Re : Souris-mètre en C
Ok, je vais regarder tout ça.
"L'informatique, c'est l'art de passer 15 jours à gagner 5 millisecondes"
Hors ligne
#52 Le 22/12/2009, à 18:38
- n3o51
Re : Souris-mètre en C
bonsoir ok pour le lien dans la page suivante mais je prends lequel celui ou tu dit si ça vous interresse le code gtk et ensuite la ligne de compilation c'est gcc etc ... ?
Welcome to the real world
________________________________
Hors ligne
#53 Le 22/12/2009, à 19:08
- bece
Re : Souris-mètre en C
voici le code :
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <math.h>
#define INTERVAL 100
typedef struct
{
gint last_x, last_y;
gdouble distance;
} MotionRecord;
gdouble distance (gint dx, gint dy)
{
static gboolean initialized = FALSE;
static gdouble dx_mm, dy_mm;
if (!initialized)
{
gdouble width_meter, width_pixel, height_meter, height_pixel;
GdkScreen *screen = gdk_screen_get_default ();
width_meter = (gdouble)gdk_screen_get_width_mm (screen) / 1000;
width_pixel = gdk_screen_get_width (screen);
height_meter = (gdouble)gdk_screen_get_height_mm (screen) / 1000;
height_pixel = gdk_screen_get_height (screen);
dx_mm = (gdouble)width_meter / width_pixel;
dy_mm = (gdouble)height_meter / height_pixel;
initialized = TRUE;
}
return sqrt (pow (dx_mm*dx, 2) + pow (dy_mm*dy, 2));
}
gboolean record_motion (gpointer data)
{
static gboolean initialized = FALSE;
MotionRecord *record = (MotionRecord *)data;
GdkWindow *root_window;
gint x, y;
root_window = gdk_screen_get_root_window (gdk_screen_get_default ());
gdk_window_get_pointer (root_window, &x, &y, NULL);
if (initialized)
{
gint dx, dy;
dx = record->last_x - x;
dy = record->last_y - y;
record->distance += distance (dx, dy);
}
else
initialized = TRUE;
record->last_x = x;
record->last_y = y;
g_print ("distance: %.2fm\n", record->distance);
return TRUE;
}
int main (int argc, char **argv)
{
MotionRecord record = {0};
gtk_init (&argc, &argv);
g_timeout_add (INTERVAL, record_motion, &record);
gtk_main ();
return EXIT_SUCCESS;
}
Et la ligne pour compiler :
gcc -o init init.c -Wall -g -pedantic $(pkg-config --libs --cflags gtk+-2.0)
"L'informatique, c'est l'art de passer 15 jours à gagner 5 millisecondes"
Hors ligne
#54 Le 22/12/2009, à 20:53
- n3o51
Re : Souris-mètre en C
Merci bien j'essaie des que j'ai 5 minute
Welcome to the real world
________________________________
Hors ligne
#55 Le 22/12/2009, à 23:23
- n3o51
Re : Souris-mètre en C
sympa niveau précision ?
sinon il affiche des lignes dans le terminal avec distance même si la souris ne bouge pas dur de mettre cela dans conky
faudrait aussi pouvoir récupérer les mètres parcourus depuis l'utilisation du prog
Welcome to the real world
________________________________
Hors ligne
#56 Le 22/12/2009, à 23:46
- tiky
Re : Souris-mètre en C
sympa niveau précision ?
sinon il affiche des lignes dans le terminal avec distance même si la souris ne bouge pas dur de mettre cela dans conky
![]()
faudrait aussi pouvoir récupérer les mètres parcourus depuis l'utilisation du prog
C'est en cours . Avec un widget transparent multi-plateforme et le support de plusieurs unités de distance/vitesse/accélération.
Conseil d'expert: il vous faut un dentifrice adapté...
Hors ligne
#57 Le 23/12/2009, à 00:55
- n3o51
Re : Souris-mètre en C
Cool merci a toi
Welcome to the real world
________________________________
Hors ligne