Example #1
0
File: main.c Project: dstenb/tfm
void main_loop()
{
	MEVENT event;
	int i;

	wdata_lock_mutex(&data);
	wdata_set_view(&data, config()->view);
	wdata_unlock_mutex(&data);

	for (;;) {
		wdata_lock_mutex(&data);
		draw(&data);
		wdata_unlock_mutex(&data);

		i = ui_getchar();

		if (i == KEY_RESIZE) {
			handle_resize();
		} else if (i == KEY_MOUSE) {
			if (getmouse(&event) == OK) {
				wdata_lock_mutex(&data);
				states_handlemouse(&data, &event);
				wdata_unlock_mutex(&data);

			}
		} else {
			wdata_lock_mutex(&data);
			states_handlekey(&data, i);
			wdata_unlock_mutex(&data);
		}
	}
}
Example #2
0
File: tasknc.c Project: skn/tasknc
void force_redraw() /* {{{ */
{
	/* force a redraw of active windows */
	WINDOW *windows[] = {statusbar, tasklist, pager, header};
	const int nwins = sizeof(windows)/sizeof(WINDOW *);
	int i;

	/* force a resize check */
	handle_resize();

	/* wipe windows */
	for (i=0; i<nwins; i++)
	{
		wattrset(windows[i], COLOR_PAIR(0));
		if (windows[i]==NULL)
			continue;
		wipe_window(windows[i]);
		wnoutrefresh(windows[i]);
	}
	doupdate();

	/* print messages */
	print_header();
	tasklist_print_task_list();
	statusbar_message(cfg.statusbar_timeout, "redrawn");
} /* }}} */
Example #3
0
File: sdl.c Project: GGGO/baresip
static void event_handler(void *arg)
{
	SDL_Event event;
	char ch;

	(void)arg;

	tmr_start(&sdl.tmr, 100, event_handler, NULL);

	while (SDL_PollEvent(&event)) {

		switch (event.type) {

		case SDL_KEYDOWN:

			switch (event.key.keysym.sym) {

			case SDLK_ESCAPE:
				if (!sdl.fullscreen)
					break;

				sdl.fullscreen = false;
				sdl_reset();
				break;

			case SDLK_f:
				if (sdl.fullscreen)
					break;

				sdl.fullscreen = true;
				sdl_reset();
				break;

			default:
				ch = event.key.keysym.unicode & 0x7f;

				/* Relay key-press to UI subsystem */
				if (isprint(ch)) {
					tmr_start(&sdl.tmr, KEY_RELEASE_VAL,
						  timeout, NULL);
					ui_input(ch);
				}
				break;
			}

			break;

		case SDL_VIDEORESIZE:
			handle_resize(event.resize.w, event.resize.h);
			break;

		case SDL_QUIT:
			ui_input('q');
			break;

		default:
			break;
		}
	}
}
Example #4
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;
}
Example #5
0
Ncurses::Ncurses(int x, int y)
{
  try
    {
      if (check_env() == -1)
	throw (DisplayException("Environement variable needed"));
    }
  catch (const Exception e)
    {
      std::cerr << e.what() << std::endl;
    }
  initscr();
  start_color();
  curs_set(FALSE);
  keypad(stdscr, TRUE);
  noecho();
  nodelay(stdscr, TRUE);
  _x = x + 2;
  _y = y + 2;
  _dtime = 150000;
  _game = newwin(_y, _x, 0, 0);
  set_color_pair();
  draw_border();
  handle_resize();
  wrefresh(_game);
  
}
Example #6
0
void
resize_windows()
{
	struct window_dimensions *dimensions;

	set_status_window_size();
	dimensions = status_win_dimensions;
	wresize(status_win, dimensions->height, dimensions->width);
	mvwin(status_win, dimensions->starty, dimensions->startx);
	wclear(status_win);
	box(status_win, 0, 0);
	show_status();
	wrefresh(status_win);

	set_main_window_size();
	dimensions = main_win_dimensions;
	wresize(main_win, dimensions->height, dimensions->width);
	handle_resize(main_win);
	show_files(main_win);
}
Example #7
0
static nh_bool option_change_callback(struct nh_option_desc *option)
{
    if (!strcmp(option->name, "classic_status") ||
	!strcmp(option->name, "darkmsg") ||
	!strcmp(option->name, "frame") ||
	!strcmp(option->name, "frame_hp_color") ||
	!strcmp(option->name, "status3") ||
	!strcmp(option->name, "sidebar")) {
	rebuild_ui();
	return TRUE;
    }
    else if (!strcmp(option->name, "showexp") ||
	!strcmp(option->name, "showscore") ||
	!strcmp(option->name, "time")) {
	curses_update_status(NULL);
    }
    else if (!strcmp(option->name, "darkroom") ||
	!strcmp(option->name, "hilite_peaceful") ||
	!strcmp(option->name, "hilite_pet") ||
	!strcmp(option->name, "mapcolors")) {
	draw_map(player.x, player.y);
    }
    else if (!strcmp(option->name, "darkgray")) {
	set_darkgray();
	draw_map(player.x, player.y);
    }
    else if (!strcmp(option->name, "dungeon_name")) {
	settings.dungeon_name = option->value.e;
	rebuild_ui();
    }
    else if (!strcmp(option->name, "menu_headings")) {
	settings.menu_headings = option->value.e;
    }
    else if (!strcmp(option->name, "graphics")) {
	settings.graphics = option->value.e;
	switch_graphics(option->value.e);
	if (ui_flags.ingame) {
	    draw_map(player.x, player.y);
	    redraw_game_windows();
	}
    }
    else if (!strcmp(option->name, "scores_top")) {
	settings.end_top = option->value.i;
    }
    else if (!strcmp(option->name, "scores_around")) {
	settings.end_around = option->value.i;
    }
    else if (!strcmp(option->name, "optstyle")) {
	settings.optstyle = option->value.e;
    }
    else if (!strcmp(option->name, "msgheight")) {
	settings.msgheight = option->value.i;
	rebuild_ui();
    }
    else if (!strcmp(option->name, "msghistory")) {
	settings.msghistory = option->value.i;
	alloc_hist_array();
    }
#if defined(PDCURSES) && defined(WIN32)
    else if (!strcmp(option->name, "win_width")) {
	settings.win_width = option->value.i;
	resize_term(settings.win_height, settings.win_width);
	handle_resize();
    }
    else if (!strcmp(option->name, "win_height")) {
	settings.win_height = option->value.i;
	resize_term(settings.win_height, settings.win_width);
	handle_resize();
    }
#endif
    else if (!strcmp(option->name, "name")) {
	if (option->value.s)
	    strcpy(settings.plname, option->value.s);
	else
	    settings.plname[0] = '\0';
    }
    else
	return FALSE;
    
    return TRUE;
}
Example #8
0
static void process_events(void)
{
	/* Our SDL event placeholder. */
	SDL_Event event;

    /* Only poll + sleep if we are autoscrolling or doing
     * something else that is interactive */
    if (((autoscroll) && autoscroll_var) || key_button_down) {
        if (!SDL_PollEvent(&event)) {
            /* If we add a sleep, the scrolling won't be super smooth.
             * Regardless, I think we need to find something to make sure we
             * don't eat 100% cpu just checking for events.
             *
             * I found that 10ms is not a bad wait. Theoretically we want to
             * wait 1000ms / fps (usually 60) -> 16ms.
             * */
            usleep(16000);

            if (autoscroll) {
                if (key_button_down & LEAST_KEY_DOWN)
                    autoscroll_var += 1;

                if (key_button_down & LEAST_KEY_UP)
                    autoscroll_var -= 1;

                scroll -= autoscroll_var;
            } else {
                if (key_button_down & LEAST_KEY_DOWN)
                    scroll -= 5;

                if (key_button_down & LEAST_KEY_UP)
                    scroll += 5;
            }

            redraw = 1;
        }
    } else {
        SDL_WaitEvent(&event);
    }

next_event:

    switch (event.type) {
    case SDL_KEYDOWN:
        /* Handle key presses. */
        handle_key_down(&event.key.keysym);
        break;

    case SDL_KEYUP:
        handle_key_up(&event.key.keysym);
        break;

    case SDL_QUIT:
        /* Handle quit requests (like Ctrl-c). */
        quit_tutorial(0);
        break;

    case SDL_VIDEORESIZE:
        handle_resize(event.resize);
        break;

    case SDL_VIDEOEXPOSE:
        redraw = 1;
        break;

    case SDL_MOUSEBUTTONDOWN:
        handle_mouse_down(&event.button);
        break;

    case SDL_MOUSEBUTTONUP:
        handle_mouse_up(&event.button);
        break;

    case SDL_MOUSEMOTION:
        handle_mouse_motion(&event.motion);
        break;

    /* A thread completed its rendering
     *
     * The thread structure of the completed job is contained
     * within the data1 pointer of the event.
     */
    case LEAST_PAGE_COMPLETE:
        finish_page_render((struct least_thread*)event.user.data1);
        redraw = 1;
        break;

    }

    /* Clear event, just in case SDL doesn't do this (TODO) */
    memset(&event, 0, sizeof(SDL_Event));
    /* If there are more events, handle them before drawing.
     * This is required for scrolling with the mouse - without this,
     * it is pretty slow and lags. */
    if (SDL_PollEvent(&event)) {
        goto next_event;
    }
}
Example #9
0
void window::main_loop()
{
  SDL_Event event;

  while(true)
  {
    while(SDL_PollEvent(&event))
    {
      switch(event.type) {
        case SDL_KEYDOWN:
          switch(event.key.keysym.sym)
	  {
            case SDLK_ESCAPE:
              exit(0);
              break;

            default:
	      keydown(event.key.keysym.sym);
              break;
          }
          break;
	case SDL_KEYUP:
	  keyup(event.key.keysym.sym);
          break;
	case SDL_MOUSEBUTTONDOWN:
	  switch(event.button.button)
	  {
	    case SDL_BUTTON_LEFT:
	      {
		const float x_screen = static_cast<float>(event.button.x);
		const float y_screen = static_cast<float>(event.button.y);

		// scaling from <0,width> to <-1,1>
		const float x_scaled =
		  2.0 * (x_screen - static_cast<float>(width) / 2.0)
		  / static_cast<float>(width);
		const float y_scaled = 
		  2.0 * (y_screen - static_cast<float>(height) / 2.0)
		  / static_cast<float>(height);
		
		mousedown(x_scaled, y_scaled);
	      }
	      break;
	    case SDL_BUTTON_WHEELUP:
	      mousewheelup();
	      break;
	    case SDL_BUTTON_WHEELDOWN:
	      mousewheeldown();
	      break;
	  }
	  break;
	case SDL_MOUSEBUTTONUP:
	  if(event.button.button == SDL_BUTTON_LEFT)
	    mouseup();
	  break;
	case SDL_MOUSEMOTION:
	  {
	    const float x_screen = static_cast<float>(event.motion.x);
	    const float y_screen = static_cast<float>(event.motion.y);

	    // scaling from <0,width> to <-1,1>
	    const float x_scaled =
	      2.0 * (x_screen - static_cast<float>(width) / 2.0)
	      / static_cast<float>(width);
	    const float y_scaled = 
	      2.0 * (y_screen - static_cast<float>(height) / 2.0)
	      / static_cast<float>(height);

	    mousemotion(x_scaled, y_scaled);
	  }
	  break;
	case SDL_VIDEORESIZE:
	  handle_resize(event.resize.w, event.resize.h);
	  break;
        case SDL_QUIT:
          exit(0);
          break;
      }
    }

    frame();
  }
}
Example #10
0
File: tasknc.c Project: skn/tasknc
void check_resize() /* {{{ */
{
	/* check for a screen resize and handle it */
	if (is_term_resized(rows, cols))
		handle_resize();
} /* }}} */