📄 txtattrb.cpp
字号:
// we reduce the end time by 1 millisec to ensure that it // goes away at t: m_endTime = (ulNewEndTime>0L? ulNewEndTime-1L:0L); if(bIsLiveSource) { // Also, if it ends up being 0, set it to TIME_INFINITY // (which is 0xfffffffe). Also, if ulNewEndTime is // TIME_INVALID, then m_endTime will be set to // TIME_INVALID-1 which is TIME_INFINITY: m_endTime = (ulNewEndTime>1L? ulNewEndTime-1L:TIME_INFINITY); } return TRUE; } return FALSE; } return FALSE;}///////////////////////////////////////////////////////////////////////////////// This gets called in OnTimeSynch() to compute where the text should be// dislayed based on the current time://LONG32 TextAttributes::ComputeCrawlDelta( ULONG32 ulCurTime, LONG32 crawlrate){ ULONG32 retVal = //Avoid overflow by casting to double and then back: //NOTE: the casting to double here is ONLY to avoid // overflow and does not need special floating-point // consideration for fixed-point code conversion, // i.e., precision does not need to be maintainted: ULONG32((double(crawlrate) * double(ulCurTime)) / 1000.0); return retVal;}///////////////////////////////////////////////////////////////////////////////// This gets called in OnTimeSynch() to compute where the text should be// dislayed based on the current time://LONG32 TextAttributes::ComputeScrollDelta( ULONG32 ulCurTime, LONG32 scrollrate){ ULONG32 retVal = //Avoid overflow by casting to double and then back: //NOTE: the casting to double here is ONLY to avoid // overflow and does not need special floating-point // consideration for fixed-point code conversion, // i.e., precision does not need to be maintainted: ULONG32((double(scrollrate) * double(ulCurTime)) / 1000.0); return retVal;}///////////////////////////////////////////////////////////////////////////////// //Changes the start and end times of *this if refTA's// start or end time is earlier or later, respectively, than this's; this// is used by TextList which updates for each TextContainer (each of which// inherit TextAttributes)://// returns FALSE if pTA is somehow invalid.//BOOL TextAttributes::updateStartAndEndTimes(TextAttributes* pTA, BOOL bIsLiveSource){ if(!pTA) { return FALSE; } if(IsTimeAMoreRecentThanTimeB( getStartTime(), pTA->getStartTime(), bIsLiveSource) ) { setStartTime(pTA->getStartTime()); } if(IsTimeAMoreRecentThanTimeB( pTA->getEndTime(), getEndTime(), bIsLiveSource) ) { setEndTime(pTA->getEndTime()); } return TRUE;}///////////////////////////////////////////////////////////////////////////////// //Changes the start and end times of *this as// calculated by "appearance" of the text in the window, i.e.,// if there is a scrollrate or crawlrate, this calculates when it first// becomes visible in the window and then when it moves back out.//// returns FALSE if pTW is somehow invalid.//BOOL TextAttributes::adjustStartAndEndTimes(TextWindow* pTW){ if(!pTW) { return FALSE; } LONG32 windowWidth = pTW->getWidth(); LONG32 windowHeight = pTW->getHeight(); LONG32 scrollRate = pTW->getScrollRate(); LONG32 crawlRate = pTW->getCrawlRate(); if(!scrollRate && !crawlRate) { return TRUE; //nothing more to do! } ULONG32 ulTimeItScrollsIntoWindow = 0L; ULONG32 ulTimeItScrollsOutOfWindow = 0L; ULONG32 ulTimeItCrawlsIntoWindow = 0L; ULONG32 ulTimeItCrawlsOutOfWindow = 0L;/* ULONG32 ulTimeDiff;*/ BOOL bFirstIsMoreRecent; BOOL bIsLiveSource = pTW->isLiveSource(); if(scrollRate) { //Now, calculate what time it will be when the text of *this // is just entering the window due to scrolling: if(m_yAtTimeZeroUpperLeftCorner - windowHeight > 0L)//pos vals only!! { ulTimeItScrollsIntoWindow = //Changed the order to fix missing-live-text bug (and // on-demand bug, too, if duration is very high); // this should be 21199150 at t=4239830seconds // with scrollrate=5, not 4019286 as it used to be // due to the order of multiplication causing an // overflow at high values (4019286 = 21199150 // modulo [0xFFFFFFFF/1000] ) //NOTE: the casting to double here is ONLY to avoid // overflow and does not need special floating-point // consideration for fixed-point code conversion, // i.e., precision does not need to be maintainted: ULONG32(1000.0 * //(converts to milliseconds) (((double)m_yAtTimeZeroUpperLeftCorner- (double)windowHeight)/ (double)scrollRate) ); if(IsTimeAMoreRecentThanTimeB( ulTimeItScrollsIntoWindow, getStartTime(), bIsLiveSource) ) { setStartTime(ulTimeItScrollsIntoWindow); } } //Now, calculate what time it will be when the text of *this // is just leaving the window due to scrolling: if(m_yAtTimeZeroUpperLeftCorner + m_yExtent > 0L)//pos vals only!! { ulTimeItScrollsOutOfWindow = ULONG32(1000.0 * //(converts to milliseconds) //NOTE: the casting to double here is ONLY to avoid // overflow and does not need special floating-point // consideration for fixed-point code conversion, // i.e., precision does not need to be maintainted: (((double)m_yAtTimeZeroUpperLeftCorner + (double)m_yExtent) / (double)scrollRate) ); bFirstIsMoreRecent = IsTimeAMoreRecentThanTimeB( getEndTime(), ulTimeItScrollsOutOfWindow, bIsLiveSource); if(bFirstIsMoreRecent //Note: for live, this will work becuase endTime (and // other times) will never be set to 0: || getEndTime()==0) //added this in case endtime init->0 { bFirstIsMoreRecent = IsTimeAMoreRecentThanTimeB( ulTimeItScrollsOutOfWindow, m_beginTime, bIsLiveSource); setEndTime(bFirstIsMoreRecent? ulTimeItScrollsOutOfWindow:m_beginTime); } } } if(crawlRate) { //Now, calculate what time it will be when the text of *this // is just entering the window due to crawling: if(m_xAtTimeZeroUpperLeftCorner - windowWidth > 0L)//pos vals only!! { ulTimeItCrawlsIntoWindow = ULONG32(1000.0 * //(converts to milliseconds) //NOTE: the casting to double here is ONLY to avoid // overflow and does not need special floating-point // consideration for fixed-point code conversion, // i.e., precision does not need to be maintainted: (((double)m_xAtTimeZeroUpperLeftCorner - (double)windowWidth)/ (double)crawlRate) ); if(IsTimeAMoreRecentThanTimeB( ulTimeItCrawlsIntoWindow, getStartTime(), bIsLiveSource) ) { setStartTime(ulTimeItCrawlsIntoWindow); } } //Now, calculate what time it will be when the text of *this // is just leaving the window due to crawling: if(m_xAtTimeZeroUpperLeftCorner + m_xExtent > 0L)//pos vals only!! { ulTimeItCrawlsOutOfWindow = ULONG32(1000.0 * //(converts to milliseconds) //NOTE: the casting to double here is ONLY to avoid // overflow and does not need special floating-point // consideration for fixed-point code conversion, // i.e., precision does not need to be maintainted: (((double)m_xAtTimeZeroUpperLeftCorner + (double)m_xExtent) / (double)crawlRate) ); bFirstIsMoreRecent = IsTimeAMoreRecentThanTimeB( getEndTime(), ulTimeItCrawlsOutOfWindow, bIsLiveSource); if(bFirstIsMoreRecent //tXXXXXEH: handle this for live (not sure how...): || getEndTime()==0) //added this in case endtime init->0 { bFirstIsMoreRecent = IsTimeAMoreRecentThanTimeB( ulTimeItCrawlsOutOfWindow, m_beginTime, bIsLiveSource); setEndTime(bFirstIsMoreRecent? ulTimeItCrawlsOutOfWindow:m_beginTime); } } } return TRUE;} ///////////////////////////////////////////////////////////////////////////////// TextAttribStack methods:///* [are inside the header file]*////////////////////////////////////////////////////////////////////////////////// TextAttributeStacks methods://///////////////////////////////////////////////////////////////////////////////// TextAttributeStacks constructor://TextAttributeStacks::TextAttributeStacks() : m_ulRequiredTagCount(0L), m_ulPreTagCount(0L) , m_bIsTickerUpperText(TRUE){ flush(); m_fontStack.init(DEFAULT_TEXT_COLOR); m_fontFaceStack.init(DEFAULT_FONT_FACE_INDX); m_textColorStack.init(DEFAULT_TEXT_COLOR); m_textBackgroundColorStack.init(DEFAULT_TEXT_BGCOLOR); m_fontCharsetStack.init(CHARSET__default); m_fontPointSizeStack.init(DEFAULT_FONT_PTSIZE); m_tickerUpperColorStack.init(DEFAULT_TICKER_UPPERCOLOR); m_tickerLowerColorStack.init(DEFAULT_TICKER_LOWERCOLOR); m_isBoldStack.init(FALSE); m_isItalicizedStack.init(FALSE); m_isUnderlinedStack.init(FALSE); m_isStruckOutStack.init(FALSE); m_blinkRateStack.init(DEFAULT_BLINKRATE); m_isCenteredStack.init(FALSE); //added this for indenting text in lists & as requested: m_lineIndentAmtInPixelsStack.init(0); m_fontTagStartByteInFileStack.init(0);}///////////////////////////////////////////////////////////////////////////////// TextAttributeStacks flush() which clears the stack except for the default// value, which is left at the bottom of the stack://void TextAttributeStacks::flush(){ flushFontStacks(); flushTickerStacks(); flushBIUSandBlinkStacks(); flushIndentAmtStack();}///////////////////////////////////////////////////////////////////////////////void TextAttributeStacks::flushFontStacks(){ m_fontStack.removeAll(); m_fontFaceStack.removeAll(); m_textColorStack.removeAll(); m_textBackgroundColorStack.removeAll(); m_fontCharsetStack.removeAll(); m_fontPointSizeStack.removeAll();}///////////////////////////////////////////////////////////////////////////////void TextAttributeStacks::flushTickerStacks(){ m_tickerUpperColorStack.removeAll(); m_tickerLowerColorStack.removeAll(); m_bIsTickerUpperText = TRUE;}///////////////////////////////////////////////////////////////////////////////void TextAttributeStacks::flushBIUSandBlinkStacks(){ m_isBoldStack.removeAll(); m_isItalicizedStack.removeAll(); m_isUnderlinedStack.removeAll(); m_isStruckOutStack.removeAll(); m_blinkRateStack.removeAll(); m_isCenteredStack.removeAll(); m_ulPreTagCount = 0L; m_ulRequiredTagCount = 0L;}///////////////////////////////////////////////////////////////////////////////void TextAttributeStacks::flushIndentAmtStack(){ m_lineIndentAmtInPixelsStack.removeAll();}///////////////////////////////////////////////////////////////////////////////// TextAttributeStacks function that sets a TextAttributes object's values// to match those on the current top of the stack://void TextAttributeStacks::setTextAttributesToTopsOfStacksVals( TextAttributes& ta){ ta.setTextColor(m_textColorStack.peek()); ta.setTextBackgroundColor(m_textBackgroundColorStack.peek()); ta.setTickerUpperColor(m_tickerUpperColorStack.peek()); ta.setTickerLowerColor(m_tickerLowerColorStack.peek()); ta.isTickerUpperText(m_bIsTickerUpperText); ta.setFontFace(m_fontFaceStack.peek()); //Added this line to handle charsets: ta.setFontCharset(m_fontCharsetStack.peek()); ta.setFontPointSize(m_fontPointSizeStack.peek()); ta.isBold((BOOL)m_isBoldStack.peek()); ta.isItalicized((BOOL)m_isItalicizedStack.peek()); ta.isUnderlined((BOOL)m_isUnderlinedStack.peek()); ta.isStruckOut((BOOL)m_isStruckOutStack.peek()); ta.setBlinkRate(m_blinkRateStack.peek()); ta.isCentered((BOOL)m_isCenteredStack.peek()); ta.isPreFormatted(peekAtIsPreStack()); ta.isRequired(m_ulRequiredTagCount); //added this for indenting text in lists and as requested: ta.setLineIndentAmtInPixels((UINT16)m_lineIndentAmtInPixelsStack.peek());}///////////////////////////////////////////////////////////////////////////////// TextAttributeStacks function that manages the contents of the // FontFace stack://void TextAttributeStacks::pushFontFaceStack(ULONG32 fontFaceIndex){ ULONG32 ulCopy = fontFaceIndex; m_fontFaceStack.push(ulCopy);}#ifdef _CARBON#pragma old_argmatch reset#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -