Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/NSColor and Colorspaces
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS Main Plugin, MBS Picture Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSColor and Colorspaces
This example is the version from Fri, 4th Dec 2014.
Project "NSColor and Colorspaces.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) //Straight Render g.ForeColor = c g.FillRect(0,0,100,100) End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Refresh End EventHandler
End Control
Control PickColorButton Inherits PushButton
ControlInstance PickColorButton Inherits PushButton
EventHandler Sub Action() dim n as color = c if SelectColor(n, "Pick a color:") then c = n UpdateColorLabel refresh timer1.Mode = 1 end if End EventHandler
End Control
Control ColorLabel Inherits Label
ControlInstance ColorLabel Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Canvas2 Inherits Canvas
ControlInstance Canvas2 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim n as new NSGraphicsMBS // current color space dim c1 as NSColorMBS = NSColorMBS.colorWithColorSpace(NSColorSpaceMBS.genericRGBColorSpace, c.Red/255, c.Green/255, c.Blue/255,1.0) n.setColor(c1) n.fillRect new NSRectMBS(0, 0, 100, 100) End EventHandler
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control Canvas3 Inherits Canvas
ControlInstance Canvas3 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim n as new NSGraphicsMBS // current color space dim c1 as NSColorMBS = NSColorMBS.colorWithDeviceRGB(c.Red/255, c.Green/255, c.Blue/255,1.0) n.setColor(c1) n.fillRect new NSRectMBS(0, 0, 100, 100) End EventHandler
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control Canvas4 Inherits Canvas
ControlInstance Canvas4 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim n as new NSGraphicsMBS // current color space dim c1 as NSColorMBS = NSColorMBS.colorWithCalibratedRGB(c.Red/255, c.Green/255, c.Blue/255,1.0) n.setColor(c1) n.fillRect new NSRectMBS(0, 0, 100, 100) End EventHandler
End Control
Control Label5 Inherits Label
ControlInstance Label5 Inherits Label
End Control
Control Canvas5 Inherits Canvas
ControlInstance Canvas5 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim n as new NSGraphicsMBS // current color space dim c1 as NSColorMBS = NSColorMBS.colorWithSRGB(c.Red/255, c.Green/255, c.Blue/255,1.0) n.setColor(c1) n.fillRect new NSRectMBS(0, 0, 100, 100) End EventHandler
End Control
Control Label6 Inherits Label
ControlInstance Label6 Inherits Label
End Control
Control Canvas6 Inherits Canvas
ControlInstance Canvas6 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim n as new NSGraphicsMBS // current color space dim cs as NSColorSpaceMBS = NSColorSpaceMBS.adobeRGB1998ColorSpace dim c1 as NSColorMBS = NSColorMBS.colorWithColorSpace(cs, c.Red/255, c.Green/255, c.Blue/255,1.0) n.setColor(c1) n.fillRect new NSRectMBS(0, 0, 100, 100) End EventHandler
End Control
Control Color1 Inherits Label
ControlInstance Color1 Inherits Label
End Control
Control Color2 Inherits Label
ControlInstance Color2 Inherits Label
End Control
Control Color3 Inherits Label
ControlInstance Color3 Inherits Label
End Control
Control Color4 Inherits Label
ControlInstance Color4 Inherits Label
End Control
Control Color5 Inherits Label
ControlInstance Color5 Inherits Label
End Control
Control Color6 Inherits Label
ControlInstance Color6 Inherits Label
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() dim p as Picture dim c as canvas dim t as label c = screen1 t = color1 p = ScreenshotRectMBS(c.left+left, c.top+top, c.width, c.Height) screen1.Backdrop = p t.Text = FormatColor(p.Graphics.Pixel(50,50)) c = screen2 t = color2 p = ScreenshotRectMBS(c.left+left, c.top+top, c.width, c.Height) screen2.Backdrop = p t.Text = FormatColor(p.Graphics.Pixel(50,50)) c = screen3 t = color3 p = ScreenshotRectMBS(c.left+left, c.top+top, c.width, c.Height) screen3.Backdrop = p t.Text = FormatColor(p.Graphics.Pixel(50,50)) c = screen4 t = color4 p = ScreenshotRectMBS(c.left+left, c.top+top, c.width, c.Height) screen4.Backdrop = p t.Text = FormatColor(p.Graphics.Pixel(50,50)) c = screen5 t = color5 p = ScreenshotRectMBS(c.left+left, c.top+top, c.width, c.Height) screen5.Backdrop = p t.Text = FormatColor(p.Graphics.Pixel(50,50)) c = screen6 t = color6 p = ScreenshotRectMBS(c.left+left, c.top+top, c.width, c.Height) screen6.Backdrop = p t.Text = FormatColor(p.Graphics.Pixel(50,50)) End EventHandler
End Control
Control Screen1 Inherits Canvas
ControlInstance Screen1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) //Straight Render g.ForeColor = c g.FillRect(0,0,100,100) End EventHandler
End Control
Control Screen2 Inherits Canvas
ControlInstance Screen2 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim n as new NSGraphicsMBS // current color space dim c1 as NSColorMBS = NSColorMBS.colorWithColorSpace(NSColorSpaceMBS.genericRGBColorSpace, c.Red/255, c.Green/255, c.Blue/255,1.0) n.setColor(c1) n.fillRect new NSRectMBS(0, 0, 100, 100) End EventHandler
End Control
Control Screen3 Inherits Canvas
ControlInstance Screen3 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim n as new NSGraphicsMBS // current color space dim c1 as NSColorMBS = NSColorMBS.colorWithDeviceRGB(c.Red/255, c.Green/255, c.Blue/255,1.0) n.setColor(c1) n.fillRect new NSRectMBS(0, 0, 100, 100) End EventHandler
End Control
Control Screen4 Inherits Canvas
ControlInstance Screen4 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim n as new NSGraphicsMBS // current color space dim c1 as NSColorMBS = NSColorMBS.colorWithCalibratedRGB(c.Red/255, c.Green/255, c.Blue/255,1.0) n.setColor(c1) n.fillRect new NSRectMBS(0, 0, 100, 100) End EventHandler
End Control
Control Screen5 Inherits Canvas
ControlInstance Screen5 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim n as new NSGraphicsMBS // current color space dim c1 as NSColorMBS = NSColorMBS.colorWithSRGB(c.Red/255, c.Green/255, c.Blue/255,1.0) n.setColor(c1) n.fillRect new NSRectMBS(0, 0, 100, 100) End EventHandler
End Control
Control Screen6 Inherits Canvas
ControlInstance Screen6 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim n as new NSGraphicsMBS // current color space dim cs as NSColorSpaceMBS = NSColorSpaceMBS.adobeRGB1998ColorSpace dim c1 as NSColorMBS = NSColorMBS.colorWithColorSpace(cs, c.Red/255, c.Green/255, c.Blue/255,1.0) n.setColor(c1) n.fillRect new NSRectMBS(0, 0, 100, 100) End EventHandler
End Control
EventHandler Sub Open() UpdateColorLabel End EventHandler
Function FormatColor(c as color) As string dim r as string = right("00"+hex(c.red ),2) dim g as string = right("00"+hex(c.green),2) dim b as string = right("00"+hex(c.blue ),2) return r+g+b+" "+str(c.red)+"/"+str(C.Green)+"/"+str(c.Blue) End Function
Sub UpdateColorLabel() ColorLabel.Text = FormatColor(c) End Sub
Property c As color = &c444444
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
End Project

Feedback, Comments & Corrections

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




Links
MBS Xojo Plugins