From 6b709f047a386268d68fbae04186d92100532845 Mon Sep 17 00:00:00 2001 From: Murilo Pereira Date: Mon, 6 Jun 2011 02:21:50 -0300 Subject: [PATCH] Name-spaced functions for cursor. --- src/cursor.c | 20 ++++++++++---------- src/cursor.h | 12 ++++++------ src/game.c | 6 +++--- src/keyboard.c | 22 +++++++++++----------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/cursor.c b/src/cursor.c index c8312a8..b23fc3a 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -8,7 +8,7 @@ #include "game.h" #include "common.h" -void allocate_cursor(struct cursor **cursor) { +void cursor_malloc(struct cursor **cursor) { if (!(*cursor = malloc(sizeof(**cursor)))) { fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__)); exit(errno); @@ -16,34 +16,34 @@ void allocate_cursor(struct cursor **cursor) { (*cursor)->window = newwin(1, 1, CURSOR_BEGIN_Y, CURSOR_BEGIN_X); } -void initialize_cursor(struct cursor *cursor) { +void cursor_init(struct cursor *cursor) { mvwin(cursor->window, CURSOR_BEGIN_Y, CURSOR_BEGIN_X); cursor->y = CURSOR_BEGIN_Y; cursor->x = CURSOR_BEGIN_X; cursor->marked = false; } -void free_cursor(struct cursor *cursor) { +void cursor_free(struct cursor *cursor) { delwin(cursor->window); free(cursor); } -void mark_cursor(struct cursor *cursor) { +void cursor_mark(struct cursor *cursor) { cursor->marked = true; } -void unmark_cursor(struct cursor *cursor) { +void cursor_unmark(struct cursor *cursor) { cursor->marked = false; } -void move_cursor(struct cursor *cursor, enum movement movement) { +void cursor_move(struct cursor *cursor, enum movement movement) { switch (movement) { case LEFT: if (cursor->x > CURSOR_BEGIN_X) { cursor->x = cursor->x - 8; if (cursor->y > CURSOR_BEGIN_Y) { - move_cursor(cursor, UP); - move_cursor(cursor, DOWN); + cursor_move(cursor, UP); + cursor_move(cursor, DOWN); } } break; @@ -78,8 +78,8 @@ void move_cursor(struct cursor *cursor, enum movement movement) { if (cursor->x < 49) { cursor->x = cursor->x + 8; if (cursor->y > CURSOR_BEGIN_Y) { - move_cursor(cursor, UP); - move_cursor(cursor, DOWN); + cursor_move(cursor, UP); + cursor_move(cursor, DOWN); } } break; diff --git a/src/cursor.h b/src/cursor.h index e54f528..39664b1 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -35,11 +35,11 @@ enum movement { LEFT, DOWN, UP, RIGHT }; extern struct deck *deck; -void allocate_cursor(struct cursor **); -void initialize_cursor(struct cursor *); -void free_cursor(struct cursor *); -void mark_cursor(struct cursor *); -void unmark_cursor(struct cursor *); -void move_cursor(struct cursor *, enum movement); +void cursor_malloc(struct cursor **); +void cursor_init(struct cursor *); +void cursor_free(struct cursor *); +void cursor_mark(struct cursor *); +void cursor_unmark(struct cursor *); +void cursor_move(struct cursor *, enum movement); #endif diff --git a/src/game.c b/src/game.c index af09df3..fc1d4ff 100644 --- a/src/game.c +++ b/src/game.c @@ -178,8 +178,8 @@ static void deal_cards(struct deck *deck) { } void game_init() { - allocate_cursor(&cursor); - initialize_cursor(cursor); + cursor_malloc(&cursor); + cursor_init(cursor); deck_malloc(&deck); deck_init(deck); @@ -202,7 +202,7 @@ void game_init() { } void game_end() { - free_cursor(cursor); + cursor_free(cursor); deck_free(deck); } diff --git a/src/keyboard.c b/src/keyboard.c index 8fece50..a5d07ce 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -99,7 +99,7 @@ static void handle_card_movement(struct cursor *cursor) { cursor->y++; } erase_cursor(cursor); - mark_cursor(cursor); + cursor_mark(cursor); draw_cursor(cursor); while (1) { @@ -107,25 +107,25 @@ static void handle_card_movement(struct cursor *cursor) { case 'h': case KEY_LEFT: erase_cursor(cursor); - move_cursor(cursor, LEFT); + cursor_move(cursor, LEFT); draw_cursor(cursor); break; case 'j': case KEY_DOWN: erase_cursor(cursor); - move_cursor(cursor, DOWN); + cursor_move(cursor, DOWN); draw_cursor(cursor); break; case 'k': case KEY_UP: erase_cursor(cursor); - move_cursor(cursor, UP); + cursor_move(cursor, UP); draw_cursor(cursor); break; case 'l': case KEY_RIGHT: erase_cursor(cursor); - move_cursor(cursor, RIGHT); + cursor_move(cursor, RIGHT); draw_cursor(cursor); break; case 'm': @@ -197,7 +197,7 @@ static void handle_card_movement(struct cursor *cursor) { cursor->y--; } } - unmark_cursor(cursor); + cursor_unmark(cursor); draw_cursor(cursor); return; case KEY_ESCAPE: @@ -211,7 +211,7 @@ static void handle_card_movement(struct cursor *cursor) { draw_stack(*origin); } if (cursor->marked) { - unmark_cursor(cursor); + cursor_unmark(cursor); draw_cursor(cursor); } return; @@ -229,25 +229,25 @@ void handle_keyboard_event(int key) { case 'h': case KEY_LEFT: erase_cursor(cursor); - move_cursor(cursor, LEFT); + cursor_move(cursor, LEFT); draw_cursor(cursor); break; case 'j': case KEY_DOWN: erase_cursor(cursor); - move_cursor(cursor, DOWN); + cursor_move(cursor, DOWN); draw_cursor(cursor); break; case 'k': case KEY_UP: erase_cursor(cursor); - move_cursor(cursor, UP); + cursor_move(cursor, UP); draw_cursor(cursor); break; case 'l': case KEY_RIGHT: erase_cursor(cursor); - move_cursor(cursor, RIGHT); + cursor_move(cursor, RIGHT); draw_cursor(cursor); break; case KEY_SPACEBAR: