/************************************************************************* Recaculate all sub window size. *************************************************************************/ void FalagardChatHistory::performWindowLayout(void) { Rect absarea(getTextRenderArea()); std::list< FalagardChatBoard* >::iterator it; float fHeightNow = 0.0f; for(it=m_listChatBoard.begin(); it!=m_listChatBoard.end(); it++) { FalagardChatBoard& child = *(*it); if(child.getText().empty()) continue; float childHeight = child.resizeSelf(absarea.getWidth()); child.setSize(Absolute, Size(absarea.getWidth(), childHeight)); child.setPosition(Absolute, Point(0.0f, fHeightNow-d_vertScrollbar->getScrollPosition())); child.requestRedraw(); fHeightNow += childHeight; //char dbgmsg[128] = {0}; //_snprintf(dbgmsg, 127, "FalagardChatHistory performWindowLayout fHeightNow:%f ScrollPos:%f, child YPos:%f\n", // fHeightNow,d_vertScrollbar->getScrollPosition(),child.getAbsoluteYPosition()); //::OutputDebugString(dbgmsg); } d_totalHeight = fHeightNow + d_extendHeight; configureScrollbars(); }
/************************************************************************* Checks the mouse cursor position is within the current 'constrain' Rect and adjusts as required. *************************************************************************/ void MouseCursor::constrainPosition(void) { Rect absarea(getConstraintArea()); if (d_position.d_x >= absarea.d_right) d_position.d_x = absarea.d_right -1; if (d_position.d_y >= absarea.d_bottom) d_position.d_y = absarea.d_bottom -1; if (d_position.d_y < absarea.d_top) d_position.d_y = absarea.d_top; if (d_position.d_x < absarea.d_left) d_position.d_x = absarea.d_left; }
/************************************************************************* Extend a Clear Region in history window. *************************************************************************/ void FalagardChatHistory::extendClearRegion() { if(m_listChatBoard.empty()) { d_extendHeight = 0.0f; return; } //scroll to end before extend scrollToEnd(); Rect absarea(getTextRenderArea()); d_extendHeight = absarea.getHeight(); performWindowLayout(); //set new scroll pos after extend d_vertScrollbar->setScrollPosition( d_vertScrollbar->getDocumentSize()-d_vertScrollbar->getPageSize()+d_extendHeight); }
void CPFRotatingText::renderRotatingText() { Font* font = d_window->getFont(); // can't render text without a font :) if( font==NULL){ return; } // get destination area for the text. Rect absarea(getTextRenderArea()); Rect clipper(absarea); float textHeight = font->getFormattedLineCount(d_window->getText(), absarea, (TextFormatting)d_horzFormatting) * font->getLineSpacing(); Scrollbar* vertScrollbar = getVertScrollbar(); Scrollbar* horzScrollbar = getHorzScrollbar(); // calculate X offset static float xOffset = horzScrollbar->getPageSize(); if( xOffset<-(horzScrollbar->getDocumentSize()+horzScrollbar->getPageSize()) ){ xOffset = horzScrollbar->getPageSize(); } static boost::system_time previous_time = boost::get_system_time(); boost::system_time time = boost::get_system_time(); boost::system_time::time_duration_type time_step = (time-previous_time); xOffset -= (static_cast<float>(time_step.total_milliseconds())*d_textSpeed); previous_time = time; absarea.offset(Point(xOffset, 0)); // see if we may need to adjust horizontal position if( horzScrollbar->isVisible() ){ switch(d_horzFormatting) { case LeftAligned: case WordWrapLeftAligned: case Justified: case WordWrapJustified: absarea.offset(Point(-horzScrollbar->getScrollPosition(), 0)); break; case Centred: case WordWrapCentred: absarea.setWidth(horzScrollbar->getDocumentSize()); absarea.offset(Point(-horzScrollbar->getScrollPosition(), 0)); break; case RightAligned: case WordWrapRightAligned: absarea.offset(Point(horzScrollbar->getScrollPosition(), 0)); break; } } // adjust y positioning according to formatting option switch(d_vertFormatting) { case TopAligned: absarea.d_top -= vertScrollbar->getScrollPosition(); break; case VertCentred: // if scroll bar is in use, act like TopAligned if( vertScrollbar->isVisible() ){ absarea.d_top -= vertScrollbar->getScrollPosition(); } // no scroll bar, so centre text instead. else{ absarea.d_top += PixelAligned((absarea.getHeight() - textHeight) * 0.5f); } break; case BottomAligned: absarea.d_top = absarea.d_bottom - textHeight; absarea.d_top += vertScrollbar->getScrollPosition(); break; } // offset the font little down so that it's centered within its own spacing absarea.d_top += (font->getLineSpacing() - font->getFontHeight()) * 0.5f; // calculate final colours ColourRect final_cols(d_textCols); final_cols.modulateAlpha(d_window->getEffectiveAlpha()); // cache the text for rendering. d_window->getRenderCache().cacheText(d_window->getText(), font, (TextFormatting)d_horzFormatting, absarea, 0, final_cols, &clipper); }
Window* FalagardChatHistory::insertChatString(int msgid,const String32& strChat, int nTalkerLength, int nOp/* = -1*/) { //2 refresh only. Change for respond speed.[7/13/2006] if(insert_refresh_only == nOp) { performWindowLayout(); return 0; } float topHeight = 0; FalagardChatBoard* pWindow = 0; if(m_listChatBoard.size() == d_chatBoardNum && m_listChatBoard.size() > 0) { /* Change for respond speed.[7/13/2006] FalagardChatBoard* pChild = static_cast<FalagardChatBoard*>(d_parentWindow->getChild((uint)0)); pChild->clearInfoItem(); d_parentWindow->removeChildWindow((uint)0); */ pWindow = *(m_listChatBoard.begin()); if(pWindow->isVisible() == false || pWindow->getText().empty()) topHeight = 0.0f; else topHeight = pWindow->resizeSelf(getTextRenderArea().getWidth()); pWindow->clearInfoItem(); pWindow->clearKillTime(); pWindow->setText(""); pWindow->show(); if ( !d_hollow ) { pWindow->setBoardHollow( d_hollow ); } m_listChatBoard.erase(m_listChatBoard.begin()); } else { pWindow = static_cast<FalagardChatBoard*>(WindowManager::getSingleton().createWindow( m_mapChildType[ "ChatBoard" ] ) ); //pWindow->setText(strChat); pWindow->show(); //pWindow->setMouseLButtonHollow(true); pWindow->subscribeEvent(FalagardChatBoard::EventInfoElementLClick, Event::Subscriber(&FalagardChatHistory::handleInfoItemBtnClick, this)); pWindow->subscribeEvent(FalagardChatBoard::EventInfoElementRClick, Event::Subscriber(&FalagardChatHistory::handleInfoItemBtnClick, this)); pWindow->subscribeEvent(FalagardChatBoard::EventInfoElementDelete, Event::Subscriber(&FalagardChatHistory::handleInfoItemDelete, this)); pWindow->subscribeEvent(FalagardChatBoard::EventInfoElementMoveIn, Event::Subscriber(&FalagardChatHistory::handleInfoItemMoveIn, this)); pWindow->subscribeEvent(FalagardChatBoard::EventInfoElementMoveOut, Event::Subscriber(&FalagardChatHistory::handleInfoItemMoveOut, this)); pWindow->subscribeEvent(FalagardChatBoard::EventKillBoard, Event::Subscriber(&FalagardChatHistory::handleBoardKillTime, this)); if ( !d_hollow ) { pWindow->setBoardHollow( d_hollow ); } d_parentWindow->addChildWindow(pWindow); } setChatBoardString(pWindow, strChat, nTalkerLength); pWindow->setmsgID(msgid); m_listChatBoard.push_back(pWindow); //InsertOperation switch switch(nOp) { case insert_kill_add_only: pWindow->setKillTime(float(d_boardKillTimer)); case insert_add_only: return pWindow; case insert_kill_normal: pWindow->setKillTime(float(d_boardKillTimer)); case insert_refresh_only: case insert_normal: default: break; } float posEnd = d_vertScrollbar->getDocumentSize()-d_vertScrollbar->getPageSize(); bool bPosEnd = (posEnd - d_vertScrollbar->getScrollPosition() < (1e-08f)) && posEnd>0?true:false; float fWinHeight = pWindow->resizeSelf(getTextRenderArea().getWidth()); //use d_extendHeight first. if(d_extendHeight > 0.0f) { d_extendHeight = (d_extendHeight - fWinHeight > 0.0f)?(d_extendHeight - fWinHeight):0.0f; } performWindowLayout(); if(bPosEnd || (d_vertScrollbar->getDocumentSize()-d_vertScrollbar->getPageSize()>0 && d_first)) { //scroll to end d_vertScrollbar->setScrollPosition( d_vertScrollbar->getDocumentSize()-d_vertScrollbar->getPageSize()); d_first = false; } if(!bPosEnd /*&& m_listChatBoard.size() == d_chatBoardNum*/ ) { Rect absarea(getTextRenderArea()); if(d_vertScrollbar->getScrollPosition() - topHeight > (1e-08f)) { //scroll up a new chatboard window's height d_vertScrollbar->setScrollPosition( d_vertScrollbar->getScrollPosition() - topHeight); } else { d_vertScrollbar->setScrollPosition( d_vertScrollbar->getDocumentSize()-d_vertScrollbar->getPageSize()); } } return pWindow; }