void keyCheck() { if (keyStates['i']||arrowKeys[UP_ARROW]){ r_up(); } if (keyStates['j']||arrowKeys[LEFT_ARROW]) { r_left(); } if (keyStates['k']||arrowKeys[DOWN_ARROW]){ r_down(); } if (keyStates['l']||arrowKeys[RIGHT_ARROW]) { r_right(); } glutPostRedisplay(); }
int CPROC DrawGrid( PSI_CONTROL frame ) { int p_r, p_c, p, x, y; Image surface = GetControlSurface( frame ); ClearImageTo( surface, BASE_COLOR_BLACK ); for( p_r = 0; p_r < 3; p_r++ ) { for( p_c = 0; p_c < 4; p_c++ ) { p = p_r*4 + p_c; BlatColor( surface , patch_left(p_c) , patch_top( p_r ) , patch_width(p_c) , patch_height( p_r ) , BASE_COLOR_DARKGREY ); for( x = 0; x < HEX_SIZE; x++ ) for( y = 0; y < HEX_SIZE; y++ ) { // 640 / 4 = 160 // 480 / 3 = 160 //lprintf( WIDE("r_left is %d -> %d r_right is %d"), r_left(x), r_left(x+1), r_width(x) ); if( x == cur_x && y == cur_y && p == cur_s ) { if( bodymap.band[p][x][y] ) { BlatColor( surface, r_left(x), r_top( y ) , r_width(x), r_height( y ) , BASE_COLOR_YELLOW ); } else { BlatColor( surface, r_left(x), r_top( y ) , r_width(x), r_height( y ) , BASE_COLOR_RED ); } } else { if( bodymap.band[p][x][y] ) { BlatColor( surface , r_left(x), r_top( y ) , r_width(x), r_height( y ) , BASE_COLOR_BLUE ); } else { BlatColor( surface , r_left(x), r_top( y ) , r_width(x), r_height( y ) , BASE_COLOR_GREEN ); } } } } } return 1; }
void WMain::generateTables() { // Amount of columns and rows. uint columns = ui -> sb_columns -> value(); uint rows = ui -> sb_rows -> value(); // Creating pixmaps. table = QPixmap(2 * columns * TABLE_CELL_W + 1, rows * TABLE_CELL_H + 1); checker = QPixmap(table.size()); // Filling up 'em with white. table.fill(); checker.fill(); // Creating painters. QPainter p_table(&table); QPainter p_checker(&checker); // Setting up font size. QFont font = p_table.font(); font.setPixelSize(TABLE_TEXT_SIZE); p_table.setFont(font); p_checker.setFont(font); // Array with available columns. std::vector<uint> column_array; if (ui -> cb_0 -> isChecked()) column_array.push_back(0); if (ui -> cb_1 -> isChecked()) column_array.push_back(1); if (ui -> cb_2 -> isChecked()) column_array.push_back(2); if (ui -> cb_3 -> isChecked()) column_array.push_back(3); if (ui -> cb_4 -> isChecked()) column_array.push_back(4); if (ui -> cb_5 -> isChecked()) column_array.push_back(5); if (ui -> cb_6 -> isChecked()) column_array.push_back(6); if (ui -> cb_7 -> isChecked()) column_array.push_back(7); if (ui -> cb_8 -> isChecked()) column_array.push_back(8); if (ui -> cb_9 -> isChecked()) column_array.push_back(9); if (ui -> cb_10 -> isChecked()) column_array.push_back(10); // WTF? if (column_array.size() == 0) return; // Initializing random. qsrand(QTime::currentTime().secsTo(QTime())); // Creating tables. for (uint i = 0; i < columns; i++) for (uint j = 0; j < rows; j++) { // Generating index. int index_1 = column_array[qrand() % column_array.size()]; int index_2 = qrand() % names[index_1].size(); // Preparing rectangles. QRect r_left(2 * i * TABLE_CELL_W, j * TABLE_CELL_H, TABLE_CELL_W, TABLE_CELL_H); QRect r_right((2 * i + 1) * TABLE_CELL_W, j * TABLE_CELL_H, TABLE_CELL_W, TABLE_CELL_H); // Drawing on table. p_table.drawText(r_left, Qt::AlignCenter | Qt::AlignHCenter, names[index_1][index_2]); p_table.drawRect(r_left); p_table.drawRect(r_right); // Drawing on checker. p_checker.drawText(r_left, Qt::AlignCenter | Qt::AlignHCenter, names[index_1][index_2]); p_checker.drawText(r_right, Qt::AlignCenter | Qt::AlignHCenter, letters[index_1][index_2]); p_checker.drawRect(r_left); p_checker.drawRect(r_right); } // Saving pictures (for debug). #ifdef QT_DEBUG table.save("table.png", "png"); checker.save("checker.png", "png"); #endif // We're ready now! ((QLabel*) ui -> sa_task -> widget()) -> setPixmap(table); ((QLabel*) ui -> sa_checker -> widget()) -> setPixmap(checker); ui -> t_task -> setEnabled(true); ui -> t_checker -> setEnabled(true); }