/* NIGHTFALL OpenGL Interface                                              */
/* Copyright (C) 2001 Rainer Wichmann & Markus Kuster                      */
/*                                                                         */
/*  This program is free software; you can redistribute it                 */
/*  and/or modify                                                          */
/*  it under the terms of the GNU General Public License as                */
/*  published by                                                           */
/*  the Free Software Foundation; either version 2 of the License, or      */
/*  (at your option) any later version.                                    */
/*         
                                                                */
/*  This program is distributed in the hope that it will be useful,        */
/*  but WITHOUT ANY WARRANTY; without even the implied warranty of         */
/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
/*  GNU General Public License for more details.                           */
/*                                                                         */
/*  You should have received a copy of the GNU General Public License      */
/*  along with this program; if not, write to the Free Software            */
/*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */

/* ANSI C forbids an empty source file, so put this outside                */
/* do nothing here if we don't have OpenGL                                 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Light.h"

#ifdef  _WITH_OPENGL
#include "LightGLPrefs.h"

/******************************************************************
 @package   nightfall
 @author    Markus Kuster (kuster@astro.uni-tuebingen.de)
 @version   1.0
 @short     Keyboard event handling 
 @param     (GtkWidget)   *widget pointer to the GL area widget
            (GdkEventKey) *event  the key event
 @return    (void)   
 @heading   Open GL Animation
*******************************************************************/
gint GLKeyboard(GtkWidget *widget, GdkEventKey *event)
{
  DispInfo *DispInfoPtr;

  DispInfoPtr = (DispInfo*)gtk_object_get_data(GTK_OBJECT(widget), "DispInfo");

  if (gtk_gl_area_make_current(GTK_GL_AREA(glArea)))
    {
      switch (event->keyval) {
	
      case GDK_space: /* reset viewing angles */
	/* reset orientation to real observer default position;
	   resets trackball quads, xpos and zoom       */
	DispInfoPtr->xpos = 0;
	DispInfoPtr->zoom = 1.;
	DispInfoPtr->quat[0] =0.;
	DispInfoPtr->quat[1] =0.;
	DispInfoPtr->quat[2] =0.;
	DispInfoPtr->quat[3] =1.;
	
	/* Don't know why we need two upates of the viewport TBD !!*/
	GLDisplayAll(); 
	GLDisplayAll();
	break;
	
      case GDK_a: /* toggle axes ON/OFF */
	if (Flags.axes == OFF) {
	  Flags.axes = ON;
	} else {
	  Flags.axes = OFF;
	}
	GLDisplayAll(); 
	break;
	
      case GDK_f: /* toggle to rendered mode */
	Flags.wireframe = OFF;
	Flags.points    = ON;
	/* check for points on/off TBD */
	if (GLPrefWinOpened == TRUE) 
	  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonPoints), TRUE);
	GLUpdateAll();
	GLDisplayAll();
	break; 
	
      case GDK_l: /* toggle to wire frame mode */
	Flags.wireframe = ON;
	Flags.points    = OFF;
	/* check for points on/off needed TBD */
	if (GLPrefWinOpened == TRUE) 
	  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonWire), TRUE);
	GLUpdateAll();
	GLDisplayAll();
	break; 
	
      case GDK_o: /* toggle to opaque mode */
	Flags.wireframe = OFF;
	Flags.points    = OFF;
	/* check for points on/off needed TBD */
	if (GLPrefWinOpened == TRUE) 
	  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonOpaque), TRUE);
	GLUpdateAll();
	GLDisplayAll();
	break; 
	
      case GDK_m: /* toggle movie mode ON/OFF */
	if (Flags.movie == OFF) {
	  Flags.movie = ON;
	} else {
	  Flags.movie = OFF;
	}
	break;
	
      case GDK_t: /* toggle texturing ON/OFF */
	if (Flags.texture == OFF) {
	  Flags.texture = ON;
	  if (GLPrefWinOpened == TRUE) {
	    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonTexture), TRUE);
	    gtk_widget_set_sensitive(ButtonPrimTxt,TRUE);
	    gtk_widget_set_sensitive(ButtonSecTxt,TRUE);
	    gtk_widget_set_sensitive(PrimTxtLabel,TRUE);
	    gtk_widget_set_sensitive(SecTxtLabel,TRUE);
#ifdef HAVE_DISK
	    gtk_widget_set_sensitive(ButtonDiskTxt,TRUE);
	    gtk_widget_set_sensitive(DiskTxtLabel,TRUE);
#endif 
	  }
	} else {
	  Flags.texture = OFF;
	  if (GLPrefWinOpened == TRUE) {
	    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonTexture), FALSE);
	    gtk_widget_set_sensitive(ButtonPrimTxt,FALSE);
	    gtk_widget_set_sensitive(ButtonSecTxt,FALSE);
	    gtk_widget_set_sensitive(PrimTxtLabel,FALSE);
	    gtk_widget_set_sensitive(SecTxtLabel,FALSE);
#ifdef HAVE_DISK
	    gtk_widget_set_sensitive(ButtonDiskTxt,FALSE);
	    gtk_widget_set_sensitive(DiskTxtLabel,FALSE);
#endif 
	  }
	}
	GLDisplayAll();
	break;
	
      case GDK_p: /* toggle texture for primary ON/OFF */
	if (Texture[Primary].IsOn == ON) {
	  Texture[Primary].IsOn = OFF;
	  if (GLPrefWinOpened == TRUE)
	    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonPrimTxt), FALSE);
	} else {
	  Texture[Primary].IsOn = ON;
	  if (GLPrefWinOpened == TRUE)
	    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonPrimTxt), TRUE);
	}
	GLDisplayAll();
	break;
	
      case GDK_s: /* toggle texture for secondary ON/OFF */
	if (Texture[Secondary].IsOn == ON) {
	  Texture[Secondary].IsOn = OFF;
	  if (GLPrefWinOpened == TRUE)
	    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonSecTxt), FALSE);
	} else {
	  Texture[Secondary].IsOn = ON;
	  if (GLPrefWinOpened == TRUE)
	    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonSecTxt), TRUE);
	}
	GLDisplayAll();
	break;
	
#ifdef HAVE_DISK
      case GDK_d: /* toggle texture for disk ON/OFF */
	if (Texture[Disk].IsOn == ON) {
	  Texture[Disk].IsOn = OFF;
	  if (GLPrefWinOpened == TRUE)
	    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonDiskTxt), FALSE);
	} else {
	  Texture[Disk].IsOn = ON;
	  if (GLPrefWinOpened == TRUE)
	    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ButtonDiskTxt), TRUE);
	}
	GLDisplayAll();
	break;
#endif 
	
      case GDK_w: /* toggle texturing type */
	/* cycle thru texturing types R.W. 23.12.2002 */
	if (Flags.textype == IMAGE) {
	  Flags.textype = TEMP;
	} else if (Flags.textype == TEMP) {
	  Flags.textype = GRAV;
	} else if (Flags.textype == GRAV) {
	  Flags.textype = FLUX;
	} else if (Flags.textype == FLUX) {
	  Flags.textype = VELOCITY;
	} else {
	  Flags.textype = IMAGE;
	}
	GLInitTexture(Primary, Flags.textype);
	GLInitTexture(Secondary, Flags.textype);

#ifdef HAVE_DISK
	GLInitTexture(Disk, Flags.textype);
#endif
	GLDisplayAll();
	break; 
	
      case GDK_Left: /* decrease observers x-position */
	Flags.GLdistancex-=0.02;
	GLDisplayAll();
	break;
	
      case GDK_Right: /* increase observers x-position */
	Flags.GLdistancex+=0.02;
	GLDisplayAll();
	break;
	
      default:
	break;
      }

      /* prevent the default handler from being run */
      gtk_signal_emit_stop_by_name(GTK_OBJECT(glArea),"key_press_event"); 
    }
  return TRUE;
}

#endif /* OpenGL end */






syntax highlighted by Code2HTML, v. 0.9.1