Replaced artist.Border with artist.Stroke
This commit is contained in:
		
							parent
							
								
									8c0956b998
								
							
						
					
					
						commit
						befec471db
					
				@ -3,10 +3,15 @@ package artist
 | 
			
		||||
import "image"
 | 
			
		||||
import "image/color"
 | 
			
		||||
 | 
			
		||||
// Border represents a border that can be fed to MultiBorder.
 | 
			
		||||
type Border struct {
 | 
			
		||||
// Stroke represents a stoke that has a weight and a pattern.
 | 
			
		||||
type Stroke struct {
 | 
			
		||||
	Weight int
 | 
			
		||||
	Stroke Pattern
 | 
			
		||||
	Pattern
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type borderInternal struct {
 | 
			
		||||
	weight int
 | 
			
		||||
	stroke Pattern
 | 
			
		||||
	bounds image.Rectangle
 | 
			
		||||
	dx, dy int
 | 
			
		||||
}
 | 
			
		||||
@ -15,15 +20,20 @@ type Border struct {
 | 
			
		||||
// be inset within one another. The final border is treated as a fill color, and
 | 
			
		||||
// its weight does not matter.
 | 
			
		||||
type MultiBorder struct {
 | 
			
		||||
	borders []Border
 | 
			
		||||
	borders []borderInternal
 | 
			
		||||
	lastWidth, lastHeight int
 | 
			
		||||
	maxBorder int
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewMultiBorder creates a new MultiBorder pattern from the given list of
 | 
			
		||||
// borders.
 | 
			
		||||
func NewMultiBorder (borders ...Border) (multi *MultiBorder) {
 | 
			
		||||
	return &MultiBorder { borders: borders }
 | 
			
		||||
func NewMultiBorder (borders ...Stroke) (multi *MultiBorder) {
 | 
			
		||||
	internalBorders := make([]borderInternal, len(borders))
 | 
			
		||||
	for index, border := range borders {
 | 
			
		||||
		internalBorders[index].weight = border.Weight
 | 
			
		||||
		internalBorders[index].stroke = border.Pattern
 | 
			
		||||
	}
 | 
			
		||||
	return &MultiBorder { borders: internalBorders }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AtWhen satisfies the Pattern interface.
 | 
			
		||||
@ -35,7 +45,7 @@ func (multi *MultiBorder) AtWhen (x, y, width, height int) (c color.RGBA) {
 | 
			
		||||
	for index := multi.maxBorder; index >= 0; index -- {
 | 
			
		||||
		border := multi.borders[index]
 | 
			
		||||
		if point.In(border.bounds) {
 | 
			
		||||
			return border.Stroke.AtWhen (
 | 
			
		||||
			return border.stroke.AtWhen (
 | 
			
		||||
				point.X - border.bounds.Min.X,
 | 
			
		||||
				point.Y - border.bounds.Min.Y,
 | 
			
		||||
				border.dx, border.dy)
 | 
			
		||||
@ -52,7 +62,7 @@ func (multi *MultiBorder) recalculate (width, height int) {
 | 
			
		||||
		multi.borders[index].bounds = bounds
 | 
			
		||||
		multi.borders[index].dx = bounds.Dx()
 | 
			
		||||
		multi.borders[index].dy = bounds.Dy()
 | 
			
		||||
		bounds = bounds.Inset(border.Weight)
 | 
			
		||||
		bounds = bounds.Inset(border.weight)
 | 
			
		||||
		if bounds.Empty() { break }
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -14,8 +14,8 @@ const (
 | 
			
		||||
 | 
			
		||||
// Striped is a pattern that produces stripes of two alternating colors.
 | 
			
		||||
type Striped struct {
 | 
			
		||||
	First     Border
 | 
			
		||||
	Second    Border
 | 
			
		||||
	First     Stroke
 | 
			
		||||
	Second    Stroke
 | 
			
		||||
	Direction StripeDirection
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -40,8 +40,8 @@ func (pattern Striped) AtWhen (x, y, width, height int) (c color.RGBA) {
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if position < pattern.First.Weight {
 | 
			
		||||
		return pattern.First.Stroke.AtWhen(x, y, width, height)
 | 
			
		||||
		return pattern.First.Pattern.AtWhen(x, y, width, height)
 | 
			
		||||
	} else {
 | 
			
		||||
		return pattern.Second.Stroke.AtWhen(x, y, width, height)
 | 
			
		||||
		return pattern.Second.Pattern.AtWhen(x, y, width, height)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -46,11 +46,11 @@ func (element *Artist) Resize (width, height int) {
 | 
			
		||||
	artist.FillRectangle (
 | 
			
		||||
		element,
 | 
			
		||||
		artist.NewMultiBorder (
 | 
			
		||||
			artist.Border { Stroke: uhex(0xFF0000FF), Weight: 1 },
 | 
			
		||||
			artist.Border { Stroke: uhex(0x888800FF), Weight: 2 },
 | 
			
		||||
			artist.Border { Stroke: uhex(0x00FF00FF), Weight: 3 },
 | 
			
		||||
			artist.Border { Stroke: uhex(0x008888FF), Weight: 4 },
 | 
			
		||||
			artist.Border { Stroke: uhex(0x0000FFFF), Weight: 5 },
 | 
			
		||||
			artist.Stroke { Pattern: uhex(0xFF0000FF), Weight: 1 },
 | 
			
		||||
			artist.Stroke { Pattern: uhex(0x888800FF), Weight: 2 },
 | 
			
		||||
			artist.Stroke { Pattern: uhex(0x00FF00FF), Weight: 3 },
 | 
			
		||||
			artist.Stroke { Pattern: uhex(0x008888FF), Weight: 4 },
 | 
			
		||||
			artist.Stroke { Pattern: uhex(0x0000FFFF), Weight: 5 },
 | 
			
		||||
			),
 | 
			
		||||
		element.cellAt(2, 0))
 | 
			
		||||
 | 
			
		||||
@ -59,8 +59,8 @@ func (element *Artist) Resize (width, height int) {
 | 
			
		||||
		artist.FillRectangle (
 | 
			
		||||
			element,
 | 
			
		||||
			artist.Striped {
 | 
			
		||||
				First:  artist.Border { Stroke: uhex(0xFF8800FF), Weight: 7 },
 | 
			
		||||
				Second: artist.Border { Stroke: uhex(0x0088FFFF), Weight: 2 },
 | 
			
		||||
				First:  artist.Stroke { Pattern: uhex(0xFF8800FF), Weight: 7 },
 | 
			
		||||
				Second: artist.Stroke { Pattern: uhex(0x0088FFFF), Weight: 2 },
 | 
			
		||||
				Direction: artist.StripeDirection(x),
 | 
			
		||||
				
 | 
			
		||||
			},
 | 
			
		||||
 | 
			
		||||
@ -3,49 +3,49 @@ package theme
 | 
			
		||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
 | 
			
		||||
 | 
			
		||||
var buttonPattern = artist.NewMultiBorder (
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: strokePattern },
 | 
			
		||||
	artist.Border {
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: strokePattern },
 | 
			
		||||
	artist.Stroke {
 | 
			
		||||
		Weight: 1,
 | 
			
		||||
		Stroke: artist.Chiseled {
 | 
			
		||||
		Pattern: artist.Chiseled {
 | 
			
		||||
			Highlight: artist.NewUniform(hex(0xCCD5D2FF)),
 | 
			
		||||
			Shadow:    artist.NewUniform(hex(0x4B5B59FF)),
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	artist.Border { Stroke: artist.NewUniform(hex(0x8D9894FF)) })
 | 
			
		||||
	artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) })
 | 
			
		||||
var selectedButtonPattern = artist.NewMultiBorder (
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: strokePattern },
 | 
			
		||||
	artist.Border {
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: strokePattern },
 | 
			
		||||
	artist.Stroke {
 | 
			
		||||
		Weight: 1,
 | 
			
		||||
		Stroke: artist.Chiseled {
 | 
			
		||||
		Pattern: artist.Chiseled {
 | 
			
		||||
			Highlight: artist.NewUniform(hex(0xCCD5D2FF)),
 | 
			
		||||
			Shadow:    artist.NewUniform(hex(0x4B5B59FF)),
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: accentPattern },
 | 
			
		||||
	artist.Border { Stroke: artist.NewUniform(hex(0x8D9894FF)) })
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: accentPattern },
 | 
			
		||||
	artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) })
 | 
			
		||||
var pressedButtonPattern = artist.NewMultiBorder (
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: strokePattern },
 | 
			
		||||
	artist.Border {
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: strokePattern },
 | 
			
		||||
	artist.Stroke {
 | 
			
		||||
		Weight: 1,
 | 
			
		||||
		Stroke: artist.Chiseled {
 | 
			
		||||
		Pattern: artist.Chiseled {
 | 
			
		||||
			Highlight: artist.NewUniform(hex(0x4B5B59FF)),
 | 
			
		||||
			Shadow:    artist.NewUniform(hex(0x8D9894FF)),
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	artist.Border { Stroke: artist.NewUniform(hex(0x8D9894FF)) })
 | 
			
		||||
	artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) })
 | 
			
		||||
var pressedSelectedButtonPattern = artist.NewMultiBorder (
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: strokePattern },
 | 
			
		||||
	artist.Border {
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: strokePattern },
 | 
			
		||||
	artist.Stroke {
 | 
			
		||||
		Weight: 1,
 | 
			
		||||
		Stroke: artist.Chiseled {
 | 
			
		||||
		Pattern: artist.Chiseled {
 | 
			
		||||
			Highlight: artist.NewUniform(hex(0x4B5B59FF)),
 | 
			
		||||
			Shadow:    artist.NewUniform(hex(0x8D9894FF)),
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	artist.Border { Stroke: artist.NewUniform(hex(0x8D9894FF)) })
 | 
			
		||||
	artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) })
 | 
			
		||||
var disabledButtonPattern = artist.NewMultiBorder (
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: weakForegroundPattern },
 | 
			
		||||
	artist.Border { Stroke: backgroundPattern })
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: weakForegroundPattern },
 | 
			
		||||
	artist.Stroke { Pattern: backgroundPattern })
 | 
			
		||||
 | 
			
		||||
func ButtonPattern (enabled, selected, pressed bool) (artist.Pattern) {
 | 
			
		||||
	if enabled {
 | 
			
		||||
 | 
			
		||||
@ -3,22 +3,22 @@ package theme
 | 
			
		||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
 | 
			
		||||
 | 
			
		||||
var inputPattern = artist.NewMultiBorder (
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: strokePattern },
 | 
			
		||||
	artist.Border {
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: strokePattern },
 | 
			
		||||
	artist.Stroke {
 | 
			
		||||
		Weight: 1,
 | 
			
		||||
		Stroke: artist.Chiseled {
 | 
			
		||||
		Pattern: artist.Chiseled {
 | 
			
		||||
			Highlight: artist.NewUniform(hex(0x89925AFF)),
 | 
			
		||||
			Shadow:    artist.NewUniform(hex(0xD2CB9AFF)),
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	artist.Border { Stroke: artist.NewUniform(hex(0xD2CB9AFF)) })
 | 
			
		||||
	artist.Stroke { Pattern: artist.NewUniform(hex(0xD2CB9AFF)) })
 | 
			
		||||
var selectedInputPattern = artist.NewMultiBorder (
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: strokePattern },
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: accentPattern },
 | 
			
		||||
	artist.Border { Stroke: artist.NewUniform(hex(0xD2CB9AFF)) })
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: strokePattern },
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: accentPattern },
 | 
			
		||||
	artist.Stroke { Pattern: artist.NewUniform(hex(0xD2CB9AFF)) })
 | 
			
		||||
var disabledInputPattern = artist.NewMultiBorder (
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: weakForegroundPattern },
 | 
			
		||||
	artist.Border { Stroke: backgroundPattern })
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: weakForegroundPattern },
 | 
			
		||||
	artist.Stroke { Pattern: backgroundPattern })
 | 
			
		||||
 | 
			
		||||
func InputPattern (enabled, selected bool) (artist.Pattern) {
 | 
			
		||||
	if enabled {
 | 
			
		||||
 | 
			
		||||
@ -24,19 +24,19 @@ var weakForegroundPattern = artist.NewUniform(color.Gray16 { 0x4444 })
 | 
			
		||||
var strokePattern         = artist.NewUniform(color.Gray16 { 0x0000 })
 | 
			
		||||
 | 
			
		||||
var sunkenPattern = artist.NewMultiBorder (
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: strokePattern },
 | 
			
		||||
	artist.Border {
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: strokePattern },
 | 
			
		||||
	artist.Stroke {
 | 
			
		||||
		Weight: 1,
 | 
			
		||||
		Stroke: artist.Chiseled {
 | 
			
		||||
		Pattern: artist.Chiseled {
 | 
			
		||||
			Highlight: artist.NewUniform(hex(0x3b534eFF)),
 | 
			
		||||
			Shadow:    artist.NewUniform(hex(0x97a09cFF)),
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	artist.Border { Stroke: artist.NewUniform(hex(0x97a09cFF)) })
 | 
			
		||||
	artist.Stroke { Pattern: artist.NewUniform(hex(0x97a09cFF)) })
 | 
			
		||||
 | 
			
		||||
var deadPattern = artist.NewMultiBorder (
 | 
			
		||||
	artist.Border { Weight: 1, Stroke: strokePattern },
 | 
			
		||||
	artist.Border { Stroke: artist.NewUniform(hex(0x97a09cFF)) })
 | 
			
		||||
	artist.Stroke { Weight: 1, Pattern: strokePattern },
 | 
			
		||||
	artist.Stroke { Pattern: artist.NewUniform(hex(0x97a09cFF)) })
 | 
			
		||||
 | 
			
		||||
func AccentPattern () (artist.Pattern) { return accentPattern }
 | 
			
		||||
func BackgroundPattern () (artist.Pattern) { return backgroundPattern }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user