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)
97 wxPaintDC::wxPaintDC( wxWindow
*window
)
106 GtkWidget
*widget
= window
->m_wxwindow
;
108 m_window
= widget
->window
;
109 if (!m_window
) return;
110 if (window
->m_wxwindow
)
111 m_cmap
= gtk_widget_get_colormap( window
->m_wxwindow
);
113 m_cmap
= gtk_widget_get_colormap( window
->m_widget
);
121 window
->GetDrawingOffset( &x
, &y
);
122 SetInternalDeviceOrigin( -x
, -y
);
125 wxPaintDC::~wxPaintDC(void)
129 void wxPaintDC::FloodFill( long WXUNUSED(x1
), long WXUNUSED(y1
),
130 wxColour
*WXUNUSED(col
), int WXUNUSED(style
) )
134 bool wxPaintDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
139 void wxPaintDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
143 if (m_pen
.GetStyle() != wxTRANSPARENT
)
145 gdk_draw_line( m_window
, m_penGC
,
146 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
150 void wxPaintDC::CrossHair( long x
, long y
)
154 if (m_pen
.GetStyle() != wxTRANSPARENT
)
159 long xx
= XLOG2DEV(x
);
160 long yy
= YLOG2DEV(y
);
161 gdk_draw_line( m_window
, m_penGC
,
162 0, yy
, XLOG2DEVREL(w
), yy
);
163 gdk_draw_line( m_window
, m_penGC
,
164 xx
, 0, xx
, YLOG2DEVREL(h
) );
168 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
172 long xx1
= XLOG2DEV(x1
);
173 long yy1
= YLOG2DEV(y1
);
174 long xx2
= XLOG2DEV(x2
);
175 long yy2
= YLOG2DEV(y2
);
176 long xxc
= XLOG2DEV((long)xc
);
177 long yyc
= YLOG2DEV((long)yc
);
178 double dx
= xx1
- xxc
;
179 double dy
= yy1
- yyc
;
180 double radius
= sqrt(dx
*dx
+dy
*dy
);
181 long r
= (long)radius
;
182 double radius1
, radius2
;
184 if (xx1
== xx2
&& yy1
== yy2
)
192 radius1
= radius2
= 0.0;
196 radius1
= (xx1
- xxc
== 0) ?
197 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
198 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
199 radius2
= (xx2
- xxc
== 0) ?
200 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
201 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
203 long alpha1
= long(radius1
* 64.0);
204 long alpha2
= long((radius2
- radius1
) * 64.0);
205 while (alpha2
<= 0) alpha2
+= 360*64;
206 while (alpha1
> 360*64) alpha1
-= 360*64;
208 if (m_brush
.GetStyle() != wxTRANSPARENT
)
209 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
211 if (m_pen
.GetStyle() != wxTRANSPARENT
)
212 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
216 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
220 long xx
= XLOG2DEV(x
);
221 long yy
= YLOG2DEV(y
);
222 long ww
= m_signX
* XLOG2DEVREL(width
);
223 long hh
= m_signY
* YLOG2DEVREL(height
);
225 // CMB: handle -ve width and/or height
226 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
227 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
229 long start
= long(sa
* 64.0);
230 long end
= long(ea
* 64.0);
231 if (m_brush
.GetStyle() != wxTRANSPARENT
)
232 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
234 if (m_pen
.GetStyle() != wxTRANSPARENT
)
235 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
238 void wxPaintDC::DrawPoint( long x
, long y
)
242 if (m_pen
.GetStyle() != wxTRANSPARENT
)
243 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
246 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
250 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
252 for (int i
= 0; i
< n
-1; i
++)
254 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
255 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
256 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
257 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
258 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
262 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
266 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
268 wxNode
*node
= points
->First();
271 wxPoint
*point
= (wxPoint
*)node
->Data();
272 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
273 long x1
= XLOG2DEV(point
->x
+ xoffset
);
274 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
275 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and again...
276 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
277 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
282 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[],
283 long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
286 if (!n
) return; // Nothing to draw
287 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
289 for (i
= 0 ; i
< n
; i
++)
291 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
292 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
294 if (m_brush
.GetStyle() != wxTRANSPARENT
)
295 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
297 if (m_pen
.GetStyle() != wxTRANSPARENT
)
298 for (i
= 0 ; i
< n
; i
++)
299 gdk_draw_line( m_window
, m_penGC
,
302 gdkpoints
[(i
+1)%n
].x
,
303 gdkpoints
[(i
+1)%n
].y
);
307 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
,
308 long yoffset
, int WXUNUSED(fillStyle
))
310 int n
= lines
->Number();
313 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
314 wxNode
*node
= lines
->First();
318 wxPoint
*p
= (wxPoint
*) node
->Data();
319 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
320 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
324 if (m_brush
.GetStyle() != wxTRANSPARENT
)
325 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
327 if (m_pen
.GetStyle() != wxTRANSPARENT
)
330 for (i
= 0 ; i
< n
; i
++)
331 gdk_draw_line( m_window
, m_penGC
,
334 gdkpoints
[(i
+1)%n
].x
,
335 gdkpoints
[(i
+1)%n
].y
);
340 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
344 long xx
= XLOG2DEV(x
);
345 long yy
= YLOG2DEV(y
);
346 long ww
= m_signX
* XLOG2DEVREL(width
);
347 long hh
= m_signY
* YLOG2DEVREL(height
);
349 // CMB: draw nothing if transformed w or h is 0
350 if (ww
== 0 || hh
== 0) return;
352 // CMB: handle -ve width and/or height
353 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
354 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
356 if (m_brush
.GetStyle() != wxTRANSPARENT
)
357 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
359 if (m_pen
.GetStyle() != wxTRANSPARENT
)
360 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
363 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
367 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
369 long xx
= XLOG2DEV(x
);
370 long yy
= YLOG2DEV(y
);
371 long ww
= m_signX
* XLOG2DEVREL(width
);
372 long hh
= m_signY
* YLOG2DEVREL(height
);
373 long rr
= XLOG2DEVREL((long)radius
);
375 // CMB: handle -ve width and/or height
376 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
377 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
379 // CMB: if radius is zero use DrawRectangle() instead to avoid
380 // X drawing errors with small radii
383 DrawRectangle( x
, y
, width
, height
);
387 // CMB: draw nothing if transformed w or h is 0
388 if (ww
== 0 || hh
== 0) return;
390 // CMB: adjust size if outline is drawn otherwise the result is
391 // 1 pixel too wide and high
392 if (m_pen
.GetStyle() != wxTRANSPARENT
)
398 // CMB: ensure dd is not larger than rectangle otherwise we
399 // get an hour glass shape
401 if (dd
> ww
) dd
= ww
;
402 if (dd
> hh
) dd
= hh
;
405 if (m_brush
.GetStyle() != wxTRANSPARENT
)
407 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
408 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
409 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
410 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
411 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
412 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
415 if (m_pen
.GetStyle() != wxTRANSPARENT
)
417 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
418 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
419 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
420 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
421 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
422 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
423 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
424 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
428 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
432 long xx
= XLOG2DEV(x
);
433 long yy
= YLOG2DEV(y
);
434 long ww
= m_signX
* XLOG2DEVREL(width
);
435 long hh
= m_signY
* YLOG2DEVREL(height
);
437 // CMB: handle -ve width and/or height
438 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
439 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
441 if (m_brush
.GetStyle() != wxTRANSPARENT
)
442 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
444 if (m_pen
.GetStyle() != wxTRANSPARENT
)
445 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
448 bool wxPaintDC::CanDrawBitmap(void) const
453 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
457 if (!icon
.Ok()) return;
459 int xx
= XLOG2DEV(x
);
460 int yy
= YLOG2DEV(y
);
462 GdkBitmap
*mask
= NULL
;
463 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
467 gdk_gc_set_clip_mask( m_penGC
, mask
);
468 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
471 GdkPixmap
*pm
= icon
.GetPixmap();
472 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
476 gdk_gc_set_clip_mask( m_penGC
, NULL
);
477 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
481 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
482 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool WXUNUSED(useMask
) )
484 if (!Ok()) return FALSE
;
486 // CMB 20/5/98: add blitting of bitmaps
487 if (source
->IsKindOf(CLASSINFO(wxMemoryDC
)))
489 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
490 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
497 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
498 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
499 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
)
505 wxClientDC
*csrc
= (wxClientDC
*)source
;
506 gdk_window_copy_area ( m_window
, m_penGC
,
507 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
509 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
510 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
) );
513 gdk_window_copy_area ( m_window, m_penGC,
514 XLOG2DEV(xdest), YLOG2DEV(ydest),
523 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool
528 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
533 // CMB 21/5/98: draw text background if mode is wxSOLID
534 if (m_backgroundMode
== wxSOLID
)
536 long width
= gdk_string_width( font
, text
);
537 long height
= font
->ascent
+ font
->descent
;
538 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
539 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
540 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
542 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
544 // CMB 17/7/98: simple underline: ignores scaling and underlying
545 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
546 // properties (see wxXt implementation)
547 if (m_font
.GetUnderlined())
549 long width
= gdk_string_width( font
, text
);
550 long ul_y
= y
+ font
->ascent
;
551 if (font
->descent
> 0) ul_y
++;
552 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
558 bool wxPaintDC::CanGetTextExtent(void) const
563 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
564 long *WXUNUSED(descent
), long *WXUNUSED(externalLeading
),
565 wxFont
*WXUNUSED(theFont
), bool WXUNUSED(use16
) )
569 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
570 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
571 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
574 long wxPaintDC::GetCharWidth(void)
578 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
579 return gdk_string_width( font
, "H" );
582 long wxPaintDC::GetCharHeight(void)
586 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
587 return font
->ascent
+ font
->descent
;
590 void wxPaintDC::Clear(void)
594 // DestroyClippingRegion();
598 gdk_window_clear( m_window
);
604 GetSize( &width
, &height
);
605 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
609 void wxPaintDC::SetFont( const wxFont
&font
)
616 void wxPaintDC::SetPen( const wxPen
&pen
)
620 if (m_pen
== pen
) return;
624 if (!m_pen
.Ok()) return;
626 gint width
= m_pen
.GetWidth();
627 // CMB: if width is non-zero scale it with the dc
634 // X doesn't allow different width in x and y and so we take
636 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
640 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
641 switch (m_pen
.GetStyle())
643 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; };
644 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
645 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
646 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; };
647 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; };
650 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
651 switch (m_pen
.GetCap())
653 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; };
654 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; };
655 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; };
658 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
659 switch (m_pen
.GetJoin())
661 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; };
662 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; };
663 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; };
666 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
668 m_pen
.GetColour().CalcPixel( m_cmap
);
669 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
672 void wxPaintDC::SetBrush( const wxBrush
&brush
)
676 if (m_brush
== brush
) return;
680 if (!m_brush
.Ok()) return;
682 m_brush
.GetColour().CalcPixel( m_cmap
);
683 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
685 GdkFill fillStyle
= GDK_SOLID
;
686 switch (m_brush
.GetStyle())
692 fillStyle
= GDK_STIPPLED
;
695 gdk_gc_set_fill( m_brushGC
, fillStyle
);
697 if (m_brush
.GetStyle() == wxSTIPPLE
)
699 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
702 if (IS_HATCH(m_brush
.GetStyle()))
704 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
705 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
709 // CMB 21/7/98: Added SetBackground. Sets background brush
710 // for Clear() and bg colour for shapes filled with cross-hatch brush
711 void wxPaintDC::SetBackground( const wxBrush
&brush
)
715 if (m_backgroundBrush
== brush
) return;
717 m_backgroundBrush
= brush
;
719 if (!m_backgroundBrush
.Ok()) return;
721 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
722 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
723 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
725 GdkFill fillStyle
= GDK_SOLID
;
726 switch (m_backgroundBrush
.GetStyle())
732 fillStyle
= GDK_STIPPLED
;
735 gdk_gc_set_fill( m_bgGC
, fillStyle
);
737 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
739 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
742 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
744 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
745 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
749 void wxPaintDC::SetLogicalFunction( int function
)
751 if (m_logicalFunction
== function
) return;
752 GdkFunction mode
= GDK_COPY
;
755 case wxXOR
: mode
= GDK_INVERT
; break;
756 case wxINVERT
: mode
= GDK_INVERT
; break;
759 m_logicalFunction
= function
;
760 gdk_gc_set_function( m_penGC
, mode
);
761 gdk_gc_set_function( m_brushGC
, mode
);
764 void wxPaintDC::SetTextForeground( const wxColour
&col
)
768 if (m_textForegroundColour
== col
) return;
770 m_textForegroundColour
= col
;
771 if (!m_textForegroundColour
.Ok()) return;
773 m_textForegroundColour
.CalcPixel( m_cmap
);
774 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
777 void wxPaintDC::SetTextBackground( const wxColour
&col
)
781 if (m_textBackgroundColour
== col
) return;
783 m_textBackgroundColour
= col
;
784 if (!m_textBackgroundColour
.Ok()) return;
786 m_textBackgroundColour
.CalcPixel( m_cmap
);
787 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
790 void wxPaintDC::SetBackgroundMode( int mode
)
792 m_backgroundMode
= mode
;
794 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
795 // transparent/solid background mode
796 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
798 gdk_gc_set_fill( m_brushGC
,
799 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
803 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
807 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
809 wxDC::SetClippingRegion( x
, y
, width
, height
);
812 rect
.x
= XLOG2DEV(x
);
813 rect
.y
= YLOG2DEV(y
);
814 rect
.width
= XLOG2DEV(x
+width
);
815 rect
.height
= YLOG2DEV(y
+height
);
816 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
817 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
818 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
819 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
823 void wxPaintDC::DestroyClippingRegion(void)
825 wxDC::DestroyClippingRegion();
827 gdk_gc_set_clip_rectangle( m_penGC
, NULL
);
828 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
829 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
830 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
833 void wxPaintDC::SetUpDC(void)
836 m_logicalFunction
= wxCOPY
;
837 if (m_penGC
) gdk_gc_unref( m_penGC
);
838 m_penGC
= gdk_gc_new( m_window
);
839 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
840 m_brushGC
= gdk_gc_new( m_window
);
841 if (m_textGC
) gdk_gc_unref( m_textGC
);
842 m_textGC
= gdk_gc_new( m_window
);
843 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
844 m_bgGC
= gdk_gc_new( m_window
);
845 SetTextForeground( m_textForegroundColour
);
846 SetTextBackground( m_textBackgroundColour
);
851 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
855 hatch_bitmap
= hatches
;
856 hatch_bitmap
[0] = gdk_bitmap_create_from_data( NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
857 hatch_bitmap
[1] = gdk_bitmap_create_from_data( NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
858 hatch_bitmap
[2] = gdk_bitmap_create_from_data( NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
859 hatch_bitmap
[3] = gdk_bitmap_create_from_data( NULL
, cross_bits
, cross_width
, cross_height
);
860 hatch_bitmap
[4] = gdk_bitmap_create_from_data( NULL
, horiz_bits
, horiz_width
, horiz_height
);
861 hatch_bitmap
[5] = gdk_bitmap_create_from_data( NULL
, verti_bits
, verti_width
, verti_height
);
865 GdkWindow
*wxPaintDC::GetWindow(void)
870 // ----------------------------------- spline code ----------------------------------------
872 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
873 double a3
, double b3
, double a4
, double b4
);
874 void wx_clear_stack(void);
875 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
876 double *y3
, double *x4
, double *y4
);
877 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
878 double x4
, double y4
);
879 static bool wx_spline_add_point(double x
, double y
);
880 static void wx_spline_draw_point_array(wxDC
*dc
);
882 wxList wx_spline_point_list
;
884 #define half(z1, z2) ((z1+z2)/2.0)
887 /* iterative version */
889 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
892 register double xmid
, ymid
;
893 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
896 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
898 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
899 xmid
= (double)half(x2
, x3
);
900 ymid
= (double)half(y2
, y3
);
901 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
902 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
903 wx_spline_add_point( x1
, y1
);
904 wx_spline_add_point( xmid
, ymid
);
906 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
907 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
908 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
909 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
914 /* utilities used by spline drawing routines */
916 typedef struct wx_spline_stack_struct
{
917 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
920 #define SPLINE_STACK_DEPTH 20
921 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
922 static Stack
*wx_stack_top
;
923 static int wx_stack_count
;
925 void wx_clear_stack(void)
927 wx_stack_top
= wx_spline_stack
;
931 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
933 wx_stack_top
->x1
= x1
;
934 wx_stack_top
->y1
= y1
;
935 wx_stack_top
->x2
= x2
;
936 wx_stack_top
->y2
= y2
;
937 wx_stack_top
->x3
= x3
;
938 wx_stack_top
->y3
= y3
;
939 wx_stack_top
->x4
= x4
;
940 wx_stack_top
->y4
= y4
;
945 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
946 double *x3
, double *y3
, double *x4
, double *y4
)
948 if (wx_stack_count
== 0)
952 *x1
= wx_stack_top
->x1
;
953 *y1
= wx_stack_top
->y1
;
954 *x2
= wx_stack_top
->x2
;
955 *y2
= wx_stack_top
->y2
;
956 *x3
= wx_stack_top
->x3
;
957 *y3
= wx_stack_top
->y3
;
958 *x4
= wx_stack_top
->x4
;
959 *y4
= wx_stack_top
->y4
;
963 static bool wx_spline_add_point(double x
, double y
)
965 wxPoint
*point
= new wxPoint
;
968 wx_spline_point_list
.Append((wxObject
*)point
);
972 static void wx_spline_draw_point_array(wxDC
*dc
)
974 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
975 wxNode
*node
= wx_spline_point_list
.First();
978 wxPoint
*point
= (wxPoint
*)node
->Data();
981 node
= wx_spline_point_list
.First();
985 void wxPaintDC::DrawOpenSpline( wxList
*points
)
988 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
989 double x1
, y1
, x2
, y2
;
991 wxNode
*node
= points
->First();
992 p
= (wxPoint
*)node
->Data();
998 p
= (wxPoint
*)node
->Data();
1002 cx1
= (double)((x1
+ x2
) / 2);
1003 cy1
= (double)((y1
+ y2
) / 2);
1004 cx2
= (double)((cx1
+ x2
) / 2);
1005 cy2
= (double)((cy1
+ y2
) / 2);
1007 wx_spline_add_point(x1
, y1
);
1009 while ((node
= node
->Next()) != NULL
)
1011 p
= (wxPoint
*)node
->Data();
1016 cx4
= (double)(x1
+ x2
) / 2;
1017 cy4
= (double)(y1
+ y2
) / 2;
1018 cx3
= (double)(x1
+ cx4
) / 2;
1019 cy3
= (double)(y1
+ cy4
) / 2;
1021 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1025 cx2
= (double)(cx1
+ x2
) / 2;
1026 cy2
= (double)(cy1
+ y2
) / 2;
1029 wx_spline_add_point( cx1
, cy1
);
1030 wx_spline_add_point( x2
, y2
);
1032 wx_spline_draw_point_array( this );