Renamed repository to opslag.de/schobers/zntg.

Renamed allegro5 package to allg5
This commit is contained in:
Sander Schobers 2018-09-22 16:23:26 +02:00
parent bb803e4cc3
commit ad697d5508
35 changed files with 167 additions and 167 deletions

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
// #include <stdlib.h> // #include <stdlib.h>

View File

@ -1,6 +1,6 @@
// +build !windows // +build !windows
package allegro5 package allg5
// #cgo pkg-config: allegro-5 allegro_font-5 allegro_image-5 allegro_primitives-5 allegro_ttf-5 // #cgo pkg-config: allegro-5 allegro_font-5 allegro_image-5 allegro_primitives-5 allegro_ttf-5
import "C" import "C"

View File

@ -1,6 +1,6 @@
// +build windows,!static // +build windows,!static
package allegro5 package allg5
// #cgo LDFLAGS: -lallegro -lallegro_font -lallegro_image -lallegro_primitives -lallegro_ttf // #cgo LDFLAGS: -lallegro -lallegro_font -lallegro_image -lallegro_primitives -lallegro_ttf
import "C" import "C"

View File

@ -1,6 +1,6 @@
// +build windows,static // +build windows,static
package allegro5 package allg5
// #cgo LDFLAGS: -lallegro_monolith-static -static -ljpeg -ldumb -lFLAC -lfreetype -lvorbisfile -lvorbis -logg -lphysfs -lpng16 -lzlib -luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 -lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi -lstdc++ // #cgo LDFLAGS: -lallegro_monolith-static -static -ljpeg -ldumb -lFLAC -lfreetype -lvorbisfile -lvorbis -logg -lphysfs -lpng16 -lzlib -luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 -lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi -lstdc++
import "C" import "C"

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
import "C" import "C"

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
import "C" import "C"

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
import "C" import "C"

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <stdlib.h> // #include <stdlib.h>
import "C" import "C"

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
// #include <allegro5/allegro_font.h> // #include <allegro5/allegro_font.h>

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
import "C" import "C"

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
import "C" import "C"

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
import "C" import "C"

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
import "C" import "C"

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
import "C" import "C"

View File

@ -1,6 +1,6 @@
// +build windows // +build windows
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
// #include <allegro5/allegro_windows.h> // #include <allegro5/allegro_windows.h>

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
// #include <allegro5/allegro_primitives.h> // #include <allegro5/allegro_primitives.h>

View File

@ -1,4 +1,4 @@
package allegro5 package allg5
// #include <allegro5/allegro.h> // #include <allegro5/allegro.h>
// #include <allegro5/allegro_font.h> // #include <allegro5/allegro_font.h>

View File

@ -1,21 +1,21 @@
package ui package ui
import ( import (
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
"opslag.de/schobers/zntg/allg5"
) )
type Button struct { type Button struct {
ControlBase ControlBase
Text string Text string
HorizontalAlignment allegro5.HorizontalAlignment HorizontalAlignment allg5.HorizontalAlignment
} }
func NewButton(text string, click MouseClickFn) *Button { func NewButton(text string, click MouseClickFn) *Button {
return &Button{ControlBase: ControlBase{OnClick: click}, Text: text} return &Button{ControlBase: ControlBase{OnClick: click}, Text: text}
} }
func NewButtonAlign(text string, click MouseClickFn, align allegro5.HorizontalAlignment) *Button { func NewButtonAlign(text string, click MouseClickFn, align allg5.HorizontalAlignment) *Button {
return &Button{ControlBase: ControlBase{OnClick: click}, Text: text, HorizontalAlignment: align} return &Button{ControlBase: ControlBase{OnClick: click}, Text: text, HorizontalAlignment: align}
} }
@ -40,14 +40,14 @@ func (b *Button) Render(ctx Context) {
if b.IsOver && !b.IsPressed { if b.IsOver && !b.IsPressed {
back = ctx.Palette().PrimaryHighlight() back = ctx.Palette().PrimaryHighlight()
} }
allegro5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, back) allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, back)
switch b.HorizontalAlignment { switch b.HorizontalAlignment {
case allegro5.AlignLeft: case allg5.AlignLeft:
fnt.Draw(min.X+.5*fntH, min.Y+.5*fntH, ctx.Palette().Lightest(), allegro5.AlignLeft, b.Text) fnt.Draw(min.X+.5*fntH, min.Y+.5*fntH, ctx.Palette().Lightest(), allg5.AlignLeft, b.Text)
case allegro5.AlignCenter: case allg5.AlignCenter:
fnt.Draw(.5*(min.X+max.X), min.Y+.5*fntH, ctx.Palette().Lightest(), allegro5.AlignCenter, b.Text) fnt.Draw(.5*(min.X+max.X), min.Y+.5*fntH, ctx.Palette().Lightest(), allg5.AlignCenter, b.Text)
case allegro5.AlignRight: case allg5.AlignRight:
fnt.Draw(min.X-.5*fntH, min.Y+.5*fntH, ctx.Palette().Lightest(), allegro5.AlignRight, b.Text) fnt.Draw(min.X-.5*fntH, min.Y+.5*fntH, ctx.Palette().Lightest(), allg5.AlignRight, b.Text)
} }
b.ControlBase.Render(ctx) b.ControlBase.Render(ctx)

View File

@ -6,13 +6,13 @@ import (
"github.com/llgcode/draw2d/draw2dimg" "github.com/llgcode/draw2d/draw2dimg"
"github.com/llgcode/draw2d/draw2dkit" "github.com/llgcode/draw2d/draw2dkit"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
"opslag.de/schobers/zntg/allg5"
) )
type CheckboxValueChangedFn func(bool) type CheckboxValueChangedFn func(bool)
func drawCheckedBitmap(fill, stroke color.Color) *allegro5.Bitmap { func drawCheckedBitmap(fill, stroke color.Color) *allg5.Bitmap {
return drawBitmap(checkboxSize, checkboxSize, func(gc *draw2dimg.GraphicContext) { return drawBitmap(checkboxSize, checkboxSize, func(gc *draw2dimg.GraphicContext) {
var size = float64(checkboxSize) var size = float64(checkboxSize)
var margin = float64(checkboxMargin) var margin = float64(checkboxMargin)
@ -30,7 +30,7 @@ func drawCheckedBitmap(fill, stroke color.Color) *allegro5.Bitmap {
}) })
} }
func drawUncheckedBitmap(fill, stroke color.Color) *allegro5.Bitmap { func drawUncheckedBitmap(fill, stroke color.Color) *allg5.Bitmap {
return drawBitmap(checkboxSize, checkboxSize, func(gc *draw2dimg.GraphicContext) { return drawBitmap(checkboxSize, checkboxSize, func(gc *draw2dimg.GraphicContext) {
var size = float64(checkboxSize) var size = float64(checkboxSize)
var margin = float64(checkboxMargin) var margin = float64(checkboxMargin)
@ -47,8 +47,8 @@ type Checkbox struct {
Value bool Value bool
Text string Text string
OnChanged CheckboxValueChangedFn OnChanged CheckboxValueChangedFn
checked *allegro5.Bitmap checked *allg5.Bitmap
unchecked *allegro5.Bitmap unchecked *allg5.Bitmap
} }
func (c *Checkbox) Created(ctx Context, p Container) error { func (c *Checkbox) Created(ctx Context, p Container) error {
@ -65,11 +65,11 @@ func (c *Checkbox) Created(ctx Context, p Container) error {
return nil return nil
} }
func (c *Checkbox) Handle(ctx Context, ev allegro5.Event) { func (c *Checkbox) Handle(ctx Context, ev allg5.Event) {
var pressed = c.IsPressed var pressed = c.IsPressed
c.ControlBase.Handle(ctx, ev) c.ControlBase.Handle(ctx, ev)
switch ev.(type) { switch ev.(type) {
case *allegro5.MouseButtonUpEvent: case *allg5.MouseButtonUpEvent:
if !c.Disabled && pressed && c.IsOver { if !c.Disabled && pressed && c.IsOver {
c.Value = !c.Value c.Value = !c.Value
var onChanged = c.OnChanged var onChanged = c.OnChanged
@ -87,7 +87,7 @@ func (c *Checkbox) DesiredSize(ctx Context) geom.PointF {
return geom.PtF(float64(w+checkboxSize), checkboxSize) return geom.PtF(float64(w+checkboxSize), checkboxSize)
} }
func (c *Checkbox) box() *allegro5.Bitmap { func (c *Checkbox) box() *allg5.Bitmap {
if c.Value { if c.Value {
return c.checked return c.checked
} }
@ -100,10 +100,10 @@ func (c *Checkbox) Render(ctx Context) {
var min = c.Bounds.Min.To32() var min = c.Bounds.Min.To32()
var fnt = fonts.Get("default") var fnt = fonts.Get("default")
fnt.Draw(min.X+checkboxSize, min.Y-.67*fnt.Ascent()+.5*checkboxSize, ctx.Palette().Darkest(), allegro5.AlignLeft, c.Text) fnt.Draw(min.X+checkboxSize, min.Y-.67*fnt.Ascent()+.5*checkboxSize, ctx.Palette().Darkest(), allg5.AlignLeft, c.Text)
if c.Disabled { if c.Disabled {
var disabled = ctx.Palette().Disabled() var disabled = ctx.Palette().Disabled()
c.box().DrawOptions(min.X, min.Y, allegro5.DrawOptions{Tint: &disabled}) c.box().DrawOptions(min.X, min.Y, allg5.DrawOptions{Tint: &disabled})
} else { } else {
c.box().Draw(min.X, min.Y) c.box().Draw(min.X, min.Y)
} }

View File

@ -3,8 +3,8 @@ package ui
import ( import (
"time" "time"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
"opslag.de/schobers/zntg/allg5"
) )
type Container interface { type Container interface {
@ -92,7 +92,7 @@ func (c *ContainerBase) Update(ctx Context, dt time.Duration) {
} }
} }
func (c *ContainerBase) Handle(ctx Context, ev allegro5.Event) { func (c *ContainerBase) Handle(ctx Context, ev allg5.Event) {
for _, child := range c.children { for _, child := range c.children {
child.Handle(ctx, ev) child.Handle(ctx, ev)
} }

View File

@ -3,8 +3,8 @@ package ui
import ( import (
"math" "math"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
"opslag.de/schobers/zntg/allg5"
) )
var _ Control = &ContentScrollbar{} var _ Control = &ContentScrollbar{}
@ -35,7 +35,7 @@ func (h *contentScrollbarHandle) Render(ctx Context) {
} }
var min = h.Bounds.Min.To32() var min = h.Bounds.Min.To32()
var max = h.Bounds.Max.To32() var max = h.Bounds.Max.To32()
allegro5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, c) allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, c)
} }
func (s *ContentScrollbar) Created(ctx Context, p Container) error { func (s *ContentScrollbar) Created(ctx Context, p Container) error {
@ -138,22 +138,22 @@ func (s *ContentScrollbar) increment(d int) {
s.change(val) s.change(val)
} }
func (s *ContentScrollbar) Handle(ctx Context, ev allegro5.Event) { func (s *ContentScrollbar) Handle(ctx Context, ev allg5.Event) {
s.ControlBase.Handle(ctx, ev) s.ControlBase.Handle(ctx, ev)
s.handle.Handle(ctx, ev) s.handle.Handle(ctx, ev)
switch e := ev.(type) { switch e := ev.(type) {
case *allegro5.MouseMoveEvent: case *allg5.MouseMoveEvent:
if s.handle.IsPressed { if s.handle.IsPressed {
s.snapTo(e.X, e.Y) s.snapTo(e.X, e.Y)
} }
if 0 != e.DeltaZ && s.IsOver { if 0 != e.DeltaZ && s.IsOver {
var d = e.DeltaZ var d = e.DeltaZ
if allegro5.IsAnyKeyDown(allegro5.KeyLShift, allegro5.KeyRShift) { if allg5.IsAnyKeyDown(allg5.KeyLShift, allg5.KeyRShift) {
d *= 10 d *= 10
} }
s.increment(d) s.increment(d)
} }
case *allegro5.MouseButtonDownEvent: case *allg5.MouseButtonDownEvent:
if !s.handle.IsPressed && s.IsOver { if !s.handle.IsPressed && s.IsOver {
s.snapTo(e.X, e.Y) s.snapTo(e.X, e.Y)
} }

View File

@ -1,9 +1,9 @@
package ui package ui
import "opslag.de/schobers/galleg/allegro5" import "opslag.de/schobers/zntg/allg5"
type Context interface { type Context interface {
Display() *allegro5.Display Display() *allg5.Display
Fonts() Fonts Fonts() Fonts
Palette() Palette Palette() Palette
Debug() Debug Debug() Debug
@ -11,13 +11,13 @@ type Context interface {
type Debug interface { type Debug interface {
IsEnabled() bool IsEnabled() bool
Rainbow() allegro5.Color Rainbow() allg5.Color
} }
var _ Context = &context{} var _ Context = &context{}
type context struct { type context struct {
disp *allegro5.Display disp *allg5.Display
fts Fonts fts Fonts
pal Palette pal Palette
dbg *debug dbg *debug
@ -25,23 +25,23 @@ type context struct {
type debug struct { type debug struct {
enbl bool enbl bool
rainb []allegro5.Color rainb []allg5.Color
col int col int
} }
func rainbow() []allegro5.Color { func rainbow() []allg5.Color {
var colors = make([]allegro5.Color, len(Colors500)) var colors = make([]allg5.Color, len(Colors500))
for i, c := range Colors500 { for i, c := range Colors500 {
colors[i] = NewColorAlpha(c, 0x7f) colors[i] = NewColorAlpha(c, 0x7f)
} }
return colors return colors
} }
func newContext(disp *allegro5.Display, f Fonts) *context { func newContext(disp *allg5.Display, f Fonts) *context {
return &context{disp, f, DefaultPalette(), &debug{rainb: rainbow()}} return &context{disp, f, DefaultPalette(), &debug{rainb: rainbow()}}
} }
func (c *context) Display() *allegro5.Display { func (c *context) Display() *allg5.Display {
return c.disp return c.disp
} }
@ -65,7 +65,7 @@ func (d *debug) resetRainbow() {
d.col = 0 d.col = 0
} }
func (d *debug) Rainbow() allegro5.Color { func (d *debug) Rainbow() allg5.Color {
var col = d.col var col = d.col
d.col = (col + 1) % len(d.rainb) d.col = (col + 1) % len(d.rainb)
return d.rainb[col] return d.rainb[col]

View File

@ -3,7 +3,7 @@ package ui
import ( import (
"time" "time"
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
) )
@ -12,7 +12,7 @@ type Control interface {
Destroyed(Context) Destroyed(Context)
Update(Context, time.Duration) Update(Context, time.Duration)
Handle(Context, allegro5.Event) Handle(Context, allg5.Event)
DesiredSize(Context) geom.PointF DesiredSize(Context) geom.PointF
Rect() geom.RectangleF Rect() geom.RectangleF
SetRect(geom.RectangleF) SetRect(geom.RectangleF)
@ -31,7 +31,7 @@ type ControlBase struct {
IsPressed bool IsPressed bool
OnClick MouseClickFn OnClick MouseClickFn
MinSize geom.PointF MinSize geom.PointF
Background *allegro5.Color Background *allg5.Color
} }
func (c *ControlBase) Created(_ Context, p Container) error { func (c *ControlBase) Created(_ Context, p Container) error {
@ -43,15 +43,15 @@ func (c *ControlBase) Destroyed(Context) {}
func (c *ControlBase) Update(Context, time.Duration) {} func (c *ControlBase) Update(Context, time.Duration) {}
func (c *ControlBase) Handle(ctx Context, ev allegro5.Event) { func (c *ControlBase) Handle(ctx Context, ev allg5.Event) {
switch e := ev.(type) { switch e := ev.(type) {
case *allegro5.MouseMoveEvent: case *allg5.MouseMoveEvent:
c.IsOver = c.IsInRect(float64(e.X), float64(e.Y)) c.IsOver = c.IsInRect(float64(e.X), float64(e.Y))
case *allegro5.MouseButtonDownEvent: case *allg5.MouseButtonDownEvent:
if c.IsOver { if c.IsOver {
c.IsPressed = true c.IsPressed = true
} }
case *allegro5.MouseButtonUpEvent: case *allg5.MouseButtonUpEvent:
if c.IsPressed && c.IsOver { if c.IsPressed && c.IsOver {
var onClick = c.OnClick var onClick = c.OnClick
if nil != onClick { if nil != onClick {
@ -74,10 +74,10 @@ func (c *ControlBase) Render(ctx Context) {
var min = c.Bounds.Min.To32() var min = c.Bounds.Min.To32()
var max = c.Bounds.Max.To32() var max = c.Bounds.Max.To32()
if nil != c.Background { if nil != c.Background {
allegro5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, *c.Background) allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, *c.Background)
} }
if ctx.Debug().IsEnabled() { if ctx.Debug().IsEnabled() {
allegro5.DrawRectangle(min.X, min.Y, max.X, max.Y, ctx.Debug().Rainbow(), 5) allg5.DrawRectangle(min.X, min.Y, max.X, max.Y, ctx.Debug().Rainbow(), 5)
} }
} }

View File

@ -6,23 +6,23 @@ import (
"math" "math"
"github.com/llgcode/draw2d/draw2dimg" "github.com/llgcode/draw2d/draw2dimg"
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
) )
func drawBitmap(w, h int, draw func(*draw2dimg.GraphicContext)) *allegro5.Bitmap { func drawBitmap(w, h int, draw func(*draw2dimg.GraphicContext)) *allg5.Bitmap {
dest := image.NewRGBA(image.Rect(0, 0, w, h)) dest := image.NewRGBA(image.Rect(0, 0, w, h))
gc := draw2dimg.NewGraphicContext(dest) gc := draw2dimg.NewGraphicContext(dest)
gc.SetFillColor(color.Transparent) gc.SetFillColor(color.Transparent)
gc.Clear() gc.Clear()
draw(gc) draw(gc)
bmp, err := allegro5.NewBitmapFromImage(dest, false) bmp, err := allg5.NewBitmapFromImage(dest, false)
if nil != err { if nil != err {
return nil return nil
} }
return bmp return bmp
} }
func drawCircle(r, w int, startAngle, a float64, c color.Color) *allegro5.Bitmap { func drawCircle(r, w int, startAngle, a float64, c color.Color) *allg5.Bitmap {
var width = 2*r + w var width = 2*r + w
return drawBitmap(width, width, func(gc *draw2dimg.GraphicContext) { return drawBitmap(width, width, func(gc *draw2dimg.GraphicContext) {
gc.SetFillColor(c) gc.SetFillColor(c)

View File

@ -3,22 +3,22 @@ package ui
import ( import (
"github.com/spf13/afero" "github.com/spf13/afero"
"opslag.de/schobers/fs/vfs" "opslag.de/schobers/fs/vfs"
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
) )
type Fonts interface { type Fonts interface {
Register(name, path string, size int) error Register(name, path string, size int) error
Get(name string) *allegro5.Font Get(name string) *allg5.Font
Destroy() Destroy()
} }
type fonts struct { type fonts struct {
fts map[string]*allegro5.Font fts map[string]*allg5.Font
dir vfs.CopyDir dir vfs.CopyDir
} }
func newFonts(dir vfs.CopyDir) *fonts { func newFonts(dir vfs.CopyDir) *fonts {
return &fonts{make(map[string]*allegro5.Font), dir} return &fonts{make(map[string]*allg5.Font), dir}
} }
func NewFonts(fs afero.Fs) (Fonts, error) { func NewFonts(fs afero.Fs) (Fonts, error) {
@ -30,7 +30,7 @@ func NewFonts(fs afero.Fs) (Fonts, error) {
} }
func (fts *fonts) load(name, path string, size int) error { func (fts *fonts) load(name, path string, size int) error {
f, err := allegro5.LoadTTFFont(path, size) f, err := allg5.LoadTTFFont(path, size)
if nil != err { if nil != err {
return err return err
} }
@ -53,7 +53,7 @@ func (fts *fonts) Register(name, path string, size int) error {
return fts.load(name, path, size) return fts.load(name, path, size)
} }
func (fts *fonts) Get(name string) *allegro5.Font { func (fts *fonts) Get(name string) *allg5.Font {
return fts.fts[name] return fts.fts[name]
} }

View File

@ -1,14 +1,14 @@
package ui package ui
import ( import (
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
) )
type Label struct { type Label struct {
ControlBase ControlBase
Text string Text string
HorizontalAlignment allegro5.HorizontalAlignment HorizontalAlignment allg5.HorizontalAlignment
} }
func (l *Label) DesiredSize(ctx Context) geom.PointF { func (l *Label) DesiredSize(ctx Context) geom.PointF {

View File

@ -3,32 +3,32 @@ package ui
import ( import (
"time" "time"
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
) )
func shouldClose(ev allegro5.Event) bool { func shouldClose(ev allg5.Event) bool {
switch e := ev.(type) { switch e := ev.(type) {
case *allegro5.KeyCharEvent: case *allg5.KeyCharEvent:
switch e.KeyCode { switch e.KeyCode {
case allegro5.KeyEscape: case allg5.KeyEscape:
return true return true
case allegro5.KeyF4: case allg5.KeyF4:
if e.Modifiers&allegro5.KeyModAlt == allegro5.KeyModAlt { if e.Modifiers&allg5.KeyModAlt == allg5.KeyModAlt {
return true return true
} }
} }
case *allegro5.DisplayCloseEvent: case *allg5.DisplayCloseEvent:
return true return true
} }
return false return false
} }
func shouldToggleDebug(ev allegro5.Event) bool { func shouldToggleDebug(ev allg5.Event) bool {
switch e := ev.(type) { switch e := ev.(type) {
case *allegro5.KeyCharEvent: case *allg5.KeyCharEvent:
switch e.KeyCode { switch e.KeyCode {
case allegro5.KeyD: case allg5.KeyD:
return e.Modifiers&allegro5.KeyModAlt == allegro5.KeyModAlt return e.Modifiers&allg5.KeyModAlt == allg5.KeyModAlt
} }
} }
return false return false
@ -44,21 +44,21 @@ func switchState(ctx Context, curr State, s State) error {
} }
func Init() error { func Init() error {
return allegro5.Init(allegro5.InitAll) return allg5.Init(allg5.InitAll)
} }
func Run(w, h int, title string, s State, f Fonts, opts *allegro5.NewDisplayOptions) error { func Run(w, h int, title string, s State, f Fonts, opts *allg5.NewDisplayOptions) error {
if nil == opts { if nil == opts {
opts = &allegro5.NewDisplayOptions{} opts = &allg5.NewDisplayOptions{}
} }
disp, err := allegro5.NewDisplay(w, h, *opts) disp, err := allg5.NewDisplay(w, h, *opts)
if nil != err { if nil != err {
return err return err
} }
disp.SetWindowTitle(title) disp.SetWindowTitle(title)
defer disp.Destroy() defer disp.Destroy()
evq, err := allegro5.NewEventQueue() evq, err := allg5.NewEventQueue()
if nil != err { if nil != err {
return err return err
} }

View File

@ -3,63 +3,63 @@ package ui
import ( import (
"image/color" "image/color"
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
) )
type Palette interface { type Palette interface {
Primary() allegro5.Color Primary() allg5.Color
PrimaryHighlight() allegro5.Color PrimaryHighlight() allg5.Color
PrimaryTransparent() allegro5.Color PrimaryTransparent() allg5.Color
Lightest() allegro5.Color Lightest() allg5.Color
Darker() allegro5.Color Darker() allg5.Color
Darkest() allegro5.Color Darkest() allg5.Color
Disabled() allegro5.Color Disabled() allg5.Color
} }
type palette struct { type palette struct {
primary allegro5.Color primary allg5.Color
primaryH allegro5.Color primaryH allg5.Color
primaryT allegro5.Color primaryT allg5.Color
lightest allegro5.Color lightest allg5.Color
darker allegro5.Color darker allg5.Color
darkest allegro5.Color darkest allg5.Color
disabled allegro5.Color disabled allg5.Color
} }
func (p *palette) Primary() allegro5.Color { func (p *palette) Primary() allg5.Color {
return p.primary return p.primary
} }
func (p *palette) PrimaryHighlight() allegro5.Color { func (p *palette) PrimaryHighlight() allg5.Color {
return p.primaryH return p.primaryH
} }
func (p *palette) PrimaryTransparent() allegro5.Color { func (p *palette) PrimaryTransparent() allg5.Color {
return p.primaryT return p.primaryT
} }
func (p *palette) Lightest() allegro5.Color { func (p *palette) Lightest() allg5.Color {
return p.lightest return p.lightest
} }
func (p *palette) Darker() allegro5.Color { func (p *palette) Darker() allg5.Color {
return p.darker return p.darker
} }
func (p *palette) Darkest() allegro5.Color { func (p *palette) Darkest() allg5.Color {
return p.darkest return p.darkest
} }
func (p *palette) Disabled() allegro5.Color { func (p *palette) Disabled() allg5.Color {
return p.disabled return p.disabled
} }
func NewColor(c *color.RGBA) allegro5.Color { func NewColor(c *color.RGBA) allg5.Color {
return allegro5.NewColorAlpha(c.R, c.G, c.B, c.A) return allg5.NewColorAlpha(c.R, c.G, c.B, c.A)
} }
func NewColorAlpha(c *color.RGBA, a uint8) allegro5.Color { func NewColorAlpha(c *color.RGBA, a uint8) allg5.Color {
return allegro5.NewColorAlpha(c.R, c.G, c.B, a) return allg5.NewColorAlpha(c.R, c.G, c.B, a)
} }
func DefaultPalette() Palette { func DefaultPalette() Palette {
@ -68,9 +68,9 @@ func DefaultPalette() Palette {
primary: NewColor(primary), primary: NewColor(primary),
primaryH: NewColor(Blue400), primaryH: NewColor(Blue400),
primaryT: NewColorAlpha(primary, 96), primaryT: NewColorAlpha(primary, 96),
lightest: allegro5.NewColor(0xff, 0xff, 0xff), lightest: allg5.NewColor(0xff, 0xff, 0xff),
darker: allegro5.NewColorAlpha(0, 0, 0, 188), darker: allg5.NewColorAlpha(0, 0, 0, 188),
darkest: allegro5.NewColorAlpha(0, 0, 0, 222), darkest: allg5.NewColorAlpha(0, 0, 0, 222),
disabled: allegro5.NewColorAlpha(0x1f, 0x1f, 0x1f, 0x1f), disabled: allg5.NewColorAlpha(0x1f, 0x1f, 0x1f, 0x1f),
} }
} }

View File

@ -1,7 +1,7 @@
package ui package ui
import ( import (
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
) )
@ -29,13 +29,13 @@ func Scroll(c Control, o Orientation) Control {
return s return s
} }
func (s *scroll) Handle(ctx Context, ev allegro5.Event) { func (s *scroll) Handle(ctx Context, ev allg5.Event) {
s.Wrapper.Handle(ctx, ev) s.Wrapper.Handle(ctx, ev)
switch e := ev.(type) { switch e := ev.(type) {
case *allegro5.MouseMoveEvent: case *allg5.MouseMoveEvent:
if 0 != e.DeltaZ && !s.Bar.IsOver && geom.PtF(float64(e.X), float64(e.Y)).In(s.Bounds) { if 0 != e.DeltaZ && !s.Bar.IsOver && geom.PtF(float64(e.X), float64(e.Y)).In(s.Bounds) {
var d = e.DeltaZ var d = e.DeltaZ
if allegro5.IsAnyKeyDown(allegro5.KeyLShift, allegro5.KeyRShift) { if allg5.IsAnyKeyDown(allg5.KeyLShift, allg5.KeyRShift) {
d *= 10 d *= 10
} }
s.Bar.increment(d) s.Bar.increment(d)
@ -46,7 +46,7 @@ func (s *scroll) Handle(ctx Context, ev allegro5.Event) {
func (s *scroll) Render(ctx Context) { func (s *scroll) Render(ctx Context) {
var bounds = s.Content.Rect() var bounds = s.Content.Rect()
var w, h = bounds.Dx(), bounds.Dy() var w, h = bounds.Dx(), bounds.Dy()
var bmp, err = allegro5.NewVideoBitmap(int(w), int(h)) var bmp, err = allg5.NewVideoBitmap(int(w), int(h))
if nil != err { if nil != err {
return return
} }

View File

@ -5,7 +5,7 @@ import (
"github.com/llgcode/draw2d/draw2dimg" "github.com/llgcode/draw2d/draw2dimg"
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
) )
@ -25,9 +25,9 @@ type Scrollbar struct {
Orientation Orientation Orientation Orientation
OnChanged ScrollbarValueChangedFn OnChanged ScrollbarValueChangedFn
handle *ControlBase handle *ControlBase
normal *allegro5.Bitmap normal *allg5.Bitmap
hover *allegro5.Bitmap hover *allg5.Bitmap
pressed *allegro5.Bitmap pressed *allg5.Bitmap
} }
func (s *Scrollbar) Created(ctx Context, p Container) error { func (s *Scrollbar) Created(ctx Context, p Container) error {
@ -68,7 +68,7 @@ func (s *Scrollbar) Created(ctx Context, p Container) error {
} }
func (s *Scrollbar) Destroyed(ctx Context) { func (s *Scrollbar) Destroyed(ctx Context) {
var d = func(b *allegro5.Bitmap) { var d = func(b *allg5.Bitmap) {
if nil != b { if nil != b {
b.Destroy() b.Destroy()
} }
@ -152,22 +152,22 @@ func (s *Scrollbar) increment(d int) {
s.change(val) s.change(val)
} }
func (s *Scrollbar) Handle(ctx Context, ev allegro5.Event) { func (s *Scrollbar) Handle(ctx Context, ev allg5.Event) {
s.ControlBase.Handle(ctx, ev) s.ControlBase.Handle(ctx, ev)
s.handle.Handle(ctx, ev) s.handle.Handle(ctx, ev)
switch e := ev.(type) { switch e := ev.(type) {
case *allegro5.MouseMoveEvent: case *allg5.MouseMoveEvent:
if s.handle.IsPressed { if s.handle.IsPressed {
s.snapTo(e.X, e.Y) s.snapTo(e.X, e.Y)
} }
if 0 != e.DeltaZ && s.IsOver { if 0 != e.DeltaZ && s.IsOver {
var d = e.DeltaZ var d = e.DeltaZ
if allegro5.IsAnyKeyDown(allegro5.KeyLShift, allegro5.KeyRShift) { if allg5.IsAnyKeyDown(allg5.KeyLShift, allg5.KeyRShift) {
d *= 10 d *= 10
} }
s.increment(d) s.increment(d)
} }
case *allegro5.MouseButtonDownEvent: case *allg5.MouseButtonDownEvent:
if !s.handle.IsPressed && s.IsOver { if !s.handle.IsPressed && s.IsOver {
s.snapTo(e.X, e.Y) s.snapTo(e.X, e.Y)
} }
@ -221,11 +221,11 @@ func (s *Scrollbar) Render(ctx Context) {
switch s.Orientation { switch s.Orientation {
case OrientationHorizontal: case OrientationHorizontal:
// Left line // Left line
allegro5.DrawLine(min, center, centerH.X, center, ctx.Palette().Primary(), 2) allg5.DrawLine(min, center, centerH.X, center, ctx.Palette().Primary(), 2)
allegro5.DrawLine(centerH.X, center, max, center, ctx.Palette().PrimaryTransparent(), 2) allg5.DrawLine(centerH.X, center, max, center, ctx.Palette().PrimaryTransparent(), 2)
default: default:
allegro5.DrawLine(center, max, center, centerH.Y, ctx.Palette().PrimaryTransparent(), 2) allg5.DrawLine(center, max, center, centerH.Y, ctx.Palette().PrimaryTransparent(), 2)
allegro5.DrawLine(center, centerH.Y, center, min, ctx.Palette().Primary(), 2) allg5.DrawLine(center, centerH.Y, center, min, ctx.Palette().Primary(), 2)
} }
var minH = s.handle.Bounds.Min.To32() var minH = s.handle.Bounds.Min.To32()

View File

@ -1,29 +1,29 @@
package ui package ui
import ( import (
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
) )
var dropShadowPalette []allegro5.Color var dropShadowPalette []allg5.Color
func initDropShadowPalette() { func initDropShadowPalette() {
if nil != dropShadowPalette { if nil != dropShadowPalette {
return return
} }
dropShadowPalette = []allegro5.Color{ dropShadowPalette = []allg5.Color{
allegro5.NewColorAlpha(0, 0, 0, 0x0f), allg5.NewColorAlpha(0, 0, 0, 0x0f),
allegro5.NewColorAlpha(0, 0, 0, 0x07), allg5.NewColorAlpha(0, 0, 0, 0x07),
allegro5.NewColorAlpha(0, 0, 0, 0x03), allg5.NewColorAlpha(0, 0, 0, 0x03),
} }
} }
func DropShadow(x1, y1, x2, y2 float32) { func DropShadow(x1, y1, x2, y2 float32) {
initDropShadowPalette() initDropShadowPalette()
allegro5.DrawLine(x1, y2+1, x2+1, y2+1, dropShadowPalette[0], 1) allg5.DrawLine(x1, y2+1, x2+1, y2+1, dropShadowPalette[0], 1)
allegro5.DrawLine(x2+1, y1, x2+1, y2, dropShadowPalette[0], 1) allg5.DrawLine(x2+1, y1, x2+1, y2, dropShadowPalette[0], 1)
allegro5.DrawLine(x1, y2+2, x2+2, y2+2, dropShadowPalette[1], 1) allg5.DrawLine(x1, y2+2, x2+2, y2+2, dropShadowPalette[1], 1)
allegro5.DrawLine(x2+2, y1, x2+2, y2+1, dropShadowPalette[1], 1) allg5.DrawLine(x2+2, y1, x2+2, y2+1, dropShadowPalette[1], 1)
allegro5.DrawLine(x1+1, y2+3, x2+2, y2+3, dropShadowPalette[2], 1) allg5.DrawLine(x1+1, y2+3, x2+2, y2+3, dropShadowPalette[2], 1)
allegro5.DrawLine(x2+3, y1+1, x2+3, y2+2, dropShadowPalette[2], 1) allg5.DrawLine(x2+3, y1+1, x2+3, y2+2, dropShadowPalette[2], 1)
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/llgcode/draw2d/draw2dimg" "github.com/llgcode/draw2d/draw2dimg"
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
) )
var _ Control = &Spinner{} var _ Control = &Spinner{}
@ -15,7 +15,7 @@ type Spinner struct {
ControlBase ControlBase
Text string Text string
spin float32 spin float32
circs *allegro5.Bitmap circs *allg5.Bitmap
} }
func (s *Spinner) Created(ctx Context, p Container) error { func (s *Spinner) Created(ctx Context, p Container) error {
@ -81,19 +81,19 @@ func (s *Spinner) Render(ctx Context) {
var fnt = fonts.Get("default") var fnt = fonts.Get("default")
var textW = fnt.TextWidth(s.Text) var textW = fnt.TextWidth(s.Text)
allegro5.DrawFilledRectangle(0, 0, width, height, ctx.Palette().Disabled()) allg5.DrawFilledRectangle(0, 0, width, height, ctx.Palette().Disabled())
const marginH, marginV float32 = 64, 16 const marginH, marginV float32 = 64, 16
const textH float32 = 12 const textH float32 = 12
var rectW, rectH float32 = textW + 2*marginH, 3*marginV + textH + 32 var rectW, rectH float32 = textW + 2*marginH, 3*marginV + textH + 32
var rectX, rectY = (width - rectW) * .5, (height - rectH) * .5 var rectX, rectY = (width - rectW) * .5, (height - rectH) * .5
allegro5.DrawFilledRectangle(rectX, rectY, rectX+rectW, rectY+rectH, ctx.Palette().Lightest()) allg5.DrawFilledRectangle(rectX, rectY, rectX+rectW, rectY+rectH, ctx.Palette().Lightest())
DropShadow(rectX, rectY, rectX+rectW, rectY+rectH) DropShadow(rectX, rectY, rectX+rectW, rectY+rectH)
fnt.Draw(rectX+marginH, rectY+marginV, ctx.Palette().Darkest(), allegro5.AlignLeft, s.Text) fnt.Draw(rectX+marginH, rectY+marginV, ctx.Palette().Darkest(), allg5.AlignLeft, s.Text)
const numCircs = 36 const numCircs = 36
var i = int(math.Floor(float64(s.spin) * numCircs)) var i = int(math.Floor(float64(s.spin) * numCircs))
s.circs.Subs()[i].DrawOptions(width*.5, rectY+2*marginV+2*textH, allegro5.DrawOptions{Center: true}) s.circs.Subs()[i].DrawOptions(width*.5, rectY+2*marginV+2*textH, allg5.DrawOptions{Center: true})
s.ControlBase.Render(ctx) s.ControlBase.Render(ctx)
} }

View File

@ -4,7 +4,7 @@ import (
"log" "log"
"time" "time"
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
) )
@ -12,7 +12,7 @@ type State interface {
Enter(Context) error Enter(Context) error
Leave(Context) error Leave(Context) error
Update(Context, time.Duration) (State, error) Update(Context, time.Duration) (State, error)
Handle(Context, allegro5.Event) error Handle(Context, allg5.Event) error
Render(Context) error Render(Context) error
} }
@ -46,7 +46,7 @@ func (s *StateBase) Update(ctx Context, dt time.Duration) (State, error) {
return s.ChangeTo, nil return s.ChangeTo, nil
} }
func (s *StateBase) Handle(ctx Context, ev allegro5.Event) error { func (s *StateBase) Handle(ctx Context, ev allg5.Event) error {
if nil != s.Control { if nil != s.Control {
s.Control.Handle(ctx, ev) s.Control.Handle(ctx, ev)
} }

View File

@ -3,7 +3,7 @@ package ui
import ( import (
"math" "math"
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
) )
@ -26,12 +26,12 @@ func (b *StatusBar) Render(ctx Context) {
var min = b.Bounds.Min.To32() var min = b.Bounds.Min.To32()
var max = b.Bounds.Max.To32() var max = b.Bounds.Max.To32()
allegro5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, ctx.Palette().Primary()) allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, ctx.Palette().Primary())
var fnt = fonts.Get("default") var fnt = fonts.Get("default")
var y = min.Y + float32(.5*b.Bounds.Dy()) - .67*fnt.Ascent() var y = min.Y + float32(.5*b.Bounds.Dy()) - .67*fnt.Ascent()
fnt.Draw(min.X+leftMargin, y, ctx.Palette().Lightest(), allegro5.AlignLeft, b.Text) fnt.Draw(min.X+leftMargin, y, ctx.Palette().Lightest(), allg5.AlignLeft, b.Text)
fnt.Draw(max.X-leftMargin, y, ctx.Palette().Lightest(), allegro5.AlignRight, b.RightText) fnt.Draw(max.X-leftMargin, y, ctx.Palette().Lightest(), allg5.AlignRight, b.RightText)
b.ControlBase.Render(ctx) b.ControlBase.Render(ctx)
} }

View File

@ -3,7 +3,7 @@ package ui
import ( import (
"time" "time"
"opslag.de/schobers/galleg/allegro5" "opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom" "opslag.de/schobers/geom"
) )
@ -28,7 +28,7 @@ func (w *Wrapper) Update(ctx Context, d time.Duration) {
w.Wrapped.Update(ctx, d) w.Wrapped.Update(ctx, d)
} }
func (w *Wrapper) Handle(ctx Context, ev allegro5.Event) { func (w *Wrapper) Handle(ctx Context, ev allg5.Event) {
w.Wrapped.Handle(ctx, ev) w.Wrapped.Handle(ctx, ev)
} }