lazpaintdialogs.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. // SPDX-License-Identifier: GPL-3.0-only
  2. procedure TLazPaintInstance.ShowPrintDlg;
  3. var f: TFPrint;
  4. wasVisible: boolean;
  5. begin
  6. wasVisible := false;
  7. if (FMain <> nil) and FMain.Visible then
  8. begin
  9. wasVisible := true;
  10. FMain.Hide;
  11. end;
  12. f := TFPrint.Create(nil);
  13. f.Instance := self;
  14. f.ShowModal;
  15. f.Free;
  16. if (FMain <> nil) and wasVisible then FMain.Show;
  17. end;
  18. procedure TLazPaintInstance.ShowCanvasSizeDlg;
  19. var topmostInfo: TTopMostInfo;
  20. begin
  21. FormsNeeded;
  22. topmostInfo := HideTopmost;
  23. try
  24. FormCanvasSize.repeatImage := False;
  25. if FormCanvasSize.ShowModal = mrOk then
  26. Image.Assign(FormCanvasSize.canvasSizeResult, true, True);
  27. except
  28. on ex:Exception do
  29. ShowError('ShowCanvasSizeDlg',ex.Message);
  30. end;
  31. ShowTopmost(topmostInfo);
  32. end;
  33. procedure TLazPaintInstance.ShowRepeatImageDlg;
  34. var topmostInfo: TTopMostInfo;
  35. begin
  36. FormsNeeded;
  37. topmostInfo := HideTopmost;
  38. try
  39. FormCanvasSize.repeatImage := True;
  40. if FormCanvasSize.ShowModal = mrOk then
  41. image.Assign(FormCanvasSize.canvasSizeResult,true,True);
  42. except
  43. on ex:Exception do
  44. ShowError('ShowRepeatImageDlg',ex.Message);
  45. end;
  46. ShowTopmost(topmostInfo);
  47. end;
  48. function TLazPaintInstance.ScriptFileNew(AVars: TVariableSet): TScriptResult;
  49. var
  50. bitmapRepl: TBGRABitmap;
  51. vW,vH,vBack: TScriptVariableReference;
  52. w,h: NativeInt;
  53. back: TBGRAPixel;
  54. whDefined: boolean;
  55. begin
  56. if ToolManager.ToolSleeping then
  57. begin
  58. result := srException;
  59. exit;
  60. end;
  61. vW := AVars.GetVariable('Width');
  62. w := 1;
  63. vH := AVars.GetVariable('Height');
  64. h := 1;
  65. vBack := AVars.GetVariable('BackColor');
  66. back := BGRAPixelTransparent;
  67. whDefined := AVars.IsReferenceDefined(vW) and AVars.IsReferenceDefined(vH);
  68. if whDefined then
  69. begin
  70. w := AVars.GetInteger(vW);
  71. h := AVars.GetInteger(vH);
  72. if AVars.IsReferenceDefined(vBack) then
  73. back := AVars.GetPixel(vBack)
  74. else
  75. back := BGRAPixelTransparent;
  76. if (w < 1) or (w > MaxImageWidth) or (h < 1) or (h > MaxImageHeight) then
  77. begin
  78. result := srInvalidParameters;
  79. exit;
  80. end;
  81. end else
  82. if AVars.IsReferenceDefined(vW) or AVars.IsReferenceDefined(vH) then //partial parameters
  83. begin
  84. result := srInvalidParameters;
  85. exit;
  86. end;
  87. if Image.IsFileModified and not AVars.Booleans['IgnoreModified'] then
  88. begin
  89. case SaveQuestion(rsNewImage) of
  90. IDYES: begin
  91. result := ScriptContext.CallScriptFunction('FileSave');
  92. if result <> srOk then exit;
  93. end;
  94. IDCANCEL: begin
  95. result := srCancelledByUser;
  96. exit;
  97. end;
  98. end;
  99. end;
  100. if whDefined then
  101. bitmapRepl := MakeNewBitmapReplacement(w,h,back)
  102. else
  103. begin
  104. if not ShowNewImageDlg(bitmapRepl) then
  105. begin
  106. result := srCancelledByUser;
  107. exit;
  108. end else
  109. if Assigned(ScriptContext.RecordingFunctionParameters) then
  110. begin
  111. ScriptContext.RecordingFunctionParameters.AddInteger('Width', bitmapRepl.Width);
  112. ScriptContext.RecordingFunctionParameters.AddInteger('Height', bitmapRepl.Height);
  113. ScriptContext.RecordingFunctionParameters.AddPixel('BackColor', bitmapRepl.GetPixel(0,0));
  114. end;
  115. end;
  116. ChooseTool(ptHand);
  117. image.Assign(bitmapRepl, True, False);
  118. Image.CurrentFilenameUTF8 := '';
  119. image.SetSavedFlag(0,-1,0);
  120. UpdateWindows;
  121. result := srOk;
  122. end;
  123. function TLazPaintInstance.ScriptImageCanvasSize(AVars: TVariableSet): TScriptResult;
  124. var
  125. w, h: Int64;
  126. anchor: String;
  127. begin
  128. w := AVars.Integers['Width'];
  129. h := AVars.Integers['Height'];
  130. if (w = Image.Width) and (h = Image.Height) then exit(srOk);
  131. if (w < 1) or (h < 1) or (w > MaxImageWidth) or (h > MaxImageHeight) then exit(srInvalidParameters);
  132. anchor := AVars.Strings['Anchor'];
  133. try
  134. Image.Assign(ComputeNewCanvasSize(self, w,h, anchor, false,false), true, True);
  135. except
  136. on ex: exception do
  137. result := srException;
  138. end;
  139. result := srOk;
  140. end;
  141. function TLazPaintInstance.ScriptImageRepeat(AVars: TVariableSet): TScriptResult;
  142. var
  143. w, h: Int64;
  144. anchor: String;
  145. flipMode: Boolean;
  146. begin
  147. w := AVars.Integers['Width'];
  148. h := AVars.Integers['Height'];
  149. if (w = Image.Width) and (h = Image.Height) then exit(srOk);
  150. if (w < 1) or (h < 1) or (w > MaxImageWidth) or (h > MaxImageHeight) then exit(srInvalidParameters);
  151. anchor := AVars.Strings['Anchor'];
  152. flipMode := AVars.Booleans['Flip'];
  153. try
  154. Image.Assign(ComputeNewCanvasSize(self, w,h, anchor, true,flipMode), true, True);
  155. except
  156. on ex: exception do
  157. result := srException;
  158. end;
  159. result := srOk;
  160. end;
  161. function TLazPaintInstance.ShowNewImageDlg(out bitmap: TBGRABitmap
  162. ): boolean;
  163. var tx,ty,bpp: integer;
  164. back: TBGRAPixel;
  165. begin
  166. FormsNeeded;
  167. Result:= unewimage.ShowNewImageDlg(self,false,tx,ty,bpp,back);
  168. if result then
  169. bitmap := MakeNewBitmapReplacement(tx,ty,back)
  170. else
  171. bitmap := nil;
  172. end;
  173. function TLazPaintInstance.ScriptImageResample(AParams: TVariableSet): TScriptResult;
  174. var w,h: NativeInt;
  175. f: TResampleFilter;
  176. begin
  177. if Assigned(ScriptContext.RecordingFunctionParameters) then AParams := ScriptContext.RecordingFunctionParameters;
  178. if AParams.IsDefined('Width') and AParams.IsDefined('Height') and AParams.IsDefined('Quality') then
  179. begin
  180. w := AParams.Integers['Width'];
  181. h := AParams.Integers['Height'];
  182. f := StrToResampleFilter(AParams.Strings['Quality']);
  183. if (CompareText(AParams.Strings['Quality'],ResampleFilterStr[f])<>0) or
  184. (w < 1) or (w > MaxImageWidth) or (h < 1) or (h > MaxImageHeight) then
  185. result := srInvalidParameters
  186. else
  187. try
  188. Image.Resample(w,h,f);
  189. result := srOk;
  190. except
  191. on ex:exception do
  192. result := srException;
  193. end;
  194. UpdateWindows;
  195. end else
  196. if ShowResampleDialog(AParams) then
  197. result := srOk
  198. else
  199. result := srCancelledByUser;
  200. end;
  201. function TLazPaintInstance.ScriptLazPaintGetVersion(AVars: TVariableSet): TScriptResult;
  202. var
  203. resList: TScriptVariableReference;
  204. begin
  205. resList := AVars.AddIntegerList('Result');
  206. AVars.AppendInteger(resList, LazPaintVersion div 1000000);
  207. AVars.AppendInteger(resList, (LazPaintVersion div 10000) mod 100);
  208. AVars.AppendInteger(resList, (LazPaintVersion div 100) mod 100);
  209. result := srOk;
  210. end;
  211. function TLazPaintInstance.ScriptShowDirectoryDialog(AVars: TVariableSet): TScriptResult;
  212. var
  213. chosenDir: string;
  214. begin
  215. if SelectDirectory(AVars.Strings['Prompt'], AVars.Strings['InitialDir'], chosenDir) then
  216. begin
  217. Avars.Strings['Result'] := chosenDir;
  218. result := srOk;
  219. end else
  220. result := srCancelledByUser;
  221. end;
  222. function TLazPaintInstance.ShowResampleDialog(AParameters: TVariableSet): boolean;
  223. begin
  224. FormsNeeded;
  225. Result:= uresample.ShowResampleDialog(self,AParameters);
  226. end;
  227. function TLazPaintInstance.ScriptColorIntensity(AVars: TVariableSet): TScriptResult;
  228. begin
  229. if Assigned(ScriptContext.RecordingFunctionParameters) then AVars := ScriptContext.RecordingFunctionParameters;
  230. if not Assigned(Image) or not image.CheckCurrentLayerVisible then
  231. begin result := srException; exit; end;
  232. result := ShowColorIntensityDlg(AVars);
  233. end;
  234. function TLazPaintInstance.ShowColorIntensityDlg(AParameters: TVariableSet): TScriptResult;
  235. var oldSelectionNormal: boolean;
  236. begin
  237. FormsNeeded;
  238. oldSelectionNormal := ShowSelectionNormal;
  239. ShowSelectionNormal := true;
  240. try
  241. case FormColorIntensity.ShowModal(self,ciIntensity,AParameters) of
  242. mrOK: result := srOk;
  243. else result := srCancelledByUser;
  244. end;
  245. except
  246. on ex:Exception do
  247. begin
  248. result := srException;
  249. ShowError(FormColorIntensity.Caption, ex.Message);
  250. end;
  251. end;
  252. ShowSelectionNormal := oldSelectionNormal;
  253. end;
  254. function TLazPaintInstance.ScriptColorLightness(AVars: TVariableSet): TScriptResult;
  255. begin
  256. if Assigned(ScriptContext.RecordingFunctionParameters) then AVars := ScriptContext.RecordingFunctionParameters;
  257. if not Assigned(Image) or not image.CheckCurrentLayerVisible then
  258. begin result := srException; exit; end;
  259. result := ShowColorLightnessDlg(AVars);
  260. end;
  261. function TLazPaintInstance.ShowColorLightnessDlg(AParameters: TVariableSet
  262. ): TScriptResult;
  263. var oldSelectionNormal: boolean;
  264. begin
  265. FormsNeeded;
  266. oldSelectionNormal := ShowSelectionNormal;
  267. ShowSelectionNormal := true;
  268. try
  269. case FormColorIntensity.ShowModal(self,ciLightness,AParameters) of
  270. mrOk: result := srOk;
  271. else result := srCancelledByUser;
  272. end;
  273. except
  274. on ex:Exception do
  275. begin
  276. result := srException;
  277. ShowError(FormColorIntensity.Caption,ex.Message);
  278. end;
  279. end;
  280. ShowSelectionNormal := oldSelectionNormal;
  281. end;
  282. function TLazPaintInstance.ScriptColorShiftColors(AVars: TVariableSet): TScriptResult;
  283. begin
  284. if Assigned(ScriptContext.RecordingFunctionParameters) then AVars := ScriptContext.RecordingFunctionParameters;
  285. if not Assigned(Image) or not image.CheckCurrentLayerVisible then
  286. begin result := srException; exit; end;
  287. result := ShowShiftColorsDlg(AVars);
  288. end;
  289. function TLazPaintInstance.ShowShiftColorsDlg(AParameters: TVariableSet): TScriptResult;
  290. var oldSelectionNormal: boolean;
  291. begin
  292. FormsNeeded;
  293. oldSelectionNormal := ShowSelectionNormal;
  294. ShowSelectionNormal := true;
  295. try
  296. case FormShiftColors.ShowModal(self,AParameters) of
  297. mrOk: result := srOk;
  298. else result := srCancelledByUser;
  299. end;
  300. except
  301. on ex:Exception do
  302. begin
  303. result := srException;
  304. ShowError(FormShiftColors.Caption,ex.Message);
  305. end;
  306. end;
  307. ShowSelectionNormal := oldSelectionNormal;
  308. end;
  309. function TLazPaintInstance.ScriptColorColorize(AVars: TVariableSet): TScriptResult;
  310. begin
  311. if Assigned(ScriptContext.RecordingFunctionParameters) then AVars := ScriptContext.RecordingFunctionParameters;
  312. if not Assigned(Image) or not image.CheckCurrentLayerVisible then
  313. begin result := srException; exit; end;
  314. result := ShowColorizeDlg(AVars);
  315. end;
  316. function TLazPaintInstance.ShowColorizeDlg(AParameters: TVariableSet): TScriptResult;
  317. var oldSelectionNormal: boolean;
  318. begin
  319. FormsNeeded;
  320. oldSelectionNormal := ShowSelectionNormal;
  321. ShowSelectionNormal := true;
  322. try
  323. case FormColorize.ShowModal(self,AParameters) of
  324. mrOk: result := srOk;
  325. else result := srCancelledByUser;
  326. end;
  327. except
  328. on ex:Exception do
  329. begin
  330. result := srException;
  331. ShowError(FormColorize.Caption, ex.Message);
  332. end;
  333. end;
  334. ShowSelectionNormal := oldSelectionNormal;
  335. end;
  336. function TLazPaintInstance.ScriptColorCurves(AVars: TVariableSet): TScriptResult;
  337. begin
  338. if Assigned(ScriptContext.RecordingFunctionParameters) then AVars := ScriptContext.RecordingFunctionParameters;
  339. if not Assigned(Image) or not Image.CheckCurrentLayerVisible then
  340. begin result := srException; exit; end;
  341. result := ShowColorCurvesDlg(AVars);
  342. end;
  343. function TLazPaintInstance.ShowColorCurvesDlg(AParameters: TVariableSet): TScriptResult;
  344. var oldSelectionNormal: boolean;
  345. begin
  346. FormsNeeded;
  347. oldSelectionNormal := ShowSelectionNormal;
  348. ShowSelectionNormal := true;
  349. try
  350. case FormAdjustCurves.ShowModal(self,AParameters) of
  351. mrOk: result := srOk;
  352. else result := srCancelledByUser;
  353. end;
  354. except
  355. on ex:Exception do
  356. begin
  357. result := srException;
  358. ShowError('ShowColorCurvesDlg',ex.Message);
  359. end;
  360. end;
  361. ShowSelectionNormal := oldSelectionNormal;
  362. end;
  363. function TLazPaintInstance.ShowRadialBlurDlg(AFilterConnector: TObject; blurType: TRadialBlurType; ACaption: string): TScriptResult;
  364. var oldSelectionNormal: boolean;
  365. top: TTopMostInfo;
  366. begin
  367. top := self.HideTopmost;
  368. oldSelectionNormal := ShowSelectionNormal;
  369. ShowSelectionNormal := true;
  370. result := URadialBlur.ShowRadialBlurDlg(AFilterConnector, blurType, ACaption);
  371. ShowSelectionNormal := oldSelectionNormal;
  372. self.ShowTopmost(top);
  373. end;
  374. function TLazPaintInstance.ShowMotionBlurDlg(AFilterConnector: TObject): TScriptResult;
  375. var oldSelectionNormal: boolean;
  376. top: TTopMostInfo;
  377. begin
  378. top := self.HideTopmost;
  379. oldSelectionNormal := ShowSelectionNormal;
  380. ShowSelectionNormal := true;
  381. result := UMotionBlur.ShowMotionBlurDlg(AFilterConnector);
  382. ShowSelectionNormal := oldSelectionNormal;
  383. self.ShowTopmost(top);
  384. end;
  385. function TLazPaintInstance.ShowCustomBlurDlg(AFilterConnector: TObject): TScriptResult;
  386. var oldSelectionNormal: boolean;
  387. top: TTopMostInfo;
  388. begin
  389. top := self.HideTopmost;
  390. oldSelectionNormal := ShowSelectionNormal;
  391. ShowSelectionNormal := true;
  392. result := FormCustomBlur.ShowDlg(AFilterConnector);
  393. ShowSelectionNormal := oldSelectionNormal;
  394. self.ShowTopmost(top);
  395. end;
  396. function TLazPaintInstance.ShowEmbossDlg(AFilterConnector: TObject): TScriptResult;
  397. var oldSelectionNormal: boolean;
  398. top: TTopMostInfo;
  399. begin
  400. top := self.HideTopmost;
  401. oldSelectionNormal := ShowSelectionNormal;
  402. ShowSelectionNormal := true;
  403. result := UEmboss.ShowEmbossDlg(AFilterConnector);
  404. ShowSelectionNormal := oldSelectionNormal;
  405. self.ShowTopmost(top);
  406. end;
  407. function TLazPaintInstance.ShowRainDlg(AFilterConnector: TObject): TScriptResult;
  408. var oldSelectionNormal: boolean;
  409. top: TTopMostInfo;
  410. begin
  411. top := self.HideTopmost;
  412. oldSelectionNormal := ShowSelectionNormal;
  413. ShowSelectionNormal := true;
  414. result := uformrain.ShowRainDlg(AFilterConnector);
  415. ShowSelectionNormal := oldSelectionNormal;
  416. self.ShowTopmost(top);
  417. end;
  418. function TLazPaintInstance.ShowPixelateDlg(AFilterConnector: TObject): TScriptResult;
  419. var oldSelectionNormal: boolean;
  420. top: TTopMostInfo;
  421. begin
  422. top := self.HideTopmost;
  423. oldSelectionNormal := ShowSelectionNormal;
  424. ShowSelectionNormal := true;
  425. result := UPixelate.ShowPixelateDlg(AFilterConnector);
  426. ShowSelectionNormal := oldSelectionNormal;
  427. self.ShowTopmost(top);
  428. end;
  429. function TLazPaintInstance.ShowNoiseFilterDlg(AFilterConnector: TObject): TScriptResult;
  430. var oldSelectionNormal: boolean;
  431. top: TTopMostInfo;
  432. begin
  433. top := self.HideTopmost;
  434. oldSelectionNormal := ShowSelectionNormal;
  435. ShowSelectionNormal := true;
  436. result := unoisefilter.ShowNoiseFilterDlg(AFilterConnector);
  437. ShowSelectionNormal := oldSelectionNormal;
  438. self.ShowTopmost(top);
  439. end;
  440. function TLazPaintInstance.ShowTwirlDlg(AFilterConnector: TObject): TScriptResult;
  441. var oldSelectionNormal: boolean;
  442. top: TTopMostInfo;
  443. begin
  444. top := self.HideTopmost;
  445. oldSelectionNormal := ShowSelectionNormal;
  446. ShowSelectionNormal := true;
  447. result := utwirl.ShowTwirlDlg(AFilterConnector);
  448. ShowSelectionNormal := oldSelectionNormal;
  449. self.ShowTopmost(top);
  450. end;
  451. function TLazPaintInstance.ShowWaveDisplacementDlg(AFilterConnector: TObject): TScriptResult;
  452. var oldSelectionNormal: boolean;
  453. top: TTopMostInfo;
  454. begin
  455. top := self.HideTopmost;
  456. oldSelectionNormal := ShowSelectionNormal;
  457. ShowSelectionNormal := true;
  458. result := UWaveDisplacement.ShowWaveDisplacementDlg(AFilterConnector);
  459. ShowSelectionNormal := oldSelectionNormal;
  460. self.ShowTopmost(top);
  461. end;
  462. function TLazPaintInstance.ShowPhongFilterDlg(AFilterConnector: TObject): TScriptResult;
  463. var oldSelectionNormal: boolean;
  464. top: TTopMostInfo;
  465. begin
  466. top := self.HideTopmost;
  467. oldSelectionNormal := ShowSelectionNormal;
  468. ShowSelectionNormal := true;
  469. result := UPhongFilter.ShowPhongFilterDlg(AFilterConnector);
  470. ShowSelectionNormal := oldSelectionNormal;
  471. self.ShowTopmost(top);
  472. end;
  473. function TLazPaintInstance.ShowFunctionFilterDlg(AFilterConnector: TObject): TScriptResult;
  474. var oldSelectionNormal: boolean;
  475. top: TTopMostInfo;
  476. begin
  477. top := self.HideTopmost;
  478. oldSelectionNormal := ShowSelectionNormal;
  479. ShowSelectionNormal := true;
  480. result := UFilterFunction.ShowFilterFunctionDlg(AFilterConnector);
  481. ShowSelectionNormal := oldSelectionNormal;
  482. self.ShowTopmost(top);
  483. end;
  484. function TLazPaintInstance.ShowSharpenDlg(AFilterConnector: TObject): TScriptResult;
  485. var oldSelectionNormal: boolean;
  486. top: TTopMostInfo;
  487. begin
  488. top := self.HideTopmost;
  489. oldSelectionNormal := ShowSelectionNormal;
  490. ShowSelectionNormal := true;
  491. result := USharpen.ShowSharpenDlg(AFilterConnector, smSharpen);
  492. ShowSelectionNormal := oldSelectionNormal;
  493. self.ShowTopmost(top);
  494. end;
  495. function TLazPaintInstance.ScriptColorPosterize(AVars: TVariableSet): TScriptResult;
  496. begin
  497. if Assigned(ScriptContext.RecordingFunctionParameters) then AVars := ScriptContext.RecordingFunctionParameters;
  498. if not Assigned(Image) or not Image.CheckCurrentLayerVisible then
  499. begin result := srException; exit; end;
  500. result := ShowPosterizeDlg(AVars);
  501. end;
  502. function TLazPaintInstance.ShowPosterizeDlg(AParameters: TVariableSet): TScriptResult;
  503. var oldSelectionNormal: boolean;
  504. top: TTopMostInfo;
  505. begin
  506. top := self.HideTopmost;
  507. oldSelectionNormal := ShowSelectionNormal;
  508. ShowSelectionNormal := true;
  509. result := uposterize.ShowPosterizeDlg(self, AParameters);
  510. ShowSelectionNormal := oldSelectionNormal;
  511. self.ShowTopmost(top);
  512. end;