Skip to content

Commit

Permalink
ArtisanKit 1.1.0
Browse files Browse the repository at this point in the history
Adds IsDarkMode, ColorIsBright, and ColorLuminance methods.
  • Loading branch information
thommcgrath committed Oct 29, 2018
1 parent 1b117e6 commit 1695f76
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Documentation/docs/ArtisanKit.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ This method blends `Color1` with `Color2` at the ratio specified in `Color2Opaci
<pre id="method.colorbrightness"><span style="font-family: 'source-code-pro', 'menlo', 'courier', monospace; color: #000000;"><span style="color: #0000FF;">Function</span> ArtisanKit.ColorBrightness (C <span style="color: #0000FF;">As</span> <span style="color: #0000FF;">Color</span>) <span style="color: #0000FF;">As</span> <span style="color: #0000FF;">Integer</span></span></pre>
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.

<pre id="method.colorisbright"><span style="font-family: 'source-code-pro', 'menlo', 'courier', monospace; color: #000000;"><span style="color: #0000FF;">Function</span> ArtisanKit.ColorIsBright (Source <span style="color: #0000FF;">As</span> <span style="color: #0000FF;">Color</span>) <span style="color: #0000FF;">As</span> <span style="color: #0000FF;">Boolean</span></span></pre>
Uses the brightness and luminance of a color to determine wether or not a color appears light on the screen.

<pre id="method.colorluminance"><span style="font-family: 'source-code-pro', 'menlo', 'courier', monospace; color: #000000;"><span style="color: #0000FF;">Function</span> ArtisanKit.ColorLuminance (Source <span style="color: #0000FF;">As</span> <span style="color: #0000FF;">Color</span>) <span style="color: #0000FF;">As</span> <span style="color: #0000FF;">Double</span></span></pre>
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.

<pre id="method.fullkeyboardaccessenabled"><span style="font-family: 'source-code-pro', 'menlo', 'courier', monospace; color: #000000;"><span style="color: #0000FF;">Function</span> ArtisanKit.FullKeyboardAccessEnabled () <span style="color: #0000FF;">As</span> <span style="color: #0000FF;">Boolean</span></span></pre>
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`.

<pre id="method.isdarkmode"><span style="font-family: 'source-code-pro', 'menlo', 'courier', monospace; color: #000000;"><span style="color: #0000FF;">Function</span> ArtisanKit.IsDarkMode () <span style="color: #0000FF;">As</span> <span style="color: #0000FF;">Boolean</span></span></pre>
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

<pre id="method.graphics.capheight"><span style="font-family: 'source-code-pro', 'menlo', 'courier', monospace; color: #000000;"><span style="color: #0000FF;">Function</span> Graphics.CapHeight (<span style="color: #0000FF;">Extends</span> G <span style="color: #0000FF;">As</span> Graphics) <span style="color: #0000FF;">As</span> <span style="color: #0000FF;">Double</span></span></pre>
Expand Down
31 changes: 30 additions & 1 deletion Project/ArtisanKit.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ Protected Module ArtisanKit
End Function
#tag EndMethod

#tag Method, Flags = &h1
Protected Function ColorIsBright(Source As Color) As Boolean
Return ColorLuminance(Source) > 0.65 Or ColorBrightness(Source) >= 170
End Function
#tag EndMethod

#tag Method, Flags = &h1
Protected Function ColorLuminance(Source As Color) As Double
If Source.Red = Source.Green And Source.Green = Source.Blue Then
Return Source.Red / 255
End If

Dim Red As Double = (Source.Red / 255) ^ 2.2
Dim Green As Double = (Source.Green / 255) ^ 2.2
Dim Blue As Double = (Source.Blue / 255) ^ 2.2
Return (0.2126 * Red) + (0.7151 * Green) + (0.0721 * Blue)
End Function
#tag EndMethod

#tag Method, Flags = &h0
Sub DrawRetinaPicture(Extends G As Graphics, Source As ArtisanKit.RetinaPicture, Left As Integer, Top As Integer)
G.DrawRetinaPicture(Source,Left,Top,Source.Width,Source.Height,0,0,Source.Width,Source.Height)
Expand Down Expand Up @@ -294,6 +313,16 @@ Protected Module ArtisanKit
End Function
#tag EndMethod

#tag Method, Flags = &h1
Protected Function IsDarkMode() As Boolean
#if XojoVersion >= 2018.03
Return REALbasic.IsDarkMode
#else
Return False
#endif
End Function
#tag EndMethod

#tag Method, Flags = &h0
Function ScalingFactor(Extends G As Graphics) As Single
#if XojoVersion >= 2016.04
Expand Down Expand Up @@ -329,7 +358,7 @@ Protected Module ArtisanKit

#tag Note, Name = Version

1.0.2
1.1.0
#tag EndNote


Expand Down

0 comments on commit 1695f76

Please sign in to comment.