//----------------------------------------------------------------------------// bool ScrollablePane::handleContentAreaChange(const EventArgs&) { Scrollbar* vertScrollbar = getVertScrollbar(); Scrollbar* horzScrollbar = getHorzScrollbar(); // get updated extents of the content Rect contentArea(getScrolledContainer()->getContentArea()); // calculate any change on the top and left edges. float xChange = contentArea.d_left - d_contentRect.d_left; float yChange = contentArea.d_top - d_contentRect.d_top; // store new content extents information d_contentRect = contentArea; configureScrollbars(); // update scrollbar positions (which causes container pane to be moved as needed). horzScrollbar->setScrollPosition(horzScrollbar->getScrollPosition() - xChange); vertScrollbar->setScrollPosition(vertScrollbar->getScrollPosition() - yChange); // this call may already have been made if the scroll positions changed. The call // is required here for cases where the top/left 'bias' has changed; in which // case the scroll position notification may or may not have been fired. if (xChange || yChange) updateContainerPosition(); // fire event WindowEventArgs args(this); onContentPaneChanged(args); return true; }
bool GVEvent::HandYMove(const CEGUI::EventArgs& args) { Scrollbar *sb = static_cast<Scrollbar*>( static_cast<const WindowEventArgs&> (args).window); static float yoldPos= DEFAULT_YTRANS; float curmove = sb->getScrollPosition() - yoldPos; yoldPos = sb->getScrollPosition(); GetInst(GoodsRender).SetTranAdd(0,curmove,0); return true; }
bool GVEvent::HandZRot(const CEGUI::EventArgs& args) { Scrollbar *sb = static_cast<Scrollbar*>( static_cast<const WindowEventArgs&> (args).window); static float oldpos = 180; float curval = sb->getScrollPosition() - oldpos; oldpos = sb->getScrollPosition(); GetInst(GoodsRender).ReSetRotAngle(D3DXToRadian(0),D3DXToRadian(0),D3DXToRadian(curval)); return true; }
/************************************************************************ Configure scroll bars ************************************************************************/ void ScrolledItemListBase::configureScrollbars(const Size& doc_size) { Scrollbar* v = getVertScrollbar(); Scrollbar* h = getHorzScrollbar(); Size render_area_size = getItemRenderArea().getSize(); // setup the pane size float pane_size_w = ceguimax(doc_size.d_width, render_area_size.d_width); UVector2 pane_size(cegui_absdim(pane_size_w), cegui_absdim(doc_size.d_height)); d_pane->setMinSize(pane_size); d_pane->setMaxSize(pane_size); //d_pane->setWindowSize(pane_size); // "fix" scrollbar visibility if (d_forceVScroll || doc_size.d_height > render_area_size.d_height) { v->show(); } else { v->hide(); } //render_area_size = getItemRenderArea().getSize(); if (d_forceHScroll || doc_size.d_width > render_area_size.d_width) { h->show(); } else { h->hide(); } // get a fresh item render area Rect render_area = getItemRenderArea(); render_area_size = render_area.getSize(); // update the pane clipper area static_cast<ClippedContainer*>(d_pane)->setClipArea(render_area); // setup vertical scrollbar v->setDocumentSize(doc_size.d_height); v->setPageSize(render_area_size.d_height); v->setStepSize(ceguimax(1.0f, render_area_size.d_height / 10.0f)); v->setScrollPosition(v->getScrollPosition()); // setup horizontal scrollbar h->setDocumentSize(doc_size.d_width); h->setPageSize(render_area_size.d_width); h->setStepSize(ceguimax(1.0f, render_area_size.d_width / 10.0f)); h->setScrollPosition(h->getScrollPosition()); }
bool GuiConfig::handleMusicVolChanged(const CEGUI::EventArgs& e) { Scrollbar *pcb = (Scrollbar*)winMgr.getWindow("MUSICVOLUME"); GConfig->SetQuality("MUSICVOLUME", (int)(pcb->getScrollPosition()) ); GProtoGui->MusicVolumeChanged(); return true; }
bool ScrolledItemListBase::handle_HScroll(const EventArgs& e) { const WindowEventArgs& we = static_cast<const WindowEventArgs&>(e); Scrollbar* h = static_cast<Scrollbar*>(we.window); float newpos = -h->getScrollPosition(); d_pane->setXPosition(cegui_absdim(newpos)); return true; }
bool GVEvent::HandScal(const CEGUI::EventArgs& args) { Scrollbar *sb = static_cast<Scrollbar*>( static_cast<const WindowEventArgs&> (args).window); float scal = sb->getScrollPosition() / sb->getDocumentSize() * DEFAULT_SCALE ; GetInst(GoodsRender).ResetScal(scal); return true; }
/************************************************************************ Event subscribers for scrolling ************************************************************************/ bool ScrolledItemListBase::handle_VScroll(const EventArgs& e) { const WindowEventArgs& we = static_cast<const WindowEventArgs&>(e); Scrollbar* v = static_cast<Scrollbar*>(we.window); Rect render_area = getItemRenderArea(); float newpos = -v->getScrollPosition()+render_area.d_top; d_pane->setYPosition(cegui_absdim(newpos)); return true; }
/************************************************************************* Handler for mouse wheel changes *************************************************************************/ void Listbox::onMouseWheel(MouseEventArgs& e) { // base class processing. Window::onMouseWheel(e); Scrollbar* vertScrollbar = getVertScrollbar(); Scrollbar* horzScrollbar = getHorzScrollbar(); if (vertScrollbar->isVisible() && (vertScrollbar->getDocumentSize() > vertScrollbar->getPageSize())) { vertScrollbar->setScrollPosition(vertScrollbar->getScrollPosition() + vertScrollbar->getStepSize() * -e.wheelChange); } else if (horzScrollbar->isVisible() && (horzScrollbar->getDocumentSize() > horzScrollbar->getPageSize())) { horzScrollbar->setScrollPosition(horzScrollbar->getScrollPosition() + horzScrollbar->getStepSize() * -e.wheelChange); } ++e.handled; }
//----------------------------------------------------------------------------// void ScrollablePane::configureScrollbars(void) { // controls should all be valid by this stage Scrollbar* vertScrollbar = getVertScrollbar(); Scrollbar* horzScrollbar = getHorzScrollbar(); // enable required scrollbars vertScrollbar->setVisible(isVertScrollbarNeeded()); horzScrollbar->setVisible(isHorzScrollbarNeeded()); // Check if the addition of the horizontal scrollbar means we // now also need the vertical bar. if (horzScrollbar->isVisible()) { vertScrollbar->setVisible(isVertScrollbarNeeded()); } performChildWindowLayout(); // get viewable area Rect viewableArea(getViewableArea()); // set up vertical scroll bar values vertScrollbar->setDocumentSize(fabsf(d_contentRect.getHeight())); vertScrollbar->setPageSize(viewableArea.getHeight()); vertScrollbar->setStepSize(ceguimax(1.0f, viewableArea.getHeight() * d_vertStep)); vertScrollbar->setOverlapSize(ceguimax(1.0f, viewableArea.getHeight() * d_vertOverlap)); vertScrollbar->setScrollPosition(vertScrollbar->getScrollPosition()); // set up horizontal scroll bar values horzScrollbar->setDocumentSize(fabsf(d_contentRect.getWidth())); horzScrollbar->setPageSize(viewableArea.getWidth()); horzScrollbar->setStepSize(ceguimax(1.0f, viewableArea.getWidth() * d_horzStep)); horzScrollbar->setOverlapSize(ceguimax(1.0f, viewableArea.getWidth() * d_horzOverlap)); horzScrollbar->setScrollPosition(horzScrollbar->getScrollPosition()); }
/************************************************************************* Ensure the item at the specified index is visible within the list box. *************************************************************************/ void Listbox::ensureItemIsVisible(size_t item_index) { Scrollbar* vertScrollbar = getVertScrollbar(); // handle simple "scroll to the bottom" case if (item_index >= getItemCount()) { vertScrollbar->setScrollPosition(vertScrollbar->getDocumentSize() - vertScrollbar->getPageSize()); } else { float bottom; float listHeight = getListRenderArea().getHeight(); float top = 0; // get height to top of item size_t i; for (i = 0; i < item_index; ++i) { top += d_listItems[i]->getPixelSize().d_height; } // calculate height to bottom of item bottom = top + d_listItems[i]->getPixelSize().d_height; // account for current scrollbar value float currPos = vertScrollbar->getScrollPosition(); top -= currPos; bottom -= currPos; // if top is above the view area, or if item is too big to fit if ((top < 0.0f) || ((bottom - top) > listHeight)) { // scroll top of item to top of box. vertScrollbar->setScrollPosition(currPos + top); } // if bottom is below the view area else if (bottom >= listHeight) { // position bottom of item at the bottom of the list vertScrollbar->setScrollPosition(currPos + bottom - listHeight); } // Item is already fully visible - nothing more to do. } }
bool handleTabPadding(const EventArgs& e) { Scrollbar* sb = static_cast<Scrollbar*>( static_cast<const WindowEventArgs&>(e).window); // Check if the window exists Window* root = d_guiContext->getRootWindow(); if (root->isChild("Frame/TabControl")) { static_cast<TabControl*>(root->getChild( "Frame/TabControl"))->setTabTextPadding( UDim(0, sb->getScrollPosition())); } return true; }
bool handleTabHeight(const EventArgs& e) { Scrollbar* sb = static_cast<Scrollbar*>( static_cast<const WindowEventArgs&>(e).window); // Check if the window exists Window* root = d_guiContext->getRootWindow(); if (root->isChild("Frame/TabControl")) { static_cast<TabControl*>(root->getChild( "Frame/TabControl"))->setTabHeight( UDim(0, sb->getScrollPosition())); } // The return value mainly sais that we handled it, not if something failed. return true; }
/************************************************************************ Handle mouse wheel event ************************************************************************/ void ScrolledItemListBase::onMouseWheel(MouseEventArgs& e) { ItemListBase::onMouseWheel(e); size_t count = getItemCount(); Scrollbar* v = getVertScrollbar(); // dont do anything if we are no using scrollbars // or have'nt got any items if (!v->isVisible(true) || !count) { return; } float pixH = d_pane->getUnclippedOuterRect().getHeight(); float delta = (pixH/float(count)) * -e.wheelChange; v->setScrollPosition(v->getScrollPosition() + delta); ++e.handled; }
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); }
/************************************************************************* display required integrated scroll bars according to current state of the list box and update their values. *************************************************************************/ void Listbox::configureScrollbars(void) { Scrollbar* vertScrollbar; Scrollbar* horzScrollbar; try { vertScrollbar = static_cast<Scrollbar*>(WindowManager::getSingleton().getWindow(getName() + "__auto_vscrollbar__")); horzScrollbar = static_cast<Scrollbar*>(WindowManager::getSingleton().getWindow(getName() + "__auto_hscrollbar__")); } catch (UnknownObjectException) { // no scrollbars? Can't configure then! return; } float totalHeight = getTotalItemsHeight(); float widestItem = getWidestItemWidth(); // // First show or hide the scroll bars as needed (or requested) // // show or hide vertical scroll bar as required (or as specified by option) if ((totalHeight > getListRenderArea().getHeight()) || d_forceVertScroll) { vertScrollbar->show(); // show or hide horizontal scroll bar as required (or as specified by option) if ((widestItem > getListRenderArea().getWidth()) || d_forceHorzScroll) { horzScrollbar->show(); } else { horzScrollbar->hide(); } } else { // show or hide horizontal scroll bar as required (or as specified by option) if ((widestItem > getListRenderArea().getWidth()) || d_forceHorzScroll) { horzScrollbar->show(); // show or hide vertical scroll bar as required (or as specified by option) if ((totalHeight > getListRenderArea().getHeight()) || d_forceVertScroll) { vertScrollbar->show(); } else { vertScrollbar->hide(); } } else { vertScrollbar->hide(); horzScrollbar->hide(); } } // // Set up scroll bar values // Rect renderArea(getListRenderArea()); vertScrollbar->setDocumentSize(totalHeight); vertScrollbar->setPageSize(renderArea.getHeight()); vertScrollbar->setStepSize(ceguimax(1.0f, renderArea.getHeight() / 10.0f)); vertScrollbar->setScrollPosition(vertScrollbar->getScrollPosition()); horzScrollbar->setDocumentSize(widestItem); horzScrollbar->setPageSize(renderArea.getWidth()); horzScrollbar->setStepSize(ceguimax(1.0f, renderArea.getWidth() / 10.0f)); horzScrollbar->setScrollPosition(horzScrollbar->getScrollPosition()); }
//----------------------------------------------------------------------------// float ScrollablePane::getHorizontalScrollPosition(void) const { Scrollbar* horzScrollbar = getHorzScrollbar(); float docSz = horzScrollbar->getDocumentSize(); return (docSz != 0) ? horzScrollbar->getScrollPosition() / docSz : 0.0f; }
/************************************************************************* display required integrated scroll bars according to current state of the list box and update their values. *************************************************************************/ void Listbox::configureScrollbars(void) { Scrollbar* vertScrollbar = getVertScrollbar(); Scrollbar* horzScrollbar = getHorzScrollbar(); float totalHeight = getTotalItemsHeight(); float widestItem = getWidestItemWidth(); // // First show or hide the scroll bars as needed (or requested) // // show or hide vertical scroll bar as required (or as specified by option) if ((totalHeight > getListRenderArea().getHeight()) || d_forceVertScroll) { vertScrollbar->show(); // show or hide horizontal scroll bar as required (or as specified by option) if ((widestItem > getListRenderArea().getWidth()) || d_forceHorzScroll) { horzScrollbar->show(); } else { horzScrollbar->hide(); } } else { // show or hide horizontal scroll bar as required (or as specified by option) if ((widestItem > getListRenderArea().getWidth()) || d_forceHorzScroll) { horzScrollbar->show(); // show or hide vertical scroll bar as required (or as specified by option) if ((totalHeight > getListRenderArea().getHeight()) || d_forceVertScroll) { vertScrollbar->show(); } else { vertScrollbar->hide(); } } else { vertScrollbar->hide(); horzScrollbar->hide(); } } // // Set up scroll bar values // Rect renderArea(getListRenderArea()); vertScrollbar->setDocumentSize(totalHeight); vertScrollbar->setPageSize(renderArea.getHeight()); vertScrollbar->setStepSize(ceguimax(1.0f, renderArea.getHeight() / 10.0f)); vertScrollbar->setScrollPosition(vertScrollbar->getScrollPosition()); horzScrollbar->setDocumentSize(widestItem); horzScrollbar->setPageSize(renderArea.getWidth()); horzScrollbar->setStepSize(ceguimax(1.0f, renderArea.getWidth() / 10.0f)); horzScrollbar->setScrollPosition(horzScrollbar->getScrollPosition()); }
bool GuiConfig::handleSFXVolChanged(const CEGUI::EventArgs& e) { Scrollbar *pcb = (Scrollbar*)winMgr.getWindow("SFXVOLUME"); GConfig->SetQuality("SFXVOLUME", (int)pcb->getScrollPosition() ); return true; }
//----------------------------------------------------------------------------// float ScrollablePane::getVerticalScrollPosition(void) const { Scrollbar* vertScrollbar = getVertScrollbar(); float docSz = vertScrollbar->getDocumentSize(); return (docSz != 0) ? vertScrollbar->getScrollPosition() / docSz : 0.0f; }