~mantas/pinta/stable

« back to all changes in this revision

Viewing changes to Pinta/Dialogs/ResizeImageDialog.cs

  • Committer: Iain Lane
  • Date: 2010-02-19 15:33:30 UTC
  • Revision ID: git-v1:92cc09614a4e2801bfe39cd971f6b31e694a500b
ImportedĀ UpstreamĀ versionĀ 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// ResizeImageDialog.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 Pinta.Core;
 
29
 
 
30
namespace Pinta
 
31
{
 
32
        public partial class ResizeImageDialog : Gtk.Dialog
 
33
        {
 
34
                private bool value_changing;
 
35
                
 
36
                public ResizeImageDialog ()
 
37
                {
 
38
                        this.Build ();
 
39
 
 
40
                        Icon = PintaCore.Resources.GetIcon ("Menu.Image.Resize.png");
 
41
 
 
42
                        widthSpinner.Value = PintaCore.Workspace.ImageSize.X;
 
43
                        heightSpinner.Value = PintaCore.Workspace.ImageSize.Y;
 
44
 
 
45
                        percentageRadio.Toggled += new EventHandler (percentageRadio_Toggled);
 
46
                        absoluteRadio.Toggled += new EventHandler (absoluteRadio_Toggled);
 
47
 
 
48
                        percentageSpinner.ValueChanged += new EventHandler (percentageSpinner_ValueChanged);
 
49
 
 
50
                        widthSpinner.ValueChanged += new EventHandler (widthSpinner_ValueChanged);
 
51
                        heightSpinner.ValueChanged += new EventHandler (heightSpinner_ValueChanged);
 
52
                }
 
53
 
 
54
                #region Public Methods
 
55
                public void SaveChanges ()
 
56
                {
 
57
                        PintaCore.Workspace.ResizeImage (widthSpinner.ValueAsInt, heightSpinner.ValueAsInt);
 
58
                }
 
59
                #endregion
 
60
                
 
61
                #region Private Methods
 
62
                private void heightSpinner_ValueChanged (object sender, EventArgs e)
 
63
                {
 
64
                        if (value_changing)
 
65
                                return;
 
66
                                
 
67
                        if (aspectCheckbox.Active) {
 
68
                                value_changing = true;
 
69
                                widthSpinner.Value = (int)((heightSpinner.Value * PintaCore.Workspace.ImageSize.X) / PintaCore.Workspace.ImageSize.Y);
 
70
                                value_changing = false;
 
71
                        }
 
72
                }
 
73
 
 
74
                private void widthSpinner_ValueChanged (object sender, EventArgs e)
 
75
                {
 
76
                        if (value_changing)
 
77
                                return;
 
78
 
 
79
                        if (aspectCheckbox.Active) {
 
80
                                value_changing = true;
 
81
                                heightSpinner.Value = (int)((widthSpinner.Value * PintaCore.Workspace.ImageSize.Y) / PintaCore.Workspace.ImageSize.X);
 
82
                                value_changing = false;
 
83
                        }
 
84
                }
 
85
 
 
86
                private void percentageSpinner_ValueChanged (object sender, EventArgs e)
 
87
                {
 
88
                        widthSpinner.Value = (int)(PintaCore.Workspace.ImageSize.X * (percentageSpinner.ValueAsInt / 100f));
 
89
                        heightSpinner.Value = (int)(PintaCore.Workspace.ImageSize.Y * (percentageSpinner.ValueAsInt / 100f));
 
90
                }
 
91
 
 
92
                private void absoluteRadio_Toggled (object sender, EventArgs e)
 
93
                {
 
94
                        RadioToggle ();
 
95
                }
 
96
 
 
97
                private void percentageRadio_Toggled (object sender, EventArgs e)
 
98
                {
 
99
                        RadioToggle ();
 
100
                }
 
101
 
 
102
                private void RadioToggle ()
 
103
                {
 
104
                        if (percentageRadio.Active) {
 
105
                                percentageSpinner.Sensitive = true;
 
106
 
 
107
                                widthSpinner.Sensitive = false;
 
108
                                heightSpinner.Sensitive = false;
 
109
                                aspectCheckbox.Sensitive = false;
 
110
                        } else {
 
111
                                percentageSpinner.Sensitive = false;
 
112
 
 
113
                                widthSpinner.Sensitive = true;
 
114
                                heightSpinner.Sensitive = true;
 
115
                                aspectCheckbox.Sensitive = true;
 
116
                        }
 
117
                }
 
118
                #endregion
 
119
        }
 
120
}
 
121