X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a1e101d0561ec98f807f176c5c3b2383ecbd9349..82a16d7e5e5c83e95a4caa7314de2dbfbd1debdc:/src/gtk1/dcclient.cpp diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 94df22e7d9..3af3e2924f 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -1079,6 +1079,14 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, wxBitmap use_bitmap = bitmap; if ((w != ww) || (h != hh)) use_bitmap = use_bitmap.Rescale( 0, 0, ww, hh, ww, hh ); + +#if !GTK_CHECK_VERSION(2,2,0) + // NB: We can't render pixbufs with GTK+ < 2.2, we need to use pixmaps code. + // Pixbufs-based bitmaps with alpha channel don't have a mask, so we + // have to call GetPixmap() here -- it converts the pixbuf into pixmap + // and also creates the mask as a side-effect: + use_bitmap.GetPixmap(); +#endif // apply mask if any GdkBitmap *mask = (GdkBitmap *) NULL; @@ -1147,7 +1155,21 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, } else { - gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 ); +#if GTK_CHECK_VERSION(2,2,0) + if (use_bitmap.HasPixbuf()) + { + gdk_draw_pixbuf(m_window, m_penGC, + use_bitmap.GetPixbuf(), + 0, 0, xx, yy, -1, -1, + GDK_RGB_DITHER_NORMAL, xx, yy); + } + else +#endif + { + gdk_draw_pixmap(m_window, m_penGC, + use_bitmap.GetPixmap(), + 0, 0, xx, yy, -1, -1); + } } // remove mask again if any @@ -1294,7 +1316,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, // Scale bitmap if required wxBitmap use_bitmap; - if ((bm_width != bm_ww) || (bm_height != bm_hh)) + if ((memDC->m_selected.GetWidth()!= bm_ww) || ( memDC->m_selected.GetHeight()!= bm_hh)) { // This indicates that the blitting code below will get // a clipped bitmap and therefore needs to move the origin @@ -1467,17 +1489,33 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) wxCHECK_RET( m_layout, wxT("no Pango layout") ); wxCHECK_RET( m_fontdesc, wxT("no Pango font description") ); + bool underlined = m_font.Ok() && m_font.GetUnderlined(); + #if wxUSE_UNICODE const wxCharBuffer data = wxConvUTF8.cWC2MB( text ); #else const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text ); + if ( !wdata ) + return; const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); #endif - pango_layout_set_text( m_layout, (const char*) data, strlen( (const char*) data )); + size_t datalen = strlen((const char*)data); + pango_layout_set_text( m_layout, (const char*) data, datalen); + + if (underlined) + { + PangoAttrList *attrs = pango_attr_list_new(); + PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); + a->start_index = 0; + a->end_index = datalen; + pango_attr_list_insert(attrs, a); + pango_layout_set_attributes(m_layout, attrs); + pango_attr_list_unref(attrs); + } int w,h; - - if (fabs(m_scaleY - 1.0) < 0.00001) + + if (fabs(m_scaleY - 1.0) > 0.00001) { // If there is a user or actually any scale applied to // the device context, scale the font. @@ -1520,6 +1558,12 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) // Draw layout. gdk_draw_layout( m_window, m_textGC, x, y, m_layout ); } + + if (underlined) + { + // undo underline attributes setting: + pango_layout_set_attributes(m_layout, NULL); + } wxCoord width = w; wxCoord height = h; @@ -1553,6 +1597,11 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) CalcBoundingBox (x, y); } + +// TODO: There is an example of rotating text with GTK2 that would probably be +// a better approach here: +// http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html + void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle ) { if (angle == 0.0) @@ -1565,26 +1614,31 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, if (!m_window) return; -#ifdef __WXGTK20__ + wxCoord w; + wxCoord h; + +#ifdef __WXGTK20__ // implement later without GdkFont for GTK 2.0 - return; + GetTextExtent(text, &w, &h, NULL,NULL, &m_font); + #else GdkFont *font = m_font.GetInternalFont( m_scaleY ); wxCHECK_RET( font, wxT("invalid font") ); // the size of the text - wxCoord w = gdk_string_width( font, text.mbc_str() ); - wxCoord h = font->ascent + font->descent; - + w = gdk_string_width( font, text.mbc_str() ); + h = font->ascent + font->descent; +#endif // draw the string normally wxBitmap src(w, h); wxMemoryDC dc; dc.SelectObject(src); dc.SetFont(GetFont()); - dc.SetBackground(*wxWHITE_BRUSH); + dc.SetBackground(*wxBLACK_BRUSH); dc.SetBrush(*wxBLACK_BRUSH); dc.Clear(); + dc.SetTextForeground( *wxWHITE ); dc.DrawText(text, 0, 0); dc.SelectObject(wxNullBitmap); @@ -1601,54 +1655,45 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, y4 = h*dx; double x3 = x4 + x2, y3 = y4 + y2; - + // calc max and min wxCoord maxX = (wxCoord)(dmax(x2, dmax(x3, x4)) + 0.5), maxY = (wxCoord)(dmax(y2, dmax(y3, y4)) + 0.5), minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5), minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5); - // prepare to blit-with-rotate the bitmap to the DC - wxImage image = src.ConvertToImage(); - - GdkColor *colText = m_textForegroundColour.GetColor(), - *colBack = m_textBackgroundColour.GetColor(); - bool textColSet = TRUE; + wxImage image = src.ConvertToImage(); - unsigned char *data = image.GetData(); + image.ConvertColourToAlpha( m_textForegroundColour.Red(), + m_textForegroundColour.Green(), + m_textForegroundColour.Blue() ); + image = image.Rotate( rad, wxPoint(0,0) ); + + int i_angle = (int) angle; + i_angle = i_angle % 360; + int xoffset = 0; + if ((i_angle >= 90.0) && (i_angle < 270.0)) + xoffset = image.GetWidth(); + int yoffset = 0; + if ((i_angle >= 0.0) && (i_angle < 180.0)) + yoffset = image.GetHeight(); + + if ((i_angle >= 0) && (i_angle < 90)) + yoffset -= (int)( cos(rad)*h ); + if ((i_angle >= 90) && (i_angle < 180)) + xoffset -= (int)( sin(rad)*h ); + if ((i_angle >= 180) && (i_angle < 270)) + yoffset -= (int)( cos(rad)*h ); + if ((i_angle >= 270) && (i_angle < 360)) + xoffset -= (int)( sin(rad)*h ); + + int i_x = x - xoffset; + int i_y = y - yoffset; + + src = image; + DoDrawBitmap( src, i_x, i_y, true ); - // paint pixel by pixel - for ( wxCoord srcX = 0; srcX < w; srcX++ ) - { - for ( wxCoord srcY = 0; srcY < h; srcY++ ) - { - // transform source coords to dest coords - double r = sqrt((double)srcX*srcX + srcY*srcY); - double angleOrig = atan2((double)srcY, (double)srcX) - rad; - wxCoord dstX = (wxCoord)(r*cos(angleOrig) + 0.5), - dstY = (wxCoord)(r*sin(angleOrig) + 0.5); - - // black pixel? - bool textPixel = data[(srcY*w + srcX)*3] == 0; - if ( textPixel || (m_backgroundMode == wxSOLID) ) - { - // change colour if needed - if ( textPixel != textColSet ) - { - gdk_gc_set_foreground( m_textGC, textPixel ? colText - : colBack ); - - textColSet = textPixel; - } - - // don't use DrawPoint() because it uses the current pen - // colour, and we don't need it here - gdk_draw_point( m_window, m_textGC, - XLOG2DEV(x) + dstX, YLOG2DEV(y) + dstY ); - } - } - } // it would be better to draw with non underlined font and draw the line // manually here (it would be more straight...) @@ -1661,13 +1706,9 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, } #endif // 0 - // restore the font colour - gdk_gc_set_foreground( m_textGC, colText ); - // update the bounding box CalcBoundingBox(x + minX, y + minY); CalcBoundingBox(x + maxX, y + maxY); -#endif } void wxWindowDC::DoGetTextExtent(const wxString &string, @@ -1675,10 +1716,17 @@ void wxWindowDC::DoGetTextExtent(const wxString &string, wxCoord *descent, wxCoord *externalLeading, wxFont *theFont) const { + if ( width ) + *width = 0; + if ( height ) + *height = 0; + if ( descent ) + *descent = 0; + if ( externalLeading ) + *externalLeading = 0; + if (string.IsEmpty()) { - if (width) (*width) = 0; - if (height) (*height) = 0; return; } @@ -1694,7 +1742,11 @@ void wxWindowDC::DoGetTextExtent(const wxString &string, #else const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); if ( !wdata ) + { + if (width) (*width) = 0; + if (height) (*height) = 0; return; + } const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); const char *dataUTF8 = (const char *)data; #endif @@ -1716,24 +1768,30 @@ void wxWindowDC::DoGetTextExtent(const wxString &string, *height = (wxCoord) h; if (descent) { - // Do something about metrics here. TODO. - *descent = 0; + PangoLayoutIter *iter = pango_layout_get_iter(m_layout); + int baseline = pango_layout_iter_get_baseline(iter); + pango_layout_iter_free(iter); + *descent = h - PANGO_PIXELS(baseline); } - if (externalLeading) - *externalLeading = 0; // ?? // Reset old font description if (theFont) pango_layout_set_font_description( m_layout, m_fontdesc ); #else // GTK+ 1.x wxFont fontToUse = m_font; - if (theFont) fontToUse = *theFont; + if (theFont) + fontToUse = *theFont; GdkFont *font = fontToUse.GetInternalFont( m_scaleY ); - if (width) (*width) = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX); - if (height) (*height) = wxCoord((font->ascent + font->descent) / m_scaleY); - if (descent) (*descent) = wxCoord(font->descent / m_scaleY); - if (externalLeading) (*externalLeading) = 0; // ?? + if ( !font ) + return; + + if (width) + *width = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX); + if (height) + *height = wxCoord((font->ascent + font->descent) / m_scaleY); + if (descent) + *descent = wxCoord(font->descent / m_scaleY); #endif // GTK+ 2/1 }