Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,57 @@
program xshowwindow;
{$mode objfpc}{$H+}
uses
xlib, x, ctypes;
procedure ModalShowX11Window(AMsg: string);
var
d: PDisplay;
w: TWindow;
e: TXEvent;
msg: PChar;
s: cint;
begin
msg := PChar(AMsg);
{ open connection with the server }
d := XOpenDisplay(nil);
if (d = nil) then
begin
WriteLn('[ModalShowX11Window] Cannot open display');
exit;
end;
s := DefaultScreen(d);
{ create window }
w := XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 50, 1,
BlackPixel(d, s), WhitePixel(d, s));
{ select kind of events we are interested in }
XSelectInput(d, w, ExposureMask or KeyPressMask);
{ map (show) the window }
XMapWindow(d, w);
{ event loop }
while (True) do
begin
XNextEvent(d, @e);
{ draw or redraw the window }
if (e._type = Expose) then
begin
XFillRectangle(d, w, DefaultGC(d, s), 0, 10, 100, 3);
XFillRectangle(d, w, DefaultGC(d, s), 0, 30, 100, 3);
XDrawString (d, w, DefaultGC(d, s), 5, 25, msg, strlen(msg));
end;
{ exit on key press }
if (e._type = KeyPress) then Break;
end;
{ close connection to server }
XCloseDisplay(d);
end;
begin
ModalShowX11Window('Hello, World!');
end.

View file

@ -0,0 +1,58 @@
use NativeCall;
class Display is repr('CStruct') {}
class GC is repr('CStruct') {}
class XEvent is repr('CStruct') {
has int32 $.type; # for 32 bits machine
#has int $.type; # for 64 bits machine
method init { $!type = 0 }
}
sub XOpenDisplay(Str $name = ':0') returns Display is native('libX11') { * }
sub XDefaultScreen(Display $) returns int is native('libX11') { * }
sub XRootWindow(Display $, int $screen_number) returns int is native('libX11') { * }
sub XBlackPixel(Display $, int $screen_number) returns int is native('libX11') { * }
sub XWhitePixel(Display $, int $screen_number) returns int is native('libX11') { * }
sub XCreateSimpleWindow(
Display $, int $parent_window, int $x, int $y,
int $width, int $height, int $border_width,
int $border, int $background
) returns int is native('libX11') { * }
sub XMapWindow(Display $, int $window) is native('libX11') { * }
sub XSelectInput(Display $, int $window, int $mask) is native('libX11') { * }
sub XFillRectangle(
Display $, int $window, GC $, int $x, int $y, int $width, int $height
) is native('libX11') { * }
sub XDrawString(
Display $, int $window, GC $, int $x, int $y, Str $, int $str_length
) is native('libX11') { * }
sub XDefaultGC(Display $, int $screen) returns GC is native('libX11') { * }
sub XNextEvent(Display $, XEvent $e) is native('libX11') { * }
sub XCloseDisplay(Display $) is native('libX11') { * }
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);

View file

@ -0,0 +1,10 @@
import scala.swing.{ MainFrame, SimpleSwingApplication }
import scala.swing.Swing.pair2Dimension
object WindowExample extends SimpleSwingApplication {
def top = new MainFrame {
title = "Hello!"
centerOnScreen
preferredSize = ((200, 150))
}
}