//--------------------------------------------------------------------------- void __fastcall TForm21::ComboBox1Change(TObject *Sender) { TLabelPlacement NewPlacement = IndexToPlacement[ComboBox1->ItemIndex]; double xPos = Data.Calc(ToWString(Edit1->Text)); double yPos = Data.Calc(ToWString(Edit2->Text)); double Width = Draw.xCoord(Label->GetRect().Right) - Draw.xCoord(Label->GetRect().Left); double Height = Draw.yCoord(Label->GetRect().Top) - Draw.yCoord(Label->GetRect().Bottom); switch(OldPlacement) { case lpUserTopRight: xPos -= Width; break; case lpUserBottomLeft: yPos += Height; break; case lpUserBottomRight: xPos -= Width; yPos += Height; break; } switch(NewPlacement) { case lpUserTopRight: xPos += Width; break; case lpUserBottomLeft: yPos -= Height; break; case lpUserBottomRight: xPos += Width; yPos -= Height; break; } Edit1->Text = xPos; Edit2->Text = yPos; OldPlacement = NewPlacement; }
const bool Shader::createVertexShaderAndInputLayout(ID3D11Device* device, const std::string filename, ID3D11VertexShader** vertexShader, ID3D11InputLayout** inputLayout, const D3D11_INPUT_ELEMENT_DESC* elements, const unsigned int elementCount) { std::ifstream file(filename,std::ifstream::binary); if(file.fail()) { Sly::error(MAJOR_ERROR, L"Shader::createVertexShaderAndInputLayout(\""+ ToWString(filename) + L"\")\nError: Failed to open shader file."); return false; } file.seekg(0, std::ios::end); const size_t filesize = static_cast<size_t>(file.tellg()); file.seekg(0, std::ios::beg); auto data = new char[filesize]; file.read(data, filesize); file.close(); auto hr = device->CreateVertexShader(data, filesize, nullptr, vertexShader); if(FAILED(hr)) { delete[] data; Sly::error(MAJOR_ERROR, L"Shader::createVertexShaderAndInputLayout(\""+ ToWString(filename) + L"\")\nError: " + HRESULTWString(hr)); return false; } hr = device->CreateInputLayout(elements, elementCount, data, filesize, inputLayout); delete[] data; if(FAILED(hr)) { Sly::error(MAJOR_ERROR, L"Shader::createVertexShaderAndInputLayout(\""+ ToWString(filename) + L"\")\nError: " + HRESULTWString(hr)); return false; } return true; }
const bool Shader::createComputeShader(ID3D11Device* device, const std::string filename, ID3D11ComputeShader** computeShader) { std::ifstream file(filename,std::ifstream::binary); if(file.fail()) { Sly::error(MAJOR_ERROR, L"Shader::createComputeShader(\""+ ToWString(filename) + L"\")\nError: Failed to open shader file."); return false; } file.seekg(0, std::ios::end); const size_t filesize = static_cast<size_t>(file.tellg()); file.seekg(0, std::ios::beg); auto data = new char[filesize]; file.read(data, filesize); file.close(); const auto hr = device->CreateComputeShader(data, filesize, NULL, computeShader); delete[] data; if(FAILED(hr)) { Sly::error(MAJOR_ERROR, L"Shader::createComputeShader(\""+ ToWString(filename) + L"\")\nError: " + HRESULTWString(hr)); return false; } return true; }
//--------------------------------------------------------------------------- void __fastcall TForm21::TntButton1Click(TObject *Sender) { TTextValue xPos; TTextValue yPos; xPos.Value = MakeFloat(Edit1); yPos.Value = MakeFloat(Edit2); xPos.Text = ToWString(Edit1->Text); yPos.Text = ToWString(Edit2->Text); int Index = ComboBox1->ItemIndex; if(Index == -1) Index = 0; boost::shared_ptr<TTextLabel> NewLabel(new TTextLabel( Label->GetText(), IndexToPlacement[Index], xPos, yPos, Label->GetBackgroundColor(), Label->GetRotation(), Label->GetOleLink() )); UndoList.Push(TUndoChange(Label, NewLabel)); Data.Replace(Label, NewLabel); NewLabel->Update(); ModalResult = mrOk; }
bool Properties (Win::Dow::Handle win, char const * path, char const * page) { std::wstring wPath = ToWString (path); std::wstring wPage = ToWString (page); BOOL result = ::SHObjectProperties (win.ToNative (), SHOP_FILEPATH, &wPath [0], &wPage [0]); return result != FALSE; }
//--------------------------------------------------------------------------- void TPolFuncFrame::Eval(const TGraphElem *Elem) { if(const TPolFunc *Func = dynamic_cast<const TPolFunc*>(Elem)) { Clear(); ErrorPrefix = "t: "; long double t = Form1->Data.Calc(ToWString(Edit1->Text)); ErrorPrefix = "r(t): "; long double r = Func->GetFunc().CalcR(t); ErrorPrefix = "x(t): "; long double x = Func->GetFunc().CalcX(t); ErrorPrefix = "y(t): "; long double y = Func->GetFunc().CalcY(t); Edit2->Text = RoundToStr(r); Edit3->Text = RoundToStr(x); Edit4->Text = RoundToStr(y); Form1->SetCrossPos(x, y); ErrorPrefix = "dr/dt: "; Edit5->Text = RoundToStr(Func->GetFunc().MakeDif().CalcR(t)); ErrorPrefix = "dy/dx: "; long double dydx = Func->GetFunc().CalcSlope(t); if(_finite(dydx)) Edit6->Text = RoundToStr(dydx); } }
std::wstring PlatformNix::GetApplicationDataDirectoryW() { // Unicode not supported on Unix-based platforms std::string path = GetApplicationDataDirectory(); return (ToWString(path)); }
bool IsRelative(const std::string& path) { #ifdef US_PLATFORM_WINDOWS if (path.size() > MAX_PATH) return false; std::wstring wpath(ToWString(path)); return (TRUE == ::PathIsRelativeW(wpath.c_str()))? true:false; #else return path.empty() || path[0] != DIR_SEP; #endif }
std::wstring PlatformWin::GetUserDocumentsDirectoryW() { LPITEMIDLIST pidl; if (SHGetFolderLocation(0, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, &pidl) == S_OK) { wchar_t cpath[MAX_PATH]; SHGetPathFromIDListW( pidl, cpath ); CoTaskMemFree(pidl); return std::wstring(cpath) + L"\\" + ToWString(std::string(APPLICATION_NAME)); } throw Exception("Failed to access user documents directory."); }
static std::wstring GetNewFilePath(const std::wstring& dir, time_t time) { std::wostringstream filename; if (!dir.empty()) { // Windows can tolerate forward slashes in paths. filename << dir << L"/"; } filename << L"events.out.tfevents." << std::setfill(L'0') << std::setw(10) << time << L"." << ToWString(GetHostName()); return filename.str(); }
void Crypt::String::Encrypt (std::string const & description) { Assert (description.size () != 0); CheckVersion (); DATA_BLOB blobIn; blobIn.cbData = _plainText.size (); // if string, includes final null blobIn.pbData = &_plainText [0]; ::CryptProtectData (&blobIn, ToWString (description).c_str (), // description 0, // entropy 0, // reserved 0, // prompt 0, // flags (only currently logged user can decrypt) &_blob); }
ConstantBuffer* DXDisplay::getConstantBuffer(const std::string id) const { auto found = constantBuffers_.find(id); if(found != constantBuffers_.end()) return found->second; Sly::error(WARNING_ERROR,L"DxDisplay::getConstantBuffer()\nError: ConstantBuffer not found with id: \"" + ToWString(id) + L"\"."); return nullptr; }
std::wstring StringUtilities::ToWString(long input) { std::string string_value = ToString(input); return ToWString(string_value); }
void DXDisplay::addCurrentRenderPass(const std::string id) { const auto found = renderPasses_.find(id); if(found == renderPasses_.end()) Sly::error(WARNING_ERROR,L"DxDisplay::addCurrentRenderPass()\nError: RenderPass not found with id: \"" + ToWString(id) + L"\"."); else currentRenderPasses_.push_back(found->second); }
void DXDisplay::setSamplerStates(const std::string* ids, const unsigned int samplerCount) { if(samplerCount > 0 && samplerCount <= 16) { int differences = 0; ID3D11SamplerState* samplers[16] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}; for(auto i = 0; i < 16; ++i) { const auto currentID = currentSamplerStates_[i]; const auto id = ids[i]; if(id != currentID && id != "") { const auto& sampler = getSamplerState(id); samplers[i] = sampler->samplerState; currentSamplerStates_[i] = id; ++differences; } } if(differences > 0) context_->PSSetSamplers(0, samplerCount, samplers); } else Sly::error(MINOR_ERROR, L"DX::setSamplerStates()\nError: SamplerStates not set. Sampler count must be 1-16 not " + ToWString(samplerCount) + L"."); }
void DXDisplay::addRenderTargetView(const std::string id, RenderTargetView* rtv) { const auto found = renderTargetViews_.find(id); if(found == renderTargetViews_.end()) renderTargetViews_[id] = rtv; else Sly::error(WARNING_ERROR, L"DXDisplay::addRenderTargetView()\nError: RenderTargetView already exists with id: \"" + ToWString(id) + L"\"."); }
void DXDisplay::addRenderPass(const std::string id, RenderPass* renderPass) { const auto found = renderPasses_.find(id); if(found == renderPasses_.end()) renderPasses_[id] = renderPass; else Sly::error(WARNING_ERROR, L"DXDisplay::addRenderPass()\nError: RenderPass already exists with id: \"" + ToWString(id) + L"\"."); }
void DXDisplay::addDepthStencilState(const std::string id, DepthStencilState* state) { const auto found = depthStencilStates_.find(id); if(found == depthStencilStates_.end()) depthStencilStates_[id] = state; else Sly::error(WARNING_ERROR, L"DXDisplay::addDepthStencilState()\nError: DepthStencilState already exists with id: \"" + ToWString(id) + L"\"."); }
BlendState* DXDisplay::getBlendState(const std::string id) const { auto found = blendStates_.find(id); if(found != blendStates_.end()) return found->second; Sly::error(WARNING_ERROR,L"DxDisplay::getBlendState()\nError: BlendState not found with id: \"" + ToWString(id) + L"\"."); return nullptr; }
void DXDisplay::addConstantBuffer(const std::string id, ConstantBuffer* buffer) { const auto found = constantBuffers_.find(id); if(found == constantBuffers_.end()) constantBuffers_[id] = buffer; else Sly::error(WARNING_ERROR, L"DXDisplay::addConstantBuffer()\nError: ConstantBuffer already exists with id: \"" + ToWString(id) + L"\"."); }
void DXDisplay::addSamplerState(const std::string id, SamplerState* state) { const auto found = samplerStates_.find(id); if(found == samplerStates_.end()) samplerStates_[id] = state; else Sly::error(WARNING_ERROR, L"DXDisplay::addSamplerState()\nError: SamplerState already exists with id: \"" + ToWString(id) + L"\"."); }
const Controller& Controllers::getController(const int n) { if(n >= 0 && n < XUSER_MAX_COUNT) return currentControllerStates_[n]; Sly::error(MINOR_ERROR, L"Controllers::getController()\nError: Controller number invalid must be between 0-"+ ToWString(XUSER_MAX_COUNT) + L"." ); return currentControllerStates_[0]; }
Platform::String^ ToPlatformString(const char* utf8String) { return ref new Platform::String(ToWString(utf8String).data()); }
DepthStencilView* DXDisplay::getDepthStencilView(const std::string id) const { const auto found = depthStencilViews_.find(id); if(found != depthStencilViews_.end()) return found->second; Sly::error(WARNING_ERROR,L"DxDisplay::getDepthStencilView()\nError: DepthStencilView not found with id: \"" + ToWString(id) + L"\"."); return nullptr; }
bool SkeletalAnimation::load(const std::string filename) { std::ifstream file(filename); if(file.fail()) { Sly::error(MAJOR_ERROR, L"SkeletalAnimation::load()\nError: Failed to load SkeletalAnimation: \""+ ToWString(filename) + L"\""); return false; } std::string param; std::string junk; const int pos = (int)file.tellg(); file.seekg(0, std::ios::end ); //get file length const int length = (int)file.tellg(); file.seekg(pos); // Restore the position of the get pointer file >> param; int frameCount = 0; int jointCount = 0; int frameDataCount = 0; while(!file.eof()) { if(param == "MD5Version") { int version; file >> version;//we only want md5 version 10 for now, newer versions detect and run differently? if(version != 10) { Sly::error(MINOR_ERROR, L"SkeletalMesh::load()\nError: Failed to load SkeletalMesh: \""+ ToWString(filename) + L"\", MD5 version not supported. (Version: " + ToWString(version) + L")"); return false; } } else if(param == "commandline")
Texture2D* DXDisplay::addTexture(const std::string id) { const auto found = textures_.find(id); if(found == textures_.end()) { Texture2D* t = new Texture2D; textures_[id] = t; return t; } else { Sly::error(WARNING_ERROR, L"DXDisplay::addTexture()\nError: Texture already exists with id: \"" + ToWString(id) + L"\"."); return found->second; } }
Texture2D* DXDisplay::getTexture(const std::string id) const { const auto found = textures_.find(id); if(found != textures_.end()) return found->second; Sly::error(WARNING_ERROR,L"DxDisplay::getTexture()\nError: Texture not found with id: \"" + ToWString(id) + L"\"."); return nullptr; }
bool CPluginFilter::IsElementHidden(const std::wstring& tag, IHTMLElement* pEl, const std::wstring& domain, const std::wstring& indent) const { CString tagCString = ToCString(tag); CString id; CComBSTR bstrId; if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) { id = bstrId; } CString classNames; CComBSTR bstrClassNames; if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames) { classNames = bstrClassNames; } CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); { // Search tag/id filters if (!id.IsEmpty()) { std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideTagsNamed::const_iterator> idItEnum = m_elementHideTagsId.equal_range(std::make_pair(tagCString, id)); for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; idIt != idItEnum.second; idIt ++) { if (idIt->second.IsMatchFilterElementHide(pEl)) { #ifdef ENABLE_DEBUG_RESULT DEBUG_HIDE_EL(indent + "HideEl::Found (tag/id) filter:" + idIt->second.m_filterText) CPluginDebug::DebugResultHiding(tag, L"id:" + ToWstring(id), ToWstring(idIt->second.m_filterText)); #endif return true; } } // Search general id idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id)); for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; idIt != idItEnum.second; idIt ++) { if (idIt->second.IsMatchFilterElementHide(pEl)) { #ifdef ENABLE_DEBUG_RESULT DEBUG_HIDE_EL(indent + "HideEl::Found (?/id) filter:" + idIt->second.m_filterText) CPluginDebug::DebugResultHiding(tag, L"id:" + ToWstring(id), ToWstring(idIt->second.m_filterText)); #endif return true; } } } // Search tag/className filters if (!classNames.IsEmpty()) { int pos = 0; CString className = classNames.Tokenize(L" \t\n\r", pos); while (pos >= 0) { std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideTagsNamed::const_iterator> classItEnum = m_elementHideTagsClass.equal_range(std::make_pair(tagCString, className)); for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.first; classIt != classItEnum.second; ++classIt) { if (classIt->second.IsMatchFilterElementHide(pEl)) { #ifdef ENABLE_DEBUG_RESULT DEBUG_HIDE_EL(indent + "HideEl::Found (tag/class) filter:" + classIt->second.m_filterText) CPluginDebug::DebugResultHiding(tag, L"class:" + ToWstring(className), ToWstring(classIt->second.m_filterText)); #endif return true; } } // Search general class name classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", className)); for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.first; classIt != classItEnum.second; ++ classIt) { if (classIt->second.IsMatchFilterElementHide(pEl)) { #ifdef ENABLE_DEBUG_RESULT DEBUG_HIDE_EL(indent + L"HideEl::Found (?/class) filter:" + ToWString(classIt->second.m_filterText)); CPluginDebug::DebugResultHiding(tag, L"class:" + ToWstring(className), ToWstring(classIt->second.m_filterText)); #endif return true; } } // Next class name className = classNames.Tokenize(L" \t\n\r", pos); } } // Search tag filters std::pair<TFilterElementHideTags::const_iterator, TFilterElementHideTags::const_iterator> tagItEnum = m_elementHideTags.equal_range(tagCString); for (TFilterElementHideTags::const_iterator tagIt = tagItEnum.first; tagIt != tagItEnum.second; ++ tagIt) { if (tagIt->second.IsMatchFilterElementHide(pEl)) { #ifdef ENABLE_DEBUG_RESULT DEBUG_HIDE_EL(indent + "HideEl::Found (tag) filter:" + tagIt->second.m_filterText) CPluginDebug::DebugResultHiding(tag, L"-", ToWstring(tagIt->second.m_filterText)); #endif return true; } } } return false; }
//--------------------------------------------------------------------------- bool TData::ImportPointSeries(const std::wstring &FileName, char Separator) { const TColor Colors[] = {clRed, clGreen, clBlue, clYellow, clPurple, clAqua, clBlack, clGray, clSkyBlue , clMoneyGreen, clDkGray}; std::ifstream Stream(FileName.c_str()); if(!Stream) { MessageBox(LoadRes(RES_NOT_GRAPH_FILE, FileName), LoadString(RES_FILE_ERROR), MB_ICONSTOP); return false; } std::string Line; while(Stream && Line.empty()) std::getline(Stream, Line); if(Separator == 0) Separator = GetSeparator(Line); std::vector<std::pair<std::wstring, std::vector<TPointSeriesPoint> > > Points; unsigned Row = 0; try { boost::escaped_list_separator<char> Sep("", std::string(1, Separator), ""); unsigned Index = 0; do { ++Row; boost::tokenizer<boost::escaped_list_separator<char> > tok(Line, Sep); boost::tokenizer<boost::escaped_list_separator<char> >::iterator beg = tok.begin(); std::wstring xStr = ToWString(*beg); if(!xStr.empty() && xStr[0] == L'#') { Index = Points.size(); Points.push_back(std::make_pair(xStr.substr(1), std::vector<TPointSeriesPoint>())); while(++beg != tok.end()) Points.push_back(std::make_pair(ToWString(*beg), std::vector<TPointSeriesPoint>())); } else { unsigned Col = Index; while(++beg != tok.end()) { if(Col == Points.size()) Points.push_back(std::make_pair(L"", std::vector<TPointSeriesPoint>())); std::wstring yStr = ToWString(*beg); if(Property.DecimalSeparator != '.') { std::replace(xStr.begin(), xStr.end(), Property.DecimalSeparator, L'.'); std::replace(yStr.begin(), yStr.end(), Property.DecimalSeparator, L'.'); } Points[Col].second.push_back(TPointSeriesPoint(xStr, yStr)); Col++; } } } while(std::getline(Stream, Line)); } catch(Func32::EParseError &E) { MessageBox(LoadRes(526, FileName.c_str(), Row+1), LoadRes(RES_FILE_ERROR), MB_ICONSTOP); return false; } catch(std::out_of_range &E) { MessageBox(LoadRes(526, FileName.c_str(), Row+1), LoadRes(RES_FILE_ERROR), MB_ICONSTOP); return false; } catch(std::bad_alloc &E) { MessageBox(LoadRes(RES_OUT_OF_MEMORY), LoadRes(RES_FILE_ERROR), MB_ICONSTOP); return false; } unsigned ColorIndex = 0; unsigned Style = Property.DefaultPoint.Style; unsigned LineStyle = Property.DefaultPointLine.Style; UndoList.BeginMultiUndo(); for(unsigned I = 0; I < Points.size(); I++) { boost::shared_ptr<TPointSeries> Series(new TPointSeries( clBlack, //FrameColor Colors[ColorIndex], //FillColor Colors[ColorIndex], //LineColor Property.DefaultPoint.Size, //Size Property.DefaultPointLine.Size, //LineSize Style, //Style static_cast<TPenStyle>(LineStyle), //LineStyle iaLinear, //Onterpolation false, //ShowLabels Property.DefaultPointLabelFont, //Font lpBelow, //LabelPosition ptCartesian, //PointType ebtNone, //xErrorBarType 0, //xErrorValues ebtNone, //yErrorBarType 0 //yErrorValue )); Series->Swap(Points[I].second); Series->SetLegendText(Points[I].first.empty() ? CreatePointSeriesDescription() : Points[I].first); Insert(Series); UndoList.Push(TUndoAdd(Series)); Series->Update(); ColorIndex = ++ColorIndex % (sizeof(Colors)/sizeof(TColor)); Style = (Style+1) % 7; LineStyle = (LineStyle+1) % 5; } UndoList.EndMultiUndo(); Modified = true; return true; }
RenderPass* DXDisplay::getRenderPass(const std::string id) const { const auto found = renderPasses_.find(id); if(found != renderPasses_.end()) return found->second; Sly::error(WARNING_ERROR,L"DxDisplay::getRenderPass()\nError: RenderPass not found with id: \"" + ToWString(id) + L"\"."); return nullptr; }