Example #1
0
//--------------------------------------------------------------
void testApp::update(){

    //update slider
    sli->sliderValue=max(0.0f, min((float)beat/(float)myData->dialog.size(),1.0f));

    //Add linebreaks to the input text
    //tooltips are updated from inputText, so the linebreaks auto-transfer
    //also reset drawing animation when editing text
    if(input->focusButton==drohneOne){
        textOneChar=0;
        input->inputText=linebreak(input->inputText, &drohneOneFont);
    }
    if(input->focusButton==drohneTwo){
        textTwoChar=0;
        input->inputText=linebreak(input->inputText, &drohneTwoFont);
    }



    // TEXT ANIMATION
    //do not update DrohneText, if we are editing it right now!
    if (bShowTextOne && input->focusButton!=drohneOne){
        textOneChar+=renderer->deltaTime*textSpeedOne*0.01;
        textOneChar=min(textOneChar,float(drohneOne->tooltip.size()));
        drohneOneText=drohneOne->tooltip.substr(0,int(textOneChar));
    }
    if (bShowTextTwo && input->focusButton!=drohneTwo){
        textTwoChar+=renderer->deltaTime*textSpeedTwo*0.01;
        textTwoChar=min(textTwoChar,float(drohneTwo->tooltip.size()));
        drohneTwoText=drohneTwo->tooltip.substr(0,int(textTwoChar));
    }

    renderer->update();

}
Example #2
0
/* The output function for an ELF hash table. The hash table is an
 * array of 32-bit values. The first two array elements indicate the
 * length of the following subsections. Line breaks are inserted to
 * indicate where the subsections start and end.
 */
static void outhashtable(void const *ptr, long size, int ndx)
{
    Elf64_Word const *entries = ptr;
    long count = size / sizeof *entries;
    long i;

    (void)ndx;
    beginblock(TRUE);
    if (count <= 2 || (long)(entries[0] + entries[1] + 2) != count) {
	for (i = 0 ; i < count ; ++i)
	    outdec(entries[i]);
    } else {
	outdec(entries[0]);
	outdec(entries[1]);
	linebreak();
	i = 2;
	if (entries[0] > 0) {
	    for ( ; i < (long)(2 + entries[0]) ; ++i)
		outdec(entries[i]);
	    linebreak();
	}
	for ( ; i < count ; ++i)
	    outdec(entries[i]);
    }
    endblock();
}
Example #3
0
void testApp::setTextFromBeat(int b, bool bPlayVoice){

    if (b>=myData->dialog.size() || b<0 ){
        cout << "reached end of dialogue: " << myData->dialog.size() << endl;
        drohneOne->tooltip="";
        drohneTwo->tooltip="";
        return;
    }

    if (myData->dialog[b].whoIs==1){
        drohneOne->tooltip=linebreak(myData->dialog[b].dialogText, &drohneOneFont);
        bShowTextOne=true;
        bShowTextTwo=false;
        bShowImageOne=parseForImage(&drohneOneImage,drohneOne->tooltip);
        bShowImageTwo=false;
        textOneChar=0;
        if (bPlayVoice && myData->dialog[b].dialogVoice.isLoaded())
            myData->dialog[b].dialogVoice.play();
    }
    if (myData->dialog[b].whoIs==2){
        drohneTwo->tooltip=linebreak(myData->dialog[b].dialogText, &drohneTwoFont);
        bShowTextTwo=true;
        bShowTextOne=false;
        bShowImageTwo=parseForImage(&drohneTwoImage,drohneTwo->tooltip);
        bShowImageOne=false;
        textTwoChar=0;
        if (bPlayVoice && myData->dialog[b].dialogVoice.isLoaded())
            myData->dialog[b].dialogVoice.play();
    }

}
Example #4
0
 void showMsg(std::wstring msg, sf::Color foreground) {
     if ( (msg.size() * style.fontsize ) > width ) {
         msg = linebreak(msg, int(width / style.tilesize));
     }
     textbox->setString(msg);
     textbox->setColor(foreground);
 }
Example #5
0
QC_INTERNAL void commit_token(QC_Tokenize_Ctx *t, const char *b, const char *e, QC_Token_Type type)
{
	if (e >= b) {
		QC_Token tok = {0};
		QC_Bool last_on_line = e + 1 < t->end && linebreak(*e);
		if (type == QC_Token_name) {
			QC_Token_Type kw = kw_tokentype(b, e - b);
			if (kw != QC_Token_unknown)
				type = kw;
		}
		tok.type = type;
		tok.text.buf = b;
		tok.text.len = e - b;
		tok.line = t->cur_line;
		tok.empty_line_before = (t->tokens_on_line == 0 && t->last_line_was_empty);
		tok.last_on_line = last_on_line;

		if (qc_is_comment_tok(type)) {
			if (t->tokens_on_line  == t->comments_on_line)
				tok.comment_bound_to = 1; /* If line is only comments, bound to next token */
			else
				tok.comment_bound_to = -1; /* Else bound to token left to comment */
			++t->comments_on_line;
		}

		qc_push_array(QC_Token)(&t->tokens, tok);
		t->state = Tok_State_none;
		++t->tokens_on_line;
	}
}
Example #6
0
/* The GNU hash table is an array of 32-bit values. (Although in a
 * 64-bit ELF file the mask subpart consists of 64-bit values. But an
 * array cannot change its type midway through, so in this case the
 * mask values are split across two array entries.)
 */
static void outgnuhash(void const *ptr, long size, int ndx)
{
    Elf64_Word const *entries = ptr;
    long count = size / sizeof *entries;
    int buckets, masks;
    int i, n;

    (void)ndx;
    if (count < 4) {
	outwords(ptr, size, ndx);
	return;
    }
    buckets = entries[0];
    masks = entries[2];
    if (iself64())
	masks *= 2;
    if (4 + masks + buckets > count) {
	outwords(ptr, size, ndx);
	return;
    }

    beginblock(TRUE);
    for (i = 0 ; i < 4 ; ++i)
	outdec(entries[i]);
    n = i;
    if (masks) {
	linebreak();
	for (i = 0 ; i < masks ; ++i)
	    outf("0x%08lX", entries[n + i]);
	n += i;
    }
    if (buckets) {
	linebreak();
	for (i = 0 ; i < buckets ; ++i)
	    outdec(entries[n + i]);
	n += i;
    }
    if (n < count) {
	linebreak();
	for (i = n ; i < count ; ++i)
	    outf("0x%08lX", entries[i]);
    }
    endblock();
}
void LineParserWrite(LineParserRef const p, byte_t const *const buf, size_t const len) {
	if(!p) return;
	if(p->discard) {
		size_t const discard = linebreak(buf, len);
		size_t const remainder = len - discard;
		if(!remainder) return;
		p->discard = false;
		return LineParserWrite(p, buf + discard, remainder);
	}
	if(p->pos) {
		size_t const extra = linebreak(buf, len);
		size_t const max = LINE_MAX - p->pos;
		if(extra > max) {
			if(extra >= len) {
				p->discard = true;
				return;
			}
			return LineParserWrite(p, buf + extra, len - extra);
		}
		memcpy(p->fixed + p->pos, buf, extra);
		p->pos += extra;
		if(extra >= len) return;
		p->cb(p->context, p->fixed, p->pos);
		p->pos = 0;
		return LineParserWrite(p, buf + extra, len - extra);
	}
	off_t pos = 0;
	for(;;) {
		size_t const line = linebreak(buf + pos, len - pos);
		if(pos + line >= len) {
			if(line > LINE_MAX) {
				p->discard = true;
				return;
			}
			memcpy(p->fixed, buf + p->pos, line);
			p->pos = line;
			return;
		}
		p->cb(p->context, buf + pos, line);
	}
}
Example #8
0
int SkTextLineBreaker::CountLines(const char text[], size_t len, const SkPaint& paint, SkScalar width)
{
    const char* stop = text + len;
    int         count = 0;

    if (width > 0)
    {
        do {
            count += 1;
            text += linebreak(text, stop, paint, width);
        } while (text < stop);
    }
    return count;
}
Example #9
0
/* The output function for note sections. The format of a note section
 * varies with the type of note, the only constant part being that it
 * starts with an Elf*_Nhdr struct, and is usually followed by a
 * string. However, each subpart is guaranteed to be a multiple of 4
 * bytes, so notes are displayed as arrays of 32-bit values. Line
 * breaks are inserted to indicate the beginning of a note header.
 * Note sections in core files are rather different, so in that case a
 * completely different function is called instead.
 */
void outnote(void const *ptr, long size, int ndx)
{
    Elf64_Word const *words = ptr;
    long count = size / sizeof *words;
    long i;
    int namesize, descsize, tag;

    (void)ndx;
    if (iscorefile()) {
	iself64() ? outnote64(ptr, size, ndx)
		  : outnote32(ptr, size, ndx);
	return;
    }

    beginblock(TRUE);
    i = 0;
    while (i < count) {
	namesize = (words[i] + 3) / 4;
	descsize = (words[i + 1] + 3) / 4;
	linebreak();
	outdec(words[i++]);
	outdec(words[i++]);
	tag = words[i++];
	outdefint(tag, "NT_GNU_");
	while (namesize-- && i < count)
	    outhex(words[i++]);
	if (descsize == 0)
	    continue;
#ifdef NT_GNU_ABI_TAG
	if (tag == NT_GNU_ABI_TAG) {
	    outdefint(words[i++], "ELF_NOTE_OS_");
	    --descsize;
	}
#endif
	while (descsize-- && i < count)
	    outhex(words[i++]);
    }
    endblock();
}
Example #10
0
SkScalar SkTextBox::getTextWidth() const {
    SkScalar marginWidth = fBox.width();

    if (marginWidth <= 0 || fLen == 0)
        return SkIntToScalar(0);

    const char* textStop = fText + fLen;

    size_t len = 0, totalLen = 0;
    SkScalar maxWidth = SkIntToScalar(0);

    for (;;)
    {
        size_t trailing;
        len = linebreak(fText + totalLen, textStop, *fPaint, marginWidth, &trailing);
        maxWidth = SkMaxScalar(maxWidth, fPaint->measureText(fText + totalLen, len));
        totalLen += len;
        if (fText + totalLen>= textStop)
            break;
    }

    return maxWidth;
}
Example #11
0
SkScalar SkTextBox::visit(Visitor& visitor, const char text[], size_t len,
                          const SkPaint& paint) const {
    SkScalar marginWidth = fBox.width();

    if (marginWidth <= 0 || len == 0) {
        return fBox.top();
    }

    const char* textStop = text + len;

    SkScalar                x, y, scaledSpacing, height, fontHeight;
    SkPaint::FontMetrics    metrics;

    switch (paint.getTextAlign()) {
    case SkPaint::kLeft_Align:
        x = 0;
        break;
    case SkPaint::kCenter_Align:
        x = SkScalarHalf(marginWidth);
        break;
    default:
        x = marginWidth;
        break;
    }
    x += fBox.fLeft;

    fontHeight = paint.getFontMetrics(&metrics);
    scaledSpacing = SkScalarMul(fontHeight, fSpacingMul) + fSpacingAdd;
    height = fBox.height();

    //  compute Y position for first line
    {
        SkScalar textHeight = fontHeight;

        if (fMode == kLineBreak_Mode && fSpacingAlign != kStart_SpacingAlign) {
            int count = SkTextLineBreaker::CountLines(text, textStop - text, paint, marginWidth);
            SkASSERT(count > 0);
            textHeight += scaledSpacing * (count - 1);
        }

        switch (fSpacingAlign) {
        case kStart_SpacingAlign:
            y = 0;
            break;
        case kCenter_SpacingAlign:
            y = SkScalarHalf(height - textHeight);
            break;
        default:
            SkASSERT(fSpacingAlign == kEnd_SpacingAlign);
            y = height - textHeight;
            break;
        }
        y += fBox.fTop - metrics.fAscent;
    }

    for (;;) {
        size_t trailing;
        len = linebreak(text, textStop, paint, marginWidth, &trailing);
        if (y + metrics.fDescent + metrics.fLeading > 0) {
            visitor(text, len - trailing, x, y, paint);
        }
        text += len;
        if (text >= textStop) {
            break;
        }
        y += scaledSpacing;
        if (y + metrics.fAscent >= fBox.fBottom) {
            break;
        }
    }
    return y + metrics.fDescent + metrics.fLeading;
}
void SkTextBox::draw(SkCanvas* canvas, const char text[], size_t len, const SkPaint& paint)
{
    SkASSERT(canvas && &paint && (text || len == 0));

    SkScalar marginWidth = fBox.width();

    if (marginWidth <= 0 || len == 0)
        return;

    const char* textStop = text + len;

    SkScalar                x, y, scaledSpacing, height, fontHeight;
    SkPaint::FontMetrics    metrics;

    switch (paint.getTextAlign()) {
    case SkPaint::kLeft_Align:
        x = 0;
        break;
    case SkPaint::kCenter_Align:
        x = SkScalarHalf(marginWidth);
        break;
    default:
        x = marginWidth;
        break;
    }
    x += fBox.fLeft;

    fontHeight = paint.getFontMetrics(&metrics);
    scaledSpacing = SkScalarMul(fontHeight, fSpacingMul) + fSpacingAdd;
    height = fBox.height();

    //  compute Y position for first line
    {
        SkScalar textHeight = fontHeight;

        if (fMode == kLineBreak_Mode && fSpacingAlign != kStart_SpacingAlign)
        {
            int count = SkTextLineBreaker::CountLines(text, textStop - text, paint, marginWidth);
            SkASSERT(count > 0);
            textHeight += scaledSpacing * (count - 1);
        }

        switch (fSpacingAlign) {
        case kStart_SpacingAlign:
            y = 0;
            break;
        case kCenter_SpacingAlign:
            y = SkScalarHalf(height - textHeight);
            break;
        default:
            SkASSERT(fSpacingAlign == kEnd_SpacingAlign);
            y = height - textHeight;
            break;
        }
        y += fBox.fTop - metrics.fAscent;
    }

    for (;;)
    {
        len = linebreak(text, textStop, paint, marginWidth);
        if (y + metrics.fDescent + metrics.fLeading > 0)
            canvas->drawText(text, len, x, y, paint);
        text += len;
        if (text >= textStop)
            break;
        y += scaledSpacing;
        if (y + metrics.fAscent >= height)
            break;
    } 
}
Example #13
0
void testApp::drawPreview(){

    ofPushMatrix();
        ofTranslate(xOffset,yOffset);

        //window dressing
        ofScale(0.3,0.3);
        ofSetColor(40,40,40);
        ofRect(0,0,1280,800);

        ofSetColor(255,255,255);
        ofRect(635,0,10,800);

        //PREVIEW
        ofSetColor(240,240,180);

        int i=0;
        float yPO=SCREENRESY+drohneOneFont.stringHeight("A") + 100;
        while(beat+i<myData->dialog.size()){

            stringstream ss;
            ss << beat+i;

            if (myData->dialog[beat+i].whoIs==1){
                string previewText=linebreak(myData->dialog[beat+i].dialogText,&drohneOneFont);
                ofSetColor(255,100,100);
                drohneOneFont.drawString(ss.str()+".)",-drohneOneFont.stringWidth(ss.str()+".)"),yPO);
                ofSetColor(200,200,180);
                drohneOneFont.drawString(previewText,5,yPO);
                yPO += drohneOneFont.stringHeight(previewText)+drohneOneFont.stringHeight("A");
            }else{
                string previewText=linebreak(myData->dialog[beat+i].dialogText,&drohneTwoFont);
                ofSetColor(255,100,100);
                drohneTwoFont.drawString(ss.str()+".)",645-drohneTwoFont.stringWidth(ss.str()+".)"),yPO);
                ofSetColor(200,200,180);
                drohneTwoFont.drawString(previewText,650,yPO);
                yPO += drohneTwoFont.stringHeight(previewText)+drohneTwoFont.stringHeight("A");
            }

            i++;
        }

        //END PREVIEW

        ofSetColor(255,255,100);
        stringstream ss;
        ss << beat-1;
        drohneOneFont.drawString(ss.str()+".)",-10-drohneOneFont.stringWidth(ss.str()+".)"),drohneOneFont.stringHeight("A")+10);

        ofSetColor(255,255,255);
        //proper text animation
        // only show pictures after text os finished displaying...
        if (bShowTextOne)
            drohneOneFont.drawString(drohneOneText,5,drohneOneFont.stringHeight("A")+10);

        if (bShowImageOne && textOneChar==drohneOne->tooltip.size())
            drohneOneImage.draw(5,drohneOneFont.stringHeight(drohneOneText)+10);



        // only show pictures after text os finished displaying...
        if (bShowTextTwo)
            drohneTwoFont.drawString(drohneTwoText,650,drohneTwoFont.stringHeight("A")+10);

        if (bShowImageTwo&& textTwoChar==drohneTwo->tooltip.size())
            drohneTwoImage.draw(655,drohneTwoFont.stringHeight(drohneTwoText)+10);

    ofPopMatrix();

}
Example #14
0
QC_Array(QC_Token) qc_tokenize(const char* src, int src_size)
{
	const char *cur;
	const char *tok_begin;
	QC_Tokenize_Ctx t = {0};
	
	cur = src;
	tok_begin = src;
	t.end = src + src_size;
	t.cur_line = 1;
	t.tokens = qc_create_array(QC_Token)(src_size/4); /* Estimate token count */

	while (cur <= t.end && tok_begin < t.end) {
		char ch = cur < t.end ? *cur : '\n';
		switch (t.state) {
			case Tok_State_none:
				if (single_char_tokentype(ch) != QC_Token_unknown) {
					t.state = Tok_State_maybe_single_char;
				} else if (ch >= '0' && ch <= '9') {
					t.state = Tok_State_number;
				} else if (	(ch >= 'a' && ch <= 'z') ||
							(ch >= 'A' && ch <= 'Z') ||
							(ch == '_')) {
					t.state = Tok_State_name;
				} else if (ch == '\"' || ch == '@') { /* @todo Remove temp hack of @ */
					t.string_begin_char = ch;
					t.state = Tok_State_str;
				} else if (linebreak(ch)) {
					on_linebreak(&t);
				}
				tok_begin = cur;
			break;
			case Tok_State_maybe_single_char: {
				QC_Token_Type type = double_char_tokentype(*tok_begin, ch);
				if (type == QC_Token_unknown) {
					commit_token(&t, tok_begin, cur, single_char_tokentype(*tok_begin));
					--cur;
				} else {
					if (type == QC_Token_line_comment) {
						t.state = Tok_State_line_comment;
						tok_begin += 2;
					} else if (type == QC_Token_block_comment) {
						t.state = Tok_State_block_comment;
						t.block_comment_depth = 1;
						tok_begin += 2;
					} else {
						commit_token(&t, tok_begin, cur + 1, type);
					}
				}
			}
			break;
			case Tok_State_number_after_dot:
			case Tok_State_number:
				if ((ch < '0' || ch > '9') && ch != '.') {
					QC_Token_Type type = QC_Token_int;
					if (t.state == Tok_State_number_after_dot)
						type = QC_Token_float;

					commit_token(&t, tok_begin, cur, type);
					--cur;
					break;
				}

				if (ch == '.')
					t.state = Tok_State_number_after_dot;
				else if (t.state != Tok_State_number_after_dot)
					t.state = Tok_State_number;
			break;
			case Tok_State_name:
				if (	whitespace(ch) ||
						single_char_tokentype(ch) != QC_Token_unknown) {
					commit_token(&t, tok_begin, cur, QC_Token_name);
					--cur;
				}
			break;
			case Tok_State_str:
				if (ch == t.string_begin_char)
					commit_token(&t, tok_begin + 1, cur, QC_Token_string);
			break;
			case Tok_State_line_comment:
				if (linebreak(ch)) {
					commit_token(&t, tok_begin, cur, QC_Token_line_comment);
					on_linebreak(&t);
				}
			case Tok_State_block_comment: {
				char a = *(cur - 1);
				char b = *(cur);
				if (double_char_tokentype(a, b) == QC_Token_block_comment) {
					++t.block_comment_depth;
				} else if (a == '*' && b == '/') {
					--t.block_comment_depth;
					if (t.block_comment_depth <= 0)
						commit_token(&t, tok_begin, cur - 1, QC_Token_block_comment);
				}
			} break;
			default:;
		}
		++cur;
	}

	{ /* Append eof */
		QC_Token eof = {0};
		eof.text.buf = "eof";
		eof.text.len = strlen(eof.text.buf);
		eof.line = t.cur_line;
		eof.last_on_line = QC_true;
		qc_push_array(QC_Token)(&t.tokens, eof);
	}
	return t.tokens;
}