Working on line clamping in vn text box
This commit is contained in:
@ -28,7 +28,8 @@ typedef struct {
|
||||
float x, y;
|
||||
|
||||
/** Animation of the textbox */
|
||||
timeline_t animTimeline;
|
||||
float textScroll;
|
||||
// timeline_t animTimeline;
|
||||
// timelineaction_t animActions;
|
||||
|
||||
/** Information about the current rendered text */
|
||||
|
@ -163,4 +163,17 @@ void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
|
||||
info->width = mathMax(info->width, quad->x1);
|
||||
info->height = mathMax(info->height, quad->y1);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t fontGetLineCharCount(fonttextinfo_t *info,int32_t start,int32_t count) {
|
||||
int32_t charCount, i, m;
|
||||
|
||||
m = mathMin(start+count, info->lineCount);
|
||||
|
||||
charCount = 0;
|
||||
for(i = start; i < m; i++) {
|
||||
charCount += info->lines[i].length;
|
||||
}
|
||||
|
||||
return charCount;
|
||||
}
|
@ -56,4 +56,15 @@ void fontTextInit(font_t *font, primitive_t *primitive, fonttextinfo_t *info);
|
||||
*/
|
||||
void fontTextClamp(font_t *font, fonttextinfo_t *info, char *text,
|
||||
float maxWidth
|
||||
);
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the number of real characters on the lines specified. Useful when
|
||||
* attempting to clamp to a set of lines.
|
||||
*
|
||||
* @param info Info to get the character counts from.
|
||||
* @param start Starting line index.
|
||||
* @param count Count of lines, this method will clamp to info's line length.
|
||||
* @returns The count of characters in those lines summed.
|
||||
*/
|
||||
int32_t fontGetLineCharCount(fonttextinfo_t *info, int32_t start,int32_t count);
|
@ -13,7 +13,7 @@ void vnTextBoxInit(vntextbox_t *box, font_t *font) {
|
||||
box->text = NULL;
|
||||
box->x = 0, box->y = 0;
|
||||
|
||||
box->linesMax = 1;
|
||||
box->linesMax = 3;
|
||||
box->lineCurrent = 0;
|
||||
}
|
||||
|
||||
@ -42,49 +42,43 @@ void vnTextBoxRebuffer(vntextbox_t *box) {
|
||||
}
|
||||
|
||||
void vnTextBoxUpdate(vntextbox_t *box, engine_t *engine) {
|
||||
int32_t i;
|
||||
|
||||
if(vnTextBoxHasScrolled(box)) {
|
||||
printf(".");
|
||||
if(!inputIsPressed(&engine->input, INPUT_ACCEPT)) return;
|
||||
|
||||
// "Next text box"
|
||||
printf("Next");
|
||||
box->lineCurrent++;
|
||||
i = 1;
|
||||
box->lineCurrent += i;
|
||||
return;
|
||||
}
|
||||
|
||||
bool speedup = inputIsDown(&engine->input, INPUT_ACCEPT);
|
||||
timelineUpdate(&box->animTimeline, engine->time.delta * (speedup ? 1 : 2));
|
||||
i = inputIsDown(&engine->input, INPUT_ACCEPT) ? 2 : 1;
|
||||
box->textScroll += engine->time.delta * VN_TEXTBOX_SCROLL_SPEED * i;
|
||||
// timelineUpdate(&box->animTimeline, engine->time.delta);
|
||||
}
|
||||
|
||||
void vnTextBoxRender(vntextbox_t *box, shader_t *shader) {
|
||||
int32_t charStart, charCount, i;
|
||||
int32_t charStart, charCount;
|
||||
float yOffset;
|
||||
if(box->text == NULL) return;
|
||||
|
||||
// Determine where we're rendering the indices up to.
|
||||
charCount = box->animTimeline.current * VN_TEXTBOX_SCROLL_SPEED;
|
||||
// charCount = box->animTimeline.current * VN_TEXTBOX_SCROLL_SPEED;
|
||||
charCount = box->textScroll;
|
||||
if(charCount == 0) return;
|
||||
|
||||
// Clamp to lines if necessary.
|
||||
if(box->linesMax > 0) {
|
||||
if(box->lineCurrent >= box->textInfo.lineCount) return;
|
||||
|
||||
// From lineCurrent to lineCurrent+lineMax (or max lines in text).
|
||||
i = box->lineCurrent;
|
||||
charStart = 0;// Misusing variable for now.
|
||||
while(i < mathMin(box->lineCurrent+box->linesMax, box->textInfo.lineCount)){
|
||||
charStart += box->textInfo.lines[i].length;// Sum char counts for lines.
|
||||
i++;
|
||||
}
|
||||
i = box->textInfo.lines[box->lineCurrent].start;//i=the starting indice now
|
||||
|
||||
if(charCount >= charStart) {
|
||||
int32_t brhva;
|
||||
brhva = 32;
|
||||
}
|
||||
|
||||
// Select either the scroll position or the total chars for the lowest.
|
||||
charCount = mathMin(charCount - i, charStart);
|
||||
charStart = box->lineCurrent;
|
||||
charStart = box->textInfo.lines[box->lineCurrent].start;
|
||||
charCount -= charStart;
|
||||
yOffset = FONT_LINE_HEIGHT * box->lineCurrent;
|
||||
} else {
|
||||
charStart = 0;
|
||||
yOffset = 0;
|
||||
}
|
||||
|
||||
// Convert characters into indices, don't render if we can't
|
||||
@ -99,7 +93,7 @@ void vnTextBoxRender(vntextbox_t *box, shader_t *shader) {
|
||||
if(charCount < 1) return;
|
||||
|
||||
// Render the debug box.
|
||||
shaderUsePosition(shader, box->x,box->y,0, 0,0,0);
|
||||
shaderUsePosition(shader, box->x,box->y - yOffset,0, 0,0,0);
|
||||
shaderUseTexture(shader, &box->testTexture);
|
||||
primitiveDraw(&box->testPrimitive, 0, -1);
|
||||
|
||||
@ -116,9 +110,17 @@ void vnTextBoxDispose(vntextbox_t *box) {
|
||||
}
|
||||
|
||||
bool vnTextBoxHasScrolled(vntextbox_t *box) {
|
||||
if(box->text == NULL) return true;
|
||||
int32_t currentChar;
|
||||
currentChar = box->textScroll;
|
||||
|
||||
return (box->animTimeline.current * (
|
||||
VN_TEXTBOX_SCROLL_SPEED * QUAD_INDICE_COUNT
|
||||
)) >= box->primitive.indiceCount;
|
||||
// Are we clamping lines?
|
||||
if(box->linesMax > 0) {
|
||||
return (
|
||||
currentChar - box->textInfo.lines[box->lineCurrent].start// "Line" space
|
||||
) >= fontGetLineCharCount(
|
||||
&box->textInfo, box->lineCurrent, box->linesMax
|
||||
);
|
||||
}
|
||||
|
||||
return currentChar > box->textInfo.realLength;
|
||||
}
|
Reference in New Issue
Block a user