Ejemplo n.º 1
0
		void draw_text(const Rect* r, const char* str)
		{
			Gdiplus::SolidBrush* brush = new Gdiplus::SolidBrush(*color);
			if(brush == NULL) return;

			st count = cl::StringUtil::char_to_wchar_count(str);
			wchar* wstr = cl_alloc_type_with_count(wchar, count);
			if(wstr == NULL) { delete brush;  return; }
			cl::StringUtil::char_to_wchar(wstr, count, str);

			Gdiplus::Region old_val;
			graphics->GetClip(&old_val);

			Gdiplus::Region new_val(TO_RECT(r));
			graphics->SetClip(&new_val);

			graphics->DrawString(wstr, -1, font, TO_POINTF(((Point*)r)), brush);
			graphics->SetClip(&old_val);
			cl_free(wstr);
			delete brush;
		}
Ejemplo n.º 2
0
void Sprite::OnDraw( Gdiplus::Graphics &g, const Gdiplus::RectF &rcDirty )
{
	if (!m_bVisible)
	{
		return; // 子节点也不会被绘制
	}
	// 前序遍历 让父节点先绘制
	//Gdiplus::RectF rc = GetRect();
	//if (10 == rc.Width && 10 == rc.Height)
	//{
	//	LOGW(<<L"Orignal Size 10 10"); // 检查下有没有多余的重绘
	//}
	if (m_bClipChildren)
	{
		Gdiplus::RectF rcClip = GetRect();
		rcClip.X = 0.0f;
		rcClip.Y = 0.0f;
		g.SetClip(rcClip);
	}
    PaintEvent ev;
    ev.graphics = &g;
    ev.rcDirty = rcDirty;
    SendNotify(ePaint, &ev);
    //this->ClientDraw(g, rcDirty);
	Sprite *sp = m_firstChild;
	while(sp)
	{
		// 如果需要重绘部分矩形和sp相交则重画它 否则不重画
		// 这里还有个问题就是 父矩形必须比子矩形要大 否则可能父的相交不到 而子的相交的到
		// 可能要强制这一原理 类似于浏览器 会撑大
		Gdiplus::RectF rc2 = sp->GetRect();
		Gdiplus::RectF rcAbs = sp->GetAbsRect();
		rcAbs.X -= 0.5f; // FIXME 有时无法得到重画导致边界1像素消失
		rcAbs.Y -= 0.5f;
		rcAbs.Width += 1.0f;
		rcAbs.Height += 1.0f;
		if (rcDirty.IntersectsWith(rcAbs))
		{
			g.TranslateTransform(rc2.X, rc2.Y);
			sp->OnDraw(g, rcDirty);
			g.TranslateTransform(-rc2.X, -rc2.Y);
		}
		sp = sp->m_nextSibling;
	}
	if (m_bClipChildren)
	{
		g.ResetClip();
	}
}
Ejemplo n.º 3
0
void GraphicsContext::clipPath(const Path& path, WindRule clipRule)
{
    if (paintingDisabled())
        return;

    // FIXME: Why does this method ignore empty paths?
    if (path.isEmpty())
        return; 

    wxGraphicsContext* gc = m_data->context->GetGraphicsContext();

#if wxUSE_CAIRO
    cairo_t* cr = (cairo_t*)gc->GetNativeContext();
    cairo_path_t* nativePath = (cairo_path_t*)path.platformPath()->GetNativePath();

    cairo_new_path(cr);
    cairo_append_path(cr, nativePath);

    cairo_set_fill_rule(cr, clipRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
    cairo_clip(cr);
#elif __WXMAC__
    CGContextRef context = (CGContextRef)gc->GetNativeContext();   
    CGPathRef nativePath = (CGPathRef)path.platformPath()->GetNativePath(); 
    
    CGContextBeginPath(context);
    CGContextAddPath(context, nativePath);
    if (clipRule == RULE_EVENODD)
        CGContextEOClip(context);
    else
        CGContextClip(context);
#elif __WXMSW__
    Gdiplus::Graphics* g = (Gdiplus::Graphics*)gc->GetNativeContext();
    Gdiplus::GraphicsPath* nativePath = (Gdiplus::GraphicsPath*)path.platformPath()->GetNativePath();
    if (clipRule == RULE_EVENODD)
        nativePath->SetFillMode(Gdiplus::FillModeAlternate);
    else
        nativePath->SetFillMode(Gdiplus::FillModeWinding);
    g->SetClip(nativePath);
#endif
}
Ejemplo n.º 4
0
 bool CanvasGdiplus::ClipRectInt(int x, int y, int w, int h)
 {
     Gdiplus::Graphics* current = GetCurrentGraphics();
     return current->SetClip(Gdiplus::Rect(x, y, w, h),
         Gdiplus::CombineModeIntersect) == Gdiplus::Ok;
 }
Ejemplo n.º 5
0
void Graphics::SetClip(const RectF& rc) {
    Gdiplus::Graphics* g = reinterpret_cast<Gdiplus::Graphics*>(_private);
    g->SetClip(ToGDIRect<RectF, Gdiplus::RectF>(rc));
}