Documentation ¶
Index ¶
- Constants
- Variables
- func AlphaAddColor(src, dst, alp uint8) byte
- func AlphaAndColor(src, dst uint8) byte
- func AlphaAndNotColor(src, dst uint8) byte
- func AlphaChoose(src, dst, alp, ab uint8) byte
- func AlphaMultiplyColor(src, dst uint8) byte
- func AlphaOrColor(src, dst uint8) byte
- func AlphaSubColor(src, dst uint8) byte
- func AlphaXorColor(src, dst uint8) byte
- func CopyDrawer(dd, ds Drawer, x, y, xs, ys, w, h int32)
- func CopyDrawerFlipBoth(dd, ds Drawer, x, y, xs, ys, w, h int32)
- func CopyDrawerFlipX(dd, ds Drawer, x, y, xs, ys, w, h int32)
- func CopyDrawerFlipY(dd, ds Drawer, x, y, xs, ys, w, h int32)
- func CopyDrawerMod(dd, ds Drawer, x, y, xs, ys, w, h int32, dm uint8)
- func DrawChar(dr Drawer, s string, x, y, sc int32, c color.RGBA, cs *CharacterSet) error
- func DrawCharFlip(dr Drawer, s string, x, y, sc int32, c color.RGBA, cs *CharacterSet) error
- func DrawLine(dr Drawer, x, y, x2, y2 int32, c color.RGBA)
- func DrawRectBorder(dr Drawer, x, y, w, h int32, c color.RGBA)
- func DrawRectFill(dr Drawer, x, y, w, h int32, c color.RGBA)
- func DrawString(dr Drawer, s string, x, y, sc int32, c color.RGBA, cs *CharacterSet) []error
- func DrawStringFlip(dr Drawer, s string, x, y, sc int32, c color.RGBA, cs *CharacterSet) []error
- func NewImageFromDrawer(dr Drawer) draw.Image
- func NewScreen(w, h, rw, rh int32, n string, fs, vs, lf bool) (*Screen, *Layer, error)
- func RandColor(s int) (c color.RGBA)
- type CharacterSet
- type ColorCount
- type Drawer
- type ImageWrap
- type Img
- type Layer
- func (l *Layer) Clear(c color.RGBA)
- func (l *Layer) DrawChar(s string, x, y, sc int32, c color.RGBA) error
- func (l *Layer) DrawCharFlip(s string, x, y, sc int32, c color.RGBA) error
- func (l *Layer) DrawCircleBorder(x, y int32, r float64, c color.RGBA)
- func (l *Layer) DrawCircleFill(x, y int32, r1, r2 float64, c color.RGBA)
- func (l *Layer) DrawLine(x, y, x2, y2 int32, c color.RGBA)
- func (l *Layer) DrawPoint(x, y int32, c color.RGBA)
- func (l *Layer) DrawRectBorder(x, y, w, h int32, c color.RGBA)
- func (l *Layer) DrawRectFill(x, y, w, h int32, c color.RGBA)
- func (l *Layer) DrawString(s string, x, y, sc int32, c color.RGBA) []error
- func (l *Layer) DrawStringFlip(s string, x, y, sc int32, c color.RGBA) []error
- func (l *Layer) FlipX()
- func (l *Layer) FlipY()
- func (l *Layer) GetHeight() int32
- func (l *Layer) GetMemory() []byte
- func (l *Layer) GetWidth() int32
- func (l *Layer) Offset(x, y float64)
- func (l *Layer) ReadPoint(x, y int32) (color.RGBA, error)
- func (l *Layer) Rotate(r float64, p *sdl.Point)
- func (l *Layer) Scale(sx, sy float64)
- type PImg
- func (pim *PImg) Clear(c color.RGBA)
- func (pim *PImg) DrawPoint(x, y int32, c color.RGBA)
- func (pim *PImg) DrawPointByIndex(x, y int32, ci uint64)
- func (pim *PImg) GetHeight() int32
- func (pim *PImg) GetMemory() []byte
- func (pim *PImg) GetWidth() int32
- func (pim *PImg) ReadPoint(x, y int32) (color.RGBA, error)
- type Palette
- func (p *Palette) Add(c color.RGBA)
- func (p *Palette) ChangeByColor(c, nc color.RGBA) error
- func (p *Palette) ChangeByIndex(i int, c color.RGBA) error
- func (p *Palette) Clamp(d uint8)
- func (p Palette) Convert(c color.RGBA) color.RGBA
- func (p *Palette) Delete(i int)
- func (p Palette) HasColor(c color.RGBA) (bool, int)
- func (p Palette) Index(c color.Color) int
- func (p *Palette) ShiftBack(i int)
- func (p *Palette) ShiftForward(i int)
- type Screen
Constants ¶
const ( //AlphaNone is no alpha blend for DrawPoint AlphaNone = iota //AlphaAdd is a basic add alpha for DrawPoint (transparency) AlphaAdd //AlphaMultiply converts both src and dst to 1.0f then multiplies by each AlphaMultiply //AlphaSub returns the highest value pixel minus the lowest value pixel AlphaSub //AlphaXor returns the xor of src and dst AlphaXor //AlphaAnd returns the and of src and dst AlphaAnd //AlphaOr returns the or of src and dst AlphaOr //AlphaAndNot returns the or of src and dst AlphaAndNot )
const ( //DrawModNone applies no transformation with CopyDrawerMod DrawModNone = iota //DrawModFlipY applies CopyDrawerMod with a Y flip DrawModFlipY //DrawModFlipX applies CopyDrawerMod with a X flip DrawModFlipX //DrawModFlipBoth applies CopyDrawerMod with both axis flipped DrawModFlipBoth )
const ( //Depth8Bit is one byte of colour data per pixel, offset by 1 so number of bytes matches bit depth Depth8Bit = iota + 1 //Depth16Bit is two bytes of colour data per pixel Depth16Bit //Depth24Bit is three bytes of colour data per pixel Depth24Bit //Depth32Bit is three bytes of colour data per pixel Depth32Bit )
Variables ¶
var ( //White color preset White color.RGBA //Silver color preset Silver color.RGBA //Gray color preset Gray color.RGBA //Black color preset Black color.RGBA //Red color preset Red color.RGBA //Maroon color preset Maroon color.RGBA //Orange color preset Orange color.RGBA //Yellow color preset Yellow color.RGBA //Olive color preset Olive color.RGBA //Lime color preset Lime color.RGBA //Green color preset Green color.RGBA //Aqua color preset Aqua color.RGBA //Teal color preset Teal color.RGBA //Blue color preset Blue color.RGBA Navy color.RGBA //Fuscia color preset Fuscia color.RGBA //Purple color preset Purple color.RGBA //NullCol color preset //Used for zero value returns NullCol color.RGBA )
Functions ¶
func AlphaAddColor ¶
AlphaAddColor blends dst and src using alp as a additive alpha blend
func AlphaAndColor ¶
AlphaAndColor returns the and of src and dst
func AlphaAndNotColor ¶
AlphaAndNotColor returns the AndNot of src and dst
func AlphaChoose ¶
AlphaChoose returns color based on current AlphaBlend setting
func AlphaMultiplyColor ¶
AlphaMultiplyColor converts src and dst to 1.f = 255 float then multiplies them by each other and returns a uint8 clamped value
func AlphaOrColor ¶
AlphaOrColor returns the or of src and dst
func AlphaSubColor ¶
AlphaSubColor returns the highest of src/dst minus the lowest in a subtractive blend
func AlphaXorColor ¶
AlphaXorColor returns the xor of src and dst
func CopyDrawer ¶
CopyDrawer copies ds at xs, ys, for w, h; to dd at x, y (for w, h)
func CopyDrawerFlipBoth ¶
CopyDrawerFlipBoth copies ds at xs, ys, for w, h; to dd at x + w, y + h (for x, y)
func CopyDrawerFlipX ¶
CopyDrawerFlipX copies ds at xs, ys, for w, h; to dd at x + w, y (for x, h)
func CopyDrawerFlipY ¶
CopyDrawerFlipY copies ds at xs, ys, for w, h; to dd at x, y + h (for w, y)
func CopyDrawerMod ¶
CopyDrawerMod copies ds at xs, ys, for w, h; to dd at x,y(for w,h) with dm
func DrawCharFlip ¶
DrawCharFlip renders charcater s at x, y scaled sc times in c color to dr using cs, upside down
func DrawLine ¶
DrawLine draws a line from x, y, to x2, y2 using c color Code derived from examples given here: https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
func DrawRectBorder ¶
DrawRectBorder makes a w wide and h high rectangle, 1 px borders only at x, y using c color
func DrawRectFill ¶
DrawRectFill makes a w wide and h high rectangle at x, y using c color
func DrawString ¶
DrawString renders string s at x, y scaled sc times with c color to dr, using cs CharacterSet
func DrawStringFlip ¶
DrawStringFlip renders string s to x,y with y scaled sc times with y 0 at bottom of screen
func NewImageFromDrawer ¶
NewImageFromDrawer creates a image interface from a drawer interface
func NewScreen ¶
NewScreen sets up package and returns a *Screen to manage the global state as well as a first *Layer to draw to. Currently only supports a ARGB8888 colour space w, h are the dimensions of the layer you draw to rw, rh are the real dimensions of the window/screen (will scale screen) n is name of Window fs is fullscreen, vs is vSync and lf is linear filtering for screen scaling When quiting, call QuitScreen to close off all SDL assets.
Types ¶
type CharacterSet ¶
type CharacterSet struct {
CharHeight, CharWidth int32
CharSpace,
CharExclaim,
CharDblQuote,
CharHash,
CharString,
CharPercent,
CharAmp,
CharApostrophe,
CharOpenBracketCurved,
CharCloseBracketCurved,
CharAsterisks,
CharPlus,
CharComma,
CharMinus,
CharPeriod,
CharForwardSlash,
Char0,
Char1,
Char2,
Char3,
Char4,
Char5,
Char6,
Char7,
Char8,
Char9,
CharColon,
CharSemiColon,
CharLessThan,
CharEqual,
CharGreaterThan,
CharQuestion,
CharAt,
CharA,
CharB,
CharC,
CharD,
CharE,
CharF,
CharG,
CharH,
CharI,
CharJ,
CharK,
CharL,
CharM,
CharN,
CharO,
CharP,
CharQ,
CharR,
CharS,
CharT,
CharU,
CharV,
CharW,
CharX,
CharY,
CharZ,
CharOpenBracketSquare,
CharBackSlash,
CharCloseBracketSquare,
CharCarrot,
CharUnderScore,
CharBackTick,
Chara,
Charb,
Charc,
Chard,
Chare,
Charf,
Charg,
Charh,
Chari,
Charj,
Chark,
Charl,
Charm,
Charn,
Charo,
Charp,
Charq,
Charr,
Chars,
Chart,
Charu,
Charv,
Charw,
Charx,
Chary,
Charz,
CharOpenCurleyBrace,
CharPipe,
CharCloseCurleyBrace,
CharTilde,
CharNoChar string
}
CharacterSet contains characters for drawing text
func (*CharacterSet) InitCharMap ¶
func (CS *CharacterSet) InitCharMap()
InitCharMap sets loads a CharacterSet up
type ColorCount ¶
type ColorCount struct {
// contains filtered or unexported fields
}
ColorCount holds a list of colors/quantities that can be sorted
func CountColors ¶
func CountColors(dr Drawer) ColorCount
CountColors returns a ColorCount of an image sorted by occurrence
func (ColorCount) Less ¶
func (cc ColorCount) Less(i, j int) bool
Less implemented to satisfy sort.Interface
func (ColorCount) Swap ¶
func (cc ColorCount) Swap(i, j int)
Swap implemented to satisfy sort.Interface
type Drawer ¶
type Drawer interface { //ReadPoint returns the colour value of location x, y in Drawer memory ReadPoint(x, y int32) (color.RGBA, error) //DrawPoint sets the colour value of location x, y in Drawer memory DrawPoint(x, y int32, c color.RGBA) //Clear sets all of Drawer to colour Clear(c color.RGBA) //GetWidth returns width of Drawer GetWidth() int32 //GetHeight returns Height of Drawer GetHeight() int32 //GetMemory returns the raw memory as a []byte (used in testing, returns []byte{0} for ImageWrap) GetMemory() []byte }
Drawer is the interface for go13h drawing functions.
type ImageWrap ¶
ImageWrap is used to satisfy the Drawer interface with a draw.Image interface
func WrapImage ¶
WrapImage returns a *ImageWrap for any image.Image that is capable of being cast to draw.Image
type Img ¶
type Img struct { Memory []byte //Raw Img data in BGRA layout W, H int32 //Img width and height A uint8 //Alpha mode for DrawPoint OD bool //Overdraw }
Img is raw image data with resolution and color context
func NewImgFromImage ¶
NewImgFromImage returns a *Img from any go image interface
type Layer ¶
type Layer struct { Memory []byte //Raw Layer data in BGRA layout W, H int32 //Layer resolution A uint8 //AlphaMode for DrawPoint Scr *Screen Hide bool OD bool //Over draw // contains filtered or unexported fields }
Layer contains a screen layer of info, a basic screen always has a 0 layer
func (*Layer) DrawChar ¶
DrawChar renders character s to x, y scaled sc times Replaced by DrawChar as a function that accepts a Drawer interface
func (*Layer) DrawCharFlip ¶
DrawCharFlip renders character s to x, y scaled sc times with y 0 at bottom of screen Replaced by DrawCharFlip as a function that accepts a Drawer interface
func (*Layer) DrawCircleBorder ¶
DrawCircleBorder makes circle of r radius at x, y using c color
func (*Layer) DrawCircleFill ¶
DrawCircleFill fills a circle from r1 to r2 at x, y using c color
func (*Layer) DrawLine ¶
DrawLine draws a line from x, y, to x2, y2 using c color Replaced by DrawLine as a function that accepts a Drawer interface
func (*Layer) DrawPoint ¶
DrawPoint sets a single point on the screen memory to current working color If l.OD is true pixels wrap once around NullCol will never draw
func (*Layer) DrawRectBorder ¶
DrawRectBorder makes a w wide and h high rectangle, borders ony2 at x, y using c color Replaced by DrawRectBorder as a function that accepts a Drawer interface
func (*Layer) DrawRectFill ¶
DrawRectFill makes a w wide and h high rectangle at x, y using c color Replaced by DrawRectFill as a function that accepts a Drawer interface
func (*Layer) DrawString ¶
DrawString renders string s to x, y scaled sc times Replaced by DrawString as a function that accepts a Drawer interface
func (*Layer) DrawStringFlip ¶
DrawStringFlip renders string s to x,y with y scaled sc times with y 0 at bottom of screen Replaced by DrawStringFlip as a function that accepts a Drawer interface
func (*Layer) FlipX ¶
func (l *Layer) FlipX()
FlipX flips layer x axis (0 is now right hand of screen)
type PImg ¶
type PImg struct { Memory []byte //Raw PImg data in a 8 bit or 16 paletted layout W, H int32 //Img width and height D uint8 //Palette mode P *Palette //PImg palette OD bool //Over draw }
PImg is raw paletted image data with resolution and color context PImg does not support Alpha draws to itself.
func NewPImgFromDrawer ¶
NewPImgFromDrawer returns an initialized PImg Derived from any Drawer clamped to d
func (*PImg) Clear ¶
Clear clears the Memory to color A bad Pim.D(epth) setting will result in a memory of []byte{0}
func (*PImg) DrawPoint ¶
DrawPoint sets a single point on the PImg memory to c color or closest c in pim.P A bad Pimg.D(epth) setting will result in no point being drawn If pim.OD is true pixels wrap once around NullCol will never draw
func (*PImg) DrawPointByIndex ¶
DrawPointByIndex sets a single point of the PImg memory to the ci colour index DrawPointByIndex guards against ci's that overflow the pim.D(epth), but will draw indexes outside of the pim.P(alette) If pim.OD is true pixels wrap once around
type Palette ¶
Palette is a slice of color.RGBA
func (*Palette) ChangeByColor ¶
ChangeByColor changes the first occurrence of c in a palette to nc, if c does not exist will return a error.
func (*Palette) ChangeByIndex ¶
ChangeByIndex changes the specified i to c, if i is too large or negative, will return an error
func (*Palette) Delete ¶
Delete replaces the color with NullCol unless it's the last color then the index is removed
func (Palette) Index ¶
Index returns the index of the palette color closest to c in Euclidean R,G,B,A space.
func (*Palette) ShiftForward ¶
ShiftForward moves palette ahead by i and wraps end to front
type Screen ¶
type Screen struct { Layers []*Layer //Slice of screen layers W, H int32 //Screen resolution CS *CharacterSet // contains filtered or unexported fields }
Screen manages the global state of go13h, and holds some useful info (ex character set) Screen also manages layer ordering and final rendering
func (*Screen) NewLayer ¶
NewLayer sets up and registers a new *Layer, note layers do not have to be the same width, height or texture filtering as other layers Layers can take up a lot of memory very easily, they take up their current working Memory, as well as the memory required for the backing texture ex: a 1920x1080 layer takes up 16Megabytes of RAM at minimum