CString CPort::GetPercentString() { CString strPercent; strPercent.Format(_T("%d%%"),GetPercent()); return strPercent; }
_UINT32 CPPTXFile::OpenDirectoryToPPTY(std::wstring bsInput, std::wstring bsOutput) { OOX::CPath pathInputDirectory = bsInput; RELEASEOBJECT(m_pPptxDocument); m_pPptxDocument = new PPTX::Document(); if (!m_pPptxDocument->isValid(pathInputDirectory.GetPath())) // true ??? { RELEASEOBJECT(m_pPptxDocument); return AVS_FILEUTILS_ERROR_CONVERT; } m_pPptxDocument->read(pathInputDirectory.GetPath() + FILE_SEPARATOR_STR, (PPTX::IPPTXEvent*)this); if(GetPercent() < 1000000) { RELEASEOBJECT(m_pPptxDocument); return AVS_FILEUTILS_ERROR_CONVERT; } smart_ptr<PPTX::Presentation> presentation = m_pPptxDocument->Get(OOX::Presentation::FileTypes::Presentation).smart_dynamic_cast<PPTX::Presentation>(); if (!presentation.is_init()) { NSDirectory::DeleteDirectory(m_strTempDir, false); return AVS_FILEUTILS_ERROR_CONVERT; } m_strDirectory = pathInputDirectory.GetDirectory(); NSBinPptxRW::CBinaryFileWriter oBinaryWriter; oBinaryWriter.m_pCommon->CheckFontPicker(); oBinaryWriter.m_pCommon->m_pNativePicker->Init(m_strFontDirectory); OOX::CPath pathDstFileOutput = bsOutput; OOX::CPath pathMedia = pathDstFileOutput.GetDirectory() + FILE_SEPARATOR_STR + _T("media"); m_strMediaDirectory = pathMedia.GetPath(); oBinaryWriter.m_strMainFolder = pathDstFileOutput.GetDirectory(); oBinaryWriter.m_pCommon->m_pMediaManager->m_strDstMedia = m_strMediaDirectory; oBinaryWriter.m_pCommon->m_pMediaManager->SetFontManager(oBinaryWriter.m_pCommon->m_pNativePicker->m_pFontManager); NSDirectory::CreateDirectory(m_strMediaDirectory); if (!m_strEmbeddedFontsDirectory.empty()) { NSDirectory::CreateDirectory(m_strEmbeddedFontsDirectory); if (NULL != oBinaryWriter.m_pCommon->m_pFontPicker) { oBinaryWriter.m_pCommon->m_pNativePicker->m_bIsEmbeddedFonts = true; oBinaryWriter.m_pCommon->m_pNativePicker->m_oEmbeddedFonts.m_strEmbeddedFontsFolder = m_strEmbeddedFontsDirectory; } } PPTX2EditorAdvanced::Convert(oBinaryWriter, *m_pPptxDocument, m_strDirectory, pathDstFileOutput.GetPath(), m_bIsNoBase64); return S_OK; }
int main() { Randomize(); int numVoters; double percentSpread, percentError; cout << "Enter number of voters: "; numVoters = GetPositiveInt(); cout << "Enter percentage spread between candidates: "; percentSpread = GetPercent(); cout << "Enter voting error percentage: "; percentError = GetPercent(); cout << endl; double chance = chanceOfInvalid(numVoters, percentSpread, percentError); cout << "Chance of an invalid election result " << "after 500 trials = " << chance << endl; return 0; }
_UINT32 CPPTXFile::LoadFromFile(std::wstring sSrcFileName, std::wstring sDstPath, std::wstring sXMLOptions) { std::wstring localTempDir(sDstPath); if(!localTempDir.empty()) { bool res = NSDirectory::CreateDirectory(localTempDir); if (res == false) return AVS_FILEUTILS_ERROR_CONVERT; put_TempDirectory(sDstPath); } else { bool res = NSDirectory::CreateDirectory(m_strTempDir); if (res == false) return AVS_FILEUTILS_ERROR_CONVERT; } localTempDir = m_strTempDir; std::wstring srcFileName = sSrcFileName; if (m_pCallbackArg) { if(!m_fCallbackExtract(m_pCallbackArg, srcFileName , localTempDir)) return AVS_FILEUTILS_ERROR_CONVERT; } else { localTempDir = sSrcFileName; } RELEASEOBJECT(m_pPptxDocument); m_pPptxDocument = new PPTX::Document(); if(!m_pPptxDocument->isValid(localTempDir)) { RELEASEOBJECT(m_pPptxDocument); return AVS_FILEUTILS_ERROR_CONVERT; } m_pPptxDocument->read(localTempDir, (PPTX::IPPTXEvent*)this); if(GetPercent() < 1000000) { RELEASEOBJECT(m_pPptxDocument); return AVS_FILEUTILS_ERROR_CONVERT; } smart_ptr<PPTX::Presentation> presentation = m_pPptxDocument->Get(OOX::Presentation::FileTypes::Presentation).smart_dynamic_cast<PPTX::Presentation>(); if (!presentation.is_init()) { NSDirectory::DeleteDirectory(m_strTempDir, false); return AVS_FILEUTILS_ERROR_CONVERT; } m_strDirectory = sSrcFileName; size_t nIndex = m_strDirectory.rfind(FILE_SEPARATOR_CHAR); if (std::wstring::npos != nIndex) m_strDirectory = m_strDirectory.substr(0, nIndex); return 0; }
void PieDraw::PaintPie(Draw& w, int scale) { Size sz = GetSize(); w.DrawRect(scale*sz, backColor); Size textsize; textsize.cx = 0; textsize.cy = 0; if(!title.IsEmpty()) { Font FontTitle6; FontTitle6 = titleFont; FontTitle6.Height(scale*titleFont.GetHeight()); FontTitle6.Width(scale*titleFont.GetWidth()); textsize = GetTextSize(title, FontTitle6); if(titlePos == TOP) w.DrawText((scale*GetSize().cx - textsize.cx)/2, scale*titleGap, title, FontTitle6,titleColor); else w.DrawText((scale*GetSize().cx - textsize.cx)/2, scale*(GetSize().cy - titleFont.GetHeight() - titleGap), title, FontTitle6,titleColor); } if(vValues.IsEmpty()) return; int alfa0 = -900; int a0 = 0; double sum = 0; for(int i = 0; i < vValues.GetCount(); i++) sum += vValues[i]; double circWidth = sz.cx - pieMarginLeft - pieMarginRight; if (circWidth < 0) circWidth = 0; double circHeight = sz.cy - pieMarginTop - textsize.cy - pieMarginBottom; if (circHeight < 0) circHeight = 0; double circ_r; if (circWidth > circHeight) circ_r = circHeight/2.; else circ_r = circWidth/2.; double circ_x = pieMarginLeft + circWidth/2.; double circ_y; if(titlePos == TOP) circ_y = pieMarginTop + titleGap + textsize.cy + circHeight/2.; else circ_y = pieMarginTop + circHeight/2.; circ_x *= scale; circ_y *= scale; circ_r *= scale; Color bc; if (IsNull(backColor)) bc = LtGray; else bc = backColor; for(int i = 0; i < vValues.GetCount(); i++) { DrawPie(w, circ_x*scale, circ_y*scale, circ_r*scale, alfa0, fround(3600.0*vValues.At(i)/sum), 1*scale, vColors.At(i), vColors.At(i), 0, bc); alfa0 += fround(3600.0*vValues[i]/sum); } if(showPercent) { alfa0 = -900; for(int i = 0; i < vValues.GetCount(); i++) { a0 = alfa0; alfa0 += fround(3600.0*vValues[i]/sum); String percent = GetPercent(vValues[i],sum); Font scaledFont; scaledFont.Height(scale*StdFont().GetHeight()); scaledFont.Width(scale*StdFont().GetWidth()); Size sz = GetTextSize(percent, scaledFont); int px = int(circ_x + scale*circ_r*cos(M_PI*(alfa0+a0)/3600)/1.3 - sz.cx/2.); int py = int(circ_y + scale*circ_r*sin(M_PI*(alfa0+a0)/3600)/1.3 - sz.cy/2.); w.DrawRect(px, py, sz.cx, 1, percentBack); w.DrawRect(px-1, py + 1, sz.cx + 2, sz.cy-2, percentBack); w.DrawRect(px, py + sz.cy - 1, sz.cx, 1, percentBack); w.DrawText(px, py, percent, scaledFont); } } if(showLegend) { double leg_x = -legendLeft + sz.cx - legendWidth; double leg_y; if (IsNull(legendTop)) leg_y = int(circ_y - scale*legendHeight/2.); else leg_y = legendTop*scale; w.DrawRect(int(leg_x), int(leg_y), scale*legendWidth, scale*legendHeight, legendBackColor); int nr = GetCatCount(); int dly = scale*legendHeight/nr; for(int i = 0; i < nr; i++) { int fh = scale*(legendFont.GetHeight()-3); w.DrawRect(int(leg_x) + 2*scale, int(leg_y) + i*dly + int(dly/2.) - fh/2, fh, fh, vColors[i]); Font scaledFont; scaledFont.Height(scale*legendFont.GetHeight()); scaledFont.Width(scale*legendFont.GetWidth()); w.DrawText(int(leg_x) + fround(1.8*fh), int(leg_y) + i*dly + int((dly - scaledFont.GetLineHeight())/2), vNames[i], scaledFont, legendTextColor); } } }
CExtGridCellEx* PropertiesBar::AddPropertyItemToTree(CPropItem& item, CExtPropertyItem* pRoot, CString& retStr, PropReturn& Return) { CExtGridCellString* pString; CExtGridCellDropListComboBox* pCombo; CExtGridCellNumber* pNumber; CExtGridCellCurrency* pCurr; CExtGridCellCheckBox* pCheck; CExtGridCellColor* pColor; CExtGridCellHyperLink* pLink; CExtGridCellSlider* pSlider; CExtGridCellFont* pFont; switch (item.Type) { // Edit case 0: { pString = GetEdit(pRoot); pString->TextSet(retStr); return pString; } // Static case 1: { pString = GetEdit(pRoot); pString->TextSet(retStr); pString->ModifyStyle(__EGCS_READ_ONLY | __EGCS_NO_INPLACE_CONTROL); return pString; } // Button case 2: { pLink = GetHyperLink(pRoot); pLink->TextSet(item.Text); return pLink; } // Value case 3: { pNumber = GetInteger(pRoot); pNumber->_VariantAssign(Return.val); return pNumber; } // Combo case 4: { pCombo = GetCombo(pRoot); // Add items CString Work = item.Text; int count = Work.Replace("|", ""); count++; for (int e = 0; e < count; e++) { CString tok; AfxExtractSubString(tok, item.Text, e, '|'); pCombo->InsertString(tok); } pCombo->SetCurSel(Return.val); return pCombo; } // Float case 5: { pNumber = GetFloat(pRoot); pNumber->_VariantAssign(Return.fVal); return pNumber; } // Color case 6: { pColor = GetColor(pRoot); pColor->SetColor((COLORREF)Return.val); return pColor; } // Checkbox (bool) case 7: { pCheck = GetCheckBox(pRoot); pCheck->SetCheck(Return.val); return pCheck; } // Font case 8: { pFont = GetFont(pRoot); return pFont; } // Percentage case 9: { pCurr = GetPercent(pRoot); pCurr->_VariantAssign(Return.fVal * 100.0); return pCurr; } // Slider (same as value) case 10: { pSlider = GetSlider(pRoot); pSlider->SetPos(Return.val); return pSlider; } // Frame property (int) case 11: { pCombo = GetCombo(pRoot); // Add frames for (int e = 0; e < m_pCurrentApplication->layouts.GetSize(); e++) pCombo->InsertString(m_pCurrentApplication->layouts.GetAt(m_pCurrentApplication->layouts.FindIndex(e))->GetName()); pCombo->SetCurSel(Return.val); return pCombo; } } // Invalid return NULL; }
// This method returns our deformer object Deformer& SpherifyMod::GetDeformer(TimeValue t, ModContext &mc, Matrix3 mat, Matrix3 invmat) { static SpherifyDeformer deformer; deformer = SpherifyDeformer(t, mc, mat, invmat, GetPercent(t)); return deformer; };