コード例 #1
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Ellipse(x, y, a, b int, n, f bool) {
	//
	x0, y0 := C.int(x-a), C.int(y-b)
	if f {
		if !n {
			C.XSetFunction(display, graphicsContext, C.GXinvert)
		} // C.GXcopyInverted ?
		if !xxb {
			C.XFillArc(display, C.Drawable(window), graphicsContext, C.int(x0), C.int(y0), C.uint(2*a), C.uint(2*b), 0, 64*360)
		}
		C.XFillArc(display, C.Drawable(pixmap), graphicsContext, C.int(x0), C.int(y0), C.uint(2*a), C.uint(2*b), 0, 64*360)
	} else {
		if !n {
			C.XSetFunction(display, graphicsContext, C.GXinvert)
		}
		if !xxb {
			C.XDrawArc(display, C.Drawable(window), graphicsContext, C.int(x0), C.int(y0), C.uint(2*a), C.uint(2*b), 0, 64*360)
		}
		C.XDrawArc(display, C.Drawable(pixmap), graphicsContext, C.int(x0), C.int(y0), C.uint(2*a), C.uint(2*b), 0, 64*360)
	}
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXcopy)
	}
	C.XFlush(display)
}
コード例 #2
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Clr(x, y, w, h uint) {
	//
	C.XSetForeground(display, graphicsContext, cc(col.ScreenB))
	C.XFillRectangle(display, C.Drawable(window), graphicsContext, C.int(x), C.int(y), C.uint(w), C.uint(h))
	C.XFillRectangle(display, C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y), C.uint(w), C.uint(h))
	C.XSetForeground(display, graphicsContext, cc(col.ScreenF))
	C.XFlush(display)
}
コード例 #3
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Invert(x, y, x1, y1 uint) {
	//
	if x > x1 || y > y1 {
	} // desaster
	C.XSetFunction(display, graphicsContext, C.GXinvert)
	if !xxb {
		C.XFillRectangle(display, C.Drawable(window), graphicsContext, C.int(x), C.int(y), C.uint(x1-x+1), C.uint(y1-y+1))
	}
	C.XFillRectangle(display, C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y), C.uint(x1-x+1), C.uint(y1-y+1))
	C.XSetFunction(display, graphicsContext, C.GXcopy)
	C.XFlush(display)
}
コード例 #4
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Point(x, y int, n bool) {
	//
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXinvert)
	}
	if !xxb {
		C.XDrawPoint(display, C.Drawable(window), graphicsContext, C.int(x), C.int(y))
	}
	C.XDrawPoint(display, C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y))
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXcopy)
	}
	C.XFlush(display)
}
コード例 #5
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Line(x, y, x1, y1 int, n bool) {
	//
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXinvert)
	}
	if !xxb {
		C.XDrawLine(display, C.Drawable(window), graphicsContext, C.int(x), C.int(y), C.int(x1), C.int(y1))
	}
	C.XDrawLine(display, C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y), C.int(x1), C.int(y1))
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXcopy)
	}
	C.XFlush(display)
}
コード例 #6
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Write(s string, x, y int, t bool) {
	//
	n := C.uint(len(s))
	if !t {
		C.XSetForeground(display, graphicsContext, C.ulong(col.CodeB))
		if !xxb {
			C.XFillRectangle(display, C.Drawable(window), graphicsContext, C.int(x), C.int(y), n*C.uint(ZB), C.uint(ZH))
		}
		C.XFillRectangle(display, C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y), n*C.uint(ZB), C.uint(ZH))
		C.XSetForeground(display, graphicsContext, C.ulong(col.CodeF))
	}
	cs := C.CString(s)
	if !xxb {
		C.XDrawString(display, C.Drawable(window), graphicsContext, C.int(x), C.int(y)+ZA, cs, C.int(n))
	}
	C.XDrawString(display, C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y)+ZA, cs, C.int(n))
	C.free(unsafe.Pointer(cs))
	C.XFlush(display)
}
コード例 #7
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Decode(x, y, w, h uint, b []byte) {
	//
	const M = C.ulong(1<<32 - 1)
	//////////////////////////////////////////////////////////////////////////////////////////////  steals a lot of time
	ximg := C.XGetImage(display, C.Drawable(window), C.int(x), C.int(y), C.uint(w), C.uint(h), M, C.XYPixmap)
	//////////////////////////////////////////////////////////////////////////////////////////////  steals a lot of time
	n := uint(0)
	//  var pixel C.ulong
	for j := uint(0); j < h; j++ {
		for i := uint(0); i < w; i++ {
			pixel := (C.ulong)(obj.Decode(n, b[n:n+4]).(uint))
			C.xPutPixel(ximg, C.int(i), C.int(j), pixel) // C.XPutPixel (ximg, C.int(i), C.int(j), pixel)
			n += 4
		}
	}
	C.XPutImage(display, C.Drawable(window), graphicsContext, ximg, 0, 0, C.int(x), C.int(y), C.uint(w), C.uint(h))
	C.XCopyArea(display, C.Drawable(window), C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y), C.uint(w), C.uint(h), C.int(x), C.int(y))
	C.XFlush(display)
	C.xDestroyImage(ximg) // C.XDestroyImage (ximg)
}
コード例 #8
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func PolygonFull(X, Y []int, n bool) {
	//
	l := len(X)
	if len(Y) != l {
		return
	}
	p := make([]C.XPoint, l)
	for i := 0; i < l; i++ {
		p[i].x, p[i].y = C.short(X[i]), C.short(Y[i])
	}
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXcopyInverted)
	}
	if !xxb {
		C.XFillPolygon(display, C.Drawable(window), graphicsContext, &p[0], C.int(l), C.Convex, C.CoordModeOrigin)
	}
	C.XFillPolygon(display, C.Drawable(pixmap), graphicsContext, &p[0], C.int(l), C.Convex, C.CoordModeOrigin)
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXcopy)
	}
	C.XFlush(display)
}
コード例 #9
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Segments(X, Y, X1, Y1 []int, n bool) {
	//
	l := len(X)
	if len(Y) != l {
		return
	}
	s := make([]C.XSegment, l)
	for i := 0; i < l; i++ {
		s[i].x1, s[i].y1, s[i].x2, s[i].y2 = C.short(X[i]), C.short(Y[i]), C.short(X1[i]), C.short(Y1[i])
	}
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXinvert)
	}
	if !xxb {
		C.XDrawSegments(display, C.Drawable(window), graphicsContext, &s[0], C.int(l))
	}
	C.XDrawSegments(display, C.Drawable(pixmap), graphicsContext, &s[0], C.int(l))
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXcopy)
	}
	C.XFlush(display)
}
コード例 #10
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Switch(x, y uint) {
	//
	if xx == maxX && yy == maxY {
		C.sw(display, window, window0, netwm_state, fullscreen, C.int(0))
	}
	xx, yy = C.uint(x), C.uint(y)
	if xx == maxX && yy == maxY {
		C.sw(display, window, window0, netwm_state, fullscreen, C.int(1))
	} else {
		C.XResizeWindow(display, window, xx, yy) // resizerequest.width, resizerequest.height
		C.XFlush(display)
	}
	C.XFreePixmap(display, pixmap)
	pixmap = C.XCreatePixmap(display, C.Drawable(window), xx, yy, bitdepth)
	C.XFreePixmap(display, pixmap1)
	pixmap1 = C.XCreatePixmap(display, C.Drawable(window), xx, yy, bitdepth)
	C.XSetForeground(display, graphicsContext, cc(col.ActualB))
	//
	C.XFillRectangle(display, C.Drawable(window), graphicsContext, 0, 0, xx, yy)
	C.XFillRectangle(display, C.Drawable(pixmap), graphicsContext, 0, 0, xx, yy)
	C.XFillRectangle(display, C.Drawable(pixmap1), graphicsContext, 0, 0, xx, yy)
	MouseDef(0, 0, int(xx-1), int(yy-1))
	//  var E *C.XEvent
	//  C.XNextEvent (display, E)
	//  et:= C.typ (&E) // et == *E.type
	//  switch et { case C.Expose, C.ConfigureNotify:
	//    for C.XCheckTypedEvent (display, C.int(et), E) == C.True { }
	//  case C.ReparentNotify:
	//    ;
	//  default:
	//    C.XPutBackEvent (display, E)
	//  }
	WarpMouse(int(xx)/2, int(yy)/2)
	//  C.XSync (display, C.False)
	//  if navi.initialized (naviFd) {
	//    go catchNavi ()
	//  }
}
コード例 #11
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Encode(x, y, w, h uint, e []byte) {
	//
	const M = C.ulong(1<<32 - 1)
	ximg := C.XGetImage(display, C.Drawable(window), C.int(x), C.int(y), C.uint(w), C.uint(h), M, C.XYPixmap)
	n := uint(0)
	//  var pixel C.ulong
	for y := 0; y < int(h); y++ {
		for x := 0; x < int(w); x++ {
			pixel := C.xGetPixel(ximg, C.int(x), C.int(y)) // = C.XGetPixel (ximg, C.int(x), C.int(y))
			copy(e[n:n+4], cd(uint(pixel)))
			n += 4
		}
	}
	C.xDestroyImage(ximg) // C.XDestroyImage (ximg)
}
コード例 #12
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Rectangle(x, y, w, h int, n, f bool) {
	//
	if f {
		if !n {
			C.XSetFunction(display, graphicsContext, C.GXinvert)
		} // C.GXcopyInverted ?
		if !xxb {
			C.XFillRectangle(display, C.Drawable(window), graphicsContext, C.int(x), C.int(y), C.uint(w), C.uint(h))
		}
		C.XFillRectangle(display, C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y), C.uint(w), C.uint(h))
	} else {
		if !n {
			C.XSetFunction(display, graphicsContext, C.GXinvert)
		}
		if !xxb {
			C.XDrawRectangle(display, C.Drawable(window), graphicsContext, C.int(x), C.int(y), C.uint(w), C.uint(h))
		}
		C.XDrawRectangle(display, C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y), C.uint(w), C.uint(h))
	}
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXcopy)
	}
	C.XFlush(display)
}
コード例 #13
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Buf(on bool) {
	//
	if xxb == on {
		return
	}
	xxb = on
	if on {
		C.XSetForeground(display, graphicsContext, cc(col.ScreenB))
		C.XFillRectangle(display, C.Drawable(pixmap), graphicsContext, 0, 0, C.uint(xx), C.uint(yy))
		C.XSetForeground(display, graphicsContext, cc(col.ScreenF))
		C.XFlush(display)
	} else {
		pp2ff()
	}
}
コード例 #14
0
ファイル: gowitt.go プロジェクト: jonvaldes/gowitt
func CreateXWindow(width, height int) (*XWindow, error) {
	C.XInitThreads()

	W := &XWindow{}

	W.Display = C.XOpenDisplay(nil)
	if W.Display == nil {
		return &XWindow{}, errors.New("Can't open display")
	}
	W.Window = C.XCreateSimpleWindow(W.Display, C.XDefaultRootWindow(W.Display), 0, 0, C.uint(width), C.uint(height), 0, 0, 0xFF151515)
	C.XSetWindowBackgroundPixmap(W.Display, W.Window, 0) // This avoids flickering on resize
	C.XMapWindow(W.Display, W.Window)
	C.XStoreName(W.Display, W.Window, C.CString("gowitt"))

	C.XSelectInput(W.Display, W.Window, C.ExposureMask|C.KeyPressMask|C.ButtonPressMask)
	C.XFlush(W.Display)

	// Cairo
	W.Surface = C.cairo_xlib_surface_create(W.Display, C.Drawable(W.Window), C.XDefaultVisual(W.Display, 0), C.int(width), C.int(height))
	C.cairo_xlib_surface_set_size(W.Surface, C.int(width), C.int(height))
	W.Cairo = C.cairo_create(W.Surface)

	// Pango
	InitLayoutsCache(W.Cairo)
	W.PangoContext = C.pango_cairo_create_context(W.Cairo)
	W.FontDesc = C.pango_font_description_from_string(C.CString("Sans 10"))

	W.AttrList = C.pango_attr_list_new()

	placeholderImage = C.cairo_image_surface_create_from_png(C.CString("test.png"))

	W.UserImages = NewImageCache(func() {
		var ev C.XEvent
		exev := (*C.XExposeEvent)(unsafe.Pointer(&ev))
		exev._type = C.Expose
		exev.count = 0
		exev.window = W.Window
		exev.send_event = 1
		exev.display = W.Display

		C.XSendEvent(W.Display, W.Window, 0, C.ExposureMask, &ev)
		C.XFlush(W.Display)
	})
	return W, nil
}
コード例 #15
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func pp2ff() {
	//
	C.XCopyArea(display, C.Drawable(pixmap), C.Drawable(window), graphicsContext, 0, 0, xx, yy, 0, 0)
	C.XFlush(display)
}
コード例 #16
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Init(w, h uint, cF, cB col.Colour) (uint, uint, uint) {
	//
	initialized = false
	//
	maxX, maxY, bitdepth = Screen()
	bdp := uint(bitdepth)
	switch bdp {
	case 15, 16, 24, 32:
		col.SetColourDepth(bdp)
	default:
		panic("strange colourdepth") /* Terminate (); */ os.Exit(1)
	}
	colourdepth := (bdp + 1) / 8
	col.ScreenF, col.ScreenB = cF, cB
	xx, yy = C.uint(w), C.uint(h)
	window = C.XCreateSimpleWindow(display, C.Window(window0), 0, 0, xx, yy, C.uint(0), C.ulong(0), cc(col.ScreenB))
	//  var E C.XEvent
	//  C.XNextEvent (display, &E) // XCreate... did not produce an XEvent
	C.initialize(display, screen, window)
	t := C.CString(env.Par(0))
	defer C.free(unsafe.Pointer(t))
	C.XStoreName(display, window, t)
	C.XMapRaised(display, window)
	const inputmask = (C.KeyPressMask + // C.KeyReleaseMask +
		C.ButtonPressMask + C.ButtonReleaseMask + C.PointerMotionMask +
		C.ExposureMask + C.StructureNotifyMask)
	C.XSelectInput(display, window, inputmask)
	cursor := C.XCreateFontCursor(display, C.XC_gumby)
	C.XDefineCursor(display, window, cursor)
	graphicsContext = C.XDefaultGC(display, screen)
	//  C.XFlushGC (display graphicsContext)
	C.XSetGraphicsExposures(display, graphicsContext, C.False)
	SetFontsize(16)
	initialized = true
	Colours(cF, cB)
	C.XSetForeground(display, graphicsContext, cc(col.ScreenB))

	C.XFillRectangle(display, C.Drawable(window), graphicsContext, 0, 0, xx, yy)
	pixmap = C.XCreatePixmap(display, C.Drawable(window), xx, yy, bitdepth)
	pixmap1 = C.XCreatePixmap(display, C.Drawable(window), maxX, maxY, bitdepth)
	C.XFillRectangle(display, C.Drawable(pixmap), graphicsContext, 0, 0, xx, yy)
	C.XFillRectangle(display, C.Drawable(pixmap1), graphicsContext, 0, 0, xx, yy)
	C.XSetForeground(display, graphicsContext, cc(col.ScreenF))

	MouseDef(0, 0, int(xx-1), int(yy-1))
	var E C.XEvent
	C.XNextEvent(display, &E)
	var et C.int = C.typ(&E) // et == *E.type
	switch et {
	case C.Expose, C.ConfigureNotify: // zur Erstausgabe
		for C.XCheckTypedEvent(display, et, &E) == C.True {
		}
		//    pp2ff ()
	case KeyPress, KeyRelease, ButtonPress, ButtonRelease, MotionNotify:
		C.XPutBackEvent(display, &E)
	case C.ReparentNotify: // at Switch (?)
		// ignore
	default: // for test purposes
		//    println ("at initializing x:" + txt [et])
	}
	p := C.CString("WM_PROTOCOLS")
	defer C.free(unsafe.Pointer(p))
	wm_protocols := C.XInternAtom(display, p, C.False)
	C.XSetWMProtocols(display, window, &wm_protocols, 1)
	s := C.CString("_NET_WM_STATE")
	defer C.free(unsafe.Pointer(s))
	netwm_state = C.XInternAtom(display, s, C.False)
	f := C.CString("_NET_WM_STATE_FULLSCREEN")
	defer C.free(unsafe.Pointer(f))
	fullscreen = C.XInternAtom(display, f, C.False)
	m := C.CString("navi")
	defer C.free(unsafe.Pointer(m))
	naviAtom = C.XInternAtom(display, m, C.False)
	Eventpipe = make(chan Event)
	go sendEvents()
	//  C.XFlush (display)
	//  println ("init ok")
	return uint(maxX), uint(maxY), colourdepth
}
コード例 #17
0
ファイル: imp.go プロジェクト: CaptainSoOmA/Uni
func Restore(x, y, w, h uint) {
	//
	C.XCopyArea(display, C.Drawable(pixmap1), C.Drawable(window), graphicsContext, C.int(x), C.int(y), C.uint(w), C.uint(h), C.int(x), C.int(y))
	C.XCopyArea(display, C.Drawable(window), C.Drawable(pixmap), graphicsContext, C.int(x), C.int(y), C.uint(w), C.uint(h), C.int(x), C.int(y))
}