suic::Size WrapPanel::ArrangeOverride(const suic::Size& size) { ClearVisualChildren(); suic::Rect rect; int iPerRowCount = size.cx / (_horizontalSpace + _itemWidth); int iRight = size.cx - GetBorderThickness().right - _horizontalSpace; int iBottom = size.cy - GetBorderThickness().bottom - _verticalSpace; if (iPerRowCount == 0) { ++iPerRowCount; } int iRowHei = iPerRowCount * (_verticalSpace + _itemHeight); int iRowWid = iPerRowCount * (_horizontalSpace + _itemWidth) - _horizontalSpace; int iRealCount = 0; rect.left = GetBorderThickness().left + _horizontalSpace; rect.top = GetBorderThickness().top + _verticalSpace; for (int i = 0; i < GetChildrenCount(); ++i) { suic::Element* pElem = GetChild(i); if (pElem->IsVisible()) { ++iRealCount; rect.right = rect.left + _itemWidth; rect.bottom = rect.top + _itemHeight; AddVisualChild(pElem); pElem->Arrange(rect); rect.left = rect.right + _horizontalSpace; if (rect.right >= iRowWid) { rect.left = GetBorderThickness().left + _horizontalSpace; rect.top = rect.bottom + _verticalSpace; } if (rect.bottom >= iBottom) { break; } } } return size; }
void ComboBox::OnRender(suic::DrawingContext * drawing) { suic::StylePtr styleArrow = FindResource(_T("ComboBox.Down")); suic::Point pt; suic::Rect drawrect(pt.x, pt.y, RenderSize().cx, RenderSize().cy); // // 先绘制背景 // if (GetBackground()) { GetBackground()->Draw(drawing, &drawrect); } // 获取下拉箭头的设置 if (styleArrow.get()) { suic::BrushPtr bkgnd(suic::Render::GetProperty(this, styleArrow.get(), _T("Background"))); if (bkgnd) { suic::Rect downRect = drawrect; downRect.Deflate(GetBorderThickness()); downRect.left = downRect.right - 16; bkgnd->Draw(drawing, &downRect); } } suic::Render::RenderBorder(drawing, this, &drawrect); }
suic::Size ItemsControl::ArrangeOverride(const suic::Size& availableSize) { suic::Rect finalRect(0, 0, availableSize.cx, availableSize.cy); finalRect.Deflate(GetBorderThickness()); _scrollHost->Arrange(finalRect); return availableSize; }
void CReportEntityLine::Draw( CDC* dc, CRect rect ) /* ============================================================ Function : CReportEntityLine::Draw Description : Draws the object. Access : Public Return : void Parameters : CDC* dc - "CDC" to draw to CRect rect - True (zoomed) rectangle to draw to. Usage : Called from "CDiagramEditor::DrawObjects". ============================================================*/ { CPen pen; const float* table = Drawer::GetColorByIndex(GetBorderColor()); COLORREF clr = RGB((int)(table[0]*255.0f),(int)(table[1]*255.0f),(int)(table[2]*255.0f)); pen.CreatePen( PS_SOLID, GetBorderThickness(), clr ); dc->SelectObject( &pen ); dc->MoveTo( rect.TopLeft() ); dc->LineTo( rect.BottomRight() ); dc->SelectStockObject( BLACK_PEN ); }
void CReportEntityBox::Draw( CDC* dc, CRect rect ) /* ============================================================ Function : CReportEntityBox::Draw Description : Draws the object. Access : Public Return : void Parameters : CDC* dc - "CDC" to draw to CRect rect - True (zoomed) rectangle to draw to. Usage : Called from "CDiagramEditor::DrawObjects". ============================================================*/ { if( GetFill() ) { const float* table = Drawer::GetColorByIndex(GetFillColor()); COLORREF clr = RGB((int)(table[0]*255.0f),(int)(table[1]*255.0f),(int)(table[2]*255.0f)); dc->FillSolidRect(rect,clr); } CPen pen; if( GetBorderStyle()!=0 ) { const float* table = Drawer::GetColorByIndex(GetBorderColor()); COLORREF clr = RGB((int)(table[0]*255.0f),(int)(table[1]*255.0f),(int)(table[2]*255.0f)); pen.CreatePen( PS_SOLID, GetBorderThickness(), clr ); dc->SelectObject( &pen ); if (GetBorderStyle() & DIAGRAM_FRAME_STYLE_LEFT) { dc->MoveTo(rect.left,rect.bottom); dc->LineTo(rect.left,rect.top); } if (GetBorderStyle() & DIAGRAM_FRAME_STYLE_RIGHT) { dc->MoveTo(rect.right,rect.bottom); dc->LineTo(rect.right,rect.top); } if (GetBorderStyle() & DIAGRAM_FRAME_STYLE_TOP) { dc->MoveTo(rect.left,rect.top); dc->LineTo(rect.right,rect.top); } if (GetBorderStyle() & DIAGRAM_FRAME_STYLE_BOTTOM) { dc->MoveTo(rect.left,rect.bottom); dc->LineTo(rect.right,rect.bottom); } } else dc->SelectStockObject( NULL_PEN ); dc->SelectStockObject( BLACK_PEN ); dc->SelectStockObject( WHITE_BRUSH ); }
void Border::Render (cairo_t *cr, Region *region, bool path_only) { Brush *background = GetBackground (); Brush *border_brush = GetBorderBrush (); cairo_save (cr); if (!path_only) RenderLayoutClip (cr); CornerRadius r = *GetCornerRadius (); CornerRadius *round = &r; Thickness thickness = *GetBorderThickness (); Rect paint_border = extents; Rect paint_background = paint_border.GrowBy (-thickness); CornerRadius inner_adjusted = *round; inner_adjusted.topLeft = MAX (round->topLeft - MAX (thickness.left, thickness.top) * .5, 0); inner_adjusted.topRight = MAX (round->topRight - MAX (thickness.right, thickness.top) * .5, 0); inner_adjusted.bottomRight = MAX (round->bottomRight - MAX (thickness.right, thickness.bottom) * .5, 0); inner_adjusted.bottomLeft = MAX (round->bottomLeft - MAX (thickness.left, thickness.bottom) * .5, 0); CornerRadius outer_adjusted = *round; outer_adjusted.topLeft = outer_adjusted.topLeft ? MAX (round->topLeft + MAX (thickness.left, thickness.top) * .5, 0) : 0; outer_adjusted.topRight = outer_adjusted.topRight ? MAX (round->topRight + MAX (thickness.right, thickness.top) * .5, 0) : 0; outer_adjusted.bottomRight = outer_adjusted.bottomRight ? MAX (round->bottomRight + MAX (thickness.right, thickness.bottom) * .5, 0) : 0; outer_adjusted.bottomLeft = outer_adjusted.bottomLeft ? MAX (round->bottomLeft + MAX (thickness.left, thickness.bottom) * .5, 0) : 0; /* * NOTE filling this way can leave alpha artifacts between the border fill and bg fill * but some simple inspection of the ms results make me think that is what happens there * too. */ cairo_new_path (cr); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); if (border_brush && !paint_border.IsEmpty ()) { border_brush->SetupBrush (cr, paint_border); paint_border.Draw (cr, &outer_adjusted); paint_background.Draw (cr, &inner_adjusted); if (!path_only) border_brush->Fill (cr); } if (background && !paint_background.IsEmpty ()) { background->SetupBrush (cr, paint_background); paint_background.Draw (cr, &inner_adjusted); if (!path_only) background->Fill (cr); } cairo_restore (cr); }
CString CReportEntityPicture::GetString() const /* ============================================================ Function : CReportEntityPicture::GetString Description : Creates a string representing this object. Access : Public Return : CString - Resulting string Parameters : none Usage : Call to save this object to file. ============================================================*/ { CRect rect = GetRect(); double oldleft = GetLeft(); double oldright = GetRight(); double oldtop = GetTop(); double oldbottom = GetBottom(); double left = CUnitConversion::PixelsToInches( rect.left ); double right = CUnitConversion::PixelsToInches( rect.right ); double top = CUnitConversion::PixelsToInches( rect.top ); double bottom = CUnitConversion::PixelsToInches( rect.bottom ); CReportEntityPicture* const local = const_cast< CReportEntityPicture* const >( this ); local->SetLeft( left ); local->SetRight( right ); local->SetTop( top ); local->SetBottom( bottom ); CString str; CString filename = GetFilename(); MakeSaveString( filename ); double thickness = CUnitConversion::PixelsToInches( GetBorderThickness() ); str.Format( _T( ",%f,%i,%i,%s" ), thickness, GetBorderStyle( ), GetBorderColor( ), filename ); str += _T( ";" ); str = GetDefaultGetString() + str; local->SetLeft( oldleft ); local->SetRight( oldright ); local->SetTop( oldtop ); local->SetBottom( oldbottom ); return str; }
void CReportEntityBox::Serialize(CArchive& ar) { typedef struct { int a_f; int b_f; } BOX_RESERVE_FIELDS; BOX_RESERVE_FIELDS box_reserve; memset(&box_reserve,0,sizeof(BOX_RESERVE_FIELDS)); CDiagramEntity::Serialize(ar); if (ar.IsStoring()) { // —охран¤ем double thickness = CUnitConversion::PixelsToInches( GetBorderThickness() ); ar.Write(&thickness,sizeof(double)); unsigned int bst = GetBorderStyle( ); ar.Write(&bst,sizeof(unsigned int)); unsigned int brC = GetBorderColor( ); ar.Write(&brC,sizeof(unsigned int)); BOOL gf = GetFill(); ar.Write(&gf, sizeof(BOOL)); brC = GetFillColor(); ar.Write(&brC,sizeof(unsigned int)); ar.Write(&box_reserve,sizeof(BOX_RESERVE_FIELDS)); } else { // „итаем double bordhickness; ar.Read(&bordhickness,sizeof(double)); unsigned int bordst; ar.Read(&bordst,sizeof(unsigned int)); unsigned int linecolor; ar.Read(&linecolor,sizeof(unsigned int)); BOOL fil; ar.Read(&fil,sizeof(BOOL)); unsigned int filcolor; ar.Read(&filcolor,sizeof(unsigned int)); ar.Read(&box_reserve,sizeof(BOX_RESERVE_FIELDS)); int bt = CUnitConversion::InchesToPixels( bordhickness ); SetBorderThickness( bt ); SetBorderStyle( bordst ); SetBorderColor( linecolor ); SetFill( fil ); SetFillColor( filcolor ); } }
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 Border::Render (Context *ctx, Region *region) { Brush *background = GetBackground (); Brush *border_brush = GetBorderBrush (); CornerRadius radius = *GetCornerRadius (); Thickness thickness = *GetBorderThickness (); Rect paint_border = extents; Rect paint_background = paint_border.GrowBy (-thickness); double m[16]; int x0, y0; if (!background && !border_brush) return; if (paint_border.IsEmpty ()) return; if (border_brush || radius != CornerRadius ()) { cairo_t *cr = ctx->Push (Context::Cairo ()); Render (cr, region); ctx->Pop (); return; } ctx->GetMatrix (m); if (!HasLayoutClip () && Matrix3D::IsIntegerTranslation (m, &x0, &y0)) { Rect r = Rect (paint_background.x + x0, paint_background.y + y0, paint_background.width, paint_background.height); ctx->Push (Context::Clip (r)); background->Paint (ctx, paint_background); ctx->Pop (); } else { cairo_t *cr = ctx->Push (Context::Cairo ()); Render (cr, region); ctx->Pop (); } }
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; }
void ScrollViewer::OnInitialized() { __super::OnInitialized(); suic::StylePtr hPtr(FindResource(_T("HScrollBar"))); suic::StylePtr vPtr(FindResource(_T("VScrollBar"))); _hScroll->SetStyle(hPtr); _vScroll->SetStyle(vPtr); _hScroll->BeginInit(); _hScroll->EndInit(); _vScroll->BeginInit(); _vScroll->EndInit(); _hScroll->Scroll.Add(this, &ScrollViewer::OnHorizontalScroll); _vScroll->Scroll.Add(this, &ScrollViewer::OnVerticalScroll); _iCurPos = GetBorderThickness().top; }
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 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 CReportEntityLine::Serialize(CArchive& ar) { typedef struct { int a_f; int b_f; } LINE_RESERVE_FIELDS; LINE_RESERVE_FIELDS line_reserve; memset(&line_reserve,0,sizeof(LINE_RESERVE_FIELDS)); CDiagramEntity::Serialize(ar); if (ar.IsStoring()) { // —охран¤ем double thickness = CUnitConversion::PixelsToInches( GetBorderThickness() ); ar.Write(&thickness,sizeof(double)); unsigned int brC = GetBorderColor( ); ar.Write(&brC,sizeof(unsigned int)); ar.Write(&line_reserve,sizeof(LINE_RESERVE_FIELDS)); } else { // „итаем double linethickness; ar.Read(&linethickness,sizeof(double)); unsigned int linecolor; ar.Read(&linecolor,sizeof(unsigned int)); ar.Read(&line_reserve,sizeof(LINE_RESERVE_FIELDS)); unsigned int lt = CUnitConversion::InchesToPixels( linethickness ); SetBorderThickness( lt ); SetBorderColor( linecolor ); } }
void CReportEntityPicture::Draw( CDC* dc, CRect rect ) /* ============================================================ Function : CReportEntityPicture::Draw Description : Draws the object. Access : Public Return : void Parameters : CDC* dc - "CDC" to draw to CRect rect - True (zoomed) rectangle to draw to. Usage : Called from "CDiagramEditor::DrawObjects". ============================================================*/ { if( m_bitmap ) { if (dc->IsPrinting()) { // get size of printer page (in pixels) int cxPage = dc->GetDeviceCaps(HORZRES); int cyPage = dc->GetDeviceCaps(VERTRES); //int dcbpp = pDC->GetDeviceCaps(BITSPIXEL); //int dcnc = pDC->GetDeviceCaps(NUMCOLORS); //int dcp = pDC->GetDeviceCaps(PLANES); // get printer pixels per inch int cxInch = dc->GetDeviceCaps(LOGPIXELSX); int cyInch = dc->GetDeviceCaps(LOGPIXELSY); // Best Fit case: create a rectangle which preserves the aspect ratio int cx=m_bitmap->GetXDPI()?(m_bitmap->GetWidth()*cxInch)/m_bitmap->GetXDPI(): m_bitmap->GetWidth()*cxInch/96; int cy=m_bitmap->GetYDPI()?(m_bitmap->GetHeight()*cyInch)/m_bitmap->GetYDPI(): m_bitmap->GetHeight()*cyInch/96; cx = rect.Width(); cy = rect.Height(); // print it! /*HDC TmpDC=CreateCompatibleDC(pDC->GetSafeHdc()); HBITMAP bm =::CreateCompatibleBitmap(pDC->GetSafeHdc(), cx, cy); HBITMAP oldbm = (HBITMAP)::SelectObject(TmpDC,bm); BitBlt(TmpDC,0,0,cx,cy,0,0,0,WHITENESS); ima->Draw(TmpDC,CRect(0,0,cx,cy)); BitBlt(pDC->GetSafeHdc(),100,100,cx,cy,TmpDC,0,0,SRCCOPY); DeleteObject(SelectObject(TmpDC,oldbm)); DeleteDC(TmpDC);*/ CxImage tmp; tmp.Copy(*m_bitmap); RGBQUAD c={255,255,255,0}; tmp.SetTransColor(c); tmp.AlphaStrip(); tmp.Stretch(dc->GetSafeHdc(), CRect(rect.left,rect.top,rect.left+cx,rect.top+cy)); } else { rect.InflateRect( -1, -1 ); m_bitmap->Draw(dc->m_hDC,rect); //dc->PlayMetaFile() //m_bitmap->GetType() } } CPen pen; if( GetBorderStyle()!=0 ) { const float* table = Drawer::GetColorByIndex(GetBorderColor()); COLORREF clr = RGB((int)(table[0]*255.0f),(int)(table[1]*255.0f),(int)(table[2]*255.0f)); pen.CreatePen( PS_SOLID, GetBorderThickness(), clr ); dc->SelectObject( &pen ); if (GetBorderStyle() & DIAGRAM_FRAME_STYLE_LEFT) { dc->MoveTo(rect.left,rect.bottom); dc->LineTo(rect.left,rect.top); } if (GetBorderStyle() & DIAGRAM_FRAME_STYLE_RIGHT) { dc->MoveTo(rect.right,rect.bottom); dc->LineTo(rect.right,rect.top); } if (GetBorderStyle() & DIAGRAM_FRAME_STYLE_TOP) { dc->MoveTo(rect.left,rect.top); dc->LineTo(rect.right,rect.top); } if (GetBorderStyle() & DIAGRAM_FRAME_STYLE_BOTTOM) { dc->MoveTo(rect.left,rect.bottom); dc->LineTo(rect.right,rect.bottom); } } dc->SelectStockObject( BLACK_PEN ); dc->SelectStockObject( WHITE_BRUSH ); }
void CReportEntityPicture::Serialize(CArchive& ar) { typedef struct { int a_f; int b_f; int c_f; int d_f; } PIC_RESERVE_FIELDS; PIC_RESERVE_FIELDS pic_reserve; memset(&pic_reserve,0,sizeof(PIC_RESERVE_FIELDS)); CDiagramEntity::Serialize(ar); if (ar.IsStoring()) { // —охран¤ем double thickness = CUnitConversion::PixelsToInches( GetBorderThickness() ); ar.Write(&thickness,sizeof(double)); unsigned int bst = GetBorderStyle( ); ar.Write(&bst,sizeof(unsigned int)); unsigned int brC = GetBorderColor( ); ar.Write(&brC,sizeof(unsigned int )); ar.Write(&pic_reserve,sizeof(PIC_RESERVE_FIELDS)); if (m_image_size>0 && m_image_bits) { ar.Write(&m_image_type,sizeof(int)); ar.Write(&m_image_size,sizeof(unsigned int)); ar.Write(m_image_bits,sizeof(BYTE)*m_image_size); } } else { // „итаем double bordhickness; ar.Read(&bordhickness,sizeof(double)); unsigned int bordst; ar.Read(&bordst,sizeof(unsigned int )); unsigned int linecolor; ar.Read(&linecolor,sizeof(unsigned int )); ar.Read(&pic_reserve,sizeof(PIC_RESERVE_FIELDS)); int bt = CUnitConversion::InchesToPixels( bordhickness ); SetBorderThickness( bt ); SetBorderStyle( bordst ); SetBorderColor( linecolor ); if( m_bitmap ) delete m_bitmap; m_bitmap = NULL; m_image_type = -1; m_image_size = 0; if (m_image_bits) delete[] m_image_bits; m_image_bits = NULL; ar.Read(&m_image_type,sizeof(int)); ar.Read(&m_image_size,sizeof(unsigned int)); if (m_image_size==0) return; try { m_image_bits = new BYTE[m_image_size]; } catch (std::bad_alloc) { AfxMessageBox("bad_alloc exception in Serialize function"); ASSERT(0); return; } if (ar.Read(m_image_bits,m_image_size*sizeof(BYTE))!=m_image_size*sizeof(BYTE)) { delete[] m_image_bits; m_image_bits=NULL; m_image_type = -1; m_image_size = 0; ASSERT(0); return; } m_bitmap = new CxImage(m_image_bits, m_image_size, m_image_type); if (!m_bitmap->IsValid()) { AfxMessageBox(m_bitmap->GetLastError()); delete m_bitmap; m_bitmap = NULL; delete[] m_image_bits; m_image_bits=NULL; m_image_type = -1; m_image_size = 0; ASSERT(0); return; } } }