API Documentation
Documentation for developing SailfishOS applicationsBackground QML Type
A position independent background item. More...
Import Statement: | import Sailfish.Silica.Background 1.0 |
Inherits: | |
Inherited By: | ColorBackground, KeyboardBackground, and ThemeBackground |
Properties
- fillMode : enum
- material : Material
- patternItem : Item
- radius : real
- roundedCorners : flags
- sourceItem : Item
- transformItem : Item
Detailed Description
Note: This QML type is under development and is subject to change.
The Background type provides a view to a fullscreen background item and tiled pattern item using a custom shader material. Unlike most items which draw their contents relative to the position and size of the item Background draws its content relative to the screen so if the item moves or is resized its contents do not move with it but are instead cropped to fit the item and if there are multiple Background items with the same source they will different windows to the same overall background.
The contents of a background are defined by a material, an optional sourceItem and patternItem, and additional QML object properties which can be read by the material GLSL shaders.
The material defines the GLSL shaders which are used to render the background item. A basic Material will render the sourceItem centered and scaled to fill the screen with the patternItem tiled above it. Materials may be shared between multiple Background items and doing so will allow resources to be shared between items.
See also Material.
Property Documentation
How the background source item should be scaled to fill the screen. The value may be one of:
Background.Strech
The source item will not be scaled.Background.PreserveAspectWidth
The source item will be scaled so its width matches the width of the screen. This may result in no background being rendered in parts of the screen and should only be used in portrait orientations with source images with the same aspect ratio or taller than the screen.Background.PreserveAspectSquare
The smallest dimension of the sourceItem will be scaled to fit the height of the screen so that the screen is filled in both orientations.
The default value is Background.PreserveAspectSquare
material : Material |
A Material containing the GLSL shaders which will be used to render the background item.
A background must have a valid material set or it will not render anything.
An item which can be tiled by the background material.
The pattern item must be a texture provider item, this can be an Image, a ShaderEffectSource, a FilteredImage, or any other item with layer.enabled: true
.
If a material GLSL vertex shader defines a uniform highp mat4 patternMatrix
that matrix will be populated with a transform which when multiplied with the screen coordinates will give the texture sampling coordinates to tile the pattern item at 1:1 scale.
To sample the patternItem in a material GLSL fragment shader add the uniform lowp sampler2D patternTexture
.
A basic material for a background which includes only a tiled patternItem would look like:
Material { vertexShader: " attribute highp vec4 position; uniform highp mat4 positionMatrix; uniform highp mat4 patternMatrix; varying highp vec2 patternCoord;" void backgroundMain() { gl_Position = positionMatrix * position; patternCoord = (patternMatrix * gl_Position).xy; } " fragmentShader: " uniform lowp sampler2D patternTexture; varying highp vec2 patternCoord; void backgroundMain() { gl_FragColor = texture2D(patternTexture, patternCoord); } " }
The radius of any rounded corners on the backround item.
By default the radius is 0.
See also roundedCorners.
Which corners of the Background item should be rounded. This can be any combination of the following flags:
Corners.None
No corners are rounded.Corners.TopLeft
The top left corner should be rounded.Corners.TopRight
The top right corner should be rounded.Corners.BottomLeft
The bottom left corner should be rounded.Corners.BottomRight
The bottom right corner should be rounded.Corners.All
All the corners should be rounded.
The default value is Corners.All
, note however that since the default radius is 0 no corners will be rounded by default.
An item which can be displayed fullscreen by the background material.
The source item must be a texture provider item, this can be an Image, a ShaderEffectSource, a FilteredImage, or any other item with layer.enabled: true
.
If a material GLSL vertex shader defines a uniform highp mat4 sourceMatrix
that matrix will be populated with a transform which when multiplied with the screen coordinates will give the texture sampling coordinates to center the item in the screen and scale it according to the fillMode.
To sample the sourceItem in a material GLSL fragment shader add the uniform lowp sampler2D sourceTexture
.
A basic material for a background which includes only a fullscreen sourceItem would look like:
Material { vertexShader: " attribute highp vec4 position; uniform highp mat4 positionMatrix; uniform highp mat4 sourceMatrix; varying highp vec2 sourceCoord;" void backgroundMain() { gl_Position = positionMatrix * position; sourceCoord = (sourceMatrix * gl_Position).xy; } " fragmentShader: " uniform lowp sampler2D sourceTexture; varying highp vec2 sourceCoord; void backgroundMain() { gl_FragColor = texture2D(sourceTexture, sourceCoord); } " }
An item which can be used to apply a rotation transform to a background.
A background item ignores the transforms applied to it directly when rendering, so just like moving an item won't effect the content it draws at any point on the screen rotating and scaling also have no effect. Instead a background can be rotated by having it follow the transforms applied to a reference transformItem.
When a transformItem is rotated the sourceMatrix
uniform of the material vertex shader will have the same transform applied so that the sourceItem is rotated to match that item and any other backgrounds with the transformItem. If the vertex shader defines the uniform highp mat4 transformMatrix
that will be populated with a transform that follows the transform item indepedently of any additional sourceItem transforms.