diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-06-28 16:38:35 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-06-28 16:38:35 +0000 |
| commit | 2d776fcd61be168e1ff0ff2e4a5e71835e7cea19 (patch) | |
| tree | 7cf274897bf540d5332d446f583ffd066e4e2e1d /src/client/term.c | |
| parent | b877ae23ac5d380ab3aa48d7724045cf4883b186 (diff) | |
- prekopanie adresarovej struktury, prva cast
git-svn-id: http://opensvn.csie.org/tuxanci_ng@77 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/client/term.c')
| -rw-r--r-- | src/client/term.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/client/term.c b/src/client/term.c new file mode 100644 index 0000000..3357f0b --- /dev/null +++ b/src/client/term.c @@ -0,0 +1,106 @@ + +#include <stdlib.h> +#include <assert.h> + +#include "base/main.h" +#include "base/list.h" +#include "base/myTimer.h" + +#include "client/interface.h" +#include "client/term.h" +#include "client/font.h" + +typedef struct struct_term_t +{ + char *text; + my_time_t delTime; +} term_t; + +static list_t *listText; + +static term_t* newTermItem(char *s) +{ + term_t *new; + char *line; + int len; + + assert( s != NULL ); + + line = strdup(s); + len = strlen(line); + line[len-1] = '\0'; + + new = malloc( sizeof(term_t) ); + memset(new, 0, sizeof(term_t)); + + new->text = line; + new->delTime = getMyTime() + TERM_DEL_TEXT_TIMEOUT; + + return new; +} + +static void destroyTermItem(term_t *p) +{ + assert( p != NULL ); + + free(p->text); + free(p); +} + +void initTerm() +{ + listText = newList(); +} + +void drawTerm() +{ + int i; + + for( i = 0 ; i < listText->count ; i++ ) + { + char *line; + + line = (char *)( (term_t *)listText->list[i] )->text; + drawFont(line, 10, 10 + i*20, COLOR_WHITE); + } +} + +void eventTerm() +{ + my_time_t currentTime; + int i; + + currentTime = getMyTime(); + + + for( i = 0 ; i < listText->count ; i++ ) + { + my_time_t thisTime; + + thisTime = ( (term_t *)listText->list[i] )->delTime; + + if( currentTime > thisTime ) + { + delListItem(listText, i, destroyTermItem); + i--; + } + } + +} + +void appendTextInTerm(char *s) +{ + + addList(listText, newTermItem(s) ); + + if( listText->count > TERM_MAX_LINES ) + { + delListItem(listText, 0, destroyTermItem); + } +} + +void quitTerm() +{ + assert( listText != NULL ); + destroyListItem(listText, destroyTermItem); +} |