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
);
120 wxPaintDC::~wxPaintDC(void)
124 void wxPaintDC::FloodFill( long WXUNUSED(x1
), long WXUNUSED(y1
),
125 wxColour
*WXUNUSED(col
), int WXUNUSED(style
) )
129 bool wxPaintDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
134 void wxPaintDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
138 if (m_pen
.GetStyle() != wxTRANSPARENT
)
140 gdk_draw_line( m_window
, m_penGC
,
141 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
145 void wxPaintDC::CrossHair( long x
, long y
)
149 if (m_pen
.GetStyle() != wxTRANSPARENT
)
154 long xx
= XLOG2DEV(x
);
155 long yy
= YLOG2DEV(y
);
156 gdk_draw_line( m_window
, m_penGC
,
157 0, yy
, XLOG2DEVREL(w
), yy
);
158 gdk_draw_line( m_window
, m_penGC
,
159 xx
, 0, xx
, YLOG2DEVREL(h
) );
163 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
167 long xx1
= XLOG2DEV(x1
);
168 long yy1
= YLOG2DEV(y1
);
169 long xx2
= XLOG2DEV(x2
);
170 long yy2
= YLOG2DEV(y2
);
171 long xxc
= XLOG2DEV((long)xc
);
172 long yyc
= YLOG2DEV((long)yc
);
173 double dx
= xx1
- xxc
;
174 double dy
= yy1
- yyc
;
175 double radius
= sqrt(dx
*dx
+dy
*dy
);
176 long r
= (long)radius
;
177 double radius1
, radius2
;
179 if (xx1
== xx2
&& yy1
== yy2
)
187 radius1
= radius2
= 0.0;
191 radius1
= (xx1
- xxc
== 0) ?
192 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
193 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
194 radius2
= (xx2
- xxc
== 0) ?
195 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
196 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
198 long alpha1
= long(radius1
* 64.0);
199 long alpha2
= long((radius2
- radius1
) * 64.0);
200 while (alpha2
<= 0) alpha2
+= 360*64;
201 while (alpha1
> 360*64) alpha1
-= 360*64;
203 if (m_brush
.GetStyle() != wxTRANSPARENT
)
204 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
206 if (m_pen
.GetStyle() != wxTRANSPARENT
)
207 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
211 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
215 long xx
= XLOG2DEV(x
);
216 long yy
= YLOG2DEV(y
);
217 long ww
= m_signX
* XLOG2DEVREL(width
);
218 long hh
= m_signY
* YLOG2DEVREL(height
);
220 // CMB: handle -ve width and/or height
221 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
222 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
224 long start
= long(sa
* 64.0);
225 long end
= long(ea
* 64.0);
226 if (m_brush
.GetStyle() != wxTRANSPARENT
)
227 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
229 if (m_pen
.GetStyle() != wxTRANSPARENT
)
230 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
233 void wxPaintDC::DrawPoint( long x
, long y
)
237 if (m_pen
.GetStyle() != wxTRANSPARENT
)
238 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
241 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
245 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
247 for (int i
= 0; i
< n
-1; i
++)
249 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
250 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
251 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
252 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
253 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
257 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
261 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
263 wxNode
*node
= points
->First();
266 wxPoint
*point
= (wxPoint
*)node
->Data();
267 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
268 long x1
= XLOG2DEV(point
->x
+ xoffset
);
269 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
270 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and again...
271 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
272 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
277 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[],
278 long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
281 if (!n
) return; // Nothing to draw
282 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
284 for (i
= 0 ; i
< n
; i
++)
286 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
287 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
289 if (m_brush
.GetStyle() != wxTRANSPARENT
)
290 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
292 if (m_pen
.GetStyle() != wxTRANSPARENT
)
293 for (i
= 0 ; i
< n
; i
++)
294 gdk_draw_line( m_window
, m_penGC
,
297 gdkpoints
[(i
+1)%n
].x
,
298 gdkpoints
[(i
+1)%n
].y
);
302 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
,
303 long yoffset
, int WXUNUSED(fillStyle
))
305 int n
= lines
->Number();
308 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
309 wxNode
*node
= lines
->First();
313 wxPoint
*p
= (wxPoint
*) node
->Data();
314 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
315 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
319 if (m_brush
.GetStyle() != wxTRANSPARENT
)
320 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
322 if (m_pen
.GetStyle() != wxTRANSPARENT
)
325 for (i
= 0 ; i
< n
; i
++)
326 gdk_draw_line( m_window
, m_penGC
,
329 gdkpoints
[(i
+1)%n
].x
,
330 gdkpoints
[(i
+1)%n
].y
);
335 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
339 long xx
= XLOG2DEV(x
);
340 long yy
= YLOG2DEV(y
);
341 long ww
= m_signX
* XLOG2DEVREL(width
);
342 long hh
= m_signY
* YLOG2DEVREL(height
);
344 // CMB: draw nothing if transformed w or h is 0
345 if (ww
== 0 || hh
== 0) return;
347 // CMB: handle -ve width and/or height
348 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
349 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
351 if (m_brush
.GetStyle() != wxTRANSPARENT
)
352 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
354 if (m_pen
.GetStyle() != wxTRANSPARENT
)
355 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
358 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
362 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
364 long xx
= XLOG2DEV(x
);
365 long yy
= YLOG2DEV(y
);
366 long ww
= m_signX
* XLOG2DEVREL(width
);
367 long hh
= m_signY
* YLOG2DEVREL(height
);
368 long rr
= XLOG2DEVREL((long)radius
);
370 // CMB: handle -ve width and/or height
371 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
372 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
374 // CMB: if radius is zero use DrawRectangle() instead to avoid
375 // X drawing errors with small radii
378 DrawRectangle( x
, y
, width
, height
);
382 // CMB: draw nothing if transformed w or h is 0
383 if (ww
== 0 || hh
== 0) return;
385 // CMB: adjust size if outline is drawn otherwise the result is
386 // 1 pixel too wide and high
387 if (m_pen
.GetStyle() != wxTRANSPARENT
)
393 // CMB: ensure dd is not larger than rectangle otherwise we
394 // get an hour glass shape
396 if (dd
> ww
) dd
= ww
;
397 if (dd
> hh
) dd
= hh
;
400 if (m_brush
.GetStyle() != wxTRANSPARENT
)
402 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
403 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
404 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
405 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
406 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
407 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
410 if (m_pen
.GetStyle() != wxTRANSPARENT
)
412 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
413 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
414 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
415 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
416 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
417 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
418 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
419 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
423 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
427 long xx
= XLOG2DEV(x
);
428 long yy
= YLOG2DEV(y
);
429 long ww
= m_signX
* XLOG2DEVREL(width
);
430 long hh
= m_signY
* YLOG2DEVREL(height
);
432 // CMB: handle -ve width and/or height
433 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
434 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
436 if (m_brush
.GetStyle() != wxTRANSPARENT
)
437 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
439 if (m_pen
.GetStyle() != wxTRANSPARENT
)
440 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
443 bool wxPaintDC::CanDrawBitmap(void) const
448 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
452 if (!icon
.Ok()) return;
454 int xx
= XLOG2DEV(x
);
455 int yy
= YLOG2DEV(y
);
457 GdkBitmap
*mask
= NULL
;
458 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
462 gdk_gc_set_clip_mask( m_penGC
, mask
);
463 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
466 GdkPixmap
*pm
= icon
.GetPixmap();
467 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
471 gdk_gc_set_clip_mask( m_penGC
, NULL
);
472 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
476 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
477 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool WXUNUSED(useMask
) )
479 if (!Ok()) return FALSE
;
481 // CMB 20/5/98: add blitting of bitmaps
482 if (source
->IsKindOf(CLASSINFO(wxMemoryDC
)))
484 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
485 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
492 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
493 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
494 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
)
500 wxClientDC
*csrc
= (wxClientDC
*)source
;
501 gdk_window_copy_area ( m_window
, m_penGC
,
502 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
504 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
505 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
) );
508 gdk_window_copy_area ( m_window, m_penGC,
509 XLOG2DEV(xdest), YLOG2DEV(ydest),
518 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
522 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
527 // CMB 21/5/98: draw text background if mode is wxSOLID
528 if (m_backgroundMode
== wxSOLID
)
530 long width
= gdk_string_width( font
, text
);
531 long height
= font
->ascent
+ font
->descent
;
532 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
533 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
534 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
536 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
538 // CMB 17/7/98: simple underline: ignores scaling and underlying
539 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
540 // properties (see wxXt implementation)
541 if (m_font
.GetUnderlined())
543 long width
= gdk_string_width( font
, text
);
544 long ul_y
= y
+ font
->ascent
;
545 if (font
->descent
> 0) ul_y
++;
546 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
550 bool wxPaintDC::CanGetTextExtent(void) const
555 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
556 long *descent
, long *externalLeading
,
557 wxFont
*theFont
, bool WXUNUSED(use16
) )
561 wxFont fontToUse
= m_font
;
562 if (theFont
) fontToUse
= *theFont
;
564 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
565 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
566 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
567 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
568 if (externalLeading
) (*externalLeading
) = 0; // ??
571 long wxPaintDC::GetCharWidth(void)
575 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
576 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
579 long wxPaintDC::GetCharHeight(void)
583 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
584 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
587 void wxPaintDC::Clear(void)
591 // DestroyClippingRegion();
595 gdk_window_clear( m_window
);
601 GetSize( &width
, &height
);
602 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
606 void wxPaintDC::SetFont( const wxFont
&font
)
613 void wxPaintDC::SetPen( const wxPen
&pen
)
617 if (m_pen
== pen
) return;
621 if (!m_pen
.Ok()) return;
623 gint width
= m_pen
.GetWidth();
624 // CMB: if width is non-zero scale it with the dc
631 // X doesn't allow different width in x and y and so we take
633 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
637 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
638 switch (m_pen
.GetStyle())
640 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
641 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
642 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
643 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
644 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
647 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
648 switch (m_pen
.GetCap())
650 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
651 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
652 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
655 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
656 switch (m_pen
.GetJoin())
658 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
659 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
660 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
663 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
665 m_pen
.GetColour().CalcPixel( m_cmap
);
666 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
669 void wxPaintDC::SetBrush( const wxBrush
&brush
)
673 if (m_brush
== brush
) return;
677 if (!m_brush
.Ok()) return;
679 m_brush
.GetColour().CalcPixel( m_cmap
);
680 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
682 GdkFill fillStyle
= GDK_SOLID
;
683 switch (m_brush
.GetStyle())
689 fillStyle
= GDK_STIPPLED
;
692 gdk_gc_set_fill( m_brushGC
, fillStyle
);
694 if (m_brush
.GetStyle() == wxSTIPPLE
)
696 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
699 if (IS_HATCH(m_brush
.GetStyle()))
701 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
702 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
706 // CMB 21/7/98: Added SetBackground. Sets background brush
707 // for Clear() and bg colour for shapes filled with cross-hatch brush
708 void wxPaintDC::SetBackground( const wxBrush
&brush
)
712 if (m_backgroundBrush
== brush
) return;
714 m_backgroundBrush
= brush
;
716 if (!m_backgroundBrush
.Ok()) return;
718 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
719 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
720 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
722 GdkFill fillStyle
= GDK_SOLID
;
723 switch (m_backgroundBrush
.GetStyle())
729 fillStyle
= GDK_STIPPLED
;
732 gdk_gc_set_fill( m_bgGC
, fillStyle
);
734 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
736 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
739 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
741 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
742 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
746 void wxPaintDC::SetLogicalFunction( int function
)
748 if (m_logicalFunction
== function
) return;
749 GdkFunction mode
= GDK_COPY
;
752 case wxXOR
: mode
= GDK_INVERT
; break;
753 case wxINVERT
: mode
= GDK_INVERT
; break;
756 m_logicalFunction
= function
;
757 gdk_gc_set_function( m_penGC
, mode
);
758 gdk_gc_set_function( m_brushGC
, mode
);
761 void wxPaintDC::SetTextForeground( const wxColour
&col
)
765 if (m_textForegroundColour
== col
) return;
767 m_textForegroundColour
= col
;
768 if (!m_textForegroundColour
.Ok()) return;
770 m_textForegroundColour
.CalcPixel( m_cmap
);
771 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
774 void wxPaintDC::SetTextBackground( const wxColour
&col
)
778 if (m_textBackgroundColour
== col
) return;
780 m_textBackgroundColour
= col
;
781 if (!m_textBackgroundColour
.Ok()) return;
783 m_textBackgroundColour
.CalcPixel( m_cmap
);
784 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
787 void wxPaintDC::SetBackgroundMode( int mode
)
789 m_backgroundMode
= mode
;
791 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
792 // transparent/solid background mode
793 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
795 gdk_gc_set_fill( m_brushGC
,
796 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
800 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
804 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
806 wxDC::SetClippingRegion( x
, y
, width
, height
);
809 rect
.x
= XLOG2DEV(x
);
810 rect
.y
= YLOG2DEV(y
);
811 rect
.width
= XLOG2DEVREL(width
);
812 rect
.height
= YLOG2DEVREL(height
);
813 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
814 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
815 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
816 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
820 void wxPaintDC::DestroyClippingRegion(void)
822 wxDC::DestroyClippingRegion();
824 gdk_gc_set_clip_rectangle( m_penGC
, NULL
);
825 gdk_gc_set_clip_rectangle( m_brushGC
, NULL
);
826 gdk_gc_set_clip_rectangle( m_textGC
, NULL
);
827 gdk_gc_set_clip_rectangle( m_bgGC
, NULL
);
830 void wxPaintDC::SetUpDC(void)
833 m_logicalFunction
= wxCOPY
;
834 if (m_penGC
) gdk_gc_unref( m_penGC
);
835 m_penGC
= gdk_gc_new( m_window
);
836 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
837 m_brushGC
= gdk_gc_new( m_window
);
838 if (m_textGC
) gdk_gc_unref( m_textGC
);
839 m_textGC
= gdk_gc_new( m_window
);
840 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
841 m_bgGC
= gdk_gc_new( m_window
);
842 SetTextForeground( m_textForegroundColour
);
843 SetTextBackground( m_textBackgroundColour
);
848 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
852 hatch_bitmap
= hatches
;
853 hatch_bitmap
[0] = gdk_bitmap_create_from_data( NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
854 hatch_bitmap
[1] = gdk_bitmap_create_from_data( NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
855 hatch_bitmap
[2] = gdk_bitmap_create_from_data( NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
856 hatch_bitmap
[3] = gdk_bitmap_create_from_data( NULL
, cross_bits
, cross_width
, cross_height
);
857 hatch_bitmap
[4] = gdk_bitmap_create_from_data( NULL
, horiz_bits
, horiz_width
, horiz_height
);
858 hatch_bitmap
[5] = gdk_bitmap_create_from_data( NULL
, verti_bits
, verti_width
, verti_height
);
862 GdkWindow
*wxPaintDC::GetWindow(void)
867 // ----------------------------------- spline code ----------------------------------------
869 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
870 double a3
, double b3
, double a4
, double b4
);
871 void wx_clear_stack(void);
872 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
873 double *y3
, double *x4
, double *y4
);
874 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
875 double x4
, double y4
);
876 static bool wx_spline_add_point(double x
, double y
);
877 static void wx_spline_draw_point_array(wxDC
*dc
);
879 wxList wx_spline_point_list
;
881 #define half(z1, z2) ((z1+z2)/2.0)
884 /* iterative version */
886 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
889 register double xmid
, ymid
;
890 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
893 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
895 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
896 xmid
= (double)half(x2
, x3
);
897 ymid
= (double)half(y2
, y3
);
898 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
899 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
900 wx_spline_add_point( x1
, y1
);
901 wx_spline_add_point( xmid
, ymid
);
903 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
904 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
905 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
906 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
911 /* utilities used by spline drawing routines */
913 typedef struct wx_spline_stack_struct
{
914 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
917 #define SPLINE_STACK_DEPTH 20
918 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
919 static Stack
*wx_stack_top
;
920 static int wx_stack_count
;
922 void wx_clear_stack(void)
924 wx_stack_top
= wx_spline_stack
;
928 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
930 wx_stack_top
->x1
= x1
;
931 wx_stack_top
->y1
= y1
;
932 wx_stack_top
->x2
= x2
;
933 wx_stack_top
->y2
= y2
;
934 wx_stack_top
->x3
= x3
;
935 wx_stack_top
->y3
= y3
;
936 wx_stack_top
->x4
= x4
;
937 wx_stack_top
->y4
= y4
;
942 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
943 double *x3
, double *y3
, double *x4
, double *y4
)
945 if (wx_stack_count
== 0)
949 *x1
= wx_stack_top
->x1
;
950 *y1
= wx_stack_top
->y1
;
951 *x2
= wx_stack_top
->x2
;
952 *y2
= wx_stack_top
->y2
;
953 *x3
= wx_stack_top
->x3
;
954 *y3
= wx_stack_top
->y3
;
955 *x4
= wx_stack_top
->x4
;
956 *y4
= wx_stack_top
->y4
;
960 static bool wx_spline_add_point(double x
, double y
)
962 wxPoint
*point
= new wxPoint
;
965 wx_spline_point_list
.Append((wxObject
*)point
);
969 static void wx_spline_draw_point_array(wxDC
*dc
)
971 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
972 wxNode
*node
= wx_spline_point_list
.First();
975 wxPoint
*point
= (wxPoint
*)node
->Data();
978 node
= wx_spline_point_list
.First();
982 void wxPaintDC::DrawOpenSpline( wxList
*points
)
985 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
986 double x1
, y1
, x2
, y2
;
988 wxNode
*node
= points
->First();
989 p
= (wxPoint
*)node
->Data();
995 p
= (wxPoint
*)node
->Data();
999 cx1
= (double)((x1
+ x2
) / 2);
1000 cy1
= (double)((y1
+ y2
) / 2);
1001 cx2
= (double)((cx1
+ x2
) / 2);
1002 cy2
= (double)((cy1
+ y2
) / 2);
1004 wx_spline_add_point(x1
, y1
);
1006 while ((node
= node
->Next()) != NULL
)
1008 p
= (wxPoint
*)node
->Data();
1013 cx4
= (double)(x1
+ x2
) / 2;
1014 cy4
= (double)(y1
+ y2
) / 2;
1015 cx3
= (double)(x1
+ cx4
) / 2;
1016 cy3
= (double)(y1
+ cy4
) / 2;
1018 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1022 cx2
= (double)(cx1
+ x2
) / 2;
1023 cy2
= (double)(cy1
+ y2
) / 2;
1026 wx_spline_add_point( cx1
, cy1
);
1027 wx_spline_add_point( x2
, y2
);
1029 wx_spline_draw_point_array( this );