nasin/internal/theme/default/icon.go

229 lines
5.5 KiB
Go

package defaultTheme
import "bytes"
import "image"
import _ "embed"
import _ "image/png"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/canvas"
//go:embed assets/icons-small.png
var atlasSmallBytes []byte
//go:embed assets/icons-large.png
var atlasLargeBytes []byte
func generateSource (data []byte, width int) map[theme.Icon] canvas.Texture {
atlasImage, _, err := image.Decode(bytes.NewReader(data))
if err != nil { panic(err) }
atlasTexture := tomo.NewTexture(atlasImage)
source := make(map[theme.Icon] canvas.Texture)
x := 0
y := 0
row := func () {
x = 0
y ++
}
col := func (id theme.Icon) {
source[id] = atlasTexture.Clip(image.Rect (
x * width,
y * width,
(x + 1) * width,
(y + 1) * width))
x++
}
// objects
col(theme.IconUnknown)
col(theme.IconFile)
col(theme.IconDirectory)
col(theme.IconStorage)
col(theme.IconApplication)
col(theme.IconNetwork)
col(theme.IconDevice)
col(theme.IconPeripheral)
col(theme.IconPort)
// actions: files
row()
col(theme.IconActionOpen)
col(theme.IconActionOpenIn)
col(theme.IconActionSave)
col(theme.IconActionSaveAs)
col(theme.IconActionPrint)
col(theme.IconActionNew)
col(theme.IconActionNewDirectory)
col(theme.IconActionDelete)
col(theme.IconActionRename)
col(theme.IconActionGetInformation)
col(theme.IconActionChangePermissions)
col(theme.IconActionRevert)
// actions: list management
row()
col(theme.IconActionAdd)
col(theme.IconActionRemove)
col(theme.IconActionAddBookmark)
col(theme.IconActionRemoveBookmark)
col(theme.IconActionAddFavorite)
col(theme.IconActionRemoveFavorite)
// actions: media
row()
col(theme.IconActionPlay)
col(theme.IconActionPause)
col(theme.IconActionStop)
col(theme.IconActionFastForward)
col(theme.IconActionRewind)
col(theme.IconActionToBeginning)
col(theme.IconActionToEnd)
col(theme.IconActionRecord)
col(theme.IconActionVolumeUp)
col(theme.IconActionVolumeDown)
col(theme.IconActionMute)
// actions: editing
row()
col(theme.IconActionUndo)
col(theme.IconActionRedo)
col(theme.IconActionCut)
col(theme.IconActionCopy)
col(theme.IconActionPaste)
col(theme.IconActionFind)
col(theme.IconActionReplace)
col(theme.IconActionSelectAll)
col(theme.IconActionSelectNone)
col(theme.IconActionIncrement)
col(theme.IconActionDecrement)
// actions: window management
row()
col(theme.IconActionClose)
col(theme.IconActionQuit)
col(theme.IconActionIconify)
col(theme.IconActionShade)
col(theme.IconActionMaximize)
col(theme.IconActionFullScreen)
col(theme.IconActionRestore)
// actions: view
row()
col(theme.IconActionExpand)
col(theme.IconActionContract)
col(theme.IconActionBack)
col(theme.IconActionForward)
col(theme.IconActionUp)
col(theme.IconActionDown)
col(theme.IconActionReload)
col(theme.IconActionZoomIn)
col(theme.IconActionZoomOut)
col(theme.IconActionZoomReset)
col(theme.IconActionMove)
col(theme.IconActionResize)
col(theme.IconActionGoTo)
// actions: tools
row()
col(theme.IconActionTransform)
col(theme.IconActionTranslate)
col(theme.IconActionRotate)
col(theme.IconActionScale)
col(theme.IconActionWarp)
col(theme.IconActionCornerPin)
col(theme.IconActionSelectRectangle)
col(theme.IconActionSelectEllipse)
col(theme.IconActionSelectLasso)
col(theme.IconActionSelectGeometric)
col(theme.IconActionSelectAuto)
col(theme.IconActionCrop)
col(theme.IconActionFill)
row()
col(theme.IconActionGradient)
col(theme.IconActionPencil)
col(theme.IconActionBrush)
col(theme.IconActionEraser)
col(theme.IconActionText)
col(theme.IconActionEyedropper)
// status: dialog
row()
col(theme.IconStatusInformation)
col(theme.IconStatusQuestion)
col(theme.IconStatusWarning)
col(theme.IconStatusError)
col(theme.IconStatusCancel)
col(theme.IconStatusOkay)
// status: network
row()
col(theme.IconStatusCellSignal0)
col(theme.IconStatusCellSignal1)
col(theme.IconStatusCellSignal2)
col(theme.IconStatusCellSignal3)
col(theme.IconStatusWirelessSignal0)
col(theme.IconStatusWirelessSignal1)
col(theme.IconStatusWirelessSignal2)
col(theme.IconStatusWirelessSignal3)
// status: power
row()
col(theme.IconStatusBattery0)
col(theme.IconStatusBattery1)
col(theme.IconStatusBattery2)
col(theme.IconStatusBattery3)
col(theme.IconStatusBrightness0)
col(theme.IconStatusBrightness1)
col(theme.IconStatusBrightness2)
col(theme.IconStatusBrightness3)
// status: media
row()
col(theme.IconStatusVolume0)
col(theme.IconStatusVolume1)
col(theme.IconStatusVolume2)
col(theme.IconStatusVolume3)
return source
}
type iconTheme struct {
texturesSmall map[theme.Icon] canvas.Texture
texturesLarge map[theme.Icon] canvas.Texture
}
func (this *iconTheme) ensure () {
if this.texturesSmall != nil { return }
this.texturesSmall = generateSource(atlasSmallBytes, 16)
this.texturesLarge = generateSource(atlasLargeBytes, 32)
}
func (this *iconTheme) selectSource (size theme.IconSize) map[theme.Icon] canvas.Texture {
if size == theme.IconSizeSmall {
return this.texturesSmall
} else {
return this.texturesLarge
}
}
func (this *iconTheme) Icon (icon theme.Icon, size theme.IconSize) canvas.Texture {
this.ensure()
source := this.selectSource(size)
if texture, ok := source[icon]; ok {
return texture
}
return source[theme.IconUnknown]
}
func (this *iconTheme) MimeIcon (mime data.Mime, size theme.IconSize) canvas.Texture {
this.ensure()
source := this.selectSource(size)
if mime == data.M("inode", "directory") {
return source[theme.IconDirectory]
} else {
return source[theme.IconFile]
}
}