frame

package module
v0.0.0-...-18f2610 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2017 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AcmeColors = &Colors{
		Back:  image.NewUniform(color.RGBA{0, 0, 0, 0}),
		Text:  image.NewUniform(color.RGBA{255, 0, 0, 255}),
		HText: image.NewUniform(color.RGBA{0, 0, 0, 255}),
		HBack: image.NewUniform(color.RGBA{255, 0, 0, 128}),
	}
	DefaultColors  = defaultColors
	DarkGrayColors = &Colors{
		Back:  image.NewUniform(color.RGBA{33, 33, 33, 4}),
		Text:  image.NewUniform(color.RGBA{0, 128 + 64, 128 + 64, 255}),
		HText: image.NewUniform(color.RGBA{0, 0, 0, 255}),
		HBack: image.NewUniform(color.RGBA{0, 128, 128, 64}),
	}
	GrayColors = &Colors{
		Back:  image.NewUniform(color.RGBA{48, 48, 48, 0}),
		Text:  image.NewUniform(color.RGBA{99, 99, 99, 255}),
		HText: image.NewUniform(color.RGBA{0, 0, 0, 255}),
		HBack: image.NewUniform(color.RGBA{0, 128, 128, 64}),
	}
)
View Source
var AlphaNum = []byte("*&!%-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
View Source
var Clip []byte
View Source
var DefaultOpt = Opt{
	Inset: -2,
	Width: 100, Height: 33,
	FGColor:  image.NewUniform(color.RGBA{44, 44, 44, 0}),
	BGColor:  image.NewUniform(color.RGBA{22, 22, 22, 0}),
	BGColor2: image.NewUniform(color.RGBA{33, 33, 33, 0}),
	BRColor:  image.NewUniform(color.RGBA{22, 22, 22, 0}),
}
View Source
var Free = [...]byte{'"', '\'', '`'}
View Source
var HintColor = image.NewUniform(color.RGBA{255, 0, 0, 255})
View Source
var Lefts = [...]byte{'(', '{', '[', '<', '"', '\'', '`'}
View Source
var MenuColor = image.NewUniform(color.RGBA{128, 128, 128, 255})
View Source
var NL = []byte{'\n'}
View Source
var Rights = [...]byte{')', '}', ']', '>', '"', '\'', '`'}

Functions

func Ellipse

func Ellipse(dst draw.Image, c image.Point, src image.Image, a, b, thick int, sp image.Point, alpha, phi int)

Ellipse draws a filled ellipse at center point c and eccentricity a and b. The thick argument is ignored (until a line drawing function is available)

The method uses an efficient integer-based rasterization technique originally described in:

McIlroy, M.D.: There is no royal road to programs: a trilogy on raster ellipses and programming methodology, Computer Science TR155, AT&T Bell Laboratories, 1990

func ParseDefaultFont

func ParseDefaultFont(size float64) font.Face

func Xor

func Xor(r0, r1 image.Rectangle) (image.Rectangle, error)
func init(){
	r0 := image.Rect(0,0,100,100)
	r1 := image.Rect(50,0,100,100)
	r2 := image.Rect(0 ,50,100,100)
	r3 := image.Rect(0 ,0,50,100)
	r4 := image.Rect(0 ,0,0,50)
	x01, _ := Xor(r0,r1)
	x02, _ := Xor(r0,r2)
	fmt.Println(r1, r3)
	panic(".")
}

Types

type Action

type Action func(mouse.Event)

Action executes a procedure on the event of a specific state transition

type Box

type Box struct {
	// contains filtered or unexported fields
}

func (Box) Bytes

func (b Box) Bytes() []byte

func (*Box) Cap

func (b *Box) Cap() int

func (*Box) Len

func (b *Box) Len() int

func (*Box) Width

func (b *Box) Width() int

type Boxes

type Boxes struct {
	Box []*Box
	// contains filtered or unexported fields
}

func NewBoxes

func NewBoxes(measure func([]byte) int) *Boxes

func (*Boxes) Add

func (b *Boxes) Add(n int)

func (*Boxes) Chop

func (b *Boxes) Chop(bn, n int)

Chop discards the first n bytes of box bn

func (*Boxes) Delete

func (b *Boxes) Delete(n0, n1 int)

func (*Boxes) Dump

func (b *Boxes) Dump()

func (*Boxes) Dup

func (b *Boxes) Dup(n int) *Box

func (*Boxes) Find

func (b *Boxes) Find(n, i, j int) (int, error)

Find starts at box n, assuming offset i, and advances to offset j. It returns the box number containing offset j, guaraneed to align on a box boundary.

func (*Boxes) Insert

func (b *Boxes) Insert(p []byte, off int)

func (*Boxes) Merge

func (b *Boxes) Merge(n int)

func (*Boxes) ReadAt

func (b *Boxes) ReadAt(p []byte, off int64) (n int, err error)

func (*Boxes) Split

func (b *Boxes) Split(n int, at int)

func (*Boxes) Truncate

func (b *Boxes) Truncate(bn, n int)

Truncate discards all but the first n bytes of box bn

func (*Boxes) WriteAt

func (b *Boxes) WriteAt(p []byte, off int64) (n int, err error)

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func (*Cache) DrawHint

func (c *Cache) DrawHint(dst draw.Image)

func (*Cache) IndexOf

func (c *Cache) IndexOf(pt image.Point) (i int, ok bool)

func (*Cache) PointOf

func (c *Cache) PointOf(i int) (pt image.Point, ok bool)

func (*Cache) Set

func (c *Cache) Set(bounds image.Rectangle, i int, b byte)

type Chord

type Chord struct {
	Start int
	Seq   int
	Step  int
}

type Click

type Click struct {
	Button mouse.Button
	At     image.Point
	Time   time.Time
}

type ClickEvent

type ClickEvent struct {
	mouse.Event
	Time   time.Time
	Double bool
}

type Colors

type Colors struct {
	Text, Back   image.Image
	HText, HBack image.Image
}

type CommitEvent

type CommitEvent struct {
	mouse.Event
}

type Direction

type Direction int
const (
	DirUp   Direction = -1
	DirNone Direction = 0
	DirDown Direction = 1
)

type Dot

type Dot struct {
	image.Point
	// contains filtered or unexported fields
}

func NewDot

func NewDot(origin image.Point, maxw int, font *Font) *Dot

func (*Dot) Advance

func (d *Dot) Advance(r rune) int

func (*Dot) Height

func (d *Dot) Height() int

func (*Dot) Insert

func (d *Dot) Insert(r rune) image.Point

Insert advances dot by the width of r, or starts a new line if r doesn't fit

func (*Dot) InsertBox

func (d *Dot) InsertBox(b *Box) image.Point

func (*Dot) Newline

func (d *Dot) Newline()

func (*Dot) Origin

func (d *Dot) Origin() image.Point

func (*Dot) Visible

func (d *Dot) Visible(r rune) bool

func (*Dot) Width

func (d *Dot) Width() int

Width returns the amount of horizontal pixels covered by dot starting from the origin

type Drawer

type Drawer interface {
	// contains filtered or unexported methods
}

type Font

type Font struct {
	font.Face
	// contains filtered or unexported fields
}

func NewFont

func NewFont(face font.Face) *Font

func (*Font) Height

func (f *Font) Height() int

type Frame

type Frame struct {
	Option
	Tick *Tick

	Cache Cache

	Menu  *Menu
	Mouse *Mouse
	// contains filtered or unexported fields
}

func New

func New(origin, size image.Point, events Sender, opt *Option) *Frame

New initializes a new frame on disp. The first glyph of text is inserted at point p. If opt is nil, the default color, wrapping, and font settings are used.

func (*Frame) Bounds

func (f *Frame) Bounds() (r image.Rectangle)

func (*Frame) Box

func (f *Frame) Box(bn int) *Box

func (*Frame) Boxes

func (f *Frame) Boxes() []*Box

func (*Frame) Bytes

func (f *Frame) Bytes() []byte

func (*Frame) CleanRange

func (f *Frame) CleanRange()

func (*Frame) Delete

func (f *Frame) Delete(i, j int) (err error)

Delete erases the range [i:j] in the framebuffer TODO: fix i == j

func (*Frame) Dirty

func (f *Frame) Dirty() bool

func (*Frame) DirtyRange

func (f *Frame) DirtyRange() []Range

func (*Frame) Draw

func (f *Frame) Draw(force bool)

func (*Frame) Handle

func (f *Frame) Handle(e interface{})

Handle handles events sent to the frame. The key.Event and mouse.Events are handled.

func (*Frame) Image

func (f *Frame) Image() draw.Image

func (*Frame) IndexOf

func (f *Frame) IndexOf(pt image.Point) (bn, offset int)

func (*Frame) Insert

func (f *Frame) Insert(s []byte, i int) (err error)

Insert inserts s starting from index i in the the frame buffer.

func (*Frame) Mark

func (f *Frame) Mark()

func (*Frame) MarkRange

func (f *Frame) MarkRange(i, j int)

func (*Frame) Origin

func (f *Frame) Origin() image.Point

Origin returns the insertion point of the first glyph in the frame

func (*Frame) PointOf

func (f *Frame) PointOf(x int) (pt image.Point)

PointOf computes the point of origin for glyph x

func (*Frame) RGBA

func (f *Frame) RGBA() *image.RGBA

func (*Frame) Redraw

func (f *Frame) Redraw(selecting bool)

Redraw redraws the entire frame. The caller should check that the frame is Dirty before calling this in a tight loop

func (*Frame) RedrawBox

func (f *Frame) RedrawBox(i, j int)

func (*Frame) RedrawBytes

func (f *Frame) RedrawBytes(origin image.Point, width int, s []byte)

func (*Frame) RedrawRange

func (f *Frame) RedrawRange(i, j int)

func (*Frame) Release

func (f *Frame) Release()

func (*Frame) Resize

func (f *Frame) Resize(size image.Point)

func (*Frame) Size

func (f *Frame) Size() image.Point

type Handler

type Handler interface {
	Draw()
	screen.Buffer
	Handle(interface{})
	Dirty() bool
}

type InsertEvent

type InsertEvent struct {
	mouse.Event
}

type Item

type Item struct {
	Name string
	Menu *Menu

	*Opt
	// contains filtered or unexported fields
}

type Machine

type Machine struct {
	Sink chan mouse.Event

	// Should only send events, no recieving.
	Sender
	// contains filtered or unexported fields
}

Machine is the conduit that state transitions happen though. It contains a Skink chan for input mouse events that drive the StateFns

func NewMachine

func NewMachine(deque Sender, f *Frame) *Machine

NewMachine initialize a new state machine with no-op functions for all chording events.

func (*Machine) CloseTo

func (m *Machine) CloseTo(e, f mouse.Event) bool

func (*Machine) Run

func (m *Machine) Run() chan mouse.Event

type MarkEvent

type MarkEvent struct {
	mouse.Event
}
type Menu struct {
	Item []*Item
	Sel  *Item

	*Opt
	// contains filtered or unexported fields
}

func NewMenuFS

func NewMenuFS(basedir string, dr Drawer, se Sender) *Menu

func NewMenuJSON

func NewMenuJSON(json []byte, dr Drawer, se Sender) *Menu
func (m *Menu) Bounds() image.Rectangle
func (m *Menu) Draw(dst draw.Image)
func (m *Menu) Hit(pt image.Point)
func (m *Menu) Size() image.Point
func (m *Menu) String() string
func (m *Menu) Strings() []string
func (m *Menu) Unselect()
func (m *Menu) Visible() bool
type MenuEvent struct {
	image.Point
	Strings []string
}

type Mouse

type Mouse struct {
	Chord Chord
	Last  []Click
	Down  mouse.Button
	At    image.Point

	*Machine
	// contains filtered or unexported fields
}

func NewMouse

func NewMouse(delay time.Duration, events Sender, f *Frame) *Mouse

func (*Mouse) Double

func (m *Mouse) Double() bool

Double returns true if and only if the previous event is part of a double click

func (*Mouse) Process

func (m *Mouse) Process(e mouse.Event)

func (*Mouse) Pt

func (m *Mouse) Pt() image.Point

type Opt

type Opt struct {
	Inset         int
	Width, Height int
	FGColor       image.Image
	BGColor       image.Image
	BGColor2      image.Image
	BRColor       image.Image
}

type Option

type Option struct {
	// Font is the font face for the frame
	*Font

	// Number of glyphs drawn on one line before wrapping
	Wrap int

	// Colors define the text and background colors for the rame
	// Text: glyph color
	// Back: background color
	// HText: highlighted glyph color
	// HBack: highlighted background color
	Colors Colors
	// contains filtered or unexported fields
}

func (Option) FontHeight

func (o Option) FontHeight() int

type Range

type Range struct {
	I, J int
}

type Resolver

type Resolver interface {
	PointOf(int) image.Point
	IndexOf(image.Point) (int, int)
	Height() int
	Origin() image.Point
}

type Sc

type Sc struct {
	Bar image.Rectangle

	BarColor, FrameColor image.Image
	// contains filtered or unexported fields
}

func NewSc

func NewSc(src Handler, origin, size image.Point, width int, bar, frame image.Image) *Sc

func (*Sc) Bounds

func (s *Sc) Bounds() image.Rectangle

func (*Sc) Clicksb

func (s *Sc) Clicksb(pt image.Point, dir Direction)

func (*Sc) Dirty

func (s *Sc) Dirty() bool

func (*Sc) Draw

func (s *Sc) Draw()

func (*Sc) EmbedBounds

func (s *Sc) EmbedBounds() image.Rectangle

func (*Sc) Handle

func (s *Sc) Handle(e interface{})

func (*Sc) Project

func (s *Sc) Project(x, y float32) (float32, float32)

func (*Sc) RGBA

func (s *Sc) RGBA() *image.RGBA

func (*Sc) Release

func (s *Sc) Release()

func (*Sc) Size

func (s *Sc) Size() image.Point

type Scroller

type Scroller interface {
	Image() draw.Image
	Bounds() image.Rectangle
	Visible() image.Rectangle
	Shift(pt image.Point)
}

type Select

type Select struct {
	Img   *image.RGBA // todo: use New
	Color image.Image

	// avoid redrawing the entire selection on the
	// canvas by caching the three rectangles representing
	// the selection
	R [3]image.Rectangle
	// contains filtered or unexported fields
}

Select consists of 3 rectangles

func NewSelect

func NewSelect(r image.Rectangle, img *image.RGBA, color image.Image, res Resolver) *Select

func (Select) Addr

func (s Select) Addr() (i, j int)

func (*Select) Clear

func (s *Select) Clear()

func (*Select) Close

func (s *Select) Close()

func (*Select) DeltaRects

func (s *Select) DeltaRects() (r []image.Rectangle)

func (*Select) Draw

func (s *Select) Draw(p, q image.Point, bg image.Image)

func (Select) Ep

func (s Select) Ep() image.Point

func (*Select) Open

func (s *Select) Open(i int)

func (*Select) Rects

func (s *Select) Rects() (r []image.Rectangle)

Rects returns the rectangles representing the active selection. cap(r) == 3

func (*Select) Resize

func (s *Select) Resize(size image.Point)

func (*Select) Seek

func (s *Select) Seek(offset int64, whence int) (int64, error)

func (Select) Sp

func (s Select) Sp() image.Point

func (*Select) Sweep

func (s *Select) Sweep(j int)

func (*Select) Update

func (s *Select) Update(j int)

type SelectEvent

type SelectEvent struct {
	mouse.Event
}

type Sender

type Sender interface {
	Send(i interface{})
	SendFirst(i interface{})
}

type SnarfEvent

type SnarfEvent struct {
	mouse.Event
}

type State

type State int

State is the state of the machine

const (
	StateNone State = iota
	StateSelect
	StateSweep
	StateSnarf
	StateInsert
	StateCommit
)

type StateFn

type StateFn func(*Machine, mouse.Event) StateFn

StateFn is a state function that expresses a state transition. All StateFns return the next state as a transitionary StateFn

type SweepEvent

type SweepEvent struct {
	mouse.Event
	Ctr int
}

type Tick

type Tick struct {
	Pen    [3]*Select
	P0, P1 int
	Fr     *Frame
	// contains filtered or unexported fields
}

func NewTick

func NewTick(f *Frame) *Tick

func (*Tick) Cancel

func (t *Tick) Cancel()

func (*Tick) Close

func (t *Tick) Close() error

func (*Tick) Commit

func (t *Tick) Commit()

func (*Tick) Delete

func (t *Tick) Delete() (err error)

func (*Tick) Draw

func (t *Tick) Draw() error

func (*Tick) Find

func (t *Tick) Find(p []byte, back bool) int

func (*Tick) FindAlpha

func (t *Tick) FindAlpha(i int) (int, int)

func (*Tick) FindOrEOF

func (t *Tick) FindOrEOF(p []byte) int

func (*Tick) FindParity

func (t *Tick) FindParity() int

func (*Tick) FindQuote

func (t *Tick) FindQuote() int

func (*Tick) FindSpecial

func (t *Tick) FindSpecial(i int) (int, int)

func (*Tick) In

func (t *Tick) In(pt image.Point) bool

func (*Tick) Insert

func (t *Tick) Insert(p []byte) (err error)

func (*Tick) Next

func (t *Tick) Next()

func (*Tick) Open

func (t *Tick) Open(i int)

func (*Tick) Read

func (t *Tick) Read(p []byte) (n int, err error)

func (*Tick) ReadByte

func (t *Tick) ReadByte() byte

func (*Tick) Rects

func (t *Tick) Rects() (r []image.Rectangle)

func (*Tick) Resize

func (t *Tick) Resize(size image.Point)

func (*Tick) Seek

func (t *Tick) Seek(offset int64, whence int) (int64, error)

func (*Tick) Selected

func (t *Tick) Selected() bool

func (*Tick) Size

func (t *Tick) Size() int

func (*Tick) String

func (t *Tick) String() string

func (*Tick) Sweep

func (t *Tick) Sweep(i int)

func (*Tick) Write

func (t *Tick) Write(p []byte) (n int, err error)

func (*Tick) WriteRune

func (t *Tick) WriteRune(r rune) (err error)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL