Created simple bordered pattern

This commit is contained in:
Sasha Koshka 2023-01-20 19:24:21 -05:00
parent befec471db
commit a71e726016
6 changed files with 53 additions and 20 deletions

24
artist/bordered.go Normal file
View File

@ -0,0 +1,24 @@
package artist
import "image"
import "image/color"
// Bordered is a pattern with a border and a fill.
type Bordered struct {
Fill Pattern
Stroke
}
// AtWhen satisfies the Pattern interface.
func (pattern Bordered) AtWhen (x, y, width, height int) (c color.RGBA) {
outerBounds := image.Rectangle { Max: image.Point { width, height }}
innerBounds := outerBounds.Inset(pattern.Weight)
if (image.Point { x, y }).In (innerBounds) {
return pattern.Fill.AtWhen (
x - pattern.Weight,
y - pattern.Weight,
innerBounds.Dx(), innerBounds.Dy())
} else {
return pattern.Stroke.AtWhen(x, y, width, height)
}
}

View File

@ -16,28 +16,28 @@ type borderInternal struct {
dx, dy int dx, dy int
} }
// MultiBorder is a pattern that allows multiple borders of different lengths to // MultiBordered is a pattern that allows multiple borders of different lengths
// be inset within one another. The final border is treated as a fill color, and // to be inset within one another. The final border is treated as a fill color,
// its weight does not matter. // and its weight does not matter.
type MultiBorder struct { type MultiBordered struct {
borders []borderInternal borders []borderInternal
lastWidth, lastHeight int lastWidth, lastHeight int
maxBorder int maxBorder int
} }
// NewMultiBorder creates a new MultiBorder pattern from the given list of // NewMultiBordered creates a new MultiBordered pattern from the given list of
// borders. // borders.
func NewMultiBorder (borders ...Stroke) (multi *MultiBorder) { func NewMultiBordered (borders ...Stroke) (multi *MultiBordered) {
internalBorders := make([]borderInternal, len(borders)) internalBorders := make([]borderInternal, len(borders))
for index, border := range borders { for index, border := range borders {
internalBorders[index].weight = border.Weight internalBorders[index].weight = border.Weight
internalBorders[index].stroke = border.Pattern internalBorders[index].stroke = border.Pattern
} }
return &MultiBorder { borders: internalBorders } return &MultiBordered { borders: internalBorders }
} }
// AtWhen satisfies the Pattern interface. // AtWhen satisfies the Pattern interface.
func (multi *MultiBorder) AtWhen (x, y, width, height int) (c color.RGBA) { func (multi *MultiBordered) AtWhen (x, y, width, height int) (c color.RGBA) {
if multi.lastWidth != width || multi.lastHeight != height { if multi.lastWidth != width || multi.lastHeight != height {
multi.recalculate(width, height) multi.recalculate(width, height)
} }
@ -54,7 +54,7 @@ func (multi *MultiBorder) AtWhen (x, y, width, height int) (c color.RGBA) {
return return
} }
func (multi *MultiBorder) recalculate (width, height int) { func (multi *MultiBordered) recalculate (width, height int) {
bounds := image.Rect (0, 0, width, height) bounds := image.Rect (0, 0, width, height)
multi.maxBorder = 0 multi.maxBorder = 0
for index, border := range multi.borders { for index, border := range multi.borders {

View File

@ -45,7 +45,7 @@ func (element *Artist) Resize (width, height int) {
// 2, 0 // 2, 0
artist.FillRectangle ( artist.FillRectangle (
element, element,
artist.NewMultiBorder ( artist.NewMultiBordered (
artist.Stroke { Pattern: uhex(0xFF0000FF), Weight: 1 }, artist.Stroke { Pattern: uhex(0xFF0000FF), Weight: 1 },
artist.Stroke { Pattern: uhex(0x888800FF), Weight: 2 }, artist.Stroke { Pattern: uhex(0x888800FF), Weight: 2 },
artist.Stroke { Pattern: uhex(0x00FF00FF), Weight: 3 }, artist.Stroke { Pattern: uhex(0x00FF00FF), Weight: 3 },
@ -54,6 +54,15 @@ func (element *Artist) Resize (width, height int) {
), ),
element.cellAt(2, 0)) element.cellAt(2, 0))
// 3, 0
artist.FillRectangle (
element,
artist.Bordered {
Stroke: artist.Stroke { Pattern: uhex(0x0000FFFF), Weight: 5 },
Fill: uhex(0xFF0000FF),
},
element.cellAt(3, 0))
// 0, 1 - 0, 3 // 0, 1 - 0, 3
for x := 0; x < 4; x ++ { for x := 0; x < 4; x ++ {
artist.FillRectangle ( artist.FillRectangle (

View File

@ -2,7 +2,7 @@ package theme
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
var buttonPattern = artist.NewMultiBorder ( var buttonPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern }, artist.Stroke { Weight: 1, Pattern: strokePattern },
artist.Stroke { artist.Stroke {
Weight: 1, Weight: 1,
@ -12,7 +12,7 @@ var buttonPattern = artist.NewMultiBorder (
}, },
}, },
artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) }) artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) })
var selectedButtonPattern = artist.NewMultiBorder ( var selectedButtonPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern }, artist.Stroke { Weight: 1, Pattern: strokePattern },
artist.Stroke { artist.Stroke {
Weight: 1, Weight: 1,
@ -23,7 +23,7 @@ var selectedButtonPattern = artist.NewMultiBorder (
}, },
artist.Stroke { Weight: 1, Pattern: accentPattern }, artist.Stroke { Weight: 1, Pattern: accentPattern },
artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) }) artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) })
var pressedButtonPattern = artist.NewMultiBorder ( var pressedButtonPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern }, artist.Stroke { Weight: 1, Pattern: strokePattern },
artist.Stroke { artist.Stroke {
Weight: 1, Weight: 1,
@ -33,7 +33,7 @@ var pressedButtonPattern = artist.NewMultiBorder (
}, },
}, },
artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) }) artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) })
var pressedSelectedButtonPattern = artist.NewMultiBorder ( var pressedSelectedButtonPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern }, artist.Stroke { Weight: 1, Pattern: strokePattern },
artist.Stroke { artist.Stroke {
Weight: 1, Weight: 1,
@ -43,7 +43,7 @@ var pressedSelectedButtonPattern = artist.NewMultiBorder (
}, },
}, },
artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) }) artist.Stroke { Pattern: artist.NewUniform(hex(0x8D9894FF)) })
var disabledButtonPattern = artist.NewMultiBorder ( var disabledButtonPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: weakForegroundPattern }, artist.Stroke { Weight: 1, Pattern: weakForegroundPattern },
artist.Stroke { Pattern: backgroundPattern }) artist.Stroke { Pattern: backgroundPattern })

View File

@ -2,7 +2,7 @@ package theme
import "git.tebibyte.media/sashakoshka/tomo/artist" import "git.tebibyte.media/sashakoshka/tomo/artist"
var inputPattern = artist.NewMultiBorder ( var inputPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern }, artist.Stroke { Weight: 1, Pattern: strokePattern },
artist.Stroke { artist.Stroke {
Weight: 1, Weight: 1,
@ -12,11 +12,11 @@ var inputPattern = artist.NewMultiBorder (
}, },
}, },
artist.Stroke { Pattern: artist.NewUniform(hex(0xD2CB9AFF)) }) artist.Stroke { Pattern: artist.NewUniform(hex(0xD2CB9AFF)) })
var selectedInputPattern = artist.NewMultiBorder ( var selectedInputPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern }, artist.Stroke { Weight: 1, Pattern: strokePattern },
artist.Stroke { Weight: 1, Pattern: accentPattern }, artist.Stroke { Weight: 1, Pattern: accentPattern },
artist.Stroke { Pattern: artist.NewUniform(hex(0xD2CB9AFF)) }) artist.Stroke { Pattern: artist.NewUniform(hex(0xD2CB9AFF)) })
var disabledInputPattern = artist.NewMultiBorder ( var disabledInputPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: weakForegroundPattern }, artist.Stroke { Weight: 1, Pattern: weakForegroundPattern },
artist.Stroke { Pattern: backgroundPattern }) artist.Stroke { Pattern: backgroundPattern })

View File

@ -23,7 +23,7 @@ var foregroundPattern = artist.NewUniform(color.Gray16 { 0x0000 })
var weakForegroundPattern = artist.NewUniform(color.Gray16 { 0x4444 }) 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.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern }, artist.Stroke { Weight: 1, Pattern: strokePattern },
artist.Stroke { artist.Stroke {
Weight: 1, Weight: 1,
@ -34,7 +34,7 @@ var sunkenPattern = artist.NewMultiBorder (
}, },
artist.Stroke { Pattern: artist.NewUniform(hex(0x97a09cFF)) }) artist.Stroke { Pattern: artist.NewUniform(hex(0x97a09cFF)) })
var deadPattern = artist.NewMultiBorder ( var deadPattern = artist.NewMultiBordered (
artist.Stroke { Weight: 1, Pattern: strokePattern }, artist.Stroke { Weight: 1, Pattern: strokePattern },
artist.Stroke { Pattern: artist.NewUniform(hex(0x97a09cFF)) }) artist.Stroke { Pattern: artist.NewUniform(hex(0x97a09cFF)) })