Platforms to show: All Mac Windows Linux Cross-Platform

CGGradientMBS.CreateWithColorComponents(colorSpace as CGColorSpaceMBS, components() as Double) as CGGradientMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
shared method CoreGraphics MBS MacCG Plugin 11.2 Yes No No Yes, macOS only No
Function: Creates a CGGradient object from a color space and the provided color components and locations.
Notes:
space: The color space to use for the gradient. You cannot use a pattern or indexed color space.
components: The color components for each color that defines the gradient. The components should be in the color space specified by space. If you are unsure of the number of components, you can call the function CGColorSpaceMBS.NumberOfComponents.

The number of items in this array should be the product of count and the number of components in the color space. For example, if the color space is an RGBA color space and you want to use two colors in the gradient (one for a starting location and another for an ending location), then you need to provide 8 values in components—red, green, blue, and alpha values for the first color, followed by red, green, blue, and alpha values for the second color.

locations: Optional, The location for each color provided in components. Each location must be a CGFloat value in the range of 0 to 1, inclusive. If 0 and 1 are not in the locations array, Quartz uses the colors provided that are closest to 0 and 1 for those locations.

If locations is not passed, the first color in colors is assigned to location 0, the last color incolors is assigned to location 1, and intervening colors are assigned locations that are at equal intervals in between.

Available in Mac OS X v10.5 and later.

See also:

Feedback, Comments & Corrections

CGGradientMBS.CreateWithColorComponents(colorSpace as CGColorSpaceMBS, components() as Double, locations() as Double) as CGGradientMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
shared method CoreGraphics MBS MacCG Plugin 11.2 Yes No No Yes, macOS only No
Function: Creates a CGGradient object from a color space and the provided color components and locations.
Example:
// put into paint event of window
dim c as CGContextMBS
if TargetCocoa then
c = GetCurrentCGContextMBS
else
c = window1.CGContextMBS
end if

dim locations() as Double = array(0.0, 0.6, 1.0)
dim components() as Double = array(1.0, 0.0, 0.0, 0.35, 0.0, 1.0, 0.0, 0.2, 0.0, 0.0, 1.0, 0.06) // Start color and End color

dim rgbColorspace as CGColorSpaceMBS = CGColorSpaceMBS.CreateDeviceRGB
dim glossGradient as CGGradientMBS = CGGradientMBS.CreateWithColorComponents(rgbColorspace, components, locations)
'dim glossGradient as CGGradientMBS = CGGradientMBS.CreateWithColorComponents(rgbColorspace, components)

dim currentBounds as CGRectMBS = CGMakeRectMBS(0,0,g.Width,g.Height)

dim topCenter as CGPointMBS = CGMakePointMBS(g.width/2, 0.0)
dim midCenter as CGPointMBS = CGMakePointMBS(g.width/2, g.height)

c.SaveGState

// fill white
c.SetRGBFillColor 1.0, 1.0, 1.0, 1.0
c.FillRect currentBounds


// draw gradient
c.AddRect(currentBounds)
c.Clip
c.DrawLinearGradient(glossGradient, topCenter, midCenter, 0)
c.RestoreGState
c.Flush
Notes:
space: The color space to use for the gradient. You cannot use a pattern or indexed color space.
components: The color components for each color that defines the gradient. The components should be in the color space specified by space. If you are unsure of the number of components, you can call the function CGColorSpaceMBS.NumberOfComponents.

The number of items in this array should be the product of count and the number of components in the color space. For example, if the color space is an RGBA color space and you want to use two colors in the gradient (one for a starting location and another for an ending location), then you need to provide 8 values in components—red, green, blue, and alpha values for the first color, followed by red, green, blue, and alpha values for the second color.

locations: Optional, The location for each color provided in components. Each location must be a CGFloat value in the range of 0 to 1, inclusive. If 0 and 1 are not in the locations array, Quartz uses the colors provided that are closest to 0 and 1 for those locations.

If locations is not passed, the first color in colors is assigned to location 0, the last color incolors is assigned to location 1, and intervening colors are assigned locations that are at equal intervals in between.

Available in Mac OS X v10.5 and later.

See also:

Feedback, Comments & Corrections

CGGradientMBS.CreateWithColors(colorSpace as CGColorSpaceMBS, colors() as CGColorMBS) as CGGradientMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
shared method CoreGraphics MBS MacCG Plugin 11.2 Yes No No Yes, macOS only No
Function: Creates a CGGradient object from a color space and the provided color objects and locations.
Example:
// put into window paint event
dim c as CGContextMBS
if TargetCocoa then
c = GetCurrentCGContextMBS
else
c = window1.CGContextMBS
end if

dim colors(-1) as CGColorMBS

colors.Append CGColorMBS.CreateGenericRGB(1.0, 0.0, 0.0, 0.35)
colors.Append CGColorMBS.CreateGenericRGB(0.0, 1.0, 0.0, 0.2)
colors.Append CGColorMBS.CreateGenericRGB(0.0, 0.0, 1.0, 0.06)

dim glossGradient as CGGradientMBS = CGGradientMBS.CreateWithColors(nil, colors)

dim topCenter as CGPointMBS = CGMakePointMBS(g.width/2, 0.0)
dim midCenter as CGPointMBS = CGMakePointMBS(g.width/2, g.height)

// fill white
c.SetRGBFillColor 1.0, 1.0, 1.0, 1.0
c.FillRect CGMakeRectMBS(0,0,g.Width,g.Height)

// gradient
dim currentBounds as CGRectMBS = CGMakeRectMBS(0,0,g.Width,g.Height)
c.SaveGState
c.AddRect(currentBounds)
c.Clip
c.DrawLinearGradient(glossGradient, topCenter, midCenter, 0)
c.RestoreGState

c.Flush
Notes:
space: The color space to use for the gradient. You cannot use a pattern or indexed color space. Can be nil.
colors: A non-empty array of CGColorMBS objects that should be in the color space specified by space. If space is not nil, each color will be converted (if necessary) to that color space and the gradient will drawn in that color space. Otherwise, each color will be converted to and drawn in the GenericRGB color space.
locations: Optional. The location for each color provided in colors; each location must be a CGFloat value in the range of 0 to 1, inclusive. If 0 and 1 are not in the locations array, Quartz uses the colors provided that are closest to 0 and 1 for those locations.

If locations is missing, the first color in colors is assigned to location 0, the last color incolors is assigned to location 1, and intervening colors are assigned locations that are at equal intervals in between.
The locations array should contain the same number of items as the colors array.

Available in Mac OS X v10.5 and later.

See also:

Feedback, Comments & Corrections

CGGradientMBS.CreateWithColors(colorSpace as CGColorSpaceMBS, colors() as CGColorMBS, locations() as Double) as CGGradientMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
shared method CoreGraphics MBS MacCG Plugin 11.2 Yes No No Yes, macOS only No
Function: Creates a CGGradient object from a color space and the provided color objects and locations.
Example:
// put into window paint event
dim c as CGContextMBS
if TargetCocoa then
c = GetCurrentCGContextMBS
else
c = window1.CGContextMBS
end if

dim locations() as Double = array(0.0, 0.8, 1.0)

dim colors(-1) as CGColorMBS

colors.Append CGColorMBS.CreateGenericRGB(1.0, 0.0, 0.0, 0.35)
colors.Append CGColorMBS.CreateGenericRGB(0.0, 1.0, 0.0, 0.2)
colors.Append CGColorMBS.CreateGenericRGB(0.0, 0.0, 1.0, 0.06)

dim glossGradient as CGGradientMBS = CGGradientMBS.CreateWithColors(nil, colors, locations)

dim topCenter as CGPointMBS = CGMakePointMBS(g.width/2, 0.0)
dim midCenter as CGPointMBS = CGMakePointMBS(g.width/2, g.height)

// fill white
c.SetRGBFillColor 1.0, 1.0, 1.0, 1.0
c.FillRect CGMakeRectMBS(0,0,g.Width,g.Height)

// gradient
dim currentBounds as CGRectMBS = CGMakeRectMBS(0,0,g.Width,g.Height)
c.SaveGState
c.AddRect(currentBounds)
c.Clip
c.DrawLinearGradient(glossGradient, topCenter, midCenter, 0)
c.RestoreGState

c.Flush
Notes:
space: The color space to use for the gradient. You cannot use a pattern or indexed color space. Can be nil.
colors: A non-empty array of CGColorMBS objects that should be in the color space specified by space. If space is not nil, each color will be converted (if necessary) to that color space and the gradient will drawn in that color space. Otherwise, each color will be converted to and drawn in the GenericRGB color space.
locations: Optional. The location for each color provided in colors; each location must be a CGFloat value in the range of 0 to 1, inclusive. If 0 and 1 are not in the locations array, Quartz uses the colors provided that are closest to 0 and 1 for those locations.

If locations is missing, the first color in colors is assigned to location 0, the last color incolors is assigned to location 1, and intervening colors are assigned locations that are at equal intervals in between.
The locations array should contain the same number of items as the colors array.

Available in Mac OS X v10.5 and later.

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCG Plugin.

The biggest plugin in space...




Links
MBS Xojo blog