1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "dcclient.h"
15 #include "wx/dcclient.h"
16 #include "wx/dcmemory.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
30 static GdkPixmap
*hatches
[num_hatches
];
31 static GdkPixmap
**hatch_bitmap
= NULL
;
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 #define RAD2DEG 57.2957795131
39 //-----------------------------------------------------------------------------
40 // temporary implementation of the missing GDK function
41 //-----------------------------------------------------------------------------
42 #include "gdk/gdkprivate.h"
43 void gdk_draw_bitmap (GdkDrawable
*drawable
,
53 GdkWindowPrivate
*drawable_private
;
54 GdkWindowPrivate
*src_private
;
55 GdkGCPrivate
*gc_private
;
57 g_return_if_fail (drawable
!= NULL
);
58 g_return_if_fail (src
!= NULL
);
59 g_return_if_fail (gc
!= NULL
);
61 drawable_private
= (GdkWindowPrivate
*) drawable
;
62 src_private
= (GdkWindowPrivate
*) src
;
63 if (drawable_private
->destroyed
|| src_private
->destroyed
)
65 gc_private
= (GdkGCPrivate
*) gc
;
68 width
= src_private
->width
;
70 height
= src_private
->height
;
72 XCopyPlane (drawable_private
->xdisplay
,
74 drawable_private
->xwindow
,
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
86 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
,wxDC
)
88 wxPaintDC::wxPaintDC(void)
92 wxPaintDC::wxPaintDC( wxWindow
*window
)
95 GtkWidget
*widget
= window
->m_wxwindow
;
97 m_window
= widget
->window
;
98 if (!m_window
) return;
99 if (window
->m_wxwindow
)
100 m_cmap
= gtk_widget_get_colormap( window
->m_wxwindow
);
102 m_cmap
= gtk_widget_get_colormap( window
->m_widget
);
107 window
->GetDrawingOffset( &x
, &y
);
108 SetInternalDeviceOrigin( -x
, -y
);
111 wxPaintDC::~wxPaintDC(void)
115 void wxPaintDC::FloodFill( long WXUNUSED(x1
), long WXUNUSED(y1
),
116 wxColour
*WXUNUSED(col
), int WXUNUSED(style
) )
120 bool wxPaintDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
125 void wxPaintDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
129 if (m_pen
.GetStyle() != wxTRANSPARENT
)
131 gdk_draw_line( m_window
, m_penGC
,
132 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
136 void wxPaintDC::CrossHair( long x
, long y
)
140 if (m_pen
.GetStyle() != wxTRANSPARENT
)
145 long xx
= XLOG2DEV(x
);
146 long yy
= YLOG2DEV(y
);
147 gdk_draw_line( m_window
, m_penGC
,
148 0, yy
, XLOG2DEVREL(w
), yy
);
149 gdk_draw_line( m_window
, m_penGC
,
150 xx
, 0, xx
, YLOG2DEVREL(h
) );
154 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
158 long xx1
= XLOG2DEV(x1
);
159 long yy1
= YLOG2DEV(y1
);
160 long xx2
= XLOG2DEV(x2
);
161 long yy2
= YLOG2DEV(y2
);
162 long xxc
= XLOG2DEV((long)xc
);
163 long yyc
= YLOG2DEV((long)yc
);
164 double dx
= xx1
- xxc
;
165 double dy
= yy1
- yyc
;
166 double radius
= sqrt(dx
*dx
+dy
*dy
);
167 long r
= (long)radius
;
168 double radius1
, radius2
;
170 if (xx1
== xx2
&& yy1
== yy2
)
178 radius1
= radius2
= 0.0;
182 radius1
= (xx1
- xxc
== 0) ?
183 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
184 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
185 radius2
= (xx2
- xxc
== 0) ?
186 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
187 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
189 long alpha1
= long(radius1
* 64.0);
190 long alpha2
= long((radius2
- radius1
) * 64.0);
191 while (alpha2
<= 0) alpha2
+= 360*64;
192 while (alpha1
> 360*64) alpha1
-= 360*64;
194 if (m_brush
.GetStyle() != wxTRANSPARENT
)
195 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
197 if (m_pen
.GetStyle() != wxTRANSPARENT
)
198 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
202 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
206 long xx
= XLOG2DEV(x
);
207 long yy
= YLOG2DEV(y
);
208 long ww
= m_signX
* XLOG2DEVREL(width
);
209 long hh
= m_signY
* YLOG2DEVREL(height
);
211 // CMB: handle -ve width and/or height
212 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
213 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
215 long start
= long(sa
* 64.0);
216 long end
= long(ea
* 64.0);
217 if (m_brush
.GetStyle() != wxTRANSPARENT
)
218 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
220 if (m_pen
.GetStyle() != wxTRANSPARENT
)
221 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
224 void wxPaintDC::DrawPoint( long x
, long y
)
228 if (m_pen
.GetStyle() != wxTRANSPARENT
)
229 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
232 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
236 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
238 for (int i
= 0; i
< n
-1; i
++)
240 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
241 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
242 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
243 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
244 gdk_draw_line( m_window
, m_brushGC
, x1
, y1
, x2
, y2
);
248 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
252 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
254 wxNode
*node
= points
->First();
257 wxPoint
*point
= (wxPoint
*)node
->Data();
258 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
259 long x1
= XLOG2DEV(point
->x
+ xoffset
);
260 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
261 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and again...
262 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
263 gdk_draw_line( m_window
, m_brushGC
, x1
, y1
, x2
, y2
);
268 void wxPaintDC::DrawPolygon( int WXUNUSED(n
), wxPoint
WXUNUSED(points
)[],
269 long WXUNUSED(xoffset
), long WXUNUSED(yoffset
), int WXUNUSED(fillStyle
) )
274 void wxPaintDC::DrawPolygon( wxList
*WXUNUSED(lines
), long WXUNUSED(xoffset
),
275 long WXUNUSED(yoffset
), int WXUNUSED(fillStyle
) )
280 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
284 long xx
= XLOG2DEV(x
);
285 long yy
= YLOG2DEV(y
);
286 long ww
= m_signX
* XLOG2DEVREL(width
);
287 long hh
= m_signY
* YLOG2DEVREL(height
);
289 // CMB: draw nothing if transformed w or h is 0
290 if (ww
== 0 || hh
== 0) return;
292 // CMB: handle -ve width and/or height
293 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
294 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
296 if (m_brush
.GetStyle() != wxTRANSPARENT
)
297 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
299 if (m_pen
.GetStyle() != wxTRANSPARENT
)
300 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
303 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
307 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
309 long xx
= XLOG2DEV(x
);
310 long yy
= YLOG2DEV(y
);
311 long ww
= m_signX
* XLOG2DEVREL(width
);
312 long hh
= m_signY
* YLOG2DEVREL(height
);
313 long rr
= XLOG2DEVREL((long)radius
);
315 // CMB: handle -ve width and/or height
316 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
317 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
319 // CMB: if radius is zero use DrawRectangle() instead to avoid
320 // X drawing errors with small radii
323 DrawRectangle( x
, y
, width
, height
);
327 // CMB: draw nothing if transformed w or h is 0
328 if (ww
== 0 || hh
== 0) return;
330 // CMB: adjust size if outline is drawn otherwise the result is
331 // 1 pixel too wide and high
332 if (m_pen
.GetStyle() != wxTRANSPARENT
)
338 // CMB: ensure dd is not larger than rectangle otherwise we
339 // get an hour glass shape
341 if (dd
> ww
) dd
= ww
;
342 if (dd
> hh
) dd
= hh
;
345 if (m_brush
.GetStyle() != wxTRANSPARENT
)
347 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
348 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
349 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
350 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
351 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
352 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
355 if (m_pen
.GetStyle() != wxTRANSPARENT
)
357 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
358 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
359 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
360 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
361 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
362 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
363 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
364 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
368 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
372 long xx
= XLOG2DEV(x
);
373 long yy
= YLOG2DEV(y
);
374 long ww
= m_signX
* XLOG2DEVREL(width
);
375 long hh
= m_signY
* YLOG2DEVREL(height
);
377 // CMB: handle -ve width and/or height
378 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
379 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
381 if (m_brush
.GetStyle() != wxTRANSPARENT
)
382 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
384 if (m_pen
.GetStyle() != wxTRANSPARENT
)
385 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
388 bool wxPaintDC::CanDrawBitmap(void) const
393 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
397 if (!icon
.Ok()) return;
399 int xx
= XLOG2DEV(x
);
400 int yy
= YLOG2DEV(y
);
402 GdkBitmap
*mask
= NULL
;
403 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
407 gdk_gc_set_clip_mask( m_penGC
, mask
);
408 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
411 GdkPixmap
*pm
= icon
.GetPixmap();
412 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
416 gdk_gc_set_clip_mask( m_penGC
, NULL
);
417 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
421 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
422 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool WXUNUSED(useMask
) )
424 if (!Ok()) return FALSE
;
426 // CMB 20/5/98: add blitting of bitmaps
427 if (source
->IsKindOf(CLASSINFO(wxMemoryDC
)))
429 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
430 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
437 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
438 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
439 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
)
445 wxClientDC
*csrc
= (wxClientDC
*)source
;
446 gdk_window_copy_area ( m_window
, m_penGC
,
447 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
449 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
450 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
) );
453 gdk_window_copy_area ( m_window, m_penGC,
454 XLOG2DEV(xdest), YLOG2DEV(ydest),
463 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
467 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
469 // CMB 21/5/98: draw text background if mode is wxSOLID
470 if (m_backgroundMode
== wxSOLID
)
472 long width
= gdk_string_width( font
, text
);
473 long height
= font
->ascent
+ font
->descent
;
474 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
475 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
476 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
478 gdk_draw_string( m_window
, font
, m_textGC
,
480 YLOG2DEV(y
) + font
->ascent
, text
);
483 bool wxPaintDC::CanGetTextExtent(void) const
488 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
489 long *WXUNUSED(descent
), long *WXUNUSED(externalLeading
),
490 wxFont
*WXUNUSED(theFont
), bool WXUNUSED(use16
) )
494 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
495 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
496 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
499 long wxPaintDC::GetCharWidth(void)
503 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
504 return gdk_string_width( font
, "H" );
507 long wxPaintDC::GetCharHeight(void)
511 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
512 return font
->ascent
+ font
->descent
;
515 void wxPaintDC::Clear(void)
519 DestroyClippingRegion();
520 gdk_window_clear( m_window
);
523 void wxPaintDC::SetFont( const wxFont
&font
)
530 void wxPaintDC::SetPen( const wxPen
&pen
)
534 if (m_pen
== pen
) return;
538 if (!m_pen
.Ok()) return;
540 gint width
= m_pen
.GetWidth();
541 // CMB: if width is non-zero scale it with the dc
548 // X doesn't allow different width in x and y and so we take
550 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
554 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
555 switch (m_pen
.GetStyle())
557 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; };
558 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
559 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
560 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
561 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; };
564 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
565 switch (m_pen
.GetCap())
567 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; };
568 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; };
569 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; };
572 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
573 switch (m_pen
.GetJoin())
575 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; };
576 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; };
577 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; };
580 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
582 m_pen
.GetColour().CalcPixel( m_cmap
);
583 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
586 void wxPaintDC::SetBrush( const wxBrush
&brush
)
590 if (m_brush
== brush
) return;
594 if (!m_brush
.Ok()) return;
596 m_brush
.GetColour().CalcPixel( m_cmap
);
597 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
599 GdkFill fillStyle
= GDK_SOLID
;
600 switch (m_brush
.GetStyle())
606 fillStyle
= GDK_STIPPLED
;
609 gdk_gc_set_fill( m_brushGC
, fillStyle
);
611 if (m_brush
.GetStyle() == wxSTIPPLE
)
613 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
616 if (IS_HATCH(m_brush
.GetStyle()))
618 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
619 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
623 void wxPaintDC::SetLogicalFunction( int function
)
625 if (m_logicalFunction
== function
) return;
626 GdkFunction mode
= GDK_COPY
;
629 case wxXOR
: mode
= GDK_INVERT
; break;
630 case wxINVERT
: mode
= GDK_INVERT
; break;
633 m_logicalFunction
= function
;
634 gdk_gc_set_function( m_penGC
, mode
);
635 gdk_gc_set_function( m_brushGC
, mode
);
638 void wxPaintDC::SetTextForeground( const wxColour
&col
)
642 if (m_textForegroundColour
== col
) return;
644 m_textForegroundColour
= col
;
645 if (!m_textForegroundColour
.Ok()) return;
647 m_textForegroundColour
.CalcPixel( m_cmap
);
648 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
651 void wxPaintDC::SetTextBackground( const wxColour
&col
)
655 if (m_textBackgroundColour
== col
) return;
657 m_textBackgroundColour
= col
;
658 if (!m_textBackgroundColour
.Ok()) return;
660 m_textBackgroundColour
.CalcPixel( m_cmap
);
661 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
664 void wxPaintDC::SetBackgroundMode( int mode
)
666 m_backgroundMode
= mode
;
669 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
673 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
675 wxDC::SetClippingRegion( x
, y
, width
, height
);
678 rect
.x
= XLOG2DEV(x
);
679 rect
.y
= YLOG2DEV(y
);
680 rect
.width
= XLOG2DEV(x
+width
);
681 rect
.height
= YLOG2DEV(y
+height
);
682 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
683 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
684 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
685 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
689 void wxPaintDC::DestroyClippingRegion(void)
691 wxDC::DestroyClippingRegion();
693 gdk_gc_set_clip_rectangle( m_penGC
, NULL
);
694 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
695 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
696 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
699 void wxPaintDC::SetUpDC(void)
702 m_logicalFunction
= wxCOPY
;
703 m_penGC
= gdk_gc_new( m_window
);
704 m_brushGC
= gdk_gc_new( m_window
);
705 m_textGC
= gdk_gc_new( m_window
);
706 m_bgGC
= gdk_gc_new( m_window
);
707 SetTextForeground( m_textForegroundColour
);
708 SetTextBackground( m_textBackgroundColour
);
713 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
717 hatch_bitmap
= hatches
;
718 hatch_bitmap
[0] = gdk_bitmap_create_from_data( NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
719 hatch_bitmap
[1] = gdk_bitmap_create_from_data( NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
720 hatch_bitmap
[2] = gdk_bitmap_create_from_data( NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
721 hatch_bitmap
[3] = gdk_bitmap_create_from_data( NULL
, cross_bits
, cross_width
, cross_height
);
722 hatch_bitmap
[4] = gdk_bitmap_create_from_data( NULL
, horiz_bits
, horiz_width
, horiz_height
);
723 hatch_bitmap
[5] = gdk_bitmap_create_from_data( NULL
, verti_bits
, verti_width
, verti_height
);
727 GdkWindow
*wxPaintDC::GetWindow(void)
732 // ----------------------------------- spline code ----------------------------------------
734 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
735 double a3
, double b3
, double a4
, double b4
);
736 void wx_clear_stack(void);
737 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
738 double *y3
, double *x4
, double *y4
);
739 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
740 double x4
, double y4
);
741 static bool wx_spline_add_point(double x
, double y
);
742 static void wx_spline_draw_point_array(wxDC
*dc
);
744 wxList wx_spline_point_list
;
746 #define half(z1, z2) ((z1+z2)/2.0)
749 /* iterative version */
751 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
754 register double xmid
, ymid
;
755 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
758 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
760 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
761 xmid
= (double)half(x2
, x3
);
762 ymid
= (double)half(y2
, y3
);
763 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
764 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
765 wx_spline_add_point( x1
, y1
);
766 wx_spline_add_point( xmid
, ymid
);
768 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
769 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
770 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
771 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
776 /* utilities used by spline drawing routines */
778 typedef struct wx_spline_stack_struct
{
779 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
782 #define SPLINE_STACK_DEPTH 20
783 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
784 static Stack
*wx_stack_top
;
785 static int wx_stack_count
;
787 void wx_clear_stack(void)
789 wx_stack_top
= wx_spline_stack
;
793 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
795 wx_stack_top
->x1
= x1
;
796 wx_stack_top
->y1
= y1
;
797 wx_stack_top
->x2
= x2
;
798 wx_stack_top
->y2
= y2
;
799 wx_stack_top
->x3
= x3
;
800 wx_stack_top
->y3
= y3
;
801 wx_stack_top
->x4
= x4
;
802 wx_stack_top
->y4
= y4
;
807 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
808 double *x3
, double *y3
, double *x4
, double *y4
)
810 if (wx_stack_count
== 0)
814 *x1
= wx_stack_top
->x1
;
815 *y1
= wx_stack_top
->y1
;
816 *x2
= wx_stack_top
->x2
;
817 *y2
= wx_stack_top
->y2
;
818 *x3
= wx_stack_top
->x3
;
819 *y3
= wx_stack_top
->y3
;
820 *x4
= wx_stack_top
->x4
;
821 *y4
= wx_stack_top
->y4
;
825 static bool wx_spline_add_point(double x
, double y
)
827 wxPoint
*point
= new wxPoint
;
830 wx_spline_point_list
.Append((wxObject
*)point
);
834 static void wx_spline_draw_point_array(wxDC
*dc
)
836 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
837 wxNode
*node
= wx_spline_point_list
.First();
840 wxPoint
*point
= (wxPoint
*)node
->Data();
843 node
= wx_spline_point_list
.First();
847 void wxPaintDC::DrawOpenSpline( wxList
*points
)
850 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
851 double x1
, y1
, x2
, y2
;
853 wxNode
*node
= points
->First();
854 p
= (wxPoint
*)node
->Data();
860 p
= (wxPoint
*)node
->Data();
864 cx1
= (double)((x1
+ x2
) / 2);
865 cy1
= (double)((y1
+ y2
) / 2);
866 cx2
= (double)((cx1
+ x2
) / 2);
867 cy2
= (double)((cy1
+ y2
) / 2);
869 wx_spline_add_point(x1
, y1
);
871 while ((node
= node
->Next()) != NULL
)
873 p
= (wxPoint
*)node
->Data();
878 cx4
= (double)(x1
+ x2
) / 2;
879 cy4
= (double)(y1
+ y2
) / 2;
880 cx3
= (double)(x1
+ cx4
) / 2;
881 cy3
= (double)(y1
+ cy4
) / 2;
883 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
887 cx2
= (double)(cx1
+ x2
) / 2;
888 cy2
= (double)(cy1
+ y2
) / 2;
891 wx_spline_add_point( cx1
, cy1
);
892 wx_spline_add_point( x2
, y2
);
894 wx_spline_draw_point_array( this );