Ejemplo n.º 1
0
bool ChoiceTask::init(AdventureScene* scene, SceneManager* smgr) {
    // 選択肢の描画位置を初期化
	int i = 0;
	for (auto it = m_choices.begin();
		it != m_choices.end();
		it++, i++) {
		std::string choice_key = "choice_" + std::to_string(i);
		DrawableText* choice = dynamic_cast<DrawableText*>(scene->getDrawable(choice_key));
		std::string window_key = "choice_window_" + std::to_string(i);
		DrawableImage* c_window = dynamic_cast<DrawableImage*>(scene->getDrawable(window_key));

		choice->setText(it->first);
		int textWidth = getTextWidth(it->first, choice->getFontHandle());
		int windowWidth = c_window->getWidth();
		int textPosition = (textWidth > windowWidth) ? 280 : 275 + (windowWidth - textWidth)/2;
		choice->setPosition(textPosition, i * 400/m_choices.size() + 81);
		choice->setIsVisible(true);

		c_window->setPosition(275, i * 400/m_choices.size() + 76);
		c_window->setIsVisible(true);
	}
	m_cursor = 0;   // カーソルの描画位置を初期化

	setInitialzed();
	return true;
}
Ejemplo n.º 2
0
bool DrawableFactory::addTextFromCSV(const std::string& filename, Resources& res, Scene* scene)
{
    // Fontリソースの読み込み
    FontResourceManager& fr = res.fonts();

    // CSVデータ読み込み
    CSVData data;
    DrawableFactory::loadCSV(filename, data);

    // データを読み出して登録する
    for (auto it = data.begin(); it != data.end(); ++it)
    {
        auto b = (*it);
        // エラー処理
        if (b.size() != 11) {
            printf("Text: ファイルフォーマットエラー\n");
            return false;
        }
        // データの格納
        std::string drawKey(b[0]);
        std::string text(b[2]);
        std::string fontKey(b[8]);
        int layer = std::atoi(b[1].c_str());
        int x =     std::atoi(b[3].c_str());
        int y =     std::atoi(b[4].c_str());
        int red =   std::atoi(b[5].c_str());
        int green = std::atoi(b[6].c_str());
        int blue =  std::atoi(b[7].c_str());
        int alpha = std::atoi(b[9].c_str());
        bool isVisible = (b[10] == "true") ? true : false;

        // エラー処理
        if (b[0] == "" ||
            b[1] == "" ||
            b[8] == "") {
            printf("Text: 未入力が存在します。\n");
            return false;
        }

        // 初期値の処理
        if (b[9] == "") alpha = 255;

        // 生成
        DrawableText* d = new DrawableText();
        d->setFontHandle(fr.get(fontKey));
        d->setPosition(x, y);
        d->setText(text);
        d->setTextColor(red, green, blue);
        d->setAlpha(alpha);
        d->setIsVisible(isVisible);
        scene->addDrawable(drawKey, d, layer);
    
        printf("$$$ Text loaded: %s\n", drawKey.c_str());
    }
    return true;
}
Ejemplo n.º 3
0
//--------------------------------------------------------------------------------------------------
/// Draw the axis labels
//--------------------------------------------------------------------------------------------------
void OverlayNavigationCube::renderAxisLabels(OpenGLContext* oglContext, bool software, const MatrixState& matrixState)
{
    // Multiply with 1.08 will slightly pull the labels away from the corresponding arrow head
    Vec3f xPos(1.08f, 0, 0);
    Vec3f yPos(0, 1.08f, 0);
    Vec3f zPos(0, 0, 1.08f);

    DrawableText drawableText;
    drawableText.setFont(m_font.p());
    drawableText.setCheckPosVisible(false);
    drawableText.setDrawBorder(false);
    drawableText.setDrawBackground(false);
    drawableText.setVerticalAlignment(TextDrawer::CENTER);
    drawableText.setTextColor(m_textColor);

    if (!m_xLabel.isEmpty()) drawableText.addText(m_xLabel, xPos);
    if (!m_yLabel.isEmpty()) drawableText.addText(m_yLabel, yPos);
    if (!m_zLabel.isEmpty()) drawableText.addText(m_zLabel, zPos);


    // Do the actual rendering
    // -----------------------------------------------
    if (software)
    {
        drawableText.renderSoftware(oglContext, matrixState);
    }
    else
    {
        ref<ShaderProgram> textShader = oglContext->resourceManager()->getLinkedTextShaderProgram(oglContext);
        drawableText.render(oglContext, textShader.p(), matrixState);
    }
}