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)
125 void wxPaintDC::FloodFill( long WXUNUSED(x1
), long WXUNUSED(y1
),
126 wxColour
*WXUNUSED(col
), int WXUNUSED(style
) )
128 wxFAIL_MSG( "wxPaintDC::FloodFill not implemented" );
131 bool wxPaintDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
133 wxFAIL_MSG( "wxPaintDC::GetPixel not implemented" );
137 void wxPaintDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
141 if (m_pen
.GetStyle() != wxTRANSPARENT
)
143 gdk_draw_line( m_window
, m_penGC
,
144 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
148 void wxPaintDC::CrossHair( long x
, long y
)
152 if (m_pen
.GetStyle() != wxTRANSPARENT
)
157 long xx
= XLOG2DEV(x
);
158 long yy
= YLOG2DEV(y
);
159 gdk_draw_line( m_window
, m_penGC
,
160 0, yy
, XLOG2DEVREL(w
), yy
);
161 gdk_draw_line( m_window
, m_penGC
,
162 xx
, 0, xx
, YLOG2DEVREL(h
) );
166 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
170 long xx1
= XLOG2DEV(x1
);
171 long yy1
= YLOG2DEV(y1
);
172 long xx2
= XLOG2DEV(x2
);
173 long yy2
= YLOG2DEV(y2
);
174 long xxc
= XLOG2DEV((long)xc
);
175 long yyc
= YLOG2DEV((long)yc
);
176 double dx
= xx1
- xxc
;
177 double dy
= yy1
- yyc
;
178 double radius
= sqrt(dx
*dx
+dy
*dy
);
179 long r
= (long)radius
;
180 double radius1
, radius2
;
182 if (xx1
== xx2
&& yy1
== yy2
)
190 radius1
= radius2
= 0.0;
194 radius1
= (xx1
- xxc
== 0) ?
195 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
196 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
197 radius2
= (xx2
- xxc
== 0) ?
198 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
199 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
201 long alpha1
= long(radius1
* 64.0);
202 long alpha2
= long((radius2
- radius1
) * 64.0);
203 while (alpha2
<= 0) alpha2
+= 360*64;
204 while (alpha1
> 360*64) alpha1
-= 360*64;
206 if (m_brush
.GetStyle() != wxTRANSPARENT
)
207 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
209 if (m_pen
.GetStyle() != wxTRANSPARENT
)
210 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
214 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
218 long xx
= XLOG2DEV(x
);
219 long yy
= YLOG2DEV(y
);
220 long ww
= m_signX
* XLOG2DEVREL(width
);
221 long hh
= m_signY
* YLOG2DEVREL(height
);
223 // CMB: handle -ve width and/or height
224 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
225 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
227 long start
= long(sa
* 64.0);
228 long end
= long(ea
* 64.0);
229 if (m_brush
.GetStyle() != wxTRANSPARENT
)
230 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
232 if (m_pen
.GetStyle() != wxTRANSPARENT
)
233 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
236 void wxPaintDC::DrawPoint( long x
, long y
)
240 if (m_pen
.GetStyle() != wxTRANSPARENT
)
241 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
244 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
248 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
250 for (int i
= 0; i
< n
-1; i
++)
252 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
253 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
254 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
255 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
256 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
260 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
264 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
266 wxNode
*node
= points
->First();
269 wxPoint
*point
= (wxPoint
*)node
->Data();
270 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
271 long x1
= XLOG2DEV(point
->x
+ xoffset
);
272 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
273 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and again...
274 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
275 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
280 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
284 if (!n
) return; // Nothing to draw
285 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
287 for (i
= 0 ; i
< n
; i
++)
289 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
290 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
292 if (m_brush
.GetStyle() != wxTRANSPARENT
)
293 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
295 if (m_pen
.GetStyle() != wxTRANSPARENT
)
296 for (i
= 0 ; i
< n
; i
++)
297 gdk_draw_line( m_window
, m_penGC
,
300 gdkpoints
[(i
+1)%n
].x
,
301 gdkpoints
[(i
+1)%n
].y
);
305 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
309 int n
= lines
->Number();
310 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
311 wxNode
*node
= lines
->First();
315 wxPoint
*p
= (wxPoint
*) node
->Data();
316 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
317 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
321 if (m_brush
.GetStyle() != wxTRANSPARENT
)
322 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
324 if (m_pen
.GetStyle() != wxTRANSPARENT
)
327 for (i
= 0 ; i
< n
; i
++)
328 gdk_draw_line( m_window
, m_penGC
,
331 gdkpoints
[(i
+1)%n
].x
,
332 gdkpoints
[(i
+1)%n
].y
);
337 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
341 long xx
= XLOG2DEV(x
);
342 long yy
= YLOG2DEV(y
);
343 long ww
= m_signX
* XLOG2DEVREL(width
);
344 long hh
= m_signY
* YLOG2DEVREL(height
);
346 // CMB: draw nothing if transformed w or h is 0
347 if (ww
== 0 || hh
== 0) return;
349 // CMB: handle -ve width and/or height
350 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
351 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
353 if (m_brush
.GetStyle() != wxTRANSPARENT
)
354 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
356 if (m_pen
.GetStyle() != wxTRANSPARENT
)
357 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
360 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
364 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
366 long xx
= XLOG2DEV(x
);
367 long yy
= YLOG2DEV(y
);
368 long ww
= m_signX
* XLOG2DEVREL(width
);
369 long hh
= m_signY
* YLOG2DEVREL(height
);
370 long rr
= XLOG2DEVREL((long)radius
);
372 // CMB: handle -ve width and/or height
373 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
374 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
376 // CMB: if radius is zero use DrawRectangle() instead to avoid
377 // X drawing errors with small radii
380 DrawRectangle( x
, y
, width
, height
);
384 // CMB: draw nothing if transformed w or h is 0
385 if (ww
== 0 || hh
== 0) return;
387 // CMB: adjust size if outline is drawn otherwise the result is
388 // 1 pixel too wide and high
389 if (m_pen
.GetStyle() != wxTRANSPARENT
)
395 // CMB: ensure dd is not larger than rectangle otherwise we
396 // get an hour glass shape
398 if (dd
> ww
) dd
= ww
;
399 if (dd
> hh
) dd
= hh
;
402 if (m_brush
.GetStyle() != wxTRANSPARENT
)
404 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
405 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
406 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
407 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
408 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
409 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
412 if (m_pen
.GetStyle() != wxTRANSPARENT
)
414 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
415 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
416 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
417 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
418 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
419 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
420 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
421 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
425 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
429 long xx
= XLOG2DEV(x
);
430 long yy
= YLOG2DEV(y
);
431 long ww
= m_signX
* XLOG2DEVREL(width
);
432 long hh
= m_signY
* YLOG2DEVREL(height
);
434 // CMB: handle -ve width and/or height
435 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
436 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
438 if (m_brush
.GetStyle() != wxTRANSPARENT
)
439 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
441 if (m_pen
.GetStyle() != wxTRANSPARENT
)
442 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
445 bool wxPaintDC::CanDrawBitmap(void) const
450 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
454 if (!icon
.Ok()) return;
456 int xx
= XLOG2DEV(x
);
457 int yy
= YLOG2DEV(y
);
459 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
460 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
464 gdk_gc_set_clip_mask( m_penGC
, mask
);
465 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
468 GdkPixmap
*pm
= icon
.GetPixmap();
469 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
473 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
474 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
478 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
479 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool WXUNUSED(useMask
) )
481 if (!Ok()) return FALSE
;
483 wxClientDC
*csrc
= (wxClientDC
*)source
;
487 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
488 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
491 gdk_draw_bitmap( m_window
, m_textGC
, bmap
,
492 source
->DeviceToLogicalX(xsrc
),
493 source
->DeviceToLogicalY(ysrc
),
496 source
->DeviceToLogicalXRel(width
),
497 source
->DeviceToLogicalYRel(height
) );
502 gdk_window_copy_area ( m_window
, m_penGC
,
503 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
505 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
506 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
) );
509 gdk_window_copy_area ( m_window, m_penGC,
510 XLOG2DEV(xdest), YLOG2DEV(ydest),
519 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
523 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
528 // CMB 21/5/98: draw text background if mode is wxSOLID
529 if (m_backgroundMode
== wxSOLID
)
531 long width
= gdk_string_width( font
, text
);
532 long height
= font
->ascent
+ font
->descent
;
533 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
534 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
535 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
537 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
539 // CMB 17/7/98: simple underline: ignores scaling and underlying
540 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
541 // properties (see wxXt implementation)
542 if (m_font
.GetUnderlined())
544 long width
= gdk_string_width( font
, text
);
545 long ul_y
= y
+ font
->ascent
;
546 if (font
->descent
> 0) ul_y
++;
547 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
551 bool wxPaintDC::CanGetTextExtent(void) const
556 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
557 long *descent
, long *externalLeading
,
558 wxFont
*theFont
, bool WXUNUSED(use16
) )
562 wxFont fontToUse
= m_font
;
563 if (theFont
) fontToUse
= *theFont
;
565 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
566 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
567 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
568 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
569 if (externalLeading
) (*externalLeading
) = 0; // ??
572 long wxPaintDC::GetCharWidth(void)
576 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
577 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
580 long wxPaintDC::GetCharHeight(void)
584 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
585 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
588 void wxPaintDC::Clear(void)
594 gdk_window_clear( m_window
);
600 GetSize( &width
, &height
);
601 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
605 void wxPaintDC::SetFont( const wxFont
&font
)
612 void wxPaintDC::SetPen( const wxPen
&pen
)
616 if (m_pen
== pen
) return;
620 if (!m_pen
.Ok()) return;
622 gint width
= m_pen
.GetWidth();
623 // CMB: if width is non-zero scale it with the dc
630 // X doesn't allow different width in x and y and so we take
632 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
636 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
637 switch (m_pen
.GetStyle())
639 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
640 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
641 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
642 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
643 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
646 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
647 switch (m_pen
.GetCap())
649 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
650 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
651 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
654 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
655 switch (m_pen
.GetJoin())
657 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
658 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
659 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
662 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
664 m_pen
.GetColour().CalcPixel( m_cmap
);
665 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
668 void wxPaintDC::SetBrush( const wxBrush
&brush
)
672 if (m_brush
== brush
) return;
676 if (!m_brush
.Ok()) return;
678 m_brush
.GetColour().CalcPixel( m_cmap
);
679 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
681 GdkFill fillStyle
= GDK_SOLID
;
682 switch (m_brush
.GetStyle())
688 fillStyle
= GDK_STIPPLED
;
691 gdk_gc_set_fill( m_brushGC
, fillStyle
);
693 if (m_brush
.GetStyle() == wxSTIPPLE
)
695 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
698 if (IS_HATCH(m_brush
.GetStyle()))
700 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
701 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
705 // CMB 21/7/98: Added SetBackground. Sets background brush
706 // for Clear() and bg colour for shapes filled with cross-hatch brush
707 void wxPaintDC::SetBackground( const wxBrush
&brush
)
711 if (m_backgroundBrush
== brush
) return;
713 m_backgroundBrush
= brush
;
715 if (!m_backgroundBrush
.Ok()) return;
717 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
718 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
719 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
721 GdkFill fillStyle
= GDK_SOLID
;
722 switch (m_backgroundBrush
.GetStyle())
728 fillStyle
= GDK_STIPPLED
;
731 gdk_gc_set_fill( m_bgGC
, fillStyle
);
733 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
735 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
738 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
740 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
741 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
745 void wxPaintDC::SetLogicalFunction( int function
)
747 if (m_logicalFunction
== function
) return;
748 GdkFunction mode
= GDK_COPY
;
751 case wxXOR
: mode
= GDK_INVERT
; break;
752 case wxINVERT
: mode
= GDK_INVERT
; break;
755 m_logicalFunction
= function
;
756 gdk_gc_set_function( m_penGC
, mode
);
757 gdk_gc_set_function( m_brushGC
, mode
);
760 void wxPaintDC::SetTextForeground( const wxColour
&col
)
764 if (m_textForegroundColour
== col
) return;
766 m_textForegroundColour
= col
;
767 if (!m_textForegroundColour
.Ok()) return;
769 m_textForegroundColour
.CalcPixel( m_cmap
);
770 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
773 void wxPaintDC::SetTextBackground( const wxColour
&col
)
777 if (m_textBackgroundColour
== col
) return;
779 m_textBackgroundColour
= col
;
780 if (!m_textBackgroundColour
.Ok()) return;
782 m_textBackgroundColour
.CalcPixel( m_cmap
);
783 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
786 void wxPaintDC::SetBackgroundMode( int mode
)
788 m_backgroundMode
= mode
;
790 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
791 // transparent/solid background mode
792 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
794 gdk_gc_set_fill( m_brushGC
,
795 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
799 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
803 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
805 wxDC::SetClippingRegion( x
, y
, width
, height
);
808 rect
.x
= XLOG2DEV(x
);
809 rect
.y
= YLOG2DEV(y
);
810 rect
.width
= XLOG2DEVREL(width
);
811 rect
.height
= YLOG2DEVREL(height
);
812 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
813 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
814 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
815 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
819 void wxPaintDC::DestroyClippingRegion(void)
821 wxDC::DestroyClippingRegion();
823 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
824 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
825 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
826 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
829 void wxPaintDC::SetUpDC(void)
833 m_logicalFunction
= wxCOPY
;
834 m_penGC
= gdk_gc_new( m_window
);
835 m_brushGC
= gdk_gc_new( m_window
);
836 m_textGC
= gdk_gc_new( m_window
);
837 m_bgGC
= gdk_gc_new( m_window
);
838 SetTextForeground( m_textForegroundColour
);
839 SetTextBackground( m_textBackgroundColour
);
844 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
848 hatch_bitmap
= hatches
;
849 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
850 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
851 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
852 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
853 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
854 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
858 void wxPaintDC::Destroy(void)
860 if (m_penGC
) gdk_gc_unref( m_penGC
);
861 m_penGC
= (GdkGC
*) NULL
;
862 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
863 m_brushGC
= (GdkGC
*) NULL
;
864 if (m_textGC
) gdk_gc_unref( m_textGC
);
865 m_textGC
= (GdkGC
*) NULL
;
866 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
867 m_bgGC
= (GdkGC
*) NULL
;
870 GdkWindow
*wxPaintDC::GetWindow(void)
875 // ----------------------------------- spline code ----------------------------------------
877 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
878 double a3
, double b3
, double a4
, double b4
);
879 void wx_clear_stack(void);
880 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
881 double *y3
, double *x4
, double *y4
);
882 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
883 double x4
, double y4
);
884 static bool wx_spline_add_point(double x
, double y
);
885 static void wx_spline_draw_point_array(wxDC
*dc
);
887 wxList wx_spline_point_list
;
889 #define half(z1, z2) ((z1+z2)/2.0)
892 /* iterative version */
894 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
897 register double xmid
, ymid
;
898 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
901 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
903 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
904 xmid
= (double)half(x2
, x3
);
905 ymid
= (double)half(y2
, y3
);
906 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
907 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
908 wx_spline_add_point( x1
, y1
);
909 wx_spline_add_point( xmid
, ymid
);
911 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
912 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
913 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
914 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
919 /* utilities used by spline drawing routines */
921 typedef struct wx_spline_stack_struct
{
922 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
925 #define SPLINE_STACK_DEPTH 20
926 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
927 static Stack
*wx_stack_top
;
928 static int wx_stack_count
;
930 void wx_clear_stack(void)
932 wx_stack_top
= wx_spline_stack
;
936 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
938 wx_stack_top
->x1
= x1
;
939 wx_stack_top
->y1
= y1
;
940 wx_stack_top
->x2
= x2
;
941 wx_stack_top
->y2
= y2
;
942 wx_stack_top
->x3
= x3
;
943 wx_stack_top
->y3
= y3
;
944 wx_stack_top
->x4
= x4
;
945 wx_stack_top
->y4
= y4
;
950 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
951 double *x3
, double *y3
, double *x4
, double *y4
)
953 if (wx_stack_count
== 0)
957 *x1
= wx_stack_top
->x1
;
958 *y1
= wx_stack_top
->y1
;
959 *x2
= wx_stack_top
->x2
;
960 *y2
= wx_stack_top
->y2
;
961 *x3
= wx_stack_top
->x3
;
962 *y3
= wx_stack_top
->y3
;
963 *x4
= wx_stack_top
->x4
;
964 *y4
= wx_stack_top
->y4
;
968 static bool wx_spline_add_point(double x
, double y
)
970 wxPoint
*point
= new wxPoint
;
973 wx_spline_point_list
.Append((wxObject
*)point
);
977 static void wx_spline_draw_point_array(wxDC
*dc
)
979 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
980 wxNode
*node
= wx_spline_point_list
.First();
983 wxPoint
*point
= (wxPoint
*)node
->Data();
986 node
= wx_spline_point_list
.First();
990 void wxPaintDC::DrawSpline( wxList
*points
)
993 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
994 double x1
, y1
, x2
, y2
;
996 wxNode
*node
= points
->First();
997 p
= (wxPoint
*)node
->Data();
1002 node
= node
->Next();
1003 p
= (wxPoint
*)node
->Data();
1007 cx1
= (double)((x1
+ x2
) / 2);
1008 cy1
= (double)((y1
+ y2
) / 2);
1009 cx2
= (double)((cx1
+ x2
) / 2);
1010 cy2
= (double)((cy1
+ y2
) / 2);
1012 wx_spline_add_point(x1
, y1
);
1014 while ((node
= node
->Next()) != NULL
)
1016 p
= (wxPoint
*)node
->Data();
1021 cx4
= (double)(x1
+ x2
) / 2;
1022 cy4
= (double)(y1
+ y2
) / 2;
1023 cx3
= (double)(x1
+ cx4
) / 2;
1024 cy3
= (double)(y1
+ cy4
) / 2;
1026 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1030 cx2
= (double)(cx1
+ x2
) / 2;
1031 cy2
= (double)(cy1
+ y2
) / 2;
1034 wx_spline_add_point( cx1
, cy1
);
1035 wx_spline_add_point( x2
, y2
);
1037 wx_spline_draw_point_array( this );