コード例 #1
0
ファイル: camview.cpp プロジェクト: adams-n-d/panya
////////////////////////////////////////////////////////////////////
// Method:	Draw
// Class:	CCamView
// Purose:	camera drawing
// Input:	reference to dc
// Output:	nothing
////////////////////////////////////////////////////////////////////
void CCamView::Draw( wxDC& dc )
{
	// check if dc available
	if( !dc.Ok( ) || m_bDrawing == true ){ return; }

		m_bDrawing = true;

		dc.BeginDrawing();

		int x,y,w,h;
		dc.GetClippingBox( &x, &y, &w, &h );
		// if there is a new image to draw
		if( m_bNewImage )
		{
			dc.DrawBitmap( m_pBitmap, x, y );
			m_bNewImage = false;
		} else
		{
			// draw inter frame ?
		}

		dc.EndDrawing();
		m_bDrawing = false;

	return;
}
コード例 #2
0
ファイル: art_aui.cpp プロジェクト: AaronDP/wxWidgets
void wxRibbonAUIArtProvider::DrawTab(wxDC& dc,
                 wxWindow* WXUNUSED(wnd),
                 const wxRibbonPageTabInfo& tab)
{
    if(tab.rect.height <= 1)
        return;

    dc.SetFont(m_tab_label_font);
    dc.SetPen(*wxTRANSPARENT_PEN);
    if(tab.active || tab.hovered || tab.highlight)
    {
        if(tab.active)
        {
            dc.SetFont(m_tab_active_label_font);
            dc.SetBrush(m_background_brush);
            dc.DrawRectangle(tab.rect.x, tab.rect.y + tab.rect.height - 1,
                tab.rect.width - 1, 1);
        }
        wxRect grad_rect(tab.rect);
        grad_rect.height -= 4;
        grad_rect.width -= 1;
        grad_rect.height /= 2;
        grad_rect.y = grad_rect.y + tab.rect.height - grad_rect.height - 1;
        dc.SetBrush(m_tab_active_top_background_brush);
        dc.DrawRectangle(tab.rect.x, tab.rect.y + 3, tab.rect.width - 1,
            grad_rect.y - tab.rect.y - 3);
        if(tab.highlight)
        {
            dc.GradientFillLinear(grad_rect, m_tab_highlight_top_colour, m_tab_highlight_top_gradient_colour, wxSOUTH);
        }
        else
        {
            dc.GradientFillLinear(grad_rect, m_tab_active_background_colour,
                m_tab_active_background_gradient_colour, wxSOUTH);
        }
    }
    else
    {
        wxRect btm_rect(tab.rect);
        btm_rect.height -= 4;
        btm_rect.width -= 1;
        btm_rect.height /= 2;
        btm_rect.y = btm_rect.y + tab.rect.height - btm_rect.height - 1;
        dc.SetBrush(m_tab_hover_background_brush);
        dc.DrawRectangle(btm_rect.x, btm_rect.y, btm_rect.width,
            btm_rect.height);
        wxRect grad_rect(tab.rect);
        grad_rect.width -= 1;
        grad_rect.y += 3;
        grad_rect.height = btm_rect.y - grad_rect.y;
        dc.GradientFillLinear(grad_rect, m_tab_hover_background_top_colour,
            m_tab_hover_background_top_gradient_colour, wxSOUTH);
    }

    wxPoint border_points[5];
    border_points[0] = wxPoint(0, 3);
    border_points[1] = wxPoint(1, 2);
    border_points[2] = wxPoint(tab.rect.width - 3, 2);
    border_points[3] = wxPoint(tab.rect.width - 1, 4);
    border_points[4] = wxPoint(tab.rect.width - 1, tab.rect.height - 1);

    dc.SetPen(m_tab_border_pen);
    dc.DrawLines(sizeof(border_points)/sizeof(wxPoint), border_points, tab.rect.x, tab.rect.y);

    wxRect old_clip;
    dc.GetClippingBox(old_clip);
    bool is_first_tab = false;
    wxRibbonBar* bar = wxDynamicCast(tab.page->GetParent(), wxRibbonBar);
    if(bar && bar->GetPage(0) == tab.page)
        is_first_tab = true;

    wxBitmap icon;
    if(m_flags & wxRIBBON_BAR_SHOW_PAGE_ICONS)
    {
        icon = tab.page->GetIcon();
        if((m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS) == 0)
        {
            if(icon.IsOk())
            {
            int x = tab.rect.x + (tab.rect.width - icon.GetWidth()) / 2;
            dc.DrawBitmap(icon, x, tab.rect.y + 1 + (tab.rect.height - 1 -
                icon.GetHeight()) / 2, true);
            }
        }
    }
    if(m_flags & wxRIBBON_BAR_SHOW_PAGE_LABELS)
    {
        wxString label = tab.page->GetLabel();
        if(!label.IsEmpty())
        {
            dc.SetTextForeground(m_tab_label_colour);
            dc.SetBackgroundMode(wxTRANSPARENT);

            int offset = 0;
            if(icon.IsOk())
                offset += icon.GetWidth() + 2;
            int text_height;
            int text_width;
            dc.GetTextExtent(label, &text_width, &text_height);
            int x = (tab.rect.width - 2 - text_width - offset) / 2;
            if(x > 8)
                x = 8;
            else if(x < 1)
                x = 1;
            int width = tab.rect.width - x - 2;
            x += tab.rect.x + offset;
            int y = tab.rect.y + (tab.rect.height - text_height) / 2;
            if(icon.IsOk())
            {
                dc.DrawBitmap(icon, x - offset, tab.rect.y + (tab.rect.height -
                    icon.GetHeight()) / 2, true);
            }
            dc.SetClippingRegion(x, tab.rect.y, width, tab.rect.height);
            dc.DrawText(label, x, y);
        }
    }

    // Draw the left hand edge of the tab only for the first tab (subsequent
    // tabs use the right edge of the prior tab as their left edge). As this is
    // outside the rectangle for the tab, only draw it if the leftmost part of
    // the tab is within the clip rectangle (the clip region has to be cleared
    // to draw outside the tab).
    if(is_first_tab && old_clip.x <= tab.rect.x
        && tab.rect.x < old_clip.x + old_clip.width)
    {
        dc.DestroyClippingRegion();
        dc.DrawLine(tab.rect.x - 1, tab.rect.y + 4, tab.rect.x - 1,
            tab.rect.y + tab.rect.height - 1);
    }
}
コード例 #3
0
ファイル: clippingbox.cpp プロジェクト: CodeTickler/wxWidgets
void ClippingBoxTestCaseBase::CheckBox(int x, int y, int width, int height)
{
    // Check clipping box boundaries.
    int clipX, clipY, clipW, clipH;
    m_dc->GetClippingBox(&clipX, &clipY, &clipW, &clipH);

    wxString msgPos;
    if ( x != clipX || y != clipY )
    {
        msgPos =
            wxString::Format(wxS("Invalid position: Actual: (%i, %i)  Expected: (%i, %i)"),
                                clipX, clipY, x, y);
    }
    wxString msgDim;
    if ( width != clipW || height != clipH )
    {
        msgDim =
            wxString::Format(wxS("Invalid dimension: Actual: %i x %i  Expected: %i x %i"),
                                clipW, clipH, width, height);
    }

    wxString msg;
    if ( !msgPos.empty() )
    {
        msg = msgPos;
        if ( !msgDim.empty() )
        {
            msg += wxS("\n- ");
            msg += msgDim;
        }
    }
    else if ( !msgDim.empty() )
    {
        msg = msgDim;
    }

    // We will examine pixels directly in the underlying bitmap
    // so we need to get device coordinates of examined area.
    x = m_dc->LogicalToDeviceX(x);
    y = m_dc->LogicalToDeviceY(y);
    width = m_dc->LogicalToDeviceXRel(width);
    height = m_dc->LogicalToDeviceYRel(height);

    // Update wxDC contents.
    FlushDC();

    // Check whether diagonal corners of the clipping box
    // are actually drawn at the edge of the clipping region.
#if wxUSE_IMAGE
    // For some renderers it's not possible to get pixels
    // value from wxDC so we would have to examine pixels
    // in the underlying bitmap.
    wxImage img;
    img = m_bmp.ConvertToImage();
#else
    return;
#endif // wxUSE_IMAGE

    // Check area near the top-left corner
    int ymin = y-1;
    int xmin = x-1;
    int ymax = y+1;
    int xmax = x+1;
    ymin = wxMin(wxMax(ymin, 0), s_dcSize.GetHeight()-1);
    xmin = wxMin(wxMax(xmin, 0), s_dcSize.GetWidth()-1);
    ymax = wxMin(wxMax(ymax, 0), s_dcSize.GetHeight()-1);
    xmax = wxMin(wxMax(xmax, 0), s_dcSize.GetWidth()-1);

    for( int py = ymin; py <= ymax; py++ )
        for( int px = xmin; px <= xmax; px++ )
        {
            wxColour c;
#if wxUSE_IMAGE
            unsigned char r = img.GetRed(px, py);
            unsigned char g = img.GetGreen(px, py);
            unsigned char b = img.GetBlue(px, py);
            c.Set(r, g, b);
#else
            // We cannot get pixel value
            break;
#endif // wxUSE_IMAGE / !wxUSE_IMAGE

            wxString msgColour;
            if ( px >= x && px <= x + (width-1) &&
                 py >= y && py <= y + (height-1) )
            {
                // Pixel inside the box.
                if ( c != s_fgColour )
                {
                    msgColour =
                        wxString::Format(wxS("Invalid colour drawn at (%i, %i): Actual: %s  Expected: %s"),
                                px, py, c.GetAsString().mbc_str(), s_fgColour.GetAsString().mbc_str());

                }
            }
            else
            {
                // Pixel outside the box.
                if ( c != s_bgColour )
                {
                    msgColour =
                        wxString::Format(wxS("Invalid colour drawn at (%i, %i): Actual: %s  Expected: %s"),
                                px, py, c.GetAsString().mbc_str(), s_bgColour.GetAsString().mbc_str());
                }
            }

            if ( !msgColour.empty() )
            {
                if ( !msg.empty() )
                {
                    msg += wxS("\n- ");
                    msg += msgColour;
                }
                else
                {
                    msg = msgColour;
                }
            }
        }

    // Check area near the bottom-right corner
    ymin = y+(height-1)-1;
    xmin = x+(width-1)-1;
    ymax = y+(height-1)+1;
    xmax = x+(width-1)+1;
    ymin = wxMin(wxMax(ymin, 0), s_dcSize.GetHeight()-1);
    xmin = wxMin(wxMax(xmin, 0), s_dcSize.GetWidth()-1);
    ymax = wxMin(wxMax(ymax, 0), s_dcSize.GetHeight()-1);
    xmax = wxMin(wxMax(ymax, 0), s_dcSize.GetWidth()-1);
    for( int py = ymin; py <= ymax; py++ )
        for( int px = xmin; px <= xmax; px++ )
        {
            wxColour c;
#if wxUSE_IMAGE
            unsigned char r = img.GetRed(px, py);
            unsigned char g = img.GetGreen(px, py);
            unsigned char b = img.GetBlue(px, py);
            c.Set(r, g, b);
#else
            // We cannot get pixel value
            break;
#endif // wxUSE_IMAGE / !wxUSE_IMAGE

            wxString msgColour;
            if ( px >= x && px <= x + (width-1) &&
                 py >= y && py <= y + (height-1) )
            {
                // Pixel inside the box.
                if ( c != s_fgColour )
                {
                    msgColour =
                        wxString::Format(wxS("Invalid colour drawn at (%i, %i): Actual: %s  Expected: %s"),
                                px, py, c.GetAsString().mbc_str(), s_fgColour.GetAsString().mbc_str());
                }
            }
            else
            {
                // Pixel outside the box.
                if ( c != s_bgColour )
                {
                    msgColour =
                        wxString::Format(wxS("Invalid colour drawn at (%i, %i): Actual: %s  Expected: %s"),
                                px, py, c.GetAsString().mbc_str(), s_bgColour.GetAsString().mbc_str());
                }
            }

            if ( !msgColour.empty() )
            {
                if ( !msg.empty() )
                {
                    msg += wxS("\n- ");
                    msg += msgColour;
                }
                else
                {
                    msg = msgColour;
                }
            }
        }

    if( !msg.empty() )
    {
        wxCharBuffer buffer = msg.ToUTF8();
        CPPUNIT_FAIL( buffer.data() );
    }
}