Differenze tra le versioni di "Creare una finestra mediante le funzioni del API di X11"

Da Gambas-it.org - Wikipedia.
Riga 313: Riga 313:
 
      
 
      
 
  <FONT color=gray>' ''Crea un nuovo contesto grafico:''</font>
 
  <FONT color=gray>' ''Crea un nuovo contesto grafico:''</font>
     gc = XCreateGC(disp, wId, 0, Null)
+
     gc = XCreateGC(disp, wId, 0, 0)
 
     If IsNull(gc) Then Error.Raise("Impossibile creare un nuovo contesto grafico !")
 
     If IsNull(gc) Then Error.Raise("Impossibile creare un nuovo contesto grafico !")
 
   
 
   

Versione delle 19:40, 30 gen 2016

Con le risorse del API di X11 è possibile creare una finestra ed interagire con essa.

Sarà necessario richiamare la libreria di X attualmente: "libX11.so.6.3.0"


Creare una semplicemente finestra colorata

Mostriamo di seguito un breve codice con le risorse essenziali della libreria X11 per creare una semplice finestra di colore rosso. Se si cliccherà al suo interno con un qualsiasi tasto del mouse, la finestra verrà distrutta:

Library "libX11:6.3.0"

Private Const ButtonPressMask As Byte = 4
Private Enum KeyPress = 2, KeyRelease, ButtonPress, ButtonRelease, MotionNotify, EnterNotify, LeaveNotify,
                           FocusIn, FocusOut, KeymapNotify, Expose, GraphicsExpose, NoExpose

' Display *XOpenDisplay(char *display_name)
' Opens a connection to the X server that controls a display.
Private Extern XOpenDisplay(display$ As String) As Pointer
 
' Window XDefaultRootWindow(Display *display)
' Return the root window for the default screen.
Private Extern XDefaultRootWindow(displayP As Pointer) As Integer

' Window XCreateSimpleWindow(Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, unsigned long border, unsigned long background)
' creates an unmapped InputOutput subwindow for a specified parent window, returns the window ID of the created window.
Private Extern XCreateSimpleWindow(displayP As Pointer, parent As Long, x As Integer, y As Integer, width As Integer, height As Integer, border_width As Integer, border As Integer, background As Long) As Integer

' XSelectInput (Display *display, Window w, long event_mask)
' requests that the X server report the events associated with the specified Event mask.
Private Extern XSelectInput(displayP As Pointer, w As Long, event_mask As Long)

' XMapRaised (Display *display, Window w)
' raises the specified window to the top of the stack.
Private Extern XMapRaised(displayP As Pointer, w As Long)

' XNextEvent (Display *display, XEvent *event_return)
' gets the next event and remove it from the queue
Private Extern XNextEvent(displayP As Pointer, event_return As Pointer)

' XDestroyWindow(Display *display, Window w)
' destroys the specified window as well as all of its subwindows
Private Extern XDestroyWindow(displayP As Pointer, w As Long)

' 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)
 
' void exit(int status)
' Termina il programma. I buffer dei file vengono svuotati, i flussi sono chiusi.
Private Extern exitus(status As Integer) In "libc:6" Exec "exit"


Public Sub Main()

 Dim disp, ev As Pointer
 Dim screen As Integer
 Dim id As Long

' Apre la connessione con il server display del sistema grafico X:
  disp = XOpenDisplay(Null)
  If IsNull(disp) Then Error.Raise("Impossibile aprire il server display !")
   
' Crea la finestra secondo i parametri previsti dalla funzione. L'ultimo parametro imposta il colore di fondo della finestra:
  id = XCreateSimpleWindow(disp, XDefaultRootWindow(disp), 0, 0, 300, 200, 0, 0, &FF0000)
  Print "ID della finestra creata: "; Hex(id, 6)

' Dice al server display quali eventi deve vedere:
  XSelectInput(disp, id, ButtonPressMask)
  
' Apre la finestra sullo schermo. Si può utilizzare anche la funzione "XMapWindow(display, w)":
  XMapRaised(disp, id)
  
' Alloca un'area di memoria pari (208 byte) o superiore alla Struttura esterna.
' Poiché sarà utilizzato soltanto il valore del primo valore di detta Struttura esterna,
' si utilizzerà quest'area di memoria riservata al posto della Struttura predetta:
  ev = Alloc(256)


' Inizia il ciclo, restando in attesa di un evento stabilito con la precedente funzione XSelectInput():
  While True

    XNextEvent(disp, ev)
' Se viene premuto un qualsiasi tasto del mouse, chiude la finestra:
     If Int@(ev) = ButtonPress Then chiude_X(disp, id, ev)

  Wend

End


Private Procedure chiude_X(disp_ch As Pointer, id As Integer, pev As Pointer)

  Free(pev)

' Chiude la finestra:
  XDestroyWindow(disp_ch, id)

  XCloseDisplay(disp_ch)

  exitus(0)

End


Creare una finestra colorata contenente disegni geometrici e caratteri alfabetici, con impostazione del puntatore del mouse

In quest'altro esempio, più complesso, verrà creata una finestra di colore rosso, nella quale saranno disegnate figure geometriche e caratteri testuali. Sarà, inoltre, possibile intercettare alcuni eventi provenienti dalla tastiera e dal mouse. Verrà anche impostato un diverso aspetto del puntatore del mouse, impostato fra uno dei disegni previsti nel file header "x11/cursorfont.h":

Public Struct XEventStruct
  type As Integer
  serial As Long
  send_event As Boolean
  display As Pointer
  windowL As Long
  root As Long
  subwindow As Long
  timeL As Long
  x As Integer
  y As Integer
  x_root As Integer
  y_root As Integer
  state As Integer
  keycode As Integer
  same_screen As Boolean
End Struct

Public Struct XFontStruct
  ext_data As Long
  fid As Pointer
  direction As Byte
  min_char_or_byte2 As Byte
  max_char_or_byte2 As Byte
  min_byte1 As Byte
  max_byte1 As Byte
  all_chars_exist As Boolean
  default_char As Byte
  n_properties As Byte
  properties As Pointer
  min_bounds As Pointer
  max_bounds As Pointer
  per_char As Pointer
  ascent As Integer
  descent As Integer
End Struct


Private Const ExposureMask As Integer = 32768
Private Const KeyPressMask As Byte = 1
Private Const ButtonPressMask As Byte = 4

Private Enum KeyPress = 2, KeyRelease, ButtonPress, ButtonRelease, MotionNotify, EnterNotify, LeaveNotify, FocusIn, FocusOut, KeymapNotify, Expose, GraphicsExpose, NoExpose
Private Enum FillSolid = 0, FillTiled, FillStippled, FillOpaqueStippled   ' fillStyle

Private disp As Pointer
Private wId As Long
Private gc As Pointer


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

' 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)

' int XDefaultScreen (Display *display)
' returns the default screen number referenced by the XOpenDisplay function.
Private Extern XDefaultScreen(displayP As Pointer) As Integer

' unsigned long XWhitePixel (Display *display, int screen_number)
' returns the white pixel value for the specified screen.
Private Extern XWhitePixel(displayP As Pointer, screen_number As Integer) As Long

' unsigned long XBlackPixel (Display *display, int screen_number)
' returns the black pixel value for the specified screen.
Private Extern XBlackPixel(displayP As Pointer, screen_number As Integer) As Long

' Window XDefaultRootWindow(Display *display)
' Return the root window for the default screen.
Private Extern XDefaultRootWindow(displayP As Pointer) As Integer

' Window XCreateSimpleWindow(Display *display,  Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, unsigned long border, unsigned long background)
' creates an unmapped InputOutput subwindow for a specified parent window, returns the window ID of the created window.
Private Extern XCreateSimpleWindow(displayP As Pointer, parent As Long, x As Integer, y As Integer, width As Integer, height As Integer, border_width As Integer, border As Integer, background As Long) As Integer 

' XSetStandardProperties (Display *display, Window w, char *window_name, char *icon_name, Pixmap icon_pixmap, char **argv, int argc, XSizeHints *hints)
' specifies a minimum set of properties describing the simplest application.
Private Extern XSetStandardProperties(displayP As Pointer, w As Long, window_name As String, icon_name As String, icon_pixmap As Integer, argv As String, argc As Integer, hints As Pointer)

' XSelectInput (Display *display, Window w, long event_mask)
' requests that the X server report the events associated with the specified Event mask.
Private Extern XSelectInput(displayP As Pointer, w As Integer, event_mask As Long)

' 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, w As Integer, valuemask 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)

' char ** XListFonts(Display *display, char *pattern, int maxnames, int *actual_count_return)
' returns an array of available font names.
Private Extern XListFonts(displayP As Pointer, pattern As String, maxnames As Integer, actual_count_return As Pointer) As Pointer

' XFontStruct * XLoadQueryFont(Display *display, char *name)
' opens(loads)the specified font.
Private Extern XLoadQueryFont(displayP As Pointer, nameFont As String) As XFontStruct

' XSetFont(Display *display, GC gc, Font font)
' Assigns a Font to a Graphics Context.
Private Extern XSetFont(displayP As Pointer, gcP As Pointer, fontP As Pointer)

' XSetFillStyle(Display *display, GC gc, int fill_style)
' changes the fill style of GC.
Private Extern XSetFillStyle(displayP As Pointer, gc As Pointer, fill_style As Integer)

' XClearWindow(Display *display, Window w)
' clears the entire area in the specified window.
Private Extern XClearWindow(displayP As Pointer, w As Long)

' XMapRaised (Display *display, Window w)
' raises the specified window to the top of the stack.
Private Extern XMapRaised(displayP As Pointer, w As Long)

' Cursor XCreateFontCursor(Display *display, unsigned int shape)
' Provides a set of standard cursor shapes in a special font named cursor.
Private Extern XCreateFontCursor(displayP As Pointer, shape As Integer) As Integer

' XDefineCursor(Display *display, Window w, Cursor cursor)
' If a cursor is set, it will be used when the pointer is in the window.
Private Extern XDefineCursor(displayP As Pointer, w As Long, cursorI As Integer) As Integer

' XNextEvent (Display *display, XEvent *event_return)
' gets the next event and remove it from the queue
Private Extern XNextEvent(displayP As Pointer, event_return As XEventStruct)

' int XLookupString(XKeyEvent *event_struct, char *buffer_return, int bytes_buffer, KeySym *keysym_return, XComposeStatus *status_in_out)
' translates a key event to a KeySym and a string.
Private Extern XLookupString(event_struct As XEventStruct, buffer_return As Byte[], bytes_buffer As Integer, keysym_return As Pointer, status_in_out As Pointer) As Integer

' 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, w As Long, gcP As Pointer, x1 As Integer, y1 As Integer)

' XDrawLine(Display *display, Drawable d, GC gc, int x1, int y1, int x2, int y2)
' draws a line between the specified set of points (x1, y1) and (x2, y2).
Private Extern XDrawLine(displayP As Pointer, w As Long, gcP As Pointer, x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)

' XDrawRectangle(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height)
' draws the outlines of the specified rectangle.
Private Extern XDrawRectangle(displayP As Pointer, w As Integer, gcP As Pointer, xI As Integer, yI As Integer, widthI As Integer, heightI As Integer)

' XFillRectangle(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height)
' fills the specified rectangle
Private Extern XFillRectangle(displayP As Pointer, w As Long, gcP As Pointer, xI As Integer, yI As Integer, widthI As Integer, heightI As Integer)

' XDrawArc(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height, int angle1, int angle2)
' draws an arc.
Private Extern XDrawArc(displayP As Pointer, w As Long, gcP As Pointer, xI As Integer, yI As Integer, widthI As Integer, heightI As Integer, angle1 As Integer, angle2 As Integer)

' XFillArc(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height, int angle1, int angle2)
' fills the specified arc.
Private Extern XFillArc(displayP As Pointer, w As Long, gcP As Pointer, xI As Integer, yI As Integer, widthI As Integer, heightI As Integer, angle1 As Integer, angle2 As Integer)

' XDrawString(Display *display, Drawable d, GC gc, int x, int y, char *string, intlength)
' draws a text.
Private Extern XDrawString(displayP As Pointer, w As Long, gcP As Pointer, x As Integer, y As Integer, test$ As String, length 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)

' XDestroyWindow(Display *display, Window w)
' destroys the specified window as well as all of its subwindows
Private Extern XDestroyWindow(displayP As Pointer, w As Long)


' void exit(int status)
' Termina il programma. I buffer dei file vengono svuotati, i flussi sono chiusi.
Private Extern exitus(status As Integer) In "libc:6" Exec "exit"


Public Sub Main()

 Dim screen, key, cursor As Integer
 Dim pxW, pxB As Long
 Dim testo As New Byte[255]
 Dim ev As New XEventStruct
 Dim xfon As New XFontStruct
 Dim scriptum As String = "testo qualsiasi"


' Apre la connessione con il server display del sistema grafico X:
   disp = XOpenDisplay(Null)
   If IsNull(disp) Then Error.Raise("Impossibile aprire il server display !")

   screen = XDefaultScreen(disp)

   pxW = XWhitePixel(disp, screen)
    
   pxB = XBlackPixel(disp, screen)
    
' Crea la finestra secondo i parametri previsti dalla funzione.
' L'ultimo parametro imposta il colore di fondo della finestra:
   wId = XCreateSimpleWindow(disp, XDefaultRootWindow(disp), 0, 0, 300, 200, 5, pxW, &FF0000)
   Print "ID della finestra creata: "; Hex(wId, 6)
   
   XSetStandardProperties(disp, wId, "Prova creazione finestra", "Nome icona finestra", 0, Null, 0, Null)
   
' Dice al server display quali eventi deve vedere:
   XSelectInput(disp, wId, ExposureMask Or KeyPressMask Or ButtonPressMask)
   
' Crea un nuovo contesto grafico:
   gc = XCreateGC(disp, wId, 0, 0)
   If IsNull(gc) Then Error.Raise("Impossibile creare un nuovo contesto grafico !")

' Imposta il colore degli elementi grafici all'interno della finestra:
   XSetForeground(disp, gc, &00FF00)

   elencoFont()

' Imposta il font per i caratteri del testo grafico:
   xfon = XLoadQueryFont(disp, "*bitstream*")
   If IsNull(xFon) Then Error.Raise("Impossibile caricare il font !")
 
   XSetFont(disp, gc, xfon.fid)

   XSetFillStyle(disp, gc, FillSolid)
   
   redraw()
   
' Apre la finestra sullo schermo. Si può utilizzare anche la funzione "XMapWindow(display, w)":
   XMapRaised(disp, wId)

' Entrando il cursore del mouse nella finestra, esso cambia aspetto, impostando quello
' che nel file header ".../X11/cursorfont.h" ha il valore 10 tra quelli visibili nella pagina "http://tronche.com/gui/x/xlib/appendix/b/":
   cursor = XCreateFontCursor(disp, 10)

   XDefineCursor(disp, wId, cursor)


   While True

     XNextEvent(disp, ev)

     Select Case ev.type
         Case Expose
' La finestra mostrata deve essere ripulita:
           redraw()
' Disegna un punto all'interno del quadrato:
           XDrawPoint(disp, wId, gc, 70, 120)
' Disegna una linea:
           XDrawLine(disp, wId, gc, 10, 10, 40, 60)
' In questo caso disegna un quadrato:
           XDrawRectangle(disp, wId, gc, 50, 100, 40, 40)
' Disegna un rettangolo colorato di bianco:
           XFillRectangle(disp, wId, gc, 200, 30, 60, 40)
' Disegna un arco:
           XDrawArc(disp, wId, gc, 100, 150, 60, 40, 0, 360 * 20)
' Disegna un arco riempito di colore bianco:
           XFillArc(disp, wId, gc, 40, 20, 60, 40, 0, 360 * 20)
' Disegna un cerchio:
           XDrawArc(disp, wId, gc, 200, 100, 50, 50, 0, 360 * 64)
' Disegna un cerchio riempito di colore bianco:
           XFillArc(disp, wId, gc, 110, 40, 50, 50, 0, 360 * 64)
' Disegna una stringa di caratteri:
           XDrawString(disp, wId, gc, 20, 170, scriptum, Len(scriptum))

         Case KeyPress
           XLookupString(ev, testo, 255, VarPtr(key), Null)
           If testo[0] = Asc("q") Then
             chiude_X()
             Print "E' stato premuto il tasto: "; Chr(testo[0]), key
             Else
' Disegna il carattere del tasto premuto alle coordinate del puntatore del mouse:
               XDrawString(disp, wId, gc, ev.x, ev.y, Chr(key), 1)
           Endif

         Case ButtonPress     ' Indica le coordinate ove è stato premuto il tasto del mouse
           With ev
             Print "E' stato premuto il tasto del mouse alle seguenti coordinate:\n"; .x; " pixel dal margine sinistro della finestra;"
             Print .y; " pixel dal margine superiore della finestra;"
             Print .x_root; " pixel dal margine sinistro dello schermo;"
             Print .y_root; " pixel dal margine superiore dello schermo." 
           End With
           redraw()
       End Select

   Wend
   
End


Private Procedure elencoFont()

 Dim po As Pointer
 Dim num_fonts As Integer
 Dim st As Stream
 Dim j As Short
 Dim b As Byte
  
 
  po = XListFonts(disp, "*itstr*", 8196, VarPtr(num_fonts))
  If IsNull(po) Then Error.Raise("Impossibile caricare i font !")

  po = Pointer@(po)

' Dereferenziamo il "puntatore" mediante i "Memory Stream":
  st = Memory po For Read
 
  For j = 0 To 8196
    Seek #st, j
    Read #st, b
    If b = 0 Then
      Print
    Else
      Print Chr(b);
    Endif
  Next

  st.Close
  Free(po)

End

 
Private Procedure redraw()
 
' Pulisce la superficie della finestra da ogni elemento presente:
 XClearWindow(disp, wId)
 
End


Private Procedure chiude_X()

   XFreeGC(disp, gc)

' Chiude la finestra:
   XDestroyWindow(disp, wId)

   XCloseDisplay(disp)

   exitus(0)

End


Creare una semplice finestra colorata, con il puntatore del mouse avente un disegno impostato liberamente da noi

Public Struct XColor
 pixel As Long
 red As Short
 green As Short
 blue As Short
 flags As Byte
 pad As Byte
End Struct

Public Struct XEventStruct
  type As Integer
  serial As Long
  send_event As Boolean
  display As Pointer
  windowL As Long
  root As Long
  subwindow As Long
  timeL As Long
  x As Integer
  y As Integer
  x_root As Integer
  y_root As Integer
  state As Integer
  keycode As Integer
  same_screen As Boolean
End Struct


Library "libX11:6.3.0"

Private Const ButtonPressMask As Byte = 4
Private Enum KeyPress = 2, KeyRelease, ButtonPress, ButtonRelease, MotionNotify, EnterNotify, LeaveNotify,
                           FocusIn, FocusOut, KeymapNotify, Expose, GraphicsExpose, NoExpose

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

' Screen *XDefaultScreenOfDisplay(Display *display)
' Returns a pointer to the default screen.
Private Extern XDefaultScreenOfDisplay(displayP As Pointer) As Pointer
 
' Window XDefaultRootWindow(Display *display)
' Return the root window for the default screen.
Private Extern XDefaultRootWindow(displayP As Pointer) As Integer

' Window XCreateSimpleWindow(Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, unsigned long border, unsigned long background)
' creates an unmapped InputOutput subwindow for a specified parent window, returns the window ID of the created window.
Private Extern XCreateSimpleWindow(displayP As Pointer, parent As Long, x As Integer, y As Integer, width As Integer, height As Integer, border_width As Integer, border As Integer, background As Long) As Integer
 
' XMapRaised (Display *display, Window w)
' raises the specified window to the top of the stack.
Private Extern XMapRaised(displayP As Pointer, w As Long)

' Pixmap XCreatePixmap(display *display, Drawable d, unsigned int width, unsigned int height, unsigned int depth)
' Creates a pixmap of the width, height, and depth you specified and returns a pixmap ID that identifies it.
Private Extern XCreatePixmap(displayP As Pointer, w As Long, width As Integer, height As Integer, depth As Integer) As Pointer

' Status XLookupColor(Display *display, Colormap colormap, char *color_name, XColor *exact_def_return, XColor *screen_def_return)
' Looks up the string name of a color with respect to the screen associated with the specified colormap.
Private Extern XLookupColor(displayP As Pointer, colormap As Pointer, color_name As String, exact_def_return As XColor, screen_def_return As XColor) As Integer

' Colormap XDefaultColormapOfScreen(Screen *screen)
' Returns the default colormap ID on the specified screen.
Private Extern XDefaultColormapOfScreen(scr As Pointer) As Pointer

' Pixmap XCreatePixmapFromBitmapData(display *display, Drawable d, char *data, unsigned int width, unsigned int height, unsigned long fg, unsigned long bg, unsigned int depth)
' Creates a pixmap of the given depth and then does a bitmap-format XPutImage() of the data into it.
Private Extern XCreatePixmapFromBitmapData(displayP As Pointer, w As Pointer, data As Byte[], width As Integer, height As Integer, fg As Long, bg As Long, depth As Integer) As Pointer

' Cursor XCreatePixmapCursor(Display *display, Pixmap source, Pixmap mask, XColor *foreground_color, XColor *background_color, unsigned int x, unsigned int y)
' Creates a cursor and returns the cursor ID associated with it.
Private Extern XCreatePixmapCursor(displayP As Pointer, source As Pointer, mask As Pointer, foreground_color As XColor, background_color As XColor, x As Integer, y As Integer) As Integer

' XDefineCursor(Display *display, Window w, Cursor cursor)
' If a cursor is set, it will be used when the pointer is in the window.
Private Extern XDefineCursor(displayP As Pointer, w As Long, cursorI As Integer) As Integer
 
' XSelectInput (Display *display, Window w, long event_mask)
' requests that the X server report the events associated with the specified Event mask.
Private Extern XSelectInput(displayP As Pointer, w As Long, event_mask As Long)
 
' XNextEvent (Display *display, XEvent *event_return)
' gets the next event and remove it from the queue
Private Extern XNextEvent(displayP As Pointer, event_return As XEventStruct)

' XDestroyWindow(Display *display, Window w)
' destroys the specified window as well as all of its subwindows
Private Extern XDestroyWindow(displayP As Pointer, w As Long)

' 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)
 
' void exit(int status)
' Terminates the calling process immediately. Any open file descriptors belonging to the process are closed.
Private Extern exit_C(status As Integer) In "libc:6" Exec "exit"


Public Sub Main()

 Dim dsp, screen, pixmap, matita, matita_mask As Pointer
 Dim id, cursore_matita As Integer
 Dim inut, cursore_primopiano, sfondo_cursore As New XColor
 Dim ev As New XEventStruct
 Dim matita_bits As Byte[] = [&00, &70, &00, &88, &00, &8C, &00, &96, &00, &69, &80, &30, &40, &10, &20, &08,
                              &10, &04, &08, &02, &08, &01, &94, &00, &64, &00, &1E, &00, &06, &00, &00, &00]
 Dim matita_mask_bits As Byte[] = [&00, &F8, &00, &FC, &00, &FE, &00, &FF, &80, &FF, &C0, &7F, &E0, &3F, &F0,
                                   &1F, &F8, &0F, &FC, &07, &FC, &03, &FE, &01, &FE, &00, &7F, &00, &1F, &00, &07, &00]
 Dim matita_width As Integer = 16
 Dim matita_height As Integer = 16
 Dim matita_X As Integer = 1
 Dim matita_Y As Integer = 15

  dsp = XOpenDisplay(Null)
 
  screen = XDefaultScreenOfDisplay(dsp)

  id = XCreateSimpleWindow(dsp, XDefaultRootWindow(dsp), 0, 0, 300, 200, 0, 0, &FF0000)
  Print "ID della finestra creata: "; Hex(id, 6)

  XMapRaised(dsp, id)

' Crea le pixmap per il cursore del mouse:
  pixmap = XCreatePixmap(dsp, XDefaultRootWindow(dsp), 1, 1, 1)
  
  XLookupColor(dsp, XDefaultColormapOfScreen(screen), "yellow", inut, cursore_primopiano)
  XLookupColor(dsp, XDefaultColormapOfScreen(screen), "blue", inut, sfondo_cursore)

  matita = XCreatePixmapFromBitmapData(dsp, pixmap, matita_bits, matita_width, matita_height, 1, 0, 1)
  matita_mask = XCreatePixmapFromBitmapData(dsp, pixmap, matita_mask_bits, matita_width, matita_height, 1, 0, 1)
   
  cursore_matita = XCreatePixmapCursor(dsp, matita, matita_mask, cursore_primopiano, sfondo_cursore, matita_X, matita_Y)

  XDefineCursor(dsp, id, cursore_matita)


  XSelectInput(dsp, id, ButtonPressMask)

  While True
    XNextEvent(dsp, ev)
    If ev.type = ButtonPress Then chiude_X(dsp, id)
  Wend

End


Private Procedure chiude_X(disp_ch As Pointer, chiudId As Integer)

' Chiude la finestra:
  XDestroyWindow(disp_ch, chiudId)

  XCloseDisplay(disp_ch)

  exit_C(0)

End



Riferimenti