Example: /MacCG/CGGradient test

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/CGGradient test


Required plugins for this example: MBS MacCG Plugin, MBS MacCF Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/CGGradient test

This example is the version from Sun, 17th Mar 2012.

Project "CGGradient test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() window1.show window2.show window3.show window4.show window2.Left = window1.Left + window1.Width + 30 window3.Left = window1.Left window4.Left = window1.Left + window1.Width + 30 window2.top = window1.top window3.Top = window1.Top + window1.Height + 50 window4.Top = window1.Top + window1.Height + 50 End EventHandler
End Class
Class Window1 Inherits Window
EventHandler Sub Paint(g As Graphics) dim c as CGContextMBS if TargetCocoa then c = GetCurrentCGContextMBS else c = self.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 End EventHandler
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class Window2 Inherits Window
EventHandler Sub Paint(g As Graphics) dim c as CGContextMBS if TargetCocoa then c = GetCurrentCGContextMBS else c = self.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 glossGradient1 as CGGradientMBS = CGGradientMBS.CreateWithColors(nil, colors, locations) dim glossGradient2 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) // left side gradient dim currentBounds1 as CGRectMBS = CGMakeRectMBS(0,0,g.Width/2.0,g.Height) c.SaveGState c.AddRect(currentBounds1) c.Clip c.DrawLinearGradient(glossGradient1, topCenter, midCenter, 0) c.RestoreGState // right side gradient with equal distances between colors dim currentBounds2 as CGRectMBS = CGMakeRectMBS(g.Width/2.0,0,g.Width/2.0,g.Height) c.SaveGState c.AddRect(currentBounds2) c.Clip c.DrawLinearGradient(glossGradient2, topCenter, midCenter, 0) c.RestoreGState c.Flush End EventHandler
End Class
Class Window3 Inherits Window
EventHandler Sub Paint(g As Graphics) dim c as CGContextMBS if TargetCocoa then c = GetCurrentCGContextMBS else c = self.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.DrawRadialGradient(glossGradient, topCenter, 30, midCenter, 100, 0) c.RestoreGState c.Flush End EventHandler
End Class
Class Window4 Inherits Window
EventHandler Sub Paint(g As Graphics) dim c as CGContextMBS if TargetCocoa then c = GetCurrentCGContextMBS else c = self.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 glossGradient1 as CGGradientMBS = CGGradientMBS.CreateWithColors(nil, colors, locations) dim glossGradient2 as CGGradientMBS = CGGradientMBS.CreateWithColors(nil, colors) dim topCenter1 as CGPointMBS = CGMakePointMBS(g.width/4, 0.0) dim midCenter1 as CGPointMBS = CGMakePointMBS(g.width/4, g.height) dim topCenter2 as CGPointMBS = CGMakePointMBS(g.width/4*3, 0.0) dim midCenter2 as CGPointMBS = CGMakePointMBS(g.width/4*3, g.height) // fill white c.SetRGBFillColor 1.0, 1.0, 1.0, 1.0 c.FillRect CGMakeRectMBS(0,0,g.Width,g.Height) // left side gradient dim currentBounds1 as CGRectMBS = CGMakeRectMBS(0,0,g.Width/2.0,g.Height) c.SaveGState c.AddRect(currentBounds1) c.Clip c.DrawRadialGradient(glossGradient1, topCenter1, 30, midCenter1, 100, 0) c.RestoreGState // right side gradient with equal distances between colors dim currentBounds2 as CGRectMBS = CGMakeRectMBS(g.Width/2.0,0,g.Width/2.0,g.Height) c.SaveGState c.AddRect(currentBounds2) c.Clip c.DrawRadialGradient(glossGradient2, topCenter2, 30, midCenter2, 100, 0) c.RestoreGState c.Flush End EventHandler
End Class
End Project

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


💬 Ask a question or report a problem