void ResourceManager::ScanResources(fiDevice* device, fwString& path) { rage::fiFindData findData; int handle = device->FindFirst(path.c_str(), &findData); if (!handle || handle == -1) { return; } do { // dotfiles we don't want if (findData.fileName[0] == '.') { continue; } fwString fullPath = path; if (path[path.length() - 1] != '/') { fullPath.append("/"); } fullPath.append(findData.fileName); // is this a directory? if (!(device->GetFileAttributes(fullPath.c_str()) & FILE_ATTRIBUTE_DIRECTORY)) { continue; } // as this is a directory, is this a resource subdirectory? if (findData.fileName[0] == '[') { char* endBracket = strrchr(findData.fileName, ']'); if (!endBracket) { // invalid name trace("ignored %s - no end bracket\n", findData.fileName); continue; } // traverse the directory ScanResources(device, fullPath); } else { // probably a resource directory... AddResource(fwString(findData.fileName), fullPath); } } while (device->FindNext(handle, &findData)); device->FindClose(handle); }
__declspec(dllexport) void CreateFrame(fwString frameName, fwString frameURL) { auto procMessage = CefProcessMessage::Create("createFrame"); auto argumentList = procMessage->GetArgumentList(); argumentList->SetSize(2); argumentList->SetString(0, frameName.c_str()); argumentList->SetString(1, frameURL.c_str()); auto rootWindow = Instance<NUIWindowManager>::Get()->GetRootWindow(); auto browser = rootWindow->GetBrowser(); browser->SendProcessMessage(PID_RENDERER, procMessage); std::unique_lock<std::shared_mutex> lock(frameListMutex); frameList.insert(frameName); }
bool FontRendererImpl::GetStringMetrics(fwWString characterString, float fontSize, float fontScale, fwString fontRef, CRect& outRect) { wchar_t fontRefWide[128]; mbstowcs(fontRefWide, fontRef.c_str(), _countof(fontRefWide)); ComPtr<IDWriteTextFormat> textFormat; m_dwFactory->CreateTextFormat(fontRefWide, nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, fontSize, L"en-us", textFormat.GetAddressOf()); ComPtr<IDWriteTextLayout> textLayout; m_dwFactory->CreateTextLayout(characterString.c_str(), characterString.length(), textFormat.Get(), 8192.0, 8192.0, textLayout.GetAddressOf()); DWRITE_TEXT_METRICS textMetrics; textLayout->GetMetrics(&textMetrics); outRect.SetRect(textMetrics.left, textMetrics.top, textMetrics.left + textMetrics.width, textMetrics.top + textMetrics.height); return true; }
void FontRendererImpl::DrawText(fwWString text, const CRect& rect, const CRGBA& color, float fontSize, float fontScale, fwString fontRef) { // wait for a swap to complete FrpSeqAllocatorWaitForSwap(); m_mutex.lock(); // create or find a text format ComPtr<IDWriteTextFormat> textFormat; auto formatKey = std::make_pair(fontRef, fontSize); auto formatIter = m_textFormatCache.find(formatKey); if (formatIter != m_textFormatCache.end()) { textFormat = formatIter->second; } else { wchar_t fontRefWide[128]; mbstowcs(fontRefWide, fontRef.c_str(), _countof(fontRefWide)); m_dwFactory->CreateTextFormat(fontRefWide, nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, fontSize, L"en-us", textFormat.GetAddressOf()); m_textFormatCache[formatKey] = textFormat; } // create or find a cached text layout ComPtr<IDWriteTextLayout> textLayout; auto layoutKey = std::make_pair(textFormat.Get(), std::make_pair(color.AsARGB(), text)); auto layoutIter = m_textLayoutCache.find(layoutKey); if (layoutIter != m_textLayoutCache.end()) { textLayout = layoutIter->second; } else { m_dwFactory->CreateTextLayout(text.c_str(), text.length(), textFormat.Get(), rect.Width(), rect.Height(), textLayout.GetAddressOf()); m_textLayoutCache[layoutKey] = textLayout; // set effect DWRITE_TEXT_RANGE effectRange = { 0, UINT32_MAX }; ComPtr<CitizenDrawingEffect> effect = Make<CitizenDrawingEffect>(); effect->SetColor(color); textLayout->SetDrawingEffect((IUnknown*)effect.Get(), effectRange); } // draw auto drawingContext = new CitizenDrawingContext(); textLayout->Draw(drawingContext, m_textRenderer.Get(), rect.Left(), rect.Top()); auto numRuns = drawingContext->glyphRuns.size(); if (numRuns) { for (auto& run : drawingContext->glyphRuns) { m_queuedGlyphRuns.push_back(run); } } delete drawingContext; m_mutex.unlock(); }
__declspec(dllexport) void SignalPoll(fwString frameName) { auto rootWindow = Instance<NUIWindowManager>::Get()->GetRootWindow(); rootWindow->SignalPoll(std::string(frameName.c_str())); }