'From Pharo3.0 of 18 March 2013 [Latest update: #30854] on 23 September 2014 at 12:08:02.915403 am'!

!X11GC methodsFor: 'drawing' stamp: 'NicolaiHess 9/23/2014 00:05'!
drawOval: aRectangle
	self
		XDrawArc: self display
			with: drawable xid
			with: self
			with: aRectangle left
			with: aRectangle top
			with: aRectangle width
			with: aRectangle height
			with: 0
			with: 64*360! !

!X11GC methodsFor: 'drawing' stamp: 'NicolaiHess 9/23/2014 00:06'!
fillRectangle: aRectangle
	self
		XFillRectangle: self display
			with: drawable xid
			with: self
			with: aRectangle left
			with: aRectangle top
			with: aRectangle width
			with: aRectangle height! !

!X11GC methodsFor: 'drawing' stamp: 'NicolaiHess 9/23/2014 00:06'!
drawRectangle: aRectangle
	self
		XDrawRectangle: self display
			with: drawable xid
			with: self
			with: aRectangle left
			with: aRectangle top
			with: aRectangle width
			with: aRectangle height! !

!X11GC methodsFor: 'drawing' stamp: 'NicolaiHess 9/23/2014 00:04'!
fillOval: aRectangle
	self
		XFillArc: self display
			with: drawable xid
			with: self
			with: aRectangle left
			with: aRectangle top
			with: aRectangle width
			with: aRectangle height
			with: 0
			with: 64*360! !

!X11GC methodsFor: 'drawing' stamp: 'NicolaiHess 9/23/2014 00:07'!
drawLineFrom: pt1 to: pt2
	self XDrawLine: self display 
			with: drawable xid
			with: self 
			with: pt1 x 
			with: pt1 y 
			with: pt2 x 
			with: pt2 y! !

!X11GC methodsFor: 'xlib calls' stamp: 'NicolaiHess 9/23/2014 00:06'!
XDrawRectangle: xDisplay with: xDrawable with: xGC with: x with: y with: w with: h
	<cdecl: void 'XDrawRectangle' (X11Display* ulong X11GC long long ulong ulong) module: 'X11'>
	^self externalCallFailed! !

!X11GC methodsFor: 'xlib calls' stamp: 'NicolaiHess 9/23/2014 00:07'!
XDrawLine: xDisplay with: aDrawable with: xGC with: x0 with: y0 with: x1 with: y1
	<cdecl: long 'XDrawLine' (X11Display* ulong X11GC long long long long) module: 'X11'>
	^self externalCallFailed! !

!X11GC methodsFor: 'xlib calls' stamp: 'NicolaiHess 9/23/2014 00:05'!
XDrawArc: xDisplay with: xDrawable with: xGC with: x with: y with: w with: h with: a1 with: a2
	<cdecl: void 'XDrawArc' (X11Display* ulong X11GC long long ulong ulong long long) module: 'X11'>
	^self externalCallFailed! !

!X11GC methodsFor: 'xlib calls' stamp: 'NicolaiHess 9/23/2014 00:04'!
XFillArc: xDisplay with: xDrawable with: xGC with: x with: y with: w with: h with: a1 with: a2
	<cdecl: void 'XFillArc' (X11Display* ulong X11GC long long ulong ulong long long) module: 'X11'>
	^self externalCallFailed! !

!X11GC methodsFor: 'xlib calls' stamp: 'NicolaiHess 9/23/2014 00:06'!
XFillRectangle: xDisplay with: xDrawable with: xGC with: x with: y with: w with: h
	<cdecl: void 'XFillRectangle' (X11Display* ulong X11GC long long ulong ulong) module: 'X11'>
	^self externalCallFailed! !


!X11Display class methodsFor: 'examples' stamp: 'NicolaiHess 9/23/2014 00:06'!
x11Draw
	"X11Display x11Draw"
	| display window gc nextPt lastPt ptr |
	display := X11Display XOpenDisplay: nil.
	window := display ourWindow.
	window display:display.
	gc := X11GC on: window.
	gc foreground: 0.
	lastPt := nil.
	[ptr := display queryPointer: window.	"{root. child. root pos. win pos. mask}"
	ptr last anyMask: 256] whileFalse:[
		nextPt := ptr fourth.
		nextPt = lastPt ifFalse:[
			lastPt ifNotNil: [
				gc drawLineFrom: lastPt to: nextPt.
				display sync].
			lastPt := nextPt].
	].
	gc free.
	display closeDisplay.
	Display forceToScreen.! !

!X11Display class methodsFor: 'examples' stamp: 'NicolaiHess 9/23/2014 00:04'!
coloredEllipses
	"X11Display coloredEllipses"
	| display window gc colors rnd w h pt1 pt2 r |
	display := X11Display XOpenDisplay: nil.
	window := display ourWindow.
	window display:display.
	gc := X11GC on: window.
	colors := Color registeredColorNames collect:[:n| (Color fromString:n) pixelWordForDepth: 32].
	rnd := Random new.
	w := Display width.
	h := Display height.
	[Sensor anyButtonPressed] whileFalse:[
		pt1 := (rnd next * w) asInteger @ (rnd next * h) asInteger.
		pt2 := (rnd next * w) asInteger @ (rnd next * h) asInteger.
		r := Rectangle encompassing: (Array with: pt1 with: pt2).
		gc foreground: colors atRandom.
		gc fillOval: r.
		gc foreground: 0.
		gc drawOval: r.
		display sync.
	].
	gc free.
	display closeDisplay.
	Display forceToScreen.! !

!X11Display class methodsFor: 'examples' stamp: 'NicolaiHess 9/23/2014 00:05'!
coloredRectangles
	"X11Display coloredRectangles"
	| display window gc colors rnd w h pt1 pt2 r nPixels time n |
	display := X11Display XOpenDisplay: nil.
	window := display ourWindow.
	window display:display.
	gc := X11GC on: window.
	colors := Color registeredColorNames  collect:[:cn| (Color fromString:cn) pixelWordForDepth: 32].
	rnd := Random new.
	w := Display width.
	h := Display height.
	n := 0.
	nPixels := 0.
	time := Time millisecondClockValue.
	[Sensor anyButtonPressed] whileFalse:[
		pt1 := (rnd next * w) asInteger @ (rnd next * h) asInteger.
		pt2 := (rnd next * w) asInteger @ (rnd next * h) asInteger.
		r := Rectangle encompassing: (Array with: pt1 with: pt2).
		gc foreground: colors atRandom.
		gc fillRectangle: r.
		gc foreground: 0.
		gc drawRectangle: r.
		display sync.
		n := n + 1.
		nPixels := nPixels + ((r right - r left) * (r bottom - r top)).
		(n \\ 100) = 0 ifTrue:[
			'Pixel fillRate: ', (nPixels * 1000 // (Time millisecondClockValue - time))
				asStringWithCommas displayAt: 0@0].
	].
	gc free.
	display closeDisplay.
	Display forceToScreen.! !


!X11GC class methodsFor: 'instance creation' stamp: 'NicolaiHess 9/23/2014 00:04'!
on: aDrawable
	| xgc |
	xgc := self XCreateGC: aDrawable display with: aDrawable xid with: 0 with: nil.
	xgc drawable: aDrawable.
	^xgc! !

!X11GC class methodsFor: 'xlib calls' stamp: 'NicolaiHess 9/23/2014 00:03'!
XCreateGC: xDisplay with: aDrawable with: valueMask with: values
	<cdecl: X11GC 'XCreateGC' (X11Display* ulong ulong long*) module: 'X11'>
	^self externalCallFailed! !

