/************************************************************************* set the movement range of the thumb for the horizontal axis. *************************************************************************/ void Thumb::setHorzRange(float min, float max) { Sizef parentSize(getParentPixelSize()); // ensure min <= max, swap if not. if (min > max) { float tmp = min; max = min; min = tmp; } d_horzMax = max; d_horzMin = min; // validate current position. const float cp = CoordConverter::asAbsolute(getXPosition(), parentSize.d_width); if (cp < min) { setXPosition(cegui_absdim(min)); } else if (cp > max) { setXPosition(cegui_absdim(max)); } }
/************************************************************************ Resize to fit content ************************************************************************/ void ItemListBase::sizeToContent_impl(void) { Rect renderArea(getItemRenderArea()); Rect wndArea(getArea().asAbsolute(getParentPixelSize())); // get size of content Size sz(getContentSize()); // calculate the full size with the frame accounted for and resize the window to this sz.d_width += wndArea.getWidth() - renderArea.getWidth(); sz.d_height += wndArea.getHeight() - renderArea.getHeight(); setSize(UVector2(cegui_absdim(sz.d_width), cegui_absdim(sz.d_height))); }
//----------------------------------------------------------------------------// Sizef Element::calculatePixelSize(bool skipAllPixelAlignment) const { // calculate pixel sizes for everything, so we have a common format for // comparisons. Sizef absMin(CoordConverter::asAbsolute(d_minSize, getRootContainerSize(), false)); Sizef absMax(CoordConverter::asAbsolute(d_maxSize, getRootContainerSize(), false)); Sizef base_size; if (skipAllPixelAlignment) { base_size = Sizef((d_parent && !d_nonClient) ? d_parent->getUnclippedInnerRect().getFresh(true).getSize() : getParentPixelSize(true)); } else { base_size = Sizef((d_parent && !d_nonClient) ? d_parent->getUnclippedInnerRect().get().getSize() : getParentPixelSize()); } Sizef ret = CoordConverter::asAbsolute(d_area.getSize(), base_size, false); // in case absMin components are larger than absMax ones, // max size takes precedence if (absMax.d_width != 0.0f && absMin.d_width > absMax.d_width) { absMin.d_width = absMax.d_width; CEGUI_LOGINSANE("MinSize resulted in an absolute pixel size with " "width larger than what MaxSize resulted in"); } if (absMax.d_height != 0.0f && absMin.d_height > absMax.d_height) { absMin.d_height = absMax.d_height; CEGUI_LOGINSANE("MinSize resulted in an absolute pixel size with " "height larger than what MaxSize resulted in"); } // limit new pixel size to: minSize <= newSize <= maxSize if (ret.d_width < absMin.d_width) ret.d_width = absMin.d_width; else if (absMax.d_width != 0.0f && ret.d_width > absMax.d_width) ret.d_width = absMax.d_width; if (ret.d_height < absMin.d_height) ret.d_height = absMin.d_height; else if (absMax.d_height != 0.0f && ret.d_height > absMax.d_height) ret.d_height = absMax.d_height; if (d_aspectMode != AM_IGNORE) { // make sure we respect current aspect mode and ratio ret.scaleToAspect(d_aspectMode, d_aspectRatio); // make sure we haven't blown any of the hard limits // still maintain the aspect when we do this if (d_aspectMode == AM_SHRINK) { float ratio = 1.0f; // check that we haven't blown the min size if (ret.d_width < absMin.d_width) { ratio = absMin.d_width / ret.d_width; } if (ret.d_height < absMin.d_height) { const float newRatio = absMin.d_height / ret.d_height; if (newRatio > ratio) ratio = newRatio; } ret.d_width *= ratio; ret.d_height *= ratio; } else if (d_aspectMode == AM_EXPAND) { float ratio = 1.0f; // check that we haven't blown the min size if (absMax.d_width != 0.0f && ret.d_width > absMax.d_width) { ratio = absMax.d_width / ret.d_width; } if (absMax.d_height != 0.0f && ret.d_height > absMax.d_height) { const float newRatio = absMax.d_height / ret.d_height; if (newRatio > ratio) ratio = newRatio; } ret.d_width *= ratio; ret.d_height *= ratio; } // NOTE: When the hard min max limits are unsatisfiable with the aspect lock mode, // the result won't be limited by both limits! } if (d_pixelAligned) { ret.d_width = CoordConverter::alignToPixels(ret.d_width); ret.d_height = CoordConverter::alignToPixels(ret.d_height); } return ret; }
/************************************************************************* Handler for mouse movement events *************************************************************************/ void Thumb::onMouseMove(MouseEventArgs& e) { // default processing PushButton::onMouseMove(e); // only react if we are being dragged if (d_beingDragged) { Sizef parentSize(getParentPixelSize()); Vector2f delta; float hmin, hmax, vmin, vmax; delta = CoordConverter::screenToWindow(*this, e.position); hmin = d_horzMin; hmax = d_horzMax; vmin = d_vertMin; vmax = d_vertMax; // calculate amount of movement delta -= d_dragPoint; delta.d_x /= parentSize.d_width; delta.d_y /= parentSize.d_height; // // Calculate new (pixel) position for thumb // UVector2 newPos(getPosition()); if (d_horzFree) { newPos.d_x.d_scale += delta.d_x; // limit value to within currently set range newPos.d_x.d_scale = (newPos.d_x.d_scale < hmin) ? hmin : (newPos.d_x.d_scale > hmax) ? hmax : newPos.d_x.d_scale; } if (d_vertFree) { newPos.d_y.d_scale += delta.d_y; // limit new position to within currently set range newPos.d_y.d_scale = (newPos.d_y.d_scale < vmin) ? vmin : (newPos.d_y.d_scale > vmax) ? vmax : newPos.d_y.d_scale; } // update thumb position if needed if (newPos != getPosition()) { setPosition(newPos); // send notification as required if (d_hotTrack) { WindowEventArgs args(this); onThumbPositionChanged(args); } } } ++e.handled; }