diff options
Diffstat (limited to 'src/rhlibrary')
-rw-r--r-- | src/rhlibrary/app_window.go | 129 |
1 files changed, 112 insertions, 17 deletions
diff --git a/src/rhlibrary/app_window.go b/src/rhlibrary/app_window.go index c524f36..b28e950 100644 --- a/src/rhlibrary/app_window.go +++ b/src/rhlibrary/app_window.go @@ -38,34 +38,129 @@ type AppWindow struct { player *player.PlayerChan } -func (mw *AppWindow) ShowAndRun() { - mw.win.ShowAll() - if err := mw.player.Load(1, 1); err != nil { - rhl.Println(err) +func (aw *AppWindow) ShowAndRun() { + aw.win.ShowAll() + gtk.Main() +} + +func (aw *AppWindow) drawSelector(grid *gtk.Grid) (err error) { + var selectorgrid *gtk.Grid + if selectorgrid, err = gtk.GridNew(); err != nil { + return + } + selectorgrid.SetColumnSpacing(3) + + var cartl, cutl *gtk.Label + var cart, cut *gtk.SpinButton + + if cartl, err = gtk.LabelNew("Cart:"); err != nil { + return } - if err := mw.player.Play(); err != nil { - rhl.Println(err) + if cart, err = gtk.SpinButtonNewWithRange(1, 999999, 1); err != nil { + return } - gtk.Main() + + if cutl, err = gtk.LabelNew("Cut:"); err != nil { + return + } + if cut, err = gtk.SpinButtonNewWithRange(1, 999, 1); err != nil { + return + } + + var loadBtn *gtk.Button + if loadBtn, err = gtk.ButtonNewWithLabel("LOAD"); err != nil { + return + } + loadBtn.Connect("clicked", func(_ *gtk.Button) { + if err := aw.player.Load((uint)(cart.GetValueAsInt()), (uint)(cut.GetValueAsInt())); err != nil { + rhdl.Println(err) + } + }) + + selectorgrid.Attach(cartl, 1, 1, 1, 1) + selectorgrid.Attach(cart, 2, 1, 1, 1) + selectorgrid.Attach(cutl, 1, 2, 1, 1) + selectorgrid.Attach(cut, 2, 2, 1, 1) + selectorgrid.Attach(loadBtn, 1, 3, 2, 1) + + selectorgrid.SetHExpand(true) + selectorgrid.SetVExpand(true) + + grid.Add(selectorgrid) + return } -func NewAppWindow(player *player.PlayerChan, width, height int) (mw *AppWindow, err error) { - mw = &AppWindow{} - mw.player = player - if mw.win, err = gtk.WindowNew(gtk.WINDOW_TOPLEVEL); err != nil { +func (aw *AppWindow) drawPlayer(grid *gtk.Grid) (err error) { + var playergrid *gtk.Grid + if playergrid, err = gtk.GridNew(); err != nil { return } - mw.win.SetTitle("rhlibrary") - mw.win.Connect("destroy", func() { + playergrid.SetOrientation(gtk.ORIENTATION_HORIZONTAL) + playergrid.SetColumnSpacing(3) + + var playBtn *gtk.Button + if playBtn, err = gtk.ButtonNewFromIconName("media-playback-start", gtk.ICON_SIZE_DIALOG); err != nil { + return + } + playBtn.Connect("clicked", func(_ *gtk.Button) { + if err := aw.player.Play(); err != nil { + rhdl.Println(err) + } + }) + + var pauseBtn *gtk.Button + if pauseBtn, err = gtk.ButtonNewFromIconName("media-playback-pause", gtk.ICON_SIZE_DIALOG); err != nil { + return + } + pauseBtn.Connect("clicked", func(_ *gtk.Button) { + if err := aw.player.Pause(); err != nil { + rhdl.Println(err) + } + }) + + var stopBtn *gtk.Button + if stopBtn, err = gtk.ButtonNewFromIconName("media-playback-stop", gtk.ICON_SIZE_DIALOG); err != nil { + return + } + stopBtn.Connect("clicked", func(_ *gtk.Button) { + if err := aw.player.Stop(); err != nil { + rhdl.Println(err) + } + }) + + playergrid.Add(playBtn) + playergrid.Add(pauseBtn) + playergrid.Add(stopBtn) + + grid.Add(playergrid) + return +} + +func NewAppWindow(player *player.PlayerChan, width, height int) (aw *AppWindow, err error) { + aw = &AppWindow{} + aw.player = player + if aw.win, err = gtk.WindowNew(gtk.WINDOW_TOPLEVEL); err != nil { + return + } + aw.win.SetTitle("rhlibrary") + aw.win.Connect("destroy", func() { gtk.MainQuit() }) - var l *gtk.Label - if l, err = gtk.LabelNew("Hello, world!"); err != nil { + var grid *gtk.Grid + if grid, err = gtk.GridNew(); err != nil { + return + } + grid.SetOrientation(gtk.ORIENTATION_VERTICAL) + + if err = aw.drawSelector(grid); err != nil { + return + } + if err = aw.drawPlayer(grid); err != nil { return } - mw.win.Add(l) + aw.win.Add(grid) - mw.win.SetDefaultSize(width, height) + aw.win.SetDefaultSize(width, height) return } |