コード例 #1
0
ファイル: imaglist.cpp プロジェクト: pradek/wxWidgets
// Draws the given image on a dc at the specified position.
// If 'solidBackground' is true, Draw sets the image list background
// colour to the background colour of the wxDC, to speed up
// drawing by eliminating masked drawing where possible.
bool wxImageList::Draw(int index,
                       wxDC& dc,
                       int x, int y,
                       int flags,
                       bool solidBackground)
{
    wxDCImpl *impl = dc.GetImpl();
    wxMSWDCImpl *msw_impl = wxDynamicCast( impl, wxMSWDCImpl );
    if (!msw_impl)
       return false;

    HDC hDC = GetHdcOf(*msw_impl);
    wxCHECK_MSG( hDC, false, wxT("invalid wxDC in wxImageList::Draw") );

    COLORREF clr = CLR_NONE;    // transparent by default
    if ( solidBackground )
    {
        const wxBrush& brush = dc.GetBackground();
        if ( brush.IsOk() )
        {
            clr = wxColourToRGB(brush.GetColour());
        }
    }

    ImageList_SetBkColor(GetHImageList(), clr);

    UINT style = 0;
    if ( flags & wxIMAGELIST_DRAW_NORMAL )
        style |= ILD_NORMAL;
    if ( flags & wxIMAGELIST_DRAW_TRANSPARENT )
        style |= ILD_TRANSPARENT;
    if ( flags & wxIMAGELIST_DRAW_SELECTED )
        style |= ILD_SELECTED;
    if ( flags & wxIMAGELIST_DRAW_FOCUSED )
        style |= ILD_FOCUS;

    bool ok = ImageList_Draw(GetHImageList(), index, hDC, x, y, style) != 0;
    if ( !ok )
    {
        wxLogLastError(wxT("ImageList_Draw()"));
    }

    return ok;
}
コード例 #2
0
ファイル: card.cpp プロジェクト: dariusliep/LogViewer
//+-------------------------------------------------------------+
//| Card::Draw()                                                |
//+-------------------------------------------------------------+
//| Description:                                                |
//| Draw the card at (x, y).                                    |
//| If the card is facedown draw the back of the card.          |
//| If the card is faceup draw the front of the card.           |
//| Cards are not held in bitmaps, instead they are drawn       |
//| from their constituent parts when required.                 |
//| hbmap_symbols contains large and small suit symbols and     |
//| pip values. These are copied to the appropriate part of     |
//| the card. Picture cards use the pictures defined in         |
//| hbmap_pictures. Note that only one picture is defined       |
//| for the Jack, Queen and King, unlike a real pack where      |
//| each suit is different.                                     |
//|                                                             |
//| WARNING:                                                    |
//| The locations of these symbols is 'hard-wired' into the     |
//| code. Editing the bitmaps or the numbers below will         |
//| result in the wrong symbols being displayed.                |
//+-------------------------------------------------------------+
void Card::Draw(wxDC& dc, int x, int y)
{
    wxBrush backgroundBrush( dc.GetBackground() );
    dc.SetBrush(* wxWHITE_BRUSH);
    dc.SetPen(* wxBLACK_PEN);
        dc.DrawRoundedRectangle(x, y, m_width, m_height, 4);
    if (m_wayUp == facedown)
    {
        dc.SetBackground(* wxRED_BRUSH);
        dc.SetBackgroundMode(wxSOLID);
        wxBrush* brush = wxTheBrushList->FindOrCreateBrush(
                            *wxBLACK, wxCROSSDIAG_HATCH
                            );
        dc.SetBrush(* brush);

        dc.DrawRoundedRectangle(
                x + 4, y + 4,
                m_width - 8, m_height - 8,
                2
                );
    }
    else
    {
        wxMemoryDC memoryDC;

        memoryDC.SelectObject(*m_symbolBmap);

//        dc.SetBackgroundMode(wxTRANSPARENT);

        dc.SetTextBackground(*wxWHITE);
        switch (m_suit)
        {
            case spades:
            case clubs:
                dc.SetTextForeground(*wxBLACK);
                break;
            case diamonds:
            case hearts:
                dc.SetTextForeground(*wxRED);
                break;
        }

        int symsize = 11;
        int sympos = 14;
        int sympos2 = 25;
        int symdist = 5;
        int symdist2 = 6;

        int pipsize,pippos,valueheight,valuewidth;
        int valuepos;
        if (m_scale > 1.2)
        {
            pipsize = symsize;
            pippos = sympos;
            valueheight = 10;
            valuewidth = 9;
            valuepos = 50;
        }
        else
        {
            pipsize = 7;
            pippos = 0;
            valueheight = 7;
            valuewidth = 6;
            valuepos = 36;
        }

        // Draw the value
        dc.Blit((wxCoord)(x + m_scale*3),
                (wxCoord)(y + m_scale*3),
                valuewidth,
                valueheight,
                &memoryDC,
                valuewidth * (m_pipValue - 1),
                valuepos,
                wxCOPY);
        dc.Blit((wxCoord)(x + m_width - m_scale*3 - valuewidth),
                (wxCoord)(y + m_height - valueheight - m_scale*3),
                valuewidth,
                valueheight,
                &memoryDC,
                valuewidth * (m_pipValue - 1),
                valuepos+valueheight,
                wxCOPY);

        // Draw the pips
        dc.Blit((wxCoord)(x + m_scale*3 + valuewidth+2),
                (wxCoord)(y + m_scale*3),
                pipsize,
                pipsize,
                &memoryDC,
                pipsize * m_suit,
                pippos,
                wxCOPY);
        dc.Blit((wxCoord)(x + m_width - m_scale*3-valuewidth-pipsize-2),
                (wxCoord)(y + m_height - pipsize - m_scale*3),
                pipsize,
                pipsize,
                &memoryDC,
                pipsize * m_suit,
                pipsize+pippos,
                wxCOPY);

        switch (m_pipValue)
        {
        case 1:
            dc.Blit((wxCoord)(x - symdist + m_width / 2),
                    (wxCoord)(y - m_scale*5 + m_height / 2),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            break;

        case 3:
            dc.Blit((wxCoord)(x - symdist + m_width / 2),
                    (wxCoord)(y - symdist + m_height / 2),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
        case 2:
            dc.Blit((wxCoord)(x - symdist + m_width / 2),
                    (wxCoord)(y - symdist + m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + m_width / 2),
                    (wxCoord)(y - symdist + 3 * m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
            break;

        case 5:
            dc.Blit((wxCoord)(x - symdist + m_width / 2),
                    (wxCoord)(y - symdist + m_height / 2),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
        case 4:
            dc.Blit((wxCoord)(x - symdist +  m_width / 4),
                    (wxCoord)(y - symdist + m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + m_width / 4),
                    (wxCoord)(y - symdist + 3 * m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
                    (wxCoord)(y - symdist + m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
                    (wxCoord)(y - symdist + 3 * m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
            break;

        case 8:
            dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10),
                    (wxCoord)(y - symdist + 5 * m_height / 8),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
        case 7:
            dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10),
                    (wxCoord)(y - symdist + 3 * m_height / 8),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
        case 6:
            dc.Blit((wxCoord)(x - symdist + m_width / 4),
                    (wxCoord)(y - symdist + m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC, symsize * m_suit, sympos, wxCOPY);
            dc.Blit((wxCoord)(x - symdist + m_width / 4),
                    (wxCoord)(y - symdist + m_height / 2),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + m_width / 4),
                    (wxCoord)(y - symdist + 3 * m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
                    (wxCoord)(y - symdist + m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
                    (wxCoord)(y - symdist + m_height / 2),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
                    (wxCoord)(y - symdist + 3 * m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
            break;

        case 10:
            dc.Blit((wxCoord)(x - symdist + m_width / 2),
                    (wxCoord)(y - symdist + 2 * m_height / 3),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
        case 9:
            dc.Blit((wxCoord)(x - symdist + m_width / 4),
                    (wxCoord)(y - symdist2 + m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + m_width / 4),
                    (wxCoord)(y - symdist2 + 5 * m_height / 12),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + m_width / 4),
                    (wxCoord)(y - symdist + 7 * m_height / 12),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + m_width / 4),
                    (wxCoord)(y - symdist + 3 * m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);

            dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
                    (wxCoord)(y - symdist2 + m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
                    (wxCoord)(y - symdist2 + 5 * m_height / 12),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
                    (wxCoord)(y - symdist + 7 * m_height / 12),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
                    (wxCoord)(y - symdist + 3 * m_height / 4),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
            dc.Blit((wxCoord)(x - symdist + m_width / 2),
                    (wxCoord)(y - symdist + m_height / 3),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            break;
        case 11:
        case 12:
        case 13:
            memoryDC.SelectObject(*m_pictureBmap);
            int picwidth = 40,picheight = 45;
            dc.Blit((wxCoord)(x + (m_width-picwidth)/2),
                    (wxCoord)(y - picheight/2 + m_height/2),
                    picwidth,
                    picheight,
                    &memoryDC,
                    picwidth * (m_pipValue - 11),
                    0,
                    wxCOPY);

            memoryDC.SelectObject(*m_symbolBmap);
            dc.Blit((wxCoord)(x + m_width-(m_width-picwidth)/2-symsize-3),
                    (wxCoord)(y - picheight/2+m_height/2+1),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos,
                    wxCOPY);
            dc.Blit((wxCoord)(x + (m_width-picwidth)/2+2),
                    (wxCoord)(y + picheight/2 + m_height/2-symsize),
                    symsize,
                    symsize,
                    &memoryDC,
                    symsize * m_suit,
                    sympos2,
                    wxCOPY);
            break;
        }

    }
    dc.SetBackground( backgroundBrush );
} // Card:Draw()
コード例 #3
0
ファイル: htmlcell.cpp プロジェクト: gitrider/wxsj2
void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
                          int WXUNUSED(view_y1), int WXUNUSED(view_y2),
                          wxHtmlRenderingInfo& info)
{
#if 0 // useful for debugging
    dc.SetPen(*wxBLACK_PEN);
    dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width /* VZ: +1? */ ,m_Height);
#endif

    bool drawSelectionAfterCell = false;

    if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING )
    {
        // Selection changing, we must draw the word piecewise:
        wxHtmlSelection *s = info.GetSelection();
        wxString txt;
        int w, h;
        int ofs = 0;

        wxPoint priv = (this == s->GetFromCell()) ?
                       s->GetFromPrivPos() : s->GetToPrivPos();

        // NB: this is quite a hack: in order to compute selection boundaries
        //     (in word's characters) we must know current font, which is only
        //     possible inside rendering code. Therefore we update the
        //     information here and store it in wxHtmlSelection so that
        //     ConvertToText can use it later:
        if ( priv == wxDefaultPosition )
        {
            SetSelectionPrivPos(dc, s);
            priv = (this == s->GetFromCell()) ?
                   s->GetFromPrivPos() : s->GetToPrivPos();
        }

        int part1 = priv.x;
        int part2 = priv.y;

        if ( part1 > 0 )
        {
            txt = m_Word.Mid(0, part1);
            dc.DrawText(txt, x + m_PosX, y + m_PosY);
            dc.GetTextExtent(txt, &w, &h);
            ofs += w;
        }

        SwitchSelState(dc, info, true);

        txt = m_Word.Mid(part1, part2-part1);
        dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY);

        if ( (size_t)part2 < m_Word.length() )
        {
            dc.GetTextExtent(txt, &w, &h);
            ofs += w;
            SwitchSelState(dc, info, false);
            txt = m_Word.Mid(part2);
            dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY);
        }
        else
            drawSelectionAfterCell = true;
    }
    else
    {
        wxHtmlSelectionState selstate = info.GetState().GetSelectionState();
        // Not changing selection state, draw the word in single mode:
        if ( selstate != wxHTML_SEL_OUT &&
                dc.GetBackgroundMode() != wxSOLID )
        {
            SwitchSelState(dc, info, true);
        }
        else if ( selstate == wxHTML_SEL_OUT &&
                  dc.GetBackgroundMode() == wxSOLID )
        {
            SwitchSelState(dc, info, false);
        }
        dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
        drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT);
    }

    // NB: If the text is justified then there is usually some free space
    //     between adjacent cells and drawing the selection only onto cells
    //     would result in ugly unselected spaces. The code below detects
    //     this special case and renders the selection *outside* the sell,
    //     too.
    if ( m_Parent->GetAlignHor() == wxHTML_ALIGN_JUSTIFY &&
            drawSelectionAfterCell )
    {
        wxHtmlCell *nextCell = m_Next;
        while ( nextCell && nextCell->IsFormattingCell() )
            nextCell = nextCell->GetNext();
        if ( nextCell )
        {
            int nextX = nextCell->GetPosX();
            if ( m_PosX + m_Width < nextX )
            {
                dc.SetBrush(dc.GetBackground());
                dc.SetPen(*wxTRANSPARENT_PEN);
                dc.DrawRectangle(x + m_PosX + m_Width, y + m_PosY,
                                 nextX - m_PosX - m_Width, m_Height);
            }
        }
    }
}