func DefaultFullTheme(X *xgbutil.XUtil) *FullTheme { return &FullTheme{ Font: xgraphics.MustFont(xgraphics.ParseFont( bytes.NewBuffer(misc.DejavusansTtf))), FontSize: 15, AFontColor: render.NewColor(0xffffff), IFontColor: render.NewColor(0x000000), TitleSize: 25, ATitleColor: render.NewColor(0x3366ff), ITitleColor: render.NewColor(0xdfdcdf), ACloseButton: builtInButton(X, misc.ClosePng), ICloseButton: builtInButton(X, misc.ClosePng), AMaximizeButton: builtInButton(X, misc.MaximizePng), IMaximizeButton: builtInButton(X, misc.MaximizePng), AMinimizeButton: builtInButton(X, misc.MinimizePng), IMinimizeButton: builtInButton(X, misc.MinimizePng), BorderSize: 10, ABorderColor: render.NewColor(0x3366ff), IBorderColor: render.NewColor(0xdfdcdf), } }
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) }
func loadFont(name string) *Font { fontReader, err := os.Open(name) if err != nil { log.Fatal(err) } font, err := xgraphics.ParseFont(fontReader) if err != nil { log.Fatal(err) } return &Font{Size: 12.0, TrueType: font} }
func OpenFont(fileName string) *truetype.Font { f, err := os.Open(fileName) FailMeMaybe(err) defer f.Close() fnt, err := xgraphics.ParseFont(f) FailMeMaybe(err) return fnt }
ActiveFontColor render.Color GroupBgColor render.Color GroupFont *truetype.Font GroupFontSize float64 GroupFontColor render.Color GroupSpacing int } var DefaultSelectTheme = &SelectTheme{ BorderSize: 10, BgColor: render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}), BorderColor: render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}), Padding: 20, Font: xgraphics.MustFont(xgraphics.ParseFont( bytes.NewBuffer(misc.DataFile("DejaVuSans.ttf")))), FontSize: 20.0, FontColor: render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}), ActiveBgColor: render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}), ActiveFontColor: render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}), GroupBgColor: render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}), GroupFont: xgraphics.MustFont(xgraphics.ParseFont( bytes.NewBuffer(misc.DataFile("DejaVuSans.ttf")))), GroupFontSize: 25.0, GroupFontColor: render.NewImageColor(color.RGBA{0x33, 0x66, 0xff, 0xff}), GroupSpacing: 15, } type SelectConfig struct {
ActiveFontColor render.Color GroupBgColor render.Color GroupFont *truetype.Font GroupFontSize float64 GroupFontColor render.Color GroupSpacing int } var DefaultSelectTheme = &SelectTheme{ BorderSize: 10, BgColor: render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}), BorderColor: render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}), Padding: 20, Font: xgraphics.MustFont(xgraphics.ParseFont( bytes.NewBuffer(bindata.DejavusansTtf()))), FontSize: 20.0, FontColor: render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}), ActiveBgColor: render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}), ActiveFontColor: render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}), GroupBgColor: render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}), GroupFont: xgraphics.MustFont(xgraphics.ParseFont( bytes.NewBuffer(bindata.DejavusansTtf()))), GroupFontSize: 25.0, GroupFontColor: render.NewImageColor(color.RGBA{0x33, 0x66, 0xff, 0xff}), GroupSpacing: 15, } type SelectConfig struct {
func SetupDisplay() (ctrlChan chan interface{}) { ctrlChan = make(chan interface{}) X, err := xgbutil.NewConn() if err != nil { log.Fatal(err) } 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) } img, gc := initGc(width+border*2, height+heading+border*2) ximg := xgraphics.NewConvert(X, img) wid := ximg.XShowExtra("Regiment", true) circle := new(draw2d.PathStorage) ctr := 0 fps := 0 go func() { for { c := <-ctrlChan switch c := c.(type) { case *generals.Regiment: c.Step() rp := c.Position() gc.SetFillColor(image.Black) gc.SetStrokeColor(image.Black) for i := 0; i < len(rp.RowPath); i++ { x, y := rp.RowPath[i].X, rp.RowPath[i].Y circle = new(draw2d.PathStorage) circle.ArcTo(x+border, y+border+heading, 1, 1, 0, 2*math.Pi) gc.FillStroke(circle) } for i := 0; i < len(rp.ColPath); i++ { x, y := rp.ColPath[i].X, rp.ColPath[i].Y circle = new(draw2d.PathStorage) circle.ArcTo(x+border, y+border+heading, 1, 1, 0, 2*math.Pi) gc.FillStroke(circle) } case *Frame: for xp := border; xp < (width + border); xp++ { for yp := border; yp < (height + border + heading); yp++ { ximg.Set(xp, yp, img.At(xp, yp)) } } _, _, err = ximg.Text(10, 0, fg, size, font, fmt.Sprintf("FPS: %v", fps)) if err != nil { log.Fatal(err) } ximg.XDraw() ximg.XPaint(wid.Id) ctr++ gc.SetFillColor(image.White) // fill the background gc.Clear() case *Timing: fps = ctr _, _, err = ximg.Text(10, 0, fg, size, font, fmt.Sprintf("FPS: %v", fps)) ctr = 0 default: fmt.Println(reflect.TypeOf(c)) } } }() go func() { xevent.Main(X) }() return ctrlChan }
"github.com/BurntSushi/xgb/xproto" "github.com/BurntSushi/xgbutil" "github.com/BurntSushi/xgbutil/keybind" "github.com/BurntSushi/xgbutil/xevent" "github.com/BurntSushi/xgbutil/xgraphics" "github.com/BurntSushi/xgbutil/xwindow" "github.com/BurntSushi/wingo/bindata" "github.com/BurntSushi/wingo/render" "github.com/BurntSushi/wingo/text" ) var ( // A near guaranteed font. If parsing fails, MustFont wll panic. font = xgraphics.MustFont(xgraphics.ParseFont( bytes.NewBuffer(bindata.FreemonoTtf()))) fontSize = 30.0 fontColor = render.NewImageColor(color.RGBA{0x0, 0x0, 0x0, 0xff}) bgColor = render.NewImageColor(color.RGBA{0xff, 0xff, 0xff, 0xff}) width = 800 padding = 10 ) func fatal(err error) { if err != nil { log.Fatal(err) } } func main() { X, err := xgbutil.NewConn()