Ejemplo n.º 1
0
int Controls_Handle_MouseMotion(int button,int state, int x, int y)
{
  //fprintf(stderr,"Mouse %u,%u\n",x,y);
  frame.mouse.mouse_x=x;
  frame.mouse.mouse_y=y;

   if  ( frame.mouse.left_pressed == 1 ) {
                                         frame.dragging_screen=1;
                                         if (PrintDevMsg()) fprintf(stderr,"DRAGGING \n");
                                       } else
                                       {
                                         frame.dragging_screen=0;
                                       //  fprintf(stderr,"NO DRAGGING \n");
                                       }

  if ( frame.dragging_screen == 1 )
   {
         float difference_x = frame.mouse.mouse_x - frame.mouse.last_mouseclick_at_x ;
         float difference_y = frame.mouse.mouse_y - frame.mouse.last_mouseclick_at_y ;

         frame.mouse.last_mouseclick_at_x = frame.mouse.mouse_x;
         frame.mouse.last_mouseclick_at_y = frame.mouse.mouse_y;

         frame.desired_x+=difference_x/20; /* We want to drag the screen to the oposite direction / the number 24 is the total viewable area of the window*/
         frame.desired_y-=difference_y/12; /* We want to drag the screen to the oposite direction / the number 24 is the total viewable area of the window*/

         frame.transitions.seek_move_activated=0;
         CalculateActiveImage_AccordingToPosition(1);
       return 1;
   }

  return 0;
}
Ejemplo n.º 2
0
static void KeyCallback(unsigned char key, int x, int y)
{
  if (key==27) {  glutLeaveMainLoop(); /*EnableScreenSaver(); exit(0);*/ } else/* Closes Application on Escape Key*/
  if (key=='j') { ToggleFullscreen();  /* Toggles Fullscreen "window" */ }

  /* The rest commands are handled in controls.cpp / controls.h */
  unsigned int nokey = Controls_Handle_Keyboard(key,x,y);
  if ( nokey == 0 )
  {
     key=0;
     if (PrintDevMsg()) fprintf(stderr,"X:%f Y:%f Z:%f \n",frame.vx,frame.vy,frame.vz);
     usleep(100);
     glutPostRedisplay();
  }
}
Ejemplo n.º 3
0
int Controls_Handle_MouseButtons(int button,int state, int x, int y)
{
    frame.mouse.mouse_x=x;
    frame.mouse.mouse_y=y;
    if (PrintDevMsg()) fprintf(stderr,"Mouse %u,%u\n",x,y);
    if ( frame.mouse.block_mouse_calls_until > frame.tick_count ) { return 0; /* We are blocking mouse calls to improve user friendlieness :P */ }


    /*
       According to zoom factor we will use a desired_step matching it in order to have smooth movement over the image
       RefreshDesiredStep_AccordingToPosition calculates it and loads it in frame.desired_step variable
    */
    RefreshDesiredStep_AccordingToPosition();
    /*---------------------------------------------------------------------------------------------------------------*/

   int is_not_mouse_wheel_event=1;
   int is_a_doubleclick_event=0;

   /*  MOUSE WHEEL HANDLING
       >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
   if ( button==GLUT_WHEEL_UP )
   {
     if (state == GLUT_UP )
      {
        frame.desired_z-=frame.desired_step;
      }
     is_not_mouse_wheel_event=0;
   } else
   if ( button==GLUT_WHEEL_DOWN )
   {
     if (state == GLUT_UP )
      {
        frame.desired_z+=frame.desired_step;
      }
     is_not_mouse_wheel_event=0;
   }
   /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
   else


   /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
   if (button==GLUT_LEFT_BUTTON)
     {
       if (state == GLUT_UP )
       {
         frame.mouse.left_pressed=1;
         if (PrintDevMsg()) fprintf(stderr,"Left mouse button UP ( but down in reality ) \n");
       } else
       if (state == GLUT_DOWN )
       {
         frame.mouse.left_pressed=1;
         if (PrintDevMsg()) fprintf(stderr,"Left mouse button DOWN \n");
       } else
       {
         if (PrintDevMsg()) fprintf(stderr,"Left mouse button OTHER ( but up in reality :P )\n");
           if ( frame.mouse.left_pressed==1 ) {
                                                frame.mouse.left_pressed=0;
                                              } else /* RELEASING DRAG AND DROP */
           {
             /* UP Without already been used to drag */
             if (PrintDevMsg()) fprintf(stderr,"Strange state");
             frame.dragging_screen=0;
           }
       }
     }
   /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
     else
   /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */
if (button==GLUT_RIGHT_BUTTON)
     {
       if (state == GLUT_DOWN )
       {
         if (PrintDevMsg()) fprintf(stderr,"Right mouse button DOWN \n");

       } else
       if (state == GLUT_UP )
       {
         frame.show_time=550; // <- show timer

         if (PrintDevMsg()) fprintf(stderr,"Right mouse button UP \n");
            if ( frame.mouse.left_pressed==1 ) {  } else /* RELEASING DRAG AND DROP */
           {
             /* UP Without already been used to drag */
           }
       }
     }
   /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */






  if ( is_not_mouse_wheel_event == 1 )
   {

    if  ( frame.mouse.left_pressed == 1 ) {
                                         frame.dragging_screen=1;
                                         if (PrintDevMsg()) fprintf(stderr,"START DRAGGING \n");
                                       } else
                                       {
                                         frame.dragging_screen=0;
                                         if (PrintDevMsg()) fprintf(stderr,"START NO DRAGGING \n");
                                       }

    if ( frame.dragging_screen == 1 )
	      {
           frame.mouse.last_mouseclick_at_x=x;
	       frame.mouse.last_mouseclick_at_y=y;
	       frame.mouse.last_mouseclick_at_z=0;
//	       frame.mouse.button_pressed=button;
	       frame.dragging_screen=1;

           frame.mouse.last_click_time=frame.tick_count;
           return 1;
	      }


    if ( is_a_doubleclick_event == 1 )
    {
      /* DOUBLE CLICK*/
      //fprintf(stderr,"Double Click Pressed at %u %u , button %u time %u - %u = %u \n",x,y,button,frame.tick_count,frame.mouse.last_click_time,frame.tick_count - frame.mouse.last_click_time);
	  SetDestinationCenter();
	  return 1;
    }

  }

    return 0;

}
Ejemplo n.º 4
0
int Controls_Handle_Keyboard(unsigned char key, int x, int y)
{
    /*
       According to zoom factor we will use a desired_step matching it in order to have smooth movement over the image
       RefreshDesiredStep_AccordingToPosition calculates it and loads it in frame.desired_step variable
    */
   // RefreshDesiredStep_AccordingToPosition();
    /*---------------------------------------------------------------------------------------------------------------*/
    char label[256]={0};

    int nokey=0;
    if (PrintDevMsg()) fprintf(stderr,"Key %u \n",key);
    switch (key)
    {
        case 1 : /* UP */    MoveToPicture(D_UP); break;
        case 2 : /* DOWN */  MoveToPicture(D_DOWN); break;
        case 3 : /* LEFT */  MoveToPicture(D_LEFT); break;
        case 4 : /* RIGHT */ MoveToPicture(D_RIGHT); break;

        case 9 : /* TAB */   frame.show_information=550; /* 550 is the time !*/ break;
        case '`' : /*Tilda button*/ frame.show_time=550; break;

        case 13  : /* ENTER */ ToggleAutomaticSlideshow(); break;
        case ' ' : /* SPACE */ ToggleAutomaticSlideshow(); break;

        //Buttons 0  -  9 , directory transactions
        case 48+0 : /*Number 0*/ if (PerformDirectoryTransaction(GetPictureDirectoryListIndex(frame.active_image_place),0)>0)  {TriggerNextPictureSlideShow(); usleep(10000); return 0; } break;
        case 48+1 : /*Number 1*/ if (PerformDirectoryTransaction(GetPictureDirectoryListIndex(frame.active_image_place),1)>0)  {TriggerNextPictureSlideShow(); usleep(10000); return 0; } break;
        case 48+2 : /*Number 2*/ if (PerformDirectoryTransaction(GetPictureDirectoryListIndex(frame.active_image_place),2)>0)  {TriggerNextPictureSlideShow(); usleep(10000); return 0; } break;
        case 48+3 : /*Number 3*/ if (PerformDirectoryTransaction(GetPictureDirectoryListIndex(frame.active_image_place),3)>0)  {TriggerNextPictureSlideShow(); usleep(10000); return 0; } break;
        case 48+4 : /*Number 4*/ if (PerformDirectoryTransaction(GetPictureDirectoryListIndex(frame.active_image_place),4)>0)  {TriggerNextPictureSlideShow(); usleep(10000); return 0; } break;
        case 48+5 : /*Number 5*/ if (PerformDirectoryTransaction(GetPictureDirectoryListIndex(frame.active_image_place),5)>0)  {TriggerNextPictureSlideShow(); usleep(10000); return 0; } break;
        case 48+6 : /*Number 6*/ if (PerformDirectoryTransaction(GetPictureDirectoryListIndex(frame.active_image_place),6)>0)  {TriggerNextPictureSlideShow(); usleep(10000); return 0; } break;
        case 48+7 : /*Number 7*/ if (PerformDirectoryTransaction(GetPictureDirectoryListIndex(frame.active_image_place),7)>0)  {TriggerNextPictureSlideShow(); usleep(10000); return 0; } break;
        case 48+8 : /*Number 8*/ if (PerformDirectoryTransaction(GetPictureDirectoryListIndex(frame.active_image_place),8)>0)  {TriggerNextPictureSlideShow(); usleep(10000); return 0; } break;
        case 48+9 : /*Number 9*/ if (PerformDirectoryTransaction(GetPictureDirectoryListIndex(frame.active_image_place),9)>0)  {TriggerNextPictureSlideShow(); usleep(10000); return 0; } break;


        case 'o': ResetCameraOrientation();
                  NewLabel(frame.desired_x,frame.desired_y,(char *) "Reset Camera to center..!");
                  break;

        case 'u': CreateObjectFountain(2); /*"PARTICLE" EFFECT*/ break;
        case 'i': CreateObjectFountain(3); /*"PARTICLE" EFFECT*/ break;
        case 'k': CreateObjectFountain(6); /*"PARTICLE" EFFECT*/ break;
        case 'j': return 1; /*This key is reserved for fullscreen*/ break;
        //case 'j': CreateObjectFountain(5); /*"PARTICLE" EFFECT*/ break;


        case 'q': RotatePictureLeft(); break;
        case 'e': RotatePictureRight();  break;


        case 'r': MoveDestinationCenter(D_OUT); /*frame.desired_z+=frame.desired_step;*/ break;
        case 'f': MoveDestinationCenter(D_IN); /*frame.desired_z-=frame.desired_step;*/ break;
        case 'a': MoveDestinationCenter(D_LEFT); /*frame.desired_x+=frame.desired_step;*/ break;
        case 'd': MoveDestinationCenter(D_RIGHT); /*frame.desired_x-=frame.desired_step;*/ break;
        case 's': MoveDestinationCenter(D_UP); /*frame.desired_y+=frame.desired_step;*/ break;
        case 'w': MoveDestinationCenter(D_DOWN); /*frame.desired_y-=frame.desired_step;*/ break;
        case '-': if ( frame.time_ms_between_two_transitions >= 100 )
                     { SetTransitionTime(frame.time_ms_between_two_transitions-100);  }
                  break;
        case '+': SetTransitionTime(frame.time_ms_between_two_transitions+100); break;
        case 'z': frame.angle_x-=0.5; break;
        case 'c': frame.angle_x+=0.5; break;
        case 't': frame.angle_y-=0.5; break;
        case 'g': frame.angle_y+=0.5; break;
        case 'y': frame.angle_z-=0.5; break;
        case 'h': frame.angle_z+=0.5; break;
        case 'n': ChangeLayout();
                  sprintf(label," Layout set to %s (%u)",GetLayoutName(),frame.layout.layout_mode);
                  NewLabel(frame.desired_x,frame.desired_y,(char *) label);
                  break; //if (ENABLE_WIGGLING) {ENABLE_WIGGLING=0;} else {ENABLE_WIGGLING=1;}
        case 'm': ToggleTransitionMode(); break;

        case 153: MoveToPicture(D_UP);   MoveToPicture(D_UP);   MoveToPicture(D_UP);  MoveToPicture(D_UP);
                  sprintf(label," Go To %u/%u",frame.active_image_place,frame.total_images);
                  NewLabel(frame.desired_x,frame.desired_y,(char *) label);
                  break; //PAGE UP
        case 161: MoveToPicture(D_DOWN); MoveToPicture(D_DOWN); MoveToPicture(D_DOWN); MoveToPicture(D_DOWN);
                  sprintf(label," Go To %u/%u",frame.active_image_place,frame.total_images);
                  NewLabel(frame.desired_x,frame.desired_y,(char *) label);
                  break; //PAGE DOWN

        case 'b':  break;

       default : nokey=1;
            break;
    }

  return nokey;
}
Ejemplo n.º 5
0
int make_texture(struct Picture * picturedata,int enable_mipmaping)
{

	if ( picturedata == 0 ) { fprintf(stderr,"Error making texture from picture , accomodation structure is not allocated\n");
	                          return 0; }

    unsigned long this_texture = picturedata->width * picturedata->height * /*RGBA ->*/ 4 /* <- RGBA*/ ;
    if ( !GPU_Memory_can_accomodate(this_texture) ) {
                                                      fprintf(stderr,"Abort making texture , GPU cant accomodate it ( %u KB ) \n",(unsigned int) this_texture/1024);
                                                      SignalGPUFull=1;
                                                      return 0;
                                                    }



    glEnable(GL_TEXTURE_2D);

     PrintDirectoryListItem(picturedata->directory_list_index);

     GLuint new_tex_id=0;
     if (PrintOpenGLDebugMsg()) fprintf(stderr,"OpenGL Generating new Texture \n");
     glGenTextures(1,&new_tex_id);
     if ( complain_about_errors() ) { return 0; }

     if (PrintOpenGLDebugMsg()) fprintf(stderr,"OpenGL Binding new Texture \n");
     glBindTexture(GL_TEXTURE_2D,new_tex_id);
     if ( complain_about_errors() ) { return 0; }
     glFlush();

    picturedata->gpu.gl_rgb_texture=new_tex_id;


    unsigned int depth_flag=GL_RGB;
    char * rgba_data = picturedata->system.rgb_data;

/* RGBA Software conversion for debugging :p   HAS ANOTHER PART (line 150+ ) THAT DOES THE FREE CALL
    rgba_data = (char*) malloc(picturedata->width*picturedata->height*4*sizeof(unsigned char));
    if (rgba_data==0)
      {
       rgba_data = picturedata->rgb_data;
      } else
      {
       depth_flag=GL_RGBA;
       software_add_alpha_channel(picturedata->rgb_data,rgba_data,picturedata->width,picturedata->height);
       fprintf(stderr,"Using Alpha texture conversion\n");
      }
*/
  unsigned int error_num=0;

  if ( ( enable_mipmaping == 1 ) || ( frame.force_mipmap_generation ==1 ) )
   {
      /* LOADING TEXTURE --WITH-- MIPMAPING */
      glPixelStorei(GL_UNPACK_ALIGNMENT,1);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);                      // GL_RGB
      glTexImage2D(GL_TEXTURE_2D, 0, depth_flag, picturedata->width , picturedata->height, 0, depth_flag, GL_UNSIGNED_BYTE, (const GLvoid *) rgba_data);
      error_num=glGetError();
      if  ( error_num!=0 ) { printoutOGLErr(error_num); fprintf(stderr,"Creating texture %ux%u:%u ( initial %ux%u )\n",picturedata->width,picturedata->height,depth_flag,picturedata->initial_width,picturedata->initial_height); return 0; }
   } else
   {
      /* LOADING TEXTURE --WITHOUT-- MIPMAPING - IT IS LOADED RAW*/
      glPixelStorei(GL_UNPACK_ALIGNMENT,1);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);                       //GL_RGB
      glTexImage2D(GL_TEXTURE_2D, 0, depth_flag, picturedata->width , picturedata->height, 0, depth_flag, GL_UNSIGNED_BYTE,(const GLvoid *) rgba_data);
      error_num=glGetError();
      if  ( error_num!=0 ) { printoutOGLErr(error_num); fprintf(stderr,"Creating texture %ux%u:%u ( initial %ux%u )\n",picturedata->width,picturedata->height,depth_flag,picturedata->initial_width,picturedata->initial_height); return 0; }
   }

/* RGBA Software conversion for debugging :p HAS A PREVIOUS PART
   if ( (rgba_data != 0)&&(depth_flag=GL_RGBA) )  { free(rgba_data); }
*/


   if (enable_mipmaping)
    {
     if (PrintDevMsg()) fprintf(stderr,"Using mipmaps there is a lot more memory consumption , needs work..\n");
    }





    /* PICTURE IS LOADED IN GPU SO WE CAN UNLOAD IT FROM MAIN RAM MEMORY */
      if ( picturedata->system.rgb_data != 0 )
        {
          frame.system.usedRAM-=picturedata->system.rgb_data_size;
          free(picturedata->system.rgb_data);
          picturedata->system.rgb_data=0;
          picturedata->system.rgb_data_size=0;
        }

    frame.gpu.lastTexture=this_texture;
    frame.gpu.usedRAM+=frame.gpu.lastTexture;

    picturedata->gpu.texture_data_size=this_texture;
    picturedata->gpu.marked_for_texture_loading=0;
    picturedata->gpu.texture_loaded=1;

    if ( complain_about_errors() ) { return 0; }

    if (PrintOpenGLDebugMsg()) fprintf(stderr,"OpenGL Texture of size ( %u %u ) id is %u\n", picturedata->width , picturedata->height,picturedata->gpu.gl_rgb_texture);

    glFlush();

         SoundLibrary_PlaySound(LOADED_PICTURE);
    return 1;
}