From d0f9e887437e974876e9207bd625018b224764d5 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 23 Sep 2008 23:29:10 +0000 Subject: [PATCH] gtk, gtk2: PolyLine must skip last point draw to be delphi/win32 compatible git-svn-id: trunk@16689 - --- lcl/interfaces/gtk/gtkdef.pp | 4 ++++ lcl/interfaces/gtk/gtkdevicecontext.inc | 18 ++++++++++++++++++ lcl/interfaces/gtk/gtkwinapi.inc | 25 ++++--------------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lcl/interfaces/gtk/gtkdef.pp b/lcl/interfaces/gtk/gtkdef.pp index 1ff22907e0..a258a0f61e 100644 --- a/lcl/interfaces/gtk/gtkdef.pp +++ b/lcl/interfaces/gtk/gtkdef.pp @@ -284,6 +284,8 @@ type FSelectedColors: TDevContextSelectedColorsType; FOwnedGDIObjects: array[TGDIType] of PGdiObject; + FLineSkipLastPoint: Boolean; + FCurValues: TGdkGCValues; function GetGDIObjects(ID: TGDIType): PGdiObject; function GetOffset: TPoint; @@ -341,6 +343,8 @@ type function HasGC: Boolean; procedure ResetGCClipping; + procedure SetLineSkipLastPoint; + procedure UnsetLineSkipLastPoint; // origins property Origin: TPoint read FOrigin write FOrigin; diff --git a/lcl/interfaces/gtk/gtkdevicecontext.inc b/lcl/interfaces/gtk/gtkdevicecontext.inc index 0c511e5c43..3386d86b26 100644 --- a/lcl/interfaces/gtk/gtkdevicecontext.inc +++ b/lcl/interfaces/gtk/gtkdevicecontext.inc @@ -652,6 +652,24 @@ begin SelectRegion; end; +procedure TGtkDeviceContext.SetLineSkipLastPoint; +begin + gdk_gc_get_values(GC, @FCurValues); + FLineSkipLastPoint := + (FCurValues.line_width = 1) or + (FCurValues.cap_style <> GDK_CAP_NOT_LAST); + if FLineSkipLastPoint then + gdk_gc_set_line_attributes(GC, 0, FCurValues.line_style, + GDK_CAP_NOT_LAST, FCurValues.join_style); +end; + +procedure TGtkDeviceContext.UnsetLineSkipLastPoint; +begin + if FLineSkipLastPoint then + gdk_gc_set_line_attributes(GC, FCurValues.line_width, FCurValues.line_style, + FCurValues.cap_style, FCurValues.join_style); +end; + function TGtkDeviceContext.SelectBitmap(AGdiObject: PGdiObject): PGdiObject; var NewDrawable: PGdkPixmap; diff --git a/lcl/interfaces/gtk/gtkwinapi.inc b/lcl/interfaces/gtk/gtkwinapi.inc index 36d9cc3cf2..aeed6fd234 100644 --- a/lcl/interfaces/gtk/gtkwinapi.inc +++ b/lcl/interfaces/gtk/gtkwinapi.inc @@ -6820,8 +6820,6 @@ var FromY: Integer; ToX: Integer; ToY: Integer; - CurValues: TGdkGCValues; - AdjustAttrib: Boolean; begin Assert(False, Format('trace:> [TGtkWidgetSet.LineTo] DC:0x%x, X:%d, Y:%d', [DC, X, Y])); @@ -6840,26 +6838,9 @@ begin ToY:=Y+DCOrigin.Y; {$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF} - gdk_gc_get_values(DevCtx.GC, @CurValues); - - // LineTo should not paint the last point - // this works under gtk only with line_width=0 - // => set linewidth to 0 and GDK_CAP_NOT_LAST - AdjustAttrib := (CurValues.line_width = 1) - or (CurValues.cap_style <> GDK_CAP_NOT_LAST); - if AdjustAttrib - then begin - gdk_gc_set_line_attributes(DevCtx.GC, 0, CurValues.line_style, - GDK_CAP_NOT_LAST, CurValues.join_style); - end; - + DevCtx.SetLineSkipLastPoint; gdk_draw_line(DevCtx.Drawable, DevCtx.GC, FromX, FromY, ToX, ToY); - - if AdjustAttrib - then begin - gdk_gc_set_line_attributes(DevCtx.GC, CurValues.line_width, CurValues.line_style, - CurValues.cap_style, CurValues.join_style); - end; + DevCtx.UnsetLineSkipLastPoint; {$IFDEF DebugGDK}EndGDKErrorTrap;{$ENDIF} DevCtx.PenPos:= Point(X, Y); @@ -7225,7 +7206,9 @@ begin if Result and not DevCtx.IsNullPen then begin {$IFDEF DebugGDK}BeginGDKErrorTrap;{$ENDIF} + DevCtx.SetLineSkipLastPoint; gdk_draw_lines(DevCtx.Drawable, DevCtx.GC, PointArray, NumPts); + DevCtx.UnsetLineSkipLastPoint; {$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF} end;