1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Markus Holzem, Chris Breeze
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dcclient.h"
14 #include "wx/dcclient.h"
15 #include "wx/dcmemory.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
29 static GdkPixmap
*hatches
[num_hatches
];
30 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 #define RAD2DEG 57.2957795131
38 //-----------------------------------------------------------------------------
39 // temporary implementation of the missing GDK function
40 //-----------------------------------------------------------------------------
41 #include "gdk/gdkprivate.h"
42 void gdk_draw_bitmap (GdkDrawable
*drawable
,
52 GdkWindowPrivate
*drawable_private
;
53 GdkWindowPrivate
*src_private
;
54 GdkGCPrivate
*gc_private
;
56 g_return_if_fail (drawable
!= NULL
);
57 g_return_if_fail (src
!= NULL
);
58 g_return_if_fail (gc
!= NULL
);
60 drawable_private
= (GdkWindowPrivate
*) drawable
;
61 src_private
= (GdkWindowPrivate
*) src
;
62 if (drawable_private
->destroyed
|| src_private
->destroyed
)
64 gc_private
= (GdkGCPrivate
*) gc
;
67 width
= src_private
->width
;
69 height
= src_private
->height
;
71 XCopyPlane (drawable_private
->xdisplay
,
73 drawable_private
->xwindow
,
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
85 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
,wxDC
)
87 wxPaintDC::wxPaintDC(void)
89 m_penGC
= (GdkGC
*) NULL
;
90 m_brushGC
= (GdkGC
*) NULL
;
91 m_textGC
= (GdkGC
*) NULL
;
92 m_bgGC
= (GdkGC
*) NULL
;
93 m_cmap
= (GdkColormap
*) NULL
;
97 wxPaintDC::wxPaintDC( wxWindow
*window
)
99 m_penGC
= (GdkGC
*) NULL
;
100 m_brushGC
= (GdkGC
*) NULL
;
101 m_textGC
= (GdkGC
*) NULL
;
102 m_bgGC
= (GdkGC
*) NULL
;
103 m_cmap
= (GdkColormap
*) NULL
;
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
) )
127 wxFAIL_MSG( "wxPaintDC::FloodFill not implemented" );
130 bool wxPaintDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
132 wxFAIL_MSG( "wxPaintDC::GetPixel not implemented" );
136 void wxPaintDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
140 if (m_pen
.GetStyle() != wxTRANSPARENT
)
142 gdk_draw_line( m_window
, m_penGC
,
143 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
147 void wxPaintDC::CrossHair( long x
, long y
)
151 if (m_pen
.GetStyle() != wxTRANSPARENT
)
156 long xx
= XLOG2DEV(x
);
157 long yy
= YLOG2DEV(y
);
158 gdk_draw_line( m_window
, m_penGC
,
159 0, yy
, XLOG2DEVREL(w
), yy
);
160 gdk_draw_line( m_window
, m_penGC
,
161 xx
, 0, xx
, YLOG2DEVREL(h
) );
165 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
169 long xx1
= XLOG2DEV(x1
);
170 long yy1
= YLOG2DEV(y1
);
171 long xx2
= XLOG2DEV(x2
);
172 long yy2
= YLOG2DEV(y2
);
173 long xxc
= XLOG2DEV((long)xc
);
174 long yyc
= YLOG2DEV((long)yc
);
175 double dx
= xx1
- xxc
;
176 double dy
= yy1
- yyc
;
177 double radius
= sqrt(dx
*dx
+dy
*dy
);
178 long r
= (long)radius
;
179 double radius1
, radius2
;
181 if (xx1
== xx2
&& yy1
== yy2
)
189 radius1
= radius2
= 0.0;
193 radius1
= (xx1
- xxc
== 0) ?
194 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
195 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
196 radius2
= (xx2
- xxc
== 0) ?
197 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
198 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
200 long alpha1
= long(radius1
* 64.0);
201 long alpha2
= long((radius2
- radius1
) * 64.0);
202 while (alpha2
<= 0) alpha2
+= 360*64;
203 while (alpha1
> 360*64) alpha1
-= 360*64;
205 if (m_brush
.GetStyle() != wxTRANSPARENT
)
206 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
208 if (m_pen
.GetStyle() != wxTRANSPARENT
)
209 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
213 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
217 long xx
= XLOG2DEV(x
);
218 long yy
= YLOG2DEV(y
);
219 long ww
= m_signX
* XLOG2DEVREL(width
);
220 long hh
= m_signY
* YLOG2DEVREL(height
);
222 // CMB: handle -ve width and/or height
223 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
224 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
226 long start
= long(sa
* 64.0);
227 long end
= long(ea
* 64.0);
228 if (m_brush
.GetStyle() != wxTRANSPARENT
)
229 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
231 if (m_pen
.GetStyle() != wxTRANSPARENT
)
232 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
235 void wxPaintDC::DrawPoint( long x
, long y
)
239 if (m_pen
.GetStyle() != wxTRANSPARENT
)
240 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
243 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
247 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
249 for (int i
= 0; i
< n
-1; i
++)
251 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
252 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
253 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
254 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
255 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
259 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
263 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
265 wxNode
*node
= points
->First();
268 wxPoint
*point
= (wxPoint
*)node
->Data();
269 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
270 long x1
= XLOG2DEV(point
->x
+ xoffset
);
271 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
272 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and again...
273 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
274 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
279 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
283 if (!n
) return; // Nothing to draw
284 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
286 for (i
= 0 ; i
< n
; i
++)
288 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
289 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
291 if (m_brush
.GetStyle() != wxTRANSPARENT
)
292 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
294 if (m_pen
.GetStyle() != wxTRANSPARENT
)
295 for (i
= 0 ; i
< n
; i
++)
296 gdk_draw_line( m_window
, m_penGC
,
299 gdkpoints
[(i
+1)%n
].x
,
300 gdkpoints
[(i
+1)%n
].y
);
304 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
308 int n
= lines
->Number();
309 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
310 wxNode
*node
= lines
->First();
314 wxPoint
*p
= (wxPoint
*) node
->Data();
315 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
316 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
320 if (m_brush
.GetStyle() != wxTRANSPARENT
)
321 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
323 if (m_pen
.GetStyle() != wxTRANSPARENT
)
326 for (i
= 0 ; i
< n
; i
++)
327 gdk_draw_line( m_window
, m_penGC
,
330 gdkpoints
[(i
+1)%n
].x
,
331 gdkpoints
[(i
+1)%n
].y
);
336 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
340 long xx
= XLOG2DEV(x
);
341 long yy
= YLOG2DEV(y
);
342 long ww
= m_signX
* XLOG2DEVREL(width
);
343 long hh
= m_signY
* YLOG2DEVREL(height
);
345 // CMB: draw nothing if transformed w or h is 0
346 if (ww
== 0 || hh
== 0) return;
348 // CMB: handle -ve width and/or height
349 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
350 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
352 if (m_brush
.GetStyle() != wxTRANSPARENT
)
353 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
355 if (m_pen
.GetStyle() != wxTRANSPARENT
)
356 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
359 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
363 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
365 long xx
= XLOG2DEV(x
);
366 long yy
= YLOG2DEV(y
);
367 long ww
= m_signX
* XLOG2DEVREL(width
);
368 long hh
= m_signY
* YLOG2DEVREL(height
);
369 long rr
= XLOG2DEVREL((long)radius
);
371 // CMB: handle -ve width and/or height
372 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
373 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
375 // CMB: if radius is zero use DrawRectangle() instead to avoid
376 // X drawing errors with small radii
379 DrawRectangle( x
, y
, width
, height
);
383 // CMB: draw nothing if transformed w or h is 0
384 if (ww
== 0 || hh
== 0) return;
386 // CMB: adjust size if outline is drawn otherwise the result is
387 // 1 pixel too wide and high
388 if (m_pen
.GetStyle() != wxTRANSPARENT
)
394 // CMB: ensure dd is not larger than rectangle otherwise we
395 // get an hour glass shape
397 if (dd
> ww
) dd
= ww
;
398 if (dd
> hh
) dd
= hh
;
401 if (m_brush
.GetStyle() != wxTRANSPARENT
)
403 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
404 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
405 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
406 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
407 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
408 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
411 if (m_pen
.GetStyle() != wxTRANSPARENT
)
413 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
414 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
415 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
416 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
417 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
418 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
419 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
420 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
424 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
428 long xx
= XLOG2DEV(x
);
429 long yy
= YLOG2DEV(y
);
430 long ww
= m_signX
* XLOG2DEVREL(width
);
431 long hh
= m_signY
* YLOG2DEVREL(height
);
433 // CMB: handle -ve width and/or height
434 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
435 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
437 if (m_brush
.GetStyle() != wxTRANSPARENT
)
438 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
440 if (m_pen
.GetStyle() != wxTRANSPARENT
)
441 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
444 bool wxPaintDC::CanDrawBitmap(void) const
449 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
453 if (!icon
.Ok()) return;
455 int xx
= XLOG2DEV(x
);
456 int yy
= YLOG2DEV(y
);
458 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
459 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
463 gdk_gc_set_clip_mask( m_penGC
, mask
);
464 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
467 GdkPixmap
*pm
= icon
.GetPixmap();
468 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
472 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
473 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
477 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
478 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool WXUNUSED(useMask
) )
480 if (!Ok()) return FALSE
;
482 wxClientDC
*csrc
= (wxClientDC
*)source
;
486 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
487 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
490 gdk_draw_bitmap( m_window
, m_textGC
, bmap
,
491 source
->DeviceToLogicalX(xsrc
),
492 source
->DeviceToLogicalY(ysrc
),
495 source
->DeviceToLogicalXRel(width
),
496 source
->DeviceToLogicalYRel(height
) );
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)
593 gdk_window_clear( m_window
);
599 GetSize( &width
, &height
);
600 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
604 void wxPaintDC::SetFont( const wxFont
&font
)
611 void wxPaintDC::SetPen( const wxPen
&pen
)
615 if (m_pen
== pen
) return;
619 if (!m_pen
.Ok()) return;
621 gint width
= m_pen
.GetWidth();
622 // CMB: if width is non-zero scale it with the dc
629 // X doesn't allow different width in x and y and so we take
631 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
635 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
636 switch (m_pen
.GetStyle())
638 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
639 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
640 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
641 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
642 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
645 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
646 switch (m_pen
.GetCap())
648 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
649 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
650 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
653 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
654 switch (m_pen
.GetJoin())
656 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
657 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
658 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
661 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
663 m_pen
.GetColour().CalcPixel( m_cmap
);
664 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
667 void wxPaintDC::SetBrush( const wxBrush
&brush
)
671 if (m_brush
== brush
) return;
675 if (!m_brush
.Ok()) return;
677 m_brush
.GetColour().CalcPixel( m_cmap
);
678 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
680 GdkFill fillStyle
= GDK_SOLID
;
681 switch (m_brush
.GetStyle())
687 fillStyle
= GDK_STIPPLED
;
690 gdk_gc_set_fill( m_brushGC
, fillStyle
);
692 if (m_brush
.GetStyle() == wxSTIPPLE
)
694 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
697 if (IS_HATCH(m_brush
.GetStyle()))
699 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
700 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
704 // CMB 21/7/98: Added SetBackground. Sets background brush
705 // for Clear() and bg colour for shapes filled with cross-hatch brush
706 void wxPaintDC::SetBackground( const wxBrush
&brush
)
710 if (m_backgroundBrush
== brush
) return;
712 m_backgroundBrush
= brush
;
714 if (!m_backgroundBrush
.Ok()) return;
716 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
717 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
718 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
720 GdkFill fillStyle
= GDK_SOLID
;
721 switch (m_backgroundBrush
.GetStyle())
727 fillStyle
= GDK_STIPPLED
;
730 gdk_gc_set_fill( m_bgGC
, fillStyle
);
732 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
734 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
737 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
739 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
740 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
744 void wxPaintDC::SetLogicalFunction( int function
)
746 if (m_logicalFunction
== function
) return;
747 GdkFunction mode
= GDK_COPY
;
750 case wxXOR
: mode
= GDK_INVERT
; break;
751 case wxINVERT
: mode
= GDK_INVERT
; break;
754 m_logicalFunction
= function
;
755 gdk_gc_set_function( m_penGC
, mode
);
756 gdk_gc_set_function( m_brushGC
, mode
);
759 void wxPaintDC::SetTextForeground( const wxColour
&col
)
763 if (m_textForegroundColour
== col
) return;
765 m_textForegroundColour
= col
;
766 if (!m_textForegroundColour
.Ok()) return;
768 m_textForegroundColour
.CalcPixel( m_cmap
);
769 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
772 void wxPaintDC::SetTextBackground( const wxColour
&col
)
776 if (m_textBackgroundColour
== col
) return;
778 m_textBackgroundColour
= col
;
779 if (!m_textBackgroundColour
.Ok()) return;
781 m_textBackgroundColour
.CalcPixel( m_cmap
);
782 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
785 void wxPaintDC::SetBackgroundMode( int mode
)
787 m_backgroundMode
= mode
;
789 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
790 // transparent/solid background mode
791 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
793 gdk_gc_set_fill( m_brushGC
,
794 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
798 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
802 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
804 wxDC::SetClippingRegion( x
, y
, width
, height
);
807 rect
.x
= XLOG2DEV(x
);
808 rect
.y
= YLOG2DEV(y
);
809 rect
.width
= XLOG2DEVREL(width
);
810 rect
.height
= YLOG2DEVREL(height
);
811 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
812 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
813 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
814 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
818 void wxPaintDC::DestroyClippingRegion(void)
820 wxDC::DestroyClippingRegion();
822 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
823 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
824 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
825 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
828 void wxPaintDC::SetUpDC(void)
831 m_logicalFunction
= wxCOPY
;
832 if (m_penGC
) gdk_gc_unref( m_penGC
);
833 m_penGC
= gdk_gc_new( m_window
);
834 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
835 m_brushGC
= gdk_gc_new( m_window
);
836 if (m_textGC
) gdk_gc_unref( m_textGC
);
837 m_textGC
= gdk_gc_new( m_window
);
838 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
839 m_bgGC
= gdk_gc_new( m_window
);
840 SetTextForeground( m_textForegroundColour
);
841 SetTextBackground( m_textBackgroundColour
);
846 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
850 hatch_bitmap
= hatches
;
851 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
852 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
853 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
854 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
855 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
856 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
860 GdkWindow
*wxPaintDC::GetWindow(void)
865 // ----------------------------------- spline code ----------------------------------------
867 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
868 double a3
, double b3
, double a4
, double b4
);
869 void wx_clear_stack(void);
870 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
871 double *y3
, double *x4
, double *y4
);
872 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
873 double x4
, double y4
);
874 static bool wx_spline_add_point(double x
, double y
);
875 static void wx_spline_draw_point_array(wxDC
*dc
);
877 wxList wx_spline_point_list
;
879 #define half(z1, z2) ((z1+z2)/2.0)
882 /* iterative version */
884 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
887 register double xmid
, ymid
;
888 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
891 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
893 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
894 xmid
= (double)half(x2
, x3
);
895 ymid
= (double)half(y2
, y3
);
896 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
897 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
898 wx_spline_add_point( x1
, y1
);
899 wx_spline_add_point( xmid
, ymid
);
901 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
902 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
903 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
904 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
909 /* utilities used by spline drawing routines */
911 typedef struct wx_spline_stack_struct
{
912 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
915 #define SPLINE_STACK_DEPTH 20
916 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
917 static Stack
*wx_stack_top
;
918 static int wx_stack_count
;
920 void wx_clear_stack(void)
922 wx_stack_top
= wx_spline_stack
;
926 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
928 wx_stack_top
->x1
= x1
;
929 wx_stack_top
->y1
= y1
;
930 wx_stack_top
->x2
= x2
;
931 wx_stack_top
->y2
= y2
;
932 wx_stack_top
->x3
= x3
;
933 wx_stack_top
->y3
= y3
;
934 wx_stack_top
->x4
= x4
;
935 wx_stack_top
->y4
= y4
;
940 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
941 double *x3
, double *y3
, double *x4
, double *y4
)
943 if (wx_stack_count
== 0)
947 *x1
= wx_stack_top
->x1
;
948 *y1
= wx_stack_top
->y1
;
949 *x2
= wx_stack_top
->x2
;
950 *y2
= wx_stack_top
->y2
;
951 *x3
= wx_stack_top
->x3
;
952 *y3
= wx_stack_top
->y3
;
953 *x4
= wx_stack_top
->x4
;
954 *y4
= wx_stack_top
->y4
;
958 static bool wx_spline_add_point(double x
, double y
)
960 wxPoint
*point
= new wxPoint
;
963 wx_spline_point_list
.Append((wxObject
*)point
);
967 static void wx_spline_draw_point_array(wxDC
*dc
)
969 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
970 wxNode
*node
= wx_spline_point_list
.First();
973 wxPoint
*point
= (wxPoint
*)node
->Data();
976 node
= wx_spline_point_list
.First();
980 void wxPaintDC::DrawSpline( wxList
*points
)
983 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
984 double x1
, y1
, x2
, y2
;
986 wxNode
*node
= points
->First();
987 p
= (wxPoint
*)node
->Data();
993 p
= (wxPoint
*)node
->Data();
997 cx1
= (double)((x1
+ x2
) / 2);
998 cy1
= (double)((y1
+ y2
) / 2);
999 cx2
= (double)((cx1
+ x2
) / 2);
1000 cy2
= (double)((cy1
+ y2
) / 2);
1002 wx_spline_add_point(x1
, y1
);
1004 while ((node
= node
->Next()) != NULL
)
1006 p
= (wxPoint
*)node
->Data();
1011 cx4
= (double)(x1
+ x2
) / 2;
1012 cy4
= (double)(y1
+ y2
) / 2;
1013 cx3
= (double)(x1
+ cx4
) / 2;
1014 cy3
= (double)(y1
+ cy4
) / 2;
1016 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1020 cx2
= (double)(cx1
+ x2
) / 2;
1021 cy2
= (double)(cy1
+ y2
) / 2;
1024 wx_spline_add_point( cx1
, cy1
);
1025 wx_spline_add_point( x2
, y2
);
1027 wx_spline_draw_point_array( this );