//----------------------------------------------------------------------------// void NullGeometryBuffer::setClippingRegion(const Rectf& region) { d_clipRect.top(ceguimax(0.0f, region.top())); d_clipRect.bottom(ceguimax(0.0f, region.bottom())); d_clipRect.left(ceguimax(0.0f, region.left())); d_clipRect.right(ceguimax(0.0f, region.right())); }
//----------------------------------------------------------------------------// void IrrlichtTexture::blitFromMemory(const void* sourceData, const Rectf& area) { if (!d_texture) return; const size_t pitch = d_texture->getPitch(); const std::uint32_t* src = static_cast<const std::uint32_t*>(sourceData); std::uint32_t* dst = static_cast<std::uint32_t*>(d_texture->lock()); if (!dst) throw RendererException( "[IrrlichtRenderer] ITexture::lock failed."); dst += static_cast<size_t>(area.top()) * (pitch / 4) + static_cast<size_t>(area.left()); const Sizef sz(area.getSize()); for (int j = 0; j < sz.d_height; ++j) { for (int i = 0; i < sz.d_width; ++i) { dst[i] = src[i]; } src += static_cast<int>(sz.d_width); dst += pitch / 4; } d_texture->unlock(); }
//----------------------------------------------------------------------------// Rectf ComponentArea::getPixelRect(const Window& wnd, const Rectf& container) const { Rectf pixelRect; // use a property? if (isAreaFetchedFromProperty()) { pixelRect = CoordConverter::asAbsolute( wnd.getProperty<URect>(d_namedSource), wnd.getPixelSize()); } else if (isAreaFetchedFromNamedArea()) { return WidgetLookManager::getSingleton() .getWidgetLook(d_namedAreaSourceLook) .getNamedArea(d_namedSource) .getArea() .getPixelRect(wnd, container); } // not via property or named area- calculate using Dimensions else { // sanity check, we mus be able to form a Rect from what we represent. assert(d_left.getDimensionType() == DT_LEFT_EDGE || d_left.getDimensionType() == DT_X_POSITION); assert(d_top.getDimensionType() == DT_TOP_EDGE || d_top.getDimensionType() == DT_Y_POSITION); assert(d_right_or_width.getDimensionType() == DT_RIGHT_EDGE || d_right_or_width.getDimensionType() == DT_WIDTH); assert(d_bottom_or_height.getDimensionType() == DT_BOTTOM_EDGE || d_bottom_or_height.getDimensionType() == DT_HEIGHT); pixelRect.left(d_left.getBaseDimension().getValue(wnd, container) + container.left()); pixelRect.top(d_top.getBaseDimension().getValue(wnd, container) + container.top()); if (d_right_or_width.getDimensionType() == DT_WIDTH) pixelRect.setWidth(d_right_or_width.getBaseDimension().getValue(wnd, container)); else pixelRect.right(d_right_or_width.getBaseDimension().getValue(wnd, container) + container.left()); if (d_bottom_or_height.getDimensionType() == DT_HEIGHT) pixelRect.setHeight(d_bottom_or_height.getBaseDimension().getValue(wnd, container)); else pixelRect.bottom(d_bottom_or_height.getBaseDimension().getValue(wnd, container) + container.top()); } return pixelRect; }
void FalagardMultiLineEditbox::cacheCaretImagery(const Rectf& textArea) { MultiLineEditbox* w = (MultiLineEditbox*)d_window; const Font* fnt = w->getFont(); // require a font so that we can calculate caret position. if (fnt) { // get line that caret is in size_t caretLine = w->getLineNumberFromIndex(w->getCaretIndex()); const MultiLineEditbox::LineList& d_lines = w->getFormattedLines(); // if caret line is valid. if (caretLine < d_lines.size()) { // calculate pixel offsets to where caret should be drawn size_t caretLineIdx = w->getCaretIndex() - d_lines[caretLine].d_startIdx; float ypos = caretLine * fnt->getLineSpacing(); float xpos = fnt->getTextAdvance(w->getText().substr(d_lines[caretLine].d_startIdx, caretLineIdx)); // // get base offset to target layer for cursor. // Renderer* renderer = System::getSingleton().getRenderer(); // float baseZ = renderer->getZLayer(7) - renderer->getCurrentZ(); // get WidgetLookFeel for the assigned look. const WidgetLookFeel& wlf = getLookNFeel(); // get caret imagery const ImagerySection& caretImagery = wlf.getImagerySection("Caret"); // calculate finat destination area for caret Rectf caretArea; caretArea.left(textArea.left() + xpos); caretArea.top(textArea.top() + ypos); caretArea.setWidth(caretImagery.getBoundingRect(*w).getSize().d_width); caretArea.setHeight(fnt->getLineSpacing()); caretArea.offset(Vector2f(-w->getHorzScrollbar()->getScrollPosition(), -w->getVertScrollbar()->getScrollPosition())); // cache the caret image for rendering. caretImagery.render(*w, caretArea, 0, &textArea); } } }
Rectf ImagerySection::getBoundingRect(const Window& wnd, const Rectf& rect) const { Rectf compRect; Rectf bounds(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::min(), std::numeric_limits<float>::min()); // measure all frame components for(FrameList::const_iterator frame = d_frames.begin(); frame != d_frames.end(); ++frame) { compRect = (*frame).getComponentArea().getPixelRect(wnd, rect); bounds.left(ceguimin(bounds.left(), compRect.left())); bounds.top(ceguimin(bounds.top(), compRect.top())); bounds.right(ceguimax(bounds.right(), compRect.right())); bounds.bottom(ceguimax(bounds.bottom(), compRect.bottom())); } // measure all imagery components for(ImageryList::const_iterator image = d_images.begin(); image != d_images.end(); ++image) { compRect = (*image).getComponentArea().getPixelRect(wnd, rect); bounds.left(ceguimin(bounds.left(), compRect.left())); bounds.top(ceguimin(bounds.top(), compRect.top())); bounds.right(ceguimax(bounds.right(), compRect.right())); bounds.bottom(ceguimax(bounds.bottom(), compRect.bottom())); } // measure all text components for(TextList::const_iterator text = d_texts.begin(); text != d_texts.end(); ++text) { compRect = (*text).getComponentArea().getPixelRect(wnd, rect); bounds.left(ceguimin(bounds.left(), compRect.left())); bounds.top(ceguimin(bounds.top(), compRect.top())); bounds.right(ceguimax(bounds.right(), compRect.right())); bounds.bottom(ceguimax(bounds.bottom(), compRect.bottom())); } return bounds; }
//----------------------------------------------------------------------------// void OpenGLTexture::loadCompressedTextureBuffer(const Rectf& dest_area, const GLvoid* buffer) const { const GLsizei image_size = getCompressedTextureSize(dest_area.getSize()); glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(dest_area.left()), static_cast<GLint>(dest_area.top()), static_cast<GLsizei>(dest_area.getWidth()), static_cast<GLsizei>(dest_area.getHeight()), d_format, image_size, buffer); }
//----------------------------------------------------------------------------// void OpenGLESTexture::loadUncompressedTextureBuffer(const Rectf& dest_area, const GLvoid* buffer) const { GLint old_pack; glGetIntegerv(GL_UNPACK_ALIGNMENT, &old_pack); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexSubImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(dest_area.left()), static_cast<GLint>(dest_area.top()), static_cast<GLsizei>(dest_area.getWidth()), static_cast<GLsizei>(dest_area.getHeight()), d_format, d_subpixelFormat, buffer); glPixelStorei(GL_UNPACK_ALIGNMENT, old_pack); }
//----------------------------------------------------------------------------// void OpenGL3Texture::blitFromMemory(void* sourceData, const Rectf& area) { // save old texture binding GLuint old_tex; glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex)); // set texture to required size glBindTexture(GL_TEXTURE_2D, d_ogltexture); glTexSubImage2D(GL_TEXTURE_2D, 0, GLint(area.left()), GLint(area.top()), GLsizei(area.getWidth()), GLsizei(area.getHeight()), GL_RGBA8, GL_UNSIGNED_BYTE, sourceData ); // restore previous texture binding. glBindTexture(GL_TEXTURE_2D, old_tex); }
float FalagardSlider::getAdjustDirectionFromPoint(const Vector2f& pt) const { Slider* w = (Slider*)d_window; const Rectf absrect(w->getThumb()->getUnclippedOuterRect().get()); if ((d_vertical && (pt.d_y < absrect.top())) || (!d_vertical && (pt.d_x > absrect.right()))) { return d_reversed ? -1.0f : 1.0f; } else if ((d_vertical && (pt.d_y > absrect.bottom())) || (!d_vertical && (pt.d_x < absrect.left()))) { return d_reversed ? 1.0f : -1.0f; } else { return 0; } }
//----------------------------------------------------------------------------// void Direct3D10Texture::blitFromMemory(const void* sourceData, const Rectf& area) { if (!d_texture) return; uint32* buff = new uint32[static_cast<size_t>(area.getWidth()) * static_cast<size_t>(area.getHeight())]; blitFromSurface(static_cast<const uint32*>(sourceData), buff, area.getSize(), static_cast<size_t>(area.getWidth()) * 4); D3D10_BOX dst_box = {static_cast<UINT>(area.left()), static_cast<UINT>(area.top()), 0, static_cast<UINT>(area.right()), static_cast<UINT>(area.bottom()), 1}; d_device.UpdateSubresource(d_texture, 0, &dst_box, buff, static_cast<UINT>(area.getWidth()) * 4, 0); delete[] buff; }
// Recursive! void Tree::drawItemList(LBItemList& itemList, Rectf& itemsArea, float widest, Vector2f& itemPos, GeometryBuffer& geometry, float alpha) { if (itemList.empty()) return; // loop through the items Sizef itemSize; Rectf itemClipper, itemRect; size_t itemCount = itemList.size(); bool itemIsVisible; for (size_t i = 0; i < itemCount; ++i) { itemSize.d_height = itemList[i]->getPixelSize().d_height; // allow item to have full width of box if this is wider than items itemSize.d_width = ceguimax(itemsArea.getWidth(), widest); // calculate destination area for this item. itemRect.left(itemPos.d_x); itemRect.top(itemPos.d_y); itemRect.setSize(itemSize); itemClipper = itemRect.getIntersection(itemsArea); itemRect.d_min.d_x += 20; // start text past open/close buttons if (itemClipper.getHeight() > 0) { itemIsVisible = true; itemList[i]->draw(geometry, itemRect, alpha, &itemClipper); } else { itemIsVisible = false; } // Process this item's list if it has items in it. if (itemList[i]->getItemCount() > 0) { Rectf buttonRenderRect; buttonRenderRect.left(itemPos.d_x); buttonRenderRect.right(buttonRenderRect.left() + 10); buttonRenderRect.top(itemPos.d_y); buttonRenderRect.bottom(buttonRenderRect.top() + 10); itemList[i]->setButtonLocation(buttonRenderRect); if (itemList[i]->getIsOpen()) { // Draw the Close button if (itemIsVisible) d_closeButtonImagery->render(*this, buttonRenderRect, 0, &itemClipper); // update position ready for next item itemPos.d_y += itemSize.d_height; itemPos.d_x += 20; drawItemList(itemList[i]->getItemList(), itemsArea, widest, itemPos, geometry, alpha); itemPos.d_x -= 20; } else { // Draw the Open button if (itemIsVisible) d_openButtonImagery->render(*this, buttonRenderRect, 0, &itemClipper); // update position ready for next item itemPos.d_y += itemSize.d_height; } } else { // update position ready for next item itemPos.d_y += itemSize.d_height; } } // Successfully drew all items, so vertical scrollbar not needed. // setShowVertScrollbar(false); }
//----------------------------------------------------------------------------// void FrameComponent::renderImage(GeometryBuffer& buffer, const Image* image, VerticalFormatting vertFmt, HorizontalFormatting horzFmt, Rectf& destRect, const ColourRect& colours, const Rectf* clipper, bool /*clipToDisplay*/) const { uint horzTiles, vertTiles; float xpos, ypos; Sizef imgSz(image->getRenderedSize()); // calculate initial x co-ordinate and horizontal tile count according to formatting options switch (horzFmt) { case HF_STRETCHED: imgSz.d_width = destRect.getWidth(); xpos = destRect.left(); horzTiles = 1; break; case HF_TILED: xpos = destRect.left(); horzTiles = std::abs(static_cast<int>( (destRect.getWidth() + (imgSz.d_width - 1)) / imgSz.d_width)); break; case HF_LEFT_ALIGNED: xpos = destRect.left(); horzTiles = 1; break; case HF_CENTRE_ALIGNED: xpos = destRect.left() + CoordConverter::alignToPixels((destRect.getWidth() - imgSz.d_width) * 0.5f); horzTiles = 1; break; case HF_RIGHT_ALIGNED: xpos = destRect.right() - imgSz.d_width; horzTiles = 1; break; default: CEGUI_THROW(InvalidRequestException( "An unknown HorizontalFormatting value was specified.")); } // calculate initial y co-ordinate and vertical tile count according to formatting options switch (vertFmt) { case VF_STRETCHED: imgSz.d_height = destRect.getHeight(); ypos = destRect.top(); vertTiles = 1; break; case VF_TILED: ypos = destRect.top(); vertTiles = std::abs(static_cast<int>( (destRect.getHeight() + (imgSz.d_height - 1)) / imgSz.d_height)); break; case VF_TOP_ALIGNED: ypos = destRect.top(); vertTiles = 1; break; case VF_CENTRE_ALIGNED: ypos = destRect.top() + CoordConverter::alignToPixels((destRect.getHeight() - imgSz.d_height) * 0.5f); vertTiles = 1; break; case VF_BOTTOM_ALIGNED: ypos = destRect.bottom() - imgSz.d_height; vertTiles = 1; break; default: CEGUI_THROW(InvalidRequestException( "An unknown VerticalFormatting value was specified.")); } // perform final rendering (actually is now a caching of the images which will be drawn) Rectf finalRect; Rectf finalClipper; const Rectf* clippingRect; finalRect.d_min.d_y = ypos; finalRect.d_max.d_y = ypos + imgSz.d_height; for (uint row = 0; row < vertTiles; ++row) { finalRect.d_min.d_x = xpos; finalRect.d_max.d_x = xpos + imgSz.d_width; for (uint col = 0; col < horzTiles; ++col) { // use custom clipping for right and bottom edges when tiling the imagery if (((vertFmt == VF_TILED) && row == vertTiles - 1) || ((horzFmt == HF_TILED) && col == horzTiles - 1)) { finalClipper = clipper ? clipper->getIntersection(destRect) : destRect; clippingRect = &finalClipper; } // not tiliing, or not on far edges, just used passed in clipper (if any). else clippingRect = clipper; image->render(buffer, finalRect, clippingRect, colours); finalRect.d_min.d_x += imgSz.d_width; finalRect.d_max.d_x += imgSz.d_width; } finalRect.d_min.d_y += imgSz.d_height; finalRect.d_max.d_y += imgSz.d_height; } }
//----------------------------------------------------------------------------// void FrameComponent::render_impl(Window& srcWindow, Rectf& destRect, const CEGUI::ColourRect* modColours, const Rectf* clipper, bool clipToDisplay) const { Rectf backgroundRect(destRect); Rectf finalRect; Sizef imageSize; Vector2f imageOffsets; ColourRect imageColours; float leftfactor, rightfactor, topfactor, bottomfactor; bool calcColoursPerImage; // vars we use to track what to do with the side pieces. float topOffset = 0, bottomOffset = 0, leftOffset = 0, rightOffset = 0; float topWidth, bottomWidth, leftHeight, rightHeight; topWidth = bottomWidth = destRect.getWidth(); leftHeight = rightHeight = destRect.getHeight(); // calculate final overall colours to be used ColourRect finalColours; initColoursRect(srcWindow, modColours, finalColours); if (finalColours.isMonochromatic()) { calcColoursPerImage = false; imageColours = finalColours; } else { calcColoursPerImage = true; } // top-left image if (const Image* const componentImage = getImage(FIC_TOP_LEFT_CORNER, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); imageOffsets = componentImage->getRenderedOffset(); finalRect.d_min = destRect.d_min; finalRect.setSize(imageSize); finalRect = destRect.getIntersection(finalRect); // update adjustments required to edges do to presence of this element. topOffset += imageSize.d_width + imageOffsets.d_x; leftOffset += imageSize.d_height + imageOffsets.d_y; topWidth -= topOffset; leftHeight -= leftOffset; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + imageOffsets.d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + imageOffsets.d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. componentImage->render(srcWindow.getGeometryBuffer(), finalRect, clipper, imageColours); } // top-right image if (const Image* const componentImage = getImage(FIC_TOP_RIGHT_CORNER, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); imageOffsets = componentImage->getRenderedOffset(); finalRect.left(destRect.right() - imageSize.d_width); finalRect.top(destRect.top()); finalRect.setSize(imageSize); finalRect = destRect.getIntersection(finalRect); // update adjustments required to edges do to presence of this element. rightOffset += imageSize.d_height + imageOffsets.d_y; topWidth -= imageSize.d_width - imageOffsets.d_x; rightHeight -= rightOffset; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + imageOffsets.d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + imageOffsets.d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. componentImage->render(srcWindow.getGeometryBuffer(), finalRect, clipper, imageColours); } // bottom-left image if (const Image* const componentImage = getImage(FIC_BOTTOM_LEFT_CORNER, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); imageOffsets = componentImage->getRenderedOffset(); finalRect.left(destRect.left()); finalRect.top(destRect.bottom() - imageSize.d_height); finalRect.setSize(imageSize); finalRect = destRect.getIntersection(finalRect); // update adjustments required to edges do to presence of this element. bottomOffset += imageSize.d_width + imageOffsets.d_x; bottomWidth -= bottomOffset; leftHeight -= imageSize.d_height - imageOffsets.d_y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + imageOffsets.d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + imageOffsets.d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. componentImage->render(srcWindow.getGeometryBuffer(), finalRect, clipper, imageColours); } // bottom-right image if (const Image* const componentImage = getImage(FIC_BOTTOM_RIGHT_CORNER, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); imageOffsets = componentImage->getRenderedOffset(); finalRect.left(destRect.right() - imageSize.d_width); finalRect.top(destRect.bottom() - imageSize.d_height); finalRect.setSize(imageSize); finalRect = destRect.getIntersection(finalRect); // update adjustments required to edges do to presence of this element. bottomWidth -= imageSize.d_width - imageOffsets.d_x; rightHeight -= imageSize.d_height - imageOffsets.d_y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. componentImage->render(srcWindow.getGeometryBuffer(), finalRect, clipper, imageColours); } // top image if (const Image* const componentImage = getImage(FIC_TOP_EDGE, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); finalRect.left(destRect.left() + topOffset); finalRect.right(finalRect.left() + topWidth); finalRect.top(destRect.top()); finalRect.bottom(finalRect.top() + imageSize.d_height); finalRect = destRect.getIntersection(finalRect); // adjust background area to miss this edge backgroundRect.d_min.d_y += imageSize.d_height + componentImage->getRenderedOffset().d_y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. renderImage(srcWindow.getGeometryBuffer(), componentImage, VF_TOP_ALIGNED, d_topEdgeFormatting.get(srcWindow), finalRect, imageColours, clipper, clipToDisplay); } // bottom image if (const Image* const componentImage = getImage(FIC_BOTTOM_EDGE, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); finalRect.left(destRect.left() + bottomOffset); finalRect.right(finalRect.left() + bottomWidth); finalRect.bottom(destRect.bottom()); finalRect.top(finalRect.bottom() - imageSize.d_height); finalRect = destRect.getIntersection (finalRect); // adjust background area to miss this edge backgroundRect.d_max.d_y -= imageSize.d_height - componentImage->getRenderedOffset().d_y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. renderImage(srcWindow.getGeometryBuffer(), componentImage, VF_BOTTOM_ALIGNED, d_bottomEdgeFormatting.get(srcWindow), finalRect, imageColours, clipper, clipToDisplay); } // left image if (const Image* const componentImage = getImage(FIC_LEFT_EDGE, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); finalRect.left(destRect.left()); finalRect.right(finalRect.left() + imageSize.d_width); finalRect.top(destRect.top() + leftOffset); finalRect.bottom(finalRect.top() + leftHeight); finalRect = destRect.getIntersection(finalRect); // adjust background area to miss this edge backgroundRect.d_min.d_x += imageSize.d_width + componentImage->getRenderedOffset().d_x; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. renderImage(srcWindow.getGeometryBuffer(), componentImage, d_leftEdgeFormatting.get(srcWindow), HF_LEFT_ALIGNED, finalRect, imageColours, clipper, clipToDisplay); } // right image if (const Image* const componentImage = getImage(FIC_RIGHT_EDGE, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); finalRect.top(destRect.top() + rightOffset); finalRect.bottom(finalRect.top() + rightHeight); finalRect.right(destRect.right()); finalRect.left(finalRect.right() - imageSize.d_width); finalRect = destRect.getIntersection (finalRect); // adjust background area to miss this edge backgroundRect.d_max.d_x -= imageSize.d_width - componentImage->getRenderedOffset().d_x; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. renderImage(srcWindow.getGeometryBuffer(), componentImage, d_rightEdgeFormatting.get(srcWindow), HF_RIGHT_ALIGNED, finalRect, imageColours, clipper, clipToDisplay); } if (const Image* const componentImage = getImage(FIC_BACKGROUND, srcWindow)) { // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (backgroundRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + backgroundRect.getWidth() / destRect.getWidth(); topfactor = (backgroundRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + backgroundRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } const HorizontalFormatting horzFormatting = d_backgroundHorzFormatting.get(srcWindow); const VerticalFormatting vertFormatting = d_backgroundVertFormatting.get(srcWindow); renderImage(srcWindow.getGeometryBuffer(), componentImage, vertFormatting, horzFormatting, backgroundRect, imageColours, clipper, clipToDisplay); } }
float FalagardScrollbar::getValueFromThumb(void) const { Scrollbar* w = (Scrollbar*)d_window; const WidgetLookFeel& wlf = getLookNFeel(); const Rectf area(wlf.getNamedArea("ThumbTrackArea").getArea().getPixelRect(*w)); Thumb* theThumb = w->getThumb(); float posExtent = w->getDocumentSize() - w->getPageSize(); if (d_vertical) { float slideExtent = area.getHeight() - theThumb->getPixelSize().d_height; return (CoordConverter::asAbsolute(theThumb->getYPosition(), w->getPixelSize().d_height) - area.top()) / (slideExtent / posExtent); } else { float slideExtent = area.getWidth() - theThumb->getPixelSize().d_width; return (CoordConverter::asAbsolute(theThumb->getXPosition(), w->getPixelSize().d_width) - area.left()) / (slideExtent / posExtent); } }
//----------------------------------------------------------------------------// void BasicImage::render(GeometryBuffer& buffer, const Rectf& dest_area, const Rectf* clip_area, const ColourRect& colours) const { const QuadSplitMode quad_split_mode(TopLeftToBottomRight); Rectf dest(dest_area); // apply rendering offset to the destination Rect dest.offset(d_scaledOffset); // get the rect area that we will actually draw to (i.e. perform clipping) Rectf final_rect(clip_area ? dest.getIntersection(*clip_area) : dest ); // check if rect was totally clipped if ((final_rect.getWidth() == 0) || (final_rect.getHeight() == 0)) return; // Obtain correct scale values from the texture const Vector2f& scale = d_texture->getTexelScaling(); const Vector2f tex_per_pix(d_area.getWidth() / dest.getWidth(), d_area.getHeight() / dest.getHeight()); // calculate final, clipped, texture co-ordinates const Rectf tex_rect((d_area.d_min + ((final_rect.d_min - dest.d_min) * tex_per_pix)) * scale, (d_area.d_max + ((final_rect.d_max - dest.d_max) * tex_per_pix)) * scale); // URGENT FIXME: Shouldn't this be in the hands of the user? final_rect.d_min.d_x = CoordConverter::alignToPixels(final_rect.d_min.d_x); final_rect.d_min.d_y = CoordConverter::alignToPixels(final_rect.d_min.d_y); final_rect.d_max.d_x = CoordConverter::alignToPixels(final_rect.d_max.d_x); final_rect.d_max.d_y = CoordConverter::alignToPixels(final_rect.d_max.d_y); Vertex vbuffer[6]; // vertex 0 vbuffer[0].position = Vector3f(final_rect.left(), final_rect.top(), 0.0f); vbuffer[0].colour_val = colours.d_top_left; vbuffer[0].tex_coords = Vector2f(tex_rect.left(), tex_rect.top()); // vertex 1 vbuffer[1].position = Vector3f(final_rect.left(), final_rect.bottom(), 0.0f); vbuffer[1].colour_val = colours.d_bottom_left; vbuffer[1].tex_coords = Vector2f(tex_rect.left(), tex_rect.bottom()); // vertex 2 vbuffer[2].position.d_x = final_rect.right(); vbuffer[2].position.d_z = 0.0f; vbuffer[2].colour_val = colours.d_bottom_right; vbuffer[2].tex_coords.d_x = tex_rect.right(); // top-left to bottom-right diagonal if (quad_split_mode == TopLeftToBottomRight) { vbuffer[2].position.d_y = final_rect.bottom(); vbuffer[2].tex_coords.d_y = tex_rect.bottom(); } // bottom-left to top-right diagonal else { vbuffer[2].position.d_y = final_rect.top(); vbuffer[2].tex_coords.d_y = tex_rect.top(); } // vertex 3 vbuffer[3].position = Vector3f(final_rect.right(), final_rect.top(), 0.0f); vbuffer[3].colour_val = colours.d_top_right; vbuffer[3].tex_coords = Vector2f(tex_rect.right(), tex_rect.top()); // vertex 4 vbuffer[4].position.d_x = final_rect.left(); vbuffer[4].position.d_z = 0.0f; vbuffer[4].colour_val = colours.d_top_left; vbuffer[4].tex_coords.d_x = tex_rect.left(); // top-left to bottom-right diagonal if (quad_split_mode == TopLeftToBottomRight) { vbuffer[4].position.d_y = final_rect.top(); vbuffer[4].tex_coords.d_y = tex_rect.top(); } // bottom-left to top-right diagonal else { vbuffer[4].position.d_y = final_rect.bottom(); vbuffer[4].tex_coords.d_y = tex_rect.bottom(); } // vertex 5 vbuffer[5].position = Vector3f(final_rect.right(), final_rect.bottom(), 0.0f); vbuffer[5].colour_val= colours.d_bottom_right; vbuffer[5].tex_coords = Vector2f(tex_rect.right(), tex_rect.bottom()); buffer.setActiveTexture(d_texture); buffer.appendGeometry(vbuffer, 6); }
float FalagardSlider::getValueFromThumb(void) const { Slider* w = (Slider*)d_window; // get area the thumb is supposed to use as it's area. const WidgetLookFeel& wlf = getLookNFeel(); const Rectf area(wlf.getNamedArea("ThumbTrackArea").getArea().getPixelRect(*w)); // get accesss to the thumb Thumb* theThumb = w->getThumb(); // slider is vertical if (d_vertical) { // pixel extent of total available area the thumb moves in float slideExtent = area.getHeight() - theThumb->getPixelSize().d_height; // calculate value represented by current thumb position float thumbValue = (CoordConverter::asAbsolute( theThumb->getYPosition(), w->getPixelSize().d_height) - area.top()) / (slideExtent / w->getMaxValue()); // return final thumb value according to slider settings return d_reversed ? thumbValue : w->getMaxValue() - thumbValue; } // slider is horizontal else { // pixel extent of total available area the thumb moves in float slideExtent = area.getWidth() - theThumb->getPixelSize().d_width; // calculate value represented by current thumb position float thumbValue = (CoordConverter::asAbsolute( theThumb->getXPosition(), w->getPixelSize().d_width) - area.left()) / (slideExtent / w->getMaxValue()); // return final thumb value according to slider settings return d_reversed ? w->getMaxValue() - thumbValue : thumbValue; } }
/************************************************************************* Handler for when mouse button is pressed *************************************************************************/ void Tree::onMouseButtonDown(MouseEventArgs& e) { // base class processing // populateGeometryBuffer(); Window::onMouseButtonDown(e); if (e.button == LeftButton) { //bool modified = false; Vector2f localPos(CoordConverter::screenToWindow(*this, e.position)); // Point localPos(screenToWindow(e.position)); TreeItem* item = getItemAtPoint(localPos); if (item != 0) { //modified = true; TreeEventArgs args(this); args.treeItem = item; populateGeometryBuffer(); Rectf buttonLocation = item->getButtonLocation(); if ((localPos.d_x >= buttonLocation.left()) && (localPos.d_x <= buttonLocation.right()) && (localPos.d_y >= buttonLocation.top()) && (localPos.d_y <= buttonLocation.bottom())) { item->toggleIsOpen(); if (item->getIsOpen()) { TreeItem *lastItemInList = item->getTreeItemFromIndex(item->getItemCount() - 1); ensureItemIsVisible(lastItemInList); ensureItemIsVisible(item); onBranchOpened(args); } else { onBranchClosed(args); } // Update the item screen locations, needed to update the scrollbars. // populateGeometryBuffer(); // Opened or closed a tree branch, so must update scrollbars. configureScrollbars(); } else { // clear old selections if no control key is pressed or if multi-select is off if (!(e.sysKeys & Control) || !d_multiselect) clearAllSelections_impl(); // select range or item, depending upon keys and last selected item #if 0 // TODO: fix this if (((e.sysKeys & Shift) && (d_lastSelected != 0)) && d_multiselect) selectRange(getItemIndex(item), getItemIndex(d_lastSelected)); else #endif item->setSelected(item->isSelected() ^ true); // update last selected item d_lastSelected = item->isSelected() ? item : 0; onSelectionChanged(args); } } else { // clear old selections if no control key is pressed or if multi-select is off if (!(e.sysKeys & Control) || !d_multiselect) { if (clearAllSelections_impl()) { // Changes to the selections were actually made TreeEventArgs args(this); args.treeItem = item; onSelectionChanged(args); } } } ++e.handled; } }