當前位置: 首頁>>代碼示例>>Golang>>正文


Golang xgraphics.New函數代碼示例

本文整理匯總了Golang中github.com/BurntSushi/xgbutil/xgraphics.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Init

func (ct *CommandTray) Init() {
	var err error

	ct.img = xgraphics.New(ct.X, image.Rect(0, 0, ct.Width, ct.Height))
	ct.pu_img = xgraphics.New(ct.X, image.Rect(0, 0, ct.Width, ct.Height*10))

	ct.window, err = xwindow.Create(ct.X, ct.Parent.Id)
	utils.FailMeMaybe(err)

	utils.FailMeMaybe(ct.img.XSurfaceSet(ct.window.Id))

	ct.window.Move(ct.Position, 0)
	ct.window.Resize(ct.Width, ct.Height)
	ct.window.Map()
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:15,代碼來源:commandtray.go

示例2: DrawText

// DrawText is a convenience function that will create a new image, render
// the provided text to it, paint the image to the provided window, and resize
// the window to fit the text snugly.
//
// An error can occur when rendering the text to an image.
func DrawText(win *xwindow.Window, font *truetype.Font, size float64,
	fontClr, bgClr render.Color, text string) error {

	// BUG(burntsushi): If `text` is zero-length, very bad things happen.
	if len(text) == 0 {
		text = " "
	}

	// Over estimate the extents.
	ew, eh := xgraphics.Extents(font, size, text)

	// Create an image using the over estimated extents.
	img := xgraphics.New(win.X, image.Rect(0, 0, ew, eh))
	xgraphics.BlendBgColor(img, bgClr.ImageColor())

	// Now draw the text, grab the (x, y) position advanced by the text, and
	// check for an error in rendering.
	_, _, err := img.Text(0, 0, fontClr.ImageColor(), size, font, text)
	if err != nil {
		return err
	}

	// Resize the window to the geometry determined by (x, y).
	win.Resize(ew, eh)

	// Now draw the image to the window and destroy it.
	img.XSurfaceSet(win.Id)
	// subimg := img.SubImage(image.Rect(0, 0, ew, eh))
	img.XDraw()
	img.XPaint(win.Id)
	img.Destroy()

	return nil
}
開發者ID:flying99999,項目名稱:wingo,代碼行數:39,代碼來源:render.go

示例3: New

// New allocates and initializes a new DockApp.  NewDockApp does not initialize
// the window contents and does not map the window to the display screen.  The
// window is mapped to the screen when the Main method is called on the
// returned DockApp.
func New(x *xgbutil.XUtil, rect image.Rectangle) (*DockApp, error) {
	win, err := xwindow.Generate(x)
	if err != nil {
		log.Fatalf("generate window: %v", err)
	}
	win.Create(x.RootWin(), 0, 0, rect.Size().X, rect.Size().Y, 0)

	// Set WM hints so that Openbox puts the window into the dock.
	hints := &icccm.Hints{
		Flags:        icccm.HintState | icccm.HintIconWindow,
		InitialState: icccm.StateWithdrawn,
		IconWindow:   win.Id,
		WindowGroup:  win.Id,
	}
	err = icccm.WmHintsSet(x, win.Id, hints)
	if err != nil {
		win.Destroy()
		return nil, fmt.Errorf("wm hints: %v", err)
	}
	img := xgraphics.New(x, rect)
	err = img.XSurfaceSet(win.Id)
	if err != nil {
		img.Destroy()
		win.Destroy()
		return nil, fmt.Errorf("xsurface set: %v", err)
	}
	app := &DockApp{
		x:   x,
		img: img,
		win: win,
	}
	return app, nil
}
開發者ID:bmatsuo,項目名稱:dockapp-go,代碼行數:37,代碼來源:dockapp.go

示例4: DrawText

// DrawText is a convenience function that will create a new image, render
// the provided text to it, paint the image to the provided window, and resize
// the window to fit the text snugly.
//
// An error can occur when rendering the text to an image.
func DrawText(win *xwindow.Window, font *truetype.Font, size float64,
	fontClr, bgClr color.RGBA, text string) error {

	// Over estimate the extents.
	ew, eh := xgraphics.TextMaxExtents(font, size, text)
	eh += misc.TextBreathe // <-- this is the bug

	// Create an image using the over estimated extents.
	img := xgraphics.New(win.X, image.Rect(0, 0, ew, eh))
	xgraphics.BlendBgColor(img, bgClr)

	// Now draw the text, grab the (x, y) position advanced by the text, and
	// check for an error in rendering.
	x, y, err := img.Text(0, 0, fontClr, size, font, text)
	if err != nil {
		return err
	}

	// Resize the window to the geometry determined by (x, y).
	w, h := x, y+misc.TextBreathe // <-- also part of the bug
	win.Resize(w, h)

	// Now draw the image to the window and destroy it.
	img.XSurfaceSet(win.Id)
	subimg := img.SubImage(image.Rect(0, 0, w, h))
	subimg.XDraw()
	subimg.XPaint(win.Id)
	img.Destroy()

	return nil
}
開發者ID:dlintw,項目名稱:wingo,代碼行數:36,代碼來源:render.go

示例5: NewInput

// NewInput constructs Input values. It needs an X connection, a parent window,
// the width of the input box, and theme information related for the font
// and background. Padding separating the text and the edges of the window
// may also be specified.
//
// While NewInput returns an *Input, a Input value also has an xwindow.Window
// value embedded into it. Thus, an Input can also be treated as a normal
// window on which you can assign callbacks, close, destroy, etc.
//
// As with all windows, the Input window should be destroyed when it is no
// longer in used.
func NewInput(X *xgbutil.XUtil, parent xproto.Window, width int, padding int,
	font *truetype.Font, fontSize float64,
	fontColor, bgColor render.Color) *Input {

	_, height := xgraphics.TextMaxExtents(font, fontSize, "M")
	height += misc.TextBreathe

	width, height = width+2*padding, height+2*padding

	img := xgraphics.New(X, image.Rect(0, 0, width, height))
	win := xwindow.Must(xwindow.Create(X, parent))
	win.Listen(xproto.EventMaskKeyPress)
	win.Resize(width, height)

	ti := &Input{
		Window:    win,
		img:       img,
		Text:      make([]rune, 0, 50),
		font:      font,
		fontSize:  fontSize,
		fontColor: fontColor,
		bgColor:   bgColor,
		padding:   padding,
	}

	ti.Render()
	return ti
}
開發者ID:dlintw,項目名稱:wingo,代碼行數:39,代碼來源:input.go

示例6: NewImage

// NewImage returns a new image canvas
// that draws to the given image.  The
// minimum point of the given image
// should probably be 0,0.
func NewImage(img draw.Image, name string) (*Canvas, error) {
	w := float64(img.Bounds().Max.X - img.Bounds().Min.X)
	h := float64(img.Bounds().Max.Y - img.Bounds().Min.Y)

	X, err := xgbutil.NewConn()
	if err != nil {
		return nil, err
	}
	keybind.Initialize(X)
	ximg := xgraphics.New(X, image.Rect(0, 0, int(w), int(h)))
	err = ximg.CreatePixmap()
	if err != nil {
		return nil, err
	}
	painter := NewPainter(ximg)
	gc := draw2d.NewGraphicContextWithPainter(ximg, painter)
	gc.SetDPI(dpi)
	gc.Scale(1, -1)
	gc.Translate(0, -h)

	wid := ximg.XShowExtra(name, true)
	go func() {
		xevent.Main(X)
	}()

	c := &Canvas{
		Canvas: vgimg.NewWith(vgimg.UseImageWithContext(img, gc)),
		x:      X,
		ximg:   ximg,
		wid:    wid,
	}
	vg.Initialize(c)
	return c, nil
}
開發者ID:nolenroyalty,項目名稱:bangarang,代碼行數:38,代碼來源:canvas.go

示例7: NewDisplay

func NewDisplay(width, height, border, heading int, name string) (*Display, error) {
	d := new(Display)
	d.w = float64(width)
	d.h = float64(height)
	d.bord = float64(border)
	d.head = float64(heading)
	X, err := xgbutil.NewConn()
	if err != nil {
		return nil, err
	}
	keybind.Initialize(X)
	d.ximg = xgraphics.New(X, image.Rect(
		0,
		0,
		border*2+width,
		border*2+heading+height))
	err = d.ximg.CreatePixmap()
	if err != nil {
		return nil, err
	}
	painter := NewXimgPainter(d.ximg)
	d.gc = draw2d.NewGraphicContextWithPainter(d.ximg, painter)
	d.gc.Save()
	d.gc.SetStrokeColor(color.White)
	d.gc.SetFillColor(color.White)
	d.gc.Clear()
	d.wid = d.ximg.XShowExtra(name, true)
	d.x = X
	go func() {
		xevent.Main(X)
	}()
	return d, nil
}
開發者ID:stanim,項目名稱:display,代碼行數:33,代碼來源:display.go

示例8: main

func main() {
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	// Load some font. You may need to change the path depending upon your
	// system configuration.
	fontReader, err := os.Open(fontPath)
	if err != nil {
		log.Fatal(err)
	}

	// Now parse the font.
	font, err := xgraphics.ParseFont(fontReader)
	if err != nil {
		log.Fatal(err)
	}

	// Create some canvas.
	ximg := xgraphics.New(X, image.Rect(0, 0, canvasWidth, canvasHeight))
	ximg.For(func(x, y int) xgraphics.BGRA {
		return bg
	})

	// Now write the text.
	_, _, err = ximg.Text(10, 10, fg, size, font, msg)
	if err != nil {
		log.Fatal(err)
	}

	// Compute extents of first line of text.
	_, firsth := xgraphics.Extents(font, size, msg)

	// Now show the image in its own window.
	win := ximg.XShowExtra("Drawing text using xgraphics", true)

	// Now draw some more text below the above and demonstrate how to update
	// only the region we've updated.
	_, _, err = ximg.Text(10, 10+firsth, fg, size, font, "Some more text.")
	if err != nil {
		log.Fatal(err)
	}

	// Now compute extents of the second line of text, so we know which region
	// to update.
	secw, sech := xgraphics.Extents(font, size, "Some more text.")

	// Now repaint on the region that we drew text on. Then update the screen.
	bounds := image.Rect(10, 10+firsth, 10+secw, 10+firsth+sech)
	ximg.SubImage(bounds).XDraw()
	ximg.XPaint(win.Id)

	// All we really need to do is block, which could be achieved using
	// 'select{}'. Invoking the main event loop however, will emit error
	// message if anything went seriously wrong above.
	xevent.Main(X)
}
開發者ID:sbinet,項目名稱:xgbutil,代碼行數:58,代碼來源:main.go

示例9: NewSolid

func NewSolid(X *xgbutil.XUtil, bgColor Color, width, height int) *Image {
	img := New(xgraphics.New(X, image.Rect(0, 0, width, height)))

	r, g, b := bgColor.RGB8()
	img.ForExp(func(x, y int) (uint8, uint8, uint8, uint8) {
		return r, g, b, 0xff
	})
	return img
}
開發者ID:flying99999,項目名稱:wingo,代碼行數:9,代碼來源:render.go

示例10: NewGUI

func NewGUI(board *Board) *GUI {
	gui := new(GUI)
	X, _ := xgbutil.NewConn()
	gui.canvas = xgraphics.New(X, image.Rect(0, 0, board.Width(), board.Height()))
	gui.queue = make(map[Pos]bool, board.Width()*board.Height())
	gui.win = gui.canvas.XShow()
	gui.board = board
	board.onUpdate = func(p Pos) { gui.Update(p) }
	gui.StartLoop()
	return gui
}
開發者ID:KaptajnKold,項目名稱:antwar,代碼行數:11,代碼來源:screen.go

示例11: NewWindow

func NewWindow(width, height int) (w *Window, err error) {

	w = new(Window)
	w.width, w.height = width, height

	w.xu, err = xgbutil.NewConn()
	if err != nil {
		return
	}

	w.conn = w.xu.Conn()
	screen := w.xu.Screen()

	w.win, err = xwindow.Generate(w.xu)
	if err != nil {
		return
	}

	err = w.win.CreateChecked(screen.Root, 600, 500, width, height, 0)
	if err != nil {
		return
	}

	w.win.Listen(AllEventsMask)

	err = icccm.WmProtocolsSet(w.xu, w.win.Id, []string{"WM_DELETE_WINDOW"})
	if err != nil {
		fmt.Println(err)
		err = nil
	}

	w.bufferLck = &sync.Mutex{}
	w.buffer = xgraphics.New(w.xu, image.Rect(0, 0, width, height))
	w.buffer.XSurfaceSet(w.win.Id)

	keyMap, modMap := keybind.MapsGet(w.xu)
	keybind.KeyMapSet(w.xu, keyMap)
	keybind.ModMapSet(w.xu, modMap)

	w.events = make(chan interface{})

	w.SetIcon(Gordon)
	w.SetIconName("Go")

	go w.handleEvents()

	return
}
開發者ID:nickoneill,項目名稱:go.wde,代碼行數:48,代碼來源:xgb.go

示例12: NewBackground

// NewBackground creates an xgraphics.Image which spans the entire screen,
// initialized to black.
func NewBackground(X *xgbutil.XUtil) (*xgraphics.Image, error) {
	res, err := randr.GetScreenResources(X.Conn(), X.RootWin()).Reply()
	if err != nil {
		return nil, err
	}
	var bgRect image.Rectangle
	for _, output := range res.Outputs {
		r, err := util.OutputRect(X, output)
		// NOTE: It doesn't really matter if this returns a Zero Rectangle.
		if err != nil {
			return nil, err
		}
		bgRect = bgRect.Union(r)
	}
	return xgraphics.New(X, bgRect), nil
}
開發者ID:proxypoke,項目名稱:chiwa,代碼行數:18,代碼來源:background.go

示例13: Init

func (c *Clock) Init() {
	var err error
	c.img = xgraphics.New(c.X, image.Rect(0, 0, c.Width, c.Height))
	c.window, err = xwindow.Create(c.X, c.Parent.Id)
	utils.FailMeMaybe(err)

	c.window.Resize(c.Width, c.Height)
	c.window.Move(c.Position, 0)
	c.img.XSurfaceSet(c.window.Id)

	c.window.Map()

	c.Draw()

	go c.tickTock()
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:16,代碼來源:clock.go

示例14: main

func main() {
	runtime.GOMAXPROCS(64)

	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	keybind.Initialize(X)

	font := loadFont("/usr/share/fonts/truetype/freefont/FreeMono.ttf")
	font.Color = xgraphics.BGRA{B: 0x00, G: 0xff, R: 0x00, A: 0xff}
	font.Size = 12.0

	ximage := xgraphics.New(X, image.Rect(0, 0, 300, 300))
	ximage.CreatePixmap()
	window, obscured := makeWindow(ximage)

	battery := batteryItem(font, 10, ximage, window)
	cpu := cpuItem(font, 30, ximage, window)
	memory := memoryItem(font, 50, ximage, window)
	before, after, quit := xevent.MainPing(X)
loop:
	for {
		select {
		case <-before:
			<-after
		case <-quit:
			break loop
		case text := <-battery.Text:
			if *obscured {
				continue loop
			}
			battery.update(text)
		case text := <-cpu.Text:
			if *obscured {
				continue loop
			}
			cpu.update(text)
		case text := <-memory.Text:
			if *obscured {
				continue loop
			}
			memory.update(text)
		}
	}
}
開發者ID:pointlander,項目名稱:csm,代碼行數:47,代碼來源:csm.go

示例15: Init

func (sb *StatusBar) Init() {
	sb.img = xgraphics.New(sb.X, image.Rect(0, 0, sb.Width, sb.Height))
	var err error

	sb.window, err = xwindow.Create(sb.X, sb.Parent.Id)
	utils.FailMeMaybe(err)

	sb.window.Move(sb.Position, 0)
	sb.window.Resize(sb.Width, sb.Height)
	sb.window.Map()

	sb.img.XSurfaceSet(sb.window.Id)

	utils.FailMeMaybe(sb.initTray())

	sb.Draw()
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:17,代碼來源:statbar.go


注:本文中的github.com/BurntSushi/xgbutil/xgraphics.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。