1 /*
2  * Copyright 2009 Alexander Curtis <alex@logicmill.com>
3  * This file is part of GEDmill - A family history website creator
4  *
5  * GEDmill is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * GEDmill is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with GEDmill.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 using System;
20 using System.Drawing;
21 using System.Drawing.Imaging;
22 using BSLib;
23 using GKCore.Logging;
24 
25 namespace GEDmill.MiniTree
26 {
27     /// <summary>
28     /// A data structure to contain the graphics drawing elements in the appropriate colours for the tree diagram.
29     /// </summary>
30     public class Paintbox : BaseObject
31     {
32         private static readonly GKCore.Logging.ILogger fLogger = LogManager.GetLogger(GMConfig.LOG_FILE, GMConfig.LOG_LEVEL, typeof(Paintbox).Name);
33 
34         public SolidBrush BrushBg;
35         public SolidBrush BrushBox;
36         public SolidBrush BrushBoxHighlight;
37         public SolidBrush BrushBoxConcealed;
38         public SolidBrush BrushBoxShade;
39         public SolidBrush BrushText;
40         public SolidBrush BrushTextLink;
41         public SolidBrush BrushTextConcealed;
42         public Pen PenConnector;
43         public Pen PenConnectorDotted;
44         public Pen PenBox;
45         public Font Font;
46         public ColorPalette Palette;
47         public TextureBrush BrushFakeTransparency;
48         public SolidBrush BrushBgGif;
49         public Color ColourGifTransparent;
50 
51 
52         // Construct the paintbox, reading values for the colours etc from the config.
Paintbox(GMConfig config)53         public Paintbox(GMConfig config)
54         {
55             ColourGifTransparent = Color.Magenta;
56             BrushBgGif = new SolidBrush(ColourGifTransparent);
57 
58             BrushBg = new SolidBrush(config.MiniTreeColourBackground);
59             BrushBox = new SolidBrush(config.MiniTreeColourIndiBackground);
60             BrushBoxHighlight = new SolidBrush(config.MiniTreeColourIndiHighlight);
61             BrushBoxConcealed = new SolidBrush(config.MiniTreeColourIndiBgConcealed);
62             BrushBoxShade = new SolidBrush(config.MiniTreeColourIndiShade);
63             BrushText = new SolidBrush(config.MiniTreeColourIndiText);
64             BrushTextLink = new SolidBrush(config.MiniTreeColourIndiLink);
65             BrushTextConcealed = new SolidBrush(config.MiniTreeColourIndiFgConcealed);
66 
67             PenConnector = new Pen(config.MiniTreeColourBranch, 1.0f);
68             PenConnectorDotted = new Pen(config.MiniTreeColourBranch, 1.0f);
69             PenConnectorDotted.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
70             PenBox = new Pen(config.MiniTreeColourIndiBorder, 1.0f);
71             BrushFakeTransparency = null;
72             Font = new Font(config.TreeFontName, config.TreeFontSize);
73         }
74 
75         // Clean up any resources being used.
Dispose(bool disposing)76         protected override void Dispose(bool disposing)
77         {
78             if (disposing) {
79                 BrushBgGif.Dispose();
80                 BrushBg.Dispose();
81                 BrushBox.Dispose();
82                 BrushBoxHighlight.Dispose();
83                 BrushBoxConcealed.Dispose();
84                 BrushBoxShade.Dispose();
85                 BrushText.Dispose();
86                 BrushTextLink.Dispose();
87                 BrushTextConcealed.Dispose();
88                 PenConnector.Dispose();
89                 PenConnectorDotted.Dispose();
90                 PenBox.Dispose();
91                 Font.Dispose();
92                 if (BrushFakeTransparency != null) {
93                     BrushFakeTransparency.Dispose();
94                 }
95             }
96             base.Dispose(disposing);
97         }
98 
99         // Sets the brush used to fill the background to the graphics image provided.
SetBackgroundImage(string filename)100         public void SetBackgroundImage(string filename)
101         {
102             if (!string.IsNullOrEmpty(filename)) {
103                 try {
104                     Image bgImage = Image.FromFile(filename);
105                     BrushFakeTransparency = new TextureBrush(bgImage);
106                 } catch (Exception e) {
107                     // e.g. System.IO.FileNotFoundException
108                     fLogger.WriteError("SetBackgroundImage()", e);
109                     BrushFakeTransparency = null;
110                 }
111             }
112         }
113     }
114 }
115