Disegnare un punto su una DrawingArea con le funzioni esterne del API di X11

Da Gambas-it.org - Wikipedia.

Con le risorse del API di X11 è possibile disegnare un punto colorato su una DrawingArea.

Sarà necessario richiamare in Gambas la libreria di X11: "libX11.so.6.3.0"


Mostriamo un esempio pratico:

Library "libX11:6.3.0"
 
' Display *XOpenDisplay(char *display_name)
' Opens a connection to the X server that controls a display.
Private Extern XOpenDisplay(display$ As String) As Pointer

' GC XCreateGC(Display *display, Drawable d, unsigned long valuemask, XGCValues *values)
' Creates a graphics context and returns a GC.
Private Extern XCreateGC(displayP As Pointer, d As Long, mask As Long, values As Pointer) As Pointer

' XSetForeground (Display *display, GC gc, unsigned long foreground)
' Sets the foreground.
Private Extern XSetForeground(displayP As Pointer, gc As Pointer, foreground As Long)

' XDrawPoint(Display *display, Drawable d, GC gc, int x, int y)
' Draws a single point into the specified drawable.
Private Extern XDrawPoint(displayP As Pointer, d As Long, gc As Pointer, xI As Integer, yI As Integer)

' XFreeGC(Display *display, GC gc)
' Destroys the specified GC as well as all the associated storage.
Private Extern XFreeGC(displayP As Pointer, gcP As Pointer)

' XCloseDisplay(Display *display)
' Closes the connection to the X server for the display specified in the Display structure and destroys all windows.
Private Extern XCloseDisplay(displayP As Pointer)


Public Sub Form_Open()
  
 With DrawingArea1
   .X = 10
   .Y = 10
   .W = 400
   .H = 400
   .Background = Color.Black
 End With
 
End


Public Sub Button1_Click()
 
 Dim dsp, gc As Pointer
 
  dsp = XOpenDisplay(Null)
  If IsNull(dsp) Then Error.Raise("Impossibile connettersi al server X !")
 
  gc = XCreateGC(dsp, DrawingArea1.Handle, 0, 0)
  If IsNull(gc) Then Error.Raise("Impossibile creare un contesto grafico !")
  
' Imposta il colore del punto: giallo.
  XSetForeground(dsp, gc, &FFFF00)
  
' Disegna il punto sulla "DrawingArea" alle coordinate x=200, y=200 :
  XDrawPoint(dsp, DrawingArea1.Handle, gc, 200, 200)
  
  
' Va in chiusura:
  XFreeGC(dsp, gc)
  XCloseDisplay(dsp)
  
End



Riferimenti