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