⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win32.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    for ( size_t n = 0; n < Arrow_Max; n++ )    {        bool isVertical = n > Arrow_Right;        int w, h;        if ( isVertical )        {            w = ARROW_WIDTH;            h = ARROW_LENGTH;        }        else        {            h = ARROW_WIDTH;            w = ARROW_LENGTH;        }        // disabled arrow is larger because of the shadow        m_bmpArrows[Arrow_Normal][n].Create(w, h);        m_bmpArrows[Arrow_Disabled][n].Create(w + 1, h + 1);        dcNormal.SelectObject(m_bmpArrows[Arrow_Normal][n]);        dcDisabled.SelectObject(m_bmpArrows[Arrow_Disabled][n]);        dcNormal.SetBackground(*wxWHITE_BRUSH);        dcDisabled.SetBackground(*wxWHITE_BRUSH);        dcNormal.Clear();        dcDisabled.Clear();        dcNormal.SetPen(m_penBlack);        dcDisabled.SetPen(m_penDarkGrey);        // calculate the position of the point of the arrow        wxCoord x1, y1;        if ( isVertical )        {            x1 = (ARROW_WIDTH - 1)/2;            y1 = n == Arrow_Up ? 0 : ARROW_LENGTH - 1;        }        else // horizontal        {            x1 = n == Arrow_Left ? 0 : ARROW_LENGTH - 1;            y1 = (ARROW_WIDTH - 1)/2;        }        wxCoord x2 = x1,                y2 = y1;        if ( isVertical )            x2++;        else            y2++;        for ( size_t i = 0; i < ARROW_LENGTH; i++ )        {            dcNormal.DrawLine(x1, y1, x2, y2);            dcDisabled.DrawLine(x1, y1, x2, y2);            if ( isVertical )            {                x1--;                x2++;                if ( n == Arrow_Up )                {                    y1++;                    y2++;                }                else // down arrow                {                    y1--;                    y2--;                }            }            else // left or right arrow            {                y1--;                y2++;                if ( n == Arrow_Left )                {                    x1++;                    x2++;                }                else                {                    x1--;                    x2--;                }            }        }        // draw the shadow for the disabled one        dcDisabled.SetPen(m_penHighlight);        switch ( n )        {            case Arrow_Left:                y1 += 2;                dcDisabled.DrawLine(x1, y1, x2, y2);                break;            case Arrow_Right:                x1 = ARROW_LENGTH - 1;                y1 = (ARROW_WIDTH - 1)/2 + 1;                x2 = 0;                y2 = ARROW_WIDTH;                dcDisabled.DrawLine(x1, y1, x2, y2);                dcDisabled.DrawLine(++x1, y1, x2, ++y2);                break;            case Arrow_Up:                x1 += 2;                dcDisabled.DrawLine(x1, y1, x2, y2);                break;            case Arrow_Down:                x1 = ARROW_WIDTH - 1;                y1 = 1;                x2 = (ARROW_WIDTH - 1)/2;                y2 = ARROW_LENGTH;                dcDisabled.DrawLine(x1, y1, x2, y2);                dcDisabled.DrawLine(++x1, y1, x2, ++y2);                break;        }        // create the inverted bitmap but only for the right arrow as we only        // use it for the menus        if ( n == Arrow_Right )        {            m_bmpArrows[Arrow_Inverted][n].Create(w, h);            dcInverse.SelectObject(m_bmpArrows[Arrow_Inverted][n]);            dcInverse.Clear();            dcInverse.Blit(0, 0, w, h,                          &dcNormal, 0, 0,                          wxXOR);            dcInverse.SelectObject(wxNullBitmap);            mask = new wxMask(m_bmpArrows[Arrow_Inverted][n], *wxBLACK);            m_bmpArrows[Arrow_Inverted][n].SetMask(mask);            m_bmpArrows[Arrow_InvertedDisabled][n].Create(w, h);            dcInverse.SelectObject(m_bmpArrows[Arrow_InvertedDisabled][n]);            dcInverse.Clear();            dcInverse.Blit(0, 0, w, h,                          &dcDisabled, 0, 0,                          wxXOR);            dcInverse.SelectObject(wxNullBitmap);            mask = new wxMask(m_bmpArrows[Arrow_InvertedDisabled][n], *wxBLACK);            m_bmpArrows[Arrow_InvertedDisabled][n].SetMask(mask);        }        dcNormal.SelectObject(wxNullBitmap);        dcDisabled.SelectObject(wxNullBitmap);        mask = new wxMask(m_bmpArrows[Arrow_Normal][n], *wxWHITE);        m_bmpArrows[Arrow_Normal][n].SetMask(mask);        mask = new wxMask(m_bmpArrows[Arrow_Disabled][n], *wxWHITE);        m_bmpArrows[Arrow_Disabled][n].SetMask(mask);        m_bmpArrows[Arrow_Pressed][n] = m_bmpArrows[Arrow_Normal][n];    }}bool wxWin32Renderer::AreScrollbarsInsideBorder() const{    return true;}// ----------------------------------------------------------------------------// label// ----------------------------------------------------------------------------void wxWin32Renderer::DrawLabel(wxDC& dc,                                const wxString& label,                                const wxRect& rect,                                int flags,                                int alignment,                                int indexAccel,                                wxRect *rectBounds){    // the underscores are not drawn for focused controls in wxMSW    if ( flags & wxCONTROL_FOCUSED )    {        indexAccel = -1;    }    if ( flags & wxCONTROL_DISABLED )    {        // the combination of wxCONTROL_SELECTED and wxCONTROL_DISABLED        // currently only can happen for a menu item and it seems that Windows        // doesn't draw the shadow in this case, so we don't do it neither        if ( flags & wxCONTROL_SELECTED )        {            // just make the label text greyed out            dc.SetTextForeground(m_penDarkGrey.GetColour());            flags &= ~wxCONTROL_DISABLED;        }    }    wxStdRenderer::DrawLabel(dc, label, rect, flags, alignment,                             indexAccel, rectBounds);}void wxWin32Renderer::DrawFrameWithLabel(wxDC& dc,                                         const wxString& label,                                         const wxRect& rectFrame,                                         const wxRect& rectText,                                         int flags,                                         int alignment,                                         int indexAccel){    wxString label2;    label2 << _T(' ') << label << _T(' ');    if ( indexAccel != -1 )    {        // adjust it as we prepended a space        indexAccel++;    }    wxStdRenderer::DrawFrameWithLabel(dc, label2, rectFrame, rectText,                                      flags, alignment, indexAccel);}void wxWin32Renderer::DrawButtonLabel(wxDC& dc,                                      const wxString& label,                                      const wxBitmap& image,                                      const wxRect& rect,                                      int flags,                                      int alignment,                                      int indexAccel,                                      wxRect *rectBounds){    // the underscores are not drawn for focused controls in wxMSW    if ( flags & wxCONTROL_PRESSED )    {        indexAccel = -1;    }    wxStdRenderer::DrawButtonLabel(dc, label, image, rect, flags, alignment,                                   indexAccel, rectBounds);}void wxWin32Renderer::DrawButtonBorder(wxDC& dc,                                       const wxRect& rectTotal,                                       int flags,                                       wxRect *rectIn){    wxRect rect = rectTotal;    wxPen penOut(*wxBLACK);    if ( flags & wxCONTROL_PRESSED )    {        // button pressed: draw a double border around it        DrawRect(dc, &rect, penOut);        DrawRect(dc, &rect, m_penDarkGrey);    }    else // button not pressed    {        if ( flags & (wxCONTROL_FOCUSED | wxCONTROL_ISDEFAULT) )        {            // button either default or focused (or both): add an extra border            // around it            DrawRect(dc, &rect, penOut);        }        // now draw a normal button border        DrawRaisedBorder(dc, &rect);    }    if ( rectIn )        *rectIn = rect;}// ----------------------------------------------------------------------------// (check)listbox items// ----------------------------------------------------------------------------void wxWin32Renderer::DrawCheckItemBitmap(wxDC& dc,                                          const wxBitmap& bitmap,                                          const wxRect& rect,                                          int flags){    wxBitmap bmp;    if ( bitmap.Ok() )    {        bmp = bitmap;    }    else // use default bitmap    {        IndicatorStatus i = flags & wxCONTROL_CHECKED                                ? IndicatorStatus_Checked                                : IndicatorStatus_Unchecked;        if ( !m_bmpCheckBitmaps[i].Ok() )        {            m_bmpCheckBitmaps[i] = wxBitmap(ms_xpmChecked[i]);        }        bmp = m_bmpCheckBitmaps[i];    }    dc.DrawBitmap(bmp, rect.x, rect.y + (rect.height - bmp.GetHeight()) / 2 - 1,                  true /* use mask */);}// ----------------------------------------------------------------------------// check/radio buttons// ----------------------------------------------------------------------------wxBitmap wxWin32Renderer::GetIndicator(IndicatorType indType, int flags){    IndicatorState indState;    IndicatorStatus indStatus;    GetIndicatorsFromFlags(flags, indState, indStatus);    wxBitmap& bmp = m_bmpIndicators[indType][indState][indStatus];    if ( !bmp.Ok() )    {        const char **xpm = ms_xpmIndicators[indType][indState][indStatus];        if ( xpm )        {            // create and cache it            bmp = wxBitmap(xpm);        }    }    return bmp;}// ----------------------------------------------------------------------------// toolbar stuff// ----------------------------------------------------------------------------#if wxUSE_TOOLBARvoid wxWin32Renderer::DrawToolBarButton(wxDC& dc,                                        const wxString& label,                                        const wxBitmap& bitmap,                                        const wxRect& rectOrig,                                        int flags,                                        long style,                                        int tbarStyle){    if (style == wxTOOL_STYLE_BUTTON)    {        wxRect rect = rectOrig;        rect.Deflate(BORDER_THICKNESS);        if ( flags & wxCONTROL_PRESSED )        {            DrawBorder(dc, wxBORDER_SUNKEN, rect, flags);        }        else if ( flags & wxCONTROL_CURRENT )        {            DrawBorder(dc, wxBORDER_RAISED, rect, flags);        }        if(tbarStyle & wxTB_TEXT)        {            if(tbarStyle & wxTB_HORIZONTAL)            {                dc.DrawLabel(label, bitmap, rect, wxALIGN_CENTRE);            }            else            {                dc.DrawLabel(label, bitmap, rect, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);            }        }        else        {            int xpoint = (rect.GetLeft() + rect.GetRight() + 1 - bitmap.GetWidth()) / 2;            int ypoint = (rect.GetTop() + rect.GetBottom() + 1 - bitmap.GetHeight()) / 2;            dc.DrawBitmap(bitmap, xpoint, ypoint, bitmap.GetMask() != NULL);        }    }    else if (style == wxTOOL_STYLE_SEPARATOR)    {        // leave a small gap aroudn the line, also account for the toolbar        // border itself        if(rectOrig.height > rectOrig.width)        {            // horizontal            DrawVerticalLine(dc, rectOrig.x + rectOrig.width/2,                             rectOrig.y + 2*BORDER_THICKNESS,                             rectOrig.GetBottom() - BORDER_THICKNESS);        }        else        {            // vertical            DrawHorizontalLine(dc, rectOrig.y + rectOrig.height/2,                         rectOrig.x + 2*BORDER_THICKNESS,                         rectOrig.GetRight() - BORDER_THICKNESS);        }    }    // don't draw wxTOOL_STYLE_CONTROL}#endif // wxUSE_TOOLBAR// ----------------------------------------------------------------------------// notebook// ----------------------------------------------------------------------------#if wxUSE_NOTEBOOKvoid wxWin32Renderer::DrawTab(wxDC& dc,                              const wxRect& rectOrig,                              wxDirection dir,                              const wxString& label,                              const wxBitmap& bitmap,                              int flags,                              int indexAccel){    #define SELECT_FOR_VERTICAL(X,Y) ( isVertical ? Y : X )    #define REVERSE_FOR_VERTICAL(X,Y) \        SELECT_FOR_VERTICAL(X,Y)      \        ,                             \        SELECT_FOR_VERTICAL(Y,X)    wxRect rect = rectOrig;    bool isVertical = ( dir == wxLEFT ) || ( dir == wxRIGHT );    // the current tab is drawn indented (to the top for default case) and    // bigger than the other ones    const wxSize indent = GetTabIndent();    if ( flags & wxCONTROL_SELECTED )    {        rect.Inflate( SELECT_FOR_VERTICAL( indent.x , 0),                      SELECT_FOR_VERTICAL( 0, indent.y ));        switch ( dir )        {            default:                wxFAIL_MSG(_T("invaild notebook tab orientation"));                // fall through            case wxTOP:                rect.y -= indent.y;                // fall through            case wxBOTTOM:                rect.height += indent.y;                break;            case wxLEFT:                rect.x -= indent.x;                // fall through            case wxRIGHT:                rect.width += indent.x;                break;        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -