├── .gitattributes ├── .gitignore ├── LICENSE.md ├── README.md ├── headers ├── SparkColourPickerUtils.h └── SparkColourPickerView.h ├── lib └── libsparkcolourpicker.dylib └── package └── com.spark.libsparkcolourpicker_0.0.22_iphoneos-arm.deb /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libSparkColourPicker 2 | This is libSparkColourPicker, a super simple and easy to implement colour picker - designed for iOS 11/12/13. 3 | 4 | It simply allows developers to set colours from their preferences, and provides a few useful tools to handle colours in their tweaks. 5 | 6 | For users, this library will just be installed as a dependency from another tweak and away you go! 7 | 8 | ## Get Started 9 | It's super easy to get started with libSparkColourPicker, let's set it up! 10 | 11 | ### Pre-Requirements 12 | ``` 13 | None! 14 | ``` 15 | 16 | ### Installation for theos 17 | Add the 'libsparkcolourpicker.dylib' file to your "theos/lib" directory, and add the headers to "theos/include" 18 | 19 | You will also need to add it to the libraries in your makefile 20 | ``` 21 | TWEAKNAME_LIBRARIES = sparkcolourpicker 22 | ``` 23 | 24 | I recommend keeping to the same version of libSparkColourPicker for now (as I am actively improving it), so I'd point users to my repo https://sparkdev.me to install it. 25 | 26 | You can add it to your control file depends like so: 27 | 28 | ``` 29 | Depends: mobilesubstrate, preferenceloader, com.spark.libsparkcolourpicker 30 | ``` 31 | 32 | 33 | ### Simple Implementation 34 | 35 | I have tried to keep libSparkColourPicker as simple to implement as possible, so tried to make it as similar to the existing "libColorPicker" library as possible. 36 | This means, you can even just switch your library and dependency in your tweak preferences and libSparkColourPicker will just work. 37 | 38 | If you want to properly implement SparkColourPicker and have access to potential future changes you need to change your preferences to the following (replacing the "defaults", "key", and "label" values with your own values) 39 | 40 | PreferenceBundle plist (Root.plist) 41 | ``` 42 | 43 | cell 44 | PSLinkCell 45 | cellClass 46 | SparkColourPickerCell 47 | libsparkcolourpicker 48 | 49 | defaults 50 | com.your.identifier 51 | fallback 52 | #ffffff 53 | alpha 54 | 55 | 56 | label 57 | Your Colour Label 58 | key 59 | YourCustomColour 60 | 61 | ``` 62 | The "Fallback" value is the default value that will be used before the user modifies it, to display in the preview and start with. This can be provided as hex, and in this example is set to #ffffff (White). 63 | 64 | Once this is implemented you can then check a colour from within your tweak. 65 | So an example of checking it, depending on the scenario, could be like this: 66 | 67 | ``` 68 | #import "SparkColourPickerUtils.h" 69 | 70 | %hook HOOKHERE 71 | 72 | -(UIColor*) FUNCTIONTOHOOK 73 | { 74 | NSString* colourString = NULL; 75 | NSDictionary* preferencesDictionary = [NSDictionary dictionaryWithContentsOfFile: @"/var/mobile/Library/Preferences/com.your.identifier.plist"]; 76 | if(preferencesDictionary) 77 | { 78 | colourString = [preferencesDictionary objectForKey: @"YourCustomColour"]; 79 | } 80 | 81 | UIColor* selectedColour = [SparkColourPickerUtils colourWithString: colourString withFallback: @"#ffffff"]; 82 | 83 | return selectedColour; 84 | } 85 | 86 | %end 87 | ``` 88 | 89 | ### 'Helper' methods 90 | 91 | ``` 92 | @interface SparkColourPickerUtils : NSObject 93 | +(NSString*) hexStringFromColour:(UIColor*) colour; 94 | +(NSString*) rgbStringFromColour:(UIColor*) colour; 95 | +(UIColor*) inverseColour:(UIColor*) colour; 96 | +(UIColor*) colour:(UIColor*) colour withBrightness:(float) newBrightness; 97 | +(BOOL) colourIsBlack:(UIColor*) colour; 98 | +(BOOL) colourIsWhite:(UIColor*) colour; 99 | +(UIColor*) colourWithString: (NSString*) colourString; 100 | +(UIColor *) colourWithString:(NSString *)stringToConvert withFallback:(NSString*) fallback; 101 | +(UIColor *) colourWithString:(NSString *)stringToConvert withFallbackColour:(UIColor*) fallback; 102 | +(UIColor*) colourWithRGBString:(NSString*) stringToConvert; 103 | +(UIColor *) colourWithHexString:(NSString *)stringToConvert; 104 | +(BOOL) colourIsLight :(UIColor*) colour; 105 | +(UIColor*) interpolateFrom:(UIColor*)startColour toColour:(UIColor*)endColour withPercentage:(float)percentage; 106 | @end 107 | ``` 108 | 109 | 110 | ### 'Advanced' methods 111 | 112 | If you want to add your own implementation instead of using the provided preference cell, you can use the following methods: 113 | 114 | ``` 115 | @protocol SparkColourPickerViewDelegate 116 | -(void) colourPicker:(id)picker didUpdateColour:(UIColor*) colour; 117 | @end 118 | 119 | @interface SparkColourPickerView : UIView 120 | 121 | // forceUIMode is used to force to dark or light mode (-1: Default, 1: Dark, 2: Light) 122 | -(instancetype) initWithFrame:(CGRect) frame forceUIMode:(int) uiMode; 123 | -(instancetype) initWithFrame:(CGRect) frame forceUIMode:(int) uiMode andViewSizeFactor:(float)viewSizeFactor; 124 | 125 | // These two properties can be set before showing the view to set the initial colour. The unmodified colour is without alpha. 126 | @property (nonatomic, retain) UIColor* currentColour; 127 | @property (nonatomic, retain) UIColor* currentColourUnmodified; 128 | 129 | @property (nonatomic, assign) float currentColourAlpha; 130 | @property (nonatomic, assign) float currentColourBrightness; 131 | 132 | // The title to display at the top, leave NULL for nothing. 133 | @property (nonatomic, retain) NSString* keyName; 134 | 135 | // Delegate to call the 'didUpdateColour' method on 136 | @property (nonatomic, retain) id delegate; 137 | 138 | // This is used for showing alerts. 139 | @property (nonatomic, retain) UIViewController* rootViewController; 140 | @end 141 | ``` 142 | 143 | ### Preference Cell Colour Preview Styling 144 | 145 | It is possible to change the style of the 'preview' in the preferences cells. 146 | Firstly, the 'gradient' effect can be enabled/disabled using the key "PreviewGradient". This is enabled by default. 147 | To enable it, simply add it to your preferences plist entry. 148 | An example would look like this: 149 | 150 | PreferenceBundle plist (Root.plist) 151 | ``` 152 | 153 | cell 154 | PSLinkCell 155 | cellClass 156 | SparkColourPickerCell 157 | libsparkcolourpicker 158 | 159 | defaults 160 | com.your.identifier 161 | fallback 162 | #ffffff 163 | alpha 164 | 165 | PreviewGradient 166 | 167 | 168 | label 169 | Your Colour Label 170 | key 171 | YourCustomColour 172 | 173 | ``` 174 | 175 | As of *the upcoming* libsparkcolourpicker 1.0.2, there are also multiple other styles that can be enabled. 176 | These are as follows: 177 | | ID | Description | 178 | |----|-------------------------------| 179 | | 0 | **Default** rectangle box preview | 180 | | 1 | Circle with glow | 181 | | 2 | Circle without glow | 182 | | 3 | Circle with border | 183 | | 4 | Square with glow | 184 | | 5 | Square without glow | 185 | | 6 | Square with border | 186 | 187 | To set this style, simple set the key "PreviewStyle" in your preferences plist entry. 188 | An example would look like this: 189 | 190 | PreferenceBundle plist (Root.plist) 191 | ``` 192 | 193 | cell 194 | PSLinkCell 195 | cellClass 196 | SparkColourPickerCell 197 | libsparkcolourpicker 198 | 199 | defaults 200 | com.your.identifier 201 | fallback 202 | #ffffff 203 | alpha 204 | 205 | PreviewGradient 206 | 207 | PreviewStyle 208 | 1 209 | 210 | label 211 | Your Colour Label 212 | key 213 | YourCustomColour 214 | 215 | ``` 216 | 217 | #### Preview of styles with gradient disabled 218 | Below is an example of each style (in order 0-6), with "PreviewGradient" set to *false*. Displaying colour rgb(0, 255, 0) (#00ff00). 219 | 220 | ![Preview of styles with gradient disabled](https://i.imgur.com/jwcg5On.jpg) 221 | 222 | #### Preview of styles with gradient enabled 223 | Below is an example of each style (in order 0-6), with "PreviewGradient" set to *true*. Displaying colour rgb(0, 255, 0) (#00ff00). 224 | 225 | ![Preview of styles with gradient enabled](https://i.imgur.com/aTKd2cM.jpg) 226 | 227 | ## Authors 228 | SparkDev 2020 229 | -------------------------------------------------------------------------------- /headers/SparkColourPickerUtils.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface SparkColourPickerUtils : NSObject 4 | +(NSString*) hexStringFromColour:(UIColor*) colour; 5 | +(NSString*) rgbStringFromColour:(UIColor*) colour; 6 | +(UIColor*) inverseColour:(UIColor*) colour; 7 | +(UIColor*) colour:(UIColor*) colour withBrightness:(float) newBrightness; 8 | +(BOOL) colourIsBlack:(UIColor*) colour; 9 | +(BOOL) colourIsWhite:(UIColor*) colour; 10 | +(UIColor*) colourWithString: (NSString*) colourString; 11 | +(UIColor *)colourWithString:(NSString *)stringToConvert withFallback:(NSString*) fallback; 12 | +(UIColor *)colourWithString:(NSString *)stringToConvert withFallbackColour:(UIColor*) fallback; 13 | +(UIColor*) colourWithRGBString:(NSString*) stringToConvert; 14 | +(UIColor *) colourWithHexString:(NSString *)stringToConvert; 15 | +(BOOL) colourIsLight :(UIColor*) colour; 16 | +(UIColor*)interpolateFrom:(UIColor*)startColour toColour:(UIColor*)endColour withPercentage:(float)percentage; 17 | @end 18 | -------------------------------------------------------------------------------- /headers/SparkColourPickerView.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NS_ASSUME_NONNULL_BEGIN 4 | @protocol SparkColourPickerViewDelegate 5 | -(void) colourPicker:(id)picker didUpdateColour:(UIColor*) colour; 6 | @end 7 | 8 | @interface SparkColourPickerView : UIView 9 | // forceUIMode is used to force to dark or light mode (-1: Default, 1: Dark, 2: Light) 10 | -(instancetype) initWithFrame:(CGRect) frame forceUIMode:(int) uiMode; 11 | -(instancetype) initWithFrame:(CGRect) frame forceUIMode:(int) uiMode andViewSizeFactor:(float)viewSizeFactor; 12 | 13 | // These two properties can be set before showing the view to set the initial colour. The unmodified colour is without alpha. 14 | @property (nonatomic, retain) UIColor* currentColour; 15 | @property (nonatomic, retain) UIColor* currentColourUnmodified; 16 | @property (nonatomic, assign) float currentColourAlpha; 17 | @property (nonatomic, assign) float currentColourBrightness; 18 | 19 | // The title to display at the top, leave NULL for nothing. 20 | @property (nonatomic, retain) NSString* keyName; 21 | 22 | // Delegate to call the 'didUpdateColour' method on 23 | @property (nonatomic, retain) id delegate; 24 | 25 | // This is used for showing alerts. 26 | @property (nonatomic, retain) UIViewController* rootViewController; 27 | @end 28 | NS_ASSUME_NONNULL_END -------------------------------------------------------------------------------- /lib/libsparkcolourpicker.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SparkDev97/libSparkColourPicker/5b60cda826b17517feb87ba65db1db71fa0fe37a/lib/libsparkcolourpicker.dylib -------------------------------------------------------------------------------- /package/com.spark.libsparkcolourpicker_0.0.22_iphoneos-arm.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SparkDev97/libSparkColourPicker/5b60cda826b17517feb87ba65db1db71fa0fe37a/package/com.spark.libsparkcolourpicker_0.0.22_iphoneos-arm.deb --------------------------------------------------------------------------------