Compare commits

..

8 Commits

8 changed files with 390 additions and 95 deletions

113
application.go Normal file
View File

@@ -0,0 +1,113 @@
package tomo
import "image"
// Application represents an application object.
type Application interface {
// Describe returns a description of the application.
Describe () ApplicationDescription
// Init performs the initial setup of the application.
Init ()
}
// ApplicationDescription describes the name and type of an application.
type ApplicationDescription struct {
// The name or ID of the application.
Name string
// Role describes what the application does.
Role ApplicationRole
}
// String satisfies the fmt.Stringer interface.
func (application ApplicationDescription) String () string {
if application.Name == "" {
return application.Role.String()
} else {
return application.Name
}
}
// 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
)
// String satisfies the fmt.Stringer interface.
func (role ApplicationRole) String () string {
switch role {
case RoleWebBrowser: return "Web Browser"
case RoleMesssanger: return "Messsanger"
case RolePhone: return "Phone"
case RoleMail: return "Mail"
case RoleTerminalEmulator: return "Terminal Emulator"
case RoleFileBrowser: return "File Browser"
case RoleTextEditor: return "Text Editor"
case RoleDocumentViewer: return "Document Viewer"
case RoleWordProcessor: return "Word Processor"
case RoleSpreadsheet: return "Spreadsheet"
case RoleSlideshow: return "Slideshow"
case RoleCalculator: return "Calculator"
case RolePreferences: return "Preferences"
case RoleProcessManager: return "Process Manager"
case RoleSystemInformation: return "System Information"
case RoleManual: return "Manual"
case RoleCamera: return "Camera"
case RoleImageViewer: return "Image Viewer"
case RoleMediaPlayer: return "Media Player"
case RoleImageEditor: return "Image Editor"
case RoleAudioEditor: return "Audio Editor"
case RoleVideoEditor: return "Video Editor"
case RoleClock: return "Clock"
case RoleCalendar: return "Calendar"
case RoleChecklist: return "Checklist"
default: return "unknown"
}
}
// RunApplication is like Run, but runs an application.
func RunApplication (application Application) error {
return Run(application.Init)
}
// NewApplicationWindow creates a window for an application. It will
// automatically set window information to signal to the OS that the window is
// owned by the application.
func NewApplicationWindow (application Application, bounds image.Rectangle) (Window, error) {
window, err := NewWindow(bounds)
if err != nil { return nil, err }
window.SetTitle(application.Describe().String())
return window, nil
}

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
@@ -18,7 +19,7 @@ type Backend interface {
// NewTexture creates a new texture from an image. The backend must
// reject any texture that was not made by it.
NewTexture (image.Image) Texture
NewTexture (image.Image) canvas.Texture
// Run runs the event loop until Stop() is called, or the backend
// experiences a fatal 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.

View File

@@ -1,4 +1,4 @@
package tomo
package canvas
import "io"
import "image"
@@ -11,6 +11,9 @@ type Texture interface {
// internal data. Becaue of this, closing a clipped section will close
// the original texture as well.
Clip (image.Rectangle) Texture
// Bounds returns the size of this texture.
Bounds () image.Rectangle
}
type protectedTexture struct {

View File

@@ -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)

View File

@@ -2,6 +2,7 @@ package theme
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data"
import "git.tebibyte.media/tomo/tomo/canvas"
// IconSize represents the size of an icon.
type IconSize int; const (
@@ -10,6 +11,18 @@ type IconSize int; const (
IconSizeLarge
)
// String satisfies the fmt.Stringer interface.
func (size IconSize) String () string {
switch size {
case IconSizeSmall: return "small"
case IconSizeMedium: return "medium"
case IconSizeLarge: return "large"
default: return "unknown"
}
}
// TODO: the Icon type, along with its String method, needs to be codegen'd.
// Icon represents an icon ID.
type Icon int; const (
// --- Objects --- //
@@ -18,7 +31,7 @@ type Icon int; const (
IconFile Icon = iota
IconDirectory
IconDirectoryFull
// places
IconDownloads
IconPhotos
@@ -33,7 +46,7 @@ type Icon int; const (
Icon3DObjects
IconHistory
IconPreferences
// storage
IconStorage // generic
IconMagneticTape
@@ -46,7 +59,7 @@ type Icon int; const (
IconRAMDisk
IconCD
IconDVD
// network
IconNetwork // generic
IconLocalNetwork
@@ -56,7 +69,7 @@ type Icon int; const (
IconCell
IconBluetooth
IconRadio
// devices
IconDevice // generic
IconRouter
@@ -67,7 +80,7 @@ type Icon int; const (
IconPhone
IconWatch
IconCamera
// peripherals
IconPeripheral // generic
IconKeyboard
@@ -79,7 +92,7 @@ type Icon int; const (
IconPenTablet
IconTrackpad
IconController
// i/o
IconPort // generic
IconEthernetPort
@@ -93,15 +106,15 @@ type Icon int; const (
IconHDMIPort
IconDisplayPort
IconInfrared
// --- Actions --- //
// files
IconOpen
IconOpenIn
IconSave
IconSaveAs
IconPrints
IconPrint
IconNew
IconNewDirectory
IconDelete
@@ -109,7 +122,7 @@ type Icon int; const (
IconGetInformation
IconChangePermissions
IconRevert
// list management
IconAdd
IconRemove
@@ -117,7 +130,7 @@ type Icon int; const (
IconRemoveBookmark
IconAddFavorite
IconRemoveFavorite
// media
IconPlay
IconPause
@@ -130,7 +143,7 @@ type Icon int; const (
IconVolumeUp
IconVolumeDown
IconMute
// editing
IconUndo
IconRedo
@@ -143,8 +156,8 @@ type Icon int; const (
IconSelectNone
IconIncrement
IconDecrement
// window management
// window management
IconClose
IconQuit
IconIconify
@@ -167,7 +180,7 @@ type Icon int; const (
IconMove
IconResize
IconGoTo
// tools
IconTransform
IconTranslate
@@ -188,9 +201,9 @@ type Icon int; const (
IconEraser
IconText
IconEyedropper
// --- Status --- //
// dialogs
IconInformation
IconQuestion
@@ -198,7 +211,7 @@ type Icon int; const (
IconError
IconCancel
IconOkay
// network
IconCellSignal0
IconCellSignal1
@@ -208,7 +221,7 @@ type Icon int; const (
IconWirelessSignal1
IconWirelessSignal2
IconWirelessSignal3
// power
IconBattery0
IconBattery1
@@ -218,7 +231,7 @@ type Icon int; const (
IconBrightness1
IconBrightness2
IconBrightness3
// media
IconVolume0
IconVolume1
@@ -226,68 +239,202 @@ type Icon int; const (
IconVolume3
)
// String satisfies the fmt.Stringer interface.
func (id Icon) String () string {
switch id {
case IconFile: return "File"
case IconDirectory: return "Directory"
case IconDirectoryFull: return "DirectoryFull"
case IconDownloads: return "Downloads"
case IconPhotos: return "Photos"
case IconBooks: return "Books"
case IconDocuments: return "Documents"
case IconRepositories: return "Repositories"
case IconMusic: return "Music"
case IconArchives: return "Archives"
case IconFonts: return "Fonts"
case IconBinaries: return "Binaries"
case IconVideos: return "Videos"
case Icon3DObjects: return "3DObjects"
case IconHistory: return "History"
case IconPreferences: return "Preferences"
case IconStorage: return "Storage"
case IconMagneticTape: return "MagneticTape"
case IconFloppyDisk: return "FloppyDisk"
case IconHardDisk: return "HardDisk"
case IconSolidStateDrive: return "SolidStateDrive"
case IconFlashDrive: return "FlashDrive"
case IconMemoryCard: return "MemoryCard"
case IconROMDisk: return "ROMDisk"
case IconRAMDisk: return "RAMDisk"
case IconCD: return "CD"
case IconDVD: return "DVD"
case IconNetwork: return "Network"
case IconLocalNetwork: return "LocalNetwork"
case IconInternet: return "Internet"
case IconEthernet: return "Ethernet"
case IconWireless: return "Wireless"
case IconCell: return "Cell"
case IconBluetooth: return "Bluetooth"
case IconRadio: return "Radio"
case IconDevice: return "Device"
case IconRouter: return "Router"
case IconServer: return "Server"
case IconDesktop: return "Desktop"
case IconLaptop: return "Laptop"
case IconTablet: return "Tablet"
case IconPhone: return "Phone"
case IconWatch: return "Watch"
case IconCamera: return "Camera"
case IconPeripheral: return "Peripheral"
case IconKeyboard: return "Keyboard"
case IconMouse: return "Mouse"
case IconMonitor: return "Monitor"
case IconWebcam: return "Webcam"
case IconMicrophone: return "Microphone"
case IconSpeaker: return "Speaker"
case IconPenTablet: return "PenTablet"
case IconTrackpad: return "Trackpad"
case IconController: return "Controller"
case IconPort: return "Port"
case IconEthernetPort: return "EthernetPort"
case IconUSBPort: return "USBPort"
case IconParallelPort: return "ParallelPort"
case IconSerialPort: return "SerialPort"
case IconPS2Port: return "PS2Port"
case IconDisplayConnector: return "DisplayConnector"
case IconCGAPort: return "CGAPort"
case IconVGAPort: return "VGAPort"
case IconHDMIPort: return "HDMIPort"
case IconDisplayPort: return "DisplayPort"
case IconInfrared: return "Infrared"
case IconOpen: return "Open"
case IconOpenIn: return "OpenIn"
case IconSave: return "Save"
case IconSaveAs: return "SaveAs"
case IconPrint: return "Print"
case IconNew: return "New"
case IconNewDirectory: return "NewDirectory"
case IconDelete: return "Delete"
case IconRename: return "Rename"
case IconGetInformation: return "GetInformation"
case IconChangePermissions: return "ChangePermissions"
case IconRevert: return "Revert"
case IconAdd: return "Add"
case IconRemove: return "Remove"
case IconAddBookmark: return "AddBookmark"
case IconRemoveBookmark: return "RemoveBookmark"
case IconAddFavorite: return "AddFavorite"
case IconRemoveFavorite: return "RemoveFavorite"
case IconPlay: return "Play"
case IconPause: return "Pause"
case IconStop: return "Stop"
case IconFastForward: return "FastForward"
case IconRewind: return "Rewind"
case IconToBeginning: return "ToBeginning"
case IconToEnd: return "ToEnd"
case IconRecord: return "Record"
case IconVolumeUp: return "VolumeUp"
case IconVolumeDown: return "VolumeDown"
case IconMute: return "Mute"
case IconUndo: return "Undo"
case IconRedo: return "Redo"
case IconCut: return "Cut"
case IconCopy: return "Copy"
case IconPaste: return "Paste"
case IconFind: return "Find"
case IconReplace: return "Replace"
case IconSelectAll: return "SelectAll"
case IconSelectNone: return "SelectNone"
case IconIncrement: return "Increment"
case IconDecrement: return "Decrement"
case IconClose: return "Close"
case IconQuit: return "Quit"
case IconIconify: return "Iconify"
case IconShade: return "Shade"
case IconMaximize: return "Maximize"
case IconFullScreen: return "FullScreen"
case IconRestore: return "Restore"
case IconExpand: return "Expand"
case IconContract: return "Contract"
case IconBack: return "Back"
case IconForward: return "Forward"
case IconUp: return "Up"
case IconDown: return "Down"
case IconReload: return "Reload"
case IconZoomIn: return "ZoomIn"
case IconZoomOut: return "ZoomOut"
case IconZoomReset: return "ZoomReset"
case IconMove: return "Move"
case IconResize: return "Resize"
case IconGoTo: return "GoTo"
case IconTransform: return "Transform"
case IconTranslate: return "Translate"
case IconRotate: return "Rotate"
case IconScale: return "Scale"
case IconWarp: return "Warp"
case IconCornerPin: return "CornerPin"
case IconSelectRectangle: return "SelectRectangle"
case IconSelectEllipse: return "SelectEllipse"
case IconSelectLasso: return "SelectLasso"
case IconSelectGeometric: return "SelectGeometric"
case IconSelectAuto: return "SelectAuto"
case IconCrop: return "Crop"
case IconFill: return "Fill"
case IconGradient: return "Gradient"
case IconPencil: return "Pencil"
case IconBrush: return "Brush"
case IconEraser: return "Eraser"
case IconText: return "Text"
case IconEyedropper: return "Eyedropper"
case IconInformation: return "Information"
case IconQuestion: return "Question"
case IconWarning: return "Warning"
case IconError: return "Error"
case IconCancel: return "Cancel"
case IconOkay: return "Okay"
case IconCellSignal0: return "CellSignal0"
case IconCellSignal1: return "CellSignal1"
case IconCellSignal2: return "CellSignal2"
case IconCellSignal3: return "CellSignal3"
case IconWirelessSignal0: return "WirelessSignal0"
case IconWirelessSignal1: return "WirelessSignal1"
case IconWirelessSignal2: return "WirelessSignal2"
case IconWirelessSignal3: return "WirelessSignal3"
case IconBattery0: return "Battery0"
case IconBattery1: return "Battery1"
case IconBattery2: return "Battery2"
case IconBattery3: return "Battery3"
case IconBrightness0: return "Brightness0"
case IconBrightness1: return "Brightness1"
case IconBrightness2: return "Brightness2"
case IconBrightness3: return "Brightness3"
case IconVolume0: return "Volume0"
case IconVolume1: return "Volume1"
case IconVolume2: return "Volume2"
case IconVolume3: return "Volume3"
default: return "Unknown"
}
}
// Texture returns a texture of the corresponding icon ID.
func (id Icon) Texture (size IconSize) tomo.Texture {
func (id Icon) Texture (size IconSize) canvas.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 {
func MimeIcon (mime data.Mime, size IconSize) canvas.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
}
type ApplicationIcon tomo.ApplicationDescription
// Texture returns a texture of the corresponding icon ID.
func (icon ApplicationIcon) Texture (size IconSize) tomo.Texture {
func (icon ApplicationIcon) Texture (size IconSize) canvas.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,15 +1,17 @@
package theme
import "fmt"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data"
import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/tomo/tomo/canvas"
// Role describes the role of an object.
type Role struct {
// Package is an optional namespace field. If specified, it should be
// the package name or module name the object is from.
Package string
// Object specifies what type of object it is. For example:
// - TextInput
// - Table
@@ -17,17 +19,24 @@ 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
}
// String satisfies the fmt.Stringer interface.
// It follows the format of:
// Package.Object[Variant]
func (r Role) String () string {
return fmt.Sprintf("%s.%s[%s]", r.Package, r.Object, r.Variant)
}
// R is shorthand for creating a Role structure.
func R (pack, object, variant string) Role {
return Role { Package: pack, Object: object, Variant: variant }
}
}
// Color represents a color ID.
type Color int; const (
@@ -38,6 +47,18 @@ type Color int; const (
ColorAccent
)
// String satisfies the fmt.Stringer interface.
func (c Color) String () string {
switch c {
case ColorBackground: return "background"
case ColorForeground: return "foreground"
case ColorRaised: return "raised"
case ColorSunken: return "sunken"
case ColorAccent: return "accent"
default: return "unknown"
}
}
// RGBA satisfies the color.Color interface.
func (id Color) RGBA () (r, g, b, a uint32) {
if current == nil { return }
@@ -46,28 +67,33 @@ func (id Color) RGBA () (r, g, b, a uint32) {
// Theme is an object that can apply a visual style to different objects.
type Theme interface {
// A word on textures:
//
// Because textures can be linked to some resource that is outside of
// the control of Go's garbage collector, methods of Theme must not
// allocate new copies of a texture each time they are called. It is
// fine to lazily load textures and save them for later use, but the
// same texture must never be allocated multiple times as this could
// cause a memory leak.
//
// As such, textures returned by these methods must be protected.
// Apply applies the theme to the given object, according to the given
// role. This may register event listeners with the given object;
// closing the returned cookie will remove them.
// closing the returned cookie must remove them.
Apply (tomo.Object, Role) event.Cookie
// 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
// Icon returns a texture of the corresponding icon ID.
Icon (Icon, IconSize) canvas.Texture
// MimeIcon returns an icon corresponding to a MIME type.
MimeIcon (data.Mime, IconSize) canvas.Texture
// ApplicationIcon returns an icon corresponding to an application.
ApplicationIcon (ApplicationIcon, IconSize) canvas.Texture
}
var current Theme
@@ -84,4 +110,3 @@ func Apply (object tomo.Object, role Role) event.Cookie {
if current == nil { return event.NoCookie { } }
return current.Apply(object, role)
}

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
@@ -82,7 +83,7 @@ func NewContainerBox () ContainerBox {
// NewTexture creates a new texture from an image. When no longer in use, it
// must be freed using Close().
func NewTexture (source image.Image) Texture {
func NewTexture (source image.Image) canvas.Texture {
assertBackend()
return backend.NewTexture(source)
}