PageRenderTime 57ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/src/AppWorkspace.cs

https://bitbucket.org/tuldok89/openpdn
C# | 2324 lines | 1847 code | 387 blank | 90 comment | 271 complexity | 2692eb01900f1c52eb6630b8e0400cf2 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /////////////////////////////////////////////////////////////////////////////////
  2. // Paint.NET //
  3. // Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors. //
  4. // Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
  5. // See src/Resources/Files/License.txt for full licensing and attribution //
  6. // details. //
  7. // . //
  8. /////////////////////////////////////////////////////////////////////////////////
  9. using PaintDotNet.Actions;
  10. using PaintDotNet.Base;
  11. using PaintDotNet.HistoryFunctions;
  12. using PaintDotNet.HistoryMementos;
  13. using PaintDotNet.SystemLayer;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.ComponentModel;
  17. using System.Drawing;
  18. using System.Globalization;
  19. using System.Reflection;
  20. using System.Windows.Forms;
  21. namespace PaintDotNet
  22. {
  23. internal class AppWorkspace
  24. : UserControl,
  25. ISnapObstacleHost
  26. {
  27. private readonly string _cursorInfoStatusBarFormat = PdnResources.GetString("StatusBar.CursorInfo.Format");
  28. private readonly string _imageInfoStatusBarFormat = PdnResources.GetString("StatusBar.Size.Format");
  29. private Type _defaultToolTypeChoice;
  30. private Type _globalToolTypeChoice;
  31. private bool _globalRulersChoice;
  32. private DocumentWorkspace _activeDocumentWorkspace;
  33. // if a new workspace is added, and this workspace is not dirty, then it will be removed.
  34. // This keeps track of the last workspace added via CreateBlankDocumentInNewWorkspace (if
  35. // true was passed for its 2nd parameter)
  36. private DocumentWorkspace _initialWorkspace;
  37. private readonly List<DocumentWorkspace> _documentWorkspaces = new List<DocumentWorkspace>();
  38. private readonly WorkspaceWidgets _widgets;
  39. private Panel _workspacePanel;
  40. private PdnStatusBar _statusBar;
  41. private ToolsForm _mainToolBarForm;
  42. private LayerForm _layerForm;
  43. private HistoryForm _historyForm;
  44. private ColorsForm _colorsForm;
  45. private MostRecentFiles _mostRecentFiles;
  46. private const int DefaultMostRecentFilesMax = 8;
  47. private SnapObstacleController _snapObstacle;
  48. private bool _addedToSnapManager;
  49. private int _ignoreUpdateSnapObstacle;
  50. private int _suspendThumbnailUpdates;
  51. public void CheckForUpdates()
  52. {
  53. ToolBar.MainMenu.CheckForUpdates();
  54. }
  55. public IDisposable SuspendThumbnailUpdates()
  56. {
  57. var resumeFn = new CallbackOnDispose(ResumeThumbnailUpdates);
  58. ++_suspendThumbnailUpdates;
  59. if (_suspendThumbnailUpdates == 1)
  60. {
  61. Widgets.DocumentStrip.SuspendThumbnailUpdates();
  62. Widgets.LayerControl.SuspendLayerPreviewUpdates();
  63. }
  64. return resumeFn;
  65. }
  66. private void ResumeThumbnailUpdates()
  67. {
  68. --_suspendThumbnailUpdates;
  69. if (_suspendThumbnailUpdates != 0) return;
  70. Widgets.DocumentStrip.ResumeThumbnailUpdates();
  71. Widgets.LayerControl.ResumeLayerPreviewUpdates();
  72. }
  73. public Type DefaultToolType
  74. {
  75. get
  76. {
  77. return _defaultToolTypeChoice;
  78. }
  79. set
  80. {
  81. _defaultToolTypeChoice = value;
  82. Settings.CurrentUser.SetString(SettingNames.DefaultToolTypeName, value.Name);
  83. }
  84. }
  85. public Type GlobalToolTypeChoice
  86. {
  87. get
  88. {
  89. return _globalToolTypeChoice;
  90. }
  91. set
  92. {
  93. _globalToolTypeChoice = value;
  94. if (ActiveDocumentWorkspace != null)
  95. {
  96. ActiveDocumentWorkspace.SetToolFromType(value);
  97. }
  98. }
  99. }
  100. public DocumentWorkspace InitialWorkspace
  101. {
  102. set
  103. {
  104. _initialWorkspace = value;
  105. }
  106. }
  107. public event EventHandler RulersEnabledChanged;
  108. protected virtual void OnRulersEnabledChanged()
  109. {
  110. if (RulersEnabledChanged != null)
  111. {
  112. RulersEnabledChanged(this, EventArgs.Empty);
  113. }
  114. }
  115. public bool RulersEnabled
  116. {
  117. get
  118. {
  119. return _globalRulersChoice;
  120. }
  121. set
  122. {
  123. if (_globalRulersChoice == value) return;
  124. _globalRulersChoice = value;
  125. if (ActiveDocumentWorkspace != null)
  126. {
  127. ActiveDocumentWorkspace.RulersEnabled = value;
  128. }
  129. OnRulersEnabledChanged();
  130. }
  131. }
  132. private void DocumentWorkspaceDrawGridChanged(object sender, EventArgs e)
  133. {
  134. DrawGrid = _activeDocumentWorkspace.DrawGrid;
  135. }
  136. private void ViewConfigStripDrawGridChanged(object sender, EventArgs e)
  137. {
  138. DrawGrid = ((ViewConfigStrip)sender).DrawGrid;
  139. }
  140. private bool DrawGrid
  141. {
  142. get
  143. {
  144. return Widgets.ViewConfigStrip.DrawGrid;
  145. }
  146. set
  147. {
  148. if (Widgets.ViewConfigStrip.DrawGrid != value)
  149. {
  150. Widgets.ViewConfigStrip.DrawGrid = value;
  151. }
  152. if (_activeDocumentWorkspace != null && _activeDocumentWorkspace.DrawGrid != value)
  153. {
  154. _activeDocumentWorkspace.DrawGrid = value;
  155. }
  156. Settings.CurrentUser.SetBoolean(SettingNames.DrawGrid, DrawGrid);
  157. }
  158. }
  159. public event EventHandler UnitsChanged;
  160. protected virtual void OnUnitsChanged()
  161. {
  162. if (UnitsChanged != null)
  163. {
  164. UnitsChanged(this, EventArgs.Empty);
  165. }
  166. }
  167. public MeasurementUnit Units
  168. {
  169. get
  170. {
  171. return _widgets.ViewConfigStrip.Units;
  172. }
  173. set
  174. {
  175. _widgets.ViewConfigStrip.Units = value;
  176. }
  177. }
  178. public SnapObstacle SnapObstacle
  179. {
  180. get
  181. {
  182. if (_snapObstacle == null)
  183. {
  184. // HACK: for some reason retrieving the ClientRectangle can raise a VisibleChanged event
  185. // so we initially pass in Rectangle.Empty for the rectangle bounds
  186. _snapObstacle = new SnapObstacleController(
  187. Name,
  188. Rectangle.Empty,
  189. SnapRegion.Interior,
  190. true) {EnableSave = false};
  191. var pdbForm = FindForm() as PdnBaseForm;
  192. if (pdbForm != null)
  193. {
  194. pdbForm.Moving += ParentFormMoving;
  195. pdbForm.Move += ParentFormMove;
  196. pdbForm.ResizeEnd += ParentFormResizeEnd;
  197. pdbForm.Layout += ParentFormLayout;
  198. pdbForm.SizeChanged += ParentFormSizeChanged;
  199. }
  200. UpdateSnapObstacle();
  201. }
  202. return _snapObstacle;
  203. }
  204. }
  205. private void ParentFormMove(object sender, EventArgs e)
  206. {
  207. UpdateSnapObstacle();
  208. }
  209. private void ParentFormSizeChanged(object sender, EventArgs e)
  210. {
  211. UpdateSnapObstacle();
  212. }
  213. private void ParentFormLayout(object sender, LayoutEventArgs e)
  214. {
  215. UpdateSnapObstacle();
  216. }
  217. private void ParentFormResizeEnd(object sender, EventArgs e)
  218. {
  219. UpdateSnapObstacle();
  220. }
  221. private void ParentFormMoving(object sender, MovingEventArgs e)
  222. {
  223. UpdateSnapObstacle();
  224. }
  225. private void SuspendUpdateSnapObstacle()
  226. {
  227. ++_ignoreUpdateSnapObstacle;
  228. }
  229. private void ResumeUpdateSnapObstacle()
  230. {
  231. --_ignoreUpdateSnapObstacle;
  232. }
  233. private void UpdateSnapObstacle()
  234. {
  235. if (_ignoreUpdateSnapObstacle > 0)
  236. {
  237. return;
  238. }
  239. if (_snapObstacle == null)
  240. {
  241. return;
  242. }
  243. if (!_addedToSnapManager)
  244. {
  245. SnapManager sm = SnapManager.FindMySnapManager(this);
  246. if (sm != null)
  247. {
  248. SnapObstacle so = SnapObstacle;
  249. if (!_addedToSnapManager)
  250. {
  251. sm.AddSnapObstacle(SnapObstacle);
  252. _addedToSnapManager = true;
  253. FindForm().Shown += AppWorkspaceShown;
  254. }
  255. }
  256. }
  257. {
  258. Rectangle clientRect = ActiveDocumentWorkspace != null ? ActiveDocumentWorkspace.VisibleViewRectangle : _workspacePanel.ClientRectangle;
  259. Rectangle screenRect = _workspacePanel.RectangleToScreen(clientRect);
  260. _snapObstacle.SetBounds(screenRect);
  261. _snapObstacle.Enabled = Visible && Enabled;
  262. }
  263. }
  264. private void AppWorkspaceShown(object sender, EventArgs e)
  265. {
  266. UpdateSnapObstacle();
  267. }
  268. protected override void OnLayout(LayoutEventArgs levent)
  269. {
  270. UpdateSnapObstacle();
  271. base.OnLayout(levent);
  272. }
  273. protected override void OnLocationChanged(EventArgs e)
  274. {
  275. UpdateSnapObstacle();
  276. base.OnLocationChanged(e);
  277. }
  278. protected override void OnSizeChanged(EventArgs e)
  279. {
  280. UpdateSnapObstacle();
  281. base.OnSizeChanged(e);
  282. }
  283. protected override void OnEnabledChanged(EventArgs e)
  284. {
  285. UpdateSnapObstacle();
  286. base.OnEnabledChanged(e);
  287. }
  288. protected override void OnVisibleChanged(EventArgs e)
  289. {
  290. UpdateSnapObstacle();
  291. base.OnVisibleChanged(e);
  292. }
  293. public void ResetFloatingForms()
  294. {
  295. ResetFloatingForm(Widgets.ToolsForm);
  296. ResetFloatingForm(Widgets.HistoryForm);
  297. ResetFloatingForm(Widgets.LayerForm);
  298. ResetFloatingForm(Widgets.ColorsForm);
  299. }
  300. public void ResetFloatingForm(FloatingToolForm ftf)
  301. {
  302. SnapManager sm = SnapManager.FindMySnapManager(this);
  303. if (ftf == Widgets.ToolsForm)
  304. {
  305. sm.ParkObstacle(Widgets.ToolsForm, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
  306. }
  307. else if (ftf == Widgets.HistoryForm)
  308. {
  309. sm.ParkObstacle(Widgets.HistoryForm, this, HorizontalSnapEdge.Top, VerticalSnapEdge.Right);
  310. }
  311. else if (ftf == Widgets.LayerForm)
  312. {
  313. sm.ParkObstacle(Widgets.LayerForm, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Right);
  314. }
  315. else if (ftf == Widgets.ColorsForm)
  316. {
  317. sm.ParkObstacle(Widgets.ColorsForm, this, HorizontalSnapEdge.Bottom, VerticalSnapEdge.Left);
  318. }
  319. else
  320. {
  321. throw new ArgumentException();
  322. }
  323. }
  324. private readonly Set<Triple<Assembly, Type, Exception>> _effectLoadErrors = new Set<Triple<Assembly, Type, Exception>>();
  325. public void ReportEffectLoadError(Triple<Assembly, Type, Exception> error)
  326. {
  327. lock (_effectLoadErrors)
  328. {
  329. if (!_effectLoadErrors.Contains(error))
  330. {
  331. _effectLoadErrors.Add(error);
  332. }
  333. }
  334. }
  335. public static string GetLocalizedEffectErrorMessage(Assembly assembly, Type type, Exception exception)
  336. {
  337. IPluginSupportInfo supportInfo;
  338. string typeName;
  339. if (type != null)
  340. {
  341. typeName = type.FullName;
  342. supportInfo = PluginSupportInfo.GetPluginSupportInfo(type);
  343. }
  344. else if (exception is TypeLoadException)
  345. {
  346. var asTlex = exception as TypeLoadException;
  347. typeName = asTlex.TypeName;
  348. supportInfo = PluginSupportInfo.GetPluginSupportInfo(assembly);
  349. }
  350. else
  351. {
  352. supportInfo = PluginSupportInfo.GetPluginSupportInfo(assembly);
  353. typeName = null;
  354. }
  355. return GetLocalizedEffectErrorMessage(assembly, typeName, supportInfo, exception);
  356. }
  357. public static string GetLocalizedEffectErrorMessage(Assembly assembly, string typeName, Exception exception)
  358. {
  359. IPluginSupportInfo supportInfo = PluginSupportInfo.GetPluginSupportInfo(assembly);
  360. return GetLocalizedEffectErrorMessage(assembly, typeName, supportInfo, exception);
  361. }
  362. private static string GetLocalizedEffectErrorMessage(Assembly assembly, string typeName, IPluginSupportInfo supportInfo, Exception exception)
  363. {
  364. string fileName = assembly.Location;
  365. string shortErrorFormat = PdnResources.GetString("EffectErrorMessage.ShortFormat");
  366. string fullErrorFormat = PdnResources.GetString("EffectErrorMessage.FullFormat");
  367. string notSuppliedText = PdnResources.GetString("EffectErrorMessage.InfoNotSupplied");
  368. string errorText;
  369. if (supportInfo == null)
  370. {
  371. errorText = string.Format(
  372. shortErrorFormat,
  373. fileName,
  374. typeName ?? notSuppliedText,
  375. exception);
  376. }
  377. else
  378. {
  379. errorText = string.Format(
  380. fullErrorFormat,
  381. fileName,
  382. typeName ?? supportInfo.DisplayName ?? notSuppliedText,
  383. (supportInfo.Version ?? new Version()),
  384. supportInfo.Author ?? notSuppliedText,
  385. supportInfo.Copyright ?? notSuppliedText,
  386. (supportInfo.WebsiteUri == null ? notSuppliedText : supportInfo.WebsiteUri.ToString()),
  387. exception);
  388. }
  389. return errorText;
  390. }
  391. public IList<Triple<Assembly, Type, Exception>> GetEffectLoadErrors()
  392. {
  393. return _effectLoadErrors.ToArray();
  394. }
  395. public void RunEffect(Type effectType)
  396. {
  397. // TODO: this is kind of a hack
  398. ToolBar.MainMenu.RunEffect(effectType);
  399. }
  400. public PdnToolBar ToolBar { get; private set; }
  401. private static ImageResource FileNewIcon
  402. {
  403. get
  404. {
  405. return PdnResources.GetImageResource("Icons.MenuFileNewIcon.png");
  406. }
  407. }
  408. private static ImageResource ImageFromDiskIcon
  409. {
  410. get
  411. {
  412. return PdnResources.GetImageResource("Icons.ImageFromDiskIcon.png");
  413. }
  414. }
  415. public MostRecentFiles MostRecentFiles
  416. {
  417. get { return _mostRecentFiles ?? (_mostRecentFiles = new MostRecentFiles(DefaultMostRecentFilesMax)); }
  418. }
  419. private void DocumentWorkspaceDocumentChanging(object sender, EventArgs<Document> e)
  420. {
  421. UI.SuspendControlPainting(this);
  422. }
  423. private void DocumentWorkspaceDocumentChanged(object sender, EventArgs e)
  424. {
  425. UpdateDocInfoInStatusBar();
  426. UI.ResumeControlPainting(this);
  427. Invalidate(true);
  428. }
  429. private void CoordinatesToStrings(int x, int y, out string xString, out string yString, out string unitsString)
  430. {
  431. _activeDocumentWorkspace.Document.CoordinatesToStrings(Units, x, y, out xString, out yString, out unitsString);
  432. }
  433. private void UpdateCursorInfoInStatusBar(int cursorX, int cursorY)
  434. {
  435. SuspendLayout();
  436. if (_activeDocumentWorkspace == null ||
  437. _activeDocumentWorkspace.Document == null)
  438. {
  439. _statusBar.CursorInfoText = string.Empty;
  440. }
  441. else
  442. {
  443. string xString;
  444. string yString;
  445. string units;
  446. CoordinatesToStrings(cursorX, cursorY, out xString, out yString, out units);
  447. string cursorText = string.Format(
  448. CultureInfo.InvariantCulture,
  449. _cursorInfoStatusBarFormat,
  450. xString,
  451. units,
  452. yString,
  453. units);
  454. _statusBar.CursorInfoText = cursorText;
  455. }
  456. ResumeLayout(false);
  457. }
  458. private void UpdateDocInfoInStatusBar()
  459. {
  460. if (_activeDocumentWorkspace == null ||
  461. _activeDocumentWorkspace.Document == null)
  462. {
  463. _statusBar.ImageInfoStatusText = string.Empty;
  464. }
  465. else
  466. {
  467. string widthString;
  468. string heightString;
  469. string units;
  470. CoordinatesToStrings(
  471. _activeDocumentWorkspace.Document.Width,
  472. _activeDocumentWorkspace.Document.Height,
  473. out widthString,
  474. out heightString,
  475. out units);
  476. string imageText = string.Format(
  477. CultureInfo.InvariantCulture,
  478. _imageInfoStatusBarFormat,
  479. widthString,
  480. units,
  481. heightString,
  482. units);
  483. _statusBar.ImageInfoStatusText = imageText;
  484. }
  485. }
  486. [Browsable(false)]
  487. public WorkspaceWidgets Widgets
  488. {
  489. get
  490. {
  491. return _widgets;
  492. }
  493. }
  494. [Browsable(false)]
  495. public AppEnvironment AppEnvironment { get; private set; }
  496. [Browsable(false)]
  497. public DocumentWorkspace ActiveDocumentWorkspace
  498. {
  499. get
  500. {
  501. return _activeDocumentWorkspace;
  502. }
  503. set
  504. {
  505. if (value == _activeDocumentWorkspace) return;
  506. if (value != null &&
  507. _documentWorkspaces.IndexOf(value) == -1)
  508. {
  509. throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
  510. }
  511. bool focused = false;
  512. if (_activeDocumentWorkspace != null)
  513. {
  514. focused = _activeDocumentWorkspace.Focused;
  515. }
  516. UI.SuspendControlPainting(this);
  517. OnActiveDocumentWorkspaceChanging();
  518. _activeDocumentWorkspace = value;
  519. OnActiveDocumentWorkspaceChanged();
  520. UI.ResumeControlPainting(this);
  521. Refresh();
  522. if (value != null)
  523. {
  524. value.Focus();
  525. }
  526. }
  527. }
  528. private void ActiveDocumentWorkspaceFirstInputAfterGotFocus(object sender, EventArgs e)
  529. {
  530. ToolBar.DocumentStrip.EnsureItemFullyVisible(ToolBar.DocumentStrip.SelectedDocumentIndex);
  531. }
  532. public DocumentWorkspace[] DocumentWorkspaces
  533. {
  534. get
  535. {
  536. return _documentWorkspaces.ToArray();
  537. }
  538. }
  539. public DocumentWorkspace AddNewDocumentWorkspace()
  540. {
  541. if (_initialWorkspace != null)
  542. {
  543. if (_initialWorkspace.Document == null || !_initialWorkspace.Document.Dirty)
  544. {
  545. _globalToolTypeChoice = _initialWorkspace.GetToolType();
  546. RemoveDocumentWorkspace(_initialWorkspace);
  547. _initialWorkspace = null;
  548. }
  549. }
  550. var dw = new DocumentWorkspace {AppWorkspace = this};
  551. _documentWorkspaces.Add(dw);
  552. ToolBar.DocumentStrip.AddDocumentWorkspace(dw);
  553. return dw;
  554. }
  555. public Image GetDocumentWorkspaceThumbnail(DocumentWorkspace dw)
  556. {
  557. ToolBar.DocumentStrip.SyncThumbnails();
  558. Image[] images = ToolBar.DocumentStrip.DocumentThumbnails;
  559. DocumentWorkspace[] documents = ToolBar.DocumentStrip.DocumentList;
  560. for (int i = 0; i < documents.Length; ++i)
  561. {
  562. if (documents[i] == dw)
  563. {
  564. return images[i];
  565. }
  566. }
  567. throw new ArgumentException("The requested DocumentWorkspace doesn't exist in this AppWorkspace");
  568. }
  569. public void RemoveDocumentWorkspace(DocumentWorkspace documentWorkspace)
  570. {
  571. int dwIndex = _documentWorkspaces.IndexOf(documentWorkspace);
  572. if (dwIndex == -1)
  573. {
  574. throw new ArgumentException("DocumentWorkspace was not created with AddNewDocumentWorkspace");
  575. }
  576. bool removingCurrentDW;
  577. if (ActiveDocumentWorkspace == documentWorkspace)
  578. {
  579. removingCurrentDW = true;
  580. _globalToolTypeChoice = documentWorkspace.GetToolType();
  581. }
  582. else
  583. {
  584. removingCurrentDW = false;
  585. }
  586. documentWorkspace.SetTool(null);
  587. // Choose new active DW if removing the current DW
  588. if (removingCurrentDW)
  589. {
  590. if (_documentWorkspaces.Count == 1)
  591. {
  592. ActiveDocumentWorkspace = null;
  593. }
  594. else if (dwIndex == 0)
  595. {
  596. ActiveDocumentWorkspace = _documentWorkspaces[1];
  597. }
  598. else
  599. {
  600. ActiveDocumentWorkspace = _documentWorkspaces[dwIndex - 1];
  601. }
  602. }
  603. _documentWorkspaces.Remove(documentWorkspace);
  604. ToolBar.DocumentStrip.RemoveDocumentWorkspace(documentWorkspace);
  605. if (_initialWorkspace == documentWorkspace)
  606. {
  607. _initialWorkspace = null;
  608. }
  609. // Clean up the DocumentWorkspace
  610. Document document = documentWorkspace.Document;
  611. documentWorkspace.Document = null;
  612. document.Dispose();
  613. documentWorkspace.Dispose();
  614. documentWorkspace = null;
  615. }
  616. private void UpdateHistoryButtons()
  617. {
  618. if (ActiveDocumentWorkspace == null)
  619. {
  620. _widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Undo, false);
  621. _widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Redo, false);
  622. }
  623. else
  624. {
  625. _widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Undo,
  626. ActiveDocumentWorkspace.History.UndoStack.Count > 1);
  627. _widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Redo,
  628. ActiveDocumentWorkspace.History.RedoStack.Count > 0);
  629. }
  630. }
  631. private void HistoryChangedHandler(object sender, EventArgs e)
  632. {
  633. UpdateHistoryButtons();
  634. // some actions change the document size: make sure we update our status bar panel
  635. // TODO: shouldn't this be handled by our DocumentWorkspace.DocumentChanged handler...?
  636. UpdateDocInfoInStatusBar();
  637. }
  638. public event EventHandler ActiveDocumentWorkspaceChanging;
  639. protected virtual void OnActiveDocumentWorkspaceChanging()
  640. {
  641. SuspendUpdateSnapObstacle();
  642. if (ActiveDocumentWorkspaceChanging != null)
  643. {
  644. ActiveDocumentWorkspaceChanging(this, EventArgs.Empty);
  645. }
  646. if (_activeDocumentWorkspace != null)
  647. {
  648. _activeDocumentWorkspace.FirstInputAfterGotFocus +=
  649. ActiveDocumentWorkspaceFirstInputAfterGotFocus;
  650. _activeDocumentWorkspace.RulersEnabledChanged -= DocumentWorkspaceRulersEnabledChanged;
  651. _activeDocumentWorkspace.DocumentMouseEnter -= DocumentMouseEnterHandler;
  652. _activeDocumentWorkspace.DocumentMouseLeave -= DocumentMouseLeaveHandler;
  653. _activeDocumentWorkspace.DocumentMouseMove -= DocumentMouseMoveHandler;
  654. _activeDocumentWorkspace.DocumentMouseDown -= DocumentMouseDownHandler;
  655. _activeDocumentWorkspace.Scroll -= DocumentWorkspaceScroll;
  656. _activeDocumentWorkspace.Layout -= DocumentWorkspaceLayout;
  657. _activeDocumentWorkspace.DrawGridChanged -= DocumentWorkspaceDrawGridChanged;
  658. _activeDocumentWorkspace.DocumentClick -= DocumentClick;
  659. _activeDocumentWorkspace.DocumentMouseUp -= DocumentMouseUpHandler;
  660. _activeDocumentWorkspace.DocumentKeyPress -= DocumentKeyPress;
  661. _activeDocumentWorkspace.DocumentKeyUp -= DocumenKeyUp;
  662. _activeDocumentWorkspace.DocumentKeyDown -= DocumentKeyDown;
  663. _activeDocumentWorkspace.History.Changed -= HistoryChangedHandler;
  664. _activeDocumentWorkspace.StatusChanged -= OnDocumentWorkspaceStatusChanged;
  665. _activeDocumentWorkspace.DocumentChanging -= DocumentWorkspaceDocumentChanging;
  666. _activeDocumentWorkspace.DocumentChanged -= DocumentWorkspaceDocumentChanged;
  667. _activeDocumentWorkspace.Selection.Changing -= SelectedPathChangingHandler;
  668. _activeDocumentWorkspace.Selection.Changed -= SelectedPathChangedHandler;
  669. _activeDocumentWorkspace.ScaleFactorChanged -= ZoomChangedHandler;
  670. _activeDocumentWorkspace.ZoomBasisChanged -= DocumentWorkspaceZoomBasisChanged;
  671. _activeDocumentWorkspace.Visible = false;
  672. _historyForm.HistoryControl.HistoryStack = null;
  673. _activeDocumentWorkspace.ToolChanging -= ToolChangingHandler;
  674. _activeDocumentWorkspace.ToolChanged -= ToolChangedHandler;
  675. if (_activeDocumentWorkspace.Tool != null)
  676. {
  677. while (_activeDocumentWorkspace.Tool.IsMouseEntered)
  678. {
  679. _activeDocumentWorkspace.Tool.PerformMouseLeave();
  680. }
  681. }
  682. Type toolType = _activeDocumentWorkspace.GetToolType();
  683. if (toolType != null)
  684. {
  685. _globalToolTypeChoice = _activeDocumentWorkspace.GetToolType();
  686. }
  687. }
  688. ResumeUpdateSnapObstacle();
  689. UpdateSnapObstacle();
  690. }
  691. public event EventHandler ActiveDocumentWorkspaceChanged;
  692. protected virtual void OnActiveDocumentWorkspaceChanged()
  693. {
  694. SuspendUpdateSnapObstacle();
  695. if (_activeDocumentWorkspace == null)
  696. {
  697. ToolBar.CommonActionsStrip.SetButtonEnabled(CommonAction.Print, false);
  698. ToolBar.CommonActionsStrip.SetButtonEnabled(CommonAction.Save, false);
  699. }
  700. else
  701. {
  702. _activeDocumentWorkspace.SuspendLayout();
  703. ToolBar.CommonActionsStrip.SetButtonEnabled(CommonAction.Print, true);
  704. ToolBar.CommonActionsStrip.SetButtonEnabled(CommonAction.Save, true);
  705. _activeDocumentWorkspace.BackColor = SystemColors.ControlDark;
  706. _activeDocumentWorkspace.Dock = DockStyle.Fill;
  707. _activeDocumentWorkspace.DrawGrid = DrawGrid;
  708. _activeDocumentWorkspace.PanelAutoScroll = true;
  709. _activeDocumentWorkspace.RulersEnabled = _globalRulersChoice;
  710. _activeDocumentWorkspace.TabIndex = 0;
  711. _activeDocumentWorkspace.TabStop = false;
  712. _activeDocumentWorkspace.RulersEnabledChanged += DocumentWorkspaceRulersEnabledChanged;
  713. _activeDocumentWorkspace.DocumentMouseEnter += DocumentMouseEnterHandler;
  714. _activeDocumentWorkspace.DocumentMouseLeave += DocumentMouseLeaveHandler;
  715. _activeDocumentWorkspace.DocumentMouseMove += DocumentMouseMoveHandler;
  716. _activeDocumentWorkspace.DocumentMouseDown += DocumentMouseDownHandler;
  717. _activeDocumentWorkspace.Scroll += DocumentWorkspaceScroll;
  718. _activeDocumentWorkspace.DrawGridChanged += DocumentWorkspaceDrawGridChanged;
  719. _activeDocumentWorkspace.DocumentClick += DocumentClick;
  720. _activeDocumentWorkspace.DocumentMouseUp += DocumentMouseUpHandler;
  721. _activeDocumentWorkspace.DocumentKeyPress += DocumentKeyPress;
  722. _activeDocumentWorkspace.DocumentKeyUp += DocumenKeyUp;
  723. _activeDocumentWorkspace.DocumentKeyDown += DocumentKeyDown;
  724. if (_workspacePanel.Controls.Contains(_activeDocumentWorkspace))
  725. {
  726. _activeDocumentWorkspace.Visible = true;
  727. }
  728. else
  729. {
  730. _activeDocumentWorkspace.Dock = DockStyle.Fill;
  731. _workspacePanel.Controls.Add(_activeDocumentWorkspace);
  732. }
  733. _activeDocumentWorkspace.Layout += DocumentWorkspaceLayout;
  734. ToolBar.ViewConfigStrip.ScaleFactor = _activeDocumentWorkspace.ScaleFactor;
  735. ToolBar.ViewConfigStrip.ZoomBasis = _activeDocumentWorkspace.ZoomBasis;
  736. _activeDocumentWorkspace.AppWorkspace = this;
  737. _activeDocumentWorkspace.History.Changed += HistoryChangedHandler;
  738. _activeDocumentWorkspace.StatusChanged += OnDocumentWorkspaceStatusChanged;
  739. _activeDocumentWorkspace.DocumentChanging += DocumentWorkspaceDocumentChanging;
  740. _activeDocumentWorkspace.DocumentChanged += DocumentWorkspaceDocumentChanged;
  741. _activeDocumentWorkspace.Selection.Changing += SelectedPathChangingHandler;
  742. _activeDocumentWorkspace.Selection.Changed += SelectedPathChangedHandler;
  743. _activeDocumentWorkspace.ScaleFactorChanged += ZoomChangedHandler;
  744. _activeDocumentWorkspace.ZoomBasisChanged += DocumentWorkspaceZoomBasisChanged;
  745. _activeDocumentWorkspace.Units = _widgets.ViewConfigStrip.Units;
  746. _historyForm.HistoryControl.HistoryStack = ActiveDocumentWorkspace.History;
  747. _activeDocumentWorkspace.ToolChanging += ToolChangingHandler;
  748. _activeDocumentWorkspace.ToolChanged += ToolChangedHandler;
  749. ToolBar.ViewConfigStrip.RulersEnabled = _activeDocumentWorkspace.RulersEnabled;
  750. ToolBar.DocumentStrip.SelectDocumentWorkspace(_activeDocumentWorkspace);
  751. _activeDocumentWorkspace.SetToolFromType(_globalToolTypeChoice);
  752. UpdateSelectionToolbarButtons();
  753. UpdateHistoryButtons();
  754. UpdateDocInfoInStatusBar();
  755. _activeDocumentWorkspace.ResumeLayout();
  756. _activeDocumentWorkspace.PerformLayout();
  757. _activeDocumentWorkspace.FirstInputAfterGotFocus +=
  758. ActiveDocumentWorkspaceFirstInputAfterGotFocus;
  759. }
  760. if (ActiveDocumentWorkspaceChanged != null)
  761. {
  762. ActiveDocumentWorkspaceChanged(this, EventArgs.Empty);
  763. }
  764. UpdateStatusBarContextStatus();
  765. ResumeUpdateSnapObstacle();
  766. UpdateSnapObstacle();
  767. }
  768. public AppWorkspace()
  769. {
  770. SuspendLayout();
  771. // initialize!
  772. InitializeComponent();
  773. InitializeFloatingForms();
  774. _mainToolBarForm.ToolsControl.SetTools(DocumentWorkspace.ToolInfos);
  775. _mainToolBarForm.ToolsControl.ToolClicked += MainToolBarToolClicked;
  776. ToolBar.ToolChooserStrip.SetTools(DocumentWorkspace.ToolInfos);
  777. ToolBar.ToolChooserStrip.ToolClicked += MainToolBarToolClicked;
  778. ToolBar.AppWorkspace = this;
  779. // init the Widgets container
  780. _widgets = new WorkspaceWidgets(this)
  781. {
  782. ViewConfigStrip = ToolBar.ViewConfigStrip,
  783. CommonActionsStrip = ToolBar.CommonActionsStrip,
  784. ToolConfigStrip = ToolBar.ToolConfigStrip,
  785. ToolsForm = _mainToolBarForm,
  786. LayerForm = _layerForm,
  787. HistoryForm = _historyForm,
  788. ColorsForm = _colorsForm,
  789. StatusBarProgress = _statusBar,
  790. DocumentStrip = ToolBar.DocumentStrip
  791. };
  792. // Load our settings and initialize the AppEnvironment
  793. LoadSettings();
  794. // hook into Environment *Changed events
  795. AppEnvironment.PrimaryColorChanged += PrimaryColorChangedHandler;
  796. AppEnvironment.SecondaryColorChanged += SecondaryColorChangedHandler;
  797. AppEnvironment.ShapeDrawTypeChanged += ShapeDrawTypeChangedHandler;
  798. AppEnvironment.GradientInfoChanged += GradientInfoChangedHandler;
  799. AppEnvironment.ToleranceChanged += OnEnvironmentToleranceChanged;
  800. AppEnvironment.AlphaBlendingChanged += AlphaBlendingChangedHandler;
  801. AppEnvironment.FontInfo = ToolBar.ToolConfigStrip.FontInfo;
  802. AppEnvironment.TextAlignment = ToolBar.ToolConfigStrip.FontAlignment;
  803. AppEnvironment.AntiAliasingChanged += EnvironmentAntiAliasingChanged;
  804. AppEnvironment.FontInfoChanged += EnvironmentFontInfoChanged;
  805. AppEnvironment.FontSmoothingChanged += EnvironmentFontSmoothingChanged;
  806. AppEnvironment.TextAlignmentChanged += EnvironmentTextAlignmentChanged;
  807. AppEnvironment.PenInfoChanged += EnvironmentPenInfoChanged;
  808. AppEnvironment.BrushInfoChanged += EnvironmentBrushInfoChanged;
  809. AppEnvironment.ColorPickerClickBehaviorChanged += EnvironmentColorPickerClickBehaviorChanged;
  810. AppEnvironment.ResamplingAlgorithmChanged += EnvironmentResamplingAlgorithmChanged;
  811. AppEnvironment.SelectionCombineModeChanged += EnvironmentSelectionCombineModeChanged;
  812. AppEnvironment.FloodModeChanged += EnvironmentFloodModeChanged;
  813. AppEnvironment.SelectionDrawModeInfoChanged += EnvironmentSelectionDrawModeInfoChanged;
  814. ToolBar.DocumentStrip.RelinquishFocus += RelinquishFocusHandler;
  815. ToolBar.ToolConfigStrip.ToleranceChanged += OnToolBarToleranceChanged;
  816. ToolBar.ToolConfigStrip.FontAlignmentChanged += ToolConfigStripTextAlignmentChanged;
  817. ToolBar.ToolConfigStrip.FontInfoChanged += ToolConfigStripFontTextChanged;
  818. ToolBar.ToolConfigStrip.FontSmoothingChanged += ToolConfigStripFontSmoothingChanged;
  819. ToolBar.ToolConfigStrip.RelinquishFocus += RelinquishFocusHandler2;
  820. ToolBar.CommonActionsStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  821. ToolBar.CommonActionsStrip.MouseWheel += OnToolStripMouseWheel;
  822. ToolBar.CommonActionsStrip.ButtonClick += CommonActionsStripButtonClick;
  823. ToolBar.ViewConfigStrip.DrawGridChanged += ViewConfigStripDrawGridChanged;
  824. ToolBar.ViewConfigStrip.RulersEnabledChanged += ViewConfigStripRulersEnabledChanged;
  825. ToolBar.ViewConfigStrip.ZoomBasisChanged += ViewConfigStripZoomBasisChanged;
  826. ToolBar.ViewConfigStrip.ZoomScaleChanged += ViewConfigStripZoomScaleChanged;
  827. ToolBar.ViewConfigStrip.ZoomIn += ViewConfigStripZoomIn;
  828. ToolBar.ViewConfigStrip.ZoomOut += ViewConfigStripZoomOut;
  829. ToolBar.ViewConfigStrip.UnitsChanged += ViewConfigStripUnitsChanged;
  830. ToolBar.ViewConfigStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  831. ToolBar.ViewConfigStrip.MouseWheel += OnToolStripMouseWheel;
  832. ToolBar.ToolConfigStrip.BrushInfoChanged += DrawConfigStripBrushChanged;
  833. ToolBar.ToolConfigStrip.ShapeDrawTypeChanged += DrawConfigStripShapeDrawTypeChanged;
  834. ToolBar.ToolConfigStrip.PenInfoChanged += DrawConfigStripPenChanged;
  835. ToolBar.ToolConfigStrip.GradientInfoChanged += ToolConfigStrip_GradientInfoChanged;
  836. ToolBar.ToolConfigStrip.AlphaBlendingChanged += OnDrawConfigStripAlphaBlendingChanged;
  837. ToolBar.ToolConfigStrip.AntiAliasingChanged += DrawConfigStripAntiAliasingChanged;
  838. ToolBar.ToolConfigStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  839. ToolBar.ToolConfigStrip.ColorPickerClickBehaviorChanged += ToolConfigStripColorPickerClickBehaviorChanged;
  840. ToolBar.ToolConfigStrip.ResamplingAlgorithmChanged += ToolConfigStripResamplingAlgorithmChanged;
  841. ToolBar.ToolConfigStrip.SelectionCombineModeChanged += ToolConfigStripSelectionCombineModeChanged;
  842. ToolBar.ToolConfigStrip.FloodModeChanged += ToolConfigStripFloodModeChanged;
  843. ToolBar.ToolConfigStrip.SelectionDrawModeInfoChanged += ToolConfigStripSelectionDrawModeInfoChanged;
  844. ToolBar.ToolConfigStrip.SelectionDrawModeUnitsChanging += ToolConfigStripSelectionDrawModeUnitsChanging;
  845. ToolBar.ToolConfigStrip.MouseWheel += OnToolStripMouseWheel;
  846. ToolBar.DocumentStrip.RelinquishFocus += OnToolStripRelinquishFocus;
  847. ToolBar.DocumentStrip.DocumentClicked += DocumentStripDocumentTabClicked;
  848. ToolBar.DocumentStrip.DocumentListChanged += DocumentStripDocumentListChanged;
  849. // Synchronize
  850. AppEnvironment.PerformAllChanged();
  851. _globalToolTypeChoice = _defaultToolTypeChoice;
  852. ToolBar.ToolConfigStrip.ToolBarConfigItems = ToolBarConfigItems.None;
  853. _layerForm.LayerControl.AppWorkspace = this;
  854. ResumeLayout();
  855. PerformLayout();
  856. }
  857. private void ToolConfigStripColorPickerClickBehaviorChanged(object sender, EventArgs e)
  858. {
  859. AppEnvironment.ColorPickerClickBehavior = _widgets.ToolConfigStrip.ColorPickerClickBehavior;
  860. }
  861. private void EnvironmentColorPickerClickBehaviorChanged(object sender, EventArgs e)
  862. {
  863. _widgets.ToolConfigStrip.ColorPickerClickBehavior = AppEnvironment.ColorPickerClickBehavior;
  864. }
  865. private void ToolConfigStripResamplingAlgorithmChanged(object sender, EventArgs e)
  866. {
  867. AppEnvironment.ResamplingAlgorithm = _widgets.ToolConfigStrip.ResamplingAlgorithm;
  868. }
  869. private void EnvironmentResamplingAlgorithmChanged(object sender, EventArgs e)
  870. {
  871. _widgets.ToolConfigStrip.ResamplingAlgorithm = AppEnvironment.ResamplingAlgorithm;
  872. }
  873. private void ToolConfigStripSelectionCombineModeChanged(object sender, EventArgs e)
  874. {
  875. AppEnvironment.SelectionCombineMode = _widgets.ToolConfigStrip.SelectionCombineMode;
  876. }
  877. private void EnvironmentSelectionCombineModeChanged(object sender, EventArgs e)
  878. {
  879. _widgets.ToolConfigStrip.SelectionCombineMode = AppEnvironment.SelectionCombineMode;
  880. }
  881. private void ToolConfigStripFloodModeChanged(object sender, EventArgs e)
  882. {
  883. AppEnvironment.FloodMode = _widgets.ToolConfigStrip.FloodMode;
  884. }
  885. private void EnvironmentFloodModeChanged(object sender, EventArgs e)
  886. {
  887. _widgets.ToolConfigStrip.FloodMode = AppEnvironment.FloodMode;
  888. }
  889. private void ToolConfigStripSelectionDrawModeInfoChanged(object sender, EventArgs e)
  890. {
  891. AppEnvironment.SelectionDrawModeInfo = _widgets.ToolConfigStrip.SelectionDrawModeInfo;
  892. }
  893. private void EnvironmentSelectionDrawModeInfoChanged(object sender, EventArgs e)
  894. {
  895. _widgets.ToolConfigStrip.SelectionDrawModeInfo = AppEnvironment.SelectionDrawModeInfo;
  896. }
  897. private sealed class ToolConfigStripSelectionDrawModeUnitsChangeHandler
  898. {
  899. private readonly ToolConfigStrip _toolConfigStrip;
  900. private readonly Document _activeDocument;
  901. private readonly MeasurementUnit _oldUnits;
  902. public ToolConfigStripSelectionDrawModeUnitsChangeHandler(ToolConfigStrip toolConfigStrip, Document activeDocument)
  903. {
  904. _toolConfigStrip = toolConfigStrip;
  905. _activeDocument = activeDocument;
  906. _oldUnits = toolConfigStrip.SelectionDrawModeInfo.Units;
  907. }
  908. public void Initialize()
  909. {
  910. _toolConfigStrip.SelectionDrawModeUnitsChanged += ToolConfigStripSelectionDrawModeUnitsChanged;
  911. }
  912. private void ToolConfigStripSelectionDrawModeUnitsChanged(object sender, EventArgs e)
  913. {
  914. try
  915. {
  916. SelectionDrawModeInfo sdmi = _toolConfigStrip.SelectionDrawModeInfo;
  917. MeasurementUnit newUnits = sdmi.Units;
  918. double oldWidth = sdmi.Width;
  919. double oldHeight = sdmi.Height;
  920. double newWidth = Document.ConvertMeasurement(oldWidth, _oldUnits, _activeDocument.DpuUnit, _activeDocument.DpuX, newUnits);
  921. double newHeight = Document.ConvertMeasurement(oldHeight, _oldUnits, _activeDocument.DpuUnit, _activeDocument.DpuY, newUnits);
  922. SelectionDrawModeInfo newSdmi = sdmi.CloneWithNewWidthAndHeight(newWidth, newHeight);
  923. _toolConfigStrip.SelectionDrawModeInfo = newSdmi;
  924. }
  925. finally
  926. {
  927. _toolConfigStrip.SelectionDrawModeUnitsChanged -= ToolConfigStripSelectionDrawModeUnitsChanged;
  928. }
  929. }
  930. }
  931. private void ToolConfigStripSelectionDrawModeUnitsChanging(object sender, EventArgs e)
  932. {
  933. if (ActiveDocumentWorkspace == null || ActiveDocumentWorkspace.Document == null) return;
  934. var tcsSdmuch = new ToolConfigStripSelectionDrawModeUnitsChangeHandler(
  935. ToolBar.ToolConfigStrip, ActiveDocumentWorkspace.Document);
  936. tcsSdmuch.Initialize();
  937. }
  938. private void DocumentStripDocumentListChanged(object sender, EventArgs e)
  939. {
  940. bool enableThem = (_widgets.DocumentStrip.DocumentCount != 0);
  941. _widgets.ToolsForm.Enabled = enableThem;
  942. _widgets.HistoryForm.Enabled = enableThem;
  943. _widgets.LayerForm.Enabled = enableThem;
  944. _widgets.ColorsForm.Enabled = enableThem;
  945. _widgets.CommonActionsStrip.SetButtonEnabled(CommonAction.Paste, enableThem);
  946. UpdateHistoryButtons();
  947. UpdateDocInfoInStatusBar();
  948. UpdateCursorInfoInStatusBar(0, 0);
  949. }
  950. public void SaveSettings()
  951. {
  952. Settings.CurrentUser.SetBoolean(SettingNames.Rulers, _globalRulersChoice);
  953. Settings.CurrentUser.SetBoolean(SettingNames.DrawGrid, DrawGrid);
  954. Settings.CurrentUser.SetString(SettingNames.DefaultToolTypeName, _defaultToolTypeChoice.Name);
  955. MostRecentFiles.SaveMruList();
  956. }
  957. private void LoadDefaultToolType()
  958. {
  959. string defaultToolTypeName = Settings.CurrentUser.GetString(SettingNames.DefaultToolTypeName, Tool.DefaultToolType.Name);
  960. ToolInfo[] tis = DocumentWorkspace.ToolInfos;
  961. ToolInfo ti = Array.Find(
  962. tis,
  963. check =>
  964. string.Compare(defaultToolTypeName, check.ToolType.Name, StringComparison.InvariantCultureIgnoreCase) ==
  965. 0);
  966. _defaultToolTypeChoice = ti == null ? Tool.DefaultToolType : ti.ToolType;
  967. }
  968. public void LoadSettings()
  969. {
  970. try
  971. {
  972. LoadDefaultToolType();
  973. _globalToolTypeChoice = _defaultToolTypeChoice;
  974. _globalRulersChoice = Settings.CurrentUser.GetBoolean(SettingNames.Rulers, false);
  975. DrawGrid = Settings.CurrentUser.GetBoolean(SettingNames.DrawGrid, false);
  976. AppEnvironment = AppEnvironment.GetDefaultAppEnvironment();
  977. _widgets.ViewConfigStrip.Units = (MeasurementUnit)Enum.Parse(typeof(MeasurementUnit),
  978. Settings.CurrentUser.GetString(SettingNames.Units, MeasurementUnit.Pixel.ToString()), true);
  979. }
  980. catch (Exception)
  981. {
  982. AppEnvironment = new AppEnvironment();
  983. AppEnvironment.SetToDefaults();
  984. try
  985. {
  986. Settings.CurrentUser.Delete(
  987. new[]
  988. {
  989. SettingNames.Rulers,
  990. SettingNames.DrawGrid,
  991. SettingNames.Units,
  992. SettingNames.DefaultAppEnvironment,
  993. SettingNames.DefaultToolTypeName,
  994. });
  995. }
  996. catch (Exception)
  997. {
  998. }
  999. }
  1000. try
  1001. {
  1002. ToolBar.ToolConfigStrip.LoadFromAppEnvironment(AppEnvironment);
  1003. }
  1004. catch (Exception)
  1005. {
  1006. AppEnvironment = new AppEnvironment();
  1007. AppEnvironment.SetToDefaults();
  1008. ToolBar.ToolConfigStrip.LoadFromAppEnvironment(AppEnvironment);
  1009. }
  1010. }
  1011. protected override void OnLoad(EventArgs e)
  1012. {
  1013. if (ActiveDocumentWorkspace != null)
  1014. {
  1015. ActiveDocumentWorkspace.Select();
  1016. }
  1017. UpdateSnapObstacle();
  1018. base.OnLoad(e);
  1019. }
  1020. public void RefreshTool()
  1021. {
  1022. Type toolType = _activeDocumentWorkspace.GetToolType();
  1023. Widgets.ToolsControl.SelectTool(toolType);
  1024. }
  1025. private void GradientInfoChangedHandler(object sender, EventArgs e)
  1026. {
  1027. if (_widgets.ToolConfigStrip.GradientInfo != AppEnvironment.GradientInfo)
  1028. {
  1029. _widgets.ToolConfigStrip.GradientInfo = AppEnvironment.GradientInfo;
  1030. }
  1031. }
  1032. private void ToolConfigStrip_GradientInfoChanged(object sender, EventArgs e)
  1033. {
  1034. if (AppEnvironment.GradientInfo != _widgets.ToolConfigStrip.GradientInfo)
  1035. {
  1036. AppEnvironment.GradientInfo = _widgets.ToolConfigStrip.GradientInfo;
  1037. }
  1038. }
  1039. /// <summary>
  1040. /// Keeps the Environment's ShapeDrawType and the corresponding widget synchronized
  1041. /// </summary>
  1042. private void ShapeDrawTypeChangedHandler(object sender, EventArgs e)
  1043. {
  1044. if (_widgets.ToolConfigStrip.ShapeDrawType != AppEnvironment.ShapeDrawType)
  1045. {
  1046. _widgets.ToolConfigStrip.ShapeDrawType = AppEnvironment.ShapeDrawType;
  1047. }
  1048. }
  1049. /// <summary>
  1050. /// Keeps the Environment's alpha blending value and the corresponding widget synchronized
  1051. /// </summary>
  1052. private void AlphaBlendingChangedHandler(object sender, EventArgs e)
  1053. {
  1054. if (_widgets.ToolConfigStrip.AlphaBlending != AppEnvironment.AlphaBlending)
  1055. {
  1056. _widgets.ToolConfigStrip.AlphaBlending = AppEnvironment.AlphaBlending;
  1057. }
  1058. }
  1059. private void ColorDisplay_UserPrimaryAndSecondaryColorsChanged(object sender, EventArgs e)
  1060. {
  1061. // We need to make sure that we don't change which user color is selected (primary vs. secondary)
  1062. /

Large files files are truncated, but you can click here to view the full file