Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/CGGradient test
Function:
Required plugins for this example: MBS MacCG 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.rbp"
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

Feedback, Comments & Corrections

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





Links
MBS FileMaker tutorial videos