Advertisement
Guest User

Untitled

a guest
Oct 7th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 5.96 KB | None | 0 0
  1. #include <Array.au3>
  2. #include "JSON.au3"
  3. #Include <File.au3>
  4. #Include <color.au3>
  5.  
  6. Dim $ThemeColors[1][2] = [[$_JSONNull,'JSONObject']]
  7. Dim $ThemeImages[1][2] = [[$_JSONNull,'JSONObject']]
  8. Dim $ThemeTints[1][2] = [[$_JSONNull,'JSONObject']]
  9. Dim $ThemeProperties[1][2] = [[$_JSONNull,'JSONObject']]
  10. Dim $ThemeTheme[1][2] = [[$_JSONNull,'JSONObject']]
  11. Dim $ThemeName = ""
  12. Dim $ThemeVersion = 1
  13. Dim $LoadedManifestPath = ""
  14. Dim $SavedManifestPath = ""
  15.  
  16. Func _LoadManifest($path)
  17. Local $file = FileOpen($path, 0)
  18. If $file = -1 Then
  19.     MsgBox(0, "Error", "Unable to open file for loading.")
  20.     Exit
  21. EndIf
  22. Local $manifest = FileRead($file)
  23. FileClose($file)
  24. _ProcessManifest($manifest)
  25. $LoadedManifestPath = $path
  26. EndFunc
  27.  
  28. Func _SaveManifest($path)
  29. Local $manifest = _MakeManifest()
  30. Local $file = FileOpen($path, 2)
  31. If $file = -1 Then
  32.     MsgBox(0, "Error", "Unable to open save file.")
  33.     Exit
  34. EndIf
  35. FileWrite ($file, $manifest )
  36. FileClose($file)
  37. $SavedManifestPath = $path
  38. EndFunc
  39.  
  40. func _ProcessManifest ($string)
  41.     local $Theme = _JSONDecode($string)
  42.     $ThemeName = _GetKey($Theme,'name')
  43.     $ThemeVersion = Number(_GetKey($Theme,'version'))
  44.     $Theme = _GetKey($Theme,'theme')
  45.     $ThemeColors = _GetKey($Theme,'colors')
  46.     $ThemeImages = _GetKey($Theme,'images')
  47.     $ThemeTints = _GetKey($Theme,'tints')
  48.     $ThemeProperties = _GetKey($Theme,'properties')
  49. EndFunc
  50.  
  51. func _ProcessManifestArray ($Theme)
  52.     $ThemeName = _GetKey($Theme,'name')
  53.     $ThemeVersion = Number(_GetKey($Theme,'version'))
  54.     $Theme = _GetKey($Theme,'theme')
  55.     $ThemeColors = _GetKey($Theme,'colors')
  56.     $ThemeImages = _GetKey($Theme,'images')
  57.     $ThemeTints = _GetKey($Theme,'tints')
  58.     $ThemeProperties = _GetKey($Theme,'properties')
  59. EndFunc
  60.  
  61. func _NewManifest($name,$version)
  62.     ReDim $ThemeColors[1][2]
  63.     ReDim $ThemeImages[1][2]
  64.     ReDim $ThemeTints[1][2]
  65.     ReDim $ThemeProperties[1][2]
  66.     ReDim $ThemeTheme[1][2]
  67.     $ThemeName = $name
  68.     $ThemeVersion = $version
  69. endfunc
  70.  
  71. func _MakeManifest()
  72. Local $Manifest[1][2] = [[$_JSONNull,'JSONObject']]
  73. Local $Theme[1][2] = [[$_JSONNull,'JSONObject']]
  74.     _KeyAdd($Manifest,'name',$ThemeName)
  75.     _KeyAdd($Manifest,'version',_FloatString($ThemeVersion))
  76.     _KeyAdd($Theme,'colors',$ThemeColors)
  77.     _KeyAdd($Theme,'images',$ThemeImages)
  78.     _KeyAdd($Theme,'tints',$ThemeTints)
  79.     _KeyAdd($Theme,'properties',$ThemeProperties)
  80.     _KeyAdd($Manifest,'theme',$Theme)
  81. Return _JSONEncode($Manifest,'',True)
  82. EndFunc
  83.  
  84. func _MakeManifestArray()
  85. Local $Manifest[1][2] = [[$_JSONNull,'JSONObject']]
  86. Local $Theme[1][2] = [[$_JSONNull,'JSONObject']]
  87.     _KeyAdd($Manifest,'name',$ThemeName)
  88.     _KeyAdd($Manifest,'version',_FloatString($ThemeVersion))
  89.     _KeyAdd($Theme,'colors',$ThemeColors)
  90.     _KeyAdd($Theme,'images',$ThemeImages)
  91.     _KeyAdd($Theme,'tints',$ThemeTints)
  92.     _KeyAdd($Theme,'properties',$ThemeProperties)
  93.     _KeyAdd($Manifest,'theme',$Theme)
  94. Return $Manifest
  95. EndFunc
  96.  
  97. func _Tint($hue,$sat,$lum,$alpha=false)
  98.     Dim $ra[3]=[$hue,$sat,$lum]
  99.         if $alpha Then
  100.     _ArrayAdd($ra,$alpha)
  101.     EndIf
  102.     Return ($ra)
  103. EndFunc
  104.  
  105. ; Colour spelt the American way because they whinge more than anybody ;)
  106. func _Color($red,$green,$blue,$alpha=false)
  107.     Local $ra[3]=[$red,$green,$blue]
  108.     if $alpha Then
  109.     _ArrayAdd($ra,$alpha)
  110.     EndIf
  111.     Return ($ra)
  112. EndFunc
  113.  
  114. func _FloatString($num)
  115. if Int($num)=$num Then
  116.     Return(String($num) & '.0')
  117. Else
  118.     Return(String($num))
  119. EndIf
  120. EndFunc
  121.  
  122. func _KeyAdd(ByRef $object, $key, $value)
  123.     ReDim $object[UBound($object)+1][2]
  124.     $object[UBound($object)-1][0]=$key
  125.     $object[UBound($object)-1][1]=$value
  126. EndFunc
  127.  
  128.  
  129. Func _KeyDelete(ByRef $object, $key)
  130. local $Index = _ArraySearch($object, $key, 0, 0, 0, 1)
  131.     if $Index >-1 Then
  132.         _ArrayDelete($object,$Index)
  133.     EndIf
  134. EndFunc
  135.  
  136. Func _SetKey(ByRef $object, $key, $value='')
  137. local $Index = _ArraySearch($object, $key, 0, 0, 0, 1)
  138. if $Index >-1 Then
  139.     If $value<>'' Then
  140.         $object[$Index][0]=$key
  141.         $object[$Index][1]=$value
  142.     Else
  143.         _KeyDelete($object, $key)
  144.     EndIf
  145. Else
  146.     If $value<>'' Then
  147.         _KeyAdd($object, $key, $value)
  148.     EndIf
  149. EndIf
  150. EndFunc
  151.  
  152. Func _GetKey(ByRef $object, $key)
  153. local $Index = _ArraySearch($object, $key, 0, 0, 0, 1)
  154. if $Index >-1 Then
  155.     Return $object[$Index][1]
  156. Else
  157.     Return ''
  158. EndIf
  159. EndFunc
  160.  
  161. ; Set the color ussing an array that may or may not contain an alpha [red,green,blue,alpha]
  162. Func _SetColor ($key, $value='')
  163.     _SetKey($ThemeColors, $key, $value)
  164. EndFunc
  165.  
  166. ;Returns an array of [red,green,blue,alpha] if there is no alpha it will return [red,green,blue]
  167. Func _GetColor ($key)
  168.     Return _GetKey($ThemeColors, $key)
  169. EndFunc
  170.  
  171. ; Set a color using something like 0xFFFFFF
  172. Func _SetColorRGB ($key, $value='')
  173.      $value = _ColorSetRGB($value)
  174.     _SetKey($ThemeColors, $key, $value)
  175. EndFunc
  176.  
  177. ; Returns a color, such as 0xFFFFFF
  178. Func _GetColorRGB ($key)
  179.     Local $temp = _GetKey($ThemeColors, $key)
  180.     If $temp <> '' Then
  181.         ReDim $temp[3]
  182.         Return _ColorSetRGB($temp)
  183.     Else
  184.         Return ''
  185.     EndIf
  186. EndFunc
  187.  
  188. Func _SetTint ($key, $value='')
  189.     _SetKey($ThemeTints, $key, $value)
  190. EndFunc
  191.  
  192. Func _GetTint ($key)
  193.     Return _GetKey($ThemeTints, $key)
  194. EndFunc
  195.  
  196. Func _SetPropety ($key, $value='')
  197.     _SetKey($ThemeProperties, $key, $value)
  198. EndFunc
  199.  
  200. Func _GetProperty ($key)
  201.     Return _GetKey($ThemeProperties, $key)
  202. EndFunc
  203.  
  204. Func _SetImage ($key, $value='')
  205.     _SetKey($ThemeImages, $key, $value)
  206. EndFunc
  207.  
  208. Func _GetImage ($key)
  209.     Return _GetKey($ThemeImages, $key)
  210. EndFunc
  211.  
  212. Func _GetFullImagePath($image, $basepath)
  213.     $image = _GetImage($image)
  214.     if $image <> '' Then
  215.         Return _PathFull($basepath &'\' & $image)
  216.     Else
  217.         Return ''
  218.     EndIf
  219. EndFunc
  220.  
  221. Func _SetImageFromPath($key, $imagedirectory, $path)
  222.     Dim $szDrive, $szDir, $szFName, $szExt
  223.     _PathSplit($path, $szDrive, $szDir, $szFName, $szExt)
  224.     _SetKey($ThemeImages, $key, $imagedirectory & '/' & $szFName & $szExt)
  225. EndFunc
  226.  
  227. Func _GetName()
  228.     Return $ThemeName
  229. EndFunc
  230.  
  231. Func _GetVersion()
  232.     Return Number($ThemeVersion)
  233. EndFunc
  234.  
  235. Func _SetName($value)
  236.     $ThemeName = $value
  237. EndFunc
  238.  
  239. Func _SetVersion($value)
  240.     $ThemeVersion = _FloatString($value)
  241. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement