void Account::SaveFile(QString filename)
{
    qDebug() << "Saving account...";

    QFile file(filename);
    if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
        return;
    QTextStream textStr(&file);
    textStr.setCodec("UTF-8");

    QDomDocument doc("AccountManagerFile");
    QDomElement root = doc.createElement("AccountManagerFile");
    doc.appendChild(root);

    QDomElement infoEle = doc.createElement("Info");
    root.appendChild(infoEle);
    {
        QDomElement accEle = doc.createElement("Account");
        accEle.setAttribute("name", m_name);
        infoEle.appendChild(accEle);

        QDomElement verEle = doc.createElement("Version");
        Version::SaveVersionInfo(verEle);
        infoEle.appendChild(verEle);
    }

    QDomElement uiEle = doc.createElement("UI");
    root.appendChild(uiEle);
    GetAccountWidget()->GetAccountSettings()->SaveFile(uiEle, doc);

    QDomElement setEle = doc.createElement("Settings");
    root.appendChild(setEle);
    GetAccountOptions()->SaveFile(setEle, doc);

    QDomElement elementsEle = doc.createElement("Elements");
    root.appendChild(elementsEle);

    std::vector<Element*>::iterator it;
    for(it = m_list.begin(); it != m_list.end(); it++)
    {
        QDomElement elementEle = doc.createElement((*it)->GetType());
        elementsEle.appendChild(elementEle);
        (*it)->SaveFile(elementEle, doc);
    }

    textStr << doc.toString();

    file.close();

    SetLastPath(filename);

    qDebug() << "Save ended.";
}
Example #2
0
int main()
{
    osg::setNotifyLevel(osg::INFO);

    // text geometry
    std::string textStr("Hello World");
    osg::ref_ptr<osgText::Text> myText = new osgText::Text;
    myText->setFont("DroidSans-Bold.ttf");
    myText->setCharacterSize(20.0f);
    myText->setText(textStr);

    // text node
    osg::ref_ptr<osg::Geode> textGeode = new osg::Geode;
    textGeode->addDrawable(myText);

    // text shaders
    osg::ref_ptr<osg::Program> shProgram = new osg::Program;
    shProgram->setName("TextShader");

    std::string vShader = std::string("#version 120\n") +
            readFileAsString("shaders/NoShading_vert.glsl");
    shProgram->addShader(new osg::Shader(osg::Shader::VERTEX,vShader));

    std::string fShader = std::string("#version 120\n") +
            readFileAsString("shaders/NoShading_frag.glsl");
    shProgram->addShader(new osg::Shader(osg::Shader::FRAGMENT,fShader));

    osg::ref_ptr<osg::Uniform> textColor = new osg::Uniform("MaterialColor",osg::Vec4(0,1,1,0.5));
    osg::ref_ptr<osg::Uniform> textTexture = new osg::Uniform("GlyphTexture",0);

    osg::StateSet *ss = textGeode->getOrCreateStateSet();
    ss->addUniform(textColor);
    ss->addUniform(textTexture);
    ss->setAttributeAndModes(shProgram,osg::StateAttribute::ON);

    osg::ref_ptr<osg::Group> nodeRoot = new osg::Group;
    nodeRoot->addChild(textGeode);

    // setup viewer
    osgViewer::Viewer viewer;
    viewer.setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
    viewer.setUpViewInWindow(100,100,800,480);
    viewer.setSceneData(nodeRoot.get());
    return viewer.run();
}
 void TextField::updateText(uint32_t start, const char* text) {
     std::string textStr(text);
     uint32_t end = (uint32_t)std::min((uint32_t)textStr.length(), numCharsTotal - start);
     std::vector<float> charOffsets(end * 8);
     for (uint32_t i = 0; i < end; ++i) {
         int offsetToChar;
         if (textStr[i] < font.firstChar || textStr[i] > font.lastChar) { // display error char
             offsetToChar = 0;
         } else {
             offsetToChar = textStr[i] - font.firstChar + font.getOffsetToFirstChar();
         }
         for (int j = 0; j < 8; j += 2) {
             charOffsets[i * 8 + j + 0] = (offsetToChar + (j == 2 || j == 6)) * font.getPanelAdvance();
             charOffsets[i * 8 + j + 1] = j / 4;
         }
     }
     glBindBuffer(GL_ARRAY_BUFFER, buffers[1]);
     glBufferSubData(GL_ARRAY_BUFFER, start * 8 * sizeof(float), charOffsets.size() * sizeof(float),
                     charOffsets.data());
 }
Example #4
0
INT_PTR DimensionDialog::DialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   switch (uMsg)
   {
   case WM_NOTIFY:
   {
      LPNMHDR pnmhdr = (LPNMHDR)lParam;
      switch (pnmhdr->code)
      {
      case LVN_ITEMCHANGED:
      {
         NMLISTVIEW * const plistview = (LPNMLISTVIEW)lParam;
         int idx = plistview->iItem;
         if (idx >= DIM_TABLE_SIZE || idx < 0)
            break;

         int width = (int)floorf(dimTable[idx].width*47.0f + 0.5f);
         int height = (int)floorf(dimTable[idx].height*47.0f + 0.5f);
         char textBuf[32];
         sprintf_s(textBuf, "%i", width);
         CString textStr(textBuf);
         SetDlgItemText(IDC_VP_WIDTH, textStr);
         sprintf_s(textBuf, "%i", height);
         textStr = CString(textBuf);
         SetDlgItemText(IDC_VP_HEIGHT, textStr);
         sprintf_s(textBuf, "%.03f", dimTable[idx].width);
         textStr = CString(textBuf);
         SetDlgItemText(IDC_SIZE_WIDTH, textStr);
         sprintf_s(textBuf, "%.03f", dimTable[idx].height);
         textStr = CString(textBuf);
         SetDlgItemText(IDC_SIZE_HEIGHT, textStr);
         float ratio = (float)height / width;
         sprintf_s(textBuf, "%.04f", ratio);
         textStr = CString(textBuf);
         SetDlgItemText(IDC_ASPECT_RATIO_EDIT, textStr);
         break;
      }
      }
      break;
   }
   case WM_COMMAND:
   {
      switch (HIWORD(wParam))
      {
      case EN_KILLFOCUS:
      {
         float sizeWidth, sizeHeight;
         int vpWidth, vpHeight;
         int ret = 0;
         if (LOWORD(wParam) == IDC_SIZE_WIDTH)
         {
            char textBuf[32];
            CString textStr;
            textStr = GetDlgItemText(IDC_SIZE_WIDTH);
            ret = sscanf_s(textStr.c_str(), "%f", &sizeWidth);
            if (ret != 1 || sizeWidth < 0.0f)
               sizeWidth = 0;
            int width = (int)floorf(sizeWidth*47.0f + 0.5f);
            sprintf_s(textBuf, "%i", width);
            CString textStr2(textBuf);
            SetDlgItemText(IDC_VP_WIDTH, textStr2);
         }
         if (LOWORD(wParam) == IDC_SIZE_HEIGHT)
         {
            char textBuf[32];
            CString textStr;
            textStr = GetDlgItemText(IDC_SIZE_HEIGHT);
            ret = sscanf_s(textStr.c_str(), "%f", &sizeHeight);
            if (ret != 1 || sizeHeight < 0.0f)
               sizeHeight = 0;
            int height = (int)floorf(sizeHeight*47.0f + 0.5f);
            sprintf_s(textBuf, "%i", height);
            CString textStr2(textBuf);
            SetDlgItemText(IDC_VP_HEIGHT, textStr2);
         }
         if (LOWORD(wParam) == IDC_VP_WIDTH)
         {
            char textBuf[32];
            CString textStr;
            textStr = GetDlgItemText(IDC_VP_WIDTH);
            ret = sscanf_s(textStr.c_str(), "%i", &vpWidth);
            if (ret != 1 || vpWidth < 0)
               vpWidth = 0;
            float width = (float)vpWidth / 47.0f;
            sprintf_s(textBuf, "%.3f", width);
            CString textStr2(textBuf);
            SetDlgItemText(IDC_SIZE_WIDTH, textStr2);
         }
         if (LOWORD(wParam) == IDC_VP_HEIGHT)
         {
            char textBuf[32];
            CString textStr;
            textStr = GetDlgItemText(IDC_VP_HEIGHT);
            ret = sscanf_s(textStr.c_str(), "%i", &vpHeight);
            if (ret != 1 || vpHeight < 0)
               vpHeight = 0;
            float height = (float)vpHeight / 47.0f;
            sprintf_s(textBuf, "%.03f", height);
            CString textStr2(textBuf);
            SetDlgItemText(IDC_SIZE_HEIGHT, textStr2);
         }
         break;
      }
      }
   }
   }
   return DialogProcDefault(uMsg, wParam, lParam);

}