From 9a8c7620763844fe58f16542a0400e1da68d88d2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 8 Dec 1999 08:19:45 +0000 Subject: [PATCH] 1. many DrawRotatedText() corrections (gtk) 2. compilation fix for window.cpp (!HAVE_XIM) 3. mentioned wxGTK slider limitations in the docs git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4866 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 + docs/latex/wx/slider.tex | 3 +- samples/drawing/drawing.cpp | 9 ++- src/gtk/dcclient.cpp | 144 +++++++++++++++++++++--------------- src/gtk/window.cpp | 25 ++++--- src/gtk1/dcclient.cpp | 144 +++++++++++++++++++++--------------- src/gtk1/window.cpp | 25 ++++--- src/msw/dc.cpp | 1 - 8 files changed, 207 insertions(+), 146 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 5e2fa23846..e5ac51edf0 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -26,6 +26,8 @@ all (GUI): - wxDC::DrawRotatedText() (contributed by Hans-Joachim Baader, limited to +/-90 degrees for now - contributions to improve it are welcome!) +- TIFF support added (libtiff required and included in the distribution) + wxMSW: - wxTreeCtrl::IsVisible() bug fixed (thanks to Gary Chessun) diff --git a/docs/latex/wx/slider.tex b/docs/latex/wx/slider.tex index 8697a032dd..7d0d391050 100644 --- a/docs/latex/wx/slider.tex +++ b/docs/latex/wx/slider.tex @@ -26,7 +26,8 @@ Slider events are handled in the same way as a scrollbar. \twocolitem{\windowstyle{wxSL\_HORIZONTAL}}{Displays the slider horizontally.} \twocolitem{\windowstyle{wxSL\_VERTICAL}}{Displays the slider vertically.} \twocolitem{\windowstyle{wxSL\_AUTOTICKS}}{Displays tick marks.} -\twocolitem{\windowstyle{wxSL\_LABELS}}{Displays minimum, maximum and value labels.} +\twocolitem{\windowstyle{wxSL\_LABELS}}{Displays minimum, maximum and value labels. +(NB: only displays the current value label under wxGTK)} \twocolitem{\windowstyle{wxSL\_LEFT}}{Displays ticks on the left, if a vertical slider.} \twocolitem{\windowstyle{wxSL\_RIGHT}}{Displays ticks on the right, if a vertical slider.} \twocolitem{\windowstyle{wxSL\_TOP}}{Displays ticks on the top, if a horizontal slider.} diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 3309863671..76af6243ef 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -212,7 +212,7 @@ void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc ) { dc.SetPen( wxPen( "black", width, wxSOLID) ); dc.SetBrush( *wxRED_BRUSH ); - dc.DrawRectangle( x+10, y+10, 110, 190 ); + dc.DrawRectangle( x+10, y+10, 100, 190 ); dc.SetPen( wxPen( "black", width, wxSOLID) ); dc.DrawLine( x+20, y+20, 100, y+20 ); @@ -276,10 +276,15 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) dc.FloodFill(0, 0, wxColour(255, 0, 0)); #endif // + // set underlined font for testing + dc.SetFont( wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, TRUE) ); dc.DrawText( "This is text", 110, 10 ); + dc.DrawRotatedText( "That is text", 60, 30, -45 ); + + dc.SetFont( *wxNORMAL_FONT ); wxString text; - dc. SetBackgroundMode(wxSOLID); + dc. SetBackgroundMode(wxTRANSPARENT); for ( int n = -180; n < 180; n += 30 ) { diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 7adf096ae7..a5af293c90 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -41,6 +41,15 @@ static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL; const double RAD2DEG = 180.0 / M_PI; +// ---------------------------------------------------------------------------- +// private functions +// ---------------------------------------------------------------------------- + +static inline double dmax(double a, double b) { return a > b ? a : b; } +static inline double dmin(double a, double b) { return a < b ? a : b; } + +static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } + //----------------------------------------------------------------------------- // temporary implementation of the missing GDK function //----------------------------------------------------------------------------- @@ -85,25 +94,6 @@ void gdk_draw_bitmap (GdkDrawable *drawable, 1 ); } -/* - * compare two doubles and return the larger rounded - * to the nearest int - */ -static int roundmax(double a, double b) -{ - return (int)((a > b ? a : b) + 0.5); -} - -/* - * compare two doubles and return the smaller rounded - * to the nearest int - */ -static int roundmin(double a, double b) -{ - return (int)((a < b ? a : b) - 0.5); -} - - //----------------------------------------------------------------------------- // wxWindowDC //----------------------------------------------------------------------------- @@ -830,13 +820,12 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, wxCHECK_RET( font, wxT("invalid font") ); -// x = XLOG2DEV(x); -// y = YLOG2DEV(y); - - int cx = gdk_string_width( font, text.mbc_str() ); - int cy = font->ascent + font->descent; + // the size of the text + int w = gdk_string_width( font, text.mbc_str() ); + int h = font->ascent + font->descent; - wxBitmap src(cx, cy); + // draw the string normally + wxBitmap src(w, h); wxMemoryDC dc; dc.SelectObject(src); dc.SetFont(GetFont()); @@ -845,52 +834,87 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, dc.Clear(); dc.DrawText(text, 0, 0); dc.SetFont(wxNullFont); + dc.SelectObject(wxNullBitmap); // Calculate the size of the rotated bounding box. - double dx = cos(angle / 180.0 * M_PI); - double dy = sin(angle / 180.0 * M_PI); - double x4 = -cy * dy; - double y4 = cy * dx; - double x3 = cx * dx; - double y3 = cx * dy; - double x2 = x3 + x4; - double y2 = y3 + y4; - double x1 = x; - double y1 = y; - - // Create image from the source bitmap after writing the text into it. - wxImage image(src); - - int minx = roundmin(0, roundmin(x4, roundmin(x2, x3))); - int miny = roundmin(0, roundmin(y4, roundmin(y2, y3))); - int maxx = roundmax(0, roundmax(x4, roundmax(x2, x3))); - int maxy = roundmax(0, roundmax(y4, roundmax(y2, y3))); - - // This rotates counterclockwise around the top left corner. - for (int rx = minx; rx < maxx; rx++) + double rad = DegToRad(angle); + double dx = cos(rad), + dy = sin(rad); + + // the rectngle vertices are counted clockwise with the first one being at + // (0, 0) (or, rather, at (x, y)) + double x2 = w*dx, + y2 = -w*dy; // y axis points to the bottom, hence minus + double x4 = h*dy, + 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); + + GdkColor *colText = m_textForegroundColour.GetColor(), + *colBack = m_textBackgroundColour.GetColor(); + + bool textColSet = TRUE; + + unsigned char *data = image.GetData(); + + // paint pixel by pixel + for ( wxCoord srcX = 0; srcX < w; srcX++ ) { - for (int ry = miny; ry < maxy; ry++) + for ( wxCoord srcY = 0; srcY < h; srcY++ ) { - // transform dest coords to source coords - int sx = (int) (rx * dx + ry * dy + 0.5); - int sy = (int) (ry * dx - rx * dy + 0.5); - if (sx >= 0 && sx < cx && sy >= 0 && sy < cy) + // transform source coords to dest coords + double r = sqrt(srcX*srcX + srcY*srcY); + double angleOrig = atan2(srcY, 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) ) { - // draw black pixels, ignore white ones (i.e. transparent b/g) - if (image.GetRed(sx, sy) == 0) + // change colour if needed + if ( textPixel != textColSet ) { - DrawPoint(x1 + maxx - rx, cy + y1 - ry); - } - else - { - // Background - //DrawPoint(x1 + maxx - rx, cy + y1 + maxy - ry); + 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) ); } } } - // TODO call CalcBoundingBox() + // it would be better to draw with non underlined font and draw the line + // manually here (it would be more straight...) +#if 0 + if ( m_font.GetUnderlined() ) + { + gdk_draw_line( m_window, m_textGC, + XLOG2DEV(x + x4), YLOG2DEV(y + y4 + font->descent), + XLOG2DEV(x + x3), YLOG2DEV(y + y3 + font->descent)); + } +#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); } void wxWindowDC::DoGetTextExtent(const wxString &string, diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 9a6841c797..5dc903f0ca 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -223,18 +223,21 @@ static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget), void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window ) { -/* - wxString tmp = name; - tmp += wxT(" FROM "); - tmp += window; + // suppress warnings about gtk_debug_focus_in_callback being unused with + // this "if ( 0 )" + if ( 0 ) + { + wxString tmp = name; + tmp += wxT(" FROM "); + tmp += window; - wxChar *s = new wxChar[tmp.Length()+1]; + wxChar *s = new wxChar[tmp.Length()+1]; - wxStrcpy( s, tmp ); + wxStrcpy( s, tmp ); - gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event", - GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s ); -*/ + gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event", + GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s ); + } } #endif // Debug @@ -1658,10 +1661,10 @@ static void gtk_wxwindow_size_callback( GtkWidget *widget, GtkAllocation* alloc, if (g_isIdle) wxapp_install_idle_handler(); +#ifdef HAVE_XIM if (!win->m_ic) return; -#ifdef HAVE_XIM if (gdk_ic_get_style (win->m_ic) & GDK_IM_PREEDIT_POSITION) { gint width, height; @@ -1671,7 +1674,7 @@ static void gtk_wxwindow_size_callback( GtkWidget *widget, GtkAllocation* alloc, win->m_icattr->preedit_area.height = height; gdk_ic_set_attr (win->m_ic, win->m_icattr, GDK_IC_PREEDIT_AREA); } -#endif +#endif // HAVE_XIM } //----------------------------------------------------------------------------- diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 7adf096ae7..a5af293c90 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -41,6 +41,15 @@ static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL; const double RAD2DEG = 180.0 / M_PI; +// ---------------------------------------------------------------------------- +// private functions +// ---------------------------------------------------------------------------- + +static inline double dmax(double a, double b) { return a > b ? a : b; } +static inline double dmin(double a, double b) { return a < b ? a : b; } + +static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } + //----------------------------------------------------------------------------- // temporary implementation of the missing GDK function //----------------------------------------------------------------------------- @@ -85,25 +94,6 @@ void gdk_draw_bitmap (GdkDrawable *drawable, 1 ); } -/* - * compare two doubles and return the larger rounded - * to the nearest int - */ -static int roundmax(double a, double b) -{ - return (int)((a > b ? a : b) + 0.5); -} - -/* - * compare two doubles and return the smaller rounded - * to the nearest int - */ -static int roundmin(double a, double b) -{ - return (int)((a < b ? a : b) - 0.5); -} - - //----------------------------------------------------------------------------- // wxWindowDC //----------------------------------------------------------------------------- @@ -830,13 +820,12 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, wxCHECK_RET( font, wxT("invalid font") ); -// x = XLOG2DEV(x); -// y = YLOG2DEV(y); - - int cx = gdk_string_width( font, text.mbc_str() ); - int cy = font->ascent + font->descent; + // the size of the text + int w = gdk_string_width( font, text.mbc_str() ); + int h = font->ascent + font->descent; - wxBitmap src(cx, cy); + // draw the string normally + wxBitmap src(w, h); wxMemoryDC dc; dc.SelectObject(src); dc.SetFont(GetFont()); @@ -845,52 +834,87 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, dc.Clear(); dc.DrawText(text, 0, 0); dc.SetFont(wxNullFont); + dc.SelectObject(wxNullBitmap); // Calculate the size of the rotated bounding box. - double dx = cos(angle / 180.0 * M_PI); - double dy = sin(angle / 180.0 * M_PI); - double x4 = -cy * dy; - double y4 = cy * dx; - double x3 = cx * dx; - double y3 = cx * dy; - double x2 = x3 + x4; - double y2 = y3 + y4; - double x1 = x; - double y1 = y; - - // Create image from the source bitmap after writing the text into it. - wxImage image(src); - - int minx = roundmin(0, roundmin(x4, roundmin(x2, x3))); - int miny = roundmin(0, roundmin(y4, roundmin(y2, y3))); - int maxx = roundmax(0, roundmax(x4, roundmax(x2, x3))); - int maxy = roundmax(0, roundmax(y4, roundmax(y2, y3))); - - // This rotates counterclockwise around the top left corner. - for (int rx = minx; rx < maxx; rx++) + double rad = DegToRad(angle); + double dx = cos(rad), + dy = sin(rad); + + // the rectngle vertices are counted clockwise with the first one being at + // (0, 0) (or, rather, at (x, y)) + double x2 = w*dx, + y2 = -w*dy; // y axis points to the bottom, hence minus + double x4 = h*dy, + 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); + + GdkColor *colText = m_textForegroundColour.GetColor(), + *colBack = m_textBackgroundColour.GetColor(); + + bool textColSet = TRUE; + + unsigned char *data = image.GetData(); + + // paint pixel by pixel + for ( wxCoord srcX = 0; srcX < w; srcX++ ) { - for (int ry = miny; ry < maxy; ry++) + for ( wxCoord srcY = 0; srcY < h; srcY++ ) { - // transform dest coords to source coords - int sx = (int) (rx * dx + ry * dy + 0.5); - int sy = (int) (ry * dx - rx * dy + 0.5); - if (sx >= 0 && sx < cx && sy >= 0 && sy < cy) + // transform source coords to dest coords + double r = sqrt(srcX*srcX + srcY*srcY); + double angleOrig = atan2(srcY, 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) ) { - // draw black pixels, ignore white ones (i.e. transparent b/g) - if (image.GetRed(sx, sy) == 0) + // change colour if needed + if ( textPixel != textColSet ) { - DrawPoint(x1 + maxx - rx, cy + y1 - ry); - } - else - { - // Background - //DrawPoint(x1 + maxx - rx, cy + y1 + maxy - ry); + 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) ); } } } - // TODO call CalcBoundingBox() + // it would be better to draw with non underlined font and draw the line + // manually here (it would be more straight...) +#if 0 + if ( m_font.GetUnderlined() ) + { + gdk_draw_line( m_window, m_textGC, + XLOG2DEV(x + x4), YLOG2DEV(y + y4 + font->descent), + XLOG2DEV(x + x3), YLOG2DEV(y + y3 + font->descent)); + } +#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); } void wxWindowDC::DoGetTextExtent(const wxString &string, diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 9a6841c797..5dc903f0ca 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -223,18 +223,21 @@ static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget), void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window ) { -/* - wxString tmp = name; - tmp += wxT(" FROM "); - tmp += window; + // suppress warnings about gtk_debug_focus_in_callback being unused with + // this "if ( 0 )" + if ( 0 ) + { + wxString tmp = name; + tmp += wxT(" FROM "); + tmp += window; - wxChar *s = new wxChar[tmp.Length()+1]; + wxChar *s = new wxChar[tmp.Length()+1]; - wxStrcpy( s, tmp ); + wxStrcpy( s, tmp ); - gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event", - GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s ); -*/ + gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event", + GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s ); + } } #endif // Debug @@ -1658,10 +1661,10 @@ static void gtk_wxwindow_size_callback( GtkWidget *widget, GtkAllocation* alloc, if (g_isIdle) wxapp_install_idle_handler(); +#ifdef HAVE_XIM if (!win->m_ic) return; -#ifdef HAVE_XIM if (gdk_ic_get_style (win->m_ic) & GDK_IM_PREEDIT_POSITION) { gint width, height; @@ -1671,7 +1674,7 @@ static void gtk_wxwindow_size_callback( GtkWidget *widget, GtkAllocation* alloc, win->m_icattr->preedit_area.height = height; gdk_ic_set_attr (win->m_ic, win->m_icattr, GDK_IC_PREEDIT_AREA); } -#endif +#endif // HAVE_XIM } //----------------------------------------------------------------------------- diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 9b43f56bb7..e006996324 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -734,7 +734,6 @@ void wxDC::DoDrawRotatedText(const wxString& text, // "upper left" and "upper right" CalcBoundingBox(x, y); CalcBoundingBox(x + w*cos(rad), y - h*sin(rad)); - CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); // "bottom left" and "bottom right" x += (wxCoord)(h*sin(rad)); -- 2.45.2