2012-05-07 06:56:00 +00:00
|
|
|
/**
|
|
|
|
* \addtogroup tetris
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file view.c
|
|
|
|
* @brief Public interface definitions of Tetris' graphical output routines.
|
|
|
|
* @author Christian Kroll
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
#ifndef TETRIS_VIEW_H_
|
|
|
|
#define TETRIS_VIEW_H_
|
|
|
|
|
2010-08-24 23:00:40 +00:00
|
|
|
#include <stdint.h>
|
2010-08-28 15:13:35 +00:00
|
|
|
#include "bearing.h"
|
2010-08-22 03:07:46 +00:00
|
|
|
#include "bucket.h"
|
2010-08-28 15:13:35 +00:00
|
|
|
#include "variants.h"
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*********
|
|
|
|
* types *
|
|
|
|
*********/
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/** presentation modes */
|
2012-05-07 06:56:00 +00:00
|
|
|
enum tetris_view_mode_e
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
|
|
|
TETRIS_VIMO_PAUSED,
|
|
|
|
TETRIS_VIMO_RUNNING
|
2011-02-25 04:31:34 +00:00
|
|
|
};
|
|
|
|
#ifdef NDEBUG
|
|
|
|
typedef uint8_t tetris_view_mode_t;
|
|
|
|
#else
|
2012-05-07 06:56:00 +00:00
|
|
|
typedef enum tetris_view_mode_e tetris_view_mode_t;
|
2011-02-25 04:31:34 +00:00
|
|
|
#endif
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
|
|
|
|
/** data structure that drives the view module */
|
2012-05-07 06:56:00 +00:00
|
|
|
typedef struct tetris_view_s
|
2008-12-03 05:40:16 +00:00
|
|
|
{
|
2010-08-24 23:00:40 +00:00
|
|
|
tetris_variant_t const *pVariantMethods; /** variant function pointers */
|
2010-08-22 03:07:46 +00:00
|
|
|
void *pVariant; /** associated variant object */
|
2010-08-24 23:00:40 +00:00
|
|
|
tetris_bucket_t *pBucket; /** associated bucket */
|
2010-08-22 03:07:46 +00:00
|
|
|
tetris_view_mode_t modeCurrent; /** current presentation mode */
|
|
|
|
tetris_view_mode_t modeOld; /** old presentation mode */
|
|
|
|
uint8_t nOldLevel; /** for detecting level changes */
|
|
|
|
tetris_bearing_t nBearing; /** bearing of the bucket */
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
tetris_view_t;
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************
|
|
|
|
* construction/destruction *
|
|
|
|
*****************************/
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* constructs a view for André's borg
|
|
|
|
* @param pVarMethods associated variant method pointers
|
|
|
|
* @param pVariantData pointer to variant data object which should be observed
|
2010-08-22 03:07:46 +00:00
|
|
|
* @param pBucket pointer to bucket which should be observed
|
2010-04-01 03:11:59 +00:00
|
|
|
* @return pointer to a newly created view
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
2010-08-24 23:00:40 +00:00
|
|
|
tetris_view_t *tetris_view_construct(tetris_variant_t const *const pVarMethods,
|
2010-04-01 03:11:59 +00:00
|
|
|
void *pVariantData,
|
2010-08-22 03:07:46 +00:00
|
|
|
tetris_bucket_t *pBucket);
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* destructs a view
|
|
|
|
* @param pView: pointer to the view to be destructed
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
2011-02-06 22:56:26 +00:00
|
|
|
inline static void tetris_view_destruct(tetris_view_t *pView)
|
|
|
|
{
|
|
|
|
assert(pView != NULL);
|
|
|
|
free(pView);
|
|
|
|
}
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***************************
|
|
|
|
* view related functions *
|
|
|
|
***************************/
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* destructs a view
|
2010-08-22 03:07:46 +00:00
|
|
|
* @param w pointer to an int8_t to store the bucket width
|
|
|
|
* @param h pointer to an int8_t to store the bucket height
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
|
|
|
void tetris_view_getDimensions(int8_t *w,
|
|
|
|
int8_t *h);
|
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* sets the view mode (pause or running)
|
|
|
|
* @param pV pointer to the view whose mode should be set
|
|
|
|
* @param vm see definition of tetris_view_mode_t
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
2010-12-15 15:25:56 +00:00
|
|
|
inline static void tetris_view_setViewMode(tetris_view_t *const pV,
|
|
|
|
tetris_view_mode_t const vm)
|
|
|
|
{
|
|
|
|
pV->modeOld = pV->modeCurrent;
|
|
|
|
pV->modeCurrent = vm;
|
|
|
|
}
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* informs a view about changes in the game
|
|
|
|
* @param pV pointer to the view which should be updated
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
|
|
|
void tetris_view_update(tetris_view_t *pV);
|
|
|
|
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/**
|
|
|
|
* shows results after game
|
|
|
|
* @param pV pointer to the view which should show the results
|
2008-12-03 05:40:16 +00:00
|
|
|
*/
|
|
|
|
void tetris_view_showResults(tetris_view_t *pV);
|
|
|
|
|
|
|
|
|
|
|
|
#endif /*TETRIS_VIEW_H_*/
|
|
|
|
|
2010-04-01 03:11:59 +00:00
|
|
|
/*@}*/
|