Window creation/X11: Difference between revisions

Content added Content deleted
(add task to ARM64 assembly Raspberry Pi)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 6: Line 6:
Implementations of this task should   ''avoid using a toolkit''   as much as possible.
Implementations of this task should   ''avoid using a toolkit''   as much as possible.
<br><br>
<br><br>

=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
Line 156: Line 157:


</lang>
</lang>

=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|tested with release mk15-0.8b.fc9.i386}}
{{works with|ALGOL 68G|tested with release mk15-0.8b.fc9.i386}}
Line 171: Line 173:
VOID (read char);
VOID (read char);
close (window)</lang>
close (window)</lang>

=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
Line 1,113: Line 1,116:
<lang guiss>Start,Programs,Applications,Editors,Leafpad,Textbox,
<lang guiss>Start,Programs,Applications,Editors,Leafpad,Textbox,
Type:[openbox]Hello World[pling][closebox]</lang>
Type:[openbox]Hello World[pling][closebox]</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.
<lang 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)
WDone(W1)
end

link graphics</lang>

{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/graphics.icn graphics.icn provides graphics]

Additionally, the '''WOpen''' procedure and Window.App methods are available.


=={{header|Haskell}}==
=={{header|Haskell}}==
Line 1,154: Line 1,142:
closeDisplay display
closeDisplay display
</lang>
</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.
<lang 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)
WDone(W1)
end

link graphics</lang>

{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/graphics.icn graphics.icn provides graphics]

Additionally, the '''WOpen''' procedure and Window.App methods are available.


=={{header|Java}}==
=={{header|Java}}==
Line 1,288: Line 1,291:
nativeHeap.free(e)
nativeHeap.free(e)
}</lang>
}</lang>

=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
M2000 interpteter is a Visual Basic 6 (vb6) gui application, so we can't use X11. When we use Wine, connecting to X11 may occur but this is invisible for interpreter scope.
M2000 interpteter is a Visual Basic 6 (vb6) gui application, so we can't use X11. When we use Wine, connecting to X11 may occur but this is invisible for interpreter scope.
Line 1,336: Line 1,340:
SquareAndText2Window
SquareAndText2Window
</lang>
</lang>

=={{header|Mathematica}}==
=={{header|Mathematica}}==
Note that GUIKit is a high-level wrapper for Swing.
Note that GUIKit is a high-level wrapper for Swing.
Line 1,387: Line 1,392:
xCloseDisplay d;
xCloseDisplay d;
;;</lang>
;;</lang>




=={{header|Pascal}}==
=={{header|Pascal}}==
Line 1,501: Line 1,504:
$X->handle_input;
$X->handle_input;
}</lang>
}</lang>

=={{header|Perl 6}}==
{{trans|C}}

There is not yet a X11 library in Perl 6 but we can write the minimal C mappings for this task.

<lang perl6>use NativeCall;

class Display is repr('CStruct') {
has int32 $!screen;
has int32 $!window;
}
class GC is repr('CStruct') {
has int32 $!context;
}
class XEvent is repr('CStruct') {
has int32 $.type;
method init { $!type = 0 }
}

sub XOpenDisplay(Str $name = ':0') returns Display is native('X11') { * }
sub XDefaultScreen(Display $) returns int32 is native('X11') { * }
sub XRootWindow(Display $, int32 $screen_number) returns int32 is native('X11') { * }
sub XBlackPixel(Display $, int32 $screen_number) returns int32 is native('X11') { * }
sub XWhitePixel(Display $, int32 $screen_number) returns int32 is native('X11') { * }
sub XCreateSimpleWindow(
Display $, int32 $parent_window, int32 $x, int32 $y,
int32 $width, int32 $height, int32 $border_width,
int32 $border, int32 $background
) returns int32 is native('X11') { * }
sub XMapWindow(Display $, int32 $window) is native('X11') { * }
sub XSelectInput(Display $, int32 $window, int32 $mask) is native('X11') { * }
sub XFillRectangle(
Display $, int32 $window, GC $, int32 $x, int32 $y, int32 $width, int32 $height
) is native('X11') { * }
sub XDrawString(
Display $, int32 $window, GC $, int32 $x, int32 $y, Str $, int32 $str_length
) is native('X11') { * }
sub XDefaultGC(Display $, int32 $screen) returns GC is native('X11') { * }
sub XNextEvent(Display $, XEvent $e) is native('X11') { * }
sub XCloseDisplay(Display $) is native('X11') { * }

my Display $display = XOpenDisplay()
or die "Can not open display";

my int $screen = XDefaultScreen($display);
my int $window = XCreateSimpleWindow(
$display,
XRootWindow($display, $screen),
10, 10, 100, 100, 1,
XBlackPixel($display, $screen), XWhitePixel($display, $screen)
);
XSelectInput($display, $window, 1 +< 15 +| 1);
XMapWindow($display, $window);

my Str $msg = 'Hello, World!';
my XEvent $e .= new; $e.init;
loop {
XNextEvent($display, $e);
if $e.type == 12 {
XFillRectangle($display, $window, XDefaultGC($display, $screen), 20, 20, 10, 10);
XDrawString($display, $window, XDefaultGC($display, $screen), 10, 50, $msg, my int $ = $msg.chars);
}
elsif $e.type == 2 {
last;
}
}
XCloseDisplay($display);</lang>


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,737: Line 1,672:
(send dc draw-text "Don't Panic!" 0 0))])
(send dc draw-text "Don't Panic!" 0 0))])
(send frame show #t)</lang>
(send frame show #t)</lang>

=={{header|Raku}}==
(formerly Perl 6)
{{trans|C}}

There is not yet a X11 library in Perl 6 but we can write the minimal C mappings for this task.

<lang perl6>use NativeCall;

class Display is repr('CStruct') {
has int32 $!screen;
has int32 $!window;
}
class GC is repr('CStruct') {
has int32 $!context;
}
class XEvent is repr('CStruct') {
has int32 $.type;
method init { $!type = 0 }
}

sub XOpenDisplay(Str $name = ':0') returns Display is native('X11') { * }
sub XDefaultScreen(Display $) returns int32 is native('X11') { * }
sub XRootWindow(Display $, int32 $screen_number) returns int32 is native('X11') { * }
sub XBlackPixel(Display $, int32 $screen_number) returns int32 is native('X11') { * }
sub XWhitePixel(Display $, int32 $screen_number) returns int32 is native('X11') { * }
sub XCreateSimpleWindow(
Display $, int32 $parent_window, int32 $x, int32 $y,
int32 $width, int32 $height, int32 $border_width,
int32 $border, int32 $background
) returns int32 is native('X11') { * }
sub XMapWindow(Display $, int32 $window) is native('X11') { * }
sub XSelectInput(Display $, int32 $window, int32 $mask) is native('X11') { * }
sub XFillRectangle(
Display $, int32 $window, GC $, int32 $x, int32 $y, int32 $width, int32 $height
) is native('X11') { * }
sub XDrawString(
Display $, int32 $window, GC $, int32 $x, int32 $y, Str $, int32 $str_length
) is native('X11') { * }
sub XDefaultGC(Display $, int32 $screen) returns GC is native('X11') { * }
sub XNextEvent(Display $, XEvent $e) is native('X11') { * }
sub XCloseDisplay(Display $) is native('X11') { * }

my Display $display = XOpenDisplay()
or die "Can not open display";

my int $screen = XDefaultScreen($display);
my int $window = XCreateSimpleWindow(
$display,
XRootWindow($display, $screen),
10, 10, 100, 100, 1,
XBlackPixel($display, $screen), XWhitePixel($display, $screen)
);
XSelectInput($display, $window, 1 +< 15 +| 1);
XMapWindow($display, $window);

my Str $msg = 'Hello, World!';
my XEvent $e .= new; $e.init;
loop {
XNextEvent($display, $e);
if $e.type == 12 {
XFillRectangle($display, $window, XDefaultGC($display, $screen), 20, 20, 10, 10);
XDrawString($display, $window, XDefaultGC($display, $screen), 10, 50, $msg, my int $ = $msg.chars);
}
elsif $e.type == 2 {
last;
}
}
XCloseDisplay($display);</lang>


=={{header|Scala}}==
=={{header|Scala}}==