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

Da Gambas-it.org - Wikipedia.
Riga 25: Riga 25:
 
  <FONT color=gray>' ''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)''
 
  <FONT color=gray>' ''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.''</font>
 
  ' ''creates an unmapped InputOutput subwindow for a specified parent window, returns the window ID of the created window.''</font>
  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 Integer) As Integer
+
  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
 
   
 
   
 
  <FONT color=gray>' ''XSelectInput (Display *display, Window w, long event_mask)''
 
  <FONT color=gray>' ''XSelectInput (Display *display, Window w, long event_mask)''
Riga 55: Riga 55:
 
   
 
   
 
   Dim disp, ev As Pointer
 
   Dim disp, ev As Pointer
   Dim screen, id As Integer
+
   Dim screen As Integer
 +
  Dim id As Long
 
   
 
   
 
  <FONT color=gray>' ''Apre la connessione con il server display del sistema grafico X:''</font>
 
  <FONT color=gray>' ''Apre la connessione con il server display del sistema grafico X:''</font>
Riga 154: Riga 155:
 
   
 
   
 
  Private disp As Pointer
 
  Private disp As Pointer
  Private cswId As Integer
+
  Private wId As Long
 
  Private gc As Pointer
 
  Private gc As Pointer
 
   
 
   
Riga 160: Riga 161:
 
  Library "libX11:6.3.0"
 
  Library "libX11:6.3.0"
 
   
 
   
  <FONT color=gray>' ''Display *XOpenDisplay(disp)''
+
  <FONT color=gray>' ''Display *XOpenDisplay(char *display_name)''
 
  ' ''Opens a connection to the X server that controls a display.''</font>
 
  ' ''Opens a connection to the X server that controls a display.''</font>
 
  Private Extern XOpenDisplay(display$ As String) As Pointer
 
  Private Extern XOpenDisplay(display$ As String) As Pointer
 
   
 
   
  <FONT color=gray>' ''XCloseDisplay(display)''
+
  <FONT color=gray>' ''XCloseDisplay(Display *display)''
 
  ' ''Closes the connection to the X server for the display specified in the Display structure and destroys all windows.''</font>
 
  ' ''Closes the connection to the X server for the display specified in the Display structure and destroys all windows.''</font>
 
  Private Extern XCloseDisplay(displayP As Pointer)
 
  Private Extern XCloseDisplay(displayP As Pointer)
 
   
 
   
  <FONT color=gray>' ''int XDefaultScreen (display)''
+
  <FONT color=gray>' ''int XDefaultScreen (Display *display)''
 
  ' ''returns the default screen number referenced by the XOpenDisplay function.''</font>
 
  ' ''returns the default screen number referenced by the XOpenDisplay function.''</font>
 
  Private Extern XDefaultScreen(displayP As Pointer) As Integer
 
  Private Extern XDefaultScreen(displayP As Pointer) As Integer
 
   
 
   
  <FONT color=gray>' ''unsigned long XWhitePixel (display, screen_number)''
+
  <FONT color=gray>' ''unsigned long XWhitePixel (Display *display, int screen_number)''
 
  ' ''returns the white pixel value for the specified screen.''</font>
 
  ' ''returns the white pixel value for the specified screen.''</font>
 
  Private Extern XWhitePixel(displayP As Pointer, screen_number As Integer) As Long
 
  Private Extern XWhitePixel(displayP As Pointer, screen_number As Integer) As Long
 
   
 
   
  <FONT color=gray>' ''unsigned long XBlackPixel (display, screen_number)''
+
  <FONT color=gray>' ''unsigned long XBlackPixel (Display *display, int screen_number)''
 
  ' ''returns the black pixel value for the specified screen.''</font>
 
  ' ''returns the black pixel value for the specified screen.''</font>
 
  Private Extern XBlackPixel(displayP As Pointer, screen_number As Integer) As Long
 
  Private Extern XBlackPixel(displayP As Pointer, screen_number As Integer) As Long
 
   
 
   
  <FONT color=gray>' ''Window XDefaultRootWindow(display)''
+
  <FONT color=gray>' ''Window XDefaultRootWindow(Display *display)''
 
  ' ''Return the root window for the default screen.''</font>
 
  ' ''Return the root window for the default screen.''</font>
 
  Private Extern XDefaultRootWindow(displayP As Pointer) As Integer
 
  Private Extern XDefaultRootWindow(displayP As Pointer) As Integer
 
   
 
   
  <FONT color=gray>' ''Window XCreateSimpleWindow(display, parent, x, y, width, height, border_width, border, background)''
+
  <FONT color=gray>' ''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.''</font>
 
  ' ''creates an unmapped InputOutput subwindow for a specified parent window, returns the window ID of the created window.''</font>
  Private Extern XCreateSimpleWindow(displayP As Pointer, parent As Integer, x As Integer, y As Integer, width As Integer, height As Integer, border_width As Integer, border As Integer, background As Integer) As Integer  
+
  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  
 
   
 
   
  <FONT color=gray>' ''XSetStandardProperties (display, w, window_name, icon_name, icon_pixmap, argv, argc, hints)''
+
  <FONT color=gray>' ''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.''</font>
 
  ' ''specifies a minimum set of properties describing the simplest application.''</font>
  Private Extern XSetStandardProperties(displayP As Pointer, w As Integer, window_name As String, icon_name As String, icon_pixmap As Integer, argv As String, argc As Integer, hints As Pointer)
+
  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)
 
   
 
   
  <FONT color=gray>' ''XSelectInput (display, w, event_mask)''
+
  <FONT color=gray>' ''XSelectInput (Display *display, Window w, long event_mask)''
 
  ' ''requests that the X server report the events associated with the specified Event mask.''</font>
 
  ' ''requests that the X server report the events associated with the specified Event mask.''</font>
 
  Private Extern XSelectInput(displayP As Pointer, w As Integer, event_mask As Long)
 
  Private Extern XSelectInput(displayP As Pointer, w As Integer, event_mask As Long)
 
   
 
   
  <FONT color=gray>' ''GC XCreateGC(display, d, valuemask, values)''
+
  <FONT color=gray>' ''GC XCreateGC(Display *display, Drawable d, unsigned long valuemask, XGCValues *values)''
 
  ' ''creates a graphics context and returns a GC.''</font>
 
  ' ''creates a graphics context and returns a GC.''</font>
 
  Private Extern XCreateGC(displayP As Pointer, w As Integer, valuemask As Long, values As Pointer) As Pointer
 
  Private Extern XCreateGC(displayP As Pointer, w As Integer, valuemask As Long, values As Pointer) As Pointer
 
   
 
   
  <FONT color=gray>' ''XSetForeground (display, gc, foreground)''
+
  <FONT color=gray>' ''XSetForeground (Display *display, GC gc, unsigned long foreground)''
 
  ' ''sets the foreground.''</font>
 
  ' ''sets the foreground.''</font>
  Private Extern XSetForeground(displayP As Pointer, gc As Pointer, foreground As Integer)
+
  Private Extern XSetForeground(displayP As Pointer, gc As Pointer, foreground As Long)
 
   
 
   
  <FONT color=gray>' ''char * * XListFonts(display, pattern, maxnames, actual_count_return)''
+
  <FONT color=gray>' ''char ** XListFonts(Display *display, char *pattern, int maxnames, int *actual_count_return)''
 
  ' ''returns an array of available font names.''</font>
 
  ' ''returns an array of available font names.''</font>
 
  Private Extern XListFonts(displayP As Pointer, pattern As String, maxnames As Integer, actual_count_return As Pointer) As Pointer
 
  Private Extern XListFonts(displayP As Pointer, pattern As String, maxnames As Integer, actual_count_return As Pointer) As Pointer
 
   
 
   
  <FONT color=gray>' ''XFontStruct * XLoadQueryFont(display, name)''
+
  <FONT color=gray>' ''XFontStruct * XLoadQueryFont(Display *display, char *name)''
 
  ' ''opens(loads)the specified font.''</font>
 
  ' ''opens(loads)the specified font.''</font>
 
  Private Extern XLoadQueryFont(displayP As Pointer, nameFont As String) As XFontStruct
 
  Private Extern XLoadQueryFont(displayP As Pointer, nameFont As String) As XFontStruct
 
   
 
   
  <FONT color=gray>' ''XSetFont(display, gc, font)''
+
  <FONT color=gray>' ''XSetFont(Display *display, GC gc, Font font)''
 
  ' ''Assigns a Font to a Graphics Context.''</font>
 
  ' ''Assigns a Font to a Graphics Context.''</font>
 
  Private Extern XSetFont(displayP As Pointer, gcP As Pointer, fontP As Pointer)
 
  Private Extern XSetFont(displayP As Pointer, gcP As Pointer, fontP As Pointer)
 
   
 
   
  <FONT color=gray>' ''XSetFillStyle(display, gc, fill_style)''
+
  <FONT color=gray>' ''XSetFillStyle(Display *display, GC gc, int fill_style)''
 
  ' ''changes the fill style of GC.''</font>
 
  ' ''changes the fill style of GC.''</font>
 
  Private Extern XSetFillStyle(displayP As Pointer, gc As Pointer, fill_style As Integer)
 
  Private Extern XSetFillStyle(displayP As Pointer, gc As Pointer, fill_style As Integer)
 
   
 
   
  <FONT color=gray>' ''XClearWindow(display, w)''
+
  <FONT color=gray>' ''XClearWindow(Display *display, Window w)''
 
  ' ''clears the entire area in the specified window.''</font>
 
  ' ''clears the entire area in the specified window.''</font>
  Private Extern XClearWindow(displayP As Pointer, w As Integer)
+
  Private Extern XClearWindow(displayP As Pointer, w As Long)
 
   
 
   
  <FONT color=gray>' ''XMapRaised (display, w)''
+
  <FONT color=gray>' ''XMapRaised (Display *display, Window w)''
 
  ' ''raises the specified window to the top of the stack.''</font>
 
  ' ''raises the specified window to the top of the stack.''</font>
  Private Extern XMapRaised(displayP As Pointer, w As Integer)
+
  Private Extern XMapRaised(displayP As Pointer, w As Long)
 
   
 
   
  <FONT color=gray>' ''Cursor XCreateFontCursor(display, shape)''
+
  <FONT color=gray>' ''Cursor XCreateFontCursor(Display *display, unsigned int shape)''
 
  ' ''Provides a set of standard cursor shapes in a special font named cursor.''</font>
 
  ' ''Provides a set of standard cursor shapes in a special font named cursor.''</font>
 
  Private Extern XCreateFontCursor(displayP As Pointer, shape As Integer) As Integer
 
  Private Extern XCreateFontCursor(displayP As Pointer, shape As Integer) As Integer
 
   
 
   
  <FONT color=gray>' ''XDefineCursor(display, w, cursor)''
+
  <FONT color=gray>' ''XDefineCursor(Display *display, Window w, Cursor cursor)''
 
  ' ''If a cursor is set, it will be used when the pointer is in the window.''</font>
 
  ' ''If a cursor is set, it will be used when the pointer is in the window.''</font>
  Private Extern XDefineCursor(displayP As Pointer, w As Integer, cursorI As Integer) As Integer
+
  Private Extern XDefineCursor(displayP As Pointer, w As Long, cursorI As Integer) As Integer
 
   
 
   
  <FONT color=gray>' ''XNextEvent (display, event_return)''
+
  <FONT color=gray>' ''XNextEvent (Display *display, XEvent *event_return)''
 
  ' ''gets the next event and remove it from the queue''</font>
 
  ' ''gets the next event and remove it from the queue''</font>
 
  Private Extern XNextEvent(displayP As Pointer, event_return As XEventStruct)
 
  Private Extern XNextEvent(displayP As Pointer, event_return As XEventStruct)
 
   
 
   
  <FONT color=gray>' ''int XLookupString(event_struct, buffer_return, bytes_buffer, keysym_return, status_in_out)''
+
  <FONT color=gray>' ''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.''</font>
 
  ' ''translates a key event to a KeySym and a string.''</font>
 
  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
 
  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
 
   
 
   
  <FONT color=gray>' ''XDrawPoint(display, d, gc, x, y)''
+
  <FONT color=gray>' ''XDrawPoint(Display *display, Drawable d, GC gc, int x, int y)''
 
  ' ''draws a single point into the specified drawable''</font>
 
  ' ''draws a single point into the specified drawable''</font>
  Private Extern XDrawPoint(displayP As Pointer, w As Integer, gcP As Pointer, x1 As Integer, y1 As Integer)
+
  Private Extern XDrawPoint(displayP As Pointer, w As Long, gcP As Pointer, x1 As Integer, y1 As Integer)
 
   
 
   
  <FONT color=gray>' ''XDrawLine(display, d, gc, x1, y1, x2, y2)''
+
  <FONT color=gray>' ''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).''</font>
 
  ' ''draws a line between the specified set of points (x1, y1) and (x2, y2).''</font>
  Private Extern XDrawLine(displayP As Pointer, w As Integer, gcP As Pointer, x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)
+
  Private Extern XDrawLine(displayP As Pointer, w As Long, gcP As Pointer, x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)
 
   
 
   
  <FONT color=gray>' ''XDrawRectangle(display, d, gc, x, y, width, height)''
+
  <FONT color=gray>' ''XDrawRectangle(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height)''
 
  ' ''draws the outlines of the specified rectangle.''</font>
 
  ' ''draws the outlines of the specified rectangle.''</font>
 
  Private Extern XDrawRectangle(displayP As Pointer, w As Integer, gcP As Pointer, xI As Integer, yI As Integer, widthI As Integer, heightI As Integer)
 
  Private Extern XDrawRectangle(displayP As Pointer, w As Integer, gcP As Pointer, xI As Integer, yI As Integer, widthI As Integer, heightI As Integer)
 
   
 
   
  <FONT color=gray>' ''XFillRectangle(display, d, gc, x, y, width, height)''
+
  <FONT color=gray>' ''XFillRectangle(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height)''
 
  ' ''fills the specified rectangle''</font>
 
  ' ''fills the specified rectangle''</font>
  Private Extern XFillRectangle(displayP As Pointer, w As Integer, gcP As Pointer, xI As Integer, yI As Integer, widthI As Integer, heightI As Integer)
+
  Private Extern XFillRectangle(displayP As Pointer, w As Long, gcP As Pointer, xI As Integer, yI As Integer, widthI As Integer, heightI As Integer)
 
   
 
   
  <FONT color=gray>' ''XDrawArc(display, d, gc, x, y, width, height, angle1, angle2)''
+
  <FONT color=gray>' ''XDrawArc(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height, int angle1, int angle2)''
 
  ' ''draws an arc.''</font>
 
  ' ''draws an arc.''</font>
  Private Extern XDrawArc(displayP As Pointer, w As Integer, gcP As Pointer, xI As Integer, yI As Integer, widthI As Integer, heightI As Integer, angle1 As Integer, angle2 As Integer)
+
  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)
 
   
 
   
  <FONT color=gray>' ''XFillArc(display, d, gc, x, y, width, height, angle1, angle2)''
+
  <FONT color=gray>' ''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.''</font>
 
  ' ''fills the specified arc.''</font>
  Private Extern XFillArc(displayP As Pointer, w As Integer, gcP As Pointer, xI As Integer, yI As Integer, widthI As Integer, heightI As Integer, angle1 As Integer, angle2 As Integer)
+
  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)
 
   
 
   
  <FONT color=gray>' ''XDrawString(display, d, gc, x, y, string, length)''
+
  <FONT color=gray>' ''XDrawString(Display *display, Drawable d, GC gc, int x, int y, char *string, intlength)''
 
  ' ''draws a text.''</font>
 
  ' ''draws a text.''</font>
  Private Extern XDrawString(displayP As Pointer, w As Integer, gcP As Pointer, x As Integer, y As Integer, test$ As String, length As Integer)
+
  Private Extern XDrawString(displayP As Pointer, w As Long, gcP As Pointer, x As Integer, y As Integer, test$ As String, length As Integer)
 
   
 
   
  <FONT color=gray>' ''XFreeGC(display, gc)''
+
  <FONT color=gray>' ''XFreeGC(Display *display, GC gc)''
 
  ' ''destroys the specified GC as well as all the associated storage.''</font>
 
  ' ''destroys the specified GC as well as all the associated storage.''</font>
 
  Private Extern XFreeGC(displayP As Pointer, gcP As Pointer)
 
  Private Extern XFreeGC(displayP As Pointer, gcP As Pointer)
 
   
 
   
  <FONT color=gray>' ''XDestroyWindow(display, w)''
+
  <FONT color=gray>' ''XDestroyWindow(Display *display, Window w)''
 
  ' ''destroys the specified window as well as all of its subwindows''</font>
 
  ' ''destroys the specified window as well as all of its subwindows''</font>
  Private Extern XDestroyWindow(displayP As Pointer, w As Integer)
+
  Private Extern XDestroyWindow(displayP As Pointer, w As Long)
 
   
 
   
 
   
 
   
Riga 308: Riga 309:
 
  <FONT color=gray>' ''Crea la finestra secondo i parametri previsti dalla funzione.''
 
  <FONT color=gray>' ''Crea la finestra secondo i parametri previsti dalla funzione.''
 
  ' ''L'ultimo parametro imposta il colore di fondo della finestra:''</font>
 
  ' ''L'ultimo parametro imposta il colore di fondo della finestra:''</font>
     cswId = XCreateSimpleWindow(disp, XDefaultRootWindow(disp), 0, 0, 300, 200, 5, pxW, &FF0000)
+
     wId = XCreateSimpleWindow(disp, XDefaultRootWindow(disp), 0, 0, 300, 200, 5, pxW, &FF0000)
     Print "ID della finestra creata: "; Hex(cswId, 6)
+
     Print "ID della finestra creata: "; Hex(wId, 6)
 
      
 
      
     XSetStandardProperties(disp, cswId, "Prova creazione finestra", "Nome icona finestra", 0, Null, 0, Null)
+
     XSetStandardProperties(disp, wId, "Prova creazione finestra", "Nome icona finestra", 0, Null, 0, Null)
 
      
 
      
 
  <FONT color=gray>' ''Dice al server display quali eventi deve vedere:''</font>
 
  <FONT color=gray>' ''Dice al server display quali eventi deve vedere:''</font>
     XSelectInput(disp, cswId, ExposureMask Or KeyPressMask Or ButtonPressMask)
+
     XSelectInput(disp, wId, ExposureMask Or KeyPressMask Or ButtonPressMask)
 
      
 
      
 
  <FONT color=gray>' ''Crea un nuovo contesto grafico:''</font>
 
  <FONT color=gray>' ''Crea un nuovo contesto grafico:''</font>
     gc = XCreateGC(disp, cswId, 0, Null)
+
     gc = XCreateGC(disp, wId, 0, Null)
 
     If IsNull(gc) Then Error.Raise("Impossibile creare un nuovo contesto grafico !")
 
     If IsNull(gc) Then Error.Raise("Impossibile creare un nuovo contesto grafico !")
 
   
 
   
Riga 336: Riga 337:
 
      
 
      
 
  <FONT color=gray>' ''Apre la finestra sullo schermo. Si può utilizzare anche la funzione "XMapWindow(display, w)":''</font>
 
  <FONT color=gray>' ''Apre la finestra sullo schermo. Si può utilizzare anche la funzione "XMapWindow(display, w)":''</font>
     XMapRaised(disp, cswId)
+
     XMapRaised(disp, wId)
 
   
 
   
 
  <FONT color=gray>' ''Entrando il cursore del mouse nella finestra, esso cambia aspetto, impostando quello''
 
  <FONT color=gray>' ''Entrando il cursore del mouse nella finestra, esso cambia aspetto, impostando quello''
Riga 342: Riga 343:
 
     cursor = XCreateFontCursor(disp, 10)
 
     cursor = XCreateFontCursor(disp, 10)
 
   
 
   
     XDefineCursor(disp, cswId, cursor)
+
     XDefineCursor(disp, wId, cursor)
 
   
 
   
 
   
 
   
Riga 354: Riga 355:
 
             redraw()
 
             redraw()
 
  <FONT color=gray>' ''Disegna un punto all'interno del quadrato:''</font>
 
  <FONT color=gray>' ''Disegna un punto all'interno del quadrato:''</font>
             XDrawPoint(disp, cswId, gc, 70, 120)
+
             XDrawPoint(disp, wId, gc, 70, 120)
 
  <FONT color=gray>' ''Disegna una linea:''</font>
 
  <FONT color=gray>' ''Disegna una linea:''</font>
             XDrawLine(disp, cswId, gc, 10, 10, 40, 60)
+
             XDrawLine(disp, wId, gc, 10, 10, 40, 60)
 
  <FONT color=gray>' ''In questo caso disegna un quadrato:''</font>
 
  <FONT color=gray>' ''In questo caso disegna un quadrato:''</font>
             XDrawRectangle(disp, cswId, gc, 50, 100, 40, 40)
+
             XDrawRectangle(disp, wId, gc, 50, 100, 40, 40)
 
  <FONT color=gray>' ''Disegna un rettangolo colorato di bianco:''</font>
 
  <FONT color=gray>' ''Disegna un rettangolo colorato di bianco:''</font>
             XFillRectangle(disp, cswId, gc, 200, 30, 60, 40)
+
             XFillRectangle(disp, wId, gc, 200, 30, 60, 40)
 
  <FONT color=gray>' ''Disegna un arco:''</font>
 
  <FONT color=gray>' ''Disegna un arco:''</font>
             XDrawArc(disp, cswId, gc, 100, 150, 60, 40, 0, 360 * 20)
+
             XDrawArc(disp, wId, gc, 100, 150, 60, 40, 0, 360 * 20)
 
  <FONT color=gray>' ''Disegna un arco riempito di colore bianco:''</font>
 
  <FONT color=gray>' ''Disegna un arco riempito di colore bianco:''</font>
             XFillArc(disp, cswId, gc, 40, 20, 60, 40, 0, 360 * 20)
+
             XFillArc(disp, wId, gc, 40, 20, 60, 40, 0, 360 * 20)
 
  <FONT color=gray>' ''Disegna un cerchio:''</font>
 
  <FONT color=gray>' ''Disegna un cerchio:''</font>
             XDrawArc(disp, cswId, gc, 200, 100, 50, 50, 0, 360 * 64)
+
             XDrawArc(disp, wId, gc, 200, 100, 50, 50, 0, 360 * 64)
 
  <FONT color=gray>' ''Disegna un cerchio riempito di colore bianco:''</font>
 
  <FONT color=gray>' ''Disegna un cerchio riempito di colore bianco:''</font>
             XFillArc(disp, cswId, gc, 110, 40, 50, 50, 0, 360 * 64)
+
             XFillArc(disp, wId, gc, 110, 40, 50, 50, 0, 360 * 64)
 
  <FONT color=gray>' ''Disegna una stringa di caratteri:''</font>
 
  <FONT color=gray>' ''Disegna una stringa di caratteri:''</font>
             XDrawString(disp, cswId, gc, 20, 170, scriptum, Len(scriptum))
+
             XDrawString(disp, wId, gc, 20, 170, scriptum, Len(scriptum))
 
   
 
   
 
           Case KeyPress
 
           Case KeyPress
Riga 379: Riga 380:
 
               Else
 
               Else
 
  <FONT color=gray>' ''Disegna il carattere del tasto premuto alle coordinate del puntatore del mouse:''</font>
 
  <FONT color=gray>' ''Disegna il carattere del tasto premuto alle coordinate del puntatore del mouse:''</font>
                 XDrawString(disp, cswId, gc, ev.x, ev.y, Chr(key), 1)
+
                 XDrawString(disp, wId, gc, ev.x, ev.y, Chr(key), 1)
 
             Endif
 
             Endif
 
   
 
   
Riga 433: Riga 434:
 
    
 
    
 
  <FONT color=gray>' ''Pulisce la superficie della finestra da ogni elemento presente:''</font>
 
  <FONT color=gray>' ''Pulisce la superficie della finestra da ogni elemento presente:''</font>
   XClearWindow(disp, cswId)
+
   XClearWindow(disp, wId)
 
    
 
    
 
  '''End'''
 
  '''End'''
Riga 443: Riga 444:
 
   
 
   
 
  <FONT color=gray>' ''Chiude la finestra:''</font>
 
  <FONT color=gray>' ''Chiude la finestra:''</font>
     XDestroyWindow(disp, cswId)
+
     XDestroyWindow(disp, wId)
 
   
 
   
 
     XCloseDisplay(disp)
 
     XCloseDisplay(disp)

Versione delle 10:47, 24 nov 2014

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"


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

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

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

  screen = XDefaultScreen(disp)
  Print "Schermo num. : "; screen
  
' 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


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:

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, Null)
   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


Riferimenti