Exemple #1
0
int main(int ac, char **av)
{
    int     move_col,
            msec;
    int     time_line,
            move_line;
    long    num_start_time,
            num_now_time;
    char    str_start_time[60],
            str_now_time[60];

    msec = 0;
    if (ac > 1) {
        msec = atoi(av[1]);
	if (msec < 10)
	    msec = 10;
	else if (msec > 1000)
	    msec = 1000;
    }
    if (! initscr())
	exit(1);

    signal(SIGINT, die);
    signal(SIGQUIT, die);
    signal(SIGHUP, die);
    signal(SIGTERM, die);

    box(stdscr, '*', '*');

    time(&num_start_time);
    strcpy(str_start_time, ctime(&num_start_time));
    *(index(str_start_time, '\n')) = '\0';

    centered(3, "*** Test started at: ***");
    centered(4, str_start_time);

    move_col = 1;
    move_line = (LINES - 2) / 2;
    time_line = move_line + (LINES - move_line - 1) / 2;

    while (TRUE) {
	time(&num_now_time);
	strcpy(str_now_time, ctime(&num_now_time));
	*(index(str_now_time, '\n')) = '\0';

	centered(time_line, str_now_time);

	mvaddstr(move_line, move_col, "<-*->");

	refresh();

	mvaddstr(move_line, move_col, "     ");
	if (++move_col >= (COLS - 6))
	    move_col = 1;

	if (msec)
	    usleep(msec * 1000);
    }
}
        /*
         * Get a random point in a unit sphere. This is done by generating
         * points in a cube until we get one inside the sphere. The square
         * of the vector length is returned, and cannot be zero.
         */
                double
        sphere (
                LXtVector	 p)
        {
                double		 r2;

                while (1)
                {
                        LXx_VSET3 (p, centered (), centered (), centered ());
                        r2 = LXx_VDOT (p, p);
                        if (r2 <= 1.0)
                                return r2;
                }
        }
        /*
         * Get a random number in an approximately normal (Gaussian)
         * distribution with stddev of 1.0.  (Box-Muller transform)
         */
                double
        normal ()
        {
                float		 u = centered ();
                float		 v = centered ();
                double		 r, c;

                r = u * u + v * v;
                if (r == 0 || r > 1)
                        return normal ();

                c = sqrt (-2.0 * log (r) / r);
                return u * c;
        }
 /*
  * Vary a base value by +/- delta.
  */
         float
 vary (
         float		 base,
         float		 delta)
 {
         return base + delta * centered ();
 }
Exemple #5
0
void MyBitmap::PaintCenter(CDC* pDC, const CRect& rect)
{
    int x = (rect.left+rect.right)/2 - m_width/2;
    int y = (rect.top+rect.bottom)/2 - m_height/2;
    CRect centered(x,y,x+m_width,y+m_height);
    CRect centeredopt;
    centeredopt.IntersectRect(&centered,&rect);
    if(centeredopt.left>rect.left || centeredopt.top>rect.top)
        pDC->FillSolidRect(&rect,m_clrbkg);
    Paint(pDC, centeredopt, false);
}
Exemple #6
0
static Line *
textblock(Paragraph *p, int toplevel, DWORD flags)
{
    Line *t, *next;

    for ( t = p->text; t ; t = next ) {
	if ( ((next = t->next) == 0) || endoftextblock(next, toplevel, flags) ) {
	    p->align = centered(p->text, t);
	    t->next = 0;
	    return next;
	}
    }
    return t;
}
Exemple #7
0
    /**
     * \return Centered points matrix.
     *
     * Creates a PointMatrix populated with zero mean points
     *
     * \throws ZeroDimensionException
     * \throws Exception
     */
    PointMatrix centered_points() const
    {
        INLINE_CHECK_POINT_SET_DIMENSIONS();

        PointMatrix centered(points_.rows(), points_.cols());

        const Point weighted_mean = mean();
        const int point_count = points_.cols();
        for (int i = 0; i < point_count; ++i)
        {
            centered.col(i) = points_.col(i) - weighted_mean;
        }

        return centered;
    }
Exemple #8
0
void initialize_curses()
{
  // start curses
  initscr();
  if (  ! has_colors() || (start_color() != OK) || COLORS != 256 ) error("colors");

  // Define three horizontally-stacked windows:
  // 
  //    1 - board window
  //    2 - CLI output window
  //    3 - CLI input window
  //
  int half_height = LINES / 2;
  //   newwin( height,          width,  begin_height,   begin_width    );
  w1 = newwin( half_height,     COLS,      0,              0              );
  w2 = newwin( half_height - 1, COLS,      half_height,    0              );
  w3 = newwin( 1,               COLS,      LINES - 1,      0              );
  if (w1 == NULL || w2 == NULL || w3 == NULL) { waddstr(stdscr, "newwin"); endwin(); }

  echo(); scrollok(w2, TRUE);

  // initialize color tuples
  //   see http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
  //                            FG,     BG
  init_pair(    LIGHT_SQUARE,   0,      229     );
  init_pair(    DARK_SQUARE,    0,      209     );
  init_pair(    BLUISH,         111,    233     );
  init_pair(    TERMINAL,       252,    232     );
  init_pair(    GREENISH,       107,    233     );
  init_pair(    CLI_INPUT,      253,    232     ); 
  init_pair(    GRAY_ON_BLACK,  245,    233     ); 
  init_pair(    RED,            1,      52      ); 

  wbkgd( w1, COLOR_PAIR( TERMINAL  ) );
  wbkgd( w2, COLOR_PAIR( TERMINAL  ) );
  wbkgd( w3, COLOR_PAIR( CLI_INPUT ) );

  wattron(w1, COLOR_PAIR( BLUISH) );
  mvwaddstr(w1, 0, centered(TITLE), TITLE);
  wstandend(w1);

  wrefresh(stdscr); wrefresh(w1); wrefresh(w2); wrefresh(w3);
  touchwin(stdscr); touchwin(w1); touchwin(w2); touchwin(w3);
}
Exemple #9
0
void
MediaWindow::_MakeEmptyParamView()
{
	fParamWeb = NULL;

	BStringView* stringView = new BStringView("noControls",
		B_TRANSLATE("This hardware has no controls."));

	BSize unlimited(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
	stringView->SetExplicitMaxSize(unlimited);

	BAlignment centered(B_ALIGN_HORIZONTAL_CENTER,
		B_ALIGN_VERTICAL_CENTER);
	stringView->SetExplicitAlignment(centered);
	stringView->SetAlignment(B_ALIGN_CENTER);

	fContentLayout->AddView(stringView);
	fContentLayout->SetVisibleItem(fContentLayout->CountItems() - 1);

	rgb_color panel = stringView->LowColor();
	stringView->SetHighColor(tint_color(panel,
		B_DISABLED_LABEL_TINT));
}
Exemple #10
0
void BandwidthMeter::render(int screenWidth, int screenHeight) {

    int x = BORDER_DISTANCE_HORIZ + (AREA_WIDTH >= 0 ? 0 : screenWidth + AREA_WIDTH);
    int y = BORDER_DISTANCE_VERT + (AREA_HEIGHT >= 0 ? 0 : screenHeight + AREA_HEIGHT);
    int w = glm::abs(AREA_WIDTH), h = glm::abs(AREA_HEIGHT);

    // Determine total
    float totalIn = 0.0f, totalOut = 0.0f;
    for (size_t i = 0; i < N_CHANNELS; ++i) {

        totalIn += inputStream(ChannelIndex(i)).getValue();
        totalOut += outputStream(ChannelIndex(i)).getValue();
    }
    totalIn *= UNIT_SCALE;
    totalOut *= UNIT_SCALE;
    float totalMax = glm::max(totalIn, totalOut);

    // Get font / caption metrics
    QFontMetrics const& fontMetrics = _textRenderer->metrics();
    int fontDescent = fontMetrics.descent(); 
    int labelWidthIn = fontMetrics.width(CAPTION_IN);
    int labelWidthOut = fontMetrics.width(CAPTION_OUT);
    int labelWidthInOut = glm::max(labelWidthIn, labelWidthOut);
    int labelHeight = fontMetrics.ascent() + fontDescent;
    int labelWidthUnit = fontMetrics.width(CAPTION_UNIT);
    int labelsWidth = labelWidthInOut + SPACING_RIGHT_CAPTION_IN_OUT + SPACING_LEFT_CAPTION_UNIT + labelWidthUnit;

    // Calculate coordinates and dimensions
    int barX = x + labelWidthInOut + SPACING_RIGHT_CAPTION_IN_OUT;
    int barWidth = w - labelsWidth;
    int barHeight = (h - SPACING_VERT_BARS) / 2;
    int textYcenteredLine = h - centered(labelHeight, h) - fontDescent;
    int textYupperLine = barHeight - centered(labelHeight, barHeight) - fontDescent;
    int textYlowerLine = h - centered(labelHeight, barHeight) - fontDescent;

    // Center of coordinate system -> upper left of bar
    glPushMatrix();
    glTranslatef((float)barX, (float)y, 0.0f);

    // Render captions
    glm::vec4 textColor = getColorRGBA(COLOR_TEXT);
    _textRenderer->draw(barWidth + SPACING_LEFT_CAPTION_UNIT, textYcenteredLine, CAPTION_UNIT, textColor);
    _textRenderer->draw(-labelWidthIn - SPACING_RIGHT_CAPTION_IN_OUT, textYupperLine, CAPTION_IN, textColor);
    _textRenderer->draw(-labelWidthOut - SPACING_RIGHT_CAPTION_IN_OUT, textYlowerLine, CAPTION_OUT, textColor);

    // Render vertical lines for the frame
    // TODO: I think there may be a bug in this newest code and/or the GeometryCache code, because it seems like
    // sometimes the bandwidth meter doesn't render the vertical lines
    renderVerticalLine(0, 0, h, COLOR_FRAME);
    renderVerticalLine(barWidth, 0, h, COLOR_FRAME);

    // Adjust scale
    int steps;
    double step, scaleMax;
    bool commit = false;
    do {
        steps = (_scaleMaxIndex % 9) + 2;
        step = pow(10.0, (_scaleMaxIndex / 9) - 10);
        scaleMax = step * steps;
        if (commit) {
//            printLog("Bandwidth meter scale: %d\n", _scaleMaxIndex);
            break;
        }
        if (totalMax < scaleMax * 0.5) {
            _scaleMaxIndex = glm::max(0, _scaleMaxIndex - 1);
            commit = true;
        } else if (totalMax > scaleMax) {
            _scaleMaxIndex += 1;
            commit = true;
        }
    } while (commit);

    step = scaleMax / NUMBER_OF_MARKERS;
    if (scaleMax < MIN_METER_SCALE) {
        scaleMax = MIN_METER_SCALE;
    }
    
    // Render scale indicators
    for (int j = NUMBER_OF_MARKERS; --j > 0;) {
        renderVerticalLine((barWidth * j) / NUMBER_OF_MARKERS, 0, h, COLOR_INDICATOR);
    }

    // Render bars
    int xIn = 0, xOut = 0;
    for (size_t i = 0; i < N_CHANNELS; ++i) {

        ChannelIndex chIdx = ChannelIndex(i);
        int wIn = (int)(barWidth * inputStream(chIdx).getValue() * UNIT_SCALE / scaleMax);
        int wOut = (int)(barWidth * outputStream(chIdx).getValue() * UNIT_SCALE / scaleMax);

        if (wIn > 0) {
            renderBox(xIn, 0, wIn, barHeight, channelInfo(chIdx).colorRGBA);
        }
        xIn += wIn;

        if (wOut > 0) {
            renderBox(xOut, h - barHeight, wOut, barHeight, channelInfo(chIdx).colorRGBA);
        }
        xOut += wOut;
    }

    // Render numbers
    char fmtBuf[8];
    sprintf(fmtBuf, "%0.1f", totalIn);
    _textRenderer->draw(glm::max(xIn - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE,
                                PADDING_HORIZ_VALUE),
                       textYupperLine, fmtBuf, textColor);
    sprintf(fmtBuf, "%0.1f", totalOut);
    _textRenderer->draw(glm::max(xOut - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE,
                                PADDING_HORIZ_VALUE),
                       textYlowerLine, fmtBuf, textColor);

    glPopMatrix();

    // After rendering, indicate that no data has been sent/received since the last feed.
    // This way, the meters fall when not continuously fed.
    for (size_t i = 0; i < N_CHANNELS; ++i) {
        inputStream(ChannelIndex(i)).updateValue(0);
        outputStream(ChannelIndex(i)).updateValue(0);
    }
}
Exemple #11
0
void cb_write_board(WINDOW *w, void *data)
{
  UPDATE *u = (UPDATE*) data;

  // ok, here we go -- update the gui
  
  //    reusable buffers
  char hh_mm_ss_ms[STR_TIME_LEN], update_line[COLS]; 
  memset(hh_mm_ss_ms, 0, STR_TIME_LEN);

  // update game info line
  memset(update_line, 0, COLS); wmove(w, GAME_INFO_LINE, 0); wclrtoeol(w);
  sprintf(update_line, "%s %s game #%d, %d +%d %s", 
                        u->my_status_str,
                        u->type, 
                        u->game_number, 
                        u->match_minutes,
                        u->match_increment,
                        u->rated ? "rated" : "unrated");
  mvwprintw(w, GAME_INFO_LINE, centered(update_line), update_line);

  // update opponent info line
  //
  memset(update_line, 0, COLS); wmove(w, OPP_INFO_LINE, 0); wclrtoeol(w);
  ms_to_hh_mm_ss_ms(u->opp_ms, hh_mm_ss_ms);
  sprintf(update_line, "%s (%s) %s %s", u->opp_nick, u->opp_rating, hh_mm_ss_ms, ( ! u->my_turn ? FINGER : "   "));
  mvwprintw(w, OPP_INFO_LINE, centered(update_line), update_line);

  // update board
  //    pad board for display
  char *board[N_ROWS][N_COLS*SQUARE_WIDTH];
  memset(board, 0, sizeof(*board));
  for (int row = 0; row < N_ROWS; row++)
    for (int col = 0; col < N_COLS*SQUARE_WIDTH; col++)
      board[row][col] = ((col - 1) % SQUARE_WIDTH == 0) 
        ? u->board[row][(col/SQUARE_WIDTH)]
        : EMPTY_SQUARE ;

  //    determine the window width and thereby, the proper indentation
  int w_y, w_x, h_indent, v_indent; getmaxyx(w, w_y, w_x);
  h_indent = (w_x - N_ROWS * SQUARE_WIDTH) / 2;
  v_indent = BOARD_START_LINE;
  UNUSED( w_y) ;

  //    print the board
  for (int row = 0; row < N_ROWS; row++)
  {
    bool black_square = even(row) ? true : false;
    wmove(w, row+v_indent, h_indent);
    for (int col = 0; col < N_COLS*SQUARE_WIDTH; col++)
    {
      // flip square color at square borders
      if ((col % SQUARE_WIDTH) == 0)
      {
        black_square = ! black_square;
      }
      if (black_square)   wattron(w, COLOR_PAIR( DARK_SQUARE    ) );
      else                wattron(w, COLOR_PAIR( LIGHT_SQUARE   ) );

      // highlight last move FIXME
      /*
      if (...)
      {
        wattron(w, COLOR_PAIR( RED ));
        waddstr(w, "X");
      }
      else
        waddstr(w, board[row][col]);
      */
      waddstr(w, board[row][col]);
      wstandend(w);
    }
  }

  // update my info line
  //
  memset(update_line, 0, COLS); wmove(w, MY_INFO_LINE, 0); wclrtoeol(w);
  ms_to_hh_mm_ss_ms(u->my_ms, hh_mm_ss_ms);
  sprintf(update_line, "%s (%s) %s %s", u->my_nick, u->my_rating, hh_mm_ss_ms, (u->my_turn ? FINGER : "   "));
  mvwprintw(w, MY_INFO_LINE, centered(update_line), update_line);

  // clean up formatting and refresh the gui
  wstandend(w);
  wrefresh(w);
}