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
;
484 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
485 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
488 gdk_draw_bitmap( m_window
, m_textGC
, bmap
,
489 source
->DeviceToLogicalX(xsrc
),
490 source
->DeviceToLogicalY(ysrc
),
493 source
->DeviceToLogicalXRel(width
),
494 source
->DeviceToLogicalYRel(height
) );
499 wxClientDC
*csrc
= (wxClientDC
*)source
;
500 gdk_window_copy_area ( m_window
, m_penGC
,
501 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
503 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
504 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
) );
507 gdk_window_copy_area ( m_window, m_penGC,
508 XLOG2DEV(xdest), YLOG2DEV(ydest),
517 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
521 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
526 // CMB 21/5/98: draw text background if mode is wxSOLID
527 if (m_backgroundMode
== wxSOLID
)
529 long width
= gdk_string_width( font
, text
);
530 long height
= font
->ascent
+ font
->descent
;
531 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
532 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
533 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
535 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
537 // CMB 17/7/98: simple underline: ignores scaling and underlying
538 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
539 // properties (see wxXt implementation)
540 if (m_font
.GetUnderlined())
542 long width
= gdk_string_width( font
, text
);
543 long ul_y
= y
+ font
->ascent
;
544 if (font
->descent
> 0) ul_y
++;
545 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
549 bool wxPaintDC::CanGetTextExtent(void) const
554 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
555 long *descent
, long *externalLeading
,
556 wxFont
*theFont
, bool WXUNUSED(use16
) )
560 wxFont fontToUse
= m_font
;
561 if (theFont
) fontToUse
= *theFont
;
563 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
564 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
565 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
566 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
567 if (externalLeading
) (*externalLeading
) = 0; // ??
570 long wxPaintDC::GetCharWidth(void)
574 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
575 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
578 long wxPaintDC::GetCharHeight(void)
582 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
583 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
586 void wxPaintDC::Clear(void)
592 gdk_window_clear( m_window
);
598 GetSize( &width
, &height
);
599 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
603 void wxPaintDC::SetFont( const wxFont
&font
)
610 void wxPaintDC::SetPen( const wxPen
&pen
)
614 if (m_pen
== pen
) return;
618 if (!m_pen
.Ok()) return;
620 gint width
= m_pen
.GetWidth();
621 // CMB: if width is non-zero scale it with the dc
628 // X doesn't allow different width in x and y and so we take
630 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
634 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
635 switch (m_pen
.GetStyle())
637 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
638 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
639 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
640 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
641 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
644 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
645 switch (m_pen
.GetCap())
647 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
648 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
649 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
652 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
653 switch (m_pen
.GetJoin())
655 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
656 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
657 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
660 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
662 m_pen
.GetColour().CalcPixel( m_cmap
);
663 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
666 void wxPaintDC::SetBrush( const wxBrush
&brush
)
670 if (m_brush
== brush
) return;
674 if (!m_brush
.Ok()) return;
676 m_brush
.GetColour().CalcPixel( m_cmap
);
677 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
679 GdkFill fillStyle
= GDK_SOLID
;
680 switch (m_brush
.GetStyle())
686 fillStyle
= GDK_STIPPLED
;
689 gdk_gc_set_fill( m_brushGC
, fillStyle
);
691 if (m_brush
.GetStyle() == wxSTIPPLE
)
693 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
696 if (IS_HATCH(m_brush
.GetStyle()))
698 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
699 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
703 // CMB 21/7/98: Added SetBackground. Sets background brush
704 // for Clear() and bg colour for shapes filled with cross-hatch brush
705 void wxPaintDC::SetBackground( const wxBrush
&brush
)
709 if (m_backgroundBrush
== brush
) return;
711 m_backgroundBrush
= brush
;
713 if (!m_backgroundBrush
.Ok()) return;
715 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
716 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
717 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
719 GdkFill fillStyle
= GDK_SOLID
;
720 switch (m_backgroundBrush
.GetStyle())
726 fillStyle
= GDK_STIPPLED
;
729 gdk_gc_set_fill( m_bgGC
, fillStyle
);
731 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
733 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
736 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
738 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
739 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
743 void wxPaintDC::SetLogicalFunction( int function
)
745 if (m_logicalFunction
== function
) return;
746 GdkFunction mode
= GDK_COPY
;
749 case wxXOR
: mode
= GDK_INVERT
; break;
750 case wxINVERT
: mode
= GDK_INVERT
; break;
753 m_logicalFunction
= function
;
754 gdk_gc_set_function( m_penGC
, mode
);
755 gdk_gc_set_function( m_brushGC
, mode
);
758 void wxPaintDC::SetTextForeground( const wxColour
&col
)
762 if (m_textForegroundColour
== col
) return;
764 m_textForegroundColour
= col
;
765 if (!m_textForegroundColour
.Ok()) return;
767 m_textForegroundColour
.CalcPixel( m_cmap
);
768 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
771 void wxPaintDC::SetTextBackground( const wxColour
&col
)
775 if (m_textBackgroundColour
== col
) return;
777 m_textBackgroundColour
= col
;
778 if (!m_textBackgroundColour
.Ok()) return;
780 m_textBackgroundColour
.CalcPixel( m_cmap
);
781 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
784 void wxPaintDC::SetBackgroundMode( int mode
)
786 m_backgroundMode
= mode
;
788 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
789 // transparent/solid background mode
790 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
792 gdk_gc_set_fill( m_brushGC
,
793 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
797 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
801 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
803 wxDC::SetClippingRegion( x
, y
, width
, height
);
806 rect
.x
= XLOG2DEV(x
);
807 rect
.y
= YLOG2DEV(y
);
808 rect
.width
= XLOG2DEVREL(width
);
809 rect
.height
= YLOG2DEVREL(height
);
810 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
811 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
812 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
813 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
817 void wxPaintDC::DestroyClippingRegion(void)
819 wxDC::DestroyClippingRegion();
821 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
822 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
823 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
824 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
827 void wxPaintDC::SetUpDC(void)
830 m_logicalFunction
= wxCOPY
;
831 if (m_penGC
) gdk_gc_unref( m_penGC
);
832 m_penGC
= gdk_gc_new( m_window
);
833 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
834 m_brushGC
= gdk_gc_new( m_window
);
835 if (m_textGC
) gdk_gc_unref( m_textGC
);
836 m_textGC
= gdk_gc_new( m_window
);
837 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
838 m_bgGC
= gdk_gc_new( m_window
);
839 SetTextForeground( m_textForegroundColour
);
840 SetTextBackground( m_textBackgroundColour
);
845 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
849 hatch_bitmap
= hatches
;
850 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
851 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
852 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
853 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
854 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
855 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
859 GdkWindow
*wxPaintDC::GetWindow(void)
864 // ----------------------------------- spline code ----------------------------------------
866 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
867 double a3
, double b3
, double a4
, double b4
);
868 void wx_clear_stack(void);
869 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
870 double *y3
, double *x4
, double *y4
);
871 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
872 double x4
, double y4
);
873 static bool wx_spline_add_point(double x
, double y
);
874 static void wx_spline_draw_point_array(wxDC
*dc
);
876 wxList wx_spline_point_list
;
878 #define half(z1, z2) ((z1+z2)/2.0)
881 /* iterative version */
883 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
886 register double xmid
, ymid
;
887 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
890 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
892 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
893 xmid
= (double)half(x2
, x3
);
894 ymid
= (double)half(y2
, y3
);
895 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
896 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
897 wx_spline_add_point( x1
, y1
);
898 wx_spline_add_point( xmid
, ymid
);
900 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
901 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
902 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
903 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
908 /* utilities used by spline drawing routines */
910 typedef struct wx_spline_stack_struct
{
911 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
914 #define SPLINE_STACK_DEPTH 20
915 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
916 static Stack
*wx_stack_top
;
917 static int wx_stack_count
;
919 void wx_clear_stack(void)
921 wx_stack_top
= wx_spline_stack
;
925 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
927 wx_stack_top
->x1
= x1
;
928 wx_stack_top
->y1
= y1
;
929 wx_stack_top
->x2
= x2
;
930 wx_stack_top
->y2
= y2
;
931 wx_stack_top
->x3
= x3
;
932 wx_stack_top
->y3
= y3
;
933 wx_stack_top
->x4
= x4
;
934 wx_stack_top
->y4
= y4
;
939 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
940 double *x3
, double *y3
, double *x4
, double *y4
)
942 if (wx_stack_count
== 0)
946 *x1
= wx_stack_top
->x1
;
947 *y1
= wx_stack_top
->y1
;
948 *x2
= wx_stack_top
->x2
;
949 *y2
= wx_stack_top
->y2
;
950 *x3
= wx_stack_top
->x3
;
951 *y3
= wx_stack_top
->y3
;
952 *x4
= wx_stack_top
->x4
;
953 *y4
= wx_stack_top
->y4
;
957 static bool wx_spline_add_point(double x
, double y
)
959 wxPoint
*point
= new wxPoint
;
962 wx_spline_point_list
.Append((wxObject
*)point
);
966 static void wx_spline_draw_point_array(wxDC
*dc
)
968 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
969 wxNode
*node
= wx_spline_point_list
.First();
972 wxPoint
*point
= (wxPoint
*)node
->Data();
975 node
= wx_spline_point_list
.First();
979 void wxPaintDC::DrawSpline( wxList
*points
)
982 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
983 double x1
, y1
, x2
, y2
;
985 wxNode
*node
= points
->First();
986 p
= (wxPoint
*)node
->Data();
992 p
= (wxPoint
*)node
->Data();
996 cx1
= (double)((x1
+ x2
) / 2);
997 cy1
= (double)((y1
+ y2
) / 2);
998 cx2
= (double)((cx1
+ x2
) / 2);
999 cy2
= (double)((cy1
+ y2
) / 2);
1001 wx_spline_add_point(x1
, y1
);
1003 while ((node
= node
->Next()) != NULL
)
1005 p
= (wxPoint
*)node
->Data();
1010 cx4
= (double)(x1
+ x2
) / 2;
1011 cy4
= (double)(y1
+ y2
) / 2;
1012 cx3
= (double)(x1
+ cx4
) / 2;
1013 cy3
= (double)(y1
+ cy4
) / 2;
1015 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1019 cx2
= (double)(cx1
+ x2
) / 2;
1020 cy2
= (double)(cy1
+ y2
) / 2;
1023 wx_spline_add_point( cx1
, cy1
);
1024 wx_spline_add_point( x2
, y2
);
1026 wx_spline_draw_point_array( this );