{\scriptsize \begin{lstlisting}
     1	/** @file Function for drawing the robot and to calculate the absolute
     2	    postion of the robot out of the mouse-position.
     3	
     4	*/
     5	
     6	/*
     7	  Copyright (c) Andreas Hofmeier
     8	  (www.an-h.de, www.an-h.de.vu, www.lgut.uni-bremen.de/an-h/)
     9	  
    10	  This program is free software; you can redistribute it and/or modify
    11	  it under the terms of the GNU General Public License as published by
    12	  the Free Software Foundation; either version 2 of the License, or
    13	  (at your option) any later version.
    14	
    15	  This program is distributed in the hope that it will be useful, but
    16	  WITHOUT ANY WARRANTY; without even the implied warranty of
    17	  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    18	  General Public License for more details.
    19	
    20	  You should have received a copy of the GNU General Public License
    21	  along with this program; if not, write to the Free Software
    22	  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    23	*/
    24	
    25	
    26	#include <time.h>
    27	#include <math.h>
    28	#include <pthread.h>
    29	#include <stdio.h>
    30	#include <stdlib.h>
    31	#include <gtk/gtk.h>
    32	#include <glib.h>
    33	
    34	
    35	/** Function for drawing the robot and to calculate the absolute
    36	    postion of the robot out of the mouse-position.
    37	
    38	    @param widget (GtkWidget *) pointer to affected object (drawing
    39	    area).
    40	
    41	    @param x (int *) pointer to absolute x position of the robot (will
    42	    changed if mouseaction equal to 1 or 2)
    43	
    44	    @param y (int *) pointer to absolute y position of the robot (will
    45	    changed if mouseaction equal to 1 or 2)
    46	
    47	    @param mx (int) x mouse position (only relevant if mouseaction
    48	    equal to 1 or 2)
    49	
    50	    @param my (int) y mouse position (only relevant if mouseaction
    51	    equal to 1 or 2)
    52	
    53	    @param mouseaction (int) current action: 1: start moving, 2:
    54	    moving or finish moving, other: plot only
    55	
    56	*/
    57	void gui_common_drawrobot(GtkWidget *widget, int *x, int *y,
    58				  int mx, int my, int mouseaction) {
    59	
    60	  // drawing area properties
    61	  gint new_width, new_height;
    62	  int height, width;
    63	
    64	  // width and hieght of the illustration of the moving platform of
    65	  // the robot.
    66	  int hwidth, wwidth;
    67	
    68	  // current position of the moving platform
    69	  int x0, y0;
    70	
    71	  // new position of the moving platform
    72	  int x0n, y0n;
    73	
    74	  // current action: 0: draw only, 1: during moving, 2: error: click
    75	  // outside from platform
    76	  static int moving = 0;
    77	
    78	  // offset for mouse-moving
    79	  static int ox, oy;
    80	
    81	  // get size of the drawing area
    82	  gdk_drawable_get_size(widget->window,
    83				&new_width,
    84				&new_height);
    85	  width = (int) new_width;
    86	  height = (int) new_height;
    87	
    88	  // clear it
    89	  gdk_window_clear_area(widget->window, 
    90				0,0,
    91				width, height); 
    92	
    93	  // calculate the width and hieght of the illustration of the moving
    94	  // platform of the robot.
    95	  hwidth = 10 * height / 100;
    96	  wwidth = 10 * width / 100;
    97	
    98	  // moving or moving finished
    99	  if (mouseaction == 2) {
   100	    moving = 0;
   101	  }
   102	  if (moving == 1) {
   103	    // calculate the new position of the platform and set the
   104	    // variables
   105	    *x = ((mx - ox) * 100) / (width - wwidth);
   106	    *y = (((my + oy) * (-1) + (height - hwidth)) * 100) / (height - hwidth);
   107	
   108	    // platform must not beyond the window bondaries
   109	    if (*x > 100) {
   110	      *x = 100;
   111	    }
   112	    if (*x < 0) {
   113	      *x = 0;
   114	    }
   115	    if (*y > 100) {
   116	      *y = 100;
   117	    }
   118	    if (*y < 0) {
   119	      *y = 0;
   120	    }
   121	  }
   122	
   123	  // draw the horizontal (X) axies track of the robot, whish is NOT
   124	  // moving
   125	  y0 = ((0 * (height - hwidth) / 100) - (height  - hwidth)) * (-1);
   126	  gdk_draw_line(widget->window,
   127			widget->style->black_gc,
   128			0,y0,
   129			width,y0);
   130	  gdk_draw_line(widget->window,
   131			widget->style->black_gc,
   132			0,y0 + hwidth,
   133			width,y0 + hwidth);
   134	
   135	  // Draw the current possition of the movind platform of the
   136	  // robot. Illustrated as a black rectangular.
   137	  // +- calculate it's current position
   138	  x0 = *x * (width - wwidth) / 100;
   139	  y0 = ((*y * (height - hwidth) / 100) - (height  - hwidth)) * (-1);
   140	  // +- draw lines under it.
   141	  gdk_draw_line(widget->window,
   142			widget->style->black_gc,
   143			x0,y0,
   144			x0,height);
   145	  gdk_draw_line(widget->window,
   146			widget->style->black_gc,
   147			x0 + wwidth,y0,
   148			x0 + wwidth,height);
   149	  // +- draw the platform
   150	  gdk_draw_rectangle(widget->window,
   151			     widget->style->black_gc,
   152			     1,
   153			     x0,y0,
   154			     wwidth, hwidth);
   155	
   156	  // start moving the platform
   157	  if ((moving == 0) && (mouseaction == 1)) {
   158	    if ((mx > x0) && (mx < (x0 + wwidth))
   159		&& (my > y0) && (my < (y0 + hwidth))) {
   160	      // click inside form platform -- moving...
   161	      moving = 1;
   162	      // offset for moving
   163	      ox = mx - x0;
   164	      oy = y0 - my;
   165	    } else {
   166	      // error, click outside from platform
   167	      moving = 2;
   168	    }
   169	  }
   170	}
   171	
   172	
\end{lstlisting}}
