Still working on my scrolling text and bug fixing.
This commit is contained in:
63
temp/talk.c
Normal file
63
temp/talk.c
Normal file
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "talk.h"
|
||||
|
||||
void pokerTalkInit(poker_t *poker) {
|
||||
poker->talkText = NULL;
|
||||
poker->talkTextInfo = NULL;
|
||||
poker->textLastWidth = 0;
|
||||
}
|
||||
|
||||
void pokerTalkDispose(poker_t *poker) {
|
||||
if(poker->talkTextInfo == NULL) return;
|
||||
fontTextInfoDispose(poker->talkTextInfo);
|
||||
primitiveDispose(&poker->talkPrimitive);
|
||||
}
|
||||
|
||||
void pokerTalkTextRebuffer(poker_t *poker) {
|
||||
// Check if we need to force a redraw or not.
|
||||
if(poker->talkText == NULL || poker->textLastWidth != poker->guiWidth) {
|
||||
if(poker->talkTextInfo != NULL) {
|
||||
fontTextInfoDispose(poker->talkTextInfo);
|
||||
primitiveDispose(&poker->talkPrimitive);
|
||||
poker->talkTextInfo = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(poker->talkText == NULL) return;
|
||||
|
||||
// Rebuffer
|
||||
poker->talkTextInfo = fontTextClamp(&poker->font, poker->talkText, poker->guiWidth);
|
||||
fontTextInit(&poker->font, &poker->talkPrimitive, poker->talkTextInfo);
|
||||
}
|
||||
|
||||
void pokerTalkRender(poker_t *poker, input_t *input) {
|
||||
pokerTalkTextRebuffer(poker);
|
||||
if(poker->talkTextInfo == NULL) return;
|
||||
|
||||
// Render text
|
||||
shaderUsePosition(&poker->shader,
|
||||
0,POKER_GUI_HEIGHT-poker->talkTextInfo->height,0,
|
||||
0,0,0
|
||||
);
|
||||
shaderUseTexture(&poker->shader, &poker->font.texture);
|
||||
primitiveDraw(&poker->talkPrimitive, 0, -1);
|
||||
|
||||
if(inputIsPressed(input, INPUT_ACCEPT)) {
|
||||
poker->talkText = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void pokerTalk(poker_t *poker, char *text) {
|
||||
poker->talkText = text;
|
||||
poker->roundTextCounter++;
|
||||
}
|
||||
|
||||
bool pokerTalkIsTalking(poker_t *poker) {
|
||||
return poker->talkText != NULL || poker->talkTextInfo != NULL;
|
||||
}
|
Reference in New Issue
Block a user