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

📄 gtk.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    // for a mono bitmap he colours it appears in depends on the current text    // colours, so set them correctly    wxColour colFgOld;    if ( bmpLineWrap.GetDepth() == 1 )    {        colFgOld = dc.GetTextForeground();        // FIXME: I wonder what should we do if the background is black too?        dc.SetTextForeground(*wxBLACK);    }    dc.DrawBitmap(bmpLineWrap,                  rect.x, rect.y + (rect.height - bmpLineWrap.GetHeight())/2);    if ( colFgOld.Ok() )    {        // restore old colour        dc.SetTextForeground(colFgOld);    }}#endif // wxUSE_TEXTCTRL// ----------------------------------------------------------------------------// notebook// ----------------------------------------------------------------------------#if wxUSE_NOTEBOOKvoid wxGTKRenderer::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;        }    }    // selected tab has different colour    wxColour col = flags & wxCONTROL_SELECTED                        ? wxSCHEME_COLOUR(m_scheme, SHADOW_IN)                        : wxSCHEME_COLOUR(m_scheme, SCROLLBAR);    DrawSolidRect(dc, col, rect);    if ( flags & wxCONTROL_FOCUSED )    {        // draw the focus rect        wxRect rectBorder = rect;        rectBorder.Deflate(4, 3);        if ( dir == wxBOTTOM )            rectBorder.Offset(0, -1);        if ( dir == wxRIGHT )            rectBorder.Offset(-1, 0);        DrawRect(dc, &rectBorder, m_penBlack);    }    // draw the text, image and the focus around them (if necessary)    wxRect rectLabel( REVERSE_FOR_VERTICAL(rect.x,rect.y),                      REVERSE_FOR_VERTICAL(rect.width,rect.height)                    );    rectLabel.Deflate(1, 1);    if ( isVertical )    {        // draw it horizontally into memory and rotate for screen        wxMemoryDC dcMem;        wxBitmap bitmapRotated,                 bitmapMem( rectLabel.x + rectLabel.width,                            rectLabel.y + rectLabel.height );        dcMem.SelectObject(bitmapMem);        dcMem.SetBackground(dc.GetBackground());        dcMem.SetFont(dc.GetFont());        dcMem.SetTextForeground(dc.GetTextForeground());        dcMem.Clear();        bitmapRotated =#if wxUSE_IMAGE                        wxBitmap( wxImage( bitmap.ConvertToImage() ).Rotate90(dir==wxLEFT) )#else                        bitmap#endif // wxUSE_IMAGE                        ;        dcMem.DrawLabel(label, bitmapRotated, rectLabel, wxALIGN_CENTRE, indexAccel);        dcMem.SelectObject(wxNullBitmap);        bitmapMem = bitmapMem.GetSubBitmap(rectLabel);#if wxUSE_IMAGE        bitmapMem = wxBitmap(wxImage(bitmapMem.ConvertToImage()).Rotate90(dir==wxRIGHT))#endif                    ;        dc.DrawBitmap(bitmapMem, rectLabel.y, rectLabel.x, false);    }    else    {        dc.DrawLabel(label, bitmap, rectLabel, wxALIGN_CENTRE, indexAccel);    }    // now draw the tab itself    wxCoord x = SELECT_FOR_VERTICAL(rect.x,rect.y),            y = SELECT_FOR_VERTICAL(rect.y,rect.x),            x2 = SELECT_FOR_VERTICAL(rect.GetRight(),rect.GetBottom()),            y2 = SELECT_FOR_VERTICAL(rect.GetBottom(),rect.GetRight());    switch ( dir )    {        default:            // default is top        case wxLEFT:            // left orientation looks like top but IsVertical makes x and y reversed        case wxTOP:            // top is not vertical so use coordinates in written order            dc.SetPen(m_penHighlight);            dc.DrawLine(REVERSE_FOR_VERTICAL(x, y2),                        REVERSE_FOR_VERTICAL(x, y));            dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y),                        REVERSE_FOR_VERTICAL(x2, y));            dc.SetPen(m_penBlack);            dc.DrawLine(REVERSE_FOR_VERTICAL(x2, y2),                        REVERSE_FOR_VERTICAL(x2, y));            dc.SetPen(m_penDarkGrey);            dc.DrawLine(REVERSE_FOR_VERTICAL(x2 - 1, y2),                        REVERSE_FOR_VERTICAL(x2 - 1, y + 1));            if ( flags & wxCONTROL_SELECTED )            {                dc.SetPen(m_penLightGrey);                // overwrite the part of the border below this tab                dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y2 + 1),                            REVERSE_FOR_VERTICAL(x2 - 1, y2 + 1));                // and the shadow of the tab to the left of us                dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y + 2),                            REVERSE_FOR_VERTICAL(x + 1, y2 + 1));            }            break;        case wxRIGHT:            // right orientation looks like bottom but IsVertical makes x and y reversed        case wxBOTTOM:            // bottom is not vertical so use coordinates in written order            dc.SetPen(m_penHighlight);            // we need to continue one pixel further to overwrite the corner of            // the border for the selected tab            dc.DrawLine(REVERSE_FOR_VERTICAL(x, y - (flags & wxCONTROL_SELECTED ? 1 : 0)),                        REVERSE_FOR_VERTICAL(x, y2));            // it doesn't work like this (TODO: implement it properly)#if 0            // erase the corner of the tab to the right            dc.SetPen(m_penLightGrey);            dc.DrawPoint(REVERSE_FOR_VERTICAL(x2 - 1, y - 2));            dc.DrawPoint(REVERSE_FOR_VERTICAL(x2 - 2, y - 2));            dc.DrawPoint(REVERSE_FOR_VERTICAL(x2 - 2, y - 1));#endif // 0            dc.SetPen(m_penBlack);            dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y2),                        REVERSE_FOR_VERTICAL(x2, y2));            dc.DrawLine(REVERSE_FOR_VERTICAL(x2, y),                        REVERSE_FOR_VERTICAL(x2, y2));            dc.SetPen(m_penDarkGrey);            dc.DrawLine(REVERSE_FOR_VERTICAL(x + 2, y2 - 1),                        REVERSE_FOR_VERTICAL(x2 - 1, y2 - 1));            dc.DrawLine(REVERSE_FOR_VERTICAL(x2 - 1, y),                        REVERSE_FOR_VERTICAL(x2 - 1, y2));            if ( flags & wxCONTROL_SELECTED )            {                dc.SetPen(m_penLightGrey);                // overwrite the part of the (double!) border above this tab                dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y - 1),                            REVERSE_FOR_VERTICAL(x2 - 1, y - 1));                dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y - 2),                            REVERSE_FOR_VERTICAL(x2 - 1, y - 2));                // and the shadow of the tab to the left of us                dc.DrawLine(REVERSE_FOR_VERTICAL(x + 1, y2 - 1),                            REVERSE_FOR_VERTICAL(x + 1, y - 1));            }            break;    }}#endif // wxUSE_NOTEBOOK// ----------------------------------------------------------------------------// slider// ----------------------------------------------------------------------------#if wxUSE_SLIDERwxSize wxGTKRenderer::GetSliderThumbSize(const wxRect& rect,                                         int lenThumb,                                         wxOrientation orient) const{    static const wxCoord SLIDER_THUMB_LENGTH = 30;    wxSize size;    wxRect rectShaft = GetSliderShaftRect(rect, lenThumb, orient);    if ( orient == wxHORIZONTAL )    {        size.x = wxMin(SLIDER_THUMB_LENGTH, rectShaft.width);        size.y = rectShaft.height;    }    else // vertical    {        size.y = wxMin(SLIDER_THUMB_LENGTH, rectShaft.height);        size.x = rectShaft.width;    }    return size;}wxRect wxGTKRenderer::GetSliderShaftRect(const wxRect& rect,                                         int WXUNUSED(lenThumb),                                         wxOrientation WXUNUSED(orient),                                         long WXUNUSED(style)) const{    return rect.Deflate(2*BORDER_THICKNESS, 2*BORDER_THICKNESS);}void wxGTKRenderer::DrawSliderShaft(wxDC& dc,                                    const wxRect& rectOrig,                                    int WXUNUSED(lenThumb),                                    wxOrientation WXUNUSED(orient),                                    int flags,                                    long WXUNUSED(style),                                    wxRect *rectShaft){    wxRect rect = rectOrig;    // draw the border first    if ( flags & wxCONTROL_FOCUSED )    {        DrawRect(dc, &rect, m_penBlack);    }    else // not focused, normal    {        DrawAntiShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);    }    DrawAntiShadedRect(dc, &rect, m_penBlack, m_penLightGrey);    // and the background    DrawSolidRect(dc, wxSCHEME_COLOUR(m_scheme, SCROLLBAR), rect);    if ( rectShaft )        *rectShaft = rect;}void wxGTKRenderer::DrawSliderThumb(wxDC& dc,                                    const wxRect& rectOrig,                                    wxOrientation orient,                                    int WXUNUSED(flags),                                    long WXUNUSED(style)){    // draw the thumb border    wxRect rect = rectOrig;    DrawAntiRaisedBorder(dc, &rect);    // draw the handle in the middle    if ( orient == wxVERTICAL )    {        rect.height = 2*BORDER_THICKNESS;        rect.y = rectOrig.y + (rectOrig.height - rect.height) / 2;    }    else // horz    {        rect.width = 2*BORDER_THICKNESS;        rect.x = rectOrig.x + (rectOrig.width - rect.width) / 2;    }    DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);}#endif // wxUSE_SLIDER#if wxUSE_MENUS// ----------------------------------------------------------------------------// menu and menubar// ----------------------------------------------------------------------------// wxGTKMenuGeometryInfo: the wxMenuGeometryInfo used by wxGTKRendererclass WXDLLEXPORT wxGTKMenuGeometryInfo : public wxMenuGeometryInfo{public:    virtual wxSize GetSize() const { return m_size; }    wxCoord GetLabelOffset() const { return m_ofsLabel; }    wxCoord GetAccelOffset() const { return m_ofsAccel; }    wxCoord GetItemHeight() const { return m_heightItem; }private:    // the total size of the menu    wxSize m_size;    // the offset of the start of the menu item label    wxCoord m_ofsLabel;    // the offset of the start of the accel label    wxCoord m_ofsAccel;    // the height of a normal (not separator) item    wxCoord m_heightItem;    friend wxMenuGeometryInfo *        wxGTKRenderer::GetMenuGeometry(wxWindow *, const wxMenu&) const;};// FIXME: all constants are hardcoded but shouldn't bestatic const wxCoord MENU_LEFT_MARGIN = 9;static const wxCoord MENU_RIGHT_MARGIN = 6;static const wxCoord MENU_HORZ_MARGIN = 6;static const wxCoord MENU_VERT_MARGIN = 3;// the margin around bitmap/check marks (on each side)static const wxCoord MENU_BMP_MARGIN = 2;// the margin between the labels and accel stringsstatic const wxCoord MENU_ACCEL_MARGIN = 8;// the separator height in pixels: in fact, strangely enough, the real height// is 2 but Windows adds one extra pixel in the bottom margin, so take it into// account herestatic const wxCoord MENU_SEPARATOR_HEIGHT = 3;// the size of the standard checkmark bitmapstatic const wxCoord MENU_CHECK_SIZE = 9;void wxGTKRenderer::DrawMenuBarItem(wxDC& dc,                                    const wxRect& rect,                                    const wxString& label,                                    int flags,                                    int indexAccel){    DoDrawMenuItem(dc, rect, label, flags, indexAccel);}void wxGTKRenderer::DrawMenuItem(wxDC& dc,                                 wxCoord y,                                 const wxMenuGeometryInfo& gi,                                 const wxString& label,                                 const wxString& accel,                                 const wxBitmap& bitmap,                                 int flags,                                 int indexAccel){    const wxGTKMenuGeometryInfo& geomInfo = (const wxGTKMenuGeometryInfo&)gi;    wxRect rect;    rect.x = 0;    rect.y = y;    rect.width = geomInfo.GetSize().x;    rect.height = geomInfo.GetItemHeight();    DoDrawMenuItem(dc, rect, label, flags, indexAccel, accel, bitmap, &geomInfo);}void wxGTKRenderer::DoDrawMenuItem(wxDC& dc,                                   const wxRect& rectOrig,                                   const wxString& label,                                   int flags,                                   int indexAccel,                                   const wxString& accel,                                   const wxBitmap& bitmap,                                   const wxGTKMenuGeometryInfo *geometryInfo){    wxRect rect = rectOrig;

⌨️ 快捷键说明

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