Added closed state flag to bntextbox
This commit is contained in:
@ -13,6 +13,8 @@
|
||||
/** Amount of characters scrolled, per second */
|
||||
#define VN_TEXTBOX_SCROLL_SPEED 60
|
||||
|
||||
#define VN_BOX_STATE_CLOSED 0x01
|
||||
|
||||
typedef struct {
|
||||
/** Stores the maximum width that this textbox can take up */
|
||||
float widthMax;
|
||||
@ -20,6 +22,9 @@ typedef struct {
|
||||
/** Font that the text box uses */
|
||||
font_t *font;
|
||||
|
||||
/** Box State Flags */
|
||||
uint8_t state;
|
||||
|
||||
/** How many rows of text at most can be displayed in a single text box */
|
||||
int32_t linesMax;
|
||||
int32_t lineCurrent;
|
||||
|
@ -12,9 +12,9 @@ void vnTextBoxInit(vntextbox_t *box, font_t *font) {
|
||||
box->widthMax = 400;
|
||||
box->text = NULL;
|
||||
box->x = 0, box->y = 0;
|
||||
|
||||
box->linesMax = 3;
|
||||
box->lineCurrent = 0;
|
||||
box->state = 0;
|
||||
}
|
||||
|
||||
void vnTextBoxRebuffer(vntextbox_t *box) {
|
||||
@ -43,23 +43,35 @@ void vnTextBoxRebuffer(vntextbox_t *box) {
|
||||
|
||||
void vnTextBoxUpdate(vntextbox_t *box, engine_t *engine) {
|
||||
int32_t i;
|
||||
if(box->state & VN_BOX_STATE_CLOSED > 0) return;
|
||||
|
||||
// "Next text box"
|
||||
if(vnTextBoxHasScrolled(box) && box->linesMax > 0) {
|
||||
if(!inputIsPressed(&engine->input, INPUT_ACCEPT)) return;
|
||||
box->lineCurrent += box->linesMax;
|
||||
if(!vnTextBoxHasScrolled(box)) {
|
||||
i = inputIsDown(&engine->input, INPUT_ACCEPT) ? 2 : 1;
|
||||
box->textScroll += engine->time.delta * VN_TEXTBOX_SCROLL_SPEED * i;
|
||||
return;
|
||||
}
|
||||
|
||||
i = inputIsDown(&engine->input, INPUT_ACCEPT) ? 2 : 1;
|
||||
box->textScroll += engine->time.delta * VN_TEXTBOX_SCROLL_SPEED * i;
|
||||
// timelineUpdate(&box->animTimeline, engine->time.delta);
|
||||
if(!inputIsPressed(&engine->input, INPUT_ACCEPT)) return;
|
||||
|
||||
if(vnTextBoxCanBeClosed(box)) {
|
||||
// Box can be closed.
|
||||
printf("Box Closed");
|
||||
box->state |= VN_BOX_STATE_CLOSED;
|
||||
return;
|
||||
}
|
||||
|
||||
// In theory this is always false
|
||||
if(box->linesMax < 1) return;
|
||||
|
||||
// More lines to scroll
|
||||
box->lineCurrent += box->linesMax;
|
||||
}
|
||||
|
||||
void vnTextBoxRender(vntextbox_t *box, shader_t *shader) {
|
||||
int32_t charStart, charCount;
|
||||
float yOffset;
|
||||
if(box->text == NULL) return;
|
||||
if(box->text == NULL || box->state & VN_BOX_STATE_CLOSED > 0) return;
|
||||
|
||||
// Determine where we're rendering the indices up to.
|
||||
charCount = box->textScroll;
|
||||
@ -119,3 +131,9 @@ bool vnTextBoxHasScrolled(vntextbox_t *box) {
|
||||
|
||||
return currentChar > box->textInfo.realLength;
|
||||
}
|
||||
|
||||
bool vnTextBoxCanBeClosed(vntextbox_t *box) {
|
||||
if(!vnTextBoxHasScrolled(box)) return false;
|
||||
if(box->linesMax < 1) return true;
|
||||
return box->lineCurrent + box->linesMax >= box->textInfo.lineCount;
|
||||
}
|
@ -59,3 +59,14 @@ void vnTextBoxDispose(vntextbox_t *box);
|
||||
* @return True if the text box has finished scrolling.
|
||||
*/
|
||||
bool vnTextBoxHasScrolled(vntextbox_t *box);
|
||||
|
||||
/**
|
||||
* Returns true when the next key press will cause the text box to close. For
|
||||
* cases when there's a line limit this would imply a user has visited all the
|
||||
* lines, for all other cases this would be when the text has finished the
|
||||
* scrolling.
|
||||
*
|
||||
* @param box Box to check.
|
||||
* @return True if the next accept input will close the text box.
|
||||
*/
|
||||
bool vnTextBoxCanBeClosed(vntextbox_t *box);
|
Reference in New Issue
Block a user