unit X11_DeviceContexts; {$MODE OBJFPC} {$M+} interface uses X11_Objects, X11_Fonts, X11, xlib, type_fixes; type TDeviceContext = class(system.TObject) // (X11_Objects.TObject, IDeviceContext, X11_Objects.IObject, IInterface) private fXGC : PXGC; fBOwnsXGC : Boolean; fDisplay : PDisplay; protected function GetFont() : IFont; procedure SetFont(const aValue : IFont); function GetForeground() : TUINT32; procedure SetForeground(aValue : TUINT32); public destructor Destroy(); override; published property Font : IFont read GetFont write SetFont; property Foreground : TUINT32 read GetForeground write SetForeground; function GetLineAttributes() : TLineAttributes; procedure SetLineAttributes(const aValue : TLineAttributes); function GetHandle() : PXGC; public property LineAttributes : TLineAttributes read GetLineAttributes write SetLineAttributes; property Handle : PXGC read GetHandle; property Display : PDisplay read fDisplay; //property BOwnsHandle : Boolean; end; implementation uses x, sysutils; function TDeviceContext.GetHandle() : PXGC; begin Result := fXGC; end; destructor TDeviceContext.Destroy(); begin if fBOwnsXGC then begin FreeAndNil(fXGC); end; inherited Destroy(); end; function TDeviceContext.GetFont() : IFont; var vValues : TXGCValues; begin ensureOK(XGetGCValues(Display, Handle, GCFont, @vValues)); Result := X11_Fonts.TFont.Reuse(Display, vValues.font, False); end; procedure TDeviceContext.SetFont(const aValue : IFont); begin ensureOK(XSetFont(Display, Handle, aValue.Handle)); end; function TDeviceContext.GetForeground() : TUINT32; var vValues : TXGCValues; begin ensureOK(XGetGCValues(Display, Handle, GCFont, @vValues)); Result := vValues.foreground; end; procedure TDeviceContext.SetForeground(aValue : TUINT32); begin ensureOK(XSetForeground(Display, Handle, aValue)); // isplay, *gc, BlackPixel(display, screen)); end; function TDeviceContext.GetLineAttributes() : TLineAttributes; begin // FIXME. end; procedure TDeviceContext.SetLineAttributes(const aValue : TLineAttributes); begin XSetLineAttributes(Display, Handle, aValue.LineWidth, aValue.LineStyle, aValue.CapStyle, aValue.JoinStyle); end; {FIXME XSetDashes(display, *gc, dash_offset, dash_list, list_length); if ((*font_info = XLoadQueryFont(display, fontname)) == } end.