Exemple #1
0
static void handle_jump( LWControl *ectl, void *edata )
{
   char a[ 24 ];
   int i, jcontext;

   GET_STR( ectl, a, sizeof( a ));
   GET_INT( ctl[ 12 ], jcontext );
   i = atoi( a );

   switch ( jcontext ) {
      case 1:   change_pos( pos, i );  break;
      case 2:   change_pos( pos, -i ); break;
      default:  change_pos( 0, i );    break;
   }
}
Exemple #2
0
t_map	*make_intra_lab(t_map *my_map, int larg, int haut)
{
  int	nb_rand;
  int	dir;
  int	cmp;

  cmp = 0;
  my_map->x = 1;
  my_map->y = 1;
  srand(time(NULL));
  my_map->seen[my_map->y][my_map->x] = 1;
  my_map->cmp_lab = (larg * haut);
  while (cmp != my_map->cmp_lab-1)
    {
      nb_rand = rand()%4+1;
      dir = check_pos(nb_rand, my_map);
      my_map = save(my_map);
      while (dir == 0)
	{
	  nb_rand = rand()%4+1;
	  dir = check_pos(nb_rand, my_map);
	}
      my_map = change_pos(my_map, dir);
      cmp++;
    }
  return(my_map);
}
void RubixCube::rotate_cube_plane()
{
	if(!rotating)
	{
		int i,j,k;
		if(plane.back()!=0 && plane.back()!=1 && plane.back()!=2)
			exit(2);
        
		switch(axis.back())
		{
            case 0:
                change_pos(dir,cubepos[plane.back()][0][0],cubepos[plane.back()][0][1],cubepos[plane.back()][0][2],cubepos[plane.back()][1][0],cubepos[plane.back()][1][1],cubepos[plane.back()][1][2],cubepos[plane.back()][2][0],cubepos[plane.back()][2][1],cubepos[plane.back()][2][2]);
                break;
            case 1:
                change_pos(dir,cubepos[2][plane.back()][0],cubepos[2][plane.back()][1],cubepos[2][plane.back()][2],cubepos[1][plane.back()][0],cubepos[1][plane.back()][1],cubepos[1][plane.back()][2],cubepos[0][plane.back()][0],cubepos[0][plane.back()][1],cubepos[0][plane.back()][2]);
                break;
            case 2:
                change_pos(dir,cubepos[0][0][plane.back()],cubepos[1][0][plane.back()],cubepos[2][0][plane.back()],cubepos[0][1][plane.back()],cubepos[1][1][plane.back()],cubepos[2][1][plane.back()],cubepos[0][2][plane.back()],cubepos[1][2][plane.back()],cubepos[2][2][plane.back()]);
                break;
            default:
                exit(2);
		}
		set_centre();
        
		switch(axis.back())
		{
            case 0:
                for(j=0;j<3;j++)
                    for(k=0;k<3;k++)
                        c[cubepos[plane.back()][j][k]].rotate(0,dir);
                break;
            case 1:
                for(i=0;i<3;i++)
                    for(k=0;k<3;k++)
                        c[cubepos[i][plane.back()][k]].rotate(1,dir);
                break;
            case 2:
                for(i=0;i<3;i++)
                    for(j=0;j<3;j++)
                        c[cubepos[i][j][plane.back()]].rotate(2,dir);
                break;
		}
    }
	else
		glutIdleFunc(NULL);
}
Exemple #4
0
static int partition(elem_t *data, int s, int f)
{
	int i, j;
	j = s-1;
	for (i = s; i <= f; i++){
		if (SE(data[i].value, data[f].value)){
			j++;
			change_pos(&data[i], &data[j]);
		}	
	}
	return j; 
}
Exemple #5
0
static void handle_scroll( LWControl *ectl, void *edata )
{
   int i, newpos;

   inscroll = 1;
   GET_INT( ectl, i );
   newpos = i * ( filesize / 1000 );
   if ( newpos > filesize - pagesize )
      newpos = filesize - pagesize;
   if ( newpos < 0 ) newpos = 0;
   change_pos( 0, newpos );
   inscroll = 0;
}
void nxtCanvasWidget::wheelEvent( QWheelEvent *event ){
	if( !is_moveable )
		return;
	
	//Set modifiers
	key_control = event->modifiers() & Qt::ControlModifier;
	key_shift = event->modifiers() & Qt::ShiftModifier;
	
	int amount = event->delta() / 8;
	
	if( key_control ){
		//Zoom
		if( amount > 0 )
			zoom_at( event->pos(), current_zoom+1 );
		else
			zoom_at( event->pos(), current_zoom-1 );
	}
	else if( key_shift )
		change_pos( amount, 0 );
	else
		change_pos( 0, -amount );
}
Exemple #7
0
static void handle_search( LWControl *ectl, void *edata )
{
   char userstr[ 64 ];
   int newpos;

   if ( !fp ) return;

   GET_INT( ctl[ 14 ], searchtype );
   GET_STR( ctl[ 13 ], userstr, sizeof( userstr ));
   if ( strlen( userstr ) == 0 ) return;

   newpos = pos;
   if ( search( fp, &newpos, userstr, searchtype, datatype, unsign, byteorder ))
      change_pos( 0, newpos );
   else
      msgf->info( "Search string not found.", NULL );
}
Exemple #8
0
t_bunny_response	mainloop(t_data *data)
{
  if (data->player->coef[0] == 0 && data->player->coef[1] == 0)
    if (to_next_node(data) == - 1)
      return (EXIT_ON_ERROR);
  if (data->player->coef[0] != 0 && data->player->coef[1] != 0)
    move_perso(data);
  if (data->id_plan == 0)
    {
      change_pos(data);
      change_pos_nuages(data);
      have_pos(data);
    }
  else if (data->id_plan == 1)
    move_poteau(data);
  envoi_to_copy(data);
  tektext(data->pix, data->text);
  change_pos_perso(data->player->mov[CUR]->calque[0]->pix, data->loop);
  bunny_blit(&data->win->buffer, &data->pix->clipable, data->pos);
  bunny_display(data->win);
  return (GO_ON);
}
Exemple #9
0
static void handle_key( LWPanelID panel, void *pdata, LWDualKey key )
{
   if ( !fp ) return;

   switch ( key )
   {
      case LWDK_SC_UP:     change_pos( pos, -linesize );         break;
      case LWDK_SC_DOWN:   change_pos( pos, linesize );          break;
      case LWDK_SC_LEFT:   change_pos( pos, -1 );                break;
      case LWDK_SC_RIGHT:  change_pos( pos, 1 );                 break;

      case LWDK_PAGEUP:
      case LWDK_PAD_9:     change_pos( pos, -pagesize );         break;
      case LWDK_PAGEDOWN:
      case LWDK_PAD_3:     change_pos( pos, pagesize );          break;
      case LWDK_HOME:
      case LWDK_PAD_7:     change_pos( 0, 0 );                   break;
      case LWDK_END:
      case LWDK_PAD_1:     change_pos( 0, filesize - pagesize ); break;

      case 'p':  handle_print();                  break;
      case 'n':  handle_new( ctl[ 16 ], NULL );   break;
      case 'j':  handle_jump( ctl[ 7 ], NULL );   break;
      case 's':  handle_search( ctl[ 8 ], NULL ); break;
      case '+':  SET_INT( ctl[ 12 ], 1 );         break;
      case '-':  SET_INT( ctl[ 12 ], 2 );         break;
      case '*':  SET_INT( ctl[ 12 ], 0 );         break;
      case 't':  SET_INT( ctl[ 14 ], 0 );         break;
      case 'h':  SET_INT( ctl[ 14 ], 1 );         break;
      case 'c':  SET_INT( ctl[ 14 ], 2 );         break;

      case 'b':
         SET_INT( ctl[ 3 ], 0 );
         handle_datatype( ctl[ 3 ], NULL );
         break;
      case 'w':
         SET_INT( ctl[ 3 ], 1 );
         handle_datatype( ctl[ 3 ], NULL );
         break;
      case 'l':
         SET_INT( ctl[ 3 ], 2 );
         handle_datatype( ctl[ 3 ], NULL );
         break;
      case 'f':
         SET_INT( ctl[ 3 ], 3 );
         handle_datatype( ctl[ 3 ], NULL );
         break;
      case 'd':
         SET_INT( ctl[ 3 ], 4 );
         handle_datatype( ctl[ 3 ], NULL );
         break;
      case 'u': {
         int i = !unsign;
         SET_INT( ctl[ 4 ], i );
         handle_unsigned( ctl[ 4 ], NULL );
         }
         break;
      case 'i':
         SET_INT( ctl[ 5 ], 0 );
         handle_byteorder( ctl[ 5 ], NULL );
         break;
      case 'm':
         SET_INT( ctl[ 5 ], 1 );
         handle_byteorder( ctl[ 5 ], NULL );
         break;
      case ',':
         if ( linesize > 1 ) {
            SET_INT( ctl[ 6 ], linesize - 1 );
            handle_rowsize( ctl[ 6 ], NULL );
         }
         break;
      case '.':
         if ( linesize < 16 ) {
            SET_INT( ctl[ 6 ], linesize + 1 );
            handle_rowsize( ctl[ 6 ], NULL );
         }
         break;
      default:
         break;
   }
}
void nxtCanvasWidget::action( action_event event ){
	static QPoint prev_last_mouse;
	
	if( active_tool == TOOL_NONE )
		return;
	
	//First handle the events that doesn't change the canvas
	if( active_tool == TOOL_SELECTION ){
		selection = get_qrect_from_points( mouse_start, mouse_current );
		if( selection.height() >= 0 )
			selection.setHeight( selection.height()+1 );
		if( selection.width() >= 0 )
			selection.setWidth( selection.width()+1 );
		update();
		//TODO: emit signal?
	}
	else if( active_tool == TOOL_MOVE ){
		if( is_moveable && event != EVENT_MOVE )	//Prevent infinitive loop
			change_pos( mouse_current.x() - mouse_last.x(), mouse_current.y() - mouse_last.y() );
	}
	else
		if( canvas ){
			//Create a fresh buffer, unless we are drawing in freehand
			if( active_tool != TOOL_PIXEL )
				new_buffer();
			
			//If this is the last action, enable auto-resize
			//if( event == EVENT_MOUSE_UP )
				canvas->set_auto_resize( true );
				//TODO: enable, then restore to previous state
			
			switch( active_tool ){
				case TOOL_PIXEL:
						//Draw a dot first time, then follow with lines
						if( event == EVENT_MOUSE_DOWN )
							canvas->PointOut( mouse_current.x(), mouse_current.y(), options );
						else
							canvas->connected_line_out( prev_last_mouse.x(), prev_last_mouse.y(), mouse_last.x(), mouse_last.y(), mouse_current.x(), mouse_current.y(), options );
						
						prev_last_mouse = mouse_last;
					break;
					
				case TOOL_LINE:
						if( key_control ){	//Limit to angles in steps of 15 degrees
							int dx = mouse_current.x() - mouse_start.x();
							int dy = mouse_current.y() - mouse_start.y();
							
							double angle = atan2( (double)( dy ), (double)( dx ) );
							double lenght = sqrt( (double)( dx*dx + dy*dy ) );
							double limiter = PI * 15 / 180;
							double new_angle = round_sym( angle / limiter ) * limiter;
							dy = round_sym( sin( new_angle ) * lenght );
							dx = round_sym( cos( new_angle ) * lenght );
							
							canvas->LineOut( mouse_start.x(), mouse_start.y(), mouse_start.x() + dx, mouse_start.y() + dy, options );
						}
						else
							canvas->LineOut( mouse_start.x(), mouse_start.y(), mouse_current.x(), mouse_current.y(), options );
					break;
				
				case TOOL_RECT:{
						QRect rect = get_qrect_from_points( mouse_start, mouse_current );
						
						//Make it a square if control is pressed
						if( key_control ){
							if( rect.width() > rect.height() ){
								if( mouse_current.y() < mouse_start.y() )
									rect.translate( 0, rect.height() - rect.width() );
								rect.setHeight( rect.width() );
							}
							else{
								if( mouse_current.x() < mouse_start.x() )
									rect.translate( rect.width() - rect.height(), 0 );
								rect.setWidth( rect.height() );
							}
						}
						
						canvas->RectOut( rect.x(), rect.y(), rect.width(), rect.height(), options );
					} break;
					
				case TOOL_ELLIPSE:
						if( key_control ){
							QPoint lenght = mouse_current - mouse_start;
							int radius = sqrt( (double)( lenght.x()*lenght.x() + lenght.y()*lenght.y() ) );
							canvas->CircleOut( mouse_start.x(), mouse_start.y(), radius, options );
						}
						else
							canvas->EllipseOut( mouse_start.x(), mouse_start.y(), abs( mouse_current.x() - mouse_start.x() ), abs( mouse_current.y() - mouse_start.y() ), options );
						break;
				
				case TOOL_BITMAP:{
						if( clipboard ){
							if( event == EVENT_MOUSE_DOWN ){
								selection.setWidth( clipboard->get_width() );
								selection.setHeight( clipboard->get_height() );
							}
							selection.moveTo( selection.topLeft() + mouse_current - mouse_last );
							canvas->copy_canvas( clipboard, 0, 0, selection.width(), selection.height(), selection.x(), selection.y(), options );
						}
					} break;
				
				case TOOL_FILL:	canvas->bucket_fill( mouse_current.x(), mouse_current.y(), options ); break;
				
				default: qDebug( "nxtCanvasWidget::action() unhandled tool: %d", active_tool );
			}
			
			//If this is the last action, make the buffer permanent
			if( event == EVENT_MOUSE_UP && active_tool != TOOL_BITMAP ){
			//	canvas->set_auto_resize( false );
				write_buffer();
			}
			
			update();
			emit value_changed();
		}
	
	
}