Compare commits

...

12 Commits

7 changed files with 366 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ package tomo
import "sort"
import "image"
import "errors"
import "git.tebibyte.media/tomo/tomo/canvas"
// Backend is any Tomo implementation. Backends handle window creation, layout,
// rendering, and events so that there can be as many platform-specific
@@ -16,6 +17,10 @@ type Backend interface {
NewCanvasBox () CanvasBox
NewContainerBox () ContainerBox
// NewTexture creates a new texture from an image. The backend must
// reject any texture that was not made by it.
NewTexture (image.Image) canvas.Texture
// Run runs the event loop until Stop() is called, or the backend
// experiences a fatal error.
Run () error

View File

@@ -44,8 +44,9 @@ type Pen interface {
StrokeWeight (int) // how thick the stroke is
StrokeAlign (StrokeAlign) // where the stroke is drawn
Stroke (color.Color) // Sets the stroke to a solid color
Fill (color.Color) // Sets the fill to a solid color
Stroke (color.Color) // Sets the stroke to a solid color
Fill (color.Color) // Sets the fill to a solid color
Texture (Texture) // Overlaps a texture onto the fill color
}
// Canvas is an image that supports drawing paths.

29
canvas/texture.go Normal file
View File

@@ -0,0 +1,29 @@
package canvas
import "io"
import "image"
// Texture is a handle that points to a 2D raster image managed by the backend.
type Texture interface {
io.Closer
// Clip returns a smaller section of this texture, pointing to the same
// internal data. Becaue of this, closing a clipped section will close
// the original texture as well.
Clip (image.Rectangle) Texture
}
type protectedTexture struct {
Texture
}
func (protectedTexture) Close () error {
return nil
}
// Protect makes the Close() method of a texture do nothing. This is useful if
// several of the same texture are given out to different objects, but only one
// has the responsibility of closing it.
func Protect (texture Texture) Texture {
return protectedTexture { Texture: texture }
}

View File

@@ -104,7 +104,7 @@ type Align int; const (
// Object is any obscreen object. Each object must be linked to a box, even if
// it is that box.
type Object interface {
Box () Box
GetBox () Box
}
// Box is a basic styled box.
@@ -132,6 +132,10 @@ type Box interface {
SetBounds (image.Rectangle)
// SetColor sets the background color of this Box.
SetColor (color.Color)
// SetTexture sets a repeating background texture. If the texture is
// transparent, it will be overlayed atop the color specified by
// SetColor().
SetTexture (canvas.Texture)
// SetBorder sets the Border(s) of the box. The first Border will be the
// most outset, and the last Border will be the most inset.
SetBorder (...Border)

293
theme/icon.go Normal file
View File

@@ -0,0 +1,293 @@
package theme
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data"
// IconSize represents the size of an icon.
type IconSize int; const (
IconSizeSmall IconSize = iota;
IconSizeMedium
IconSizeLarge
)
// Icon represents an icon ID.
type Icon int; const (
// --- Objects --- //
// files
IconFile Icon = iota
IconDirectory
IconDirectoryFull
// places
IconDownloads
IconPhotos
IconBooks
IconDocuments
IconRepositories
IconMusic
IconArchives
IconFonts
IconBinaries
IconVideos
Icon3DObjects
IconHistory
IconPreferences
// storage
IconStorage // generic
IconMagneticTape
IconFloppyDisk
IconHardDisk
IconSolidStateDrive
IconFlashDrive
IconMemoryCard
IconROMDisk
IconRAMDisk
IconCD
IconDVD
// network
IconNetwork // generic
IconLocalNetwork
IconInternet
IconEthernet
IconWireless
IconCell
IconBluetooth
IconRadio
// devices
IconDevice // generic
IconRouter
IconServer
IconDesktop
IconLaptop
IconTablet
IconPhone
IconWatch
IconCamera
// peripherals
IconPeripheral // generic
IconKeyboard
IconMouse
IconMonitor
IconWebcam
IconMicrophone
IconSpeaker
IconPenTablet
IconTrackpad
IconController
// i/o
IconPort // generic
IconEthernetPort
IconUSBPort
IconParallelPort
IconSerialPort
IconPS2Port
IconDisplayConnector
IconCGAPort
IconVGAPort
IconHDMIPort
IconDisplayPort
IconInfrared
// --- Actions --- //
// files
IconOpen
IconOpenIn
IconSave
IconSaveAs
IconPrints
IconNew
IconNewDirectory
IconDelete
IconRename
IconGetInformation
IconChangePermissions
IconRevert
// list management
IconAdd
IconRemove
IconAddBookmark
IconRemoveBookmark
IconAddFavorite
IconRemoveFavorite
// media
IconPlay
IconPause
IconStop
IconFastForward
IconRewind
IconToBeginning
IconToEnd
IconRecord
IconVolumeUp
IconVolumeDown
IconMute
// editing
IconUndo
IconRedo
IconCut
IconCopy
IconPaste
IconFind
IconReplace
IconSelectAll
IconSelectNone
IconIncrement
IconDecrement
// window management
IconClose
IconQuit
IconIconify
IconShade
IconMaximize
IconFullScreen
IconRestore
// view controls
IconExpand
IconContract
IconBack
IconForward
IconUp
IconDown
IconReload
IconZoomIn
IconZoomOut
IconZoomReset
IconMove
IconResize
IconGoTo
// tools
IconTransform
IconTranslate
IconRotate
IconScale
IconWarp
IconCornerPin
IconSelectRectangle
IconSelectEllipse
IconSelectLasso
IconSelectGeometric
IconSelectAuto
IconCrop
IconFill
IconGradient
IconPencil
IconBrush
IconEraser
IconText
IconEyedropper
// --- Status --- //
// dialogs
IconInformation
IconQuestion
IconWarning
IconError
IconCancel
IconOkay
// network
IconCellSignal0
IconCellSignal1
IconCellSignal2
IconCellSignal3
IconWirelessSignal0
IconWirelessSignal1
IconWirelessSignal2
IconWirelessSignal3
// power
IconBattery0
IconBattery1
IconBattery2
IconBattery3
IconBrightness0
IconBrightness1
IconBrightness2
IconBrightness3
// media
IconVolume0
IconVolume1
IconVolume2
IconVolume3
)
// Texture returns a texture of the corresponding icon ID.
func (id Icon) Texture (size IconSize) tomo.Texture {
if current == nil { return nil }
return current.Icon(id, size)
}
// MimeIcon returns an icon corresponding to a MIME type.
func MimeIcon (mime data.Mime, size IconSize) tomo.Texture {
if current == nil { return nil }
return current.MimeIcon(mime, size)
}
// ApplicationIcon describes the icon of the application.
type ApplicationIcon struct {
// The name or ID of the application. If applicable, this should
// correspond to the file name (without the path or extension) of the
// icon on the system. This field is optional.
Name string
// Role describes what the application does. If a specific icon file
// cannot be found, a generic one is picked using this field.
Role ApplicationRole
}
// Texture returns a texture of the corresponding icon ID.
func (icon ApplicationIcon) Texture (size IconSize) tomo.Texture {
if current == nil { return nil }
return current.ApplicationIcon(icon, size)
}
// ApplicationRole describes what an application does.
type ApplicationRole int; const (
RoleUnknown ApplicationRole = iota
RoleWebBrowser
RoleMesssanger
RolePhone
RoleMail
RoleTerminalEmulator
RoleFileBrowser
RoleTextEditor
RoleDocumentViewer
RoleWordProcessor
RoleSpreadsheet
RoleSlideshow
RoleCalculator
RolePreferences
RoleProcessManager
RoleSystemInformation
RoleManual
RoleCamera
RoleImageViewer
RoleMediaPlayer
RoleImageEditor
RoleAudioEditor
RoleVideoEditor
RoleClock
RoleCalendar
RoleChecklist
)

View File

@@ -1,6 +1,7 @@
package theme
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data"
import "git.tebibyte.media/tomo/tomo/event"
// Role describes the role of an object.
@@ -16,11 +17,16 @@ type Role struct {
// - Dial
// This should correspond directly to the type name of the object.
Object string
// Variant is an optional field to be used when an object has one or
// more soft variants under one type. For example, an object "Slider"
// may have variations "horizontal" and "vertical".
Variant string
}
// R is shorthand for creating a Role structure.
func R (pack, object string) Role {
return Role { Package: pack, Object: object }
func R (pack, object, variant string) Role {
return Role { Package: pack, Object: object, Variant: variant }
}
// Color represents a color ID.
@@ -47,6 +53,21 @@ type Theme interface {
// RGBA returns the RGBA values of the corresponding color ID.
RGBA (Color) (r, g, b, a uint32)
// Icon returns a texture of the corresponding icon ID. This texture
// should be protected, unless a new copy of it is returned with each
// subsequent call.
Icon (Icon, IconSize) tomo.Texture
// MimeIcon returns an icon corresponding to a MIME type. This texture
// should be protected, unless a new copy of it is returned with each
// subsequent call.
MimeIcon (data.Mime, IconSize) tomo.Texture
// ApplicationIcon returns an icon corresponding to an application. This
// texture should be protected, unless a new copy of it is returned with
// each subsequent call.
ApplicationIcon (ApplicationIcon, IconSize) tomo.Texture
}
var current Theme

View File

@@ -3,6 +3,7 @@ package tomo
import "sync"
import "image"
import "errors"
import "git.tebibyte.media/tomo/tomo/canvas"
var backendLock sync.Mutex
var backend Backend
@@ -79,3 +80,10 @@ func NewContainerBox () ContainerBox {
assertBackend()
return backend.NewContainerBox()
}
// NewTexture creates a new texture from an image. When no longer in use, it
// must be freed using Close().
func NewTexture (source image.Image) canvas.Texture {
assertBackend()
return backend.NewTexture(source)
}