Borders3D.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. //
  5. // Purpose: 3D borders related classes:
  6. // BorderTypeRegistry - known borders registry.
  7. // IBorderType - border class interface.
  8. // BorderSkin - border visual properties.
  9. //
  10. using System;
  11. using System.Collections;
  12. using System.ComponentModel;
  13. using System.Drawing;
  14. using System.Drawing.Design;
  15. using System.Reflection;
  16. using System.Resources;
  17. namespace FastReport.DataVisualization.Charting
  18. {
  19. #region Border style enumeration
  20. /// <summary>
  21. /// Styles of the border skin.
  22. /// </summary>
  23. public enum BorderSkinStyle
  24. {
  25. /// <summary>
  26. /// Border not used.
  27. /// </summary>
  28. None,
  29. /// <summary>
  30. /// Emboss border.
  31. /// </summary>
  32. Emboss,
  33. /// <summary>
  34. /// Raised border.
  35. /// </summary>
  36. Raised,
  37. /// <summary>
  38. /// Sunken border.
  39. /// </summary>
  40. Sunken,
  41. /// <summary>
  42. /// Thin border with rounded corners.
  43. /// </summary>
  44. FrameThin1,
  45. /// <summary>
  46. /// Thin border with rounded top corners.
  47. /// </summary>
  48. FrameThin2,
  49. /// <summary>
  50. /// Thin border with square corners.
  51. /// </summary>
  52. FrameThin3,
  53. /// <summary>
  54. /// Thin border with square outside corners and rounded inside corners.
  55. /// </summary>
  56. FrameThin4,
  57. /// <summary>
  58. /// Thin border with rounded corners and screws.
  59. /// </summary>
  60. FrameThin5,
  61. /// <summary>
  62. /// Thin border with square inside corners and rounded outside corners.
  63. /// </summary>
  64. FrameThin6,
  65. /// <summary>
  66. /// Border with rounded corners. Supports title text.
  67. /// </summary>
  68. FrameTitle1,
  69. /// <summary>
  70. /// Border with rounded top corners. Supports title text.
  71. /// </summary>
  72. FrameTitle2,
  73. /// <summary>
  74. /// Border with square corners. Supports title text.
  75. /// </summary>
  76. FrameTitle3,
  77. /// <summary>
  78. /// Border with rounded inside corners and square outside corners. Supports title text.
  79. /// </summary>
  80. FrameTitle4,
  81. /// <summary>
  82. /// Border with rounded corners and screws. Supports title text.
  83. /// </summary>
  84. FrameTitle5,
  85. /// <summary>
  86. /// Border with rounded outside corners and square inside corners. Supports title text.
  87. /// </summary>
  88. FrameTitle6,
  89. /// <summary>
  90. /// Border with rounded corners. No border on the right side. Supports title text.
  91. /// </summary>
  92. FrameTitle7,
  93. /// <summary>
  94. /// Border with rounded corners on top and bottom sides only. Supports title text.
  95. /// </summary>
  96. FrameTitle8
  97. }
  98. #endregion
  99. /// <summary>
  100. /// Drawing properties of the 3D border skin.
  101. /// </summary>
  102. [
  103. DefaultProperty("SkinStyle"),
  104. SRDescription("DescriptionAttributeBorderSkin_BorderSkin"),
  105. ]
  106. public class BorderSkin : ChartElement
  107. {
  108. #region Fields
  109. // Private data members, which store properties values
  110. private Color _pageColor = Color.White;
  111. private BorderSkinStyle _skinStyle = BorderSkinStyle.None;
  112. private GradientStyle _backGradientStyle = GradientStyle.None;
  113. private Color _backSecondaryColor = Color.Empty;
  114. private Color _backColor = Color.Gray;
  115. private string _backImage = "";
  116. private ChartImageWrapMode _backImageWrapMode = ChartImageWrapMode.Tile;
  117. private Color _backImageTransparentColor = Color.Empty;
  118. private ChartImageAlignmentStyle _backImageAlignment = ChartImageAlignmentStyle.TopLeft;
  119. private Color _borderColor = Color.Black;
  120. private int _borderWidth = 1;
  121. private ChartDashStyle _borderDashStyle = ChartDashStyle.NotSet;
  122. private ChartHatchStyle _backHatchStyle = ChartHatchStyle.None;
  123. #endregion
  124. #region Constructors
  125. /// <summary>
  126. /// Default public constructor.
  127. /// </summary>
  128. public BorderSkin() : base()
  129. {
  130. }
  131. /// <summary>
  132. /// Constructor.
  133. /// </summary>
  134. /// <param name="parent">The parent chart element.</param>
  135. internal BorderSkin(IChartElement parent) : base (parent)
  136. {
  137. }
  138. #endregion
  139. #region Border skin properties
  140. /// <summary>
  141. /// Gets or sets the page color of a border skin.
  142. /// </summary>
  143. [
  144. SRCategory("CategoryAttributeAppearance"),
  145. Bindable(true),
  146. NotifyParentPropertyAttribute(true),
  147. DefaultValue(typeof(Color), "White"),
  148. SRDescription("DescriptionAttributeBorderSkin_PageColor"),
  149. TypeConverter(typeof(ColorConverter)),
  150. #if DESIGNER
  151. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  152. #endif
  153. ]
  154. public Color PageColor
  155. {
  156. get
  157. {
  158. return _pageColor;
  159. }
  160. set
  161. {
  162. _pageColor = value;
  163. this.Invalidate();
  164. }
  165. }
  166. /// <summary>
  167. /// Gets or sets the style of a border skin.
  168. /// </summary>
  169. [
  170. SRCategory("CategoryAttributeAppearance"),
  171. Bindable(true),
  172. NotifyParentPropertyAttribute(true),
  173. DefaultValue(BorderSkinStyle.None),
  174. SRDescription("DescriptionAttributeBorderSkin_SkinStyle"),
  175. ParenthesizePropertyNameAttribute(true)
  176. ]
  177. public BorderSkinStyle SkinStyle
  178. {
  179. get
  180. {
  181. return _skinStyle;
  182. }
  183. set
  184. {
  185. _skinStyle = value;
  186. this.Invalidate();
  187. }
  188. }
  189. /// <summary>
  190. /// Gets or sets the background color of a skin frame.
  191. /// </summary>
  192. [
  193. SRCategory("CategoryAttributeAppearance"),
  194. Bindable(true),
  195. NotifyParentPropertyAttribute(true),
  196. DefaultValue(typeof(Color), "Gray"),
  197. SRDescription("DescriptionAttributeFrameBackColor"),
  198. TypeConverter(typeof(ColorConverter)),
  199. #if DESIGNER
  200. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  201. #endif
  202. ]
  203. public Color BackColor
  204. {
  205. get
  206. {
  207. return _backColor;
  208. }
  209. set
  210. {
  211. _backColor = value;
  212. this.Invalidate();
  213. }
  214. }
  215. /// <summary>
  216. /// Gets or sets the border color of a skin frame.
  217. /// </summary>
  218. [
  219. SRCategory("CategoryAttributeAppearance"),
  220. Bindable(true),
  221. NotifyParentPropertyAttribute(true),
  222. DefaultValue(typeof(Color), "Black"),
  223. SRDescription("DescriptionAttributeBorderColor"),
  224. TypeConverter(typeof(ColorConverter)),
  225. #if DESIGNER
  226. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  227. #endif
  228. ]
  229. public Color BorderColor
  230. {
  231. get
  232. {
  233. return _borderColor;
  234. }
  235. set
  236. {
  237. _borderColor = value;
  238. this.Invalidate();
  239. }
  240. }
  241. /// <summary>
  242. /// Gets or sets the background hatch style of a skin frame.
  243. /// </summary>
  244. [
  245. SRCategory("CategoryAttributeAppearance"),
  246. Bindable(true),
  247. NotifyParentPropertyAttribute(true),
  248. DefaultValue(ChartHatchStyle.None),
  249. SRDescription("DescriptionAttributeFrameBackHatchStyle"),
  250. #if DESIGNER
  251. Editor(typeof(HatchStyleEditor), typeof(UITypeEditor))
  252. #endif
  253. ]
  254. public ChartHatchStyle BackHatchStyle
  255. {
  256. get
  257. {
  258. return _backHatchStyle;
  259. }
  260. set
  261. {
  262. _backHatchStyle = value;
  263. this.Invalidate();
  264. }
  265. }
  266. /// <summary>
  267. /// Gets or sets the background image of a skin frame.
  268. /// </summary>
  269. [
  270. SRCategory("CategoryAttributeAppearance"),
  271. Bindable(true),
  272. NotifyParentPropertyAttribute(true),
  273. DefaultValue(""),
  274. SRDescription("DescriptionAttributeBackImage"),
  275. #if DESIGNER
  276. Editor(typeof(ImageValueEditor), typeof(UITypeEditor)),
  277. #endif
  278. ]
  279. public string BackImage
  280. {
  281. get
  282. {
  283. return _backImage;
  284. }
  285. set
  286. {
  287. _backImage = value;
  288. this.Invalidate();
  289. }
  290. }
  291. /// <summary>
  292. /// Gets or sets the drawing mode for the background image of a skin frame.
  293. /// </summary>
  294. [
  295. SRCategory("CategoryAttributeAppearance"),
  296. Bindable(true),
  297. NotifyParentPropertyAttribute(true),
  298. DefaultValue(ChartImageWrapMode.Tile),
  299. SRDescription("DescriptionAttributeImageWrapMode"),
  300. ]
  301. public ChartImageWrapMode BackImageWrapMode
  302. {
  303. get
  304. {
  305. return _backImageWrapMode;
  306. }
  307. set
  308. {
  309. _backImageWrapMode = value;
  310. this.Invalidate();
  311. }
  312. }
  313. /// <summary>
  314. /// Gets or sets a color which will be replaced with a transparent color
  315. /// while drawing the background image of a skin frame.
  316. /// </summary>
  317. [
  318. SRCategory("CategoryAttributeAppearance"),
  319. Bindable(true),
  320. NotifyParentPropertyAttribute(true),
  321. DefaultValue(typeof(Color), ""),
  322. SRDescription("DescriptionAttributeImageTransparentColor"),
  323. TypeConverter(typeof(ColorConverter)),
  324. #if DESIGNER
  325. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  326. #endif
  327. ]
  328. public Color BackImageTransparentColor
  329. {
  330. get
  331. {
  332. return _backImageTransparentColor;
  333. }
  334. set
  335. {
  336. _backImageTransparentColor = value;
  337. this.Invalidate();
  338. }
  339. }
  340. /// <summary>
  341. /// Gets or sets the background image alignment of a skin frame.
  342. /// </summary>
  343. /// <remarks>
  344. /// Used by ClampUnscale drawing mode.
  345. /// </remarks>
  346. [
  347. SRCategory("CategoryAttributeAppearance"),
  348. Bindable(true),
  349. NotifyParentPropertyAttribute(true),
  350. DefaultValue(ChartImageAlignmentStyle.TopLeft),
  351. SRDescription("DescriptionAttributeBackImageAlign"),
  352. ]
  353. public ChartImageAlignmentStyle BackImageAlignment
  354. {
  355. get
  356. {
  357. return _backImageAlignment;
  358. }
  359. set
  360. {
  361. _backImageAlignment = value;
  362. this.Invalidate();
  363. }
  364. }
  365. /// <summary>
  366. /// Gets or sets the background gradient style of a skin frame.
  367. /// </summary>
  368. [
  369. SRCategory("CategoryAttributeAppearance"),
  370. Bindable(true),
  371. NotifyParentPropertyAttribute(true),
  372. DefaultValue(GradientStyle.None),
  373. SRDescription("DescriptionAttributeBackGradientStyle"),
  374. #if DESIGNER
  375. Editor(typeof(GradientEditor), typeof(UITypeEditor))
  376. #endif
  377. ]
  378. public GradientStyle BackGradientStyle
  379. {
  380. get
  381. {
  382. return _backGradientStyle;
  383. }
  384. set
  385. {
  386. _backGradientStyle = value;
  387. this.Invalidate();
  388. }
  389. }
  390. /// <summary>
  391. /// Gets or sets the secondary background color of a skin frame.
  392. /// </summary>
  393. /// <remarks>
  394. /// This color is used with <see cref="BackColor"/> when <see cref="BackHatchStyle"/> or
  395. /// <see cref="BackGradientStyle"/> are used.
  396. /// </remarks>
  397. [
  398. SRCategory("CategoryAttributeAppearance"),
  399. Bindable(true),
  400. NotifyParentPropertyAttribute(true),
  401. DefaultValue(typeof(Color), ""),
  402. SRDescription("DescriptionAttributeBorderSkin_FrameBackSecondaryColor"),
  403. TypeConverter(typeof(ColorConverter)),
  404. #if DESIGNER
  405. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  406. #endif
  407. ]
  408. public Color BackSecondaryColor
  409. {
  410. get
  411. {
  412. return _backSecondaryColor;
  413. }
  414. set
  415. {
  416. _backSecondaryColor = value;
  417. this.Invalidate();
  418. }
  419. }
  420. /// <summary>
  421. /// Gets or sets the width of the border line of a skin frame.
  422. /// </summary>
  423. [
  424. SRCategory("CategoryAttributeAppearance"),
  425. Bindable(true),
  426. NotifyParentPropertyAttribute(true),
  427. DefaultValue(1),
  428. SRDescription("DescriptionAttributeBorderSkin_FrameBorderWidth"),
  429. ]
  430. public int BorderWidth
  431. {
  432. get
  433. {
  434. return _borderWidth;
  435. }
  436. set
  437. {
  438. if(value < 0)
  439. {
  440. throw(new ArgumentOutOfRangeException("value", SR.ExceptionBorderWidthIsNotPositive));
  441. }
  442. _borderWidth = value;
  443. this.Invalidate();
  444. }
  445. }
  446. /// <summary>
  447. /// Gets or sets the style of the border line of a skin frame.
  448. /// </summary>
  449. [
  450. SRCategory("CategoryAttributeAppearance"),
  451. Bindable(true),
  452. NotifyParentPropertyAttribute(true),
  453. DefaultValue(ChartDashStyle.NotSet),
  454. SRDescription("DescriptionAttributeBorderSkin_FrameBorderDashStyle"),
  455. ]
  456. public ChartDashStyle BorderDashStyle
  457. {
  458. get
  459. {
  460. return _borderDashStyle;
  461. }
  462. set
  463. {
  464. _borderDashStyle = value;
  465. this.Invalidate();
  466. }
  467. }
  468. #endregion
  469. }
  470. }
  471. namespace FastReport.DataVisualization.Charting.Borders3D
  472. {
  473. /// <summary>
  474. /// Keep track of all registered 3D borders.
  475. /// </summary>
  476. internal class BorderTypeRegistry : IServiceProvider
  477. {
  478. #region Fields
  479. // Border types image resource manager
  480. private ResourceManager _resourceManager = null;
  481. // Storage for all registered border types
  482. internal Hashtable registeredBorderTypes = new Hashtable(StringComparer.OrdinalIgnoreCase);
  483. private Hashtable _createdBorderTypes = new Hashtable(StringComparer.OrdinalIgnoreCase);
  484. #endregion
  485. #region Constructors and services
  486. /// <summary>
  487. /// Border types registry public constructor
  488. /// </summary>
  489. public BorderTypeRegistry()
  490. {
  491. }
  492. /// <summary>
  493. /// Returns border type registry service object
  494. /// </summary>
  495. /// <param name="serviceType">Service type to get.</param>
  496. /// <returns>Border registry service.</returns>
  497. [EditorBrowsableAttribute(EditorBrowsableState.Never)]
  498. object IServiceProvider.GetService(Type serviceType)
  499. {
  500. if(serviceType == typeof(BorderTypeRegistry))
  501. {
  502. return this;
  503. }
  504. throw (new ArgumentException( SR.ExceptionBorderTypeRegistryUnsupportedType( serviceType.ToString()) ));
  505. }
  506. #endregion
  507. #region Methods
  508. /// <summary>
  509. /// Adds 3D border type into the registry.
  510. /// </summary>
  511. /// <param name="name">Border type name.</param>
  512. /// <param name="borderType">Border class type.</param>
  513. public void Register(string name, Type borderType)
  514. {
  515. // First check if border type with specified name already registered
  516. if(registeredBorderTypes.Contains(name))
  517. {
  518. // If same type provided - ignore
  519. if(registeredBorderTypes[name].GetType() == borderType)
  520. {
  521. return;
  522. }
  523. // Error - throw exception
  524. throw (new ArgumentException(SR.ExceptionBorderTypeNameIsNotUnique( name ) ) );
  525. }
  526. // Make sure that specified class support IBorderType interface
  527. bool found = false;
  528. Type[] interfaces = borderType.GetInterfaces();
  529. foreach(Type type in interfaces)
  530. {
  531. if(type == typeof(IBorderType))
  532. {
  533. found = true;
  534. break;
  535. }
  536. }
  537. if(!found)
  538. {
  539. throw (new ArgumentException(SR.ExceptionBorderTypeHasNoInterface ));
  540. }
  541. // Add border type to the hash table
  542. registeredBorderTypes[name] = borderType;
  543. }
  544. /// <summary>
  545. /// Returns border type object by name.
  546. /// </summary>
  547. /// <param name="name">Border type name.</param>
  548. /// <returns>Border type object derived from IBorderType.</returns>
  549. public IBorderType GetBorderType(string name)
  550. {
  551. // First check if border type with specified name registered
  552. if(!registeredBorderTypes.Contains(name))
  553. {
  554. throw( new ArgumentException( SR.ExceptionBorderTypeUnknown( name ) ) );
  555. }
  556. // Check if the border type object is already created
  557. if(!_createdBorderTypes.Contains(name))
  558. {
  559. // Create border type object
  560. _createdBorderTypes[name] =
  561. ((Type)registeredBorderTypes[name]).Assembly.
  562. CreateInstance(((Type)registeredBorderTypes[name]).ToString());
  563. }
  564. return (IBorderType)_createdBorderTypes[name];
  565. }
  566. /// <summary>
  567. /// Border images resource manager.
  568. /// </summary>
  569. public ResourceManager ResourceManager
  570. {
  571. get
  572. {
  573. // Create border images resource manager
  574. if(_resourceManager == null)
  575. {
  576. _resourceManager = new ResourceManager("System.Web.UI.DataVisualization.Charting", Assembly.GetExecutingAssembly());
  577. }
  578. return _resourceManager;
  579. }
  580. }
  581. #endregion
  582. }
  583. /// <summary>
  584. /// Interface which defines the set of standard methods and
  585. /// properties for each border type.
  586. /// </summary>
  587. internal interface IBorderType
  588. {
  589. #region Properties and Method
  590. /// <summary>
  591. /// Border type name.
  592. /// </summary>
  593. string Name { get; }
  594. /// <summary>
  595. /// Sets/Gets the resolution to draw with;
  596. /// </summary>
  597. float Resolution
  598. {
  599. set;
  600. }
  601. /// <summary>
  602. /// Draws 3D border.
  603. /// </summary>
  604. /// <param name="graph">Graphics to draw the border on.</param>
  605. /// <param name="borderSkin">Border skin object.</param>
  606. /// <param name="rect">Rectangle of the border.</param>
  607. /// <param name="backColor">Color of rectangle.</param>
  608. /// <param name="backHatchStyle">Hatch style.</param>
  609. /// <param name="backImage">Back Image.</param>
  610. /// <param name="backImageWrapMode">Image mode.</param>
  611. /// <param name="backImageTransparentColor">Image transparent color.</param>
  612. /// <param name="backImageAlign">Image alignment.</param>
  613. /// <param name="backGradientStyle">Gradient type.</param>
  614. /// <param name="backSecondaryColor">Gradient End Color.</param>
  615. /// <param name="borderColor">Border Color.</param>
  616. /// <param name="borderWidth">Border Width.</param>
  617. /// <param name="borderDashStyle">Border Style.</param>
  618. void DrawBorder(
  619. ChartGraphics graph,
  620. BorderSkin borderSkin,
  621. RectangleF rect,
  622. Color backColor,
  623. ChartHatchStyle backHatchStyle,
  624. string backImage,
  625. ChartImageWrapMode backImageWrapMode,
  626. Color backImageTransparentColor,
  627. ChartImageAlignmentStyle backImageAlign,
  628. GradientStyle backGradientStyle,
  629. Color backSecondaryColor,
  630. Color borderColor,
  631. int borderWidth,
  632. ChartDashStyle borderDashStyle);
  633. /// <summary>
  634. /// Adjust areas rectangle coordinate to fit the 3D border.
  635. /// </summary>
  636. /// <param name="graph">Graphics to draw the border on.</param>
  637. /// <param name="areasRect">Position to adjust.</param>
  638. void AdjustAreasPosition(ChartGraphics graph, ref RectangleF areasRect);
  639. /// <summary>
  640. /// Returns the position of the rectangular area in the border where
  641. /// title should be displayed. Returns empty rect if title can't be shown in the border.
  642. /// </summary>
  643. /// <returns>Title position in border.</returns>
  644. RectangleF GetTitlePositionInBorder();
  645. #endregion
  646. }
  647. }