ArtisanKit Module

This module provides a number of classes, methods, and extension methods useful in custom control authoring.



Function ArtisanKit.BlendColors (Color1 As Color, Color2 As Color, Color2Opacity As Double = 1) As Color

This method blends Color1 with Color2 at the ratio specified in Color2Opacity. An opacity of 1 means 100% Color2 and 0% Color1. An opacity of 0.5 means 50% Color2 and 50% Color1. Alpha channels are not supported and will fire an UnsupportedOperationException.

Function ArtisanKit.ColorBrightness (C As Color) As Integer

Estimates the perceived brightness of a color. Experimentation will be necessary, though generally a value less than 170 should be considered dark. This is useful for custom background colors, so the foreground/text color can be switched from black to white to provide clear contrast.

Function ArtisanKit.ColorIsBright (Source As Color) As Boolean

Uses the brightness and luminance of a color to determine wether or not a color appears light on the screen.

Function ArtisanKit.ColorLuminance (Source As Color) As Double

Calculates the relative luminance of a color. Returns a value between 0 and 1. Values greater than 0.65 should be considered light colors. Luminance is most useful for calculating the contrast between two colors.

Function ArtisanKit.FullKeyboardAccessEnabled () As Boolean

In OS X Keyboard Preferences, under Shortcuts there is a setting called "Full Keyboard Access." This method returns True when this option is set to "All controls." The control will automatically accept tabs if the user is tabbing through controls, and the user should be able to use the keyboard to interact with the control.

On other platforms, this method always returns True.

Function ArtisanKit.IsDarkMode () As Boolean

A simple wrapper for the REALbasic.IsDarkMode method introduced in 2018r3. For older versions, this method always returns false. This method simply saves the caller from having to detect the Xojo version with conditional compilation.

Extension Methods

Function Graphics.CapHeight (Extends G As Graphics) As Double

A font's CapHeight is the measurement from the baseline to the top of a capital letter. This is similar to Graphics.TextAscent, but the ascent of the font includes space for diacritical marks. This method uses system declares on OS X, but must rely on guesswork on Windows and Linux.

When trying to vertically center some text, the CapHeight will produce a much more visually pleasing result than TextAscent or TextHeight.

Sub Graphics.DrawRetinaPicture (Extends G As Graphics, Source As ArtisanKit.RetinaPicture, Left As Integer, Top As Integer)
Sub Graphics.DrawRetinaPicture (Extends G As Graphics, Source As ArtisanKit.RetinaPicture, Left As Integer, Top As Integer, Width As Integer, Height As Integer)
Sub Graphics.DrawRetinaPicture (Extends G As Graphics, Source As ArtisanKit.RetinaPicture, Left As Integer, Top As Integer, Width As Integer, Height As Integer, SourceLeft As Integer, SourceTop As Integer, SourceWidth As Integer, SourceHeight As Integer)

Draws a ArtisanKit.RetinaPicture to the Graphics object. Like Graphics.DrawPicture, there are multiple signatures useful for scaling and clipping the Source.

Sub Graphics.DrawStretchedPicture (Extends G As Graphics, Source As Picture, Destination As REALbasic.Rect, StretchVertical As Boolean = True, StretchHorizontal As Boolean = True)

Stretches the Source picture to fill the Destination rect. If StretchVertical is True, the picture will be vertically divided into 3 equal parts, with the middle stretching to fill the height, the first and third parts used to "cap" the fill. StretchHorizonal does the same for the width. The width must be a multiple of 3 when StretchHorizontal is True, the height must be a multiple of 3 when StrechVertical is True. The Destination dimensions must be greater than the Source dimensions.

Sub Graphics.FillWithPattern (Extends G As Graphics, Source As Picture, Area As REALbasic.Rect, SourcePortion As REALbasic.Rect = Nil)

Pattern fills the area given by Area with the Source picture. The SourcePortion rect can be added to use only a portion of the Source picture for the fill.

Function Graphics.ScalingFactor (Extends G As Graphics) As Single

Returns the scaling factor for the given Graphics object. See ArtisanKit.Control.Paint for more information about the scaling factor.