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
);
110 window
->GetDrawingOffset( &x
, &y
);
111 SetInternalDeviceOrigin( -x
, -y
);
114 wxPaintDC::~wxPaintDC(void)
118 void wxPaintDC::FloodFill( long WXUNUSED(x1
), long WXUNUSED(y1
),
119 wxColour
*WXUNUSED(col
), int WXUNUSED(style
) )
123 bool wxPaintDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
128 void wxPaintDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
132 if (m_pen
.GetStyle() != wxTRANSPARENT
)
134 gdk_draw_line( m_window
, m_penGC
,
135 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
139 void wxPaintDC::CrossHair( long x
, long y
)
143 if (m_pen
.GetStyle() != wxTRANSPARENT
)
148 long xx
= XLOG2DEV(x
);
149 long yy
= YLOG2DEV(y
);
150 gdk_draw_line( m_window
, m_penGC
,
151 0, yy
, XLOG2DEVREL(w
), yy
);
152 gdk_draw_line( m_window
, m_penGC
,
153 xx
, 0, xx
, YLOG2DEVREL(h
) );
157 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
161 long xx1
= XLOG2DEV(x1
);
162 long yy1
= YLOG2DEV(y1
);
163 long xx2
= XLOG2DEV(x2
);
164 long yy2
= YLOG2DEV(y2
);
165 long xxc
= XLOG2DEV((long)xc
);
166 long yyc
= YLOG2DEV((long)yc
);
167 double dx
= xx1
- xxc
;
168 double dy
= yy1
- yyc
;
169 double radius
= sqrt(dx
*dx
+dy
*dy
);
170 long r
= (long)radius
;
171 double radius1
, radius2
;
173 if (xx1
== xx2
&& yy1
== yy2
)
181 radius1
= radius2
= 0.0;
185 radius1
= (xx1
- xxc
== 0) ?
186 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
187 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
188 radius2
= (xx2
- xxc
== 0) ?
189 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
190 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
192 long alpha1
= long(radius1
* 64.0);
193 long alpha2
= long((radius2
- radius1
) * 64.0);
194 while (alpha2
<= 0) alpha2
+= 360*64;
195 while (alpha1
> 360*64) alpha1
-= 360*64;
197 if (m_brush
.GetStyle() != wxTRANSPARENT
)
198 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
200 if (m_pen
.GetStyle() != wxTRANSPARENT
)
201 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
205 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
209 long xx
= XLOG2DEV(x
);
210 long yy
= YLOG2DEV(y
);
211 long ww
= m_signX
* XLOG2DEVREL(width
);
212 long hh
= m_signY
* YLOG2DEVREL(height
);
214 // CMB: handle -ve width and/or height
215 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
216 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
218 long start
= long(sa
* 64.0);
219 long end
= long(ea
* 64.0);
220 if (m_brush
.GetStyle() != wxTRANSPARENT
)
221 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
223 if (m_pen
.GetStyle() != wxTRANSPARENT
)
224 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
227 void wxPaintDC::DrawPoint( long x
, long y
)
231 if (m_pen
.GetStyle() != wxTRANSPARENT
)
232 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
235 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
239 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
241 for (int i
= 0; i
< n
-1; i
++)
243 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
244 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
245 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
246 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
247 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
251 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
255 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
257 wxNode
*node
= points
->First();
260 wxPoint
*point
= (wxPoint
*)node
->Data();
261 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
262 long x1
= XLOG2DEV(point
->x
+ xoffset
);
263 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
264 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and again...
265 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
266 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
271 void wxPaintDC::DrawPolygon( int WXUNUSED(n
), wxPoint
WXUNUSED(points
)[],
272 long WXUNUSED(xoffset
), long WXUNUSED(yoffset
), int WXUNUSED(fillStyle
) )
277 void wxPaintDC::DrawPolygon( wxList
*WXUNUSED(lines
), long WXUNUSED(xoffset
),
278 long WXUNUSED(yoffset
), int WXUNUSED(fillStyle
) )
283 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
287 long xx
= XLOG2DEV(x
);
288 long yy
= YLOG2DEV(y
);
289 long ww
= m_signX
* XLOG2DEVREL(width
);
290 long hh
= m_signY
* YLOG2DEVREL(height
);
292 // CMB: draw nothing if transformed w or h is 0
293 if (ww
== 0 || hh
== 0) return;
295 // CMB: handle -ve width and/or height
296 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
297 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
299 if (m_brush
.GetStyle() != wxTRANSPARENT
)
300 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
302 if (m_pen
.GetStyle() != wxTRANSPARENT
)
303 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
306 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
310 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
312 long xx
= XLOG2DEV(x
);
313 long yy
= YLOG2DEV(y
);
314 long ww
= m_signX
* XLOG2DEVREL(width
);
315 long hh
= m_signY
* YLOG2DEVREL(height
);
316 long rr
= XLOG2DEVREL((long)radius
);
318 // CMB: handle -ve width and/or height
319 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
320 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
322 // CMB: if radius is zero use DrawRectangle() instead to avoid
323 // X drawing errors with small radii
326 DrawRectangle( x
, y
, width
, height
);
330 // CMB: draw nothing if transformed w or h is 0
331 if (ww
== 0 || hh
== 0) return;
333 // CMB: adjust size if outline is drawn otherwise the result is
334 // 1 pixel too wide and high
335 if (m_pen
.GetStyle() != wxTRANSPARENT
)
341 // CMB: ensure dd is not larger than rectangle otherwise we
342 // get an hour glass shape
344 if (dd
> ww
) dd
= ww
;
345 if (dd
> hh
) dd
= hh
;
348 if (m_brush
.GetStyle() != wxTRANSPARENT
)
350 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
351 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
352 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
353 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
354 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
355 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
358 if (m_pen
.GetStyle() != wxTRANSPARENT
)
360 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
361 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
362 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
363 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
364 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
365 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
366 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
367 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
371 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
375 long xx
= XLOG2DEV(x
);
376 long yy
= YLOG2DEV(y
);
377 long ww
= m_signX
* XLOG2DEVREL(width
);
378 long hh
= m_signY
* YLOG2DEVREL(height
);
380 // CMB: handle -ve width and/or height
381 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
382 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
384 if (m_brush
.GetStyle() != wxTRANSPARENT
)
385 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
387 if (m_pen
.GetStyle() != wxTRANSPARENT
)
388 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
391 bool wxPaintDC::CanDrawBitmap(void) const
396 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
400 if (!icon
.Ok()) return;
402 int xx
= XLOG2DEV(x
);
403 int yy
= YLOG2DEV(y
);
405 GdkBitmap
*mask
= NULL
;
406 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
410 gdk_gc_set_clip_mask( m_penGC
, mask
);
411 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
414 GdkPixmap
*pm
= icon
.GetPixmap();
415 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
419 gdk_gc_set_clip_mask( m_penGC
, NULL
);
420 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
424 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
425 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool WXUNUSED(useMask
) )
427 if (!Ok()) return FALSE
;
429 // CMB 20/5/98: add blitting of bitmaps
430 if (source
->IsKindOf(CLASSINFO(wxMemoryDC
)))
432 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
433 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
440 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
441 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
442 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
)
448 wxClientDC
*csrc
= (wxClientDC
*)source
;
449 gdk_window_copy_area ( m_window
, m_penGC
,
450 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
452 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
453 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
) );
456 gdk_window_copy_area ( m_window, m_penGC,
457 XLOG2DEV(xdest), YLOG2DEV(ydest),
466 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
470 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
472 // CMB 21/5/98: draw text background if mode is wxSOLID
473 if (m_backgroundMode
== wxSOLID
)
475 long width
= gdk_string_width( font
, text
);
476 long height
= font
->ascent
+ font
->descent
;
477 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
478 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
479 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
481 gdk_draw_string( m_window
, font
, m_textGC
,
483 YLOG2DEV(y
) + font
->ascent
, text
);
486 bool wxPaintDC::CanGetTextExtent(void) const
491 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
492 long *WXUNUSED(descent
), long *WXUNUSED(externalLeading
),
493 wxFont
*WXUNUSED(theFont
), bool WXUNUSED(use16
) )
497 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
498 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
499 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
502 long wxPaintDC::GetCharWidth(void)
506 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
507 return gdk_string_width( font
, "H" );
510 long wxPaintDC::GetCharHeight(void)
514 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
515 return font
->ascent
+ font
->descent
;
518 void wxPaintDC::Clear(void)
522 DestroyClippingRegion();
526 gdk_window_clear( m_window
);
532 GetSize( &width
, &height
);
533 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, 0, 0, width
, height
);
537 void wxPaintDC::SetFont( const wxFont
&font
)
544 void wxPaintDC::SetPen( const wxPen
&pen
)
548 if (m_pen
== pen
) return;
552 if (!m_pen
.Ok()) return;
554 gint width
= m_pen
.GetWidth();
555 // CMB: if width is non-zero scale it with the dc
562 // X doesn't allow different width in x and y and so we take
564 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
568 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
569 switch (m_pen
.GetStyle())
571 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; };
572 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
573 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
574 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
575 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; };
578 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
579 switch (m_pen
.GetCap())
581 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; };
582 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; };
583 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; };
586 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
587 switch (m_pen
.GetJoin())
589 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; };
590 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; };
591 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; };
594 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
596 m_pen
.GetColour().CalcPixel( m_cmap
);
597 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
600 void wxPaintDC::SetBrush( const wxBrush
&brush
)
604 if (m_brush
== brush
) return;
608 if (!m_brush
.Ok()) return;
610 m_brush
.GetColour().CalcPixel( m_cmap
);
611 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
613 GdkFill fillStyle
= GDK_SOLID
;
614 switch (m_brush
.GetStyle())
620 fillStyle
= GDK_STIPPLED
;
623 gdk_gc_set_fill( m_brushGC
, fillStyle
);
625 if (m_brush
.GetStyle() == wxSTIPPLE
)
627 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
630 if (IS_HATCH(m_brush
.GetStyle()))
632 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
633 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
637 void wxPaintDC::SetLogicalFunction( int function
)
639 if (m_logicalFunction
== function
) return;
640 GdkFunction mode
= GDK_COPY
;
643 case wxXOR
: mode
= GDK_INVERT
; break;
644 case wxINVERT
: mode
= GDK_INVERT
; break;
647 m_logicalFunction
= function
;
648 gdk_gc_set_function( m_penGC
, mode
);
649 gdk_gc_set_function( m_brushGC
, mode
);
652 void wxPaintDC::SetTextForeground( const wxColour
&col
)
656 if (m_textForegroundColour
== col
) return;
658 m_textForegroundColour
= col
;
659 if (!m_textForegroundColour
.Ok()) return;
661 m_textForegroundColour
.CalcPixel( m_cmap
);
662 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
665 void wxPaintDC::SetTextBackground( const wxColour
&col
)
669 if (m_textBackgroundColour
== col
) return;
671 m_textBackgroundColour
= col
;
672 if (!m_textBackgroundColour
.Ok()) return;
674 m_textBackgroundColour
.CalcPixel( m_cmap
);
675 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
678 void wxPaintDC::SetBackgroundMode( int mode
)
680 m_backgroundMode
= mode
;
683 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
687 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
689 wxDC::SetClippingRegion( x
, y
, width
, height
);
692 rect
.x
= XLOG2DEV(x
);
693 rect
.y
= YLOG2DEV(y
);
694 rect
.width
= XLOG2DEV(x
+width
);
695 rect
.height
= YLOG2DEV(y
+height
);
696 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
697 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
698 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
699 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
703 void wxPaintDC::DestroyClippingRegion(void)
705 wxDC::DestroyClippingRegion();
707 gdk_gc_set_clip_rectangle( m_penGC
, NULL
);
708 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
709 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
710 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
713 void wxPaintDC::SetUpDC(void)
716 m_logicalFunction
= wxCOPY
;
717 m_penGC
= gdk_gc_new( m_window
);
718 m_brushGC
= gdk_gc_new( m_window
);
719 m_textGC
= gdk_gc_new( m_window
);
720 m_bgGC
= gdk_gc_new( m_window
);
721 SetTextForeground( m_textForegroundColour
);
722 SetTextBackground( m_textBackgroundColour
);
727 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
731 hatch_bitmap
= hatches
;
732 hatch_bitmap
[0] = gdk_bitmap_create_from_data( NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
733 hatch_bitmap
[1] = gdk_bitmap_create_from_data( NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
734 hatch_bitmap
[2] = gdk_bitmap_create_from_data( NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
735 hatch_bitmap
[3] = gdk_bitmap_create_from_data( NULL
, cross_bits
, cross_width
, cross_height
);
736 hatch_bitmap
[4] = gdk_bitmap_create_from_data( NULL
, horiz_bits
, horiz_width
, horiz_height
);
737 hatch_bitmap
[5] = gdk_bitmap_create_from_data( NULL
, verti_bits
, verti_width
, verti_height
);
741 GdkWindow
*wxPaintDC::GetWindow(void)
746 // ----------------------------------- spline code ----------------------------------------
748 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
749 double a3
, double b3
, double a4
, double b4
);
750 void wx_clear_stack(void);
751 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
752 double *y3
, double *x4
, double *y4
);
753 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
754 double x4
, double y4
);
755 static bool wx_spline_add_point(double x
, double y
);
756 static void wx_spline_draw_point_array(wxDC
*dc
);
758 wxList wx_spline_point_list
;
760 #define half(z1, z2) ((z1+z2)/2.0)
763 /* iterative version */
765 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
768 register double xmid
, ymid
;
769 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
772 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
774 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
775 xmid
= (double)half(x2
, x3
);
776 ymid
= (double)half(y2
, y3
);
777 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
778 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
779 wx_spline_add_point( x1
, y1
);
780 wx_spline_add_point( xmid
, ymid
);
782 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
783 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
784 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
785 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
790 /* utilities used by spline drawing routines */
792 typedef struct wx_spline_stack_struct
{
793 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
796 #define SPLINE_STACK_DEPTH 20
797 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
798 static Stack
*wx_stack_top
;
799 static int wx_stack_count
;
801 void wx_clear_stack(void)
803 wx_stack_top
= wx_spline_stack
;
807 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
809 wx_stack_top
->x1
= x1
;
810 wx_stack_top
->y1
= y1
;
811 wx_stack_top
->x2
= x2
;
812 wx_stack_top
->y2
= y2
;
813 wx_stack_top
->x3
= x3
;
814 wx_stack_top
->y3
= y3
;
815 wx_stack_top
->x4
= x4
;
816 wx_stack_top
->y4
= y4
;
821 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
822 double *x3
, double *y3
, double *x4
, double *y4
)
824 if (wx_stack_count
== 0)
828 *x1
= wx_stack_top
->x1
;
829 *y1
= wx_stack_top
->y1
;
830 *x2
= wx_stack_top
->x2
;
831 *y2
= wx_stack_top
->y2
;
832 *x3
= wx_stack_top
->x3
;
833 *y3
= wx_stack_top
->y3
;
834 *x4
= wx_stack_top
->x4
;
835 *y4
= wx_stack_top
->y4
;
839 static bool wx_spline_add_point(double x
, double y
)
841 wxPoint
*point
= new wxPoint
;
844 wx_spline_point_list
.Append((wxObject
*)point
);
848 static void wx_spline_draw_point_array(wxDC
*dc
)
850 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
851 wxNode
*node
= wx_spline_point_list
.First();
854 wxPoint
*point
= (wxPoint
*)node
->Data();
857 node
= wx_spline_point_list
.First();
861 void wxPaintDC::DrawOpenSpline( wxList
*points
)
864 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
865 double x1
, y1
, x2
, y2
;
867 wxNode
*node
= points
->First();
868 p
= (wxPoint
*)node
->Data();
874 p
= (wxPoint
*)node
->Data();
878 cx1
= (double)((x1
+ x2
) / 2);
879 cy1
= (double)((y1
+ y2
) / 2);
880 cx2
= (double)((cx1
+ x2
) / 2);
881 cy2
= (double)((cy1
+ y2
) / 2);
883 wx_spline_add_point(x1
, y1
);
885 while ((node
= node
->Next()) != NULL
)
887 p
= (wxPoint
*)node
->Data();
892 cx4
= (double)(x1
+ x2
) / 2;
893 cy4
= (double)(y1
+ y2
) / 2;
894 cx3
= (double)(x1
+ cx4
) / 2;
895 cy3
= (double)(y1
+ cy4
) / 2;
897 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
901 cx2
= (double)(cx1
+ x2
) / 2;
902 cy2
= (double)(cy1
+ y2
) / 2;
905 wx_spline_add_point( cx1
, cy1
);
906 wx_spline_add_point( x2
, y2
);
908 wx_spline_draw_point_array( this );