コード例 #1
0
ファイル: menu.c プロジェクト: naev/naev
/**
 * @brief Opens the menu options from a button.
 */
static void menu_options_button( unsigned int wid, char *str )
{
   (void) wid;
   (void) str;
   opt_menu();
}
コード例 #2
0
ファイル: persp_sdl_gl.c プロジェクト: rikirenz/Graphic
int main()
{
SDL_Window *win;
SDL_Rect v;
TTF_Font *font;
SDL_Event myevent;
SDL_GLContext mainContext;
int choice, done=0;

if (SDL_Init (SDL_INIT_VIDEO) < 0)
{
	fprintf (stderr, "Couldn't init video: %s\n", SDL_GetError ());
	return (1);
}

/* Initialize the TTF library */
if (TTF_Init () < 0)
{
	fprintf (stderr, "Couldn't initialize TTF: %s\n", SDL_GetError ());
	SDL_Quit ();
	return (2);
}

font = TTF_OpenFont ("FreeSans.ttf", DEFAULT_PTSIZE);
if (font == NULL)
{
	fprintf (stderr, "Couldn't load font\n");
}

v.x = 0;
v.y = 0;
v.w = 720;
v.h = 600;
xvmin = v.x+5;
yvmin = v.y+5;
xvmax = v.w-130;
yvmax = v.h-10;

  win= SDL_CreateWindow("View Bivariate Function", 0, 0, v.w, v.h, SDL_WINDOW_OPENGL);
  if(win==NULL){
        fprintf(stderr,"SDL_CreateWindow Error: %s\n",SDL_GetError());
        SDL_Quit();
        return 1;
  }

SetOpenGLAttributes();
//Create our opengl context and attach it to our window
mainContext=SDL_GL_CreateContext(win);

init_menu(menu);
define_fun_grid();   /* griglia di approssimazione funzione bivariata*/
define_view(); /* calcolo dei parametri di vista */
display(win,menu,font,v);

while (done == 0)
{
 if (SDL_PollEvent(&myevent))
 {
 SDL_EventState(0xff, SDL_IGNORE); //0xff is all events
 switch(myevent.type)
 {
  case SDL_MOUSEMOTION:
    if(myevent.motion.state==1)
    {
       opt_menu(menu,11,myevent.motion.x,myevent.motion.y,&choice);
       switch(choice)
       {
        case 1: //choice==tetawin
  		tmpx = myevent.motion.x-(menu[1].rect.x+menu[1].rect.w/2);
  		tmpy = myevent.motion.y-(menu[1].rect.y+menu[1].rect.h/2);
  		teta = atan2(tmpy,tmpx);
                display(win,menu,font,v);
	 break;
	 case 2: //choice==fiwin 	  
  		tmpx = myevent.motion.x-(menu[2].rect.x+menu[2].rect.w/2);
  		tmpy = myevent.motion.y-(menu[2].rect.y+menu[2].rect.h/2);
  		fi = atan2(tmpy,tmpx);
                display(win,menu,font,v);
         break;
        }
   }
   break;
  
  case SDL_MOUSEBUTTONDOWN:
        if(myevent.button.button==1)
        {
           opt_menu(menu,11,myevent.button.x,myevent.button.y,&choice);
           switch(choice)
           {
            case 0: //choice == finewin 
	        done = 1;
	    break;
	    case 7: //choice == rightwin
                ssx=-sin(teta);
		ssy=cos(teta);
		csx-=sr*ssx;
		csy-=sr*ssy;
                display(win,menu,font,v);
	    break;
	    case 8: //choice == leftwin
		ssx=-sin(teta);
		ssy=cos(teta);
		csx+=sr*ssx;
		csy+=sr*ssy;
                display(win,menu,font,v);
	    break;
	    case 9: //choice == upwin
		ssx=-cos(fi)*cos(teta);
		ssy=-cos(fi)*sin(teta);
		ssz=sin(fi);
		csx+=sr*ssx;
		csy+=sr*ssy;
		csz+=sr*ssz;
                display(win,menu,font,v);
	     break;	
	     case 10: //choice == downwin
		ssx=-cos(fi)*cos(teta);
		ssy=-cos(fi)*sin(teta);
		ssz=sin(fi);
		csx-=sr*ssx;
		csy-=sr*ssy;
		csz-=sr*ssz;
                display(win,menu,font,v);
	     break;
	     case 3: //choice == ziwin
		if (alpha-salpha >0)
  		   alpha-=salpha;
                display(win,menu,font,v);
             break;
	     case 4: //choice == zowin
	        if (alpha+salpha <1.57)
  		   alpha+=salpha;
                display(win,menu,font,v);
             break;
	     case 5: //choice == Dziwin
	        if (D-Dstep>0)
	     	  D-=Dstep;
                display(win,menu,font,v);
             break;
	     case 6: //choice == Dzowin
	     	D+=Dstep;
                display(win,menu,font,v);
             break;
            }
       }
     break;     
  case SDL_KEYDOWN:
    if(myevent.key.keysym.sym == SDLK_ESCAPE)
   	done = 1;
  break; 
  SDL_EventState(0xff, SDL_ENABLE);
  }/* fine switch */ 	
  SDL_EventState(0xff, SDL_ENABLE);
 }
} /* fine while */

TTF_CloseFont (font);
TTF_Quit ();
SDL_GL_DeleteContext(mainContext);
SDL_DestroyWindow(win);
SDL_Quit ();
return (0);

} /* fine main */