Exemple #1
0
static void
draw_part(void (*func) (DATA *), int state, DATA * data)
{
    data->func = func;
    data->state = state;
    use_window(stdscr, really_draw, (void *) data);
    napsome();
}
Exemple #2
0
void t_curses_term_reader(void *config) // read messages from terminal
{
  CONFIG *c = (CONFIG*) config;
  while ( running )
  {
    char command_buf[MAX_LINE_SIZE];
    memset(command_buf, 0, MAX_LINE_SIZE);
    use_window(c->w3, (NCURSES_WINDOW_CB) cb_read_command, command_buf);
    if ( strlen(command_buf) < 1 )          continue;
    // user command to the server AND echo to the screen
    send_message(c->ob_mq, command_buf);
    send_message(c->ib_mq, command_buf);
    if ( begins_with(command_buf, FICS_QUIT) ) running = false;
  }
}
Exemple #3
0
/* new window size or exposure */
static void
reshape(int width, int height)
{
   GLfloat ar = (GLfloat) width / (GLfloat) height;

   use_window();

   glViewport(0, 0, (GLint) width, (GLint) height);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glFrustumf(-ar, ar, -1, 1, 5.0, 60.0);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef(0.0, 0.0, -40.0);
}
Exemple #4
0
static void
draw(void)
{
   use_pbuffer();
   draw_triangle();

   use_window();

   eglBindTexImage(dpy, surf_pbuf, EGL_BACK_BUFFER);

   glPushMatrix();
   glRotatef(view_rotx, 1, 0, 0);
   glRotatef(view_roty, 0, 1, 0);
   glRotatef(view_rotz, 0, 0, 1);

   draw_textured_cube();

   glPopMatrix();

   eglReleaseTexImage(dpy, surf_pbuf, EGL_BACK_BUFFER);
}
Exemple #5
0
void t_curses_term_writer(void *config) // write messages to terminal
{
  CONFIG *c = (CONFIG*) config;
  UPDATE *u = malloc(sizeof *u); if ( u == NULL ) error("update malloc");

  // track changes matrix out as false
  bool changed[N_ROWS][N_COLS];// = { [0 ... N_ROWS-1][0 ... N_COLS-1] = false };

  int s12, g1, _ = 0;
  while ( running )
  {
    // 
    char recv_buf[MAX_LINE_SIZE];
    memset(recv_buf, 0, MAX_LINE_SIZE);

    int MODE = IDLE;

    if ( mq_receive(c->ib_mq, recv_buf, MAX_LINE_SIZE, 0) == -1 ) error("mq_receive");

    // peek into the message and handle appropriately
    //
    if ( begins_with(recv_buf, GAMEINFO_MARKER) )
    {
      parse_gameinfo_string( recv_buf, u );
      g1++;
    }
    else if ( begins_with(recv_buf, STYLE12_MARKER) )
    { 
      // make a copy of the existing ("old") board
      memset(u->old_board, 0, sizeof u->old_board);
      memcpy(u->old_board, u->board, sizeof u->board);

      // parse the new board
      parse_s12_string( recv_buf, u );

      if (s12 > 0) // this is not the first message
      {
        // assume new board has not changed
        memset(changed, false, sizeof changed);
        // compare new board to old board
        for (int i=0; i<N_ROWS; i++)
          for (int j=0; j<N_ROWS; j++)
            changed[i][j] = (bool) (u->old_board[i][j] != u->board[i][j]);
      }

      MODE = u->my_status;
      if ( ! ( u->white_rating == NULL) ) // have gameinfo
        use_window(c->w1, (NCURSES_WINDOW_CB) cb_write_board, u);

      s12++;
    }
    else
    { 
      // normal line, no parsing necessary.  write to w2
      use_window(c->w2, (NCURSES_WINDOW_CB) cb_write_response, recv_buf);
      _++;
    }

    // handle cursor placement in a mode-dependent way
    switch ( MODE )
    {
      case PLAYING_MY_MOVE:
      case PLAYING_OPPONENTS_MOVE:
        // TODO move cursor to last remaining piece, or king pawn if
        // first move, etc
        break;
      case OBSERVING: 
      case IDLE:
        // move cursor to the input line
        // TODO command history (?)
        wmove(c->w3, LINES, COLS);
        wrefresh(c->w3);
        break;
      default: break;
    }
  }
  // clear dynamic memory
  free(u->my_nick);
  free(u->opp_nick);
  free(u->text);
  free(u->type);
  free(u->white_rating);
  free(u->black_rating);
  free(u);
  u = NULL;
}