~mantas/pinta/stable

« back to all changes in this revision

Viewing changes to Pinta.Core/Classes/BaseTool.cs

  • Committer: Iain Lane
  • Date: 2010-03-13 18:20:18 UTC
  • mfrom: (1.1.2)
  • Revision ID: git-v1:1781694a68ecf232d0110c0b2f3d4a1b96c74ec2
Merge commit 'upstream/0.2'

Conflicts:
        debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// BaseTool.cs
3
 
//  
4
 
// Author:
5
 
//       Jonathan Pobst <monkey@jpobst.com>
6
 
// 
7
 
// Copyright (c) 2010 Jonathan Pobst
8
 
// 
9
 
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
 
// of this software and associated documentation files (the "Software"), to deal
11
 
// in the Software without restriction, including without limitation the rights
12
 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 
// copies of the Software, and to permit persons to whom the Software is
14
 
// furnished to do so, subject to the following conditions:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
19
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
 
// THE SOFTWARE.
26
 
 
27
 
using System;
28
 
using Gtk;
29
 
using System.IO;
30
 
 
31
 
namespace Pinta.Core
32
 
{
33
 
        public abstract class BaseTool
34
 
        {
35
 
                protected ToggleToolButton tool_item;
36
 
                protected ToolItem tool_label;
37
 
                protected ToolItem tool_image;
38
 
                protected ToolItem tool_sep;
39
 
                
40
 
                protected BaseTool ()
41
 
                {
42
 
                }
43
 
                
44
 
                public virtual string Name { get { throw new ApplicationException ("Tool didn't override Name"); } }
45
 
                public virtual string Icon { get { throw new ApplicationException ("Tool didn't override Icon"); } }            
46
 
                public virtual string ToolTip { get { throw new ApplicationException ("Tool didn't override ToolTip"); } }
47
 
                public virtual string StatusBarText { get { return string.Empty; } }
48
 
                public virtual ToggleToolButton ToolItem { get { if (tool_item == null) tool_item = CreateToolButton (); return tool_item; } }
49
 
                public virtual bool Enabled { get { return false; } }
50
 
                
51
 
                #region Public Methods
52
 
                public void DoMouseMove (object o, MotionNotifyEventArgs args, Cairo.PointD point)
53
 
                {
54
 
                        OnMouseMove (o, args, point);
55
 
                }
56
 
 
57
 
                public void DoBuildToolBar (Toolbar tb)
58
 
                {
59
 
                        OnBuildToolBar (tb);
60
 
                }
61
 
 
62
 
                public void DoClearToolBar (Toolbar tb)
63
 
                {
64
 
                        OnClearToolBar (tb);
65
 
                }
66
 
 
67
 
                public void DoMouseDown (DrawingArea canvas, ButtonPressEventArgs args, Cairo.PointD point)
68
 
                {
69
 
                        OnMouseDown (canvas, args, point);
70
 
                }
71
 
 
72
 
                public void DoMouseUp (DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point)
73
 
                {
74
 
                        OnMouseUp (canvas, args, point);
75
 
                }
76
 
 
77
 
                public void DoDeactivated ()
78
 
                {
79
 
                        OnDeactivated ();
80
 
                }               
81
 
                #endregion
82
 
 
83
 
                #region Protected Methods
84
 
                protected virtual void OnMouseMove (object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
85
 
                {
86
 
                }
87
 
 
88
 
                protected virtual void OnBuildToolBar (Toolbar tb)
89
 
                {
90
 
                        if (tool_label == null)
91
 
                                tool_label = new ToolBarLabel (" Tool:  ");
92
 
                        
93
 
                        tb.AppendItem (tool_label);
94
 
                        
95
 
                        if (tool_image == null)
96
 
                                tool_image = new ToolBarImage (Icon);
97
 
                        
98
 
                        tb.AppendItem (tool_image);
99
 
                        
100
 
                        if (tool_sep == null)
101
 
                                tool_sep = new SeparatorToolItem ();
102
 
                        
103
 
                        tb.AppendItem (tool_sep);
104
 
                }
105
 
 
106
 
                protected virtual void OnClearToolBar (Toolbar tb)
107
 
                {
108
 
                        while (tb.NItems > 0)
109
 
                                tb.Remove (tb.Children[tb.NItems - 1]);
110
 
                }
111
 
 
112
 
                protected virtual void OnMouseDown (DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
113
 
                {
114
 
                }
115
 
 
116
 
                protected virtual void OnMouseUp (DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
117
 
                {
118
 
                }
119
 
 
120
 
                protected virtual void OnDeactivated ()
121
 
                {
122
 
                }
123
 
 
124
 
                protected virtual ToggleToolButton CreateToolButton ()
125
 
                {
126
 
                        Image i2 = new Image (PintaCore.Resources.GetIcon (Icon));
127
 
                        i2.Show ();
128
 
                        
129
 
                        ToggleToolButton tool_item = new ToggleToolButton ();
130
 
                        tool_item.IconWidget = i2;
131
 
                        tool_item.Show ();
132
 
                        tool_item.Label = Name;
133
 
                        tool_item.TooltipText = Name;
134
 
                        
135
 
                        return tool_item;
136
 
                }               
137
 
                #endregion
138
 
        }
139
 
}