48
48
PintaCore.Actions.AccelGroup = new AccelGroup ();
49
49
this.AddAccelGroup (PintaCore.Actions.AccelGroup);
51
PintaCore.Initialize (tooltoolbar, label5, drawingarea1, treeview1, this);
51
PintaCore.Initialize (tooltoolbar, label5, drawingarea1, history_treeview, this);
52
52
colorpalettewidget1.Initialize ();
54
54
PintaCore.Chrome.StatusBarTextChanged += new EventHandler<TextChangedEventArgs> (Chrome_StatusBarTextChanged);
55
PintaCore.History.HistoryItemAdded += new EventHandler<HistoryItemAddedEventArgs> (History_HistoryItemAdded);
56
55
PintaCore.Workspace.CanvasInvalidated += new EventHandler<CanvasInvalidatedEventArgs> (Workspace_CanvasInvalidated);
57
56
PintaCore.Workspace.CanvasSizeChanged += new EventHandler (Workspace_CanvasSizeChanged);
86
85
PintaCore.Workspace.Filename = "Untitled1";
86
PintaCore.History.PushNewItem (new BaseHistoryItem ("gtk-new", "New Image"));
87
87
PintaCore.Workspace.IsDirty = false;
89
88
PintaCore.Workspace.Invalidate ();
91
treeview1.Model = new ListStore (typeof (Pixbuf), typeof (string));
92
treeview1.HeadersVisible = false;
93
AddColumns (treeview1);
91
history_treeview.Model = PintaCore.History.ListStore;
92
history_treeview.HeadersVisible = false;
93
history_treeview.Selection.Mode = SelectionMode.Single;
94
history_treeview.Selection.SelectFunction = HistoryItemSelected;
96
Gtk.TreeViewColumn icon_column = new Gtk.TreeViewColumn ();
97
Gtk.CellRendererPixbuf icon_cell = new Gtk.CellRendererPixbuf ();
98
icon_column.PackStart (icon_cell, true);
100
Gtk.TreeViewColumn text_column = new Gtk.TreeViewColumn ();
101
Gtk.CellRendererText text_cell = new Gtk.CellRendererText ();
102
text_column.PackStart (text_cell, true);
104
text_column.SetCellDataFunc (text_cell, new Gtk.TreeCellDataFunc (HistoryRenderText));
105
icon_column.SetCellDataFunc (icon_cell, new Gtk.TreeCellDataFunc (HistoryRenderIcon));
107
history_treeview.AppendColumn (icon_column);
108
history_treeview.AppendColumn (text_column);
110
PintaCore.History.HistoryItemAdded += new EventHandler<HistoryItemAddedEventArgs> (OnHistoryItemsChanged);
111
PintaCore.History.ActionUndone += new EventHandler (OnHistoryItemsChanged);
112
PintaCore.History.ActionRedone += new EventHandler (OnHistoryItemsChanged);
95
114
PintaCore.Actions.View.ZoomToWindow.Activated += new EventHandler (ZoomToWindow_Activated);
96
115
DeleteEvent += new DeleteEventHandler (MainWindow_DeleteEvent);
98
EffectsAction.Visible = false;
99
117
WindowAction.Visible = false;
119
if (Platform.GetOS () == Platform.OS.Mac)
122
//enable the global key handler for keyboard shortcuts
123
IgeMacMenu.GlobalKeyHandlerEnabled = true;
125
//Tell the IGE library to use your GTK menu as the Mac main menu
126
IgeMacMenu.MenuBar = menubar1;
128
//tell IGE which menu item should be used for the app menu's quit item
129
IgeMacMenu.QuitMenuItem = yourQuitMenuItem;
131
//add a new group to the app menu, and add some items to it
132
var appGroup = IgeMacMenu.AddAppMenuGroup();
133
MenuItem aboutItem = (MenuItem) PintaCore.Actions.Help.About.CreateMenuItem();
134
appGroup.AddMenuItem(aboutItem, Mono.Unix.Catalog.GetString ("About"));
138
// If things don't work out, just use a normal menu.
102
143
private void MainWindow_DeleteEvent (object o, DeleteEventArgs args)
107
148
private void Workspace_CanvasSizeChanged (object sender, EventArgs e)
109
150
Requisition req = new Requisition ();
110
req.Height = (int)PintaCore.Workspace.CanvasSize.Y;
111
req.Width = (int)PintaCore.Workspace.CanvasSize.X;
151
req.Height = PintaCore.Workspace.CanvasSize.Y;
152
req.Width = PintaCore.Workspace.CanvasSize.X;
112
153
drawingarea1.Requisition = req;
114
155
drawingarea1.QueueResize ();
117
158
private void ZoomToWindow_Activated (object sender, EventArgs e)
119
int image_x = (int)PintaCore.Workspace.ImageSize.X;
120
int image_y = (int)PintaCore.Workspace.ImageSize.Y;
122
int window_x = GtkScrolledWindow.Children[0].Allocation.Width;
123
int window_y = GtkScrolledWindow.Children[0].Allocation.Height;
125
160
// The image is small enough to fit in the window
126
if (image_x <= window_x && image_y <= window_y) {
161
if (PintaCore.Workspace.ImageFitsInWindow) {
127
162
PintaCore.Actions.View.ActualSize.Activate ();
166
int image_x = PintaCore.Workspace.ImageSize.X;
167
int image_y = PintaCore.Workspace.ImageSize.Y;
169
int window_x = GtkScrolledWindow.Children[0].Allocation.Width;
170
int window_y = GtkScrolledWindow.Children[0].Allocation.Height;
131
172
// The image is more constrained by width than height
132
173
if ((double)image_x / (double)window_x >= (double)image_y / (double)window_y) {
133
174
double ratio = (double)(window_x - 20) / (double)image_x;
134
175
PintaCore.Workspace.Scale = ratio;
176
PintaCore.Actions.View.SuspendZoomUpdate ();
177
(PintaCore.Actions.View.ZoomComboBox.ComboBox as ComboBoxEntry).Entry.Text = string.Format ("{0}%", (int)(PintaCore.Workspace.Scale * 100));
178
PintaCore.Actions.View.ResumeZoomUpdate ();
136
180
double ratio2 = (double)(window_y - 20) / (double)image_y;
137
181
PintaCore.Workspace.Scale = ratio2;
182
PintaCore.Actions.View.SuspendZoomUpdate ();
183
(PintaCore.Actions.View.ZoomComboBox.ComboBox as ComboBoxEntry).Entry.Text = string.Format ("{0}%", (int)(PintaCore.Workspace.Scale * 100));
184
PintaCore.Actions.View.ResumeZoomUpdate ();
146
193
drawingarea1.GdkWindow.InvalidateRect (e.Rectangle, false);
149
void History_HistoryItemAdded (object sender, HistoryItemAddedEventArgs e)
151
(treeview1.Model as Gtk.ListStore).AppendValues (PintaCore.Resources.GetIcon (e.Item.Icon), e.Item.Text);
154
196
private void Chrome_StatusBarTextChanged (object sender, TextChangedEventArgs e)
156
198
label5.Text = e.Text;
159
void AddColumns (TreeView treeView)
161
CellRendererPixbuf pix = new CellRendererPixbuf ();
162
TreeViewColumn col1 = new TreeViewColumn (string.Empty, pix, "pixbuf", 0);
163
treeView.AppendColumn (col1);
165
CellRendererText rendererText = new CellRendererText ();
166
TreeViewColumn column = new TreeViewColumn (string.Empty, rendererText, "text", 1);
167
treeView.AppendColumn (column);
202
public bool HistoryItemSelected (TreeSelection selection, TreeModel model, TreePath path, bool path_currently_selected)
204
int current = path.Indices[0];
205
if (!path_currently_selected) {
206
while (PintaCore.History.Pointer < current) {
207
PintaCore.History.Redo ();
209
while (PintaCore.History.Pointer > current) {
210
PintaCore.History.Undo ();
216
private void HistoryRenderText (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
218
BaseHistoryItem item = (BaseHistoryItem) model.GetValue (iter, 0);
219
if (item.State == HistoryItemState.Undo) {
220
(cell as Gtk.CellRendererText).Style = Pango.Style.Normal;
221
(cell as Gtk.CellRendererText).Foreground = "black";
222
(cell as Gtk.CellRendererText).Text = item.Text;
223
} else if (item.State == HistoryItemState.Redo) {
224
(cell as Gtk.CellRendererText).Style = Pango.Style.Oblique;
225
(cell as Gtk.CellRendererText).Foreground = "gray";
226
(cell as Gtk.CellRendererText).Text = item.Text;
231
private void HistoryRenderIcon (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
233
BaseHistoryItem item = (BaseHistoryItem) model.GetValue (iter, 0);
234
(cell as Gtk.CellRendererPixbuf).Pixbuf = PintaCore.Resources.GetIcon (item.Icon);
237
private void OnHistoryItemsChanged (object o, EventArgs args) {
238
if (PintaCore.History.Current != null) {
239
history_treeview.Selection.SelectIter (PintaCore.History.Current.Id);
240
history_treeview.ScrollToCell (history_treeview.Model.GetPath (PintaCore.History.Current.Id), history_treeview.Columns[1], true, (float)0.9, 0);
170
246
private void CreateToolBox ()
172
248
// Create our tools