void draw_board(SDL_Surface* screen, int* board, Uint32 bg_color, Uint32 cell_color) { SDL_FillRect(screen, &(screen->clip_rect), bg_color); for (int y = 0; y < ROWS; ++y) { for (int x = 0; x < COLUMNS; ++x) { if (board[CELL(x,y)]) { fill_cell(screen, x, y, cell_color); } } } draw_line(screen, 0, 0, SCR_WIDTH - 1, 0, bg_color); draw_line(screen, 0, 0, 0, SCR_HEIGHT - 1, bg_color); draw_line(screen, 0, SCR_HEIGHT - 1, SCR_WIDTH - 1, SCR_HEIGHT - 1, bg_color); draw_line(screen, SCR_WIDTH - 1, 0, SCR_WIDTH - 1, SCR_HEIGHT - 1, bg_color); for (int x = CELL_SIZE; x < SCR_WIDTH; x += CELL_SIZE) { draw_line(screen, x, 0, x, SCR_HEIGHT - 1, bg_color); } for (int y = CELL_SIZE; y < SCR_HEIGHT; y += CELL_SIZE) { draw_line(screen, 0, y, SCR_WIDTH - 1, y, bg_color); } SDL_Flip(screen); }
/* * draws the live cells on the board */ void Widget::draw_cells(QPainter &p) { p.setPen(Qt::blue); // blue color for (int i = 0; i < controller.get_world_state().get_number_of_cells(); i++) { // get the center of each cell in the controller's worldstate Point cellCenter = controller.get_world_state().cell_at_index(i).get_coordinates(); cellCenter.set_x(cellCenter.get_x() * cell_length); // scale cell size cellCenter.set_y(cellCenter.get_y() * cell_length); // scale cell size // fill the cell with the desired center fill_cell(cellCenter, p); } }
gboolean next_piece_expose_event(GtkWidget *widget, gpointer data) { int square_index; cairo_t* cr = gdk_cairo_create (widget->window); cairo_set_source_rgb(cr, 1, 1, 1); cairo_paint(cr); for (square_index = 0; square_index < NUMBER_OF_SQUARES; square_index++) { int i = tetrominos[next_shape].coords[square_index][0]; int j = 2 + tetrominos[next_shape].coords[square_index][1]; fill_cell(cr, next_shape, i, j); } cairo_destroy(cr); return TRUE; }
void draw_grid() { int row_index, column_index; cairo_t* cr = gdk_cairo_create (application.grid->window); cairo_set_source_rgb(cr, WHITE.red, WHITE.green, WHITE.blue); cairo_paint(cr); for (row_index = 0; row_index < NUMBER_OF_ROWS; row_index++) { for (column_index = 0; column_index < NUMBER_OF_COLUMNS; column_index++) { int tetromino_type = grid[row_index][column_index]; if (tetromino_type != 0) { fill_cell(cr, tetromino_type - 1, row_index, column_index); } } } cairo_destroy(cr); }