Beispiel #1
0
void
mouse_update( void )
#endif
{
  static int btn_state = 0;
  unsigned char mousebuf[60]; /* max. events: 20 (PS/2) or 15 (other) */
  ssize_t xoff = 0, yoff = 0;
  int btn_changed = 0, btn_new = btn_state, btn_mod = btn_state;

  if( mouse_fd == -1 ) return;

  while( 1 ) {
    ssize_t available;
    const unsigned char *i;

    available = read( mouse_fd, &mousebuf, sizeof( mousebuf ) );
    if( available <= 0 ) break;

    if( !ui_mouse_grabbed ) continue;

    for( i = mousebuf; i < mousebuf + available; i += packet_size ) {
      btn_changed |= btn_mod ^= btn_new = i[0] & 7;
      btn_changed |= btn_mod ^= btn_new = i[0] & 7;
      xoff += i[1]; if( i[0] & 16 ) xoff -= 256;
      yoff += i[2]; if( i[0] & 32 ) yoff -= 256;
    }
  }

  btn_state = btn_new;
  if( btn_changed & 1 ) ui_mouse_button( 1, btn_new & 1 );
  if( btn_changed & 2 ) ui_mouse_button( 3, btn_new & 2 );

  if( xoff || yoff ) ui_mouse_motion( xoff, -yoff );
}
Beispiel #2
0
static void
mouse_update_gpm( void )
{
  Gpm_Event event;
  int db;
  static int oldbuttons = 0;

  if( gpmfd < 0 ) {
    static int t = 0;
    if (!t) fprintf (stderr, "gpm not there?\n");
    t = 1;
    return;
  }

  for (;;) {
    struct pollfd ufd = { gpmfd, POLLIN | POLLPRI };
    if( poll( &ufd, 1, 0 ) < 1 ) break;

    gpm_getevent( &event );

    if( !ui_mouse_grabbed ) continue;

    if( event.dx | event.dy ) ui_mouse_motion( event.dx, event.dy );

    db = event.buttons ^ oldbuttons;
    if( db ) {
      oldbuttons = event.buttons;
      if( db & GPM_B_LEFT  ) ui_mouse_button( 1, event.buttons & GPM_B_LEFT  );
      if( db & GPM_B_RIGHT ) ui_mouse_button( 3, event.buttons & GPM_B_RIGHT );
    }
  }
}
Beispiel #3
0
int ui_event(void)
{
  XEvent event;

  XFlush( display );
  while( XEventsQueued( display, QueuedAlready ) ) {
    XNextEvent( display, &event );

    switch(event.type) {
    case ConfigureNotify:
      xdisplay_configure_notify(event.xconfigure.width,
				event.xconfigure.height);
      break;
    case Expose:
      xdisplay_area( event.xexpose.x, event.xexpose.y,
		     event.xexpose.width, event.xexpose.height );
      break;
    case ButtonPress:
      ui_mouse_button( event.xbutton.button, 1 );
      break;
    case ButtonRelease:
      ui_mouse_button( event.xbutton.button, 0 );
      break;
    case MotionNotify:
      if( ui_mouse_grabbed ) {
        ui_mouse_motion( event.xmotion.x - 128, event.xmotion.y - 128 );
        if( event.xmotion.x != 128 || event.xmotion.y != 128 )
          XWarpPointer( display, None, xui_mainWindow, 0, 0, 0, 0, 128, 128 );
      }
      break;
    case FocusOut:
      keyboard_release_all();
      ui_mouse_suspend();
      break;
    case FocusIn:
      ui_mouse_resume();
      break;
    case KeyPress:
      xkeyboard_keypress(&(event.xkey));
      break;
    case KeyRelease:
      xkeyboard_keyrelease(&(event.xkey));
      break;
    case ClientMessage:
      if( event.xclient.format == 32 &&
          event.xclient.data.l[0] == delete_window_atom ) {
        fuse_emulation_pause();
        menu_file_exit(0);
        fuse_emulation_unpause();
      }
      break;
    }
  }
  return 0;
}
Beispiel #4
0
float MENUS::ui_do_scrollbar_h(const void *id, const RECT *rect, float current)
{
	RECT handle;
	static float offset_x;
	ui_vsplit_l(rect, 33, &handle, 0);

	handle.x += (rect->w-handle.w)*current;

	/* logic */
    float ret = current;
    int inside = ui_mouse_inside(&handle);

	if(ui_active_item() == id)
	{
		if(!ui_mouse_button(0))
			ui_set_active_item(0);
		
		float min = rect->x;
		float max = rect->w-handle.w;
		float cur = ui_mouse_x()-offset_x;
		ret = (cur-min)/max;
		if(ret < 0.0f) ret = 0.0f;
		if(ret > 1.0f) ret = 1.0f;
	}
	else if(ui_hot_item() == id)
	{
		if(ui_mouse_button(0))
		{
			ui_set_active_item(id);
			offset_x = ui_mouse_x()-handle.x;
		}
	}
	
	if(inside)
		ui_set_hot_item(id);

	// render
	RECT rail;
	ui_hmargin(rect, 5.0f, &rail);
	ui_draw_rect(&rail, vec4(1,1,1,0.25f), 0, 0.0f);

	RECT slider = handle;
	slider.h = rail.y-slider.y;
	ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_T, 2.5f);
	slider.y = rail.y+rail.h;
	ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_B, 2.5f);

	slider = handle;
	ui_margin(&slider, 5.0f, &slider);
	ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f);
	
    return ret;
}
Beispiel #5
0
int ui_event(void)
{
  XEvent event;

  while(XCheckMaskEvent(display,~NoEventMask,&event)) {
    switch(event.type) {
    case ConfigureNotify:
      xdisplay_configure_notify(event.xconfigure.width,
				event.xconfigure.height);
      break;
    case Expose:
      xdisplay_area( event.xexpose.x, event.xexpose.y,
		     event.xexpose.width, event.xexpose.height );
      break;
    case ButtonPress:
      ui_mouse_button( event.xbutton.button, 1 );
      break;
    case ButtonRelease:
      ui_mouse_button( event.xbutton.button, 0 );
      break;
    case MotionNotify:
      if( ui_mouse_grabbed ) {
        ui_mouse_motion( event.xmotion.x - 128, event.xmotion.y - 128 );
        if( event.xmotion.x != 128 || event.xmotion.y != 128 )
          XWarpPointer( display, None, xui_mainWindow, 0, 0, 0, 0, 128, 128 );
      }
      break;
    case FocusOut:
      keyboard_release_all();
      ui_mouse_suspend();
      break;
    case FocusIn:
      ui_mouse_resume();
      break;
    case KeyPress:
      xkeyboard_keypress(&(event.xkey));
      break;
    case KeyRelease:
      xkeyboard_keyrelease(&(event.xkey));
      break;
    case ClientMessage:
      if( event.xclient.data.l[0] == delete_window_atom ) fuse_exiting = 1;
      break;
    }
  }
  return 0;
}
Beispiel #6
0
int MENUS::ui_do_key_reader(void *id, const RECT *rect, int key)
{
	// process
	static void *grabbed_id = 0;
	static bool mouse_released = true;
	int inside = ui_mouse_inside(rect);
	int new_key = key;
	
	if(!ui_mouse_button(0) && grabbed_id == id)
		mouse_released = true;

	if(ui_active_item() == id)
	{
		if(binder.got_key)
		{
			new_key = binder.key.key;
			binder.got_key = false;
			ui_set_active_item(0);
			mouse_released = false;
			grabbed_id = id;
		}
	}
	else if(ui_hot_item() == id)
	{
		if(ui_mouse_button(0) && mouse_released)
		{
			binder.take_key = true;
			binder.got_key = false;
			ui_set_active_item(id);
		}
	}
	
	if(inside)
		ui_set_hot_item(id);

	// draw
	if (ui_active_item() == id)
		ui_draw_keyselect_button(id, "???", 0, rect, 0);
	else
	{
		if(key == 0)
			ui_draw_keyselect_button(id, "", 0, rect, 0);
		else
			ui_draw_keyselect_button(id, inp_key_name(key), 0, rect, 0);
	}
	return new_key;
}
Beispiel #7
0
static LRESULT
handle_WM_MBUTTONUP(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  g_mousex = LOWORD(lParam);
  g_mousey = HIWORD(lParam);
  ui_mouse_button(3, g_mousex + g_xscroll, g_mousey + g_yscroll, 0);
  return 0;
}
Beispiel #8
0
static LRESULT
handle_WM_MOUSEWHEEL(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  int delta;

  delta = ((signed short)HIWORD(wParam)); /* GET_WHEEL_DELTA_WPARAM(wParam); */
  if (delta > 0)
  {
    ui_mouse_button(4, 0, 0, 1);
    ui_mouse_button(4, 0, 0, 0);
  }
  else
  {
    ui_mouse_button(5, 0, 0, 1);
    ui_mouse_button(5, 0, 0, 0);
  }
  return 0;
}
Beispiel #9
0
void ui_do_popup_menu()
{
	for(int i = 0; i < ui_num_popups; i++)
	{
		bool inside = ui_mouse_inside(&ui_popups[i].rect);
		ui_set_hot_item(&ui_popups[i].id);
		
		if(ui_active_item() == &ui_popups[i].id)
		{
			if(!ui_mouse_button(0))
			{
				if(!inside)
					ui_num_popups--;
				ui_set_active_item(0);
			}
		}
		else if(ui_hot_item() == &ui_popups[i].id)
		{
			if(ui_mouse_button(0))
				ui_set_active_item(&ui_popups[i].id);
		}
		
		int corners = CORNER_ALL;
		if(ui_popups[i].is_menu)
			corners = CORNER_R|CORNER_B;
		
		RECT r = ui_popups[i].rect;
		ui_draw_rect(&r, vec4(0.5f,0.5f,0.5f,0.75f), corners, 3.0f);
		ui_margin(&r, 1.0f, &r);
		ui_draw_rect(&r, vec4(0,0,0,0.75f), corners, 3.0f);
		ui_margin(&r, 4.0f, &r);
		
		if(ui_popups[i].func(r))
			ui_num_popups--;
			
		if(inp_key_down(KEY_ESCAPE))
			ui_num_popups--;
	}
}
Beispiel #10
0
int MENUS::ui_do_edit_box(void *id, const RECT *rect, char *str, unsigned str_size, float font_size, bool hidden)
{
    int inside = ui_mouse_inside(rect);
	int r = 0;
	static int at_index = 0;

	if(ui_last_active_item() == id)
	{
		int len = strlen(str);
			
		if (inside && ui_mouse_button(0))
		{
			int mx_rel = (int)(ui_mouse_x() - rect->x);

			for (int i = 1; i <= len; i++)
			{
				if (gfx_text_width(0, font_size, str, i) + 10 > mx_rel)
				{
					at_index = i - 1;
					break;
				}

				if (i == len)
					at_index = len;
			}
		}

		for(int i = 0; i < num_inputevents; i++)
		{
			len = strlen(str);
			LINEINPUT::manipulate(inputevents[i], str, str_size, &len, &at_index);
		}
	}

	bool just_got_active = false;
	
	if(ui_active_item() == id)
	{
		if(!ui_mouse_button(0))
			ui_set_active_item(0);
	}
	else if(ui_hot_item() == id)
	{
		if(ui_mouse_button(0))
		{
			if (ui_last_active_item() != id)
				just_got_active = true;
			ui_set_active_item(id);
		}
	}
	
	if(inside)
		ui_set_hot_item(id);

	RECT textbox = *rect;
	ui_draw_rect(&textbox, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f);
	ui_vmargin(&textbox, 5.0f, &textbox);
	
	const char *display_str = str;
	char stars[128];
	
	if(hidden)
	{
		unsigned s = strlen(str);
		if(s >= sizeof(stars))
			s = sizeof(stars)-1;
		memset(stars, '*', s);
		stars[s] = 0;
		display_str = stars;
	}

	ui_do_label(&textbox, display_str, font_size, -1);
	
	if (ui_last_active_item() == id && !just_got_active)
	{
		float w = gfx_text_width(0, font_size, display_str, at_index);
		textbox.x += w*ui_scale();
		ui_do_label(&textbox, "_", font_size, -1);
	}

	return r;
}
Beispiel #11
0
int 
ui_event( void )
{
  SDL_Event event;

  while ( SDL_PollEvent( &event ) ) {
    switch ( event.type ) {
    case SDL_KEYDOWN:
      sdlkeyboard_keypress( &(event.key) );
      break;
    case SDL_KEYUP:
      sdlkeyboard_keyrelease( &(event.key) );
      break;

    case SDL_MOUSEBUTTONDOWN:
      ui_mouse_button( event.button.button, 1 );
      break;
    case SDL_MOUSEBUTTONUP:
      ui_mouse_button( event.button.button, 0 );
      break;
    case SDL_MOUSEMOTION:
      if( ui_mouse_grabbed ) {
        ui_mouse_motion( event.motion.x - 128, event.motion.y - 128 );
        if( event.motion.x != 128 || event.motion.y != 128 )
          SDL_WarpMouse( 128, 128 );
      }	
      break;

#if defined USE_JOYSTICK && !defined HAVE_JSW_H

    case SDL_JOYBUTTONDOWN:
      sdljoystick_buttonpress( &(event.jbutton) );
      break;
    case SDL_JOYBUTTONUP:
      sdljoystick_buttonrelease( &(event.jbutton) );
      break;
    case SDL_JOYAXISMOTION:
      sdljoystick_axismove( &(event.jaxis) );
      break;

#endif			/* if defined USE_JOYSTICK && !defined HAVE_JSW_H */

    case SDL_QUIT:
      fuse_emulation_pause();
      menu_file_exit(0);
      fuse_emulation_unpause();
      break;
    case SDL_VIDEOEXPOSE:
      display_refresh_all();
      break;
    case SDL_ACTIVEEVENT:
      if( event.active.state & SDL_APPINPUTFOCUS ) {
	if( event.active.gain ) ui_mouse_resume(); else ui_mouse_suspend();
      }
      break;
    default:
      break;
    }
  }

  return 0;
}
Beispiel #12
0
void MENUS::render_demoplayer(RECT main_view)
{
	const DEMOPLAYBACK_INFO *info = client_demoplayer_getinfo();
	
	const float seekbar_height = 15.0f;
	const float buttonbar_height = 20.0f;
	const float margins = 5.0f;
	float total_height;
	
	if(menu_active)
	{
		total_height = seekbar_height+buttonbar_height+margins*3;
	/*
	else
		total_height = seekbar_height+margins*2;
	*/
	
		ui_hsplit_b(&main_view, total_height, 0, &main_view);
		ui_vsplit_l(&main_view, 250.0f, 0, &main_view);
		ui_vsplit_r(&main_view, 250.0f, &main_view, 0);
	
		ui_draw_rect(&main_view, color_tabbar_active, CORNER_T, 10.0f);
		
		ui_margin(&main_view, 5.0f, &main_view);
	}
	
	RECT seekbar, buttonbar;
	
	if(menu_active)
	{
		ui_hsplit_t(&main_view, seekbar_height, &seekbar, &buttonbar);
		ui_hsplit_t(&buttonbar, margins, 0, &buttonbar);
	}
	/*
	else
		seekbar = main_view;
	*/
	
	// do seekbar
	if(menu_active)
	{
		static int seekbar_id = 0;
		void *id = &seekbar_id;
		char buffer[128];
		
		ui_draw_rect(&seekbar, vec4(0,0,0,0.5f), CORNER_ALL, 5.0f);
		
		int current_tick = info->current_tick - info->first_tick;
		int total_ticks = info->last_tick - info->first_tick;
		
		float amount = current_tick/(float)total_ticks;
		
		RECT filledbar = seekbar;
		filledbar.w = 10.0f + (filledbar.w-10.0f)*amount;
		
		ui_draw_rect(&filledbar, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f);
		
		str_format(buffer, sizeof(buffer), "%d:%02d / %d:%02d",
			current_tick/SERVER_TICK_SPEED/60, (current_tick/SERVER_TICK_SPEED)%60,
			total_ticks/SERVER_TICK_SPEED/60, (total_ticks/SERVER_TICK_SPEED)%60);
		ui_do_label(&seekbar, buffer, seekbar.h*0.70f, 0);

		// do the logic
	    int inside = ui_mouse_inside(&seekbar);
			
		if(ui_active_item() == id)
		{
			if(!ui_mouse_button(0))
				ui_set_active_item(0);
			else
			{
				float amount = (ui_mouse_x()-seekbar.x)/(float)seekbar.w;
				if(amount > 0 && amount < 1.0f)
				{
					gameclient.on_reset();
					gameclient.suppress_events = true;
					client_demoplayer_setpos(amount);
					gameclient.suppress_events = false;
				}
			}
		}
		else if(ui_hot_item() == id)
		{
			if(ui_mouse_button(0))
				ui_set_active_item(id);
		}		
		
		if(inside)
			ui_set_hot_item(id);
	}	
	

	if(menu_active)
	{
		// do buttons
		RECT button;

		// pause button
		ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar);
		static int pause_button = 0;
		if(ui_do_button(&pause_button, "| |", info->paused, &button, ui_draw_demoplayer_button, 0))
			client_demoplayer_setpause(!info->paused);
		
		// play button
		ui_vsplit_l(&buttonbar, margins, 0, &buttonbar);
		ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar);
		static int play_button = 0;
		if(ui_do_button(&play_button, ">", !info->paused, &button, ui_draw_demoplayer_button, 0))
		{
			client_demoplayer_setpause(0);
			client_demoplayer_setspeed(1.0f);
		}

		// slowdown
		ui_vsplit_l(&buttonbar, margins, 0, &buttonbar);
		ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar);
		static int slowdown_button = 0;
		if(ui_do_button(&slowdown_button, "<<", 0, &button, ui_draw_demoplayer_button, 0))
		{
			if(info->speed > 4.0f) client_demoplayer_setspeed(4.0f);
			else if(info->speed > 2.0f) client_demoplayer_setspeed(2.0f);
			else if(info->speed > 1.0f) client_demoplayer_setspeed(1.0f);
			else if(info->speed > 0.5f) client_demoplayer_setspeed(0.5f);
			else client_demoplayer_setspeed(0.05f);
		}
		
		// fastforward
		ui_vsplit_l(&buttonbar, margins, 0, &buttonbar);
		ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar);
		static int fastforward_button = 0;
		if(ui_do_button(&fastforward_button, ">>", 0, &button, ui_draw_demoplayer_button, 0))
		{
			if(info->speed < 0.5f) client_demoplayer_setspeed(0.5f);
			else if(info->speed < 1.0f) client_demoplayer_setspeed(1.0f);
			else if(info->speed < 2.0f) client_demoplayer_setspeed(2.0f);
			else if(info->speed < 4.0f) client_demoplayer_setspeed(4.0f);
			else client_demoplayer_setspeed(8.0f);
		}

		// speed meter
		ui_vsplit_l(&buttonbar, margins*3, 0, &buttonbar);
		char buffer[64];
		if(info->speed >= 1.0f)
			str_format(buffer, sizeof(buffer), "x%.0f", info->speed);
		else
			str_format(buffer, sizeof(buffer), "x%.1f", info->speed);
		ui_do_label(&buttonbar, buffer, button.h*0.7f, -1);

		// exit button
		ui_vsplit_r(&buttonbar, buttonbar_height*3, &buttonbar, &button);
		static int exit_button = 0;
		if(ui_do_button(&exit_button, "Exit", 0, &button, ui_draw_demoplayer_button, 0))
			client_disconnect();
	}
}