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 <stdlib.h>

View File

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

View File

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

View File

@ -1,6 +1,6 @@
// +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++
import "C"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,21 +1,21 @@
package ui
import (
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg/allg5"
)
type Button struct {
ControlBase
Text string
HorizontalAlignment allegro5.HorizontalAlignment
HorizontalAlignment allg5.HorizontalAlignment
}
func NewButton(text string, click MouseClickFn) *Button {
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}
}
@ -40,14 +40,14 @@ func (b *Button) Render(ctx Context) {
if b.IsOver && !b.IsPressed {
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 {
case allegro5.AlignLeft:
fnt.Draw(min.X+.5*fntH, min.Y+.5*fntH, ctx.Palette().Lightest(), allegro5.AlignLeft, b.Text)
case allegro5.AlignCenter:
fnt.Draw(.5*(min.X+max.X), min.Y+.5*fntH, ctx.Palette().Lightest(), allegro5.AlignCenter, b.Text)
case allegro5.AlignRight:
fnt.Draw(min.X-.5*fntH, min.Y+.5*fntH, ctx.Palette().Lightest(), allegro5.AlignRight, b.Text)
case allg5.AlignLeft:
fnt.Draw(min.X+.5*fntH, min.Y+.5*fntH, ctx.Palette().Lightest(), allg5.AlignLeft, b.Text)
case allg5.AlignCenter:
fnt.Draw(.5*(min.X+max.X), min.Y+.5*fntH, ctx.Palette().Lightest(), allg5.AlignCenter, b.Text)
case allg5.AlignRight:
fnt.Draw(min.X-.5*fntH, min.Y+.5*fntH, ctx.Palette().Lightest(), allg5.AlignRight, b.Text)
}
b.ControlBase.Render(ctx)

View File

@ -6,13 +6,13 @@ import (
"github.com/llgcode/draw2d/draw2dimg"
"github.com/llgcode/draw2d/draw2dkit"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg/allg5"
)
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) {
var size = float64(checkboxSize)
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) {
var size = float64(checkboxSize)
var margin = float64(checkboxMargin)
@ -47,8 +47,8 @@ type Checkbox struct {
Value bool
Text string
OnChanged CheckboxValueChangedFn
checked *allegro5.Bitmap
unchecked *allegro5.Bitmap
checked *allg5.Bitmap
unchecked *allg5.Bitmap
}
func (c *Checkbox) Created(ctx Context, p Container) error {
@ -65,11 +65,11 @@ func (c *Checkbox) Created(ctx Context, p Container) error {
return nil
}
func (c *Checkbox) Handle(ctx Context, ev allegro5.Event) {
func (c *Checkbox) Handle(ctx Context, ev allg5.Event) {
var pressed = c.IsPressed
c.ControlBase.Handle(ctx, ev)
switch ev.(type) {
case *allegro5.MouseButtonUpEvent:
case *allg5.MouseButtonUpEvent:
if !c.Disabled && pressed && c.IsOver {
c.Value = !c.Value
var onChanged = c.OnChanged
@ -87,7 +87,7 @@ func (c *Checkbox) DesiredSize(ctx Context) geom.PointF {
return geom.PtF(float64(w+checkboxSize), checkboxSize)
}
func (c *Checkbox) box() *allegro5.Bitmap {
func (c *Checkbox) box() *allg5.Bitmap {
if c.Value {
return c.checked
}
@ -100,10 +100,10 @@ func (c *Checkbox) Render(ctx Context) {
var min = c.Bounds.Min.To32()
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 {
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 {
c.box().Draw(min.X, min.Y)
}

View File

@ -3,8 +3,8 @@ package ui
import (
"time"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg/allg5"
)
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 {
child.Handle(ctx, ev)
}

View File

@ -3,8 +3,8 @@ package ui
import (
"math"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg/allg5"
)
var _ Control = &ContentScrollbar{}
@ -35,7 +35,7 @@ func (h *contentScrollbarHandle) Render(ctx Context) {
}
var min = h.Bounds.Min.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 {
@ -138,22 +138,22 @@ func (s *ContentScrollbar) increment(d int) {
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.handle.Handle(ctx, ev)
switch e := ev.(type) {
case *allegro5.MouseMoveEvent:
case *allg5.MouseMoveEvent:
if s.handle.IsPressed {
s.snapTo(e.X, e.Y)
}
if 0 != e.DeltaZ && s.IsOver {
var d = e.DeltaZ
if allegro5.IsAnyKeyDown(allegro5.KeyLShift, allegro5.KeyRShift) {
if allg5.IsAnyKeyDown(allg5.KeyLShift, allg5.KeyRShift) {
d *= 10
}
s.increment(d)
}
case *allegro5.MouseButtonDownEvent:
case *allg5.MouseButtonDownEvent:
if !s.handle.IsPressed && s.IsOver {
s.snapTo(e.X, e.Y)
}

View File

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

View File

@ -3,7 +3,7 @@ package ui
import (
"time"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom"
)
@ -12,7 +12,7 @@ type Control interface {
Destroyed(Context)
Update(Context, time.Duration)
Handle(Context, allegro5.Event)
Handle(Context, allg5.Event)
DesiredSize(Context) geom.PointF
Rect() geom.RectangleF
SetRect(geom.RectangleF)
@ -31,7 +31,7 @@ type ControlBase struct {
IsPressed bool
OnClick MouseClickFn
MinSize geom.PointF
Background *allegro5.Color
Background *allg5.Color
}
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) Handle(ctx Context, ev allegro5.Event) {
func (c *ControlBase) Handle(ctx Context, ev allg5.Event) {
switch e := ev.(type) {
case *allegro5.MouseMoveEvent:
case *allg5.MouseMoveEvent:
c.IsOver = c.IsInRect(float64(e.X), float64(e.Y))
case *allegro5.MouseButtonDownEvent:
case *allg5.MouseButtonDownEvent:
if c.IsOver {
c.IsPressed = true
}
case *allegro5.MouseButtonUpEvent:
case *allg5.MouseButtonUpEvent:
if c.IsPressed && c.IsOver {
var onClick = c.OnClick
if nil != onClick {
@ -74,10 +74,10 @@ func (c *ControlBase) Render(ctx Context) {
var min = c.Bounds.Min.To32()
var max = c.Bounds.Max.To32()
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() {
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"
"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))
gc := draw2dimg.NewGraphicContext(dest)
gc.SetFillColor(color.Transparent)
gc.Clear()
draw(gc)
bmp, err := allegro5.NewBitmapFromImage(dest, false)
bmp, err := allg5.NewBitmapFromImage(dest, false)
if nil != err {
return nil
}
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
return drawBitmap(width, width, func(gc *draw2dimg.GraphicContext) {
gc.SetFillColor(c)

View File

@ -3,22 +3,22 @@ package ui
import (
"github.com/spf13/afero"
"opslag.de/schobers/fs/vfs"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/zntg/allg5"
)
type Fonts interface {
Register(name, path string, size int) error
Get(name string) *allegro5.Font
Get(name string) *allg5.Font
Destroy()
}
type fonts struct {
fts map[string]*allegro5.Font
fts map[string]*allg5.Font
dir vfs.CopyDir
}
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) {
@ -30,7 +30,7 @@ func NewFonts(fs afero.Fs) (Fonts, 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 {
return err
}
@ -53,7 +53,7 @@ func (fts *fonts) Register(name, path string, size int) error {
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]
}

View File

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

View File

@ -3,32 +3,32 @@ package ui
import (
"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) {
case *allegro5.KeyCharEvent:
case *allg5.KeyCharEvent:
switch e.KeyCode {
case allegro5.KeyEscape:
case allg5.KeyEscape:
return true
case allegro5.KeyF4:
if e.Modifiers&allegro5.KeyModAlt == allegro5.KeyModAlt {
case allg5.KeyF4:
if e.Modifiers&allg5.KeyModAlt == allg5.KeyModAlt {
return true
}
}
case *allegro5.DisplayCloseEvent:
case *allg5.DisplayCloseEvent:
return true
}
return false
}
func shouldToggleDebug(ev allegro5.Event) bool {
func shouldToggleDebug(ev allg5.Event) bool {
switch e := ev.(type) {
case *allegro5.KeyCharEvent:
case *allg5.KeyCharEvent:
switch e.KeyCode {
case allegro5.KeyD:
return e.Modifiers&allegro5.KeyModAlt == allegro5.KeyModAlt
case allg5.KeyD:
return e.Modifiers&allg5.KeyModAlt == allg5.KeyModAlt
}
}
return false
@ -44,21 +44,21 @@ func switchState(ctx Context, curr State, s State) 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 {
opts = &allegro5.NewDisplayOptions{}
opts = &allg5.NewDisplayOptions{}
}
disp, err := allegro5.NewDisplay(w, h, *opts)
disp, err := allg5.NewDisplay(w, h, *opts)
if nil != err {
return err
}
disp.SetWindowTitle(title)
defer disp.Destroy()
evq, err := allegro5.NewEventQueue()
evq, err := allg5.NewEventQueue()
if nil != err {
return err
}

View File

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

View File

@ -1,7 +1,7 @@
package ui
import (
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom"
)
@ -29,13 +29,13 @@ func Scroll(c Control, o Orientation) Control {
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)
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) {
var d = e.DeltaZ
if allegro5.IsAnyKeyDown(allegro5.KeyLShift, allegro5.KeyRShift) {
if allg5.IsAnyKeyDown(allg5.KeyLShift, allg5.KeyRShift) {
d *= 10
}
s.Bar.increment(d)
@ -46,7 +46,7 @@ func (s *scroll) Handle(ctx Context, ev allegro5.Event) {
func (s *scroll) Render(ctx Context) {
var bounds = s.Content.Rect()
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 {
return
}

View File

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

View File

@ -1,29 +1,29 @@
package ui
import (
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/zntg/allg5"
)
var dropShadowPalette []allegro5.Color
var dropShadowPalette []allg5.Color
func initDropShadowPalette() {
if nil != dropShadowPalette {
return
}
dropShadowPalette = []allegro5.Color{
allegro5.NewColorAlpha(0, 0, 0, 0x0f),
allegro5.NewColorAlpha(0, 0, 0, 0x07),
allegro5.NewColorAlpha(0, 0, 0, 0x03),
dropShadowPalette = []allg5.Color{
allg5.NewColorAlpha(0, 0, 0, 0x0f),
allg5.NewColorAlpha(0, 0, 0, 0x07),
allg5.NewColorAlpha(0, 0, 0, 0x03),
}
}
func DropShadow(x1, y1, x2, y2 float32) {
initDropShadowPalette()
allegro5.DrawLine(x1, y2+1, x2+1, y2+1, dropShadowPalette[0], 1)
allegro5.DrawLine(x2+1, y1, x2+1, y2, dropShadowPalette[0], 1)
allegro5.DrawLine(x1, y2+2, x2+2, y2+2, dropShadowPalette[1], 1)
allegro5.DrawLine(x2+2, y1, x2+2, y2+1, dropShadowPalette[1], 1)
allegro5.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(x1, y2+1, x2+1, y2+1, dropShadowPalette[0], 1)
allg5.DrawLine(x2+1, y1, x2+1, y2, dropShadowPalette[0], 1)
allg5.DrawLine(x1, y2+2, x2+2, y2+2, dropShadowPalette[1], 1)
allg5.DrawLine(x2+2, y1, x2+2, y2+1, dropShadowPalette[1], 1)
allg5.DrawLine(x1+1, y2+3, x2+2, y2+3, 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"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/zntg/allg5"
)
var _ Control = &Spinner{}
@ -15,7 +15,7 @@ type Spinner struct {
ControlBase
Text string
spin float32
circs *allegro5.Bitmap
circs *allg5.Bitmap
}
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 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 textH float32 = 12
var rectW, rectH float32 = textW + 2*marginH, 3*marginV + textH + 32
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)
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
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)
}

View File

@ -4,7 +4,7 @@ import (
"log"
"time"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom"
)
@ -12,7 +12,7 @@ type State interface {
Enter(Context) error
Leave(Context) error
Update(Context, time.Duration) (State, error)
Handle(Context, allegro5.Event) error
Handle(Context, allg5.Event) error
Render(Context) error
}
@ -46,7 +46,7 @@ func (s *StateBase) Update(ctx Context, dt time.Duration) (State, error) {
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 {
s.Control.Handle(ctx, ev)
}

View File

@ -3,7 +3,7 @@ package ui
import (
"math"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom"
)
@ -26,12 +26,12 @@ func (b *StatusBar) Render(ctx Context) {
var min = b.Bounds.Min.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 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(max.X-leftMargin, y, ctx.Palette().Lightest(), allegro5.AlignRight, b.RightText)
fnt.Draw(min.X+leftMargin, y, ctx.Palette().Lightest(), allg5.AlignLeft, b.Text)
fnt.Draw(max.X-leftMargin, y, ctx.Palette().Lightest(), allg5.AlignRight, b.RightText)
b.ControlBase.Render(ctx)
}

View File

@ -3,7 +3,7 @@ package ui
import (
"time"
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/zntg/allg5"
"opslag.de/schobers/geom"
)
@ -28,7 +28,7 @@ func (w *Wrapper) Update(ctx Context, d time.Duration) {
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)
}