Window creation/X11: Difference between revisions
Added Yabasic
(Added Yabasic) |
|||
(5 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">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program creatFenX1164.s */
Line 156:
.include "../includeARM64.inc"
</syntaxhighlight>
=={{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.
<
draw device (window, "X", "600x400");
open (window, "Hello, World!", stand draw channel);
Line 172:
draw show (window);
VOID (read char);
close (window)</
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
Line 650:
bx lr @ leave function
iMagicNumber: .int 0xCCCCCCCD
</syntaxhighlight>
=={{header|BaCon}}==
<syntaxhighlight lang="c">
'--- added a flush to exit cleanly
PRAGMA LDFLAGS `pkg-config --cflags --libs x11`
Line 719:
FLUSH(d)
CLOSE_DISPLAY(d)
</
=={{header|C}}==
Line 728:
* gcc hello-x.c -L/usr/X11R6/lib -lX11 -o hello-x
<
#include <stdio.h>
#include <stdlib.h>
Line 764:
XCloseDisplay(d);
return 0;
}</
=== XCB ===
Line 772:
* gcc -o helloxcb helloxcb.c -lxcb
<
#include <stdio.h>
#include <string.h>
Line 854:
return 0;
}</
=={{header|COBOL}}==
Tested with GnuCOBOL, and only on 64bit architecture, GNU/Linux. Nods to the C XLib version.
<
program-id. x11-hello.
installation. cobc -x x11-hello.cob -lX11
Line 1,033:
goback.
end program x11-hello.</
=={{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.
<
(let* ((display (open-default-display))
Line 1,076:
(close-display display)))
</syntaxhighlight>
=={{header|Forth}}==
Running Ubuntu 20.04 64-bit
Using : Gforth 0.7.9_20211014
<syntaxhighlight lang="forth">
warnings off
require xlib.fs
Line 1,145:
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>
=={{header|Go}}==
{{trans|C}}
<
// Copyright (c) 2013 Alex Kesling
Line 1,266 ⟶ 1,291:
}
return
}</
Screen capture:
Line 1,275 ⟶ 1,300:
groovy WindowCreation.groovy
<
import java.awt.*
import java.awt.event.WindowAdapter
Line 1,305 ⟶ 1,330:
}
}
}</
=={{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:
<
Type:[openbox]Hello World[pling][closebox]</
=={{header|Haskell}}==
Using {{libheader|X11}} from [http://hackage.haskell.org/packages/hackage.html HackageDB]
<
import Control.Concurrent (threadDelay)
Line 1,337 ⟶ 1,362:
destroyWindow display xwin
closeDisplay display
</syntaxhighlight>
=={{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.
<
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,347 ⟶ 1,372:
end
link graphics</
{{libheader|Icon Programming Library}}
Line 1,359 ⟶ 1,384:
run
java WindowExample
<
import javax.swing.SwingUtilities;
Line 1,379 ⟶ 1,404:
frame.setVisible(true);
}
}</
import java.awt.event.*;
import java.awt.geom.*;
Line 1,405 ⟶ 1,430:
f.setVisible(true);
}
}</
=={{header|Julia}}==
This was based on https://en.wikipedia.org/wiki/Xlib, and mostly quoted from from the XLib.jl test2() testing code function.
<
using Xlib
Line 1,450 ⟶ 1,475:
x11demo()
</syntaxhighlight>
=={{header|Kotlin}}==
{{trans|C}}
{{libheader|Xlib}}
<
import kotlinx.cinterop.*
Line 1,486 ⟶ 1,511:
XCloseDisplay(d)
nativeHeap.free(e)
}</
=={{header|M2000 Interpreter}}==
Line 1,493 ⟶ 1,518:
Ao for this task we use the M2000 way to make a form and do something on it.
<syntaxhighlight 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,535 ⟶ 1,560:
}
SquareAndText2Window
</syntaxhighlight>
=={{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,546 ⟶ 1,571:
"GIF"]]}],
Widget["Label", { "text" -> "Hello World!"}]}
]]</
=={{header|Nim}}==
<
const
Line 1,624 ⟶ 1,649:
main()</
=={{header|OCaml}}==
Line 1,639 ⟶ 1,664:
#load "Xlib.cma"
<
let () =
Line 1,662 ⟶ 1,687:
main_loop();
xCloseDisplay d;
;;</
=={{header|Pascal}}==
Line 1,669 ⟶ 1,694:
from wiki.freepascal.org/X11#Examples.
Compiled with Freepascal 2.6.4-32
<
{$mode objfpc}{$H+}
Line 1,726 ⟶ 1,751:
ModalShowX11Window('Hello, World!');
end.
</syntaxhighlight>
=={{header|Perl}}==
=== X11::Protocol ===
<
use strict;
use X11::Protocol;
Line 1,774 ⟶ 1,799:
for (;;) {
$X->handle_input;
}</
=={{header|Phix}}==
Line 1,782 ⟶ 1,807:
=={{header|PicoLisp}}==
The following script works in the 32-bit version, using inlined C code
<
(load "@lib/misc.l" "@lib/gcc.l")
Line 1,829 ⟶ 1,854:
(simpleWin 300 200 "Hello World")
(bye)</
=={{header|
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,845 ⟶ 1,874:
* python xlib_hello_world.py
<
class Window:
Line 1,878 ⟶ 1,907:
if __name__ == "__main__":
Window(display.Display(), "Hello, World!").loop()</
=== XCB ===
{{libheader|python-xcb}}
<
from xcb.xproto import *
import xcb.render
Line 1,925 ⟶ 1,954:
conn.disconnect()
main()</
=={{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.
<
(define frame (new frame%
Line 1,942 ⟶ 1,971:
(send dc set-text-foreground "blue")
(send dc draw-text "Don't Panic!" 0 0))])
(send frame show #t)</
=={{header|Raku}}==
Line 1,950 ⟶ 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"
class Display is repr('CStruct') {
Line 2,011 ⟶ 2,040:
}
}
XCloseDisplay($display);</
=={{header|Scala}}==
{{libheader|Scala}}<
import scala.swing.Swing.pair2Dimension
Line 2,023 ⟶ 2,052:
preferredSize = ((200, 150))
}
}</
=={{header|Standard ML}}==
Works with PolyML
<
val dp = XOpenDisplay "" ;
val w = XCreateSimpleWindow (RootWindow dp) origin (Area {x=0,y=0,w=400,h=300}) 3 0 0xffffff ;
Line 2,033 ⟶ 2,062:
XFlush dp ;
XDrawString w (DefaultGC dp) (XPoint {x=10,y=50}) "Hello World!" ;
XFlush dp ;</
=={{header|Tcl}}==
Line 2,040 ⟶ 2,069:
===Low level interface===
{{libheader|critcl}}
<
package require critcl
Line 2,104 ⟶ 2,133:
const char *str = Tcl_GetStringFromObj(msg, &len);
XDrawString(d, (Window)w, gc, x, y, str, len);
}</
Note that this only does enough for this demo. A full adaptation is too long for RosettaCode...
This could then be used like this:
<
XOpenDisplay {}
Line 2,118 ⟶ 2,147:
}
XDestroyWindow $w
XCloseDisplay</
===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}}
<
package provide x11 1
Line 2,175 ⟶ 2,204:
}
}
}</
This script puts the pieces together to carry out the details of the task.
<
# With a display connection open, create and map a window
Line 2,197 ⟶ 2,226:
$w destroy
}</
Improving this by adding more sophisticated event handling and more window methods is left as an exercise.
Line 2,209 ⟶ 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.
<
var KeyPressMask = 1 << 0
Line 2,272 ⟶ 2,301:
if (e.eventType == KeyPress) break
}
xd.closeDisplay()</
<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>▼
#include <stdlib.h>
#include <string.h>
Line 2,476 ⟶ 2,507:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 2,492 ⟶ 2,523:
free(script);
return 0;
}</
{{out}}
<pre>Same as C example.</pre>▼
▲Same as C example.
=={{header|Yabasic}}==
<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}}
|