Beispiel #1
0
std::string GlslShaderSource::convert_glesv2_gl(const std::string &op)
{
  std::string ret = op;
  std::string::const_iterator ii = ret.begin();
  std::string::const_iterator ee = ret.end();

  while(ii != ee)
  {
    std::string::const_iterator jj = regex_glesv2(ii, ee);
    if(jj != ii)
    {
      // TODO: Erase with iterators when C++11.
      std::string::difference_type erase_start = ii - ret.begin();
      std::string::difference_type erase_count = jj - ret.begin() - erase_start;
      ret = ret.erase(static_cast<size_t>(erase_start), static_cast<size_t>(erase_count));
      ii = ret.begin() + erase_start;
      ee = ret.end();
      continue;
    }
    jj = regex_comment(ii, ee);
    if(jj != ii)
    {
      ii = jj;
      continue;
    }
    ++ii;
  }

  return ret;
}
Beispiel #2
0
ImGuiStyle& DialogStyle::load(std::string styleFilePath) {
   ImGuiStyle& style = ImGui::GetStyle();

    std::FILE *fp = std::fopen(styleFilePath.c_str(), "rb");
    if (fp) {
        std::string fileContents;
        std::fseek(fp, 0, SEEK_END);
        fileContents.resize(std::ftell(fp));
        std::rewind(fp);
        std::fread(&fileContents[0], 1, fileContents.size(), fp);
        std::fclose(fp);

        size_t pos = 0;
        std::string singleLine;
        std::regex regex_comment("^#.*");
        std::regex regex_equalsSign("=");

        while ((pos = fileContents.find(Settings::Instance()->newLineDelimiter)) != std::string::npos) {
            singleLine = fileContents.substr(0, pos);

            if (singleLine == "" || std::regex_match(singleLine, regex_comment)) {
                fileContents.erase(0, pos + Settings::Instance()->newLineDelimiter.length());
                continue;
            }
            else {
                std::string opKey, opValue;
                std::vector<std::string> lineElements = this->splitString(singleLine, regex_equalsSign);
                opKey = lineElements[0];
                boost::algorithm::trim(opKey);

                if (lineElements.size() > 1) {
                    opValue = lineElements[1];
                    boost::algorithm::trim(opValue);
                }
                else
                    opValue = "";

                boost::replace_all(opKey, "style.rendering.", "");
                boost::replace_all(opKey, "style.sizes.", "");
                boost::replace_all(opKey, "style.colors.", "");
                boost::trim_right(opKey);
                boost::trim_right(opValue);

                try {
                    if (opKey == "Font")
                        Settings::Instance()->UIFontFile = opValue;
                    else if (opKey == "FontSize")
                        Settings::Instance()->UIFontSize = std::stof(opValue);
                    else if (opKey == "AntiAliasedLines")
                        style.AntiAliasedLines = std::stoi(opValue) != 0;
                    else if (opKey == "AntiAliasedShapes")
                        style.AntiAliasedShapes = std::stoi(opValue) != 0;
                    else if (opKey == "CurveTessellationTol")
                        style.CurveTessellationTol = std::stof(opValue);
                    else if (opKey == "Alpha")
                        style.Alpha = std::stof(opValue);

                    else if (opKey == "WindowPadding")
                        style.WindowPadding = this->tov2(opValue);
                    else if (opKey == "WindowRounding")
                        style.WindowRounding = std::stof(opValue);
                    else if (opKey == "ChildWindowRounding")
                        style.ChildWindowRounding = std::stof(opValue);
                    else if (opKey == "FramePadding")
                        style.FramePadding = this->tov2(opValue);
                    else if (opKey == "FrameRounding")
                        style.FrameRounding = std::stof(opValue);
                    else if (opKey == "ItemSpacing")
                        style.ItemSpacing = this->tov2(opValue);
                    else if (opKey == "ItemInnerSpacing")
                        style.ItemInnerSpacing = this->tov2(opValue);
                    else if (opKey == "TouchExtraPadding")
                        style.TouchExtraPadding = this->tov2(opValue);
                    else if (opKey == "IndentSpacing")
                        style.IndentSpacing = std::stof(opValue);
                    else if (opKey == "ScrollbarSize")
                        style.ScrollbarSize = std::stof(opValue);
                    else if (opKey == "ScrollbarRounding")
                        style.ScrollbarRounding = std::stof(opValue);
                    else if (opKey == "GrabMinSize")
                        style.GrabMinSize = std::stof(opValue);
                    else if (opKey == "GrabRounding")
                        style.GrabRounding = std::stof(opValue);

                    else
                        style.Colors[std::stoi(opKey)] = this->tov4(opValue);
                }
                catch (...) {
                    Settings::Instance()->funcDoLog("[GUI Style] Can't load default GUI styles - [" + opKey + "] with value [" + opValue + "]!");
                }
            }

            fileContents.erase(0, pos + Settings::Instance()->newLineDelimiter.length());
        }
    }

    return style;
}