void CNFORenderer::RenderBackgrounds(size_t a_rowStart, size_t a_rowEnd, double a_yBase, cairo_t* cr) const { cairo_save(cr); if(GetBackColor().A > 0) { cairo_set_source_rgba(cr, S_COLOR_T_CAIRO_A(GetBackColor())); cairo_paint(cr); } if(m_nfo->HasColorMap()) { double dbw = static_cast<double>(GetBlockWidth()); double dbh = static_cast<double>(GetBlockHeight()); uint32_t l_defaultColor = GetBackColor().AsWord(); for(size_t row = (a_rowStart == -1 ? 0 : a_rowStart); row <= a_rowEnd; row++) { std::vector<size_t> l_columns; std::vector<uint32_t> l_colors; if(!m_nfo->GetColorMap()->GetLineBackgrounds(row, l_defaultColor, m_gridData->GetCols(), l_columns, l_colors)) continue; _ASSERT(l_colors.size() == l_columns.size()); _ASSERT(l_columns.size() > 0); size_t col = 0; for(size_t section = 0; section < l_colors.size(); section++) { _ASSERT(l_columns[section] > 0); _ASSERT(l_columns[section] <= m_gridData->GetCols()); size_t col_to = col + l_columns[section]; _ASSERT(col_to > col); if(l_colors[section] != l_defaultColor) { double x_from = col * dbw, x_to = col_to * dbw; cairo_set_source_rgb(cr, S_COLOR_T_CAIRO(S_COLOR_T(l_colors[section]))); cairo_rectangle(cr, GetPadding() + x_from, a_yBase + GetPadding() + dbh * row, x_to - x_from, dbh); cairo_fill(cr); } col = col_to; } } } cairo_restore(cr); }
int CNFORenderer::GetStripeHeight(size_t a_stripe) const { int l_height = m_stripeHeight; if(a_stripe == 0) l_height += GetPadding(); if(a_stripe == m_numStripes - 1) l_height += GetPadding(); return l_height; }
void CheckButton::OnRender(suic::DrawingContext * drawing) { if (GetStyle()) { // // 先绘制背景 // suic::Rect drawrect(0, 0, RenderSize().cx, RenderSize().cy); suic::ImageBrushPtr bkgnd(suic::Render::GetProperty(this, GetStyle().get(), InternalBackgrount())); if (bkgnd) { suic::Rect rectBk = bkgnd->GetContentBrounds(); drawrect.right = drawrect.left + rectBk.Width(); drawrect.top += (drawrect.Height() - rectBk.Height()) / 2; drawrect.bottom = drawrect.top + rectBk.Height(); bkgnd->Draw(drawing, &drawrect); } // // 绘制文字 // drawrect.top = 0; drawrect.bottom = RenderSize().cy; drawrect.left = drawrect.right + GetPadding().left; drawrect.right = RenderSize().cx; suic::Render::RenderText(drawing, this, GetText(), &drawrect, true); } }
void GenericThumbnail::GetRequiredSize(INT32& width, INT32& height) { GetRequiredThumbnailSize(width, height); INT32 padding_width = 0, padding_height = 0; GetPadding(padding_width, padding_height); width += padding_width; height += padding_height; }
Int32 SoftKeyboard::GetSkbTotalWidth() { AutoPtr<IRect> padding = GetPadding(); Int32 left = 0, right = 0; padding->GetLeft(&left); padding->GetRight(&right); return mSkbCoreWidth + left + right; }
Int32 SoftKeyboard::GetSkbTotalHeight() { AutoPtr<IRect> padding = GetPadding(); Int32 top = 0, bottom = 0; padding->GetTop(&top); padding->GetBottom(&bottom); return mSkbCoreHeight + top + bottom; }
suic::Size TreeViewItem::MeasureOverride(const suic::Size& availableSize) { _expand->Measure(availableSize); _check.Measure(availableSize); suic::Size retSize; if (!IsCollapsed()) { retSize = __super::MeasureOverride(availableSize); } retSize.cy += GetPadding().top; retSize.cy += GetPadding().bottom; retSize.cx += GetIndent(); return retSize; }
//----------------------------------------------------------------------------------------------------------------------------------- void TextBox::Resize() { const Vector2& textSize = m_text->GetSize(); const Vector2& padding = GetPadding(); SetSize(textSize + 2 * padding); m_resized = true; }
XResult CXElement::SetLayoutRect( Property::LayoutRectType param ) { CRect padding; GetPadding(padding); param.left -= padding.left; param.right += padding.right; param.top -= padding.top; param.bottom += padding.bottom; return SetSize(param.Size()); }
XResult CXElement::GetLayoutRect( Property::LayoutRectType& value ) { GetRect(value); CRect padding; GetPadding(padding); value.left += padding.left; value.right -= padding.right; value.top += padding.top; value.bottom -= padding.bottom; return XResult_OK; }
suic::Size ComboBox::ArrangeOverride(const suic::Size& size) { suic::Rect rect(0, 0, size.cx, size.cy); rect.right -= size.cy; rect.Deflate(GetBorderThickness()); rect.Deflate(GetPadding()); _textBox->Arrange(rect); return size; }
void CheckBoxObject::SaveToXml(TiXmlElement * elem) { TiXmlElement * str = new TiXmlElement( "String" ); elem->LinkEndChild( str ); str->SetAttribute("value", GetString().c_str()); TiXmlElement * checked = new TiXmlElement( "Checked" ); elem->LinkEndChild( checked ); checked->SetAttribute("value", static_cast<bool>(IsChecked())); TiXmlElement * font = new TiXmlElement( "Font" ); elem->LinkEndChild( font ); font->SetAttribute("value", GetFont().c_str()); TiXmlElement * characterSize = new TiXmlElement( "CharacterSize" ); elem->LinkEndChild( characterSize ); characterSize->SetAttribute("value", GetCharacterSize()); TiXmlElement * backgroundColorElem = new TiXmlElement( "BackgroundColorScheme" ); elem->LinkEndChild( backgroundColorElem ); backgroundColor->SaveToXml(backgroundColorElem); TiXmlElement * borderColorElem = new TiXmlElement( "BorderColorScheme" ); elem->LinkEndChild( borderColorElem ); borderColor->SaveToXml(borderColorElem); TiXmlElement * textColorElem = new TiXmlElement( "TextColorScheme" ); elem->LinkEndChild( textColorElem ); textColor->SaveToXml(textColorElem); TiXmlElement * checkColorElem = new TiXmlElement( "CheckColorScheme" ); elem->LinkEndChild( checkColorElem ); checkColor->SaveToXml(checkColorElem); TiXmlElement * borderWidthElem = new TiXmlElement( "BorderWidth" ); elem->LinkEndChild( borderWidthElem ); borderWidthElem->SetAttribute("value", GetBorderWidth()); TiXmlElement * paddingElem = new TiXmlElement( "Padding" ); elem->LinkEndChild( paddingElem ); paddingElem->SetAttribute("value", GetPadding()); TiXmlElement * boxSizeElem = new TiXmlElement( "BoxSize" ); elem->LinkEndChild( boxSizeElem ); boxSizeElem->SetAttribute("value", GetBoxSize()); TiXmlElement * checkSignSizeElem = new TiXmlElement( "CheckSignSize" ); elem->LinkEndChild( checkSignSizeElem ); checkSignSizeElem->SetAttribute("value", GetCheckSignSize()); }
INT32 OpLabel::GetTextHeight() { INT32 h = 0, left, top, right, bottom; GetPadding(&left, &top, &right, &bottom); if (m_wrap) h = ((OpMultilineEdit *)m_edit)->GetContentHeight(); else h = ((OpEdit *)m_edit)->string.GetHeight(); h += (top + bottom); return h; }
INT32 OpLabel::GetTextWidth() { INT32 w = 0, left, top, right, bottom; GetPadding(&left, &top, &right, &bottom); if (m_wrap) w = ((OpMultilineEdit *)m_edit)->GetMaxBlockWidth(); else w = ((OpEdit *)m_edit)->string.GetWidth(); w += (left + right); return w; }
void CNFORenderer::RenderStripeBlocks(size_t a_stripe, bool a_opaqueBg, bool a_gaussStep, cairo_t* a_context) const { cairo_t* l_context = (a_context ? a_context : cairo_create(GetStripeSurface(a_stripe))); RenderBlocks(a_opaqueBg, a_gaussStep, l_context, (m_numStripes > 1 ? a_stripe * m_linesPerStripe - GetStripeExtraLinesTop(a_stripe) : (size_t)-1), a_stripe * m_linesPerStripe + m_linesPerStripe + GetStripeExtraLinesBottom(a_stripe), // see comment in RenderStripe(): 0, (a_stripe == 0 ? 0 : -GetPadding() - (double)a_stripe * m_stripeHeight) + GetStripeHeightExtraTop(a_stripe)); if(!a_context) { cairo_destroy(l_context); } }
INT32 OpLabel::GetPreferedHeight(UINT32 rows) { INT32 h = 0, left, top, right, bottom; GetPadding(&left, &top, &right, &bottom); if (m_wrap) { VisualDeviceHandler handler(m_edit); h = ((OpMultilineEdit *)m_edit)->GetVisibleLineHeight() + 1; //Pixel compension } else h = ((OpEdit *)m_edit)->string.GetHeight(); h = rows * h + top + bottom; return h; }
NS_IMETHODIMP nsIFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding) { aBorderAndPadding.SizeTo(0, 0, 0, 0); nsresult rv = GetBorder(aBorderAndPadding); if (NS_FAILED(rv)) return rv; nsMargin padding; rv = GetPadding(padding); if (NS_FAILED(rv)) return rv; aBorderAndPadding += padding; return rv; }
Size Border::MeasureOverrideWithError (Size availableSize, MoonError *error) { Size desired = Size (0,0); Thickness border = *GetPadding () + *GetBorderThickness (); // Get the desired size of our child, and include any margins we set VisualTreeWalker walker = VisualTreeWalker (this); while (UIElement *child = walker.Step ()) { child->MeasureWithError (availableSize.GrowBy (-border), error); desired = child->GetDesiredSize (); } desired = desired.GrowBy (border); desired = desired.Min (availableSize); return desired; }
/** * * Method Name: ParseByeReport * * * Inputs: unsigned char *puchReportBuffer - Buffer containing the Bye Report * * Outputs: None * * Returns: unsigned long * * Description: Extracts the contents of an Bye report using the buffer * passed in by the caller. * * Usage Notes: The header of the RTCP Report shall be parsed by delegating * to the base class. * * */ unsigned long CByeReport::ParseByeReport(unsigned char *puchReportBuffer) { unsigned char *puchPayloadBuffer = puchReportBuffer; // Check whether the RTCP Header has been correctly // formed (Version, etc...). if(!ParseRTCPHeader(puchReportBuffer)) return(GetReportLength()); // Good header. Let's bump the payload pointer and continue. puchPayloadBuffer += GetHeaderLength(); // Let's store the CSRCs from the Bye Report unsigned long ulCSRCCount = GetReportCount() ? GetReportCount() - 1 : 0; SetCSRC((ssrc_t *)puchPayloadBuffer, ulCSRCCount, TRUE); puchPayloadBuffer += (sizeof(ssrc_t) * ulCSRCCount); // Let's determine whether there is an optional Reason field associated // with this Bye Report. We can surmise this through comparing the // packet length to what we've already processed if(puchPayloadBuffer - puchReportBuffer < (long)GetReportLength()) { uint32_t ulReasonLength = (uint32_t)*puchPayloadBuffer++; SetReason(puchPayloadBuffer, ulReasonLength); puchPayloadBuffer += ulReasonLength; } // Let's process any padding that might be present to align the // payload on a 32 bit boundary. if(GetPadding()) puchPayloadBuffer += ExtractPadding(puchPayloadBuffer); return(puchPayloadBuffer - puchReportBuffer); }
Size Border::ArrangeOverrideWithError (Size finalSize, MoonError *error) { Thickness border = *GetPadding () + *GetBorderThickness (); Size arranged = finalSize; VisualTreeWalker walker = VisualTreeWalker (this); while (UIElement *child = walker.Step ()) { Rect childRect (0,0,finalSize.width,finalSize.height); childRect = childRect.GrowBy (-border); child->ArrangeWithError (childRect, error); arranged = Size (childRect.width, childRect.height).GrowBy (border); arranged = arranged.Max (finalSize); } return finalSize; }
void CNFORenderer::CalcStripeDimensions() { if(!m_nfo || !m_gridData) { return; } #ifndef COMPACT_RELEASE // 2 CPU cores <=> 2000 px stripe height // ==> 8 CPU cores <=> 250 // (= more threads) // but: never use less than 500px per stripe. size_t l_stripeHeightMaxForCores = std::max(2000 * 2 / omp_get_num_procs(), 500); #else size_t l_stripeHeightMaxForCores = 2000; #endif /* COMPACT_RELEASE */ size_t l_stripeHeightMax = std::max(l_stripeHeightMaxForCores, GetBlockHeight() * 2); // MUST not be smaller than one line's height, using two for sanity size_t l_numStripes = GetHeight() / l_stripeHeightMax; // implicit floor() if(l_numStripes == 0) l_numStripes = 1; size_t l_linesPerStripe = m_nfo->GetGridHeight() / l_numStripes; // implicit floor() while(l_linesPerStripe * l_numStripes < m_nfo->GetGridHeight()) { // correct rounding errors l_numStripes++; } // storing these three is a bit redundant, but saves code & calculations in other places: m_linesPerStripe = l_linesPerStripe; m_stripeHeight = static_cast<int>(l_linesPerStripe * GetBlockHeight()); m_numStripes = l_numStripes; _ASSERT(m_stripeHeight * m_numStripes + GetPadding() * 2 >= GetHeight()); }
void TextBlock::OnRender(suic::DrawingContext * drawing) { suic::Rect elemrect(0, 0, RenderSize().cx, RenderSize().cy); // 绘制背景 //suic::UIRender::DrawBackground(drawing, GetStyle()->GetTrigger(), &elemrect); elemrect.Deflate(GetPadding()); suic::UIRender::DrawText(drawing, GetText() , GetStyle()->GetTrigger(), &elemrect , GetHorizontalContentAlignment(), GetVerticalContentAlignment()); // // 如果拥有焦点则绘制焦点虚线 // if (IsFocused()) { suic::Rect rect(0, 0, RenderSize().cx, RenderSize().cy); rect.Deflate(GetBorderThickness()); drawing->DrawFocused(&rect); } }
void ItemsControl::OnInitialized() { __super::OnInitialized(); // 加入可视树 AddVisualChild(_scrollHost.get()); AddLogicalChild(_scrollHost.get()); _itemsHost->WriteFlag(CoreFlags::IsComposition, true); _scrollHost->WriteFlag(CoreFlags::IsComposition, true); _scrollHost->BeginInit(); _scrollHost->EndInit(); _scrollHost->SetHorizontalAlignment(HoriAlignment::Stretch); _scrollHost->SetVerticalAlignment(VertAlignment::Stretch); _scrollHost->SetMargin(GetMargin()); _scrollHost->SetFocusable(false); _itemsHost->SetFocusable(false); _itemsHost->SetPadding(GetPadding()); SetPadding(suic::Rect()); }
int UI::Element::GetInnerLeft() const { return GetLeft() + GetPadding(); }
bool CNFORenderer::DrawToSurface(cairo_surface_t *a_surface, int dest_x, int dest_y, // coordinates in a_surface int source_x, int source_y, // coordinates between 0 and GetHeight() / GetWidth() int a_width, int a_height) { if(m_onDemandRendering && m_numStripes == 0) { CalcStripeDimensions(); } if(!m_onDemandRendering || m_numStripes == 1) { if(!m_rendered && !Render()) { return false; } } else if(!m_rendered && !m_gridData) { // not correctly initialized yet return false; } cairo_t *cr = cairo_create(a_surface); // fix for sloppy width + height calculations... int l_widthFixed = std::min(a_width, (int)GetWidth() - source_x); int l_heightFixed = std::min(a_height, (int)GetHeight() - source_y); if(m_numStripes == 1) { cairo_set_source_surface(cr, *m_stripes[0], dest_x - source_x, dest_y - source_y); cairo_rectangle(cr, dest_x, dest_y, l_widthFixed, l_heightFixed); cairo_fill(cr); } else { int l_padding = GetPadding(), l_stripeStart = (source_y - l_padding) / m_stripeHeight, // implicit floor() l_stripeEnd = ((source_y + a_height - l_padding) / m_stripeHeight); // sanity confinement ;) l_stripeStart = std::min(l_stripeStart, (int)m_numStripes - 1); l_stripeEnd = std::min(l_stripeEnd, (int)m_numStripes - 1); if(m_onDemandRendering) { Render(l_stripeStart, l_stripeEnd); } for(int l_stripe = l_stripeStart; l_stripe <= l_stripeEnd; l_stripe++) { cairo_surface_t* l_sourceSourface = GetStripeSurface(l_stripe); if(!l_sourceSourface) { // happens when zooming out, shouldn't happen otherwise. continue; } // y pos in complete image: int l_stripe_virtual_y = (l_stripe == 0 ? 0 : l_stripe * m_stripeHeight + GetPadding()); // y pos in stripe: int l_stripe_source_y = (source_y - l_stripe_virtual_y); // height of area of this stripe that is to be painted: int l_height = (l_stripe == l_stripeEnd ? l_heightFixed : GetStripeHeight(l_stripe) - l_stripe_source_y); if(l_stripe > l_stripeStart) { // must clip destination or additional pixels that have been added to stripes for // correct blurring will be copied, too: cairo_save(cr); cairo_rectangle(cr, dest_x, l_stripe_virtual_y - source_y, l_widthFixed, l_height); cairo_clip(cr); } // actual copy operation: cairo_set_source_surface(cr, l_sourceSourface, dest_x - source_x, dest_y - l_stripe_source_y - GetStripeHeightExtraTop(l_stripe)); cairo_rectangle(cr, dest_x, dest_y, l_widthFixed, l_height); cairo_fill(cr); if(l_stripe > l_stripeStart) { // undo clip: cairo_restore(cr); } } } if(l_heightFixed < a_height) { cairo_set_source_rgb(cr, S_COLOR_T_CAIRO(GetBackColor())); cairo_rectangle(cr, dest_x, dest_y + l_heightFixed, a_width, a_height - l_heightFixed); cairo_fill(cr); } if(l_widthFixed < a_width) { cairo_set_source_rgb(cr, S_COLOR_T_CAIRO(GetBackColor())); cairo_rectangle(cr, dest_x + l_widthFixed, dest_y, a_width - l_widthFixed, a_height); cairo_fill(cr); } cairo_destroy(cr); return true; }
int UI::Element::GetInnerWidth() const { return std::max(0, GetWidth() - 2 * GetPadding()); }
void CheckBoxObject::UpdateProperties() { //Update BackgroundColor sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId(), "BackgroundColor", backgroundColor->unfocusedColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":PRELIGHT", "BackgroundColor", backgroundColor->hoveredColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":ACTIVE", "BackgroundColor", backgroundColor->focusedColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":INSENSITIVE", "BackgroundColor", backgroundColor->disabledColor ); //Update BorderColor sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId(), "BorderColor", borderColor->unfocusedColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":PRELIGHT", "BorderColor", borderColor->hoveredColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":ACTIVE", "BorderColor", borderColor->focusedColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":INSENSITIVE", "BorderColor", borderColor->disabledColor ); //Update TextColor sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + "", "Color", textColor->unfocusedColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":PRELIGHT", "Color", textColor->hoveredColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":ACTIVE", "Color", textColor->focusedColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":INSENSITIVE", "Color", textColor->disabledColor ); //Update CheckColor sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + "", "CheckColor", checkColor->unfocusedColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":PRELIGHT", "CheckColor", checkColor->hoveredColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":ACTIVE", "CheckColor", checkColor->focusedColor ); sfg::Context::Get().GetEngine().SetProperty<sf::Color>( "CheckButton#" + obj->GetId() + ":INSENSITIVE", "CheckColor", checkColor->disabledColor ); //Update font size sfg::Context::Get().GetEngine().SetProperty<unsigned int>("CheckButton#" + obj->GetId() + "", "FontSize", GetCharacterSize()); sfg::Context::Get().GetEngine().SetProperty<std::string>("CheckButton#" + obj->GetId(), "FontName", std::string("gdres:") + GetFont()); //Update border width and padding sfg::Context::Get().GetEngine().SetProperty<float>("CheckButton#" + obj->GetId(), "BorderWidth", static_cast<float>(GetBorderWidth())); sfg::Context::Get().GetEngine().SetProperty<float>("CheckButton#" + obj->GetId(), "Padding", static_cast<float>(GetPadding())); sfg::Context::Get().GetEngine().SetProperty<float>("CheckButton#" + obj->GetId(), "BoxSize", static_cast<float>(GetBoxSize())); sfg::Context::Get().GetEngine().SetProperty<float>("CheckButton#" + obj->GetId(), "CheckSize", static_cast<float>(GetCheckSignSize())); }
void EditorTweaks::AlignToString(const wxString AlignmentString) { cbStyledTextCtrl* control = GetSafeControl(); if (!control) return; int line_start = wxSCI_INVALID_POSITION; int line_end = wxSCI_INVALID_POSITION; if (GetSelectionLines(line_start, line_end)) { // get furthest position of alignmentstring size_t find_position = wxString::npos; size_t max_position = wxString::npos; int matches = 0; for (int i=line_start; i<=line_end; i++) { // look for string find_position = control->GetLine(i).Find(AlignmentString); // store max position if (find_position != wxString::npos) { matches++; if ((int) find_position > (int) max_position) max_position = find_position; } } // if string has been found more than once if (matches > 1) { // loop through lines wxString replacement_text = _T(""); wxString current_line = _T(""); int spacing_diff = 0; for (int i=line_start; i<=line_end; i++) { // get line current_line = control->GetLine(i); if ( i == line_end ) current_line = current_line.Trim(); // look for string find_position = current_line.Find(AlignmentString); // insert spacing if (find_position != wxString::npos) { spacing_diff = (int) max_position - (int) find_position; if (spacing_diff > 0) { // assemble next part of replacement string current_line = current_line.insert(find_position, GetPadding(_T(" "), spacing_diff)); } } // tack on line replacement_text += current_line; } // start undo control->BeginUndoAction(); // get character positions of true selection start and end int pos_start = control->PositionFromLine(line_start); int pos_end = control->GetLineEndPosition(line_end); // select all lines properly control->SetSelectionVoid(pos_start, pos_end); // replace with replacement string control->ReplaceSelection(replacement_text); // finish undo control->EndUndoAction(); } } }
void CNFORenderer::RenderStripe(size_t a_stripe) const { cairo_surface_t * const l_surface = GetStripeSurface(a_stripe); _ASSERT(l_surface != NULL); if((!m_hasBlocks || m_classic) && GetBackColor().A > 0) { cairo_t* cr = cairo_create(l_surface); cairo_set_source_rgba(cr, S_COLOR_T_CAIRO_A(GetBackColor())); cairo_paint(cr); cairo_destroy(cr); } // hacke-di-hack (RenderClassic is adding GetPadding() for historical reasons, so we have to subtract it beforehand. // it's also operating on the full NFO image's coordinates, so we have to subtract those too): double l_baseY = (a_stripe == 0 ? 0 : -GetPadding() - (double)a_stripe * m_stripeHeight) + GetStripeHeightExtraTop(a_stripe); size_t l_rowStart = (m_numStripes > 1 ? a_stripe * m_linesPerStripe - GetStripeExtraLinesTop(a_stripe) : (size_t)-1), l_rowEnd = a_stripe * m_linesPerStripe + m_linesPerStripe + GetStripeExtraLinesBottom(a_stripe); if(m_classic) { RenderClassic(GetTextColor(), NULL, GetHyperLinkColor(), false, l_rowStart, 0, l_rowEnd, m_nfo->GetGridWidth() - 1, l_surface, 0, l_baseY); } else { if(m_hasBlocks && GetEnableGaussShadow() && ((m_partial & NRP_RENDER_BLOCKS) != 0 || (m_partial & NRP_RENDER_GAUSS_BLOCKS) != 0)) { if((m_partial & NRP_RENDER_GAUSS_SHADOW) != 0) { shared_ptr<CCairoBoxBlur> p_blur(new CCairoBoxBlur( (int)GetWidth(), GetStripeHeightPhysical(a_stripe), (int)GetGaussBlurRadius(), ms_useGPU && !m_forceGPUOff)); p_blur->SetAllowFallback(m_allowCPUFallback); cairo_t* cr = cairo_create(l_surface); RenderBackgrounds(l_rowStart, l_rowEnd, l_baseY, cr); // shadow effect: if(!m_cancelRenderingImmediately) { RenderStripeBlocks(a_stripe, false, true, p_blur->GetContext()); // important when running in CPU fallback mode only: cairo_set_source_rgba(cr, S_COLOR_T_CAIRO_A(GetGaussColor())); if(!p_blur->Paint(cr) && p_blur->IsFallbackAllowed()) { // retry once. RenderStripeBlocks(a_stripe, false, true, p_blur->GetContext()); // important when running in CPU fallback mode only: cairo_set_source_rgba(cr, S_COLOR_T_CAIRO_A(GetGaussColor())); p_blur->Paint(cr); } } cairo_destroy(cr); } if((m_partial & NRP_RENDER_GAUSS_BLOCKS) != 0 && (m_partial & NRP_RENDER_GAUSS_SHADOW) == 0 && !m_cancelRenderingImmediately) { // render blocks in gaussian color RenderStripeBlocks(a_stripe, false, true); } else if((m_partial & NRP_RENDER_BLOCKS) != 0 && !m_cancelRenderingImmediately) { // normal mode RenderStripeBlocks(a_stripe, false, false); } } else if(m_hasBlocks && (m_partial & NRP_RENDER_BLOCKS) != 0 && !m_cancelRenderingImmediately) { RenderStripeBlocks(a_stripe, true, false); } if((m_partial & NRP_RENDER_TEXT) != 0 && !m_cancelRenderingImmediately) { RenderText(GetTextColor(), NULL, GetHyperLinkColor(), l_rowStart, 0, l_rowEnd, m_nfo->GetGridWidth() - 1, l_surface, 0, l_baseY); } } }
void CNFORenderer::RenderBlocks(bool a_opaqueBg, bool a_gaussStep, cairo_t* a_context, size_t a_rowStart, size_t a_rowEnd, double a_xBase, double a_yBase) const { double l_off_x = GetPadding() + a_xBase, l_off_y = GetPadding() + a_yBase; size_t l_rowStart = 0, l_rowEnd = m_gridData->GetRows() - 1; if(a_rowStart != (size_t)-1) { l_rowStart = std::max(a_rowStart, l_rowStart); l_rowEnd = std::min(a_rowEnd, l_rowEnd); } cairo_t * const cr = a_context; cairo_save(cr); if(a_opaqueBg) { RenderBackgrounds(l_rowStart, l_rowEnd, a_yBase, cr); } cairo_set_antialias(cr, CAIRO_ANTIALIAS_SUBPIXEL); bool l_hasColorMap = m_nfo->HasColorMap(); int l_oldAlpha = 0; uint32_t l_oldColor = 0; bool l_first = true; // micro optimization const double bwd = static_cast<double>(GetBlockWidth()); const double bhd = static_cast<double>(GetBlockHeight()); const double bwd05 = bwd * 0.5; const double bhd05 = bhd * 0.5; for(size_t row = l_rowStart; row <= l_rowEnd; row++) { if(m_cancelRenderingImmediately) { break; } for(size_t col = 0; col < m_gridData->GetCols(); col++) { const CRenderGridBlock *l_block = &(*m_gridData)[row][col]; if(l_block->shape == RGS_NO_BLOCK || l_block->shape == RGS_WHITESPACE || l_block->shape == RGS_WHITESPACE_IN_TEXT) { continue; } S_COLOR_T l_drawingColor = a_gaussStep ? GetGaussColor() : GetArtColor(); if(l_hasColorMap) { uint32_t clr; m_nfo->GetColorMap()->GetForegroundColor(row, col, l_drawingColor.AsWord(), clr); l_drawingColor = S_COLOR_T(clr); } if(l_first || (l_block->alpha != l_oldAlpha) // R,G,B never change during the loop (unless there's a colormap) || (l_hasColorMap && l_drawingColor != l_oldColor) ) { cairo_fill(cr); // complete previous drawing operation(s) cairo_set_source_rgba(cr, S_COLOR_T_CAIRO(l_drawingColor), (l_block->alpha / 255.0) * (l_drawingColor.A / 255.0)); // known issue: Alpha from GetGauss/ArtColor is discarded if there's a colormap. l_oldAlpha = l_block->alpha; l_oldColor = l_drawingColor.AsWord(); l_first = false; } double l_pos_x = col * bwd, l_pos_y = row * bhd, l_width = bwd, l_height = bhd; switch(l_block->shape) { case RGS_BLOCK_LOWER_HALF: l_pos_y += bhd05; case RGS_BLOCK_UPPER_HALF: l_height = bhd05; break; case RGS_BLOCK_RIGHT_HALF: l_pos_x += bwd05; case RGS_BLOCK_LEFT_HALF: l_width = bwd05; break; case RGS_BLACK_SQUARE: l_width = l_height = bwd * 0.75; l_pos_y += bhd05 - l_height * 0.5; l_pos_x += bwd05 - l_width * 0.5; break; case RGS_BLACK_SMALL_SQUARE: l_width = l_height = bwd05; l_pos_y += bhd05 - l_height * 0.5; l_pos_x += bwd05 - l_width * 0.5; break; } cairo_rectangle(cr, l_off_x + l_pos_x, l_off_y + l_pos_y, l_width, l_height); } } cairo_fill(cr); // complete pending drawing operation(s) cairo_restore(cr); }