Window creation/X11: Difference between revisions

Added Yabasic
No edit summary
(Added Yabasic)
 
(7 intermediate revisions by 4 users not shown)
Line 9:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program creatFenX1164.s */
Line 156:
.include "../includeARM64.inc"
 
</syntaxhighlight>
</lang>
 
=={{header|ALGOL 68}}==
Line 163:
Using the X11 & plotutil libraries is not part of any of the original UNESCO/IFIP [[ALGOL 68]]
reports. As at December 2008 only [[ALGOL 68G]] comes with these built in.
<langsyntaxhighlight lang="algol68">FILE window;
draw device (window, "X", "600x400");
open (window, "Hello, World!", stand draw channel);
Line 172:
draw show (window);
VOID (read char);
close (window)</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
Line 650:
bx lr @ leave function
iMagicNumber: .int 0xCCCCCCCD
</syntaxhighlight>
</lang>
 
 
=={{header|BaCon}}==
 
<syntaxhighlight lang="c">
<lang c>
'--- added a flush to exit cleanly
PRAGMA LDFLAGS `pkg-config --cflags --libs x11`
Line 719:
FLUSH(d)
CLOSE_DISPLAY(d)
</langsyntaxhighlight>
 
=={{header|C}}==
Line 728:
* gcc hello-x.c -L/usr/X11R6/lib -lX11 -o hello-x
 
<langsyntaxhighlight lang="c">#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
Line 764:
XCloseDisplay(d);
return 0;
}</langsyntaxhighlight>
 
=== XCB ===
Line 772:
* gcc -o helloxcb helloxcb.c -lxcb
 
<langsyntaxhighlight lang="c">#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Line 854:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|COBOL}}==
Tested with GnuCOBOL, and only on 64bit architecture, GNU/Linux. Nods to the C XLib version.
 
<langsyntaxhighlight lang="cobol"> identification division.
program-id. x11-hello.
installation. cobc -x x11-hello.cob -lX11
Line 1,033:
 
goback.
end program x11-hello.</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
Line 1,046:
This example uses CLX, which is the de facto standard X11 library for Common Lisp. CLX is not a binding to Xlib; it is a Lisp library implementing the X11 protocol.
 
<langsyntaxhighlight lang="lisp">;;; Single-file/interactive setup; large applications should define an ASDF system instead
 
(let* ((display (open-default-display))
Line 1,076:
(close-display display)))
 
</syntaxhighlight>
</lang>
=={{header|Forth}}==
Running Ubuntu 20.04 64-bit
<lang Forth>
Using : Gforth 0.7.9_20211014
 
<syntaxhighlight lang="forth">
warnings off
require xlib.fs
 
0 value X11-D \ Display
0 value X11-S \ Screen
0 value X11-root
0 value X11-GC
0 value X11-W \ Window
0 value X11-Black
0 value X11-White
Line 1,102 ⟶ 1,105:
: open-X11 ( -- )
X11-D 0= if 0 XOpendisplay to X11-D
X11-D 0= abort" can't connect to X server"
X11-D XDefaultscreen to X11-S
X11-D-S XRootwindow to X11-root
X11-D-S XDefaultGC to X11-GC
X11-D-S XBlackPixel to X11-Black
X11-D-S XWhitePixel to X11-White
then
X11-W 0= if X11-D X11-root X11-top X11-left 400 220 0 0 $808080 XCreateSimplewindow to X11-W
X11-W 0= abort" failed to create X11-window"
X11-D-W $28043 XSelectInput drop
X11-D s" WM_DELETE_WEINDOW" 1 XInternAtom wm_delete !
X11-D-W wm_delete 1 XSetWMProtocols drop
X11-D-W XMapwindow drop
X11-D XFlush drop
then ;
 
: close-graphics ( -- )
X11-W if X11-D-W XDestroywindow drop 0 to X11-W
then
X11-D if X11-D XClosedisplay 0 to X11-D
then ;
 
: foreground >r X11-D-G r> XSetForeground drop ;
: background >r X11-D-G r> XSetBackground drop ;
: keysym X11-ev 0 XLookupKeysym ;
 
: ev-loop
begin X11-D X11-ev XNextEvent throw
X11-White foreground
X11-Black background
X11-D-W-G 100 100 s" Hello World" XDrawString drop
X11-D-W-G 100 120 150 25 XDrawRectangle drop
X11-D-W-G 110 135 s" Press ESC to exit ..." XDrawString drop
case X11-ev @ $ffffffff and
3 of keysym XK_Escape = if exit then endof
endcase
again ;
\ #### Test #####
 
0 open-X11
ev-loop
close-graphics
bye
</syntaxhighlight>
 
=={{header|FreeBASIC}}==
=== Xlib ===
{{libheader|Xlib}}
<syntaxhighlight lang="vbnet">#include once "X11/Xlib.bi"
 
Dim As Display Ptr dpy
Dim As Window win
Dim As GC gc
Dim As XEvent ev
 
dpy = XOpenDisplay(NULL)
win = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy), 0, 0, 400, 300, 0, 0, 0)
gc = XCreateGC(dpy, win, 0, NULL)
XSelectInput(dpy, win, ExposureMask Or KeyPressMask)
XMapWindow(dpy, win)
 
While XNextEvent(dpy, @ev) = 0
If ev.type = Expose Then
XDrawString(dpy, win, gc, 200, 150, "Hello World", 11)
EndIf
Wend
 
XCloseDisplay(dpy)</syntaxhighlight>
 
</lang>
=={{header|Go}}==
{{trans|C}}
<langsyntaxhighlight lang="go">package main
 
// Copyright (c) 2013 Alex Kesling
Line 1,263 ⟶ 1,291:
}
return
}</langsyntaxhighlight>
Screen capture:
 
Line 1,272 ⟶ 1,300:
groovy WindowCreation.groovy
 
<langsyntaxhighlight lang="groovy">import javax.swing.*
import java.awt.*
import java.awt.event.WindowAdapter
Line 1,302 ⟶ 1,330:
}
}
}</langsyntaxhighlight>
 
=={{header|GUISS}}==
Graphical User Interface Support Script is really a language for operating a computer, rather than programming one, so we cannot do this via X11 libraries. The example uses leafpad for our open window, and the box symbols to enclose our text:
 
<langsyntaxhighlight lang="guiss">Start,Programs,Applications,Editors,Leafpad,Textbox,
Type:[openbox]Hello World[pling][closebox]</langsyntaxhighlight>
 
=={{header|Haskell}}==
Using {{libheader|X11}} from [http://hackage.haskell.org/packages/hackage.html HackageDB]
<langsyntaxhighlight lang="haskell">import Graphics.X11.Xlib
import Control.Concurrent (threadDelay)
 
Line 1,334 ⟶ 1,362:
destroyWindow display xwin
closeDisplay display
</syntaxhighlight>
</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
Icon and Unicon provide a portable graphics implementation that does not rely upon a toolkit. The intent is to be platform independent and the same code runs on multiple platforms without change and producing results with only minor variations. Icon and Unicon graphics are implemented in X-Windows as well as MS-Windows and others. There are additional 3D graphics capabilities implemented using opengl.
<langsyntaxhighlight Iconlang="icon">procedure main()
W1 := open("X-Window","g","size=250,250","bg=black","fg=red") | stop("unable to open window")
FillRectangle(W1,50,50,150,150)
Line 1,344 ⟶ 1,372:
end
 
link graphics</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
Line 1,356 ⟶ 1,384:
run
java WindowExample
<langsyntaxhighlight lang="java">import javax.swing.JFrame;
import javax.swing.SwingUtilities;
 
Line 1,376 ⟶ 1,404:
frame.setVisible(true);
}
}</langsyntaxhighlight>The previous example works but doesn't write any text or draw any box; the following does both.<langsyntaxhighlight lang="java">import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
Line 1,402 ⟶ 1,430:
f.setVisible(true);
}
}</langsyntaxhighlight>
 
=={{header|Julia}}==
This was based on https://en.wikipedia.org/wiki/Xlib, and mostly quoted from from the XLib.jl test2() testing code function.
<langsyntaxhighlight lang="julia">
using Xlib
 
Line 1,447 ⟶ 1,475:
 
x11demo()
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|C}}
{{libheader|Xlib}}
<langsyntaxhighlight lang="scala">// Kotlin Native v0.3
 
import kotlinx.cinterop.*
Line 1,483 ⟶ 1,511:
XCloseDisplay(d)
nativeHeap.free(e)
}</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
Line 1,490 ⟶ 1,518:
Ao for this task we use the M2000 way to make a form and do something on it.
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
\\ M2000 froms (windows) based on a flat, empty with no title bar, vb6 window and a user control.
\\ title bar is a user control in M2000 form
Line 1,532 ⟶ 1,560:
}
SquareAndText2Window
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Note that GUIKit is a high-level wrapper for Swing.
<syntaxhighlight lang="text">Needs["GUIKit`"]
ref = GUIRun[Widget["Panel", {
Widget[
Line 1,543 ⟶ 1,571:
"GIF"]]}],
Widget["Label", { "text" -> "Hello World!"}]}
]]</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import x11/[xlib,xutil,x]
 
const
Line 1,621 ⟶ 1,649:
 
 
main()</langsyntaxhighlight>
 
=={{header|OCaml}}==
Line 1,636 ⟶ 1,664:
#load "Xlib.cma"
 
<langsyntaxhighlight lang="ocaml">open Xlib
 
let () =
Line 1,659 ⟶ 1,687:
main_loop();
xCloseDisplay d;
;;</langsyntaxhighlight>
 
=={{header|Pascal}}==
Line 1,666 ⟶ 1,694:
from wiki.freepascal.org/X11#Examples.
Compiled with Freepascal 2.6.4-32
<langsyntaxhighlight lang="pascal">program xshowwindow;
{$mode objfpc}{$H+}
 
Line 1,723 ⟶ 1,751:
ModalShowX11Window('Hello, World!');
end.
</syntaxhighlight>
</lang>
 
=={{header|Perl}}==
=== X11::Protocol ===
<langsyntaxhighlight lang="perl">#!/usr/bin/perl -w
use strict;
use X11::Protocol;
Line 1,771 ⟶ 1,799:
for (;;) {
$X->handle_input;
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 1,779 ⟶ 1,807:
=={{header|PicoLisp}}==
The following script works in the 32-bit version, using inlined C code
<langsyntaxhighlight PicoLisplang="picolisp">#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
 
(load "@lib/misc.l" "@lib/gcc.l")
Line 1,826 ⟶ 1,854:
 
(simpleWin 300 200 "Hello World")
(bye)</langsyntaxhighlight>
 
=={{header|PythonPureBasic}}==
PureBasic does not have direct support for the X11 library like Xlib or XCB.
 
See [[Window_creation#PureBasic]].
 
=={{header|Python}}==
=== Xlib ===
{{field attention|Python|X11|Note (stolen from CLX example): This example was written in near-total ignorance of X11 by consulting the python-xlib's examples (included in its distribution) to find equivalents for the parts of the C example.}}
Line 1,842 ⟶ 1,874:
* python xlib_hello_world.py
 
<langsyntaxhighlight lang="python">from Xlib import X, display
 
class Window:
Line 1,875 ⟶ 1,907:
if __name__ == "__main__":
Window(display.Display(), "Hello, World!").loop()</langsyntaxhighlight>
 
=== XCB ===
{{libheader|python-xcb}}
 
<langsyntaxhighlight lang="python">import xcb
from xcb.xproto import *
import xcb.render
Line 1,922 ⟶ 1,954:
conn.disconnect()
 
main()</langsyntaxhighlight>
 
=={{header|Racket}}==
Using Racket's GUI which is implemented using gtk. It's not low level, but OTOH it works on Windows and OS X too.
 
<langsyntaxhighlight Racketlang="racket">#lang racket/gui
 
(define frame (new frame%
Line 1,939 ⟶ 1,971:
(send dc set-text-foreground "blue")
(send dc draw-text "Don't Panic!" 0 0))])
(send frame show #t)</langsyntaxhighlight>
 
=={{header|Raku}}==
Line 1,947 ⟶ 1,979:
There is not yet a X11 library in Raku but we can write the minimal C mappings for this task.
 
<syntaxhighlight lang="raku" perl6line>use NativeCall;
 
class Display is repr('CStruct') {
Line 2,008 ⟶ 2,040:
}
}
XCloseDisplay($display);</langsyntaxhighlight>
 
=={{header|Scala}}==
{{libheader|Scala}}<langsyntaxhighlight Scalalang="scala">import scala.swing.{ MainFrame, SimpleSwingApplication }
import scala.swing.Swing.pair2Dimension
 
Line 2,020 ⟶ 2,052:
preferredSize = ((200, 150))
}
}</langsyntaxhighlight>
 
=={{header|Standard ML}}==
Works with PolyML
<langsyntaxhighlight Standardlang="standard MLml">open XWindows ;
val dp = XOpenDisplay "" ;
val w = XCreateSimpleWindow (RootWindow dp) origin (Area {x=0,y=0,w=400,h=300}) 3 0 0xffffff ;
Line 2,030 ⟶ 2,062:
XFlush dp ;
XDrawString w (DefaultGC dp) (XPoint {x=10,y=50}) "Hello World!" ;
XFlush dp ;</langsyntaxhighlight>
 
=={{header|Tcl}}==
Line 2,037 ⟶ 2,069:
===Low level interface===
{{libheader|critcl}}
<langsyntaxhighlight lang="tcl">package provide xlib 1
package require critcl
 
Line 2,101 ⟶ 2,133:
const char *str = Tcl_GetStringFromObj(msg, &len);
XDrawString(d, (Window)w, gc, x, y, str, len);
}</langsyntaxhighlight>
Note that this only does enough for this demo. A full adaptation is too long for RosettaCode...
 
This could then be used like this:
<langsyntaxhighlight lang="tcl">package require xlib
 
XOpenDisplay {}
Line 2,115 ⟶ 2,147:
}
XDestroyWindow $w
XCloseDisplay</langsyntaxhighlight>
===Higher level interface===
Just because there is a low level package does not mean that it is pleasant to use from Tcl code. Therefore this second package wraps it up inside a higher-level package that provides a more natural way of interacting.
<br>
{{works with|Tcl|8.6}} or {{libheader|TclOO}}
<langsyntaxhighlight lang="tcl">package require TclOO
package provide x11 1
 
Line 2,172 ⟶ 2,204:
}
}
}</langsyntaxhighlight>
This script puts the pieces together to carry out the details of the task.
<langsyntaxhighlight lang="tcl">package require x11
 
# With a display connection open, create and map a window
Line 2,194 ⟶ 2,226:
 
$w destroy
}</langsyntaxhighlight>
Improving this by adding more sophisticated event handling and more window methods is left as an exercise.
 
Line 2,206 ⟶ 2,238:
<br>
As it's not currently possible for Wren-cli to access Xlib directly, we embed a Wren script in a C application to complete this task.
<langsyntaxhighlight ecmascriptlang="wren">/* window_creation_x11Window_creation_X11.wren */
 
var KeyPressMask = 1 << 0
Line 2,269 ⟶ 2,301:
if (e.eventType == KeyPress) break
}
xd.closeDisplay()</langsyntaxhighlight>
<br>
We now embed this Wren script in the following C program, compile and run it.
<syntaxhighlight lang="c">/* gcc Window_creation_X11.c -o Window_creation_X11 -lX11 -lwren -lm */
<lang c>#include <stdio.h>
 
<lang c>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 2,473 ⟶ 2,507:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "window_creation_x11Window_creation_X11.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 2,489 ⟶ 2,523:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{out}}
<pre>Same as C example.</pre>
<pre>
 
Same as C example.
=={{header|Yabasic}}==
</pre>
<syntaxhighlight lang="vbnet">open window 300,200
 
text 150, 100, "Hello World"
 
rectangle 10,10 to 90,90
fill rectangle 40,40,60,60
 
clear screen
 
inkey$
close window</syntaxhighlight>
 
{{omit from|ACL2}}
2,122

edits