Exemplo n.º 1
0
int moth_gui::read_book(moth_book *book)
{
	SDL_Event event;
	this->book = book;
	create_textures();
	index.name = "START";
	book->build_index(index);
	while(running) {
		while(SDL_PollEvent(&event)) {
			switch( event.type ) {
			case SDL_KEYDOWN:
				handle_key_down(&event.key.keysym);
				break;
			case SDL_KEYUP:
				handle_key_up(&event.key.keysym);
				break;
			case SDL_MOUSEMOTION:
				handle_mouse_motion(&event.motion);
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				handle_mouse_button(&event.button);
				break;
			case SDL_VIDEORESIZE:
				handle_resize(&event.resize);
				break;
			case SDL_QUIT:
				running = 0;
				break;
			}
		}
		show_pages();
	}
	return SUCCESS;
}
Exemplo n.º 2
0
void handle_event(){
  SDL_Event event;
  while(SDL_PollEvent(&event)){
    switch(event.type){
    case SDL_ACTIVEEVENT:
      //lost focus
      if(event.active.gain == 0)
	Active = true;
      else
	Active = true;
      break;
    case SDL_VIDEORESIZE:
      surface = SDL_SetVideoMode(event.resize.w,
				 event.resize.h,
				 SCREEN_BPP, videoFlags);
    case SDL_KEYDOWN: handle_keypress(&event.key.keysym); break;
    case SDL_MOUSEMOTION: handle_mouse_motion(event.motion); break;
    case SDL_MOUSEBUTTONDOWN: handle_mouse_button(event.button); break;
    case SDL_QUIT: Running = false; break;
    default: break;
    }
  }
}
Exemplo n.º 3
0
void event_loop( Display* display, Window window )
{
while (1)
	{
	while (XPending(display) > 0)
		{
	        	XEvent event;
			XNextEvent( display, &event );

			switch (event.type)
			{
				case Expose:
					break;
				case ConfigureNotify:
					change_size(event.xconfigure.width, event.xconfigure.height);
					break;
				case KeyPress:
				{
					int code;

					code = XLookupKeysym( &event.xkey, 0);

					if ((code == XK_Escape)||(code == XK_q))
						return;
					if (code == XK_Up)
					{
						eLit += lStep;
						if ( eLit > PI)
							eLit = PI;
					}
					if (code == XK_Down)
					{
						eLit -= lStep;
						if (eLit < 0.f)
							eLit = 0.f;
					}
					if (code == XK_Left)
						aLit -= lStep;
					if (code == XK_Right)
						aLit += lStep;
					if(code == XK_w)
						dCam = tStep;
					if(code == XK_s)
						dCam = -tStep;
					if(code == XK_d)
						lCam = tStep;
					if(code == XK_a)
						lCam = -tStep;
					if(code == XK_g)
						GLSLshader = !GLSLshader;
					if (code == XK_f)
						print_fps = !print_fps;
					if (code == XK_o)
					{
				        	scalePoly++;
        					glPolygonOffset(scalePoly, biasPoly);
					}
					if (code == XK_i)
					{
						scalePoly--;
						glPolygonOffset(scalePoly, biasPoly);
					}
					if (code == XK_l)
					{
				        	biasPoly++;
        					glPolygonOffset(scalePoly, biasPoly);
					}
					if (code == XK_k)
					{
						biasPoly--;
						glPolygonOffset(scalePoly, biasPoly);
					}
					if (code == XK_p) // toggle character 0 running/standing
					{
						md2_model[0]->anim_command = ANIMATION_CHANGE;
						md2_model[1]->anim_command = ANIMATION_CHANGE;
						if (md2_model[0]->current_animation == ANIMATION_RUN)
						{
							md2_model[0]->anim_state = ANIMATION_STANDING_IDLE;
							md2_model[1]->anim_state = ANIMATION_STANDING_IDLE;
						}
						else
						{
							md2_model[0]->anim_state = ANIMATION_RUN;
							md2_model[1]->anim_state = ANIMATION_RUN;
						}
					}
					if (code == XK_0) // increase character 1 animation
					{
						md2_model[2]->anim_command = ANIMATION_CHANGE;
						if ( md2_model[2]->anim_state++ == ANIMATION_CROUCH_DEATH )
							md2_model[2]->anim_state = ANIMATION_STANDING_IDLE;
					}
					if (code == XK_9) // decrease character 1 animation
					{
						md2_model[2]->anim_command = ANIMATION_CHANGE;
						if ( md2_model[2]->anim_state-- == ANIMATION_STANDING_IDLE )
							md2_model[2]->anim_state = ANIMATION_CROUCH_DEATH;
					}
					if (code == XK_h) // kill character 1
					{
						md2_model[2]->anim_command = ANIMATION_CHANGE;
						md2_model[2]->anim_state = ANIMATION_DEATH_SLOW;
					}
					if (code == XK_r)
					{
						wireframe = !wireframe;
						if (wireframe)
							glPolygonMode(GL_FRONT, GL_LINE);
						else
						glPolygonMode(GL_FRONT, GL_FILL);
					}
				}
				case ButtonPress:
				{
					handle_mouse_button(event.xbutton.button, 0, event.xbutton.x, event.xbutton.y);
					break;
				}
				case ButtonRelease:
				{
					handle_mouse_button(event.xbutton.button, 1, event.xbutton.x, event.xbutton.y);
					break;
				}
				case MotionNotify:
				{
					if (event.xmotion.state & Button1Mask)
					{
						handle_mouse_motion(1, event.xmotion.x, event.xmotion.y);
						break;
					}
					if (event.xmotion.state & Button3Mask)
						handle_mouse_motion(3, event.xmotion.x, event.xmotion.y);
					break;
				}
			}
		}

	render();
	glXSwapBuffers( display, window );

	switch (signal_pending)
	{
		case SIGINT:
		case SIGHUP:
		case SIGTERM:
			return;	/* return from event_loop */
		default:
			break;
	}

	signal_pending = 0;

	if( (use_timer) && ( (etime - t2) > max_timer ) )
		return;

	}
}