Example #1
0
void Scene_Battle_Rpg2k3::DrawFloatText(int x, int y, int color, const std::string& text, int _duration) {
	Rect rect = Font::Default()->GetSize(text);

	BitmapRef graphic = Bitmap::Create(rect.width, rect.height);
	graphic->Clear();
	graphic->TextDraw(-rect.x, -rect.y, color, text);

	Sprite* floating_text = new Sprite();
	floating_text->SetBitmap(graphic);
	floating_text->SetOx(rect.width / 2);
	floating_text->SetOy(rect.height + 5);
	floating_text->SetX(x);
	floating_text->SetY(y);
	floating_text->SetZ(500 + y);

	FloatText float_text = FloatText(EASYRPG_SHARED_PTR<Sprite>(floating_text), _duration);

	floating_texts.push_back(float_text);
}
Example #2
0
bool parseStream(const char *stream, unsigned long streamLen) {
    //std::cout << "parseStream of length " << streamLen << std::endl;
    setlocale(LC_ALL, "C");
    QStack<FloatText> stack;
    QVector<double> lastArray;
    unsigned long previousPosition = 0;
    unsigned long tokenPosition = 0;
    bool inArray = false;
    FloatText x1, y1, x2, y2, x3, y3;
    double capStyle, offset, joinStyle;
    QList<GraphicContext> contexts;
    GraphicContext currentContext;
    currentContext.brush.setStyle(Qt::SolidPattern);
    currentContext.brush.setColor(Qt::black);
    currentContext.pen.setStyle(Qt::SolidLine);
    currentContext.pen.setColor(Qt::black);
    QString currentPath;
    FloatText cur_x, cur_y;
    do {
        // Special case : array handling
        if (stream[tokenPosition] == '[') {
            inArray = true;
            tokenPosition++;
            previousPosition = tokenPosition;
            continue;
        }
        if ((stream[tokenPosition] != ' ') && (stream[tokenPosition] != '\n') && (stream[tokenPosition] != '\0') && (stream[tokenPosition] != '\t') && (stream[tokenPosition] != ']')) {
            tokenPosition++;
            continue;
        }
        if (previousPosition != tokenPosition) {
            switch (stream[previousPosition]) {
            case 'l':
                y1 = stack.pop();
                x1 = stack.pop();
                //currentPath.lineTo(x1, y1);
                std::cout << " L " << x1 << ',' << y1;
                cur_x = x1;
                cur_y = y1;
                break;
            case 'v':
                y3 = stack.pop();
                x3 = stack.pop();
                y2 = stack.pop();
                x2 = stack.pop();
                //currentPath.quadTo(x2, y2, x3, y3); WRONG, it's not a quad but a cubic command !
                std::cout << " C " << cur_x << ',' << cur_y << ' ' << x2 << ',' << y2 << ' ' << x3 << ',' << y3;
                cur_x = x3;
                cur_y = y3;
                break;
            case 'y':
                y3 = stack.pop();
                x3 = stack.pop();
                y2 = stack.pop();
                x2 = stack.pop();
                std::cout << " C " << x2 << ',' << y2 << ' ' << x3 << ',' << y3 << ' ' << x3 << ',' << y3;
                cur_x = x3;
                cur_y = y3;
                break;
            case 'm':
                y1 = stack.pop();
                x1 = stack.pop();
                //currentPath.moveTo(x1, y1);
                std::cout << " M " << x1 << ',' << y1;
                cur_x = x1;
                cur_y = y1;
                break;
            case 'h':
                //currentPath.closeSubpath();
                std::cout << " Z";
                break;
            case 'W':
                //if (currentContext.clipPath.length() == 0)
                //    currentContext.clipPath = currentPath.toPainterPath();
                //if (stream[previousPosition+1] == '*') {
                //    currentContext.clipPath.setFillRule(Qt::OddEvenFill);
                //    currentPath.setFillRule(Qt::OddEvenFill);
                //} else {
                //    currentContext.clipPath.setFillRule(Qt::WindingFill);
                //    currentPath.setFillRule(Qt::WindingFill);
                //}
                //currentContext.clipPath = currentContext.clipPath.intersected(currentPath.toPainterPath());
                break;
            case 'n':
                //currentPath = VectorPath();
                std::cout << std::endl << "" << std::endl;
                break;
            case 'q':
                contexts.append(currentContext);
                break;
            case 'Q':
                currentContext = contexts.takeLast();
                break;
            case 'S':
                //emit strikePath(currentPath, currentContext);
                //currentPath = VectorPath();
                std::cout << std::endl << "fill:none;stroke:" << currentContext.pen.color().name().toStdString();
                std::cout << ";stroke-opacity:1";
                if (currentContext.pen.style() == Qt::SolidLine) {
                    std::cout << ";stroke-dasharray:none";
                }
                std::cout << ";stroke-width:" << currentContext.pen.widthF();
                std::cout << std::endl;
                break;
            case 'w':
                currentContext.pen.setWidthF(stack.pop().value());
                break;
            case 'R':
                if (stream[previousPosition+1] == 'G') {
                    double b = stack.pop().value();
                    double g = stack.pop().value();
                    double r = stack.pop().value();
                    currentContext.pen.setColor(QColor(r*255, g*255, b*255));
                }
                break;
            case 'J':
                capStyle = stack.pop().value();
                if (capStyle == 0)
                    currentContext.pen.setCapStyle(Qt::FlatCap);
                else if (capStyle == 1)
                    currentContext.pen.setCapStyle(Qt::RoundCap);
                else
                    currentContext.pen.setCapStyle(Qt::SquareCap);
                break;
            case 'M':
                currentContext.pen.setMiterLimit(stack.pop().value());
                break;
            case 'f':
                std::cout << std::endl << "fill:" << currentContext.brush.color().name().toStdString();
                std::cout << ";stroke:none";
                if (stream[previousPosition+1] == '*')
                    //emit fillPath(currentPath, currentContext, Qt::OddEvenFill);
                    std::cout << ";fill-rule:evenodd";
                else
                    //emit fillPath(currentPath, currentContext, Qt::WindingFill);
                    std::cout << ";fill-rule:nonzero";
                //currentPath = VectorPath();
                std::cout << std::endl;
                break;
            case 'd':
                offset = stack.pop().value();
                if (lastArray.count() == 0) {
                    currentContext.pen.setStyle(Qt::SolidLine);
                } else {
                    currentContext.pen.setDashOffset(offset);
                    currentContext.pen.setDashPattern(lastArray);
                    lastArray.clear();
                }
                break;
            case 'r':
                if (stream[previousPosition+1] == 'g') {
                    double b = stack.pop().value();
                    double g = stack.pop().value();
                    double r = stack.pop().value();
                    currentContext.brush.setColor(QColor(r*255, g*255, b*255));
                }
                break;
            case 'c':
                y3 = stack.pop();
                x3 = stack.pop();
                y2 = stack.pop();
                x2 = stack.pop();
                y1 = stack.pop();
                x1 = stack.pop();
                //currentPath.cubicTo(x1, y1, x2, y2, x3, y3);
                std::cout << " C " << x1 << ',' << y1 << ' ' << x2 << ',' << y2 << ' ' << x3 << ',' << y3;
                cur_x = x3;
                cur_y = y3;
                break;
            case 'j':
                joinStyle = stack.pop().value();
                if (joinStyle  == 0)
                    currentContext.pen.setJoinStyle(Qt::MiterJoin);
                else if (joinStyle  == 1)
                    currentContext.pen.setJoinStyle(Qt::RoundJoin);
                else
                    currentContext.pen.setJoinStyle(Qt::BevelJoin);
                break;
            default:
                // handle a number then
                errno = 0;
                //double d = strtod(stream + previousPosition, NULL);
                FloatText d = FloatText(stream + previousPosition);
                if (errno != 0)
                    qFatal("Convertion to double failed !");
                if (inArray)
                    //lastArray << d;
                    lastArray << d.value();
                else
                    stack.push(d);
            }
        }
        previousPosition = tokenPosition + 1;
        if (stream[tokenPosition] == ']') {
            inArray = false;
        }
        tokenPosition++;
    } while (tokenPosition <= streamLen);
    //std::cerr << "stack: " << stack.size() << std::endl;
    return true;
}