Search This Blog

Monday, May 21, 2007

example of Bresenham's line algorithm

it depends on gtk+-2.0,using function gdk_draw_point to draw points.I wrote this little program because the stupid Chinese education:they are still writing c programs compiled by turbo c and with a "graphic.h" to draw graphics.



#include <gdk/gdk.h>//in fact,I do not know whether I need this

#include <gtk/gtk.h>



void linebres(int xa, int ya, int xb, int yb,GtkWidget *widget,GdkDrawable *drawable)

{

int dx = abs(xa-xb), dy = abs(ya-yb);

int p;

int twody, twodx;

int x,y,xend,yend;

float k=dy/dx;

int temp;

if(k > 1|| k < -1){

temp = xa;

xa = ya;

ya = temp;

temp = xb;

xb = yb;

yb = temp;

}



p = 2 * dy - dx;

twody = 2 * dy;

twodx = 2 * dx;



if(xa - xb > 0){

x = xb;

y = yb;

xend=xa;

}

else{

x = xa;

y = ya;

xend = xb;

}



gdk_draw_point (drawable,widget->style->black_gc,x,y);



while(x < xend){

x++;

if(p < 0)

p += twody;

else{

y++;

p += (twody-twodx);

}

gdk_draw_point (drawable,widget->style->black_gc,x,y);

}

}





static void on_destroy (GtkWidget * widget, gpointer data)

{

gtk_main_quit ();

}



gint expose_callback(GtkWidget *widget, GdkEventAny *event, gpointer data)

{

GdkDrawable *drawable;

int i;

drawable=widget->window;

linebres (10,5,180,60,widget,drawable);

return 0;

}



int main(int argc, char **argv)

{

gtk_init ( &argc, &argv);



GdkWindowAttr attr;



GtkWidget *window;



GtkWidget *widget = gtk_drawing_area_new ();

gtk_drawing_area_size (GTK_DRAWING_AREA (widget),200,200);



window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

gtk_container_add (GTK_CONTAINER (window),widget);



g_signal_connect (G_OBJECT (window), "destroy",G_CALLBACK (on_destroy), NULL);



g_signal_connect (G_OBJECT(widget), "expose_event",GTK_SIGNAL_FUNC(expose_callback), NULL);



gtk_widget_show_all (window);



gtk_main ();



return 0;



}



Wednesday, May 16, 2007

trackpoint in gentoo

trackpoint will work fine in gentoo by the following steps:
1.enable "press to select"

echo -n 1 > /sys/devices/platform/i8042/serio1/press_to_select

2.to enable scrolling,put the following lines into xorg.conf's trackpoint section(it's an "InputDevice" section)

Option "Emulate3Buttons" "on"
Option "Emulate3TimeOut" "50"
Option "EmulateWheel" "on"
Option "EmulateWheelTimeOut" "200"
Option "EmulateWheelButton" "2"
Option "YAxisMapping" "4 5"
Option "XAxisMapping" "6 7"
Option "ZAxisMapping" "4 5"

now restart X,and enjoy the trackpoint.