本文整理汇总了C++中core::rect类的典型用法代码示例。如果您正苦于以下问题:C++ rect类的具体用法?C++ rect怎么用?C++ rect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了rect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
{
if (!Driver)
return;
// Clear the glyph pages of their render information.
for (u32 i = 0; i < Glyph_Pages.size(); ++i)
{
Glyph_Pages[i]->render_positions.clear();
Glyph_Pages[i]->render_source_rects.clear();
}
// Set up some variables.
core::dimension2d<s32> textDimension;
core::position2d<s32> offset = position.UpperLeftCorner;
// Determine offset positions.
if (hcenter || vcenter)
{
textDimension = getDimension(text.c_str());
if (hcenter)
offset.X = ((position.getWidth() - textDimension.Width) >> 1) + offset.X;
if (vcenter)
offset.Y = ((position.getHeight() - textDimension.Height) >> 1) + offset.Y;
}
示例2: IGUIComboBox
//! constructor
CGUIComboBox::CGUIComboBox(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle)
: IGUIComboBox(environment, parent, id, rectangle),
ListButton(0), SelectedText(0), ListBox(0), LastFocus(0),
Selected(-1), HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_CENTER), MaxSelectionRows(5), HasFocus(false),
ActiveFont(0)
{
#ifdef _DEBUG
setDebugName("CGUIComboBox");
#endif
IGUISkin* skin = Environment->getSkin();
s32 width = 15;
if (skin)
width = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH);
core::rect<s32> r;
r.UpperLeftCorner.X = rectangle.getWidth() - width - 2;
r.LowerRightCorner.X = rectangle.getWidth() - 2;
r.UpperLeftCorner.Y = 2;
r.LowerRightCorner.Y = rectangle.getHeight() - 2;
ListButton = Environment->addButton(r, this, -1, L"");
if (skin && skin->getSpriteBank())
{
ListButton->setSpriteBank(skin->getSpriteBank());
ListButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL));
ListButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL));
}
ListButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
ListButton->setSubElement(true);
ListButton->setTabStop(false);
r.UpperLeftCorner.X = 2;
r.UpperLeftCorner.Y = 2;
r.LowerRightCorner.X = RelativeRect.getWidth() - (ListButton->getAbsolutePosition().getWidth() + 2);
r.LowerRightCorner.Y = RelativeRect.getHeight() - 2;
SelectedText = Environment->addStaticText(L"", r, false, false, this, -1, false);
SelectedText->setSubElement(true);
SelectedText->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
SelectedText->setTextAlignment(EGUIA_UPPERLEFT, EGUIA_CENTER);
if (skin)
SelectedText->setOverrideColor(skin->getColor(EGDC_BUTTON_TEXT));
SelectedText->enableOverrideColor(true);
// this element can be tabbed to
setTabStop(true);
setTabOrder(-1);
}
示例3: IGUISpinBox
//! constructor
CGUISpinBox::CGUISpinBox(const wchar_t* text, bool border,IGUIEnvironment* environment,
IGUIElement* parent, s32 id, const core::rect<s32>& rectangle)
: IGUISpinBox(environment, parent, id, rectangle),
EditBox(0), ButtonSpinUp(0), ButtonSpinDown(0), StepSize(1.f),
RangeMin(-FLT_MAX), RangeMax(FLT_MAX), FormatString(L"%f"),
DecimalPlaces(-1)
{
#ifdef _DEBUG
setDebugName("CGUISpinBox");
#endif
s32 ButtonWidth = 16;
IGUISpriteBank *sb = 0;
if (environment && environment->getSkin())
{
ButtonWidth = environment->getSkin()->getSize(EGDS_SCROLLBAR_SIZE);
sb = environment->getSkin()->getSpriteBank();
}
ButtonSpinDown = Environment->addButton(
core::rect<s32>(rectangle.getWidth() - ButtonWidth, rectangle.getHeight()/2 +1,
rectangle.getWidth(), rectangle.getHeight()), this);
ButtonSpinDown->grab();
ButtonSpinDown->setSubElement(true);
ButtonSpinDown->setTabStop(false);
ButtonSpinDown->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_CENTER, EGUIA_LOWERRIGHT);
ButtonSpinUp = Environment->addButton(
core::rect<s32>(rectangle.getWidth() - ButtonWidth, 0,
rectangle.getWidth(), rectangle.getHeight()/2), this);
ButtonSpinUp->grab();
ButtonSpinUp->setSubElement(true);
ButtonSpinUp->setTabStop(false);
ButtonSpinUp->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_CENTER);
if (sb)
{
IGUISkin *skin = environment->getSkin();
ButtonSpinDown->setSpriteBank(sb);
ButtonSpinDown->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_SMALL_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL));
ButtonSpinDown->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_SMALL_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL));
ButtonSpinUp->setSpriteBank(sb);
ButtonSpinUp->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_SMALL_CURSOR_UP), skin->getColor(EGDC_WINDOW_SYMBOL));
ButtonSpinUp->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_SMALL_CURSOR_UP), skin->getColor(EGDC_WINDOW_SYMBOL));
}
else
{
ButtonSpinDown->setText(L"-");
ButtonSpinUp->setText(L"+");
}
const core::rect<s32> rectEdit(0, 0, rectangle.getWidth() - ButtonWidth - 1, rectangle.getHeight());
EditBox = Environment->addEditBox(text, rectEdit, border, this, -1);
EditBox->grab();
EditBox->setSubElement(true);
EditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
}
示例4: IGUIElement
CGUIPanel::CGUIPanel( IGUIEnvironment* environment, IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
bool border, E_SCROLL_BAR_MODE vMode, E_SCROLL_BAR_MODE hMode)
: IGUIElement(EGUIET_ELEMENT, environment, parent, id, rectangle),
VScrollBar(0), HScrollBar(0), ClipPane(0), InnerPane(0),
Border(border), VScrollBarMode(vMode), HScrollBarMode(hMode), NeedsUpdate(true)
{
#ifdef _DEBUG
setDebugName("CGUIPanel");
#endif
s32 width = rectangle.getWidth();
s32 height = rectangle.getHeight();
core::rect<s32> rct = core::rect<s32>(width - SCROLL_BAR_SIZE,0, width, height);
VScrollBar = environment->addScrollBar( false, rct, 0, id );
VScrollBar->setSubElement(true);
VScrollBar->setTabStop(false);
VScrollBar->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
VScrollBar->grab();
IGUIElement::addChild(VScrollBar);
rct = core::rect<s32>(0,height - SCROLL_BAR_SIZE, width - SCROLL_BAR_SIZE,height );
HScrollBar = environment->addScrollBar( true, rct, 0, id );
HScrollBar->setSubElement(true);
HScrollBar->setTabStop(false);
HScrollBar->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
HScrollBar->grab();
IGUIElement::addChild(HScrollBar);
rct = core::rect<s32>(0,0, width - SCROLL_BAR_SIZE, height - SCROLL_BAR_SIZE);
ClipPane = environment->addTab( rct, 0, -1);
ClipPane->setSubElement(true);
ClipPane->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
ClipPane->grab();
IGUIElement::addChild(ClipPane);
InnerPane = environment->addTab( rct, ClipPane, -1);
InnerPane->setSubElement(true);
InnerPane->grab();
calculateClientArea();
resizeInnerPane();
}
示例5: draw2DImageFilterScaled
/* Replacement for driver->draw2DImage() that uses the high-quality pre-scaled
* texture, if configured.
*/
void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
const core::rect<s32> &destrect, const core::rect<s32> &srcrect,
const core::rect<s32> *cliprect, const video::SColor *const colors,
bool usealpha)
{
// Attempt to pre-scale image in software in high quality.
video::ITexture *scaled = guiScalingResizeCached(driver, txr, srcrect, destrect);
if (scaled == NULL)
return;
// Correct source rect based on scaled image.
const core::rect<s32> mysrcrect = (scaled != txr)
? core::rect<s32>(0, 0, destrect.getWidth(), destrect.getHeight())
: srcrect;
driver->draw2DImage(scaled, destrect, mysrcrect, cliprect, colors, usealpha);
}
示例6: if
void GUITable::drawCell(const Cell *cell, video::SColor color,
const core::rect<s32> &row_rect,
const core::rect<s32> &client_clip)
{
if ((cell->content_type == COLUMN_TYPE_TEXT)
|| (cell->content_type == COLUMN_TYPE_TREE)) {
core::rect<s32> text_rect = row_rect;
text_rect.UpperLeftCorner.X = row_rect.UpperLeftCorner.X
+ cell->xpos;
text_rect.LowerRightCorner.X = row_rect.UpperLeftCorner.X
+ cell->xmax;
if (cell->color_defined)
color = cell->color;
if (m_font) {
if (cell->content_type == COLUMN_TYPE_TEXT)
m_font->draw(m_strings[cell->content_index],
text_rect, color,
false, true, &client_clip);
else // tree
m_font->draw(cell->content_index ? L"+" : L"-",
text_rect, color,
false, true, &client_clip);
}
}
else if (cell->content_type == COLUMN_TYPE_IMAGE) {
if (cell->content_index < 0)
return;
video::IVideoDriver *driver = Environment->getVideoDriver();
video::ITexture *image = m_images[cell->content_index];
if (image) {
core::position2d<s32> dest_pos =
row_rect.UpperLeftCorner;
dest_pos.X += cell->xpos;
core::rect<s32> source_rect(
core::position2d<s32>(0, 0),
image->getOriginalSize());
s32 imgh = source_rect.LowerRightCorner.Y;
s32 rowh = row_rect.getHeight();
if (imgh < rowh)
dest_pos.Y += (rowh - imgh) / 2;
else
source_rect.LowerRightCorner.Y = rowh;
video::SColor color(255, 255, 255, 255);
driver->draw2DImage(image, dest_pos, source_rect,
&client_clip, color, true);
}
}
}
示例7: IGUIProfiler
//! constructor
CGUIProfiler::CGUIProfiler(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle, IProfiler* profiler)
: IGUIProfiler(environment, parent, id, rectangle, profiler)
, Profiler(profiler)
, DisplayTable(0), CurrentGroupIdx(0), CurrentGroupPage(0), NumGroupPages(1)
, DrawBackground(false), Frozen(false), UnfreezeOnce(false), ShowGroupsTogether(false)
, MinCalls(0), MinTimeSum(0), MinTimeAverage(0.f), MinTimeMax(0)
{
if ( !Profiler )
Profiler = &getProfiler();
core::recti r(0, 0, rectangle.getWidth(), rectangle.getHeight());
// Really just too lazy to code a complete new element for this.
// If anyone can do this nicer he's welcome.
DisplayTable = Environment->addTable(r, this, -1, DrawBackground);
DisplayTable->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
DisplayTable->setSubElement(true);
rebuildColumns();
}
示例8: draw
//! draws an text and clips it to the specified rectangle if wanted
void CGUIFont::draw(const wchar_t* text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
{
if (!Driver)
return;
core::dimension2d<s32> textDimension;
core::position2d<s32> offset = position.UpperLeftCorner;
core::rect<s32> pos;
if (hcenter || vcenter)
{
textDimension = getDimension(text);
if (hcenter)
offset.X = ((position.getWidth() - textDimension.Width)>>1) + offset.X;
if (vcenter)
offset.Y = ((position.getHeight() - textDimension.Height)>>1) + offset.Y;
}
示例9: drawElementStyle
void CImageGUISkin::drawHorizontalProgressBar( IGUIElement* element, const core::rect<s32>& rectangle, const core::rect<s32>* clip,
f32 filledRatio, video::SColor fillColor )
{
if ( !Config.ProgressBar.Texture || !Config.ProgressBarFilled.Texture )
{
return;
}
// Draw empty progress bar
drawElementStyle( Config.ProgressBar, rectangle, clip );
// Draw filled progress bar on top
if ( filledRatio < 0.0f )
filledRatio = 0.0f;
else
if ( filledRatio > 1.0f )
filledRatio = 1.0f;
if ( filledRatio > 0.0f )
{
s32 filledPixels = (s32)( filledRatio * rectangle.getSize().Width );
s32 height = rectangle.getSize().Height;
core::rect<s32> clipRect = clip? *clip:rectangle;
if ( filledPixels < height )
{
if ( clipRect.LowerRightCorner.X > rectangle.UpperLeftCorner.X + filledPixels )
clipRect.LowerRightCorner.X = rectangle.UpperLeftCorner.X + filledPixels;
filledPixels = height;
}
core::rect<s32> filledRect = core::rect<s32>(
rectangle.UpperLeftCorner.X,
rectangle.UpperLeftCorner.Y,
rectangle.UpperLeftCorner.X + filledPixels,
rectangle.LowerRightCorner.Y );
drawElementStyle( Config.ProgressBarFilled, filledRect, &clipRect, &fillColor );
}
}
示例10: IGUISpinBox
//! constructor
CGUISpinBox::CGUISpinBox(const wchar_t* text, bool border,IGUIEnvironment* environment,
IGUIElement* parent, s32 id, const core::rect<s32>& rectangle)
: IGUISpinBox(environment, parent, id, rectangle),
EditBox(0), ButtonSpinUp(0), ButtonSpinDown(0), StepSize(1.f),
RangeMin(-FLT_MAX), RangeMax(FLT_MAX), FormatString(L"%f"),
DecimalPlaces(-1)
{
#ifdef _DEBUG
setDebugName("CGUISpinBox");
#endif
CurrentIconColor = video::SColor(255,255,255,255);
s32 ButtonWidth = 16;
IGUISpriteBank *sb = 0;
if (environment && environment->getSkin())
{
ButtonWidth = environment->getSkin()->getSize(EGDS_SCROLLBAR_SIZE);
sb = environment->getSkin()->getSpriteBank();
}
ButtonSpinDown = Environment->addButton(
core::rect<s32>(rectangle.getWidth() - ButtonWidth, rectangle.getHeight()/2 +1,
rectangle.getWidth(), rectangle.getHeight()), this);
ButtonSpinDown->grab();
ButtonSpinDown->setSubElement(true);
ButtonSpinDown->setTabStop(false);
ButtonSpinDown->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_CENTER, EGUIA_LOWERRIGHT);
ButtonSpinUp = Environment->addButton(
core::rect<s32>(rectangle.getWidth() - ButtonWidth, 0,
rectangle.getWidth(), rectangle.getHeight()/2), this);
ButtonSpinUp->grab();
ButtonSpinUp->setSubElement(true);
ButtonSpinUp->setTabStop(false);
ButtonSpinUp->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_CENTER);
const core::rect<s32> rectEdit(0, 0, rectangle.getWidth() - ButtonWidth - 1, rectangle.getHeight());
EditBox = Environment->addEditBox(text, rectEdit, border, this, -1);
EditBox->grab();
EditBox->setSubElement(true);
EditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
refreshSprites();
}
示例11: getDimension
//! draws some text and clips it to the specified rectangle if wanted
void CGUIFont::draw(const wchar_t* text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
{
if (!Driver)
return;
core::dimension2d<s32> textDimension;
core::position2d<s32> offset = position.UpperLeftCorner;
core::rect<s32> pos;
if (hcenter || vcenter || clip)
textDimension = getDimension(text);
if (hcenter)
offset.X = ((position.getWidth() - textDimension.Width)>>1) + offset.X;
if (vcenter)
offset.Y = ((position.getHeight() - textDimension.Height)>>1) + offset.Y;
if (clip)
{
core::rect<s32> clippedRect(offset, textDimension);
clippedRect.clipAgainst(*clip);
if (!clippedRect.isValid())
return;
}
while(*text)
{
SFontArea& area = Areas[getAreaFromCharacter(*text)];
offset.X += area.underhang;
SpriteBank->draw2DSprite(area.spriteno, offset, clip, color);
offset.X += area.width + area.overhang + GlobalKerningWidth;
++text;
}
}
示例12: draw
//! draws an text and clips it to the specified rectangle if wanted
void CGUITTFont::draw(const core::stringw& text_, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
{
const wchar_t* text = text_.c_str();
if (!Driver)
return;
core::dimension2d<u32> textDimension;
core::position2d<s32> offset = position.UpperLeftCorner;
video::SColor colors[4];
for (int i = 0;i < 4;i++){
colors[i] = color;
}
if (hcenter || vcenter)
{
textDimension = getDimension(text);
if (hcenter)
offset.X = ((position.getWidth() - textDimension.Width)>>1) + offset.X;
if (vcenter)
offset.Y = ((position.getHeight() - textDimension.Height)>>1) + offset.Y;
}
示例13: IGUIComboBox
//! constructor
CGUIComboBox::CGUIComboBox(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle)
: IGUIComboBox(environment, parent, id, rectangle),
ListButton(0), ListBox(0), Selected(-1), HasFocus(false), LastFocus(0)
{
#ifdef _DEBUG
setDebugName("CGUICheckBox");
#endif
IGUISkin* skin = Environment->getSkin();
s32 width = 15;
if (skin)
width = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH);
core::rect<s32> r;
r.UpperLeftCorner.X = rectangle.getWidth() - width - 2;
r.LowerRightCorner.X = rectangle.getWidth() - 2;
r.UpperLeftCorner.Y = 2;
r.LowerRightCorner.Y = rectangle.getHeight() - 2;
ListButton = Environment->addButton(r, this, -1, L"");
if (skin && skin->getSpriteBank())
{
ListButton->setSpriteBank(skin->getSpriteBank());
ListButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL));
ListButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL));
}
ListButton->setSubElement(true);
ListButton->setTabStop(false);
// this element can be tabbed to
setTabStop(true);
setTabOrder(-1);
}
示例14: getColor
void CImageGUISkin::drawElementStyle( const SImageGUIElementStyle& elem, const core::rect<s32>& rect, const core::rect<s32>* clip, video::SColor* pcolor )
{
core::rect<s32> srcRect;
core::rect<s32> dstRect;
core::dimension2d< u32 > tsize = elem.Texture->getSize();
video::ITexture* texture = elem.Texture;
video::SColor color = elem.Color;
if ( pcolor )
color = *pcolor;
video::SColor faceColor = getColor(EGDC_3D_FACE);
color.setRed( (u8)(color.getRed() * faceColor.getRed() / 255) );
color.setGreen( (u8)(color.getGreen() * faceColor.getGreen() / 255) );
color.setBlue( (u8)(color.getBlue() * faceColor.getBlue() / 255) );
color.setAlpha( (u8)(color.getAlpha() * faceColor.getAlpha() / 255 ) );
video::SColor colors [4] = { color, color, color, color };
core::dimension2di dstSize = rect.getSize();
// Scale the border if there is insufficient room
SImageGUIElementStyle::SBorder dst = elem.DstBorder;
f32 scale = 1.0f;
if ( dstSize.Width < dst.Left + dst.Right )
{
scale = dstSize.Width / (f32)( dst.Left + dst.Right );
}
if ( dstSize.Height < dst.Top + dst.Bottom )
{
f32 x = dstSize.Height / (f32)( dst.Top + dst.Bottom );
if ( x < scale )
{
scale = x;
}
}
if ( scale < 1.0f )
{
dst.Left = (s32)( dst.Left * scale );
dst.Right = (s32)( dst.Right * scale );
dst.Top = (s32)( dst.Top * scale );
dst.Bottom = (s32)( dst.Bottom * scale );
}
const SImageGUIElementStyle::SBorder& src = elem.SrcBorder;
// Draw the top left corner
srcRect = core::rect<s32>( 0, 0, src.Left, src.Top );
dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.UpperLeftCorner.Y, rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y+dst.Top );
if ( !clip || clipRects( dstRect, srcRect, *clip ) )
VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
// Draw the top right corner
srcRect = core::rect<s32>( tsize.Width-src.Right, 0, tsize.Width, src.Top );
dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y, rect.LowerRightCorner.X, rect.UpperLeftCorner.Y+dst.Top );
if ( !clip || clipRects( dstRect, srcRect, *clip ) )
VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
// Draw the top border
srcRect = core::rect<s32>( src.Left, 0, tsize.Width-src.Right, src.Top );
dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y, rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y+dst.Top );
if ( !clip || clipRects( dstRect, srcRect, *clip ) )
VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
// Draw the left border
srcRect = core::rect<s32>( 0, src.Top, src.Left, tsize.Height-src.Bottom );
dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.UpperLeftCorner.Y+dst.Top, rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y-dst.Bottom );
if ( !clip || clipRects( dstRect, srcRect, *clip ) )
VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
// Draw the right border
srcRect = core::rect<s32>( tsize.Width-src.Right, src.Top, tsize.Width, tsize.Height-src.Bottom );
dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.UpperLeftCorner.Y+dst.Top, rect.LowerRightCorner.X, rect.LowerRightCorner.Y-dst.Bottom );
if ( !clip || clipRects( dstRect, srcRect, *clip ) )
VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
// Draw the middle section
srcRect = core::rect<s32>( src.Left, src.Top, tsize.Width-src.Right, tsize.Height-src.Bottom );
dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.UpperLeftCorner.Y+dst.Top, rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y-dst.Bottom );
if ( !clip || clipRects( dstRect, srcRect, *clip ) )
VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
// Draw the bottom left corner
srcRect = core::rect<s32>( 0, tsize.Height-src.Bottom, src.Left, tsize.Height );
dstRect = core::rect<s32>( rect.UpperLeftCorner.X, rect.LowerRightCorner.Y-dst.Bottom, rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y );
if ( !clip || clipRects( dstRect, srcRect, *clip ) )
VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
// Draw the bottom right corner
srcRect = core::rect<s32>( tsize.Width-src.Right, tsize.Height-src.Bottom, tsize.Width, tsize.Height );
dstRect = core::rect<s32>( rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y-dst.Bottom, rect.LowerRightCorner.X, rect.LowerRightCorner.Y );
if ( !clip || clipRects( dstRect, srcRect, *clip ) )
VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
// Draw the bottom border
srcRect = core::rect<s32>( src.Left, tsize.Height-src.Bottom, tsize.Width-src.Right, tsize.Height );
dstRect = core::rect<s32>( rect.UpperLeftCorner.X+dst.Left, rect.LowerRightCorner.Y-dst.Bottom, rect.LowerRightCorner.X-dst.Right, rect.LowerRightCorner.Y );
if ( !clip || clipRects( dstRect, srcRect, *clip ) )
VideoDriver->draw2DImage( texture, dstRect, srcRect, clip, colors, true );
//.........这里部分代码省略.........
示例15: draw
void ScalableFont::doDraw(const core::stringw& text,
const core::rect<s32>& position, video::SColor color,
bool hcenter, bool vcenter,
const core::rect<s32>* clip,
FontCharCollector* charCollector)
{
if (!m_video_driver) return;
GUIEngine::GlyphPageCreator* gp_creator = GUIEngine::getGlyphPageCreator();
if (m_shadow)
{
m_shadow = false; // avoid infinite recursion
core::rect<s32> shadowpos = position;
shadowpos.LowerRightCorner.X += 2;
shadowpos.LowerRightCorner.Y += 2;
draw(text, shadowpos, m_shadow_color, hcenter, vcenter, clip);
m_shadow = true; // set back
}
core::position2d<s32> offset = position.UpperLeftCorner;
core::dimension2d<s32> text_dimension;
if (m_rtl || hcenter || vcenter || clip)
{
text_dimension = getDimension(text.c_str());
if (hcenter) offset.X += (position.getWidth() - text_dimension.Width) / 2;
else if (m_rtl) offset.X += (position.getWidth() - text_dimension.Width);
if (vcenter) offset.Y += (position.getHeight() - text_dimension.Height) / 2;
if (clip)
{
core::rect<s32> clippedRect(offset, text_dimension);
clippedRect.clipAgainst(*clip);
if (!clippedRect.isValid()) return;
}
}
// ---- collect character locations
const unsigned int text_size = text.size();
core::array<s32> indices(text_size);
core::array<core::position2di> offsets(text_size);
std::vector<bool> fallback(text_size);
if (m_type == T_NORMAL || T_BOLD) //lazy load char, have to do this again
{ //because some text isn't drawn with getDimension
for (u32 i = 0; i < text_size; i++)
{
wchar_t c = text[i];
if (c == L'\r' || c == L'\n' || c == L' ' || c < 32) continue;
if (!GUIEngine::getFont()->hasThisChar(c))
gp_creator->insertChar(c);
if (charCollector != NULL && m_type == T_NORMAL && m_spritebank->getSprites()
[GUIEngine::getFont()->getSpriteNoFromChar(&c)].Frames[0].textureNumber
== m_spritebank->getTextureCount() - 1) //Prevent overwriting texture used by billboard text
{
Log::debug("ScalableFont::doDraw",
"Character used by billboard text is in the last "
"glyph page of normal font. Create a new glyph "
"page for new characters inserted later to prevent "
"it from being removed.");
GUIEngine::getFont()->forceNewPage();
}
}
if (gp_creator->getNewChar().size() > 0 && !m_is_hollow_copy && m_scale == 1)
{
Log::debug("ScalableFont::doDraw",
"New character(s) %s discoverd, perform lazy loading",
StringUtils::wideToUtf8(gp_creator->getNewChar()).c_str());
if (!GUIEngine::getFont()->lazyLoadChar())
Log::error("ScalableFont::lazyLoadChar",
"Can't insert new char into glyph pages.");
}
}
for (u32 i = 0; i < text_size; i++)
{
wchar_t c = text[i];
if (c == L'\r' || // Windows breaks
c == L'\n' ) // Unix breaks
{
if(c==L'\r' && text[i+1]==L'\n') c = text[++i];
offset.Y += (int)(m_max_height*m_scale);
offset.X = position.UpperLeftCorner.X;
if (hcenter)
offset.X += (position.getWidth() - text_dimension.Width) >> 1;
continue;
} // if lineBreak
bool use_fallback_font = false;
const SFontArea &area = getAreaFromCharacter(c, &use_fallback_font);
fallback[i] = use_fallback_font;
//.........这里部分代码省略.........