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
471 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
476 // CMB 21/5/98: draw text background if mode is wxSOLID
477 if (m_backgroundMode
== wxSOLID
)
479 long width
= gdk_string_width( font
, text
);
480 long height
= font
->ascent
+ font
->descent
;
481 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
482 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
483 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
485 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
487 // CMB 17/7/98: simple underline: ignores scaling and underlying
488 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
489 // properties (see wxXt implementation)
490 if (m_font
.GetUnderlined())
492 long width
= gdk_string_width( font
, text
);
493 long ul_y
= y
+ font
->ascent
;
494 if (font
->descent
> 0) ul_y
++;
495 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
501 bool wxPaintDC::CanGetTextExtent(void) const
506 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
507 long *WXUNUSED(descent
), long *WXUNUSED(externalLeading
),
508 wxFont
*WXUNUSED(theFont
), bool WXUNUSED(use16
) )
512 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
513 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
514 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
517 long wxPaintDC::GetCharWidth(void)
521 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
522 return gdk_string_width( font
, "H" );
525 long wxPaintDC::GetCharHeight(void)
529 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
530 return font
->ascent
+ font
->descent
;
533 void wxPaintDC::Clear(void)
537 DestroyClippingRegion();
541 gdk_window_clear( m_window
);
547 GetSize( &width
, &height
);
548 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, 0, 0, width
, height
);
552 void wxPaintDC::SetFont( const wxFont
&font
)
559 void wxPaintDC::SetPen( const wxPen
&pen
)
563 if (m_pen
== pen
) return;
567 if (!m_pen
.Ok()) return;
569 gint width
= m_pen
.GetWidth();
570 // CMB: if width is non-zero scale it with the dc
577 // X doesn't allow different width in x and y and so we take
579 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
583 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
584 switch (m_pen
.GetStyle())
586 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; };
587 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
588 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
589 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
590 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; };
593 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
594 switch (m_pen
.GetCap())
596 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; };
597 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; };
598 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; };
601 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
602 switch (m_pen
.GetJoin())
604 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; };
605 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; };
606 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; };
609 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
611 m_pen
.GetColour().CalcPixel( m_cmap
);
612 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
615 void wxPaintDC::SetBrush( const wxBrush
&brush
)
619 if (m_brush
== brush
) return;
623 if (!m_brush
.Ok()) return;
625 m_brush
.GetColour().CalcPixel( m_cmap
);
626 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
628 GdkFill fillStyle
= GDK_SOLID
;
629 switch (m_brush
.GetStyle())
635 fillStyle
= GDK_STIPPLED
;
638 gdk_gc_set_fill( m_brushGC
, fillStyle
);
640 if (m_brush
.GetStyle() == wxSTIPPLE
)
642 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
645 if (IS_HATCH(m_brush
.GetStyle()))
647 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
648 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
652 void wxPaintDC::SetLogicalFunction( int function
)
654 if (m_logicalFunction
== function
) return;
655 GdkFunction mode
= GDK_COPY
;
658 case wxXOR
: mode
= GDK_INVERT
; break;
659 case wxINVERT
: mode
= GDK_INVERT
; break;
662 m_logicalFunction
= function
;
663 gdk_gc_set_function( m_penGC
, mode
);
664 gdk_gc_set_function( m_brushGC
, mode
);
667 void wxPaintDC::SetTextForeground( const wxColour
&col
)
671 if (m_textForegroundColour
== col
) return;
673 m_textForegroundColour
= col
;
674 if (!m_textForegroundColour
.Ok()) return;
676 m_textForegroundColour
.CalcPixel( m_cmap
);
677 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
680 void wxPaintDC::SetTextBackground( const wxColour
&col
)
684 if (m_textBackgroundColour
== col
) return;
686 m_textBackgroundColour
= col
;
687 if (!m_textBackgroundColour
.Ok()) return;
689 m_textBackgroundColour
.CalcPixel( m_cmap
);
690 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
693 void wxPaintDC::SetBackgroundMode( int mode
)
695 m_backgroundMode
= mode
;
698 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
702 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
704 wxDC::SetClippingRegion( x
, y
, width
, height
);
707 rect
.x
= XLOG2DEV(x
);
708 rect
.y
= YLOG2DEV(y
);
709 rect
.width
= XLOG2DEV(x
+width
);
710 rect
.height
= YLOG2DEV(y
+height
);
711 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
712 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
713 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
714 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
718 void wxPaintDC::DestroyClippingRegion(void)
720 wxDC::DestroyClippingRegion();
722 gdk_gc_set_clip_rectangle( m_penGC
, NULL
);
723 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
724 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
725 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
728 void wxPaintDC::SetUpDC(void)
731 m_logicalFunction
= wxCOPY
;
732 m_penGC
= gdk_gc_new( m_window
);
733 m_brushGC
= gdk_gc_new( m_window
);
734 m_textGC
= gdk_gc_new( m_window
);
735 m_bgGC
= gdk_gc_new( m_window
);
736 SetTextForeground( m_textForegroundColour
);
737 SetTextBackground( m_textBackgroundColour
);
742 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
746 hatch_bitmap
= hatches
;
747 hatch_bitmap
[0] = gdk_bitmap_create_from_data( NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
748 hatch_bitmap
[1] = gdk_bitmap_create_from_data( NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
749 hatch_bitmap
[2] = gdk_bitmap_create_from_data( NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
750 hatch_bitmap
[3] = gdk_bitmap_create_from_data( NULL
, cross_bits
, cross_width
, cross_height
);
751 hatch_bitmap
[4] = gdk_bitmap_create_from_data( NULL
, horiz_bits
, horiz_width
, horiz_height
);
752 hatch_bitmap
[5] = gdk_bitmap_create_from_data( NULL
, verti_bits
, verti_width
, verti_height
);
756 GdkWindow
*wxPaintDC::GetWindow(void)
761 // ----------------------------------- spline code ----------------------------------------
763 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
764 double a3
, double b3
, double a4
, double b4
);
765 void wx_clear_stack(void);
766 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
767 double *y3
, double *x4
, double *y4
);
768 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
769 double x4
, double y4
);
770 static bool wx_spline_add_point(double x
, double y
);
771 static void wx_spline_draw_point_array(wxDC
*dc
);
773 wxList wx_spline_point_list
;
775 #define half(z1, z2) ((z1+z2)/2.0)
778 /* iterative version */
780 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
783 register double xmid
, ymid
;
784 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
787 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
789 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
790 xmid
= (double)half(x2
, x3
);
791 ymid
= (double)half(y2
, y3
);
792 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
793 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
794 wx_spline_add_point( x1
, y1
);
795 wx_spline_add_point( xmid
, ymid
);
797 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
798 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
799 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
800 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
805 /* utilities used by spline drawing routines */
807 typedef struct wx_spline_stack_struct
{
808 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
811 #define SPLINE_STACK_DEPTH 20
812 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
813 static Stack
*wx_stack_top
;
814 static int wx_stack_count
;
816 void wx_clear_stack(void)
818 wx_stack_top
= wx_spline_stack
;
822 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
824 wx_stack_top
->x1
= x1
;
825 wx_stack_top
->y1
= y1
;
826 wx_stack_top
->x2
= x2
;
827 wx_stack_top
->y2
= y2
;
828 wx_stack_top
->x3
= x3
;
829 wx_stack_top
->y3
= y3
;
830 wx_stack_top
->x4
= x4
;
831 wx_stack_top
->y4
= y4
;
836 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
837 double *x3
, double *y3
, double *x4
, double *y4
)
839 if (wx_stack_count
== 0)
843 *x1
= wx_stack_top
->x1
;
844 *y1
= wx_stack_top
->y1
;
845 *x2
= wx_stack_top
->x2
;
846 *y2
= wx_stack_top
->y2
;
847 *x3
= wx_stack_top
->x3
;
848 *y3
= wx_stack_top
->y3
;
849 *x4
= wx_stack_top
->x4
;
850 *y4
= wx_stack_top
->y4
;
854 static bool wx_spline_add_point(double x
, double y
)
856 wxPoint
*point
= new wxPoint
;
859 wx_spline_point_list
.Append((wxObject
*)point
);
863 static void wx_spline_draw_point_array(wxDC
*dc
)
865 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
866 wxNode
*node
= wx_spline_point_list
.First();
869 wxPoint
*point
= (wxPoint
*)node
->Data();
872 node
= wx_spline_point_list
.First();
876 void wxPaintDC::DrawOpenSpline( wxList
*points
)
879 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
880 double x1
, y1
, x2
, y2
;
882 wxNode
*node
= points
->First();
883 p
= (wxPoint
*)node
->Data();
889 p
= (wxPoint
*)node
->Data();
893 cx1
= (double)((x1
+ x2
) / 2);
894 cy1
= (double)((y1
+ y2
) / 2);
895 cx2
= (double)((cx1
+ x2
) / 2);
896 cy2
= (double)((cy1
+ y2
) / 2);
898 wx_spline_add_point(x1
, y1
);
900 while ((node
= node
->Next()) != NULL
)
902 p
= (wxPoint
*)node
->Data();
907 cx4
= (double)(x1
+ x2
) / 2;
908 cy4
= (double)(y1
+ y2
) / 2;
909 cx3
= (double)(x1
+ cx4
) / 2;
910 cy3
= (double)(y1
+ cy4
) / 2;
912 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
916 cx2
= (double)(cx1
+ x2
) / 2;
917 cy2
= (double)(cy1
+ y2
) / 2;
920 wx_spline_add_point( cx1
, cy1
);
921 wx_spline_add_point( x2
, y2
);
923 wx_spline_draw_point_array( this );