uconfig.pas 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997
  1. // SPDX-License-Identifier: GPL-3.0-only
  2. unit UConfig;
  3. {$mode objfpc}{$H+}
  4. interface
  5. uses
  6. Classes, SysUtils, IniFiles, BGRABitmapTypes, Graphics, LCLType, uscripting,
  7. Forms, LCVectorRectShapes;
  8. type
  9. TLazPaintConfig = class;
  10. IConfigProvider = interface
  11. function GetConfig: TLazPaintConfig;
  12. end;
  13. TDarkThemePreference = (dtpAuto, dtpDark, dtpLight);
  14. { TLazPaintConfig }
  15. TLazPaintConfig = class
  16. private
  17. iniOptions: TIniFile;
  18. recentFiles, recentDirs: TStringList;
  19. tempFont: TFont;
  20. colorizePresets: TList;
  21. FVersion: string;
  22. FDarkTheme,FDarkThemeEvaluated: boolean;
  23. FDarkThemePreference: TDarkThemePreference;
  24. FDarkThemePreferenceEvaluated: boolean;
  25. FWorkspaceColor: TColor;
  26. FWorkspaceColorEvaluated: boolean;
  27. function GetBrushCount: integer;
  28. function GetBrushInfo(Index: integer): string;
  29. function GetColorizePreset(Index: Integer): TVariableSet;
  30. function GetColorizePresetCount: integer;
  31. function GetRecentDirectoriesCount: integer;
  32. function GetRecentDirectory(Index: Integer): string;
  33. function GetRecentFile(Index: Integer): string;
  34. function GetRecentFilesCount: integer;
  35. public
  36. Languages: TStringList;
  37. constructor Create(ini: TIniFile; AVersion: string);
  38. destructor Destroy; override;
  39. procedure InitRecentFiles;
  40. procedure AddRecentFile(filename: string);
  41. procedure AddRecentDirectory(dirname: string);
  42. procedure FinalizeRecentFiles;
  43. function DefaultRememberStartupTargetDirectory: boolean;
  44. procedure SetRememberStartupTargetDirectory(AValue: boolean);
  45. function DefaultRememberStartupExportDirectory: boolean;
  46. procedure SetRememberStartupExportDirectory(AValue: boolean);
  47. function DefaultRememberStartupSourceDirectory: boolean;
  48. procedure SetRememberStartupSourceDirectory(AValue: boolean);
  49. function DefaultStartupSourceDirectory: string;
  50. procedure SetStartupSourceDirectory(AValue: string);
  51. function DefaultStartupTargetDirectory: string;
  52. procedure SetStartupTargetDirectory(AValue: string);
  53. function DefaultStartupExportDirectory: string;
  54. procedure SetStartupExportDirectory(AValue: string);
  55. function DefaultRememberSaveFormat: boolean;
  56. procedure SetRememberSaveFormat(AValue: boolean);
  57. function DefaultSaveExtensions: string;
  58. procedure SetSaveExtensions(AValue: string);
  59. procedure SetBrushes(ABrushes: TStringList);
  60. function DefaultJpegQuality: integer;
  61. procedure SetDefaultJpegQuality(value: integer);
  62. function DefaultWebPLossless: boolean;
  63. procedure SetDefaultWebPLossless(value: boolean);
  64. function DefaultSaveOptionDialogMaximized: boolean;
  65. procedure SetDefaultSaveOptionDialogMaximized(value: boolean);
  66. procedure InitColorizePresets;
  67. function AddColorizePreset(AName: string; AHue, ASaturation: double; ACorrection: Boolean): integer;
  68. function AddColorizePreset(AParams: TVariableSet): integer;
  69. procedure RemoveColorizePreset(AIndex: integer);
  70. function IndexOfColorizePreset(AName: string): integer;
  71. procedure FinalizeColorizePresets;
  72. function DefaultLangage: string;
  73. class function ClassGetDefaultLangage(AIni: TIniFile): string; static;
  74. procedure SetDefaultLangage(value: string);
  75. function GetLastUpdateCheck: TDateTime;
  76. procedure SetLastUpdateCheck(value: TDateTime);
  77. function LatestVersion: string;
  78. procedure SetLatestVersion(value: string);
  79. procedure GetUpdatedLanguages(AList: TStringList);
  80. procedure SetUpdatedLanguages(AList: TStringList);
  81. class procedure ClassGetUpdatedLanguages(AList: TStringList; AIni: TIniFile; AVersion: string); static;
  82. class procedure ClassSetUpdatedLanguages(AList: TStringList; AIni: TIniFile; AVersion: string); static;
  83. procedure AddUpdatedLanguage(ALang: string);
  84. function Default3dObjectDirectory: string;
  85. procedure SetDefault3dObjectDirectory(value: string);
  86. function DefaultTextureDirectory: string;
  87. procedure SetDefaultTextureDirectory(value: string);
  88. function DefaultBrushDirectory: string;
  89. procedure SetDefaultBrushDirectory(value: string);
  90. function DefaultPaletteDirectory: string;
  91. procedure SetDefaultPaletteDirectory(value: string);
  92. function DefaultScriptDirectory: string;
  93. procedure SetDefaultScriptDirectory(value: string);
  94. function DefaultCheckScriptsSecure: boolean;
  95. procedure SetDefaultCheckScriptsSecure(value: boolean);
  96. function DefaultIconSize(defaultValue: integer): integer;
  97. procedure SetDefaultIconSize(value: integer);
  98. function GetDarkTheme: boolean;
  99. procedure SetDarkTheme(AValue: boolean);
  100. function GetDarkThemePreference: TDarkThemePreference;
  101. procedure SetDarkThemePreference(AValue: TDarkThemePreference);
  102. //new image config
  103. function DefaultImageWidth: integer;
  104. function DefaultImageHeight: integer;
  105. function DefaultImageBackgroundColor: TBGRAPixel;
  106. procedure SetDefaultImageWidth(value: integer);
  107. procedure SetDefaultImageHeight(value: integer);
  108. procedure SetDefaultImageBackgroundColor(value: TBGRAPixel);
  109. function DefaultIconImageWidth: integer;
  110. function DefaultIconImageHeight: integer;
  111. function DefaultIconImageBitDepth: integer;
  112. function DefaultIconImageBackgroundColor: TBGRAPixel;
  113. procedure SetDefaultIconImageWidth(value: integer);
  114. procedure SetDefaultIconImageHeight(value: integer);
  115. procedure SetDefaultIconImageBitDepth(value: integer);
  116. procedure SetDefaultIconImageBackgroundColor(value: TBGRAPixel);
  117. //resample config
  118. function DefaultResampleKeepAspectRatio: boolean;
  119. function DefaultResampleQuality: integer;
  120. procedure SetDefaultResampleKeepAspectRatio(value: boolean);
  121. procedure SetDefaultResampleQuality(value: integer);
  122. //window
  123. function DefaultScreenSize: TRect;
  124. function DefaultDockLayersAndColors: boolean;
  125. procedure SetDefaultDockLayersAndColors(value: boolean);
  126. function DefaultDockLayersAndColorsWidth: integer;
  127. procedure SetDefaultDockLayersAndColorsWidth(AValue: integer);
  128. function ScreenSizeChanged: boolean;
  129. procedure SetDefaultScreenSize(value: TRect);
  130. function DefaultMainWindowMaximized: boolean;
  131. procedure SetDefaultMainWindowMaximized(value: boolean);
  132. function DefaultMainWindowPosition: TRect;
  133. procedure SetDefaultMainWindowPosition(value: TRect);
  134. function DefaultColorWindowPosition: TRect;
  135. procedure SetDefaultColorWindowPosition(value: TRect);
  136. function DefaultLayerWindowPosition: TRect;
  137. procedure SetDefaultLayerWindowPosition(value: TRect);
  138. function DefaultLayerStackZoom: single;
  139. procedure SetDefaultLayerStackZoom(value: single);
  140. function DefaultToolboxWindowPosition: TRect;
  141. procedure SetDefaultToolboxWindowPosition(value: TRect);
  142. function DefaultToolboxDocking: string;
  143. procedure SetDefaultToolboxDocking(value: string);
  144. function DefaultImageListPosition: TRect;
  145. procedure SetDefaultImagelistWindowPosition(value: TRect);
  146. function DefaultBrowseWindowMaximized: boolean;
  147. procedure SetDefaultBrowseWindowMaximized(value: boolean);
  148. function DefaultBrowseWindowPosition: TRect;
  149. procedure SetDefaultBrowseWindowPosition(value: TRect);
  150. function DefaultPreviewDialogMaximized: boolean;
  151. procedure SetDefaultPreviewDialogMaximized(value: boolean);
  152. function DefaultPreviewDialogPosition: TRect;
  153. procedure SetDefaultPreviewDialogPosition(value: TRect);
  154. function DefaultPaletteToolbarVisible: boolean;
  155. procedure SetDefaultPaletteToolbarVisible(value: boolean);
  156. function DefaultColorWindowVisible: boolean;
  157. procedure SetDefaultColorWindowVisible(value: boolean);
  158. function DefaultLayerWindowVisible: boolean;
  159. procedure SetDefaultLayerWindowVisible(value: boolean);
  160. function DefaultToolboxWindowVisible: boolean;
  161. procedure SetDefaultToolboxWindowVisible(value: boolean);
  162. function DefaultImagelistWindowVisible: boolean;
  163. procedure SetDefaultImagelistWindowVisible(value: boolean);
  164. function DefaultGridVisible: boolean;
  165. procedure SetDefaultGridVisible(value: boolean);
  166. function DefaultZoomToolbarVisible: boolean;
  167. procedure SetDefaultZoomToolbarVisible(value: boolean);
  168. function DefaultFileToolbarVisible: boolean;
  169. procedure SetDefaultFileToolbarVisible(value: boolean);
  170. function DefaultUndoRedoToolbarVisible: boolean;
  171. procedure SetDefaultUndoRedoToolbarVisible(value: boolean);
  172. function DefaultCopyPasteToolbarVisible: boolean;
  173. procedure SetDefaultCopyPasteToolbarVisible(value: boolean);
  174. function DefaultCoordinatesToolbarVisible: boolean;
  175. procedure SetDefaultCoordinatesToolbarVisible(value: boolean);
  176. function GetStatusBarVisible: boolean;
  177. procedure SetStatusBarVisible(value: boolean);
  178. function GetWorkspaceColor: TColor;
  179. procedure SetWorkspaceColor(value: TColor);
  180. function DefaultUseImageBrowser: boolean;
  181. procedure SetDefaultUseImageBrowser(value: boolean);
  182. //tools
  183. function DefaultToolForeColor: TBGRAPixel;
  184. function DefaultToolBackColor: TBGRAPixel;
  185. function DefaultToolOutlineColor: TBGRAPixel;
  186. procedure SetDefaultToolForeColor(value: TBGRAPixel);
  187. procedure SetDefaultToolBackColor(value: TBGRAPixel);
  188. procedure SetDefaultToolOutlineColor(value: TBGRAPixel);
  189. function DefaultToolForeGradient: string;
  190. function DefaultToolBackGradient: string;
  191. function DefaultToolOutlineGradient: string;
  192. procedure SetDefaultToolForeGradient(value: string);
  193. procedure SetDefaultToolBackGradient(value: string);
  194. procedure SetDefaultToolOutlineGradient(value: string);
  195. function DefaultToolPenWidth: single;
  196. procedure SetDefaultToolPenWidth(value: single);
  197. function DefaultToolEraserWidth: single;
  198. procedure SetDefaultToolEraserWidth(value: single);
  199. function DefaultToolOptionDrawShape: boolean;
  200. procedure SetDefaultToolOptionDrawShape(value: boolean);
  201. function DefaultToolOptionFillShape: boolean;
  202. procedure SetDefaultToolOptionFillShape(value: boolean);
  203. function DefaultToolOptionCloseShape: boolean;
  204. procedure SetDefaultToolOptionCloseShape(value: boolean);
  205. function DefaultToolTolerance: integer;
  206. procedure SetDefaultToolTolerance(value: integer);
  207. function DefaultToolTextOutline: boolean;
  208. procedure SetDefaultToolTextOutline(value: boolean);
  209. function DefaultToolTextOutlineWidth: single;
  210. procedure SetDefaultToolTextOutlineWidth(value: single);
  211. function DefaultToolTextShadow: boolean;
  212. procedure SetDefaultToolTextShadow(value: boolean);
  213. function DefaultToolTextFont: TFont;
  214. procedure SetDefaultToolTextFont(AName: string; ASize: single; AStyle: TFontStyles);
  215. function DefaultToolTextBlur: single;
  216. procedure SetDefaultToolTextBlur(value: single);
  217. function DefaultToolTextShadowOffsetX: integer;
  218. procedure SetDefaultToolTextShadowOffsetX(value: integer);
  219. function DefaultToolTextShadowOffsetY: integer;
  220. procedure SetDefaultToolTextShadowOffsetY(value: integer);
  221. procedure SetDefaultToolTextShadowOffset(value: TPoint);
  222. function DefaultToolTextShadowOffset: TPoint;
  223. function DefaultToolTextPhong: boolean;
  224. procedure SetDefaultToolTextPhong(value: boolean);
  225. function ToolPopupMessageShownCount(index: integer): integer;
  226. procedure SetToolPopupMessageShownCount(index: integer; AValue: integer);
  227. function DefaultToolLightPositionX: single;
  228. procedure SetDefaultToolLightPositionX(value: single);
  229. function DefaultToolLightPositionY: single;
  230. procedure SetDefaultToolLightPositionY(value: single);
  231. procedure SetDefaultToolLightPosition(const value: TPointF);
  232. function DefaultToolLightPosition: TPointF;
  233. function DefaultToolLightAltitude: integer;
  234. procedure SetDefaultToolLightAltitude(value: integer);
  235. function DefaultToolShapeAltitude: integer;
  236. procedure SetDefaultToolShapeAltitude(value: integer);
  237. function DefaultToolShapeBorderSize: integer;
  238. procedure SetDefaultToolShapeBorderSize(value: integer);
  239. function DefaultToolShapeType: TPhongShapeKind;
  240. procedure SetDefaultToolShapeType(value: TPhongShapeKind);
  241. function DefaultRetrieveSelectionAnswer: TModalResult;
  242. procedure SetDefaultRetrieveSelectionAnswer(value: TModalResult);
  243. function DefaultTransformSelectionAnswer: TModalResult;
  244. procedure SetDefaultTransformSelectionAnswer(value: TModalResult);
  245. //palette
  246. function DefaultColorsBoundToKeys: string;
  247. procedure SetDefaultColorsBoundToKeys(value: string);
  248. //radial blur config
  249. function DefaultBlurRadius: single;
  250. procedure SetDefaultBlurRadius(value: single);
  251. function DefaultPixelateSize: integer;
  252. procedure SetDefaultPixelateSize(value: integer);
  253. function DefaultPixelateQuality: string;
  254. procedure SetDefaultPixelateQuality(value: string);
  255. function DefaultSharpenAmount: single;
  256. procedure SetDefaultSharpenAmount(value: single);
  257. //motion blur config
  258. function DefaultBlurMotionAngle: double;
  259. function DefaultBlurMotionDistance: single;
  260. function DefaultBlurMotionOriented: boolean;
  261. procedure SetDefaultBlurMotionAngle(value: double);
  262. procedure SetDefaultBlurMotionDistance(value: single);
  263. procedure SetDefaultBlurMotionOriented(value: boolean);
  264. //custom blur config
  265. function DefaultCustomBlurMaskUTF8: string;
  266. procedure SetDefaultCustomBlurMaskUTF8(value: string);
  267. //emboss config
  268. function DefaultEmbossAngle: double;
  269. procedure SetDefaultEmbossAngle(value: double);
  270. //rain config
  271. function DefaultRainWind: double;
  272. procedure SetDefaultRainWind(value: double);
  273. function DefaultRainQuantity: double;
  274. procedure SetDefaultRainQuantity(value: double);
  275. function DefaultCuspCount: integer;
  276. procedure SetDefaultCuspCount(value: integer);
  277. function DefaultSuperformulaParameters: string;
  278. procedure SetDefaultSuperformulaParameters(value: string);
  279. //twirl config
  280. function DefaultTwirlRadius: double;
  281. procedure SetDefaultTwirlRadius(value: double);
  282. function DefaultTwirlTurn: double;
  283. procedure SetDefaultTwirlTurn(value: double);
  284. //wave displacement config
  285. function DefaultWaveDisplacementWavelength: double;
  286. procedure SetDefaultWaveDisplacementWavelength(value: double);
  287. function DefaultWaveDisplacementAmount: double;
  288. procedure SetDefaultWaveDisplacementAmount(value: double);
  289. function DefaultWaveDisplacementPhase: double;
  290. procedure SetDefaultWaveDisplacementPhase(value: double);
  291. //phong filter
  292. function DefaultPhongFilterAltitude: integer;
  293. procedure SetDefaultPhongFilterAltitude(value: integer);
  294. //color config
  295. function DefaultPosterizeLevels: integer;
  296. procedure SetDefaultPosterizeLevels(value: integer);
  297. function DefaultPosterizeByLightness: boolean;
  298. procedure SetDefaultPosterizeByLightness(value: boolean);
  299. function DefaultUseGSBA: boolean;
  300. procedure SetDefaultUseGSBA(value: boolean);
  301. property RecentFilesCount : integer read GetRecentFilesCount;
  302. property RecentFile[Index: Integer]: string read GetRecentFile;
  303. property RecentDirectoriesCount : integer read GetRecentDirectoriesCount;
  304. property RecentDirectory[Index: Integer]: string read GetRecentDirectory;
  305. property ColorizePresetCount: integer read GetColorizePresetCount;
  306. property ColorizePreset[Index: Integer]: TVariableSet read GetColorizePreset;
  307. property BrushCount: integer read GetBrushCount;
  308. property BrushInfo[Index: integer]: string read GetBrushInfo;
  309. //ImageList
  310. function ImageListLastFolder: string;
  311. procedure SetImageListLastFolder(value: string);
  312. function ImageListAutoZoom: Boolean;
  313. procedure SetImageListAutoZoom(value: Boolean);
  314. function ImageListAutoUncheck: Boolean;
  315. procedure SetImageListAutoUncheck(value: Boolean);
  316. function ImageListAutoUncheckMode: Integer;
  317. procedure SetImageListAutoUncheckMode(value: integer);
  318. end;
  319. function GetActualConfig: TIniFile;
  320. function DefaultPicturesDirectory: string;
  321. var
  322. ActualConfigDirUTF8 : string;
  323. MenuDefinitionKeys,MenuDefinitionValues: TStringList;
  324. implementation
  325. uses uparse, LCLProc, BGRAUTF8, LazFileUtils, UFileSystem, UDarkTheme;
  326. const maxRecentFiles = 10;
  327. maxRecentDirectories = 10;
  328. //returns the config file to use
  329. function GetActualConfig: TIniFile;
  330. var
  331. PortableConfig: TIniFile;
  332. AppDirSys: string;
  333. PortableConfigFilenameSys: string;
  334. ActualConfigFilenameSys: string;
  335. {$IFDEF DARWIN}
  336. ConfigPath: string;
  337. {$ENDIF}
  338. i: integer;
  339. begin
  340. ActualConfigFilenameSys := '';
  341. //check if a config file path is defined
  342. AppDirSys := ExtractFilePath(Application.ExeName);
  343. PortableConfigFilenameSys := AppDirSys+'lazpaint.ini';
  344. If FileExists(PortableConfigFilenameSys) then
  345. begin
  346. PortableConfig := TIniFile.Create(PortableConfigFilenameSys);
  347. ActualConfigFilenameSys:= PortableConfig.ReadString('General','ConfigFile','');
  348. if ActualConfigFilenameSys <> '' then
  349. ActualConfigFilenameSys:= ExpandFileName(AppDirSys+ActualConfigFilenameSys);
  350. MenuDefinitionKeys.Clear;
  351. MenuDefinitionValues.Clear;
  352. PortableConfig.ReadSection('Menu',MenuDefinitionKeys);
  353. for i := 0 to MenuDefinitionKeys.Count-1 do
  354. MenuDefinitionValues.Add(PortableConfig.ReadString('Menu',MenuDefinitionKeys[i],''));
  355. PortableConfig.Free;
  356. end;
  357. //otherwise, use default path
  358. if ActualConfigFilenameSys = '' then
  359. begin
  360. CreateDir(GetAppConfigDir(False));
  361. ActualConfigFilenameSys := GetAppConfigFile(False,False);
  362. end;
  363. {$IFDEF DARWIN}
  364. ConfigPath := ExtractFilePath(ActualConfigFilenameSys);
  365. CreateDir(ConfigPath);
  366. {$ENDIF}
  367. result := TIniFile.Create(ActualConfigFilenameSys,True);
  368. ActualConfigDirUTF8 := SysToUTF8(ExtractFilePath(ActualConfigFilenameSys));
  369. end;
  370. function DefaultPicturesDirectory: string;
  371. begin
  372. DefaultPicturesDirectory := SysToUTF8(GetUserDir);
  373. if DirectoryExistsUTF8(AppendPathDelim(DefaultPicturesDirectory)+'Pictures') then
  374. DefaultPicturesDirectory := AppendPathDelim(DefaultPicturesDirectory)+'Pictures';
  375. end;
  376. { TLazPaintConfig }
  377. function TLazPaintConfig.DefaultImageWidth: integer;
  378. begin
  379. result := iniOptions.ReadInteger('General','DefaultImageWidth',
  380. round(640 * ScreenInfo.PixelsPerInchX / 96));
  381. end;
  382. function TLazPaintConfig.DefaultImageHeight: integer;
  383. begin
  384. result := iniOptions.ReadInteger('General','DefaultImageHeight',
  385. round(480 * ScreenInfo.PixelsPerInchX / 96));
  386. end;
  387. procedure TLazPaintConfig.SetDefaultImageWidth(value: integer);
  388. begin
  389. iniOptions.WriteInteger('General','DefaultImageWidth',value);
  390. end;
  391. procedure TLazPaintConfig.SetDefaultImageHeight(value: integer);
  392. begin
  393. iniOptions.WriteInteger('General','DefaultImageHeight',value);
  394. end;
  395. procedure TLazPaintConfig.SetDefaultImageBackgroundColor(value: TBGRAPixel);
  396. begin
  397. iniOptions.WriteString('General','DefaultImageBackColor',BGRAToStr(value));
  398. end;
  399. function TLazPaintConfig.DefaultImageBackgroundColor: TBGRAPixel;
  400. begin
  401. result := StrToBGRA(iniOptions.ReadString('General','DefaultImageBackColor','00000000'));
  402. end;
  403. function TLazPaintConfig.DefaultIconImageWidth: integer;
  404. begin
  405. result := iniOptions.ReadInteger('General','DefaultIconImageWidth',128);
  406. end;
  407. function TLazPaintConfig.DefaultIconImageHeight: integer;
  408. begin
  409. result := iniOptions.ReadInteger('General','DefaultIconImageHeight',128);
  410. end;
  411. function TLazPaintConfig.DefaultIconImageBitDepth: integer;
  412. begin
  413. result := iniOptions.ReadInteger('General','DefaultIconImageBitDepth',32);
  414. end;
  415. procedure TLazPaintConfig.SetDefaultIconImageWidth(value: integer);
  416. begin
  417. iniOptions.WriteInteger('General','DefaultIconImageWidth',value);
  418. end;
  419. procedure TLazPaintConfig.SetDefaultIconImageHeight(value: integer);
  420. begin
  421. iniOptions.WriteInteger('General','DefaultIconImageHeight',value);
  422. end;
  423. procedure TLazPaintConfig.SetDefaultIconImageBitDepth(value: integer);
  424. begin
  425. iniOptions.WriteInteger('General','DefaultIconImageBitDepth',value);
  426. end;
  427. procedure TLazPaintConfig.SetDefaultIconImageBackgroundColor(value: TBGRAPixel);
  428. begin
  429. iniOptions.WriteString('General','DefaultIconImageBackColor',BGRAToStr(value));
  430. end;
  431. function TLazPaintConfig.DefaultIconImageBackgroundColor: TBGRAPixel;
  432. begin
  433. result := StrToBGRA(iniOptions.ReadString('General','DefaultIconImageBackColor','00000000'));
  434. end;
  435. function TLazPaintConfig.DefaultResampleKeepAspectRatio: boolean;
  436. begin
  437. result := iniOptions.ReadBool('General','ResampleKeepAspectRatio',true);
  438. end;
  439. function TLazPaintConfig.DefaultResampleQuality: integer;
  440. begin
  441. result := iniOptions.ReadInteger('General','ResampleQuality',2);
  442. end;
  443. procedure TLazPaintConfig.SetDefaultResampleKeepAspectRatio(value: boolean);
  444. begin
  445. iniOptions.WriteBool('General','ResampleKeepAspectRatio',value);
  446. end;
  447. procedure TLazPaintConfig.SetDefaultResampleQuality(value: integer);
  448. begin
  449. iniOptions.WriteInteger('General','ResampleQuality',value);
  450. end;
  451. function TLazPaintConfig.DefaultScreenSize: TRect;
  452. begin
  453. result := StrToRect(iniOptions.ReadString('Window','ScreenSize',''));
  454. end;
  455. function TLazPaintConfig.DefaultDockLayersAndColors: boolean;
  456. begin
  457. result := iniOptions.ReadBool('Window','DockLayersAndColors',true);
  458. end;
  459. procedure TLazPaintConfig.SetDefaultDockLayersAndColors(value: boolean);
  460. begin
  461. iniOptions.WriteBool('Window','DockLayersAndColors',value);
  462. end;
  463. function TLazPaintConfig.DefaultDockLayersAndColorsWidth: integer;
  464. begin
  465. result := iniOptions.ReadInteger('Window','DockLayersAndColorsWidth',0);
  466. end;
  467. procedure TLazPaintConfig.SetDefaultDockLayersAndColorsWidth(AValue: integer);
  468. begin
  469. iniOptions.WriteInteger('Window','DockLayersAndColorsWidth',AValue);
  470. end;
  471. procedure TLazPaintConfig.SetDefaultScreenSize(value: TRect);
  472. begin
  473. iniOptions.WriteString('Window','ScreenSize',RectToStr(value));
  474. end;
  475. function TLazPaintConfig.DefaultMainWindowMaximized: boolean;
  476. begin
  477. result := iniOptions.ReadBool('Window','MainWindowMaximized',false);
  478. end;
  479. procedure TLazPaintConfig.SetDefaultMainWindowMaximized(value: boolean);
  480. begin
  481. iniOptions.WriteBool('Window','MainWindowMaximized',value);
  482. end;
  483. function TLazPaintConfig.DefaultMainWindowPosition: TRect;
  484. begin
  485. result := StrToRect(iniOptions.ReadString('Window','MainWindowPosition',''));
  486. end;
  487. procedure TLazPaintConfig.SetDefaultMainWindowPosition(value: TRect);
  488. begin
  489. iniOptions.WriteString('Window','MainWindowPosition',RectToStr(value));
  490. SetDefaultMainWindowMaximized(False);
  491. end;
  492. function TLazPaintConfig.DefaultColorWindowPosition: TRect;
  493. begin
  494. result := StrToRect(iniOptions.ReadString('Window','ColorWindowPosition',''));
  495. end;
  496. procedure TLazPaintConfig.SetDefaultColorWindowPosition(value: TRect);
  497. begin
  498. iniOptions.WriteString('Window','ColorWindowPosition',RectToStr(value));
  499. end;
  500. function TLazPaintConfig.DefaultLayerWindowPosition: TRect;
  501. begin
  502. result := StrToRect(iniOptions.ReadString('Window','LayerWindowPosition',''));
  503. end;
  504. procedure TLazPaintConfig.SetDefaultLayerWindowPosition(value: TRect);
  505. begin
  506. iniOptions.WriteString('Window','LayerWindowPosition',RectToStr(value));
  507. end;
  508. function TLazPaintConfig.DefaultLayerStackZoom: single;
  509. begin
  510. result := iniOptions.ReadFloat('Window', 'LayerStackZoom', EmptySingle);
  511. end;
  512. procedure TLazPaintConfig.SetDefaultLayerStackZoom(value: single);
  513. begin
  514. iniOptions.WriteFloat('Window', 'LayerStackZoom', value);
  515. end;
  516. function TLazPaintConfig.DefaultToolboxWindowPosition: TRect;
  517. begin
  518. result := StrToRect(iniOptions.ReadString('Window','ToolboxWindowPosition',''));
  519. end;
  520. procedure TLazPaintConfig.SetDefaultToolboxWindowPosition(value: TRect);
  521. begin
  522. iniOptions.WriteString('Window','ToolboxWindowPosition',RectToStr(value));
  523. end;
  524. function TLazPaintConfig.DefaultToolboxDocking: string;
  525. begin
  526. result := iniOptions.ReadString('Window','ToolBoxDocking','Left');
  527. end;
  528. procedure TLazPaintConfig.SetDefaultToolboxDocking(value: string);
  529. begin
  530. iniOptions.WriteString('Window','ToolBoxDocking',value);
  531. end;
  532. function TLazPaintConfig.DefaultImageListPosition: TRect;
  533. begin
  534. result := StrToRect(iniOptions.ReadString('Window','ImagelistWindowPosition',''));
  535. end;
  536. procedure TLazPaintConfig.SetDefaultImagelistWindowPosition(value: TRect);
  537. begin
  538. iniOptions.WriteString('Window','ImagelistWindowPosition',RectToStr(value));
  539. end;
  540. function TLazPaintConfig.DefaultBrowseWindowMaximized: boolean;
  541. begin
  542. result := iniOptions.ReadBool('Window','BrowseWindowMaximized',false);
  543. end;
  544. procedure TLazPaintConfig.SetDefaultBrowseWindowMaximized(value: boolean);
  545. begin
  546. iniOptions.WriteBool('Window','BrowseWindowMaximized',value);
  547. end;
  548. function TLazPaintConfig.DefaultBrowseWindowPosition: TRect;
  549. begin
  550. result := StrToRect(iniOptions.ReadString('Window','BrowseWindowPosition',''));
  551. end;
  552. procedure TLazPaintConfig.SetDefaultBrowseWindowPosition(value: TRect);
  553. begin
  554. iniOptions.WriteString('Window','BrowseWindowPosition',RectToStr(value));
  555. end;
  556. function TLazPaintConfig.DefaultPreviewDialogMaximized: boolean;
  557. begin
  558. result := iniOptions.ReadBool('Window','PreviewDialogMaximized',false);
  559. end;
  560. procedure TLazPaintConfig.SetDefaultPreviewDialogMaximized(value: boolean);
  561. begin
  562. iniOptions.WriteBool('Window','PreviewDialogMaximized',value);
  563. end;
  564. function TLazPaintConfig.DefaultPreviewDialogPosition: TRect;
  565. begin
  566. result := StrToRect(iniOptions.ReadString('Window','PreviewDialogPosition',''));
  567. end;
  568. procedure TLazPaintConfig.SetDefaultPreviewDialogPosition(value: TRect);
  569. begin
  570. iniOptions.WriteString('Window','PreviewDialogPosition',RectToStr(value));
  571. end;
  572. function TLazPaintConfig.DefaultPaletteToolbarVisible: boolean;
  573. begin
  574. result := iniOptions.ReadBool('Toolbar','PaletteToolbar',true);
  575. end;
  576. procedure TLazPaintConfig.SetDefaultPaletteToolbarVisible(value: boolean);
  577. begin
  578. iniOptions.WriteBool('Toolbar','PaletteToolbar',value);
  579. end;
  580. function TLazPaintConfig.DefaultColorWindowVisible: boolean;
  581. begin
  582. result := iniOptions.ReadBool('Window','ColorWindowVisible',true);
  583. end;
  584. procedure TLazPaintConfig.SetDefaultColorWindowVisible(value: boolean);
  585. begin
  586. iniOptions.WriteBool('Window','ColorWindowVisible',value);
  587. end;
  588. function TLazPaintConfig.DefaultLayerWindowVisible: boolean;
  589. begin
  590. result := iniOptions.ReadBool('Window','LayerWindowVisible',true);
  591. end;
  592. procedure TLazPaintConfig.SetDefaultLayerWindowVisible(value: boolean);
  593. begin
  594. iniOptions.WriteBool('Window','LayerWindowVisible',value);
  595. end;
  596. function TLazPaintConfig.DefaultToolboxWindowVisible: boolean;
  597. begin
  598. result := iniOptions.ReadBool('Window','ToolboxWindowVisible',true);
  599. end;
  600. function TLazPaintConfig.DefaultImagelistWindowVisible: boolean;
  601. begin
  602. result := iniOptions.ReadBool('Window','ImagelistWindowVisible',false);
  603. end;
  604. procedure TLazPaintConfig.SetDefaultToolboxWindowVisible(value: boolean);
  605. begin
  606. iniOptions.WriteBool('Window','ToolboxWindowVisible',value);
  607. end;
  608. procedure TLazPaintConfig.SetDefaultImagelistWindowVisible(value: boolean);
  609. begin
  610. iniOptions.WriteBool('Window','ImagelistWindowVisible',value);
  611. end;
  612. function TLazPaintConfig.DefaultGridVisible: boolean;
  613. begin
  614. result := iniOptions.ReadBool('General','GridVisible',true);
  615. end;
  616. procedure TLazPaintConfig.SetDefaultGridVisible(value: boolean);
  617. begin
  618. iniOptions.WriteBool('General','GridVisible',value);
  619. end;
  620. function TLazPaintConfig.DefaultZoomToolbarVisible: boolean;
  621. begin
  622. result := iniOptions.ReadBool('Toolbar','ZoomToolbar',true);
  623. end;
  624. procedure TLazPaintConfig.SetDefaultZoomToolbarVisible(value: boolean);
  625. begin
  626. iniOptions.WriteBool('Toolbar','ZoomToolbar',value);
  627. end;
  628. function TLazPaintConfig.DefaultFileToolbarVisible: boolean;
  629. begin
  630. result := iniOptions.ReadBool('Toolbar','FileToolbar',true);
  631. end;
  632. procedure TLazPaintConfig.SetDefaultFileToolbarVisible(value: boolean);
  633. begin
  634. iniOptions.WriteBool('Toolbar','FileToolbar',value);
  635. end;
  636. function TLazPaintConfig.DefaultUndoRedoToolbarVisible: boolean;
  637. begin
  638. result := iniOptions.ReadBool('Toolbar','UndoRedoToolbar',true);
  639. end;
  640. procedure TLazPaintConfig.SetDefaultUndoRedoToolbarVisible(value: boolean);
  641. begin
  642. iniOptions.WriteBool('Toolbar','UndoRedoToolbar',value);
  643. end;
  644. function TLazPaintConfig.DefaultCopyPasteToolbarVisible: boolean;
  645. begin
  646. result := iniOptions.ReadBool('Toolbar','CopyPasteToolbar',false);
  647. end;
  648. procedure TLazPaintConfig.SetDefaultCopyPasteToolbarVisible(value: boolean);
  649. begin
  650. iniOptions.WriteBool('Toolbar','CopyPasteToolbar',value);
  651. end;
  652. function TLazPaintConfig.DefaultCoordinatesToolbarVisible: boolean;
  653. begin
  654. result := iniOptions.ReadBool('Toolbar','CoordinatesToolbar',true);
  655. end;
  656. procedure TLazPaintConfig.SetDefaultCoordinatesToolbarVisible(value: boolean);
  657. begin
  658. iniOptions.WriteBool('Toolbar','CoordinatesToolbar',value);
  659. end;
  660. function TLazPaintConfig.GetStatusBarVisible: boolean;
  661. begin
  662. result := iniOptions.ReadBool('Toolbar','StatusBar',true);
  663. end;
  664. procedure TLazPaintConfig.SetStatusBarVisible(value: boolean);
  665. begin
  666. iniOptions.WriteBool('Toolbar','StatusBar',value);
  667. end;
  668. function TLazPaintConfig.GetWorkspaceColor: TColor;
  669. begin
  670. if not FWorkspaceColorEvaluated then
  671. begin
  672. if GetDarkTheme then
  673. FWorkspaceColor := StrToBGRA(iniOptions.ReadString('General','DarkWorkspaceColor', '#2D3B49'), clAppWorkspace)
  674. else
  675. FWorkspaceColor := StrToBGRA(iniOptions.ReadString('General','WorkspaceColor', '#BBD1E8'), clAppWorkspace);
  676. FWorkspaceColorEvaluated := true;
  677. end;
  678. result := FWorkspaceColor;
  679. end;
  680. procedure TLazPaintConfig.SetWorkspaceColor(value: TColor);
  681. begin
  682. if GetDarkTheme then
  683. iniOptions.WriteString('General','DarkWorkspaceColor', BGRAToStr(value))
  684. else
  685. iniOptions.WriteString('General','WorkspaceColor', BGRAToStr(value));
  686. FWorkspaceColor:= value;
  687. FWorkspaceColorEvaluated:= true;
  688. end;
  689. function TLazPaintConfig.DefaultUseImageBrowser: boolean;
  690. begin
  691. result := iniOptions.ReadBool('General','UseImageBrowser',{$IFDEF DARWIN}false{$ELSE}true{$ENDIF});
  692. end;
  693. procedure TLazPaintConfig.SetDefaultUseImageBrowser(value: boolean);
  694. begin
  695. iniOptions.WriteBool('General','UseImageBrowser',value);
  696. end;
  697. function TLazPaintConfig.DefaultToolForeColor: TBGRAPixel;
  698. begin
  699. result := StrToBGRA(iniOptions.ReadString('Tool','ForeColor','000000FF'));
  700. end;
  701. function TLazPaintConfig.DefaultToolBackColor: TBGRAPixel;
  702. begin
  703. result := StrToBGRA(iniOptions.ReadString('Tool','BackColor','0080FFC0'));
  704. end;
  705. function TLazPaintConfig.DefaultToolOutlineColor: TBGRAPixel;
  706. begin
  707. result := StrToBGRA(iniOptions.ReadString('Tool','OutlineColor','FF0000C0'));
  708. end;
  709. procedure TLazPaintConfig.SetDefaultToolForeColor(value: TBGRAPixel);
  710. begin
  711. iniOptions.WriteString('Tool','ForeColor',BGRAToStr(value));
  712. end;
  713. procedure TLazPaintConfig.SetDefaultToolBackColor(value: TBGRAPixel);
  714. begin
  715. iniOptions.WriteString('Tool','BackColor',BGRAToStr(value));
  716. end;
  717. procedure TLazPaintConfig.SetDefaultToolOutlineColor(value: TBGRAPixel);
  718. begin
  719. iniOptions.WriteString('Tool','OutlineColor',BGRAToStr(value));
  720. end;
  721. function TLazPaintConfig.DefaultToolForeGradient: string;
  722. begin
  723. result := iniOptions.ReadString('Tool','ForeGradient','');
  724. end;
  725. function TLazPaintConfig.DefaultToolBackGradient: string;
  726. begin
  727. result := iniOptions.ReadString('Tool','BackGradient','');
  728. end;
  729. function TLazPaintConfig.DefaultToolOutlineGradient: string;
  730. begin
  731. result := iniOptions.ReadString('Tool','OutlineGradient','');
  732. end;
  733. procedure TLazPaintConfig.SetDefaultToolForeGradient(value: string);
  734. begin
  735. iniOptions.WriteString('Tool','ForeGradient',value);
  736. end;
  737. procedure TLazPaintConfig.SetDefaultToolBackGradient(value: string);
  738. begin
  739. iniOptions.WriteString('Tool','BackGradient',value);
  740. end;
  741. procedure TLazPaintConfig.SetDefaultToolOutlineGradient(value: string);
  742. begin
  743. iniOptions.WriteString('Tool','OutlineGradient',value);
  744. end;
  745. function TLazPaintConfig.DefaultToolPenWidth: single;
  746. begin
  747. result := iniOptions.ReadFloat('Tool','PenWidth',
  748. round(5 * ScreenInfo.PixelsPerInchX / 96));
  749. end;
  750. procedure TLazPaintConfig.SetDefaultToolPenWidth(value: single);
  751. begin
  752. iniOptions.WriteFloat('Tool','PenWidth',value);
  753. end;
  754. function TLazPaintConfig.DefaultToolEraserWidth: single;
  755. begin
  756. result := iniOptions.ReadFloat('Tool','EraserWidth',
  757. round(10 * ScreenInfo.PixelsPerInchX / 96));
  758. end;
  759. procedure TLazPaintConfig.SetDefaultToolEraserWidth(value: single);
  760. begin
  761. iniOptions.WriteFloat('Tool','EraserWidth',value);
  762. end;
  763. function TLazPaintConfig.DefaultToolOptionDrawShape: boolean;
  764. begin
  765. result := iniOptions.ReadBool('Tool','DrawShape',true);
  766. end;
  767. procedure TLazPaintConfig.SetDefaultToolOptionDrawShape(value: boolean);
  768. begin
  769. iniOptions.WriteBool('Tool','DrawShape',value);
  770. end;
  771. function TLazPaintConfig.DefaultToolOptionFillShape: boolean;
  772. begin
  773. result := iniOptions.ReadBool('Tool','FillShape',true);
  774. end;
  775. procedure TLazPaintConfig.SetDefaultToolOptionFillShape(value: boolean);
  776. begin
  777. iniOptions.WriteBool('Tool','FillShape',value);
  778. end;
  779. function TLazPaintConfig.DefaultToolOptionCloseShape: boolean;
  780. begin
  781. result := iniOptions.ReadBool('Tool','CloseShape',true);
  782. end;
  783. procedure TLazPaintConfig.SetDefaultToolOptionCloseShape(value: boolean);
  784. begin
  785. iniOptions.WriteBool('Tool','CloseShape',value);
  786. end;
  787. function TLazPaintConfig.DefaultToolTolerance: integer;
  788. begin
  789. result := iniOptions.ReadInteger('Tool','Tolerance',64);
  790. end;
  791. procedure TLazPaintConfig.SetDefaultToolTolerance(value: integer);
  792. begin
  793. iniOptions.WriteInteger('Tool','Tolerance',value);
  794. end;
  795. function TLazPaintConfig.DefaultToolTextOutline: boolean;
  796. begin
  797. result := iniOptions.ReadBool('Tool','TextOutline',false);
  798. end;
  799. procedure TLazPaintConfig.SetDefaultToolTextOutline(value: boolean);
  800. begin
  801. iniOptions.WriteBool('Tool','TextOutline',value);
  802. end;
  803. function TLazPaintConfig.DefaultToolTextOutlineWidth: single;
  804. begin
  805. result := iniOptions.ReadFloat('Tool','TextOutlineWidth',2);
  806. end;
  807. procedure TLazPaintConfig.SetDefaultToolTextOutlineWidth(value: single);
  808. begin
  809. iniOptions.WriteFloat('Tool','TextOutlineWidth',value);
  810. end;
  811. function TLazPaintConfig.DefaultToolTextShadow: boolean;
  812. begin
  813. result := iniOptions.ReadBool('Tool','TextShadow',false);
  814. end;
  815. procedure TLazPaintConfig.SetDefaultToolTextShadow(value: boolean);
  816. begin
  817. iniOptions.WriteBool('Tool','TextShadow',value);
  818. end;
  819. function TLazPaintConfig.DefaultToolTextFont: TFont;
  820. var fontStyle: TFontStyles;
  821. begin
  822. tempFont.Name := iniOptions.ReadString('Tool','TextFontName','');
  823. tempFont.Size := iniOptions.ReadInteger('Tool','TextFontSize',10);
  824. fontStyle := [];
  825. if iniOptions.ReadBool('Tool','TextFontBold',False) then fontStyle += [fsBold];
  826. if iniOptions.ReadBool('Tool','TextFontItalic',False) then fontStyle += [fsItalic];
  827. if iniOptions.ReadBool('Tool','TextFontStrikeOut',False) then fontStyle += [fsStrikeOut];
  828. if iniOptions.ReadBool('Tool','TextFontUnderline',False) then fontStyle += [fsUnderline];
  829. tempFont.Style := fontStyle;
  830. result := tempFont;
  831. end;
  832. procedure TLazPaintConfig.SetDefaultToolTextFont(AName: string; ASize: single;
  833. AStyle: TFontStyles);
  834. begin
  835. iniOptions.WriteString('Tool','TextFontName',AName);
  836. iniOptions.WriteInteger('Tool','TextFontSize',round(ASize));
  837. iniOptions.DeleteKey('Tool','TextFontHeight');
  838. iniOptions.WriteBool('Tool','TextFontBold',fsBold in AStyle);
  839. iniOptions.WriteBool('Tool','TextFontItalic',fsItalic in AStyle);
  840. iniOptions.WriteBool('Tool','TextFontStrikeOut',fsStrikeOut in AStyle);
  841. iniOptions.WriteBool('Tool','TextFontUnderline',fsUnderline in AStyle);
  842. end;
  843. function TLazPaintConfig.DefaultToolTextBlur: single;
  844. begin
  845. result := iniOptions.ReadFloat('Tool','TextBlur',4);
  846. end;
  847. procedure TLazPaintConfig.SetDefaultToolTextBlur(value: single);
  848. begin
  849. iniOptions.WriteFloat('Tool','TextBlur',value);
  850. end;
  851. function TLazPaintConfig.DefaultToolTextShadowOffsetX: integer;
  852. begin
  853. result := iniOptions.ReadInteger('Tool','TextShadowX',5);
  854. end;
  855. procedure TLazPaintConfig.SetDefaultToolTextShadowOffsetX(value: integer);
  856. begin
  857. iniOptions.WriteInteger('Tool','TextShadowX',value);
  858. end;
  859. function TLazPaintConfig.DefaultToolTextShadowOffsetY: integer;
  860. begin
  861. result := iniOptions.ReadInteger('Tool','TextShadowY',5);
  862. end;
  863. procedure TLazPaintConfig.SetDefaultToolTextShadowOffsetY(value: integer);
  864. begin
  865. iniOptions.WriteInteger('Tool','TextShadowY',value);
  866. end;
  867. procedure TLazPaintConfig.SetDefaultToolTextShadowOffset(value: TPoint);
  868. begin
  869. SetDefaultToolTextShadowOffsetX(value.X);
  870. SetDefaultToolTextShadowOffsetY(value.Y);
  871. end;
  872. function TLazPaintConfig.DefaultToolTextShadowOffset: TPoint;
  873. begin
  874. result := Point(DefaultToolTextShadowOffsetX,DefaultToolTextShadowOffsetY);
  875. end;
  876. function TLazPaintConfig.DefaultToolTextPhong: boolean;
  877. begin
  878. result := iniOptions.ReadBool('Tool','TextPhong',false);
  879. end;
  880. procedure TLazPaintConfig.SetDefaultToolTextPhong(value: boolean);
  881. begin
  882. iniOptions.WriteBool('Tool','TextPhong',value);
  883. end;
  884. function TLazPaintConfig.ToolPopupMessageShownCount(index: integer): integer;
  885. begin
  886. result := iniOptions.ReadInteger('Popup','ToolPopupMessage' + inttostr(index),0);
  887. end;
  888. procedure TLazPaintConfig.SetToolPopupMessageShownCount(index: integer;
  889. AValue: integer);
  890. begin
  891. iniOptions.WriteInteger('Popup','ToolPopupMessage' + inttostr(index), avalue);
  892. end;
  893. function TLazPaintConfig.DefaultToolLightPositionX: single;
  894. begin
  895. result := iniOptions.ReadFloat('Tool','LightPositionX',0);
  896. end;
  897. procedure TLazPaintConfig.SetDefaultToolLightPositionX(value: single);
  898. begin
  899. iniOptions.WriteFloat('Tool','LightPositionX',value);
  900. end;
  901. function TLazPaintConfig.DefaultToolLightPositionY: single;
  902. begin
  903. result := iniOptions.ReadFloat('Tool','LightPositionY',0);
  904. end;
  905. procedure TLazPaintConfig.SetDefaultToolLightPositionY(value: single);
  906. begin
  907. iniOptions.WriteFloat('Tool','LightPositionY',value);
  908. end;
  909. procedure TLazPaintConfig.SetDefaultToolLightPosition(const value: TPointF);
  910. begin
  911. SetDefaultToolLightPositionX(value.X);
  912. SetDefaultToolLightPositionY(value.Y);
  913. end;
  914. function TLazPaintConfig.DefaultToolLightPosition: TPointF;
  915. begin
  916. result := PointF(DefaultToolLightPositionX,DefaultToolLightPositionY);
  917. end;
  918. function TLazPaintConfig.DefaultToolLightAltitude: integer;
  919. begin
  920. result := iniOptions.ReadInteger('Filter','LightPositionZ',100);
  921. end;
  922. procedure TLazPaintConfig.SetDefaultToolLightAltitude(value: integer);
  923. begin
  924. iniOptions.WriteInteger('Filter','LightPositionZ',value);
  925. end;
  926. function TLazPaintConfig.DefaultToolShapeAltitude: integer;
  927. begin
  928. result := iniOptions.ReadInteger('Filter','ShapeAltitude',50);
  929. end;
  930. procedure TLazPaintConfig.SetDefaultToolShapeAltitude(value: integer);
  931. begin
  932. iniOptions.WriteInteger('Filter','ShapeAltitude',value);
  933. end;
  934. function TLazPaintConfig.DefaultToolShapeBorderSize: integer;
  935. begin
  936. result := iniOptions.ReadInteger('Filter','ShapeBorderSize',20);
  937. end;
  938. procedure TLazPaintConfig.SetDefaultToolShapeBorderSize(value: integer);
  939. begin
  940. iniOptions.WriteInteger('Filter','ShapeBorderSize',value);
  941. end;
  942. function TLazPaintConfig.DefaultToolShapeType: TPhongShapeKind;
  943. var
  944. str: String;
  945. begin
  946. str := iniOptions.ReadString('Filter','ShapeType','Rectangle');
  947. if str = 'RoundRectangle' then result := pskRoundRectangle else
  948. if str = 'Sphere' then result := pskHalfSphere else
  949. if str = 'Cone' then result := pskConeTop else
  950. if str = 'VerticalCone' then result := pskConeSide else
  951. if str = 'VerticalCylinder' then result := pskVertCylinder else
  952. if str = 'HorizontalCylinder' then result := pskHorizCylinder
  953. else result := pskRectangle;
  954. end;
  955. procedure TLazPaintConfig.SetDefaultToolShapeType(value: TPhongShapeKind);
  956. var
  957. str: String;
  958. begin
  959. case value of
  960. pskRoundRectangle: str := 'RoundRectangle';
  961. pskHalfSphere: str := 'Sphere';
  962. pskConeTop: str := 'Cone';
  963. pskConeSide: str := 'VerticalCone';
  964. pskVertCylinder: str := 'VerticalCylinder';
  965. pskHorizCylinder: str := 'HorizontalCylinder';
  966. else str:= 'Rectangle'
  967. end;
  968. iniOptions.WriteString('Filter','ShapeType',str);
  969. end;
  970. function TLazPaintConfig.DefaultRetrieveSelectionAnswer: TModalResult;
  971. begin
  972. result := iniOptions.ReadInteger('Tool','RetrieveSelectionAnswer', 0);
  973. end;
  974. procedure TLazPaintConfig.SetDefaultRetrieveSelectionAnswer(value: TModalResult);
  975. begin
  976. iniOptions.WriteInteger('Tool','RetrieveSelectionAnswer', value);
  977. end;
  978. function TLazPaintConfig.DefaultTransformSelectionAnswer: TModalResult;
  979. begin
  980. result := iniOptions.ReadInteger('Tool','TransformSelectionAnswer', 0);
  981. end;
  982. procedure TLazPaintConfig.SetDefaultTransformSelectionAnswer(value: TModalResult);
  983. begin
  984. iniOptions.WriteInteger('Tool','TransformSelectionAnswer', value);
  985. end;
  986. function TLazPaintConfig.DefaultColorsBoundToKeys: string;
  987. begin
  988. result := iniOptions.ReadString('Palette','ColorsBoundToKeys','');
  989. end;
  990. procedure TLazPaintConfig.SetDefaultColorsBoundToKeys(value: string);
  991. begin
  992. iniOptions.WriteString('Palette','ColorsBoundToKeys',value);
  993. end;
  994. function TLazPaintConfig.DefaultBlurRadius: single;
  995. begin
  996. result := iniOptions.ReadFloat('Filter','BlurRadius',5);
  997. end;
  998. procedure TLazPaintConfig.SetDefaultBlurRadius(value: single);
  999. begin
  1000. iniOptions.WriteFloat('Filter','BlurRadius',value);
  1001. end;
  1002. function TLazPaintConfig.DefaultPixelateSize: integer;
  1003. begin
  1004. result := iniOptions.ReadInteger('Filter','PixelateSize',5);
  1005. end;
  1006. procedure TLazPaintConfig.SetDefaultPixelateSize(value: integer);
  1007. begin
  1008. iniOptions.WriteInteger('Filter','PixelateSize',value);
  1009. end;
  1010. function TLazPaintConfig.DefaultPixelateQuality: string;
  1011. begin
  1012. result := iniOptions.ReadString('Filter','PixelateQuality','Linear');
  1013. end;
  1014. procedure TLazPaintConfig.SetDefaultPixelateQuality(value: string);
  1015. begin
  1016. iniOptions.WriteString('Filter','PixelateQuality',value);
  1017. end;
  1018. function TLazPaintConfig.DefaultSharpenAmount: single;
  1019. begin
  1020. result := iniOptions.ReadFloat('Filter','SharpenAmount',1);
  1021. end;
  1022. procedure TLazPaintConfig.SetDefaultSharpenAmount(value: single);
  1023. begin
  1024. iniOptions.WriteFloat('Filter','SharpenAmount',value);
  1025. end;
  1026. function TLazPaintConfig.DefaultBlurMotionAngle: double;
  1027. begin
  1028. result := iniOptions.ReadFloat('Filter','MotionBlurAngle',0);
  1029. end;
  1030. function TLazPaintConfig.DefaultBlurMotionDistance: single;
  1031. begin
  1032. result := iniOptions.ReadFloat('Filter','MotionBlurDistance',5);
  1033. end;
  1034. function TLazPaintConfig.DefaultBlurMotionOriented: boolean;
  1035. begin
  1036. result := iniOptions.ReadBool('Filter','MotionBlurOriented',true);
  1037. end;
  1038. procedure TLazPaintConfig.SetDefaultBlurMotionAngle(value: double);
  1039. begin
  1040. iniOptions.WriteFloat('Filter','MotionBlurAngle',value);
  1041. end;
  1042. procedure TLazPaintConfig.SetDefaultBlurMotionDistance(value: single);
  1043. begin
  1044. iniOptions.WriteFloat('Filter','MotionBlurDistance',value);
  1045. end;
  1046. procedure TLazPaintConfig.SetDefaultBlurMotionOriented(value: boolean);
  1047. begin
  1048. iniOptions.WriteBool('Filter','MotionBlurOriented',value);
  1049. end;
  1050. function TLazPaintConfig.DefaultCustomBlurMaskUTF8: string;
  1051. begin
  1052. result := iniOptions.ReadString('Filter','CustomBlurMask','');
  1053. end;
  1054. procedure TLazPaintConfig.SetDefaultCustomBlurMaskUTF8(value: string);
  1055. begin
  1056. iniOptions.WriteString('Filter','CustomBlurMask',value);
  1057. end;
  1058. function TLazPaintConfig.DefaultEmbossAngle: double;
  1059. begin
  1060. result := iniOptions.ReadFloat('Filter','EmbossAngle',45);
  1061. end;
  1062. procedure TLazPaintConfig.SetDefaultEmbossAngle(value: double);
  1063. begin
  1064. iniOptions.WriteFloat('Filter','EmbossAngle',value);
  1065. end;
  1066. function TLazPaintConfig.DefaultRainWind: double;
  1067. begin
  1068. result := iniOptions.ReadFloat('Filter','RainWind',-0.5);
  1069. end;
  1070. procedure TLazPaintConfig.SetDefaultRainWind(value: double);
  1071. begin
  1072. iniOptions.WriteFloat('Filter','RainWind',value);
  1073. end;
  1074. function TLazPaintConfig.DefaultRainQuantity: double;
  1075. begin
  1076. result := iniOptions.ReadFloat('Filter','RainQuantity',0.5);
  1077. end;
  1078. procedure TLazPaintConfig.SetDefaultRainQuantity(value: double);
  1079. begin
  1080. iniOptions.WriteFloat('Filter','RainQuantity',value);
  1081. end;
  1082. function TLazPaintConfig.DefaultCuspCount: integer;
  1083. begin
  1084. result := iniOptions.ReadInteger('Filter','CuspCount',6);
  1085. end;
  1086. procedure TLazPaintConfig.SetDefaultCuspCount(value: integer);
  1087. begin
  1088. iniOptions.WriteInteger('Filter','CuspCount',value);
  1089. end;
  1090. function TLazPaintConfig.DefaultSuperformulaParameters: string;
  1091. begin
  1092. result := iniOptions.ReadString('Filter','SuperformulaParameters','');
  1093. end;
  1094. procedure TLazPaintConfig.SetDefaultSuperformulaParameters(value: string);
  1095. begin
  1096. iniOptions.WriteString('Filter','SuperformulaParameters',value);
  1097. end;
  1098. function TLazPaintConfig.DefaultTwirlRadius: double;
  1099. begin
  1100. result := iniOptions.ReadFloat('Filter','TwirlRadius',100);
  1101. end;
  1102. procedure TLazPaintConfig.SetDefaultTwirlRadius(value: double);
  1103. begin
  1104. iniOptions.WriteFloat('Filter','TwirlRadius',value);
  1105. end;
  1106. function TLazPaintConfig.DefaultTwirlTurn: double;
  1107. begin
  1108. result := iniOptions.ReadFloat('Filter','TwirlTurn',1);
  1109. end;
  1110. procedure TLazPaintConfig.SetDefaultTwirlTurn(value: double);
  1111. begin
  1112. iniOptions.WriteFloat('Filter','TwirlTurn',value);
  1113. end;
  1114. function TLazPaintConfig.DefaultWaveDisplacementWavelength: double;
  1115. begin
  1116. result := iniOptions.ReadFloat('Filter','WaveDisplacementWavelength',100);
  1117. end;
  1118. procedure TLazPaintConfig.SetDefaultWaveDisplacementWavelength(value: double);
  1119. begin
  1120. iniOptions.WriteFloat('Filter','WaveDisplacementWavelength',value);
  1121. end;
  1122. function TLazPaintConfig.DefaultWaveDisplacementAmount: double;
  1123. begin
  1124. result := iniOptions.ReadFloat('Filter','WaveDisplacementAmount',50);
  1125. end;
  1126. procedure TLazPaintConfig.SetDefaultWaveDisplacementAmount(value: double);
  1127. begin
  1128. iniOptions.WriteFloat('Filter','WaveDisplacementAmount',value);
  1129. end;
  1130. function TLazPaintConfig.DefaultWaveDisplacementPhase: double;
  1131. begin
  1132. result := iniOptions.ReadFloat('Filter','WaveDisplacementPhase',0);
  1133. end;
  1134. procedure TLazPaintConfig.SetDefaultWaveDisplacementPhase(value: double);
  1135. begin
  1136. iniOptions.WriteFloat('Filter','WaveDisplacementPhase',value);
  1137. end;
  1138. function TLazPaintConfig.DefaultPhongFilterAltitude: integer;
  1139. begin
  1140. result := iniOptions.ReadInteger('Filter','MapAltitude',10);
  1141. end;
  1142. procedure TLazPaintConfig.SetDefaultPhongFilterAltitude(value: integer);
  1143. begin
  1144. iniOptions.WriteInteger('Filter','MapAltitude',value);
  1145. end;
  1146. function TLazPaintConfig.DefaultPosterizeLevels: integer;
  1147. begin
  1148. result := iniOptions.ReadInteger('Filter','PosterizeLevels',4);
  1149. end;
  1150. procedure TLazPaintConfig.SetDefaultPosterizeLevels(value: integer);
  1151. begin
  1152. iniOptions.WriteInteger('Filter','PosterizeLevels',value);
  1153. end;
  1154. function TLazPaintConfig.DefaultPosterizeByLightness: boolean;
  1155. begin
  1156. result := iniOptions.ReadBool('Filter','PosterizeByLightness',True);
  1157. end;
  1158. procedure TLazPaintConfig.SetDefaultPosterizeByLightness(value: boolean);
  1159. begin
  1160. iniOptions.WriteBool('Filter','PosterizeByLightness',value);
  1161. end;
  1162. function TLazPaintConfig.DefaultUseGSBA: boolean;
  1163. begin
  1164. result := iniOptions.ReadBool('Filter','UseGSBA',True);
  1165. end;
  1166. procedure TLazPaintConfig.SetDefaultUseGSBA(value: boolean);
  1167. begin
  1168. iniOptions.WriteBool('Filter','UseGSBA',value);
  1169. end;
  1170. procedure TLazPaintConfig.InitRecentFiles;
  1171. var i: integer;
  1172. begin
  1173. recentFiles := TStringList.Create;
  1174. iniOptions.ReadSection('RecentFiles',recentFiles);
  1175. for i := 0 to recentFiles.Count-1 do
  1176. recentFiles[i] := iniOptions.ReadString('RecentFiles',recentFiles[i],'');
  1177. for i := recentFiles.Count-1 downto 0 do
  1178. if not FileManager.FileExists(recentFiles[i]) then recentFiles.Delete(i);
  1179. recentDirs := TStringList.Create;
  1180. iniOptions.ReadSection('RecentDirectories',recentDirs);
  1181. for i := 0 to recentDirs.Count-1 do
  1182. recentDirs[i] := iniOptions.ReadString('RecentDirectories',recentDirs[i],'');
  1183. for i := recentDirs.Count-1 downto 0 do
  1184. if not FileManager.IsDirectory(recentDirs[i]) then recentDirs.Delete(i);
  1185. end;
  1186. procedure TLazPaintConfig.FinalizeRecentFiles;
  1187. var i: integer;
  1188. begin
  1189. iniOptions.EraseSection('RecentFiles');
  1190. for i := 0 to recentFiles.Count-1 do
  1191. iniOptions.WriteString('RecentFiles','File'+inttostr(I+1),recentFiles[i]);
  1192. recentFiles.Free;
  1193. iniOptions.EraseSection('RecentDirectories');
  1194. for i := 0 to recentDirs.Count-1 do
  1195. iniOptions.WriteString('RecentDirectories','Dir'+inttostr(I+1),recentDirs[i]);
  1196. recentDirs.Free;
  1197. end;
  1198. function TLazPaintConfig.DefaultRememberStartupTargetDirectory: boolean;
  1199. begin
  1200. result := iniOptions.ReadBool('Startup', 'RememberTargetDirectory', false);
  1201. end;
  1202. procedure TLazPaintConfig.SetRememberStartupTargetDirectory(AValue: boolean);
  1203. begin
  1204. iniOptions.WriteBool('Startup', 'RememberTargetDirectory', AValue);
  1205. end;
  1206. function TLazPaintConfig.DefaultRememberStartupExportDirectory: boolean;
  1207. begin
  1208. result := iniOptions.ReadBool('Startup', 'RememberExportDirectory', false);
  1209. end;
  1210. procedure TLazPaintConfig.SetRememberStartupExportDirectory(AValue: boolean);
  1211. begin
  1212. iniOptions.WriteBool('Startup', 'RememberExportDirectory', AValue);
  1213. end;
  1214. function TLazPaintConfig.DefaultRememberStartupSourceDirectory: boolean;
  1215. begin
  1216. result := iniOptions.ReadBool('Startup', 'RememberSourceDirectory', false);
  1217. end;
  1218. procedure TLazPaintConfig.SetRememberStartupSourceDirectory(AValue: boolean);
  1219. begin
  1220. iniOptions.WriteBool('Startup', 'RememberSourceDirectory', AValue);
  1221. end;
  1222. function TLazPaintConfig.DefaultStartupSourceDirectory: string;
  1223. begin
  1224. result := iniOptions.ReadString('Startup', 'SourceDirectory', '');
  1225. end;
  1226. procedure TLazPaintConfig.SetStartupSourceDirectory(AValue: string);
  1227. begin
  1228. iniOptions.WriteString('Startup', 'SourceDirectory', AValue);
  1229. end;
  1230. function TLazPaintConfig.DefaultStartupTargetDirectory: string;
  1231. begin
  1232. result := iniOptions.ReadString('Startup', 'TargetDirectory', '');
  1233. end;
  1234. procedure TLazPaintConfig.SetStartupTargetDirectory(AValue: string);
  1235. begin
  1236. iniOptions.WriteString('Startup', 'TargetDirectory', AValue);
  1237. end;
  1238. function TLazPaintConfig.DefaultStartupExportDirectory: string;
  1239. begin
  1240. result := iniOptions.ReadString('Startup', 'ExportDirectory', '');
  1241. end;
  1242. procedure TLazPaintConfig.SetStartupExportDirectory(AValue: string);
  1243. begin
  1244. iniOptions.WriteString('Startup', 'ExportDirectory', AValue);
  1245. end;
  1246. function TLazPaintConfig.DefaultRememberSaveFormat: boolean;
  1247. begin
  1248. result := iniOptions.ReadBool('Startup', 'RememberSaveFormat', false);
  1249. end;
  1250. procedure TLazPaintConfig.SetRememberSaveFormat(AValue: boolean);
  1251. begin
  1252. iniOptions.WriteBool('Startup', 'RememberSaveFormat', AValue);
  1253. end;
  1254. function TLazPaintConfig.DefaultSaveExtensions: string;
  1255. begin
  1256. result := iniOptions.ReadString('Startup', 'SaveExtensions', '');
  1257. end;
  1258. procedure TLazPaintConfig.SetSaveExtensions(AValue: string);
  1259. begin
  1260. iniOptions.WriteString('Startup', 'SaveExtensions', AValue);
  1261. end;
  1262. procedure TLazPaintConfig.SetBrushes(ABrushes: TStringList);
  1263. var
  1264. i: Integer;
  1265. begin
  1266. iniOptions.EraseSection('Brushes');
  1267. iniOptions.WriteInteger('Brushes','Count',ABrushes.Count);
  1268. for i := 0 to ABrushes.Count-1 do
  1269. iniOptions.WriteString('Brushes','Brush'+inttostr(I+1),ABrushes[i]);
  1270. end;
  1271. function TLazPaintConfig.DefaultJpegQuality: integer;
  1272. begin
  1273. result := iniOptions.ReadInteger('General','JpegQuality',100);
  1274. end;
  1275. procedure TLazPaintConfig.SetDefaultJpegQuality(value: integer);
  1276. begin
  1277. iniOptions.WriteInteger('General','JpegQuality',value);
  1278. end;
  1279. function TLazPaintConfig.DefaultWebPLossless: boolean;
  1280. begin
  1281. result := iniOptions.ReadBool('General','WebPLossless',true);
  1282. end;
  1283. procedure TLazPaintConfig.SetDefaultWebPLossless(value: boolean);
  1284. begin
  1285. iniOptions.WriteBool('General','WebPLossless',value);
  1286. end;
  1287. function TLazPaintConfig.DefaultSaveOptionDialogMaximized: boolean;
  1288. begin
  1289. result := iniOptions.ReadBool('Window','SaveOptionDialogMaximized',false);
  1290. end;
  1291. procedure TLazPaintConfig.SetDefaultSaveOptionDialogMaximized(value: boolean);
  1292. begin
  1293. iniOptions.WriteBool('Window','SaveOptionDialogMaximized',value);
  1294. end;
  1295. procedure TLazPaintConfig.InitColorizePresets;
  1296. var presetsStr: TStringList;
  1297. i: integer;
  1298. begin
  1299. presetsStr := TStringList.Create;
  1300. iniOptions.ReadSection('Colorize',presetsStr);
  1301. colorizePresets := TList.Create;
  1302. for i := 0 to presetsStr.Count-1 do
  1303. begin
  1304. AddColorizePreset(TVariableSet.Create('ColorColorize',iniOptions.ReadString('Colorize',presetsStr[i],'')));
  1305. end;
  1306. presetsStr.free;
  1307. if ColorizePresetCount = 0 then
  1308. begin
  1309. AddColorizePreset('Antartic',211,0.660,True);
  1310. AddColorizePreset('Mars',16.5,0.902,True);
  1311. AddColorizePreset('Purple',291,0.634,False);
  1312. AddColorizePreset('Sepia',31.0,0.119,False);
  1313. end;
  1314. end;
  1315. function TLazPaintConfig.AddColorizePreset(AName: string; AHue,
  1316. ASaturation: double; ACorrection: Boolean): integer;
  1317. var
  1318. params: TVariableSet;
  1319. begin
  1320. params := TVariableSet.Create('ColorColorize');
  1321. params.AddString('Name',AName);
  1322. params.AddFloat('Hue', AHue);
  1323. params.AddFloat('Saturation',ASaturation);
  1324. params.AddBoolean('Correction',ACorrection);
  1325. result := AddColorizePreset(params);
  1326. end;
  1327. function TLazPaintConfig.AddColorizePreset(AParams: TVariableSet): integer;
  1328. var i: integer;
  1329. s: string;
  1330. begin
  1331. s := AParams.Strings['Name'];
  1332. for i := ColorizePresetCount-1 downto 0 do
  1333. if CompareText(colorizePreset[i].Strings['Name'],s) = 0 then
  1334. RemoveColorizePreset(i);
  1335. result := colorizePresets.Add(AParams);
  1336. end;
  1337. procedure TLazPaintConfig.RemoveColorizePreset(AIndex: integer);
  1338. begin
  1339. if (AIndex >= 0) and (AIndex < ColorizePresetCount) then
  1340. begin
  1341. ColorizePreset[AIndex].Free;
  1342. colorizePresets.Delete(AIndex);
  1343. end;
  1344. end;
  1345. function TLazPaintConfig.IndexOfColorizePreset(AName: string): integer;
  1346. var i: integer;
  1347. begin
  1348. for i := ColorizePresetCount-1 downto 0 do
  1349. if CompareText(colorizePreset[i].Strings['Name'],AName) = 0 then
  1350. begin
  1351. result := i;
  1352. exit;
  1353. end;
  1354. result := -1;
  1355. end;
  1356. procedure TLazPaintConfig.FinalizeColorizePresets;
  1357. var i: integer;
  1358. begin
  1359. iniOptions.EraseSection('Colorize');
  1360. for i := 0 to ColorizePresetCount-1 do
  1361. iniOptions.WriteString('Colorize','Preset'+inttostr(I+1),ColorizePreset[i].VariablesAsString);
  1362. for i := 0 to ColorizePresetCount-1 do
  1363. ColorizePreset[i].Free;
  1364. colorizePresets.Free;
  1365. end;
  1366. function TLazPaintConfig.DefaultLangage: string;
  1367. begin
  1368. result := ClassGetDefaultLangage(iniOptions);
  1369. end;
  1370. class function TLazPaintConfig.ClassGetDefaultLangage(AIni: TIniFile): string;
  1371. begin
  1372. result := AIni.ReadString('General','Language','');
  1373. if result = '' then result := 'auto';
  1374. end;
  1375. procedure TLazPaintConfig.SetDefaultLangage(value: string);
  1376. begin
  1377. if value = 'auto' then value := '';
  1378. iniOptions.WriteString('General','Language',value);
  1379. end;
  1380. function TLazPaintConfig.GetLastUpdateCheck: TDateTime;
  1381. begin
  1382. result := iniOptions.ReadInt64('General','LastUpdateCheck',0);
  1383. end;
  1384. procedure TLazPaintConfig.SetLastUpdateCheck(value: TDateTime);
  1385. begin
  1386. iniOptions.WriteInt64('General','LastUpdateCheck',round(value));
  1387. end;
  1388. function TLazPaintConfig.LatestVersion: string;
  1389. begin
  1390. result := iniOptions.ReadString('General','LatestOnlineVersion','');
  1391. end;
  1392. procedure TLazPaintConfig.SetLatestVersion(value: string);
  1393. begin
  1394. iniOptions.WriteString('General','LatestOnlineVersion',value);
  1395. end;
  1396. procedure TLazPaintConfig.GetUpdatedLanguages(AList: TStringList);
  1397. begin
  1398. ClassGetUpdatedLanguages(AList,iniOptions,FVersion);
  1399. end;
  1400. procedure TLazPaintConfig.SetUpdatedLanguages(AList: TStringList);
  1401. begin
  1402. ClassSetUpdatedLanguages(AList,iniOptions,FVersion);
  1403. end;
  1404. class procedure TLazPaintConfig.ClassGetUpdatedLanguages(AList: TStringList;
  1405. AIni: TIniFile; AVersion: string);
  1406. begin
  1407. AList.CommaText := AIni.ReadString('General','UpdatedLanguages'+AVersion,'');
  1408. end;
  1409. class procedure TLazPaintConfig.ClassSetUpdatedLanguages(AList: TStringList;
  1410. AIni: TIniFile; AVersion: string);
  1411. begin
  1412. AIni.WriteString('General','UpdatedLanguages'+AVersion,AList.CommaText)
  1413. end;
  1414. procedure TLazPaintConfig.AddUpdatedLanguage(ALang: string);
  1415. var list: TStringList;
  1416. begin
  1417. list := TStringList.Create;
  1418. GetUpdatedLanguages(list);
  1419. if list.IndexOf(ALang)=-1 then
  1420. begin
  1421. list.Add(ALang);
  1422. SetUpdatedLanguages(list);
  1423. end;
  1424. list.Free;
  1425. end;
  1426. function TLazPaintConfig.Default3dObjectDirectory: string;
  1427. begin
  1428. result := iniOptions.ReadString('General','3dObjectDirectory','');
  1429. end;
  1430. procedure TLazPaintConfig.SetDefault3dObjectDirectory(value: string);
  1431. begin
  1432. iniOptions.WriteString('General','3dObjectDirectory',ChompPathDelim(value))
  1433. end;
  1434. function TLazPaintConfig.DefaultTextureDirectory: string;
  1435. begin
  1436. result := iniOptions.ReadString('General','TextureDirectory',DefaultPicturesDirectory);
  1437. end;
  1438. procedure TLazPaintConfig.SetDefaultTextureDirectory(value: string);
  1439. begin
  1440. iniOptions.WriteString('General','TextureDirectory',ChompPathDelim(value))
  1441. end;
  1442. function TLazPaintConfig.DefaultBrushDirectory: string;
  1443. begin
  1444. result := iniOptions.ReadString('General','BrushDirectory',DefaultPicturesDirectory);
  1445. end;
  1446. procedure TLazPaintConfig.SetDefaultBrushDirectory(value: string);
  1447. begin
  1448. iniOptions.WriteString('General','BrushDirectory',ChompPathDelim(value))
  1449. end;
  1450. function TLazPaintConfig.DefaultPaletteDirectory: string;
  1451. begin
  1452. result := iniOptions.ReadString('General','PaletteDirectory','');
  1453. end;
  1454. procedure TLazPaintConfig.SetDefaultPaletteDirectory(value: string);
  1455. begin
  1456. iniOptions.WriteString('General','PaletteDirectory',ChompPathDelim(value))
  1457. end;
  1458. function TLazPaintConfig.DefaultScriptDirectory: string;
  1459. begin
  1460. result := iniOptions.ReadString('General','ScriptDirectory','');
  1461. end;
  1462. procedure TLazPaintConfig.SetDefaultScriptDirectory(value: string);
  1463. begin
  1464. iniOptions.WriteString('General','ScriptDirectory',ChompPathDelim(value))
  1465. end;
  1466. function TLazPaintConfig.DefaultCheckScriptsSecure: boolean;
  1467. begin
  1468. result := iniOptions.ReadBool('General', 'CheckScriptsSecure', true);
  1469. end;
  1470. procedure TLazPaintConfig.SetDefaultCheckScriptsSecure(value: boolean);
  1471. begin
  1472. iniOptions.WriteBool('General', 'CheckScriptsSecure', value);
  1473. end;
  1474. function TLazPaintConfig.DefaultIconSize(defaultValue: integer): integer;
  1475. begin
  1476. result := iniOptions.ReadInteger('General','DefaultIconSize',0);
  1477. if result > 48 then result := 48;
  1478. if result = 0 then result := defaultValue;
  1479. end;
  1480. procedure TLazPaintConfig.SetDefaultIconSize(value: integer);
  1481. begin
  1482. iniOptions.WriteInteger('General','DefaultIconSize',value);
  1483. end;
  1484. function TLazPaintConfig.GetDarkTheme: boolean;
  1485. begin
  1486. if not FDarkThemeEvaluated then
  1487. begin
  1488. if GetDarkThemePreference = dtpAuto then
  1489. begin
  1490. FDarkTheme := DarkThemeInstance.IsSystemDarkTheme;
  1491. DarkThemeInstance.HasSystemDarkThemeChanged;
  1492. end else
  1493. FDarkTheme := iniOptions.ReadBool('General','DarkTheme', false);
  1494. FDarkThemeEvaluated:= true;
  1495. end;
  1496. result := FDarkTheme;
  1497. end;
  1498. procedure TLazPaintConfig.SetDarkTheme(AValue: boolean);
  1499. begin
  1500. if FDarkThemeEvaluated and (AValue = FDarkTheme) then exit;
  1501. iniOptions.WriteBool('General','DarkTheme', AValue);
  1502. FDarkTheme:= AValue;
  1503. FDarkThemeEvaluated:= true;
  1504. FWorkspaceColorEvaluated:= false;
  1505. end;
  1506. function TLazPaintConfig.GetDarkThemePreference: TDarkThemePreference;
  1507. var
  1508. s: String;
  1509. begin
  1510. if not FDarkThemePreferenceEvaluated then
  1511. begin
  1512. s := iniOptions.ReadString('General','DarkThemePreference', 'auto');
  1513. if CompareText(s,'dark')=0 then FDarkThemePreference:= dtpDark
  1514. else if CompareText(s,'light')=0 then FDarkThemePreference:= dtpLight
  1515. else FDarkThemePreference:= dtpAuto;
  1516. FDarkThemePreferenceEvaluated:= true;
  1517. end;
  1518. result := FDarkThemePreference;
  1519. end;
  1520. procedure TLazPaintConfig.SetDarkThemePreference(AValue: TDarkThemePreference);
  1521. var
  1522. s: String;
  1523. begin
  1524. if FDarkThemeEvaluated and (AValue = FDarkThemePreference) then exit;
  1525. case AValue of
  1526. dtpDark: s := 'Dark';
  1527. dtpLight: s := 'Light';
  1528. else s := 'Auto';
  1529. end;
  1530. iniOptions.WriteString('General','DarkThemePreference', s);
  1531. FDarkThemePreference:= AValue;
  1532. FDarkThemePreferenceEvaluated:= true;
  1533. end;
  1534. function TLazPaintConfig.ScreenSizeChanged: boolean;
  1535. var currentScreenSize,previousScreenSize: TRect;
  1536. begin
  1537. currentScreenSize := rect(0,0,screen.Width,screen.Height);
  1538. previousScreenSize := DefaultScreenSize;
  1539. if not CompareRect(@previousScreenSize,@currentScreenSize.left) then
  1540. begin
  1541. SetDefaultScreenSize(currentScreenSize);
  1542. result := true;
  1543. end else
  1544. result := false;
  1545. end;
  1546. procedure TLazPaintConfig.AddRecentFile(filename: string);
  1547. var idx : integer;
  1548. begin
  1549. idx := recentFiles.IndexOf(filename);
  1550. if idx <> -1 then
  1551. recentFiles.Delete(idx);
  1552. recentFiles.Insert(0,filename);
  1553. while recentFiles.count > maxRecentFiles do
  1554. recentFiles.Delete(recentFiles.count-1);
  1555. end;
  1556. procedure TLazPaintConfig.AddRecentDirectory(dirname: string);
  1557. var idx : integer;
  1558. begin
  1559. dirname := ChompPathDelim(dirname);
  1560. idx := recentDirs.IndexOf(dirname);
  1561. if idx <> -1 then
  1562. recentDirs.Delete(idx);
  1563. recentDirs.Insert(0,dirname);
  1564. while recentDirs.count > maxRecentDirectories do
  1565. recentDirs.Delete(recentDirs.count-1);
  1566. end;
  1567. function TLazPaintConfig.GetRecentFilesCount: integer;
  1568. begin
  1569. result := recentFiles.Count;
  1570. end;
  1571. function TLazPaintConfig.GetColorizePreset(Index: Integer): TVariableSet;
  1572. begin
  1573. result := TVariableSet(colorizePresets[Index]);
  1574. end;
  1575. function TLazPaintConfig.GetBrushCount: integer;
  1576. begin
  1577. result := iniOptions.ReadInteger('Brushes','Count',0);
  1578. end;
  1579. function TLazPaintConfig.GetBrushInfo(Index: integer): string;
  1580. begin
  1581. result := iniOptions.ReadString('Brushes','Brush'+IntToStr(index+1),'');
  1582. end;
  1583. function TLazPaintConfig.GetColorizePresetCount: integer;
  1584. begin
  1585. result := colorizePresets.Count;
  1586. end;
  1587. function TLazPaintConfig.GetRecentDirectoriesCount: integer;
  1588. begin
  1589. result := recentDirs.Count;
  1590. end;
  1591. function TLazPaintConfig.GetRecentDirectory(Index: Integer): string;
  1592. begin
  1593. result := recentDirs[Index];
  1594. end;
  1595. function TLazPaintConfig.GetRecentFile(Index: Integer): string;
  1596. begin
  1597. result := recentFiles[Index];
  1598. end;
  1599. function TLazPaintConfig.ImageListLastFolder: string;
  1600. begin
  1601. result := iniOptions.ReadString('ImageList','LastFolder','');
  1602. end;
  1603. procedure TLazPaintConfig.SetImageListLastFolder(value: string);
  1604. begin
  1605. iniOptions.WriteString('ImageList','LastFolder',ChompPathDelim(value));
  1606. end;
  1607. function TLazPaintConfig.ImageListAutoZoom: Boolean;
  1608. begin
  1609. result := iniOptions.ReadBool('ImageList','AutoZoom',True);
  1610. end;
  1611. procedure TLazPaintConfig.SetImageListAutoZoom(value: Boolean);
  1612. begin
  1613. iniOptions.WriteBool('ImageList','AutoZoom',Value);
  1614. end;
  1615. function TLazPaintConfig.ImageListAutoUncheck: Boolean;
  1616. begin
  1617. result := iniOptions.ReadBool('ImageList','AutoUncheck',True);
  1618. end;
  1619. procedure TLazPaintConfig.SetImageListAutoUncheck(value: Boolean);
  1620. begin
  1621. iniOptions.WriteBool('ImageList','AutoUncheck',Value);
  1622. end;
  1623. function TLazPaintConfig.ImageListAutoUncheckMode: Integer;
  1624. begin
  1625. result := iniOptions.ReadInteger('ImageList','AutoUncheckMode',0);
  1626. end;
  1627. procedure TLazPaintConfig.SetImageListAutoUncheckMode(value: integer);
  1628. begin
  1629. iniOptions.WriteInteger('ImageList','AutoUncheckMode',value);
  1630. end;
  1631. constructor TLazPaintConfig.Create(ini: TIniFile; AVersion: string);
  1632. begin
  1633. FVersion:= AVersion;
  1634. iniOptions := ini;
  1635. InitRecentFiles;
  1636. if ScreenSizeChanged then
  1637. begin
  1638. SetDefaultMainWindowPosition(EmptyRect);
  1639. SetDefaultColorWindowPosition(EmptyRect);
  1640. SetDefaultToolboxWindowPosition(EmptyRect);
  1641. SetDefaultLayerWindowPosition(EmptyRect);
  1642. SetDefaultImagelistWindowPosition(EmptyRect);
  1643. SetDefaultBrowseWindowPosition(EmptyRect);
  1644. end;
  1645. tempFont := TFont.Create;
  1646. Languages := TStringList.Create;
  1647. InitColorizePresets;
  1648. end;
  1649. destructor TLazPaintConfig.Destroy;
  1650. begin
  1651. FinalizeRecentFiles;
  1652. FinalizeColorizePresets;
  1653. iniOptions.Free;
  1654. tempFont.Free;
  1655. Languages.Free;
  1656. end;
  1657. initialization
  1658. MenuDefinitionKeys := TStringList.Create;
  1659. MenuDefinitionValues := TStringList.Create;
  1660. finalization
  1661. MenuDefinitionKeys.Free;
  1662. MenuDefinitionValues.Free;
  1663. end.