/********************************************************************** * CTextRun::Split * *-----------------* * Description: * Splits up a TextRun so that this text run now ends at lFirstEnd * and the second text run begins at lSecondBegin. * "This" will now be a shorter range (it will end sooner), * and *ppTextRun will point to the new text run * (space will be allocated here for *ppTextRun) * to be inserted in the list. * * Return: * S_OK * E_INVALIDARG * E_OUTOFMEMORY * Return value of ITextDocument::Range() **********************************************************************/ HRESULT CTextRun::Split( long *plFirstEnd, long *plSecondBegin, ITextDocument *cpTextDoc, CTextRun **ppTextRun ) { if ( !plFirstEnd || !plSecondBegin || !cpTextDoc || !ppTextRun ) { return E_INVALIDARG; } _ASSERTE( m_cpTextRange ); if ( !m_cpTextRange ) { return E_UNEXPECTED; } // These values won't be changing, since this run has no associated // RecoResult. // We can chop this block right at these positions. long lFirstEnd = *plFirstEnd; long lSecondBegin = *plSecondBegin; if ( !WithinRange( lFirstEnd ) || (lFirstEnd > lSecondBegin) ) { return E_INVALIDARG; } if ( (GetStart() == lSecondBegin) || (GetEnd() == lFirstEnd) || (lSecondBegin > GetEnd()) ) { // Don't need to do anything, since we are asking for both of the // cuts to be made on already-existing TextRun boundaries *ppTextRun = NULL; return S_OK; } *ppTextRun = new CTextRun(); if ( !(*ppTextRun) ) { return E_OUTOFMEMORY; } // The latter range will start at lSecondBegin and end where "this" ended long lEnd = GetEnd(); CComPtr<ITextRange> pLatterRange; HRESULT hr = cpTextDoc->Range( lSecondBegin, lEnd, &pLatterRange ); if ( FAILED( hr ) ) { return hr; } (*ppTextRun)->SetTextRange( pLatterRange ); // Adjust the end of "this"'s range; it will end at lFirstEnd m_cpTextRange->SetEnd( lFirstEnd ); return S_OK; } /* CTextRun::Split */
/********************************************************************** * CTextRun::HowManySpacesAfter * *------------------------------* * Description: * Returns the number of spaces that would need to precede text * if text were to be inserted at position lPos. * This number is in the out param puiSpaces. * For a text run this value will always be zero, since * typed text has no "display attributes" * Return: * S_OK * E_POINTER * E_INVALIDARG if lPos is out of range **********************************************************************/ HRESULT CTextRun::HowManySpacesAfter( const long lPos, UINT *puiSpaces ) { if ( !puiSpaces ) { return E_POINTER; } if ( !WithinRange( lPos ) ) { return E_INVALIDARG; } *puiSpaces = 0; return S_OK; } /* CTextRun::HowManySpacesAfter */
/********************************************************************** * CTextRun::IsConsumeLeadingSpaces * *----------------------------------* * Description: * Sets *pfConsumeLeadingSpaces to true iff leading spaces before * lPos would need to be consumed. * For a text run this value will always be false, since * typed text has no "display attributes" * Return: * S_OK * E_POINTER * E_INVALIDARG if lPos is out of range **********************************************************************/ HRESULT CTextRun::IsConsumeLeadingSpaces( const long lPos, bool *pfConsumeLeadingSpaces ) { if ( !pfConsumeLeadingSpaces ) { return E_POINTER; } if ( !WithinRange( lPos ) ) { return E_INVALIDARG; } *pfConsumeLeadingSpaces = false; return S_OK; } /* CTextRun::IsConsumeLeadingSpaces */
void psShadowManager::UpdateShadows() { if (!shadowsEnabled) return; const csPDelArray<GEMClientObject>& entities = psengine->GetCelClient()->GetEntities(); size_t len = entities.GetSize(); for (size_t a=0; a<len; ++a) { if (!WithinRange(entities[a])) { RemoveShadow(entities[a]); } else if(entities[a]->HasShadow()) { CreateShadow(entities[a]); } } }
void psShadowManager::CreateShadow(GEMClientObject * object) { if (!shadowsEnabled) return; if (!object) return; // don't create one if the object already has a shadow if (object->GetShadow()) return; csRef<iMeshWrapper> mesh = object->GetMesh(); if (!mesh || !mesh->GetMeshObject()) return; if (!WithinRange(object)) return; // calculate a suitable size for this shadow const csBox3& boundBox = object->GetBBox(); float scale = (boundBox.Max(0) + boundBox.Max(2)) * 0.75f; if (scale < 0.35f) scale = 0.35f; psEffectManager* effectMgr = psengine->GetEffectManager(); // Create the effect unsigned int id = effectMgr->RenderEffect("shadow", csVector3(0,0,0), mesh); psEffect* effect = effectMgr->FindEffect(id); if (!effect) return; effect->SetScaling(scale, 1.0f); object->SetShadow(effect); }
/********************************************************************** * CTextRun::Speak() * *-------------------* * Description: * Uses *plStart and *plEnd to find the nearest start and * endpoints for speaking (to the nearest word). * Returns these values in plStart and plEnd. * Speaks the text associated with this CTextRun from *plStart * to *plEnd. * * If *plStart is not within the range, then * start at the beginning. If lEnd is not within range, then * end at the end. * * Return: * S_OK * E_POINTER * Return value of CTextRun::Speak() **********************************************************************/ HRESULT CTextRun::Speak( ISpVoice &rVoice, long *plStart, long *plEnd ) { if ( !plStart || !plEnd ) { return E_POINTER; } _ASSERTE( m_cpTextRange ); if ( !m_cpTextRange ) { return E_UNEXPECTED; } // Save the old range long lOldStart = GetStart(); long lOldEnd = GetEnd(); // Out of range start or end means we start speaking from the start // or end (resp.) of the text range. if ( WithinRange( *plStart ) ) { // The start needs to be moved SetStart( *plStart ); } else { *plStart = GetStart(); } if ( WithinRange( *plEnd ) ) { // The end needs to be moved SetEnd( *plEnd ); } else { *plEnd = GetEnd(); } // Expand to include whole words m_cpTextRange->Expand( tomWord, NULL ); // Get the new start and end so that we can pass them back m_cpTextRange->GetStart( plStart ); m_cpTextRange->GetEnd( plEnd ); // We should never speak past the end of this run, even if expanding to include // whole words caused extra text to be included // (e.g. if you typed "This is a sentence" and dictated some text that // consumed leading spaces right afterwards) *plStart = __max( *plStart, lOldStart ); *plEnd = __min( *plEnd, lOldEnd ); SetStart( *plStart ); SetEnd( *plEnd ); // Pass to the CTextRun::Speak() that speaks an entire run HRESULT hr = Speak( rVoice ); // Restore the old range limits SetStart( lOldStart ); SetEnd( lOldEnd ); return hr; } /* CTextRun::Speak */