12#define FIELD_PADDING 10
14#define FIELD_HEIGHT 20
15#define FIELD_LEFT (FIELD_PADDING)
16#define FIELD_TOP (FIELD_PADDING)
17#define FIELD_RIGHT (FIELD_PADDING + BLOCK_SIZE * FIELD_WIDTH)
18#define FIELD_BOTTOM (FIELD_PADDING + BLOCK_SIZE * FIELD_HEIGHT)
20#define SIDE_PANEL_PADDING 20
21#define SIDE_PANEL_WIDTH 220
22#define SIDE_PANEL_LEFT (FIELD_RIGHT + FIELD_PADDING)
23#define SIDE_PANEL_TOP (FIELD_TOP)
24#define SIDE_PANEL_RIGHT (SIDE_PANEL_LEFT + SIDE_PANEL_WIDTH - FIELD_PADDING)
25#define SIDE_PANEL_BOTTOM (FIELD_BOTTOM)
26#define SIDE_PANEL_TEXT_HEIGHT 42
27#define SIDE_PANEL_LABEL_HEIGHT 42
28#define SIDE_PANEL_LABEL_PADDING 40
30#define WINDOW_WIDTH ((FIELD_WIDTH) * BLOCK_SIZE + FIELD_PADDING * 2 + SIDE_PANEL_WIDTH)
31#define WINDOW_HEIGHT ((FIELD_HEIGHT) * BLOCK_SIZE + FIELD_PADDING * 2)
33#define CURRENT_SCORE_LABEL_ID 0
34#define COMPLETE_LINES_LABEL_ID 1
35#define PLAYED_BLOCKS_LABEL_ID 2
37#define TICK_SPEED (CLOCKS_PER_SEC)
38#define DROPPING_TICK_SPEED (CLOCKS_PER_SEC / 12)
39#define CLEARING_LINES_TICK_SPEED (CLOCKS_PER_SEC / 15)
40#define START_SCREEN_TICK_SPEED ((CLOCKS_PER_SEC / 4) * 3)
238 textRect.
top = rect.
bottom - fontHeight * 7;
241 textRect.
top += fontHeight;
242 textRect.
bottom += fontHeight;
244 textRect.
top += fontHeight;
245 textRect.
bottom += fontHeight;
333 for (
uint64_t j = i; j < 4 - i - 1; j++)
336 (*piece)[i][j] = (*piece)[4 - 1 - j][i];
337 (*piece)[4 - 1 - j][i] = (*piece)[4 - 1 - i][4 - 1 - j];
338 (*piece)[4 - 1 - i][4 - 1 - j] = (*piece)[j][4 - 1 - i];
339 (*piece)[j][4 - 1 - i] = temp;
476 bool isLineComplete =
true;
481 isLineComplete =
false;
694 rect.
left += width - 8;
695 rect.
right += width - 8;
698 rect.
left += width + 8;
699 rect.
right += width + 8;
705 static bool blink =
false;
uint64_t font_width(const font_t *font, const char *string, uint64_t length)
void font_free(font_t *font)
font_t * font_new(display_t *disp, const char *family, const char *weight, uint64_t size)
uint64_t font_height(const font_t *font)
void display_disconnect(display_t *disp)
Disconnect the display connection.
uint64_t display_next(display_t *disp, event_t *event, clock_t timeout)
Retrieve the next event from the display connection.
uint64_t display_dispatch(display_t *disp, const event_t *event)
Dispatch an event to the appropriate surface.
void display_free(display_t *disp)
Free a display connection.
display_t * display_new(void)
Create a new display connection.
void draw_rect(drawable_t *draw, const rect_t *rect, pixel_t pixel)
Draw a filled rectangle.
void draw_ridge(drawable_t *draw, const rect_t *rect, uint64_t width, pixel_t foreground, pixel_t background)
Draw a ridge effect.
void draw_text(drawable_t *draw, const rect_t *rect, const font_t *font, align_t xAlign, align_t yAlign, pixel_t pixel, const char *text)
Draw text to a drawable.
void draw_bezel(drawable_t *draw, const rect_t *rect, uint64_t width, pixel_t pixel)
Draw a filled border bezel just inside the given rectangle.
void draw_frame(drawable_t *draw, const rect_t *rect, uint64_t width, pixel_t foreground, pixel_t background)
Draw a skeuomorphic frame.
text_props_t * element_get_text_props(element_t *elem)
Get the text properties of an element.
theme_t * element_get_theme(element_t *elem)
Get the theme of an element.
void element_draw_end(element_t *elem, drawable_t *draw)
End drawing to an element.
void element_draw_begin(element_t *elem, drawable_t *draw)
Begin drawing to an element.
void element_redraw(element_t *elem, bool shouldPropagate)
Redraw an element.
uint64_t element_set_text(element_t *elem, const char *text)
Set the text of an element.
uint64_t window_set_visible(window_t *win, bool isVisible)
Set the visibility of the window.
uint64_t window_set_timer(window_t *win, timer_flags_t flags, clock_t timeout)
Set the window timer.
window_t * window_new(display_t *disp, const char *name, const rect_t *rect, surface_type_t type, window_flags_t flags, procedure_t procedure, void *private)
Allocate and initialize a new window.
void window_free(window_t *win)
Free a window.
display_t * window_get_display(window_t *win)
Get the display associated with the window.
@ WINDOW_DECO
Enable decorations (titlebar, close/minimize buttons, etc).
keycode_t
Keyboard keycode type.
@ KBD_RELEASE
Key release event.
@ KBD_PRESS
Key press event.
clock_t uptime(void)
System call for retreving the time since boot.
#define NULL
Pointer error value.
EFI_PHYSICAL_ADDRESS buffer
#define PIXEL_ARGB(a, r, g, b)
static uint64_t procedure(window_t *win, element_t *elem, const event_t *event)
static void current_piece_rotate(element_t *elem, drawable_t *draw)
static uint64_t oldCurrentScore
static uint64_t oldCompletedLines
static void field_check_for_lines(element_t *elem, drawable_t *draw)
static element_t * playedBlocksLabel
static void block_draw(element_t *elem, drawable_t *draw, block_t block, int64_t x, int64_t y)
#define CLEARING_LINES_TICK_SPEED
static const pixel_t shadowColors[]
static void current_piece_draw(element_t *elem, drawable_t *draw)
static font_t * massiveFont
static void side_panel_draw(element_t *elem, drawable_t *draw)
static bool isClearingLines
static void piece_outline_draw(element_t *elem, drawable_t *draw, const piece_t *piece, uint64_t pieceX, uint64_t pieceY)
static uint64_t oldPlayedBlocks
static block_t field[FIELD_HEIGHT][FIELD_WIDTH]
static void piece_rotate(piece_t *piece)
static uint64_t playedBlocks
static void current_piece_update(element_t *elem, drawable_t *draw)
#define DROPPING_TICK_SPEED
static bool piece_is_out_of_bounds(const piece_t *piece, int64_t pieceX, int64_t pieceY)
static uint64_t completedLines
static void current_piece_clear(element_t *elem, drawable_t *draw)
static block_t oldField[FIELD_HEIGHT][FIELD_WIDTH]
#define START_SCREEN_TICK_SPEED
#define SIDE_PANEL_LABEL_HEIGHT
static bool field_collides(const piece_t *piece, int64_t pieceX, int64_t pieceY)
static void current_piece_move(element_t *elem, drawable_t *draw, keycode_t code)
static element_t * currentScoreLabel
static struct @30 currentPiece
static void piece_clear(element_t *elem, drawable_t *draw, const piece_t *piece, uint64_t pieceX, uint64_t pieceY)
static const pixel_t normalColors[]
static const pixel_t highlightColors[]
static void field_clear_lines(element_t *elem, drawable_t *draw)
#define SIDE_PANEL_LABEL_PADDING
static font_t * largeFont
static void current_piece_drop(element_t *elem, drawable_t *draw)
static void current_piece_choose_new(void)
static void field_edge_draw(element_t *elem, drawable_t *draw)
static void field_move_down(uint64_t line)
block_t piece_t[PIECE_HEIGHT][PIECE_WIDTH]
static void field_draw(element_t *elem, drawable_t *draw)
static uint64_t currentScore
static point_t piece_block_pos_in_field(int64_t pieceX, int64_t pieceY, int64_t blockX, int64_t blockY)
static void piece_draw(element_t *elem, drawable_t *draw, const piece_t *piece, uint64_t pieceX, uint64_t pieceY)
static void start_press_space_draw(element_t *elem, drawable_t *draw)
#define PLAYED_BLOCKS_LABEL_ID
static void start_tetris_draw(drawable_t *draw)
#define COMPLETE_LINES_LABEL_ID
#define SIDE_PANEL_BOTTOM
#define SIDE_PANEL_TEXT_HEIGHT
static element_t * completeLinesLabel
static void field_add_piece(const piece_t *piece, int64_t pieceX, int64_t pieceY)
#define CURRENT_SCORE_LABEL_ID
#define RECT_SHRINK(rect, margin)
#define RECT_INIT_DIM(x, y, width, height)
#define RECT_INIT(left, top, right, bottom)
#define RECT_EXPAND(rect, margin)
_PUBLIC int sprintf(char *_RESTRICT s, const char *_RESTRICT format,...)
_PUBLIC void srand(unsigned int seed)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
Opaque display structure.
Opaque element structure.